XLM prolgoue

Sébastien Boisgérault Sebastien.Boisgerault at gmail.com
Wed Jan 17 14:22:05 EST 2007


fscked wrote:
> How do I go about creating the XML prologue like I want it to be?

> Specifically, I am trying to add encoding and some namespace stuff.

The XML declaration and the DTD that may appear in the prolog are
optional.

[22]   	prolog ::= XMLDecl? Misc* (doctypedecl  Misc*)?
[23]   	XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'

If your encoding is UTF-8 (or ASCII ...) you don't need an XML
declaration. Otherwise everything depends on the XML lib you
use.  For ElementTree, `tostring(elt, "ISO-8859-1")` for example
will automatically include the right declaration at the beginning
of your xml string ...

There is no namespace information inside the prolog. Such
"stuff" may appear inside the root element. Again, RTFM of
your specific XML lib :) For ElementTree, see
http://effbot.org/zone/element.htm#xml-namespaces

Cheers,

SB




More information about the Python-list mailing list