Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java org.w3c.dom:有Java解析器库吗?_Java_Parsing_Dom - Fatal编程技术网

Java org.w3c.dom:有Java解析器库吗?

Java org.w3c.dom:有Java解析器库吗?,java,parsing,dom,Java,Parsing,Dom,我有一个DOM文档org.w3c.DOM,但我需要能够通过XPath之类的方法找到元素。哪个解析器或库可以提供此功能?如果您已经有文档,那么您不需要解析器,因为XML已经被解析了 有一种提供XPath功能的方法。如果您已经有了一个文档,那么就不需要解析器,因为XML已经被解析了 提供XPath功能的方法有很多 嗯 嗯 页面末尾甚至有一个关于如何在DOM文档上使用XPath的示例: // parse the XML as a W3C Document DocumentBuilder builder

我有一个DOM文档org.w3c.DOM,但我需要能够通过XPath之类的方法找到元素。哪个解析器或库可以提供此功能?

如果您已经有文档,那么您不需要解析器,因为XML已经被解析了

有一种提供XPath功能的方法。

如果您已经有了一个文档,那么就不需要解析器,因为XML已经被解析了

提供XPath功能的方法有很多

页面末尾甚至有一个关于如何在DOM文档上使用XPath的示例:

// parse the XML as a W3C Document
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.parse(new File("/widgets.xml"));

XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "/widgets/widget";
Node widgetNode = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);
页面末尾甚至有一个关于如何在DOM文档上使用XPath的示例:

// parse the XML as a W3C Document
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.parse(new File("/widgets.xml"));

XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "/widgets/widget";
Node widgetNode = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);
我首选的xpath库是。它使用简单,功能强大。延迟的示例使用例外:

List<Node> matchingNodes = new DOMXPath("//myxpath").selectNodes(document);
我首选的xpath库是。它使用简单,功能强大。延迟的示例使用例外:

List<Node> matchingNodes = new DOMXPath("//myxpath").selectNodes(document);