Recursive XML Elements

Discussion in 'XML' started by rankam@rogers.com, Mar 12, 2005.

  1. Guest

    Hi There,

    We have a requirement for recursive elements within a XML document? Is
    it possible to design it through XML Schema? And what are implications
    using recursive elements when using DOM Parser in Java?

    Any samples demonstrating this concept in XSD is helpful? I need a XML
    structure something like this below :

    <forms>
    <form-name>formName</form-name>
    <form-id>1234</form-id>
    <secondary>
    ..... other elements
    <secondary>
    ...... Other Elements
    <secondary>
    ..... Other Elements
    </secondary>
    </secondary>
    </secondary>
    <forms>

    thanks,
    Ramesh ANKAM
     
    , Mar 12, 2005
    #1
    1. Advertising

  2. wrote:


    > We have a requirement for recursive elements within a XML document? Is
    > it possible to design it through XML Schema?


    Yes, certainly.

    > And what are implications
    > using recursive elements when using DOM Parser in Java?


    None in particular, of course if you do
    xmlDocument.getElementsByTagName('element')
    or
    element.getElementsByTagName('element')
    you could end up with elements on different nesting levels then but you
    can still process them in document order.

    > Any samples demonstrating this concept in XSD is helpful?


    Here is an XML sample:

    <?xml version="1.0" encoding="UTF-8"?>
    <element xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="test2005031301Xsd.xml">
    <child-element />
    <element>
    <childElement />
    <element>
    <element />
    </element>
    </element>
    </element>

    and here the schema

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    version="1.0">

    <xs:element name="element">
    <xs:complexType>
    <xs:sequence>
    <xs:any processContents="skip" minOccurs="0" />
    <xs:element ref="element" minOccurs="0" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    </xs:schema>

    So you can use
    <xs:element ref
    to refer to the element itself.

    And you need to make sure that somewhere the recursion can stop, meaning
    the nested element needs to be allowed to not occur where needed for
    instance with minOccurs="0".



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Mar 13, 2005
    #2
    1. Advertising

  3. Ramesh Ankam Guest

    Thanks Martin

    Now using "ref" attribute I was able to design a schema with recursive elements.

    thanks,
    Ramesh


    Martin Honnen <> wrote in message news:<42341784$0$26545$-online.net>...
    > wrote:
    >
    >
    > > We have a requirement for recursive elements within a XML document? Is
    > > it possible to design it through XML Schema?

    >
    > Yes, certainly.
    >
    > > And what are implications
    > > using recursive elements when using DOM Parser in Java?

    >
    > None in particular, of course if you do
    > xmlDocument.getElementsByTagName('element')
    > or
    > element.getElementsByTagName('element')
    > you could end up with elements on different nesting levels then but you
    > can still process them in document order.
    >
    > > Any samples demonstrating this concept in XSD is helpful?

    >
    > Here is an XML sample:
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <element xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > xsi:noNamespaceSchemaLocation="test2005031301Xsd.xml">
    > <child-element />
    > <element>
    > <childElement />
    > <element>
    > <element />
    > </element>
    > </element>
    > </element>
    >
    > and here the schema
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <xs:schema
    > xmlns:xs="http://www.w3.org/2001/XMLSchema"
    > version="1.0">
    >
    > <xs:element name="element">
    > <xs:complexType>
    > <xs:sequence>
    > <xs:any processContents="skip" minOccurs="0" />
    > <xs:element ref="element" minOccurs="0" />
    > </xs:sequence>
    > </xs:complexType>
    > </xs:element>
    >
    > </xs:schema>
    >
    > So you can use
    > <xs:element ref
    > to refer to the element itself.
    >
    > And you need to make sure that somewhere the recursion can stop, meaning
    > the nested element needs to be allowed to not occur where needed for
    > instance with minOccurs="0".
     
    Ramesh Ankam, Mar 14, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. P
    Replies:
    1
    Views:
    1,182
    Joe Kesselman
    Jul 7, 2006
  2. Ultrus
    Replies:
    4
    Views:
    2,706
    Stefan Behnel
    Aug 30, 2007
  3. n00m
    Replies:
    12
    Views:
    1,122
  4. vamsi
    Replies:
    21
    Views:
    2,113
    Keith Thompson
    Mar 9, 2009
  5. Chris Seberino
    Replies:
    3
    Views:
    757
    Stefan Behnel
    Jun 12, 2009
Loading...

Share This Page