xml中的节点位置 - Java [英] Node position in xml - Java
问题描述
我想准备一个函数,它会给我节点在xml中的位置.
例如:
I would like to prepare function which will give me position of node in xml.
For example:
int NodePosition = doc.getDocumentElement().getChildNodes().item(t).getNodeName().Position()
将来我想做一些这样的(当然这是例子):
and in future I would like make some like this (of course this is example):
System.out.println(Node.row[NodePosition].tostring());
有没有可能制作这样的东西?或者,也许您知道一些可以实现类似功能的函数.
Is it possible to make something like this? Or maybe you know some function which make something like this.
例如,当我深入时,获得位置时会出现问题.因为 m = 7
For example when I go deeper there is a problem to get position. Because m = 7
doc.getDocumentElement().getChildNodes().item(t).getChildNodes().item(m)
当我尝试制作时(但我必须保存位置):
When I try make this (but I have to save position):
System.out.println(doc.getDocumentElement().getChildNodes().item(7).getNodeName());
我收到错误
java.lang.NullPointerException
推荐答案
对我来说,您似乎在重新发明轮子 - 您正在尝试构建自己的 XPath 版本 - 请参阅:http://www.ibm.com/developerworks/library/x-javaxpathapi/index.html
To me it looks like you are reinventing the wheel - you are trying to build your own version of XPath - See: http://www.ibm.com/developerworks/library/x-javaxpathapi/index.html
这篇关于xml中的节点位置 - Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!