简体   繁体   中英

Node position in xml - Java

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.

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());

I get error

java.lang.NullPointerException

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

How to select specified node within Xpath node sets by index

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM