问题
Can anybody tell me how we can parse the following Xml. I get the following xml as response of HttpGet method. I can be store this xml in the string form.
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1">
    <head>
    <status>200</status>
        </head>
    <body>
<outline type="text" text="General" guide_id="f1" is_default="true"/>
<outline type="text" text="Rock Stations" guide_id="f2"/>
<outline type="text" text="Rock Stations" guide_id="f3"/>
<outline type="text" text="Rock" guide_id="f4"/>
<outline type="text" text="Awdhesh" guide_id="f5"/>
    </body>
</opml>
I want to be parse the attribute of outline. And I also want to show the value of text in listview. Please provide me a sample code.
Thanks in Advance ...!!!
回答1:
If you are using SAXParcer, see an example of sax parcer implementation:
http://mobile.tutsplus.com/tutorials/android/android-sdk-build-a-simple-sax-parser/
Please note method
public void startElement(String uri, String localName, String qName,
            Attributes attributes) throws SAXException
here you can check attributes and their values
if(localName.equals("outline"))
    String txtValue= attributes.getValue("text");
    来源:https://stackoverflow.com/questions/10990767/android-how-we-can-get-the-value-from-attribute-from-xml-string