473,396 Members | 1,804 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,396 software developers and data experts.

enumerating paths to leaf nodes in XML Schema

Hi -
I'm looking for a way to generate a list of the fully-qualified paths
to all of the leaf nodes in an XML Schema. The reason: I have a large
schema for which I'm building a transform stylesheet; I need to be sure
I've covered everything. With a list of the paths to all the leaves, I
can check off my progress.

Have you encountered a program that can generate such a list? Or any
pointers about how to approach it? It seems that there should be a
generic stylesheet to do this, but I don't know how to tackle it. The
schema that I want to analyze is complex -- it has many Type
definitions and references, and uses includes. Any pointers greatly
appreciated.
- Don

Dec 4 '06 #1
3 2589
There may not be a complete enumeration, if any of the data structures
are recursive..

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Dec 4 '06 #2
For that matter, as soon as you allow axes other than child the concept
of "all possible paths" breaks down, since you then have
multiple/redundant ways to express the same request.

Folks have analysed schemas to express them as data-structure trees --
IBM has published papers on schema-driven specialization of parsing and
XSLT processing -- but that's a matter of deciding in advance exactly
which paths are going to be considered significant/useful (and,
sometimes, rewriting the application so it only uses those forms)

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Dec 4 '06 #3

Joseph Kesselman wrote:
For that matter, as soon as you allow axes other than child the concept
of "all possible paths" breaks down, since you then have
multiple/redundant ways to express the same request.

Folks have analysed schemas to express them as data-structure trees --
IBM has published papers on schema-driven specialization of parsing and
XSLT processing -- but that's a matter of deciding in advance exactly
which paths are going to be considered significant/useful (and,
sometimes, rewriting the application so it only uses those forms)

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Thanks. You're right that there might be an unlimited number of paths,
and that it's necessary to limit the axes. Taking what you say into
account, I can restate my goal: I want to build a tree structure that
represents the minimal set of nodes an xml document instance would have
if it had one occurence of each node allowed by the schema. The result
should look like the output of the tree /f /a command in windows, or
the find . -print command in unix.

Thinking about it that way, I realized that there was a way to get what
I was looking for. IDEs like XML Spy allow you to visualize a schema as
such a tree. But, as best I could tell, XML Spy at least doesn't offer
a text listing of the tree. But IDEs do offer to generate a sample
instance, and you can tune whether to include optional nodes. So I
generated a sample instance for my schema. Then I wrote a small
transform to re-present the nodes in the generated xml in a more
compact form:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<!-- enumerate_paths: lists every path (to internal nodes and leaves)
in the input xml -->
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select="child::*">
<xsl:call-template name="listNodes">
<xsl:with-param name="prefix" select="''"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="listNodes">
<xsl:param name="prefix"/>
<xsl:variable name="myName" select="local-name()"/>
<xsl:value-of select="concat($prefix, '/', $myName, ' ')"/>
<xsl:for-each select="attribute::*">
<xsl:value-of select="concat($prefix, '/', $myName, '/@',
local-name(), ' ')"/>
</xsl:for-each>
<xsl:for-each select="child::*">
<xsl:call-template name="listNodes">
<xsl:with-param name="prefix" select="concat($prefix, '/',
$myName)"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

I fed my generated document instance in to this transform, and got back
a listing like the one I want, except that it had duplicates. This was
easy to fix, with sort -u in unix. The end result was the listing I
was looking for. So I'm all set. Thanks for your help.
- Don

Dec 5 '06 #4

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

Similar topics

4
by: abhrajit | last post by:
I'm looking for a C/C++/Java library to create a balanced binary tree data structure given a set of leaf nodes as input. A leaf node should never become an interior node. So if I wish to create...
0
by: Daniel Yacob | last post by:
Greetings, I'm looking for a Java API that would read an XML doc, as a DOM would be fine, and spit out a list of xpaths and corresponding values for all leaf nodes. Is there such a thing? If...
0
by: indo3 | last post by:
Hello, I program an xml editor with xerces for the university of Braunschweig, the user dont see any xml tags, it is represented in a JTree. Now the user shall be able to insert nodes, which...
0
by: Marv | last post by:
Is it possible to print the path of all leaf nodes of an XML using XML::Simple This is the kind of output text that i'm trying to print (not the leaf node values but the path to reach them) c:\>...
5
by: costantinos | last post by:
Hello. I have implemented the Dijkstra shortest path algorithm, it works fine but I have one question on how I can improve something. I want to find all the possible shortest paths from a node...
3
by: Uriah Piddle | last post by:
Hi Gang, I have a SiteMapPath, bound to a Site Map, that traces a hierarchy down to an 'Article' leaf node. But the Article page shows one of many individual articles depending on which article...
5
by: Daniel | last post by:
I am trying to find all possible routes between two points on a tree using a top to bottom search only. The tree looks like this: ' 1 ' / \ ...
2
by: Louis | last post by:
Please help..... I am starting to learn using javascript on DOM. One of the first things I tested was listing all the child nodes from an element. Like -> *html code: <div id="pagetitle">...
0
by: nmaddock | last post by:
Hi Guys, seen this example on msdn, how can i remove the invalide nodes and elements when they fail against the schema and then save to a new xml document. any help would be great my code is...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.