471,356 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,356 software developers and data experts.

Suggestions for Python XML library which can search and insert

Hi,

I'm looking for a library that can search through an XML document tree,
locate an element by attribute (ideally this can be done through
XPath), and insert an element (as its child).

Simple? Yes? ...but the code I've seen so far which does this uses
'nested for loops' for trees which are relatively shallow compared to
mine. So I'm wondering if you could give me some suggestions as to
which XML library could do this without resorting to nested for loops,
and/or better yet, what's the trend in this type of operation?

Thanks in advance.

Jul 26 '05 #1
3 998
la*********@gmail.com wrote:
Simple? Yes? ...but the code I've seen so far which does this uses
'nested for loops' for trees which are relatively shallow compared to
mine. So I'm wondering if you could give me some suggestions as to
which XML library could do this without resorting to nested for loops,
and/or better yet, what's the trend in this type of operation?


Why do you care if they are nested for loops?

What is the problem you are experiencing that is caused
by for loops?

Does the software you've seen not work with your XML
trees? What error do you get when you try it?

Or are you just opposed to for loops on philosophical
grounds?
--
Steven.

Jul 26 '05 #2
> Why do you care if they are nested for loops?

What is the problem you are experiencing that is caused
by for loops?


The nested loops which I speak of are highly dependent
on the structure of the document tree. The examples which
I've seen using DOM or ElementTree deal with shallow trees,
but in my case, I am dealing with deeper trees--which means
that the degree of nesting would also grow deeper if I were
to follow suit. Also, it makes for hard to manage code.

I'd say that lxml is exactly what I'm looking for, because
it supports XPath and Robert Kern's example is pretty reassuring.
Thanks Robert Kern!

Jul 26 '05 #3
"I'm looking for a library that can search through an XML document
tree,
locate an element by attribute (ideally this can be done through
XPath), and insert an element (as its child).

Simple? Yes? ...but the code I've seen so far which does this uses
'nested for loops' for trees which are relatively shallow compared to
mine. "

Amara can easily do this using XPath (complete with predicates,
functions, etc.), without nested for loops:

http://uche.ogbuji.net/tech/4Suite/amara/

--
Uche
http://uche.ogbuji.net

Jul 29 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Stephen Ferg | last post: by
6 posts views Thread by Jeff Elkins | last post: by
5 posts views Thread by Owen | last post: by
25 posts views Thread by Tor Erik Sønvisen | last post: by
2 posts views Thread by ajikoe | last post: by
62 posts views Thread by A.M. Kuchling | last post: by
6 posts views Thread by kpd | last post: by
reply views Thread by =?utf-8?Q?Poor=20Yorick?= | last post: by
2 posts views Thread by Guillermo | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.