Android: How we can get the value from attribute from xml string

為{幸葍}努か 提交于 2020-01-30 08:45:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!