471,107 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,107 software developers and data experts.

Recursive elements in XML. How do i create a XSD for this?

Hello,

I am trying to create a XML schema to validate a XML document. The XML document has recursive <Section> elements (as shown below). Can someone help me create the XSD for the recursive part (Section One and the children)

<?xml version="1.0" encoding="UTF-8"?>
<MenuHelp sectionHeading="" menuSpace="">
<Description>></Description>
<Sections>
<Section name="Application Help" url="" helpFileName="" isLegacy="1" code="">
<Section name="Section One Help" url="" helpFileName="" isLegacy="1" code="">
<Section name="Section One SubHelp" url="" helpFileName="" isLegacy="1" code="">
<Section name="Section One SubSubHelp" url="" helpFileName="" isLegacy="1" code="">
<Section name="SubSubSubHelp " url="" helpFileName="" isLegacy="1" code=""/>
</Section>
</Section>
<Section name="Header " url="" helpFileName="" isLegacy="1" code=""/>
</Section>
<Section name="Saved Search Help" url="" helpFileName="" isLegacy="1" code=""/>
<Section name="Changes Help" url="" helpFileName="" isLegacy="1" code=""/>
</Section>
<Section name="Login Help" url="" helpFileName="" isLegacy="1" code="">
<Section name="Login Sub Help" url="" helpFileName="" isLegacy="1" code=""/>
</Section>
</Sections>
</MenuHelp>
Jan 31 '08 #1
1 7396
jkmyoung
2,057 Expert 2GB
The key is to use the ref attribute.
When you initially reference the Section element inside the sections, use a ref:
Expand|Select|Wrap|Line Numbers
  1. <xs:element name="Sections">
  2.     <xs:complexType>
  3.         <xs:sequence>
  4.             <xs:element ref="Section" minOccurs="0" maxOccurs="unbounded"/>
  5.         </xs:sequence>
  6.     </xs:complexType>
  7. </xs:element>
  8.  
Then declare the Section element, and have it reference itself.
Expand|Select|Wrap|Line Numbers
  1. <xs:element name="Section">
  2.     <xs:complexType>
  3.         <xs:sequence>
  4.             <xs:element ref="Section" minOccurs="0" maxOccurs="unbounded"/>
  5.         </xs:sequence>
  6.         <xs:attribute name="code"/>
  7.         <xs:attribute name="url"/>
  8.         <xs:attribute name="isLegacy"/>
  9.         <xs:attribute name="name"/>
  10.         <xs:attribute name="helpFileName"/>
  11.     </xs:complexType>
  12. </xs:element>
  13.  
Feb 4 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Perttu Pulkkinen | last post: by
reply views Thread by inquirydog | last post: by
2 posts views Thread by rankam | last post: by
6 posts views Thread by Johan Bergman | last post: by
2 posts views Thread by samuel.adam | last post: by
9 posts views Thread by Csaba Gabor | last post: by
41 posts views Thread by Harry | last post: by
2 posts views Thread by wgarner | last post: by
2 posts views Thread by Susan Harris | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.