【问题标题】:Android: How we can get the value from attribute from xml stringAndroid:我们如何从 xml 字符串的属性中获取值
【发布时间】:2012-06-14 23:42:00
【问题描述】:

谁能告诉我我们如何解析以下 Xml。我得到以下 xml 作为 HttpGet 方法的响应。我可以以字符串形式存储这个xml。

<?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>

我想解析outline的属性。而且我还想在列表视图中显示text 的值。请给我一个示例代码。

在此先感谢...!!!

【问题讨论】:

  • 是的,但是是android的新手,所以我不知道解析属性,但我可以解析状态的值。

标签: android xml-parsing opml


【解决方案1】:

如果您使用的是 SAXParcer,请查看 sax parcer 实现示例:

http://mobile.tutsplus.com/tutorials/android/android-sdk-build-a-simple-sax-parser/

请注意方法

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

在这里您可以检查属性及其值

if(localName.equals("outline"))
    String txtValue= attributes.getValue("text");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-04
    • 1970-01-01
    • 2020-09-29
    • 1970-01-01
    • 2015-06-13
    • 1970-01-01
    • 2012-10-30
    • 1970-01-01
    相关资源
    最近更新 更多