[lxml-dev] blather question about XML declaration

Stefan Behnel stefan_ml at behnel.de
Thu Jul 9 22:03:28 CEST 2009


Hi,

Hervé Cauwelier wrote:
> I just wonder why lxml is producing XML declarations such as
> 
>   <?xml version='1.0' encoding='UTF-8'?>
> 
> or sometimes
> 
>   <?xml version=&apos;1.0&apos; encoding=&apos;UTF-8&apos;?>

Except that the latter is impossible to get out of the serialiser.


> instead of the most common (to my knowledge)
> 
>     <?xml version="1.0" encoding="UTF-8"?>

Why should this be more common? Just because Java doesn't understand
strings in single quotes?

The XML spec allows both:

http://www.w3.org/TR/REC-xml/#sec-prolog-dtd

and I see no reason to use '"'. It just degrades readability.


> For now I don't ask tostring() to print it, I concatenate my own with
> the tree serialisation.

Should work as long as you only serialise to UTF-8 (in which case the
declaration is optional anyway).

Stefan



More information about the lxml-dev mailing list