Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 4th, 2006, 05:45 PM
dkacher
Guest
 
Posts: n/a
Default 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

  #2  
Old December 4th, 2006, 05:45 PM
Joseph Kesselman
Guest
 
Posts: n/a
Default Re: enumerating paths to leaf nodes in XML Schema

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
  #3  
Old December 4th, 2006, 05:55 PM
Joseph Kesselman
Guest
 
Posts: n/a
Default Re: enumerating paths to leaf nodes in XML Schema

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
  #4  
Old December 5th, 2006, 03:35 PM
dkacher
Guest
 
Posts: n/a
Default Re: enumerating paths to leaf nodes in XML Schema


Joseph Kesselman wrote:
Quote:
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

 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles