busting-out XML sections

Thomas Gagne tgagne at ix.netcom.com
Thu Oct 5 18:25:07 EDT 2000


I have a file that looks like:

<batch>
<order>
<order_head/> (only one of these)
<order_detail/> (multiples of these)
</order>
<order>....

</batch>

What I need is a good approach to take each <order></order> section and send
the entire contents within it to a separate process.  I'm not worried about
how to send it, I'm trying to figure out the best way to grab the text between
the <order> tags.

If I use sax, I'd have to write methods for everthing that might appear
between the tags and accumulate the text (remember, I don't want to change
anything) into an instance variable.

I thought of using nawk or grep or python but then my scripting language would
have to know how to parse XML to make sure it correctly detects the tags it's
looking for.  That would be too much effort.

Niether solution sounds appealing.  It amounts to a lot of code for what's
really a simple problem.  Maybe there's something in the SAX stuff that would
allow me to grab everything between (and including) the <order> tags.


--
.tom






More information about the Python-list mailing list