0

How to parse 3 different xml file.XML files are as follow

<?xml version="1.0" encoding="UTF-8"?>
<login>
    <item>
        <user_id>id</user_id>
        <user_name>Piron</user_name>
        <user_status>false</user_status>
        </item>
    </login>
<?xml version="1.0" encoding="UTF-8"?>
<logout>
    <logout_item>
        <user_id>id</user_id>
        <user_name>kumar</user_name>
        <user_status>true</user_status>
        </logout_item>
    </logout>
<?xml version="1.0" encoding="UTF-8"?>
<registration>
    <registration_item>
        <user_id>id</user_id>
        <user_name>name</user_name>
        <user_status>user already exist</user_status>
        </registration_item>
</registration>

How to parse them using a single SAX Handler(startElement() and endElement()) in android?

4

1 回答 1

0

是的,你可以尝试这样的事情:

public void startElement(String uri, String localName, String qName,
                         Attributes attributes) throws SAXException {

    currentElement = true;

    if (localName.equals("login") 
        || localName.equals("logout") 
        || localName.equals("registration"))
    {
        /** Start **/
        youList = new YourmodelList();
    } else if(localName.equals("user_id")) {
        youlistList = new YourmodelList();
    } else if(localName.equals("user_name")) {
        youlistList = new YourmodelList();
    } else if (localName.equals("user_status")) {
        youlistList = new YourmodelList();
    } else if (localName.equals("registration")) {
        youlistList = new YourmodelList(); 
    }
}
于 2012-06-29T10:50:37.403 回答