Hello All!
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
<example attr="This is an attribute with several
break
lines"/>
$ cat test.py
import sys
import lxml.etree
xml = lxml.etree.parse(sys.stdin)
xml.write(sys.stdout)
print()
$ python test.py < example.xml
<example attr="This is an attribute with several break lines"/>()
$ python -c 'import lxml.etree ; print(lxml.etree.__version__)'
2.3.0
$ python -V
Python 2.6.5
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 10.04.2 LTS
Release: 10.04
Codename: lucid
$
Is there any way I can get lxml to write those line breaks back?
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-…
Thanks in advance for your help!
--
Giovanni