0

I want to create a XSD schema which is valid for both type of XML file:

<caption> 
    <tt>blah</tt>
</caption>

and

<tt>blah</tt>

And I tried minOccurs for caption but as it is the root it can't be minOccurs = 0 times. So, how to achieve this?

Jirka Š.
  • 3,388
  • 2
  • 15
  • 17
user1041889
  • 88
  • 1
  • 6
  • 1
    Neither of your example instances is well-formed, so I'm not sure exactly what your question is intended to mean. – Michael Kay Jul 06 '14 at 17:29

1 Answers1

0

Just a tip

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <!-- First possible root element -->
    <xs:element name="tt" type="xs:string"/>

    <!-- Second possible root element-->
    <xs:element name="caption">
        <xs:complexType>
            <xs:sequence>
                <!-- just reference to first defined element - when something change there, it won't be necessary to change it everywhere -->
                <xs:element ref="tt" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

Obviously there are other ways how to reach the same effect.

Jirka Š.
  • 3,388
  • 2
  • 15
  • 17
  • Oh, I see. I didn't know you can put two elemets as roots in one xsd. Will try that out and mark this accepted. – user1041889 Jul 10 '14 at 08:55
  • Single xsd but created two classes which I wanted to avoid. Hmm.. anyway your answer is correct for the question i asked. – user1041889 Jul 21 '14 at 18:35