XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
RE: [xml-dev] element census tool?

There’s always the XQuery approach

( example in xmlsh)

 

xquery  -q  ‘ distinct-values( //node-name(.) ) ‘

 

 

 

 

 

----------------------------------------

David A. Lee

dlee@calldei.com

http://www.xmlsh.org

 

From: Uche Ogbuji [mailto:uche@ogbuji.net]
Sent: Wednesday, February 02, 2011 4:43 PM
To: xml-dev@lists.xml.org
Subject: Re: [xml-dev] element census tool?

 

Oh what the heck.  I might as well offer a quick and dirty Amara [1] recipe.

 

import sys

 

import amara

from amara.lib.util import element_subtree_iter

from amara.xpath.util import abspath

 

doc = amara.parse(sys.argv[1])

top_prefixes = dict(doc.xml_select('*')[0].xml_namespaces)

for e in element_subtree_iter(doc):

    print abspath(e, prefixes=top_prefixes)

    attrs = dict(e.xml_attributes)

    if attrs:

        print '\t', attrs

 

 

So for example:

 

/xbel

            {(None, u'version'): u'1.0'}

/xbel/title

/xbel/folder

            {(None, u'folded'): u'yes'}

/xbel/folder[2]

            {(None, u'folded'): u'yes'}

/xbel/folder[2]/title

/xbel/folder[2]/bookmark

            {(None, u'href'): u'http://www.sciam.com/1999/0599issue/0599bosak.html'}

 

Pretty easy to tweak or format and details of report, etc.

 

In the example above I pass along a URL.  You can also pass along a file name, if you like.

 



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS