Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one create a schema for composite types?

Tags:

xml

schema

I have an XML spec that looks like this:

<Root>
    <Directory Name="SomeName">
        <TextFile Name="ExampleDocument.txt>This is the content of my sample text file.</TextFile>
        <Directory Name="SubDirectory">
            <Speech Name="Example Canned Speech">
               ...
            </Speech>
        </Directory>
    </Directory>
</Root>

Note that Directory elements can contain other Directory elements. How can I represent that using W3C Schema?

like image 845
Billy ONeal Avatar asked Feb 04 '26 22:02

Billy ONeal


1 Answers

You need to create a recursive <complexType> to represent your <Directory> type. The following is an example of this technique, given the elements you provided.

  <xs:complexType name="DirectoryType">
    <xs:sequence>
      <xs:element name="TextFile"/>
      <xs:element name="Speech"/>
      <xs:element name="Directory" type="DirectoryType"/>
    </xs:sequence>
  </xs:complexType>

  <xs:element name="Root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Directory" type="DirectoryType" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
like image 156
Steve Guidi Avatar answered Feb 07 '26 15:02

Steve Guidi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!