如何使用Xpath读取更多X​​SD架构?

时间:2015-11-02 10:58:41

标签: java xpath xsd element

我有2个XSD架构first.xsd和second.xsd 在first.xsd中是:

<xs:include schemaLocation="second.xsd" />

我希望在second.xsd中读取元素。 我已定义:

DocumentBuilder builder =  builderFactory.newDocumentBuilder();
Document xmlDocument = builder.parse(new FileInputStream("first.xsd"));
XPath xPath =  XPathFactory.newInstance().newXPath();
NodeList result1 = null;
result1 = (NodeList) xPath.compile("//element[@name='List']").evaluate(xmlDocument, XPathConstants.NODESET);
for (int k = 0; k < result1.getLength(); k++) {
Element ele = (Element)result1.item(k);
System.out.println(ele.getAttribute("type")); }

问题是程序没有在second.xsd中找到元素列表。 我能定义一些吗?

Document xmlDocument = builder.parse(new FileInputStream("first.xsd","second.xsd"));

是LSResourceResolver,但是用于验证。 我可以将它用于我的代码吗? 谢谢你的建议。

0 个答案:

没有答案