Simple XML-to-Python conversion

gaudetteje at gmail.com gaudetteje at gmail.com
Sat Mar 19 05:24:56 CET 2005


I've tried xmltramp and element tree, but these tools aren't what I had
in mind.  I've come to the realization that it's not the tools that are
lacking.  In fact, I'm a big fan of ElementTree now, but would only use
it for large parsing tasks.  Instead, I think the problem is either
inherent in the XML standard, or I'm missing something conceptually.

Let me elaborate.  Most of these tools I've experimented with parse a
document rather easily into a structure that I can traverse one element
at a time.  Each level of a node/tree has 4 basic pieces:
1) the tag,
2) one or more attributes,
3) encapsulated data, and
4) children nodes/trees

>From what I understand, this is how XML was standardized, in a sort of
hierarchical structure of infinite possibilities.  The problem I'm
having with these structures is that I need to actively search through
each level for the item I want.  All I really want to do is access one
or more elements at the same time and know where they are without
searching.

What I'm looking to use are basic structures such as:
root.path
root.input.method
root.input.filename
root.output.filename
to name a few.  Since these are essentially unique constants that will
only be used once or twice, I want to be able to place them in a
function argument, or concatenate several of them, such as root.path
and root.input.filename to create a new string.  I'm finding it rather
impossible to do such things unless I basically create my own structure
from the tree structure that I get when I parse the XML document.

If I used a simple INI file or CSV file, I would simply have to parse
my file once and match the name with the value.  Why is it necessary to
parse a document once and then re-parse your information into a format
that you can use.  This seems absurd to me.  Any thoughts on this?  Do
I even have the correct understanding of how this is done?




More information about the Python-list mailing list