busting-out XML sections
Eric Richardson
eric at milagrosoft.com
Fri Oct 6 07:18:16 EDT 2000
Thomas Gagne wrote:
>
> 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.
You could use DOM and then just get a NodeList for order and then
iterate thru the node list passing the Node(s) to the sub-process. The
subprocess could grab any attributes or content and just do whatever it
does.
Hope this helps,
Eric :-)
>
> 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
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
More information about the Python-list
mailing list