| |
XPath is a language for selecting XML nodes. It was originally part of the
XSLT spec, but was split out because the W3C realized XPath was useful
by itself.
In Resin, you can use XPath.find() to find a node from an XML DOM
data structure.
XPath.find(String pattern, Node node)
|
The first example finds the first <b> in the tree.
test.xml
<top>
<a id='1'>
<b id='2'/>
</a>
<b id='3'/>
<c id='4'/>
</top>
|
import org.w3c.dom.*;
import com.caucho.xml.*;
import com.caucho.xpath.*;
...
Document doc = new Xml().parseDocument("test.xml");
Element elt = (Element) XPath.find("b", doc);
System.out.println("Node: " + elt.getNodeName());
System.out.println("id: " + elt.getAttribute("id"));
|
- XPath is a language for selecting XML nodes
- XPath.find() returns the first matching node
- XPath searches in document order
- The pattern b matches any element <b>
Copyright © 1998-2002 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark,
and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc. | |
|