Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android中,如何在解析xml时获得相同标记名的内部标记的内容?_Android_Parsing_Xml Parsing - Fatal编程技术网

在android中,如何在解析xml时获得相同标记名的内部标记的内容?

在android中,如何在解析xml时获得相同标记名的内部标记的内容?,android,parsing,xml-parsing,Android,Parsing,Xml Parsing,在android中,如何在解析xml时获得相同标记名的内部标记的内容? 如果一个程序在xml中有相同的标记名,那么每次我只得到与该名称的第一个标记相关的值时,我们如何才能得到该名称相同的标记的内部标记的值 我的本地xml文件如下所示。如何获取值 <?xml version="1.0" encoding="UTF-8"?> <categories> <category> <id> 1 </id> <name> Main nam

在android中,如何在解析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>

1.
主要名称
1.
2.
子名称
5.
1.
全名
这是全名什么的
白色
xyz
2.
测试
www.test.com/test1.jpg
2.
其他名称
1.
2.
其他名称子名称
5.
1.
他名
这是我的名字什么的
白色
xyz
2.
测试
www.test.com/test1.jpg

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

这取决于使用哪个解析器?您还应该给出一个xml示例片段……您尝试了什么?我已经添加了我的本地xml文件,所以在看到后给出了答案。