如何在Android中使用XMLPullParsing让孩子或分标签中的XML [英] How to get child or sub Tags in xml using XMLPullParsing in android
问题描述
我使用XmlPullParser在android系统解析的XML文件。其时,有我的XML中没有子标签运行良好,我只是检查使用开始标记 XmlPullParse.START_TAG
并获得相应的属性值,但我在一个被卡住的问题,在这里一个标记有另一个子标记,该子标记有包含图片链接的属性。我不能够提取的子标签的链接。
I am using XmlPullParser in android for parsing an XML file. Its running fine when there are no sub tags inside my xml, I just check for the starting tag using XmlPullParse.START_TAG
and get the appropriate attributes value, But I get stuck in a problem, here a single tag has another sub tag and in this sub tag there is an attribute which contains the image link. I am not able to extract that link from that sub tag.
下面是我的XML: -
Here is my XML :-
<section name="section1">
<photo id="1" ilink="ImageLink 1"/>
<photo id="2" ilink="ImageLink 2"/>
</section>
<section name="section2">
<photo id="3" ilink="ImageLink 1"/>
<photo id="4" ilink="ImageLink 2"/>
</section>
我收到父标记是部分,其属性是名,但我怎么能根据段名获得照片标签?也就是说,如果我想解析命名段的照片标记第2节那我怎么能做到这一点????
I am getting the parent tag that is "section" and its attribute that is "name" but how can I get "photo" tag according to section name ?? That is if I want to parse photo tag of section named "section2" then how can I do this ????
请帮我理清了。任何帮助将是AP preciable。
Please help me to sort out that. Any help would be appreciable.
先谢谢了。
推荐答案
您可以编写一个XSL
You could write a xsl
<xsl:template match="/">
<xsl:for-each select="section">
<xsl:value-of select="concat('link ',photo@id, ' from ',@name,' is ',photo@ilink)"><xsl:value-of>
</xsl:for-each>
</xsl:template>
运行在你的XML的XSL,输出将是
链接1从SECTION1为1 ImageLink的
..
链接4从第2节是2 ImageLink的
run the xsl on your xml, the output will be link 1 from section1 is ImageLink 1 .. link 4 from section2 is ImageLink 2
这篇关于如何在Android中使用XMLPullParsing让孩子或分标签中的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!