如何获取xml节点的完整路径 [英] How to get the full path of an xml node
本文介绍了如何获取xml节点的完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨...
请任何人都可以告诉如何获取通过getElementsByTagName()函数获得的xml节点的完整路径.通过此函数,我可以获得指定名称的节点列表.现在我想遍历每个节点,我需要获取完整的每个节点的路径.如何获取路径....
Hi...
Please anybody can tell how to get the full path of an xml node which I obtained with getElementsByTagName() function.With this function I got a list of nodes of specified name.Now I want to iterate each node and I need to get the full path of each node.How can I get the path....
推荐答案
这很简单.
循环获取Node.parentNode
,直到到达文档节点.一种方法是检查Node.nodeType
.循环在nodeType == Document
时结束;另一种方法是检查null
父节点的条件.
要获得完整路径,请在当前路径的左侧将Node.nodeName
的值连接起来,并在nodeName
值之间使用一些定界符.
—SA
This is very simple.
In a loop, getNode.parentNode
until document node is reached. One way of doing this is checkingNode.nodeType
; the loops ends whennodeType == Document
; another way is checking the condition ofnull
parent node.
To get a full path concatenate the values ofNode.nodeName
on the left side of the current path with some delimiter betweennodeName
values.
—SA
这篇关于如何获取xml节点的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文