Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Recursive XML Elements

Reply
Thread Tools

Recursive XML Elements

 
 
rankam@rogers.com
Guest
Posts: n/a
 
      03-12-2005
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

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      03-13-2005


http://www.velocityreviews.com/forums/(E-Mail Removed) 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 xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test2005031301Xsd.x ml">
<child-element />
<element>
<childElement />
<element>
<element />
</element>
</element>
</element>

and here the schema

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlnss="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/
 
Reply With Quote
 
 
 
 
Ramesh Ankam
Guest
Posts: n/a
 
      03-14-2005
Thanks Martin

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

thanks,
Ramesh


Martin Honnen <(E-Mail Removed)> wrote in message news:<42341784$0$26545$(E-Mail Removed)-online.net>...
> (E-Mail Removed) 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 xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="test2005031301Xsd.x ml">
> <child-element />
> <element>
> <childElement />
> <element>
> <element />
> </element>
> </element>
> </element>
>
> and here the schema
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema
> xmlnss="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".

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How *build* new elements and *replace* elements with xml.dom.minidom? Chris Seberino Python 3 06-12-2009 05:08 AM
Recursive functions Vs Non-recursive functions - performance aspect vamsi C Programming 21 03-09-2009 10:53 PM
Two recursive calls inside of a recursive function n00m C++ 12 03-13-2008 03:18 PM
replacing xml elements with other elements using lxml Ultrus Python 4 08-30-2007 07:17 AM
XML elements to JavaScript Array elements Conversion P XML 1 07-07-2006 09:08 PM



Advertisments