IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

Cannot generate sample XML in XMLSpy Options · View
Stephen Aras
Posted: Thursday, November 19, 2009 5:52:59 PM
Rank: Newbie

Joined: 11/19/2009
Posts: 2
Location: Springfield, MA
I created a schema that has recursive nodes. I used this example from wrox.

Wrox sample

The file validates, but when I try to have XMLSpy create a sample xml doc, a window briefly appears....then shuts down.

Any ideas?

Thanks.

Steve

<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>
island
Posted: Friday, November 20, 2009 5:58:42 AM
Rank: Newbie

Joined: 10/28/2002
Posts: 1,283
Location: AT
Hi,

this is because of the infinite recursive definition of "node". The problem with the schema definition, although it may be valid, is that there is no xml file in existence which could possibly validate against this schema because it stipulates an infinite hierarchy of "node" elements i.e. that "node" must have a child element named "node", and that this child element "node" must inturn also have a child element "node" and so on, infinitely i.e. it is a bad example from wrox. What you have to do, to generate a valid sample file would be to slightly alter the schema definition i.e. add a minOccurs="0" attribute to the node reference. Now the node hierarchy is not infinite, which means that it is possible to generate a valid sample file from it.



Code:

    <xs:element ref="node" minOccurs="0" maxOccurs="unbounded"/>



Stephen Aras
Posted: Friday, November 20, 2009 12:54:48 PM
Rank: Newbie

Joined: 11/19/2009
Posts: 2
Location: Springfield, MA
Thanks Island. I'm new to the forum and wonder if I'd get a quick reply. When you mentioned that the worx example is bad, what do you mean by that? Recursive elements seem like a valid concept. If I had a machine that had a function and a subfunction and a subfunction within that subfunction, it seems to me that recursion is the only way to describe that variable hierarchy.

I'm lost. I tried A and B below. If I do get a good xml doc, will it validate?

A.

<Product_Info xsi:noNamespaceSchemaLocation="Product_Info.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Product_Class Product_Class_Name="Software">
<Product_Type Product_Type_Name="Complicated">
<Functions> <Function Function_Name="Func1"></Function>
<Function Function_Name="Func2">
<Function Function_Name="SubFunction1"></Function>
<Function Function_Name="SubFunction2"></Function>
</Function>
<Function Function_Name="Func3"></Function>
</Functions>
</Product_Type>
</Product_Class>
</Product_Info>

B.

<Product_Info xsi:noNamespaceSchemaLocation="Product_Info.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Product_Class Product_Class_Name="Software">
<Product_Type Product_Type_Name="Complicated">
<Functions>
<Function Function_Name="Func1"></Function>
<Functions>
<Function Function_Name="SubFunction1"></Function>
<Function Function_Name="SubFunction2"></Function>
</Functions>
<Function Function_Name="Func3"></Function>
</Functions>
</Product_Type>
</Product_Class>
</Product_Info>
vlad
Posted: Friday, November 20, 2009 1:14:47 PM
Rank: Advanced Member

Joined: 12/13/2005
Posts: 2,856
Location: Mauritius
Stephen,

"island" has already answered your question "is there better way to do this?" - all you need is to modify the schema as he proposed.

The problem with wrox-sample is not the recursion itself, but the absolute requirement for every XML element to have subelement with the same name.

Think of this example from programming perspective:

function()
{
function();
}


if you execute it, you will end with stack-overflow. This function only makes sense if there is an optional call to the subfunction


function()
{
if ( condition ) { function(); }
}


A minOccurs=0 is such an option from XML perspective.
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.