[XML-SIG] Need an equivalent to Perl's XML::Parser "Tree" style

Benjamin Saller case@appliedtheory.com
Tue, 6 Jun 2000 12:38:16 -0400 (EDT)

Today, John Posner wrote:

    Hi --
    Back when I was a Perl hacker (more of a dabbler, really), I had good luck
    creating an object that represents an entire XML document, using this call:
      new XML::Parser(Style => Tree)
    Here's a description, in Python terms, of the recursive data structure
    created by the above call:
    QUESTION: what set of Python tools comes closest to creating a data
    structure similar to, or exactly like, the above?

I have something somewhat similar. Might be a good staring point if
nothing else. Below is how to get this out of sourceforge's CVS where it
is a just a piece of a larger system.

The idea is to make it behave more like a native object. Rather than lots
of tuples you can use dotted notation to drill down into an object and
dictionary access to get at metadata.

There are test cases that show how to use it, but the quick of it is.
For a file like this

	<listen port="9000"/>


import xmlConfig
container = xmlConfig.xmlConfig().parse(filename)

port  = container.container1.listen['port']
hosts = container.container2.allow.get('host')

print port  # 9000
print hosts # ['', 'foo.bar.com', 'baz.bar.com']


I am not sure how useful this will be, but if it looks helpful give it a
try.  I realize this is not a general purpose solution and doesn't allow
you to address all the data with out getting intermediate handles, but it
works well for simple tasks.

cvs -d:pserver:anonymous@cvs.PASS.sourceforge.net:/cvsroot/PASS login

cvs -z3 -d:pserver:anonymous@cvs.PASS.sourceforge.net:/cvsroot/PASS co 

Benjamin Saller                                     <case@appliedtheory.com>
Technical Strategist                                AppliedTheory
	Where tire hits pavement on the Information super-highway,	
			 that's where my head is...