From stefan_ml at behnel.de Tue Mar 1 07:20:22 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 01 Mar 2011 07:20:22 +0100 Subject: [lxml-dev] [lxml] Adding top-level comments to an ElementTree object In-Reply-To: References: Message-ID: <4D6C9026.6030209@behnel.de> Tyler Erickson, 28.02.2011 21:14: > How do you add top-level comments to an ElementTree object? http://lxml.de/api/lxml.etree._Element-class.html#addprevious Stefan From stefan_ml at behnel.de Tue Mar 1 12:48:41 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 01 Mar 2011 12:48:41 +0100 Subject: [lxml-dev] [lxml] availability of lxml 2.3 windows binaries In-Reply-To: References: <4D6CBCC1.1030808@gmail.com> Message-ID: <4D6CDD19.4060105@behnel.de> Sidnei da Silva, 01.03.2011 12:28: > On Tue, Mar 1, 2011 at 6:30 AM, Adam GROSZER wrote: >> Are those files somewhere in the lxml repo? >> If not, would be great to have them close to the source... > > Indeed. It would be great if someone could pick that up. Well, lxml is an open source project. I take patches. Could someone else try these scripts to see how hard it is to get them working on a different machine? Stefan From tylerickson at gmail.com Tue Mar 1 20:18:39 2011 From: tylerickson at gmail.com (Tyler Erickson) Date: Tue, 1 Mar 2011 12:18:39 -0700 Subject: [lxml-dev] [lxml] Adding top-level comments to an ElementTree object In-Reply-To: <4D6C9026.6030209@behnel.de> References: <4D6C9026.6030209@behnel.de> Message-ID: Stefan, Thanks, that was what I was looking for... - Tyler $ python Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from lxml import etree >>> from lxml.builder import E >>> # construct an Element class using the E-factory ... element = ( ... E.root( ... E.a('eggs'), ... ) ... ) >>> element.addprevious(etree.Comment('top level comment')) >>> print etree.tostring(etree.ElementTree(element)) eggs On Mon, Feb 28, 2011 at 11:20 PM, Stefan Behnel wrote: > Tyler Erickson, 28.02.2011 21:14: > >> How do you add top-level comments to an ElementTree object? >> > > http://lxml.de/api/lxml.etree._Element-class.html#addprevious > > Stefan > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/lxml-dev/attachments/20110301/f9a015a9/attachment.htm From stefan_ml at behnel.de Fri Mar 4 16:39:21 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 04 Mar 2011 16:39:21 +0100 Subject: [lxml-dev] [lxml] lxml removes line breaks from XML attributes In-Reply-To: References: Message-ID: <4D7107A9.7010902@behnel.de> Giovanni Torres, 04.03.2011 10:35: > Some of you might not be happy with my question. But, I'm dealing with > an XML file that has line breaks in XML attributes. I use lxml to > parse the file, run some XPath queries, make changes to it and write > it back. Unfortunately, lxml removes the line breaks from the > attributes. > > Here is what I mean more clearly: > > $ cat example.xml > > > $ cat test.py > > import sys > import lxml.etree > > xml = lxml.etree.parse(sys.stdin) > xml.write(sys.stdout) > print() > > $ python test.py< example.xml > () This is called "attribute-value normalisation" in the XML spec: http://www.w3.org/TR/REC-xml/#AVNormalize > Is there any way I can get lxml to write those line breaks back? You should escape the newlines in attribute values as presented in the spec, i.e. use "#xA;" etc. > I'm actually not sure if they are even legal. But, they seem to be > according to this: > > http://stackoverflow.com/questions/449627/are-line-breaks-in-xml-attribute-values-valid Well, technically, the example is "legal", as stated, but it doesn't give the requested result. Stefan