PDA

View Full Version : A good Python book for manipulating XML!



rivalslayer
July 17th, 2008, 05:51 AM
Can anyone suggest me a good book for manipulating XML with Python? Need it!:confused:

ceclauson
July 17th, 2008, 06:18 AM
I don't know if this is helpful, but Python supports DOM (document-object model), which is a language-independent API for working with XML.

This means that if you understand how DOM works, it works the same in any language, so you should be able to use it in any language. For instance, I first used DOM in Java, and have since been able to apply it in C++ and Python.

I googled a page with an introduction:
http://www.boddie.org.uk/python/XML_intro.html

I hope this was helpful.

-Cooper

LaRoza
July 17th, 2008, 06:29 AM
http://docs.python.org/lib/markup.html

Wybiral
July 17th, 2008, 06:46 AM
Use elementtree (http://docs.python.org/lib/module-xml.etree.ElementTree.html), it's in the standard library and it's the most "pythonic" way to go about it.

LaRoza
July 17th, 2008, 07:45 AM
Use elementtree (http://docs.python.org/lib/module-xml.etree.ElementTree.html), it's in the standard library and it's the most "pythonic" way to go about it.

Use the DOM because it is the most standard way...

ghostdog74
July 17th, 2008, 09:18 AM
look for Python & XML here (http://slav0nic.org.ua/static/books/python/) before its gone

babacan
July 17th, 2008, 02:41 PM
look for Python & XML here (http://slav0nic.org.ua/static/books/python/) before its gone

strong warez abilities lol

pmasiar
July 17th, 2008, 04:06 PM
Another vote for ElementTree. It's so good it was included in core libraries (since 2.5).

Compared to SAX or DOM, which are very static-language oriented, ET builds dictionary of dictionaries with elements and attributes - much simpler to comprehend and use than any of the "standard" solutions.

Wybiral
July 17th, 2008, 04:10 PM
Use the DOM because it is the most standard way...

Standard, for other languages, but for Python ElementTree is much more commonly used these days.

ghostdog74
July 17th, 2008, 04:16 PM
strong warez abilities lol

just simple google search. Nothing fancy.

LaRoza
July 17th, 2008, 06:20 PM
Standard, for other languages, but for Python ElementTree is much more commonly used these days.

I was merely pointing out there is no single "better" option.

I use the DOM because it is included in ECMA-262 R2, and I use that a lot.

xelapond
July 17th, 2008, 06:33 PM
Another vote for ElementTree. I needed a fast way to parse xml, and I was able to figure out a good amount of it in about 10 minutes. Its really simple, but very powerful at the same time(like Python!)

All the best,

Alex

Wybiral
July 17th, 2008, 08:42 PM
I was merely pointing out there is no single "better" option.

I use the DOM because it is included in ECMA-262 R2, and I use that a lot.

But the OP was asking about Python, and the Python idiom is to use ElementTree instead of the DOM module... It's just more common and Pythonic (not to mention more convenient). And if it's HTML instead of standard XML, the best to use is BeautifulSoup. And yes, it is "better" than the other XML parsers (for parsing HTML) and provides an ElementTree-like interface.

LaRoza
July 17th, 2008, 09:59 PM
But the OP was asking about Python, and the Python idiom is to use ElementTree instead of the DOM module... It's just more common and Pythonic (not to mention more convenient). And if it's HTML instead of standard XML, the best to use is BeautifulSoup. And yes, it is "better" than the other XML parsers (for parsing HTML) and provides an ElementTree-like interface.

I know... I said that is why I used it ;)

The DOM isn't hard to use, so these other options must be extremely easy to use.