Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 13th, 2007, 11:59 AM
Registered User
 
Join Date: Feb 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Recursive nodes in XML Schema

I have an XML file which I want to generate a schema for. The file, simplified, looks like this:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<nodes>
  <node>
    <node></node>
    <node>
      <node></node>
    </node>
    <text></text>
  </node>
</nodes>
The <node> elements can hold an infinite number of other <node> elements.

Now I auto generated the schema from VS2005 and get:
Code:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="nodes">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="node">
          <xs:complexType>
            <xs:sequence>
              <xs:element maxOccurs="unbounded" name="node">
                <xs:complexType>
                  <xs:sequence minOccurs="0">
                    <xs:element name="node" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="text" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
I cannot work out how to modify the schema to tell it about the <node> once and make it understand that <node> can nest other <node>'s.

Any ideas?

 
Old April 13th, 2007, 12:25 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You want something like:

<xs:element name="nodes">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="node" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:element name="node">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="node" maxOccurs="unbounded"/>
        <xs:element name="text" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
</xs:element>




Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a recursive template for various nodes spencer.clark XSLT 5 August 2nd, 2005 03:49 PM
Handling recursive XML Nodes using XSL RichaM XSLT 5 June 21st, 2005 02:45 PM
What's the use of XML Schema?! janise XML 2 August 29th, 2004 05:31 AM
xml schema help allang XML 0 August 19th, 2004 09:58 PM
XML, XML Schema, JavaScript, ASP cyberjames2003 XML 0 June 4th, 2003 04:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.