【问题标题】:how can we get content of inner tag of the same tag name in parse xml in android?我们如何在android中解析xml中获取相同标签名称的内部标签的内容?
【发布时间】:2011-12-07 12:52:26
【问题描述】:

我们如何在 android 的 parse xml 中获取相同标签名称的内部标签的内容? 如果一个程序在 xml 中具有相同的标签名称,那么我们如何获得该标签的内部标签的值,其名称每次我只得到与该名称的第一个标签相关的值时 我的本地 xml 文件如下所示。如何解析并获取值?

<?xml version="1.0" encoding="UTF-8"?>
<categories>
<category>
<id>
1
</id>
<name>
Main name
</name> 
<subcategories>
<count>
1
</count>
<subcategory>
<id>
2
</id>
<name>
Sub name
</name> 
<products> 
<count>
5
</count> 
<product> 
<id>
1
</id>
<name>
fullname
</name>
<description>
this is full name and something 
</description>
<color>
white
</color> 
<size>
xyz
</size>
<images> 
<count>
2
</count>
<image>
<title>
test
</title>
<url>
www.test.com/test1.jpg
</url> 
</image>
</images> 
</product>
</products>
</subcategory>
</subcategories>
</category>
<category> 
<id>
2
</id> 
<name>
other name
</name>
<subcategories>
<count>
1
</count>
<subcategory>
<id>
2
</id> 
<name>
other name subname
</name> 
<products>
<count>
5
</count> 
<product> 
<id>
1
</id>
<name>
patname of othername
</name>
<description>
this isapt name and something
</description>
<color>
white
</color> 
<size>
xyz
</size> 
<images>
<count>
2
</count> 
<image> 
<title>
test
</title>
<url>
www.test.com/test1.jpg
</url>
</image>
</images> 
</product>
</products> 
</subcategory>
</subcategories>
</category> 
</categories>

【问题讨论】:

  • 这取决于你使用哪个解析器?????????
  • 你还应该给一个xml样本sn-p...你试过什么?
  • 我已经添加了有问题的本地 xml 文件,所以在看到之后给出答案。

标签: android parsing xml-parsing


【解决方案1】:

如果您使用的是 DOM 解析器,您可以简单地检查 parentMode,因为外部节点和内部节点将具有不同的父节点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-19
    • 2015-09-17
    • 2023-03-06
    • 2016-11-26
    • 1970-01-01
    • 2016-12-28
    • 1970-01-01
    • 2012-01-24
    相关资源
    最近更新 更多