Re: [lxml-dev] newb: How to create a simple xml file?
Ram Peters wrote:
I needed to know how to create xml headers, using lxml like this: <?xml version="1.0" encoding="UTF-8"?> ?
Hmm, why? By specification, there is no difference between this <?xml version="1.0" encoding="UTF-8"?> <weatherNow xmlns="http://example.com/weatherNow/"> <temperature>57</temperature> <pressure>29.97</pressure> <pressureChange>rising</pressureChange> </weatherNow> and this <weatherNow xmlns="http://example.com/weatherNow/"> <temperature>57</temperature> <pressure>29.97</pressure> <pressureChange>rising</pressureChange> </weatherNow> However, if you really need to output the header, pass the "xml_declaration=True" keyword argument to tostring() or write(). Hope it helps, Stefan
On 29/03/07, Stefan Behnel <stefan_ml@behnel.de> wrote:
How to create a simple xml file like the one below in lxml?
<?xml version="1.0" encoding="UTF-8"?> <weatherNow xmlns="http://example.com/weatherNow/"> <temperature>57</temperature> <pressure>29.97</pressure> <pressureChange>rising</pressureChange> </weatherNow>
Hi,
what about reading some of the documentation?
http://codespeak.net/lxml/#documentation
Given your target XML above (which is data style, not document style XML), you might especially be interested in the objectify API.
http://codespeak.net/lxml/objectify.html http://codespeak.net/lxml/objectify.html#creating-objectify-trees
Hope it helps, Stefan
participants (1)
-
Stefan Behnel