473,378 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Sample XML from Schema: Handling Recursion

comp.text.xml -

I've developed a simple XSLT program that generates a sample XML file
from a schema (note, it won't work in every instance, but works for
this program). My problem: how do I tell if an element encountered in
the schema is recursive? Without knowing this, the sample XML is
generated indefinitely. Here is a simple example:

<schema>
<complexType name="Package">
<element name="PackageID" type="string"/>
<element name="Quantity" type="integer"/>
<element ref="Package" minOccurs="0" maxOccurs="unbounded" />
</complexType>
<element name="Package" type="Package"/>
</schema>

My program simply prints elements and their children recursively. If
an @type or @ref is found, it finds the corresponding simpleType or
complexType and continues from there. In the example above, the
Package element (complexType) would continue to print infinitely. Is
there a way, using XSLT, to determine if an element is recursive, and
thus avoid "re-printing" it?

Thanks,
Josh
Jul 20 '05 #1
2 4043
In the example above, the
Package element (complexType) would continue to print infinitely. Is
there a way, using XSLT, to determine if an element is recursive, and
thus avoid "re-printing" it?

Hi,

I don't know if there is a standard way to deal with it, but I came up with this:

<xsl:if test="0=count(//complexType[@name = current()/@ref][element/@ref=current()/../@name])"/>
will be true if it is recursive.

Using this stylesheet:
<xsl:template match="/">
<html>
<head>
</head>
<body>
<xsl:apply-templates select="//complexType"/>
</body></html>
</xsl:template>

<xsl:template match="complexType">
<h1><xsl:value-of select="local-name()"/> - name: <xsl:value-of select="@name"/></h1>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="*">
<p>
<xsl:value-of select="local-name()"/> - ref: <xsl:value-of select="@ref"/> - recursive:
<xsl:value-of select="0!=count(//complexType[@name = current()/@ref][element/@ref=current()/../@name])"/>
</p>
</xsl:template>
an input XML schema like this:

<complexType name="test">
<element ref="d" />
<element ref="test" />
</complexType>
<complexType name="a">
<element ref="b" />
<element ref="a" />
</complexType>
<complexType name="b">
<element ref="f" />
<element ref="a" />
</complexType>
<complexType name="c">
<element ref="a" />
</complexType>
<complexType name="d">
<element ref="e" />
</complexType>

will be outputed as:

complexType - name: test
element - ref: d - recursive: false

element - ref: test - recursive: true

complexType - name: a
element - ref: b - recursive: true

element - ref: a - recursive: true

complexType - name: b
element - ref: f - recursive: false

element - ref: a - recursive: true

complexType - name: c
element - ref: a - recursive: false

complexType - name: d
element - ref: e - recursive: false
I hope you can use this somehow.

regards,

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #2
> Hi,

I don't know if there is a standard way to deal with it, but I came up with this:


Joris -

Thanks for the help! I'm tweaking it right now to work with my schema.

Josh
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jari Kujansuu | last post by:
I can successfully parse XML document using SAX or DOM and I can also validate XML document against schema. Problem is that my program should deal with user-defined schemas which means that when...
1
by: ruthless | last post by:
hello. i've got a question can i in XML Schema define tag that works as lists knows from e.g. C,C++ - recurrent tags? i'm talking about e.g. genealogical tree every level of this tree is...
2
by: Michael Wein | last post by:
Hello, does anyone know of a tool that automatically anonymizes a DTD or XML Schema? By anonymizing I mean renaming all elements/type definitions but still containing the structure, esp. the...
8
by: Jakob Møbjerg Nielsen | last post by:
Hi Is it possible to represent a linked list in XML-Schema. Somthing like: <xsd:complexType name="Llist" > <xsd:sequence> <xsd:element name="content" type="xsd:string"/> <xsd:element...
0
by: Steve Jorgensen | last post by:
In a schema I've been working on recently, a convention I evolved was to use a consistent naming pattern such that, for instance, a Resident could appear in a ResidentSet, and could be referred to...
3
by: Davide Bedin | last post by:
I have a "library" schema with the simple and complex types I commonly use in other schemas and then several other schemas, maybe created by other developers, that import/include the library...
4
by: Ganesh Muthuvelu | last post by:
Hello, Let us say that I have a schema or complex type like this one below: Is there a way programtically or a tool to create sample XML file/data for the schema?. I have number of such complex...
4
by: Henry | last post by:
Does anybody have a real-world sample of buiding a treeview control using data from database tables? All the sample code I have found either builds the treeview manually or uses a file directory...
1
by: George2 | last post by:
Hello everyone, Such code segment is used to check whether function call or exception- handling mechanism runs out of memory first (written by Bjarne), void perverted() { try{
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.