在针对XSD验证XML时忽略元素顺序 [英] Ignore element order while validating XML against XSD

查看:214
本文介绍了在针对XSD验证XML时忽略元素顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个需要针对XSD进行验证的XML。 XML由XSTREAM生成。我们正在使用jaxp api来针对相应的XSD验证XML。遗憾的是,目前我们的测试用例失败了,因为生成的XML具有与XSD不同的顺序/顺序的元素/标签。

We have an XML which needs to be validated against an XSD. The XML is being generated by XSTREAM. and We are using jaxp api's to validate the XML against the respective XSD. Unfortunately, currently our test case fail as the generated XML has elements/Tags in different order/sequence than the XSD.

在针对XSD进行验证时,是否可以忽略生成的XML中元素的顺序?

Is it possible to ignore the order of elements in generated XML while validating it against XSD?

先谢谢你的帮助。

推荐答案

你是什么要求是一种说验证一些XSD并忽略其他部分的方法。我不认为可以做到。

What you are asking for is a way to say "validate some of the XSD and ignore other parts". I don't think that can be done.

一种可能的解决方案是修改架构,使其不使用< sequence> 对于那些元素(要求元素按特定顺序排列),您可以使用< all> ,这允许元素在任何顺序。

One possible solution would be to modify the schema so that instead of using a <sequence> for those elements (which requires that the elements be in a particular order) you can use <all>, which allows the elements to be in any order.

模式的要点是对XML文档强加某些结构和要求。你不能只是说呃,我不喜欢架构的那个特定部分,忽略它,因为那时文档不再符合架构了。

The point of a schema is to impose certain structure and requirements on an XML document. You can't just say "eh, I don't like that particular part of the schema, ignore it" as then the document doesn't conform to the schema anymore.

这篇关于在针对XSD验证XML时忽略元素顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆