LXML -- Would it be Wise?
I have a question about whether the community at large has or is willing to install a library.Would it be wise to use LXML? Would it be something that most people have, or wouldn't have a problem installing?
It seems to me that it's fairly widely available for *NIX, but I'm not sure as far as Windows or OS X.
For those who aren't familiar, LXML is a Pythonic wrapper around LibXML2, written in C. The main issue I have is that even if I can bundle it, it is platform-specific.
Or, if there is a pure-python XML library with decent performance that I can bundle in, I'd love to hear about it. :-)
I'm asking because I'd like to use XML for my data this time around, but I don't necessarily want to write my own parser.
Anywho, again, any thoughts about LXML, or pure-python parsers are welcome! ^_^
(log in to comment)
Comments
I didn't know Python had built-in XML support! That's probably what I'll use, then. I don't need anything fancy.(I confess, I'm not even sure what XSLT is ^^;)
I'll have to look through the docs for that, thanks!
@adam:
I'll keep that in mind :-)
Thanks for the info
--Akake
To add to what's been said, you mentioned in your first message that you're looking for something with "decent performance". The raw xml.etree.ElementTree module is a little bit on the slow side, but there's a C implementation of it available as xml.etree.cElementTree (it's mentioned once in the documentation, but it's quite easy to overlook). That should provide more than enough speed for your needs. And, of course, if you don't much like the element tree API, there are SAX and DOM parsers available as well. I highly recommend a look at section 20 of the Python Library Reference - there should be something there to fit most needs.
However, I'd also ask that you reconsider whether you actually need XML support. Python makes it quite easy to read and write data structures as Python code which is, in my opinion, a lot easier for a human to handle, as well as being simpler to code for. XML is only really advantageous as an interchange format between different programs - if you're not planning on using external editors, it can be much easier to just write your data structures as Python dictionaries, etc. Finally, if you're just looking at data which is to be loaded and saved by your game, and not intended for human consumption, Python's pickling libraries can make serialisation a doddle.
That's a good idea. I think Python dicts would be better for me. :-)
Well, that and xml.etree.ElementTree doesn't seem to be able to pretty-print things, which would be nice for me to have.
Thanks for the idea
---Akake
Chard on 2009/07/31 11:18:
Hi, Akake. Nice to see you back again!
Regarding lxml: unless you actually want to use lxml XSLT features I would strongly recommend using Python's built in XML modules. The ElementTree interface in xml.etree.ElementTree is quite straightforward.
Having previously wanted good cross platform XSLT support in Python I can confirm that lxml is an excellent choice for that problem. But if you just need to parse some XML it would be best not to have the extra dependency.
Good luck!