Android:我们如何从 xml 字符串的属性中获取值 [英] Android: How we can get the value from attribute from xml string

查看:36
本文介绍了Android:我们如何从 xml 字符串的属性中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

我想解析outline的属性.而且我还想在列表视图中显示 text 的值.请提供示例代码.

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.

提前谢谢...!!!

推荐答案

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

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/

请注意方法

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");

这篇关于Android:我们如何从 xml 字符串的属性中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆