Xml 限制其他命名空间中类型的元素
我想我需要做的是XSD1.0不可能做到,但无论如何我会问。。。 我在文件中有一个Xml 限制其他命名空间中类型的元素,xml,xsd,redefine,xsd-1.0,Xml,Xsd,Redefine,Xsd 1.0,我想我需要做的是XSD1.0不可能做到,但无论如何我会问。。。 我在文件中有一个complexType,比如a.xsd。原则上,我不能触摸这个文件。特别是,我无法更改其targetNamespace。例如: <xs:schema targetNamespace="http://myns.original" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:orig="http://myns.original"> <
complexType
,比如a.xsd
。原则上,我不能触摸这个文件。特别是,我无法更改其targetNamespace
。例如:
<xs:schema targetNamespace="http://myns.original"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:orig="http://myns.original">
<xs:element name="config" type="orig:ConfigType"/>
<xs:complexType name="ConfigType">
<xs:sequence>
<xs:element name="fieldA" type="xs:integer" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
问题来了:原始complexType
中的一个字段是可选的(minOccurs=0
)。现在,我需要重新定义该类型,以便该字段是必需的(minOccurs=1
)。我猜想这可以通过xsd:redefinite
实现,因此我尝试了以下方法:
<xs:schema targetNamespace="http://myns.myns"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:myns="http://myns.myns">
<xs:redefine schemaLocation="b.xsd">
<xs:complexType name="ConfigType">
<xs:complexContent>
<xs:restriction base="myns:ConfigType">
<xs:sequence>
<xs:element name="fieldA" minOccurs="1"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:redefine>
</xs:schema>
老实说,我不太理解这些消息,但经过一些调查,实际问题似乎是重新定义的字段必须与重新定义的字段属于同一名称空间。在我的例子中,我试图将字段orig:fieldA
限制在名称空间http://myns.original
,位于targetNamespace=”的文件中http://myns.myns". 当然,如果a像我在b.xsd
中那样在c.xsd
中继续扩展该类型,那么就没有问题,因为我不会尝试从不同的名称空间修改任何内容
有人知道这能否实现吗?一种解决方案是使用右侧的
targetNamespace
复制将在不同文件a_2.xsd
中修改的定义。但对于一个复杂的系统来说,这是一个非常不受欢迎且无法维护的解决方案。到目前为止,我看到的唯一问题是,在schemaa.xsd
中,您定义了:
<xs:element name="fieldA" type="xs:integer" minOccurs="0"/>
请记住,当您通过限制(实际上是
必须重新定义元素内容模型。
但新的内容模型必须完全符合旧的内容模型
在上一个模式中不是这样的,因为以前
根据a.xsd
,元素fieldA
只允许有整数值。
但现在,你说它可以接受任何东西。
这肯定会导致错误,并且您收到的消息(尽管确实有些胡言乱语):
类型的粒子不是基粒子的有效限制
似乎正是这样说的。你可以用XSD 1.1做到这一点,我仍然在寻找1.0中的解决方案
There is not a complete functional mapping between the particles.
Error for type 'ConfigType'. The particle of the type is not a valid restriction of the particle of the base.
<xs:element name="fieldA" type="xs:integer" minOccurs="0"/>
<xs:element name="fieldA" minOccurs="1"/>
<xs:element name="fieldA" type="xs:anyType" minOccurs="1"/>