Alessandro Ronchi wrote:
I have a very simple xml file, where some elements have "name" childs.
<name> contains a string wich I must get, starting from the parent
element.
<schemaVersion>
<name>0</name>
<schemaGraph>
<factNode>
<id>99</id>
<name>Shipment</name>
<tableName>shipment</tableName>
</factNode>
<dimension>
<id>0</id>
<name>Date</name>
<tableName>date</tableName>
</dimension>
</schemaGraph>
</schemaVersion>
I can select a node and get the referring element, but I cannot select
the name starting from that element.
If I select factNode, and xelement = factNode,
//I create the xpath
XPath xPathSelector = DocumentHelper.createXPath("//name");
// I want to select the name starting from factNode
List results = xPathSelector.selectNodes(xelement);
// I get the node
Node node = (Node) results.get(0);
//Here I get the string
stringa = node.getText();
I always get all the name occurencies, and the first is always
the /schemaVersion/name. I want only one
result: /schemaversion/factNode/name instead of all //name occurrencies.
The DOM4J docs says:
selectNodes
public List selectNodes(Object context)
selectNodes performs this XPath expression on the given Node or List
of Nodes instances appending all the results together into a single
list.
Parameters:
context - is either a node or a list of nodes on which to
evalute the XPath
Returns:
the results of all the XPath evaluations as a single list
Where is my mistake? How can I do what I want?
Thanks in advance, it's a blocking problem for my university thesis.
I think you can use XPath axes such as "descendant".
Ex: //descendant::factNode/name
Bye, Seva
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user