String query = null;
XPathExpression expr;
Object Result = null;
expr = xpath.compile("//table/column[contains(translate(text(),'ABCDEFGHIJKLMNAOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'"+query+"')]//text()");
result = expr.evaluate(doc, XpathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int i = 0; i<nodes.getLength(); i++){
System.out.println(nodes.item(i).getParentNode().getNodeName() + "" + nodes.item(i).getNodeValue());
}
Hi, so I want to start off by saying I am new to xpath and fairly new to java. I am trying to create a query interface for this large xml file and this is what I have come up with so far. The xml file is full of logs and it is setup somewhat like this....
<database>
<table>
<column1>
<column2>
<column3>
.....
The code works well at pulling back the column that match the search term however I would like it to pull back the whole table and then print it out. this will give me more valuable info including the date stamp the person who entered it ect.... I have tried various things from trying to get the parentnode from nodes(i) then putting the .getchildnodes into another nodelist but that didn't work at all. I also tried adding /.. at the end of the xpath before the text() to see if it would give me back the parent but that ended up just giving me the root tag somehow. I think I am kinda close, maybe not I don't know but if anyone can help that would be much appreciated, I have been stuck on this for a while now.
I think you want to use ..
instead of //
For example to get all table
with a td
value of xxx
you could use
//table/tr/td[text() = 'xxx']/../..