Jdom of the API of XPath is in the org.jdom.xpath. Under this package, there is an abstract class xpath.java and implement class jaxenxpath.java, get XPath objects with the XPath class when using the XPath class, then call its selectnodes (object context) method or selectsinglenode (Object) Context) Method, the former returns a set of nodes (List objects) based on the XPath statement; the latter returns the first node (Object type) in accordance with an XPath statement. See the JDM-B10 self-containers: it analyzes the number and parameter number of registered servlets in the web.xml file, and outputs the role name.
Web.xml file: XML Version = "1.0" encoding = "ISO-8859-1"> -> version 1.0 * / public class XPathReader {public static void main (String [] args) throws IOException, JDOMException {if (args.length = 1!) {System.err.println ( "Usage: java XPathReader web.xml"); Return;} String filename = args [0]; // Enter web.xml printstream out = system.out; Saxbuilder Builder = New Saxbuilder (); Docuild (new file (filename); / / Get Document Object // Print Servlet Information XPath ServletPath = XPath.newInstance ("// servlet"); //, select any path serm element list servlets = servletpath.selectnodes (// Returns all servlet elements. xpathreader code> demonstrates how to * read a servlet 2.2 Web archive file usning xpath. * P> * * @Author jason hunter * @