Recursive XML Elements

R

rankam

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
 
M

Martin Honnen

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".
 
R

Ramesh Ankam

Thanks Martin

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

thanks,
Ramesh
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top