如何忽略未知标签的验证? [英] How to ignore the validation of Unknown tags?

查看:27
本文介绍了如何忽略未知标签的验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对 XSD 功能的另一个挑战,

我一直在通过我的客户发送 XML 文件,这些文件将有 0 个或多个未定义或 [调用] 意外标记(可能出现在层次结构中).好吧,它们对我来说是多余的标签..所以我必须忽略它们的存在,但与它们一起还有一些需要验证的标签集.

One more challenge to the XSD capability,

I have been sending XML files by my clients, which will be having 0 or more undefined or [call] unexpected tags (May appear in hierarchy). Well they are redundant tags for me .. so I have got to ignore their presence, but along with them there are some set of tags which are required to be validated.

这是一个示例 XML:

This is a sample XML:

<root>
  <undefined_1>one</undefined_1>
  <undefined_2>two</undefined_2>
  <node>to_be_validated</node>
  <undefined_3>two</undefined_3>
  <undefined_4>two</undefined_4>
</root>

以及我尝试使用的 XSD:

And the XSD I tried with:

  <xs:element name="root" type="root"></xs:element>
  <xs:complexType name="root">
    <xs:sequence>
      <xs:any maxOccurs="2" minOccurs="0"/>
      <xs:element name="node" type="xs:string"/>
      <xs:any maxOccurs="2" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType

由于某些原因,XSD 不允许这样做.
上面提到的例子只是一个例子.实用的 XML 带有复杂的 XML 标签层次结构..

XSD doesn't allow this, due to certain reasons.
The above mentioned example is just a sample. The practical XML comes with the complex hierarchy of XML tags ..

如果你能破解它,请告诉我.

Kindly let me know if you can get a hack of it.

顺便说一句,替代解决方案是在验证过程之前插入 XSL 转换.好吧,我避免使用它,因为我需要更改触发验证过程的 .Net 代码,这至少得到我公司的支持.

By the way, The alternative solution is to insert XSL-transformation, before validation process. Well, I am avoiding it because I need to change the .Net code which triggers validation process, which is supported at the least by my company.

推荐答案

结论:

这在 XSD 中是不可能的.我试图达到要求的所有方法都被验证工具命名为模棱两可",伴随着一堆错误.

This is not possible with XSD. All the approaches I was trying to achieve the requirement were named as "ambiguous" by validation-tools, accompanying bunch of errors.

这篇关于如何忽略未知标签的验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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