xml.dom.minidom losing the XML document type attribute

J

Johannes Bauer

Hello group,

when I read in a XML document with the xml.dom.minidom parser and write
it out again, an attribute is lost:

Input:

<?xml version="1.0" encoding="utf-8" ?>
[...]

Output:
<?xml version="1.0" ?>

How can I fix this? Python is Python 3.0rc2 (r30rc2:67114, Nov 16 2008,
15:24:36)

Kind regards,
Johannes
 
S

Stefan Behnel

Johannes said:
when I read in a XML document with the xml.dom.minidom parser and write
it out again, an attribute is lost:

Input:

<?xml version="1.0" encoding="utf-8" ?>
[...]

Output:
<?xml version="1.0" ?>

How can I fix this?

You don't have to. UTF-8 is the default encoding, so the two lines above
are equivalent.

Stefan
 
J

Johannes Bauer

Stefan said:
Johannes said:
when I read in a XML document with the xml.dom.minidom parser and write
it out again, an attribute is lost:

Input:

<?xml version="1.0" encoding="utf-8" ?>
[...]

Output:
<?xml version="1.0" ?>

How can I fix this?

You don't have to. UTF-8 is the default encoding, so the two lines above
are equivalent.

Can I somehow force Python to generate it anyways? I have software which
complains if an explicit encoding is missing...

Kind regards,
Johannes
 
S

Stefan Behnel

Johannes said:
Stefan said:
Johannes said:
when I read in a XML document with the xml.dom.minidom parser and write
it out again, an attribute is lost:

Input:

<?xml version="1.0" encoding="utf-8" ?>
[...]

Output:
<?xml version="1.0" ?>

How can I fix this?
You don't have to. UTF-8 is the default encoding, so the two lines above
are equivalent.

Can I somehow force Python to generate it anyways?

Did you try passing encoding='UTF-8' on serialisation?

I have software which
complains if an explicit encoding is missing...

Well, to parse XML, it's best to use an XML parser. ;)

Stefan
 
J

Johannes Bauer

Stefan said:
Did you try passing encoding='UTF-8' on serialisation?

Uhm... nope - how can I do that?
Well, to parse XML, it's best to use an XML parser. ;)

Well, I'm not speaking about my software :) Actually it's Gnucash which
complains if the tag is not explicitly set. This is because they
appearently had a ancient version which did not specify the charset, but
used a different one than UTF-8. Kind of annoying, but fixing my XML
output seems to be easier than convincing the Gnucash people to change
their software :)

Kind regards,
Johannes
 
S

Stefan Behnel

Johannes said:
Uhm... nope - how can I do that?

Well, depends on what your code currently does.

Maybe you could use something like

doc.xmlwrite(..., encoding='UTF-8')

Stefan
 
D

David Robinow

Well, I'm not speaking about my software :) Actually it's Gnucash which
complains if the tag is not explicitly set. This is because they
appearently had a ancient version which did not specify the charset, but
used a different one than UTF-8. Kind of annoying, but fixing my XML
output seems to be easier than convincing the Gnucash people to change
their software :)

from the GnuCash web page:
How can you help?

Testing: Test it and help us discover all bugs that might show up in
there. Please enter each and every bug into bugzilla.

Translating: The new release comes with some new translation strings.
If you consider contributing a translation, we invite you to test this
release already. A string freeze will be announced in one of the later
2.3.x releases. Please check
http://wiki.gnucash.org/wiki/Translation_Status for updates on this.

We would like to encourage people to test this and any further
releases as much as possible and submit bug reports in order that we
can polish GnuCash to be as stable as possible for the 2.4.0 release
in a few weeks. Then post any bugs you find to bugzilla
(http://bugzilla.gnome.org/enter_bug.cgi?product=GnuCash)
 
J

Johannes Bauer

David said:
from the GnuCash web page:
How can you help?

Well, it's not as if it's a bug of GnuCash. This is a deliberate
decision used to ensure backwards compatibility with older versions of
GnuCash. So a bug report wouldn't really do good anything at all
("Please remove your backwards compatibility feature, it annoys me and I
only use recent versions anyways").

Kind regards,
Johannes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,732
Latest member
ArronPalin

Latest Threads

Top