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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With