Android xml解析内部元素?

时间:2013-11-05 06:27:31

标签: android xml parsing

我是android dev的新手,只是想知道xml解析,所以我已经有了我的结构来获取xml,但在解析它时,我有这个设置:

 for (int i = 0; i < nl.getLength(); i++) {
                        HashMap<String, Object> map = new HashMap<String, Object>();
                        Element e = (Element) nl.item(i);

                        Log.d("onLoginHelper", e.toString());

                        //create the temp map of the specific item
                        map.put(KEY_NAME, xmlparser.getValue(e, KEY_NAME));
                        map.put(KEY_VALUE, xmlparser.getValue(e, KEY_VALUE));

但是,我的key_value不包含值,xml如下所示:

<member>
<name>test</name>
<value>
<int>0</int>
</value>
</member>

 <member>
 <name>testmsg</name>
    <value>
    <string>Success</string>
    </value>
 </member>

值代码是另一个xml元素,但它可以有所不同,那么我如何在for循环中获取该元素的值? 感谢名单

1 个答案:

答案 0 :(得分:0)

看看这个演示:

  1. http://androidexample.com/XML_Parsing_-_Android_Example/index.php?view=article_discription&aid=69&aaid=94
  2. http://theopentutorials.com/tutorials/android/xml/android-simple-xml-sax-parser-tutorial/
  3. 您还可以使用XmlPullParser类来解析xml。

    Its recommend to use `XmlPullParser`, which is an efficient and maintainable way to parse XML on Android. 
    

    看看:http://developer.android.com/training/basics/network-ops/xml.html

    使用XmlPullParser的教程:http://www.vogella.com/articles/AndroidXML/article.html

相关问题