简体   繁体   English

如何允许我的复杂类型中的任何类型的元素排除导入模式中的类型/元素

[英]How to allow elements of any type in my complex type excluding the types/elements from imported schemas

I am writting a xml schema(lets say A) and it imports another schema(lets say B). 我正在编写一个xml模式(让我们说A),然后导入另一个模式(让我们说B)。 I have a complex type (lets say it is named CT) and it lists sequence/choice of elements defined in B. I want to allow any element in the sequence/choice but list some of them explicitly. 我有一个复杂的类型(可以说它命名为CT),它列出了B中定义的元素的序列/选择。我想允许序列/选择中的任何元素,但要明确列出其中的一些。 How do I do that ? 我怎么做 ? For example 例如

<xs:schema xmlns:b="http://B" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:a="http://A" targetNamespace="http://A">
        <xs:import namespace="http://B"/>
                <xs:complexType name="CT">
                    <xs:sequence minOccurs="0" maxOccurs="unbounded"> <!-- using choice is a possible option -->
                        <xs:element ref="b:e1" minOccurs="0"/>
                        <xs:element ref="b:e2" minOccurs="0"/>
                        <xs:element ref="b:e3" minOccurs="0"/>
                        <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
                    </xs:sequence>
                </xs:complexType>
    </xs:schema>

The problem with this schema is that it is ambiguous. 这种模式的问题在于它是模棱两可的。 The validation does not pass because the "##other" namespace allows any namespaces different from A => it is possible to use elements from B but some of them are already declared in the choice/sequence and that is where the ambiguity comes from. 验证不会通过,因为“ ## other”命名空间允许使用与A =>不同的任何命名空间,可以使用B中的元素,但是其中一些元素已经在选择/序列中声明,这就是歧义的来源。

Note: The order of B:e1, B:e2, B:e3 is not defined. 注意:B:e1,B:e2,B:e3的顺序未定义。

One would ask "why would you like to do that" ? 有人会问“为什么要这么做”

Because I am using JAXB to generate some classes from this xml schema. 因为我正在使用JAXB从此xml模式生成一些类。 I know the elements B:e1, B:e2, B:e3 most probably will be there and I have special workflow for them (so I need java object representation for each of them) and I don't really have to handle the other possible elements (but they should be allowed). 我知道元素B:e1,B:e2,B:e3很可能会在那里,并且我为它们提供了特殊的工作流程(因此我需要为它们每个使用Java对象表示),而我真的不必处理其他的可能的元素(但应该允许)。

Note: I can not use include instead of import, because the B schema is predefined and targets different namespace. 注意:我不能使用include代替import,因为B模式是预定义的并且针对不同的名称空间。

So does anyone knows how to exclude B from ##other ? 有人知道如何从## other中排除B吗? Any other solutions are welcome. 欢迎任何其他解决方案。

Thank you. 谢谢。

This is straightforward in XSD 1.1, because in 1.1 when a wildcard competes with an xsd:element element, the xsd:element element wins. 这在XSD 1.1中非常简单,因为在1.1中,当通配符与xsd:element元素竞争时,xsd:element元素将获胜。 (In 1.0, the pattern you illustrate produces a violation of the 'Unique Particle Attribution' [ie determinism] rule.) (在1.0中,您演示的模式违反了“唯一粒子归因”(即确定性)规则。)

Currently XSD 1.1 is supported by (in alpha order) Altova, Saxon, and Xerces. 当前,Altova,Saxon和Xerces(按字母顺序)支持XSD 1.1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM