xsd:选择中的任何+其他元素 [英] xsd:any + other elements inside choice

查看:74
本文介绍了xsd:选择中的任何+其他元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何实现这样的目标:

How can I achieve something like this:

<xs:element name="getSubjectProductsResponse">
   <xs:complexType>
        <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:element name="Products">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="Date" type="xs:date"/>
                        <xs:element name="Branch" type="xs:date" minOccurs="0"/>
                        <xs:element name="State" type="xs:string">

                        <xs:element name="ProductDetail">
                          <xs:complexType>
                             **<xs:choice>
                                  <xs:element name="Account" type="ns:TAccount"/>
                                  <xs:element name="KK" type="ns:TCreditCard"/>
                                  <xs:any/>
                             </xs:choice>**
                          </xs:complexType>
                       </xs:element>

此架构无效.

这是产品列表服务响应消息结构的一部分.对于每个响应中的产品,都有公共属性(日期,分支...)和特定于特定产品类型的属性(在ProductDetail元素中).这就是使用选择"的原因.因此,在ProductDetail中,应该只有一个产品元素,即KK或Account.

It's the part of the structure of the response message for Product List Service. For every Product in response message, there are common attributes (Date, Branch...) and attributes which are specific for specific type of product(in ProductDetail element). That's the reason for using "choice". So, in ProductDetail, there should be only one product element, either KK, or Account.

但是将来可能会发生,我需要添加另一种类型的产品.而且,当这种情况发生时,我不想影响对这款产品不感兴趣的消费者.我希望他们仍然能够使用新类型的产品(不更改其代码)来验证消息.

But it may happen in the future, that I will need to add another type of product. And when this happens, I don't want to impact consumers who are not interested in this product. I want them to be still able to validate messages with new types of products (without changes in their code).

简而言之,我试图要求 Account KK 之一,或一个 xs:any 其他元​​素.

In short, I am trying to require one of Account or KK OR one xs:any other element.

有什么办法,如何在XSD中实现呢?

Is there some way, how can I achieve this in XSD?

推荐答案

XSD 1.1

ProductDetail 的声明将允许 Account KK xs:any 其他元​​素:

XSD 1.1

This declaration for ProductDetail will allow either Account or KK or xs:any other element:

<xs:element name="ProductDetail">
  <xs:complexType>
    <xs:choice>
      <xs:element name="Account" type="xs:string"/>
      <xs:element name="KK" type="xs:string"/>
      <xs:any/>
    </xs:choice>
  </xs:complexType>
</xs:element>

注释:

  • The above solution works for XSD 1.1 only. Your requirement runs afoul of Unique Particle Attribution under XSD 1.0.
  • By default xs:any has processContents="strict". See processContents strict vs lax vs skip for xsd:any for an explanation of the various values for processContents.

这篇关于xsd:选择中的任何+其他元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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