我的XML数据带有SOAP信封,但是我的XSD模式只能验证信封内的XML数据。我期待着可以编辑XSD并遍历并且仅验证信封内xml的机制。
例如,在XSLT中,我们可以选择设置根参数<xsl:template match="*:MsgHeader">
而不是<xsl:template match="*:Envelope">
答案 0 :(得分:0)
正如您建议的那样,在XSLT(2.0+)中进行验证是一个选择-但可能不是一个很好的选择,因为XSLT在第一个验证错误后停止。
如果您使用Saxon作为验证引擎,则可以通过Java进行所需的验证,如下所示:
Processor p = new Processor(true);
SchemaManager sm = p.getSchemaManager();
sm.load(new StreamSource(new File('schema.xsd')));
SchemaValidator sv = sm.newSchemaValidator();
DocumentBuilder db = p.newDocumentBuilder();
XdmNode doc = db.build(new StreamSource(new File('source.xml')));
XdmNode target = (XdmNode)doc.select(descendant("payload")).findFirst().get();
sv.validate(target.asSource());