Kadzhaev Marat
Kadzhaev Marat

Reputation: 1317

XSD if-else condition

I need to make if/else condition in my xsd schema. Specifically pattern node. How I can do it?

<s:complexType name="parent">
    <s:sequence>
        <s:element name="elem1" type="s:string"/>
        <s:element name="elem2">
            <s:simpleType>
                <s:restriction base="s:string">
                    <s:pattern value="if (elem1 == 3) //todo 
                                      else //todo"/>
                </s:restriction>
            </s:simpleType>
        </s:element>
   </s:sequence>
</s:complexType name="parent">

Upvotes: 2

Views: 6101

Answers (1)

kjhughes
kjhughes

Reputation: 111630

No, you cannot use if within xs:pattern/@value.

No, you cannot reference another element within xs:pattern/@value.

What you can do:

  • XSD 1.0: Refactor your XML design and use the core content modeling constructs.
  • XSD 1.1: Conditional Type assignment might help.
  • XSD 1.1: Assertions might help.

More specific guidance than that is possible only with a more specific question that shows XML that should and should not be valid, that explains //todo, etc.

Upvotes: 7

Related Questions