On 18/01/2011, at 3:25 PM, Robert Smit wrote:
Hi All
I have a python / XML problem that I was hoping someone could help
me with.
This url is where I'm blogging about what I'm doing if your
interested but
basically I'm using the python xml.etree, which seams to be the
default XML
module but not the only one there in my default installation.
http://robert-smit.info/index.php/blog/52-pythonlearn.html
Reading the EML file is fine and saving the XML to a file again,
also fine. But it
has 2 issues:-
1) seams to be droping the XML definition at the start ie.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE kvtml PUBLIC "kvtml2.dtd" "http://edu.kde.org/kvtml/kvtml2.dtd
">
is not in the output file. What am I missing?
Not sure if this only works in lxml etree or not
http://codespeak.net/lxml/tutorial.html#serialisation
>>> print(etree.tostring(root, xml_declaration=True)) <?xml
version='1.0' encoding='ASCII'?> <root><a><b/></a></root>
2) The original file is multi-lingal and has rusian and arabic
character sets
which read correctly in KDEs text editor but after saving to the
output file
only show as character codes.
Sounds like you need to manage the file encoding. Ensure your original
text is decoded to unicode and then ensure your final output is
encoded to something like utf or whatever encoding you think you need.
2a) at one stage I have seen errors related to var/function
expecting str and
getting unicode. this is clearly related to prob 2 just thought I'd
mention it
as well.
Should I be using a different xml module?
Is there a difference between xml.etree and lxml.etree modules?
I generally use lxml which has a nice full set of apis, including
compatibility with the etree api and wrapping beautifulsoup parser.
The docs tell you whats different.
http://codespeak.net/lxml/
It can be a little painful to install depending on your platform.
I use buildout for all my python code and so I use this recipe takes
care of compiling it for me or all platforms.
http://pypi.python.org/pypi/z3c.recipe.staticlxml
You might also want to post python related questions to either the
sydneypython users group sydneypyt...@googlegroups.com or the python...@python.net
list.
Is there an option I should be enabling in the module I'm using?
Thanks for any help you can give me
Robert
-----------------------------------------
-----------------------------------------
_______________________________________________
coders mailing list
coders@slug.org.au
http://lists.slug.org.au/listinfo/coders
_______________________________________________
coders mailing list
coders@slug.org.au
http://lists.slug.org.au/listinfo/coders