我想验证XML文件对this schema(即在zip中);它会导入两个其他XSD文件。如何使用导入另一个模式文件的模式文件验证XML?
<import namespace="http://www.w3.org/2000/09/xmldsig#"
schemaLocation="xmldsig-core-schema.xsd"/>
<import namespace="http://www.w3.org/2001/04/xmlenc#"
schemaLocation="xenc-schema.xsd"/>
2点档也可在这里:
- http://www.forum-datenaustausch.ch/xmldsig-core-schema.zip
- http://www.forum-datenaustausch.ch/xenc-schema.zip。
在验证,我得到这个错误:
Src-resolve: Cannot Resolve The Name 'xenc:EncryptedData' To A(n) 'element Declaration' Component.
我的验证/解组代码如下所示(使用MOXY作为JAXB提供者):
jaxbContext = JAXBContext.newInstance(type.getRequestType().getPackage().getName());
Unmarshaller um = jaxbContext.createUnmarshaller();
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new StreamSource(this.getClass().getResourceAsStream("/xsd/" + type.getXsdName())));
um.setSchema(schema);
root = um.unmarshal(new StreamSource(new ByteArrayInputStream(xmlData)), type.getRequestType());
之前你问什么呢类型是:我编写的代码可以从http://www.forum-datenaustausch.ch/导入所有类型的发票。但4.3和更高版本使用这两个附加的模式文件。如何验证XML文件?
两个的XSD并给出了XML,并都是从同一个“官方”源http://www.forum-datenaustausch.ch/。所以在xsd或xml中很可能没有问题。 但是在你引用的文章中,我发现该模式工厂可能需要多个xsd - 我认为这就是解决方案。我会尽力。 – dermoritz 2013-03-26 08:07:44
我只是试图加载模式工厂中的所有模式,但错误仍然存在。另一方面,如果我尝试验证xml在线,我得到了同样的错误 - 所以我不知道模式是否加载并正确使用?! – dermoritz 2013-03-26 10:07:05
@dermoritz,您是否按照文章中描述的方式进行了尝试,并且您是否已将*所有* XSD放入您的jar中的相同文件夹中? – 2013-03-26 12:37:29