如何使用Java中的XPath访问OWL文档?我有一个XML文件形式的OWL文档。我想从这个文档中提取元素。我的代码适用于简单的XML文档,但它不适用于OWL XML文档。我实际上是想获得这个元素:/rdf:RDF/owl:Ontology/rdfs:label为此我做了这个: DocumentBuilder builder = builderfactory.newDocumentBuilder();
Document xmlDocument = builder.parse(
new File(XpathMain.class.getResource("person.xml").getFile()));
XPathFactory factory = javax.xml.xpath.XPathFactory.newInstance();
XPath xPath = factory.newXPath();
XPathExpression xPathExpression = xPath.compile("/rdf:RDF/owl:Ontology/rdfs:label/text()");
String nameOfTheBook = xPathExpression.evaluate(xmlDocument,XPathConstants.STRING).toString();我也试过这样只提取rdfs:label元素: XPathExpression xPathExpression = xPath.compile("//rdfs:label");
NodeList nodes = (NodeList) xPathExpression.evaluate(xmlDocument, XPathConstants.NODESET);但是这个节点列表是空的。请让我知道我哪里出错了。我正在使用Java XPath API。
添加回答
举报
0/150
提交
取消