I'm having some problems while attempting to serialize a libxml2 object in python.
In particular, if I run :
xmlstring = cdoc.serialize('UTF-8', 1)
where cdoc is a libxml2 document created before,
I have something like this : ( on a mac - port python 2.5.6)
<?xml version="1.0" encoding="UTF-8"?>
<body>
<journal>
<journal_metadata language="en">
<full_title>Contributions of Lick Observatory</full_title>
<issn media_type="print">1750-0095</issn>
<coden>CoLic</coden>
</journal_metadata>
</journal>
</body>
while on Linux (Centos 5.6 with python 2.4 or 2.6) I have :
<?xml version="1.0" encoding="UTF-8"?>
<body>
<journal>
<journal_metadata language="en">
<full_title>
Contributions of Lick Observatory
</full_title>
<issn media_type="print">
1750-0095
</issn>
<coden>
CoLic
</coden>
</journal_metadata>
</journal>
</body>
There is a problem in the indentation of the string node.
Now I could solve this by doing :
xmlstring = cdoc.serialize('UTF-8')
without the option for the indentation, but the output format is not very readable.
Is there a way to fix the awkward indentation of the output?
I just noticed that I was running:
xmlstring = cdoc.serialize('UTF-8', 2)
and not
xmlstring = cdoc.serialize('UTF-8', 1)
This, for some reasons, on libxml2 2.6 indents also the text node and on libxml2 2.7 doesn't.
It could be a behaviour difference between the version of libxml2 on the different machines. Try upgrading the oldest one to the newer release (or a more recent one).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.