[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: element census tool?

  • From: "David Lee" <dlee@calldei.com>
  • To: "'Uche Ogbuji'" <uche@ogbuji.net>, <xml-dev@l...>
  • Date: Wed, 2 Feb 2011 17:03:16 -0500

RE:  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@o...]
Sent: Wednesday, February 02, 2011 4:43 PM
To: xml-dev@l...
Subject: Re: 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:

 

python element_census.py http://www.retards.org/library/technology/computers/programming/xml/example-xbel.xml | head

/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.

 

[1] http://www.xml3k.org/Amara


--
Uche Ogbuji                       http://uche.ogbuji.net
Weblog: http://copia.ogbuji.net
Poetry ed @TNB: http://www.thenervousbreakdown.com/author/uogbuji/
Founding Partner, Zepheira        http://zepheira.com
Linked-in: http://www.linkedin.com/in/ucheogbuji
Articles: http://uche.ogbuji.net/tech/publications/
Friendfeed: http://friendfeed.com/uche
Twitter: http://twitter.com/uogbuji
http://www.google.com/profiles/uche.ogbuji



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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.