xs:任何包装器 xml 架构验证 [英] xs:any wrapper xml schema validation

查看:26
本文介绍了xs:任何包装器 xml 架构验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种方法来开发扩展另一个模式验证 XML 结构的模式.假设我们有架构 A,它包含一个使用 <xs:any> 元素的扩展点这样我们就有了这样的架构:

Hi I'm trying to find a way to develop a schema that extends another schema validate XML structures. Lets say we have Schema A and it contains an extension point using the <xs:any> element So that we have a schema like this:

Source.xsd:

<xs:complexType name="AType">
  <xs:complexContent>
    <xs:sequence>
      <xs:element name="B"/>
      <xs:any/>
    </xs:sequence>
  </xs:complexContent>
</xs:complexType>

<xs:element name="A" type="AType"/>

我可以创建另一个模式来验证此 XML 并引用原始模式吗?

Can I make another schema that will validate this XML with a reference to the original schema?

Extended.xml:

<A>
  <B></B>
  <C></C>
</A>

我想创建一个架构来验证整个 A(带有 C)元素,而我不必重写整个 AType 合并 C 元素.我也不能使用 redefine 元素.

I would like to create a schema that will validate the whole A (with the C) element without me having to rewrite the whole AType to incorporate the C element. I also can't use the redefine element.

提前致谢!

推荐答案

我认为 Petru 的建议 - 以及我们实际使用的东西 - 是这样的:你定义

What I think Petru is suggesting - and something we actually use - is this: you define

Base.xsd

<xs:complexType name="AType"> 
  <xs:complexContent> 
    <xs:sequence> 
      <xs:element name="B" type="BType"/> 
      <xs:group ref="ATypeExtra"/> 
    </xs:sequence> 
  </xs:complexContent> 
</xs:complexType> 

<xs:element name="A" type="AType"/> 

简单.xsd

<xs:include schemaLocation="Base.xsd"/>

<xs:group name="ATypeExtra">
  <xs:sequence>
  </xs:sequence>
</xs:group>

扩展.xsd

<xs:include schemaLocation="Base.xsd"/>

<xs:group name="ATypeExtra">
  <xs:sequence>
     <xs:element name="C" type="CType"/>
  </xs:sequence>
</xs:group>

然后根据您想要的定义使用 Simple.xsdExtended.xsd 进行验证.

and then use either Simple.xsd or Extended.xsd for the validation depending on which definition you want.

在我们的例子中,我们有一个核心架构不能改变但可以在不同的安装中扩展的系统,所以我们分发与所有 xxxExtra 组(和属性组)引用,然后在每个安装中以不同的方式定义.

In our case we have a system with a core schema that must not change but can be extended in different installations, so we distribute the equivalent of Base.xsd above with all the xxxExtra groups (and attribute groups) references, that are then defined in different ways in each installation.

这篇关于xs:任何包装器 xml 架构验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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