[英]parse xml using java for recursive xpath node
I have xml with a repeating node structure within single node. 我在单个节点内具有带有重复节点结构的xml。 How do I parse all the values by level?
如何按级别解析所有值?
<Totallevel>3</Totallevel>
<A>
<B>text</B>
<level>1</level>
<A>
<B>text</B>
<level>2</level>
<A>
<B>text</B>
<level>3</level>
</A>
</A>
</A>
That would allow you to specify level 那将允许您指定级别
//A[level='2']
If you need to get value from B than example is here for level 2 如果您需要从B获取价值,那么这里是2级的示例
//A[level='2']/B
Parse your xml with DocumentBuilder
so that you can get the Document
. 使用
DocumentBuilder
解析xml,以便获取Document
。 Iterates then using getChildNodes()
method from the root down to leaf 然后使用
getChildNodes()
方法从根到叶进行迭代
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.