我正在尝试解组一个包含< xi:include>的xml文档.里面的标签.但SAXParser不允许这样做,即使我特别告诉SAXParserFactory允许它.
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setXIncludeaware(true);
spf.setNamespaceAwere(true);
spf.setFeature("http://apache.org/xml/features/xinclude", true);
spf.setFeature("http://apache.org/xml/features/xinclude/fixup-base-uris", true);
XMLReader xr = spf.newSAXParser().getXMLReader();
SAXSource source = new SAXSource(xr, new InputSource(inputStream));
JAXBElement<MyClass> el = unmarshaller.unmarshal(source, MyClass.class);
要读取的XML文档
<?xml version="1.0" encoding="UTF-8"?>
<extension xmlns="http://www.example.com/test" xmlns:ext="http://www.example.com/test" xmlns:xi="http://www.w3.org/2003/XInclude">
<visibility>
<resourceConstraints>
<resourceConstraint ext:resourceId="resourceOne">
<role ext:show="true">AdminUsers</role>
</resourceConstraint>
<resourceConstraint ext:resourceId="resourceTwo">
<role ext:show="true">AdminUsers</role>
</resourceConstraint>
</resourceConstraints>
<xi:include href="extraContent.xml" />
</visibility>
</extension>
当我运行它时,我得到这个例外:
org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 50; cvc-complex-type.2.4.a: Invalid content was found starting with element 'xi:include'. One of '{"http://www.example.com/test":resourceConstraints}' is expected.
当我删除< xi:include>从XML文档中标记,文件解组就好了. unmarshaller附加了一个模式.架构不允许< xi:include>.
解决方法:
我使用xmlns:xi =“http://www.w3.org/2003/XInclude”,而我应该使用xmlns:xi =“http://www.w3.org/2001/XInclude”
问题现在解决了!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。