2

I have this HTML code:

<description>This is an <a href="example.htm">example</a> <it>text </it>!</description>

For this code, I have to create an XSD.

My try was to create an element with xs:all for a tag and it tag. But how can I create the simple text within the xs:all? I tried it with an string element, but this is of course wrong, because it is an element. But also if I am using an any element, it is an element. How can I create this simple text within the a and it tags?

<xs:element name="description" minOccurs="0">
     <xs:complexType>
         <xs:all>
          <xs:element name="a">
                <xs:complexType>
                  <xs:attribute name="href" type="xs:string" />
                 </xs:complexType>
               </xs:element>
          <xs:element name="it" type="xs:string" />
          <xs:element name="text" type="xs:string" />
        </xs:all>
    </xs:complexType>
  </xs:element>
kjhughes
  • 106,133
  • 27
  • 181
  • 240
Matthias M
  • 135
  • 3
  • 19

1 Answers1

3

To allow your description element to be a string with a and it elements mixed in zero or more times in any order:

  • Use mixed="true" in XSD for mixed content.
  • Use xs:choice with minOccurs="0" to allow a and it to never appear.
  • Use xs:choice with maxOccurs="unbounded" to allow a and it to appear multiple times.

XSD

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="description">
    <xs:complexType mixed="true">
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="a">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
                <xs:attribute name="href" type="xs:string"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
        <xs:element name="it" type="xs:string" />
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>
kjhughes
  • 106,133
  • 27
  • 181
  • 240