修改XSD以使用substitutionGroup

时间:2021-08-12 17:19:54

I need help changing the xsd file by using substitutionGroup or Choice, Below is the xsd file I used in my code, Now I started receiving the XML data with tag "Organization" instead of "INDIVIDUAL", except that change , all other tags were same. How I can I accommodate the change in my xsd file . I tried changing the xsd like Below ,but my xml is not getting validated against the schema.

我需要帮助通过使用substitutionGroup或Choice更改xsd文件,下面是我在代码中使用的xsd文件,现在我开始接收带有标签“Organization”而不是“INDIVIDUAL”的XML数据,除了更改,所有其他标签都是相同。我如何能够容纳我的xsd文件中的更改。我尝试像下面一样更改xsd,但我的xml没有得到针对模式的验证。

修改XSD以使用substitutionGroup

修改XSD以使用substitutionGroup

1 个解决方案

#1


0  

Substitution group works with elements declared as global elements (they are not defined within a type but a top level of a schema).

替换组使用声明为全局元素的元素(它们不是在类型中定义,而是在模式的*定义)。

In case your Individual element and Organization element are globally defined:

如果您的Individual元素和Organization元素是全局定义的:

<xs:element name="INDIVIDUAL">
    <!-- ind. element content -->
</xs:element>

<xs:element name="ORGANIZATION" substitutionGroup="INDIVIDUAL">
    <!-- org. element content -->
</xs:element>

Then you only need to use a reference to the head of the substitutionGroup to be valid:

然后,您只需要使用对substitutionGroup的头部的引用有效:

<xs:element name="TEST">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="INDIVIDUAL">

Individual or any element substituable to individual will be valid here. So you mainly need to make your element global before using substitution.

个人或任何可替代个人的元素在此处有效。所以你主要需要在使用替换之前使你的元素全局化。

#1


0  

Substitution group works with elements declared as global elements (they are not defined within a type but a top level of a schema).

替换组使用声明为全局元素的元素(它们不是在类型中定义,而是在模式的*定义)。

In case your Individual element and Organization element are globally defined:

如果您的Individual元素和Organization元素是全局定义的:

<xs:element name="INDIVIDUAL">
    <!-- ind. element content -->
</xs:element>

<xs:element name="ORGANIZATION" substitutionGroup="INDIVIDUAL">
    <!-- org. element content -->
</xs:element>

Then you only need to use a reference to the head of the substitutionGroup to be valid:

然后,您只需要使用对substitutionGroup的头部的引用有效:

<xs:element name="TEST">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="INDIVIDUAL">

Individual or any element substituable to individual will be valid here. So you mainly need to make your element global before using substitution.

个人或任何可替代个人的元素在此处有效。所以你主要需要在使用替换之前使你的元素全局化。