How to define newline in an XML ENTITY

315 views Asked by At

I am trying to define an XML ENTITY that contains only a newline character (&#10 ;). But unfortunalty this does not seem to be working:

<?xml version="1.0"?>
<!DOCTYPE my_doc [
 <!ENTITY newline "&#10;">
]>

<root attr="hello &newline; world !!!" attr1="hello &#10; world !!!" ></root>

In the example above I expect the attributes attr and attr1 to have the same value. But in case of 'attr' the entity 'newline' is replaced with a space by parsers:

attr => hello   world !!!
attr1 => hello
 world !!!

I am using python to parse this, but I do not think that this is relevant:

import xml.etree.ElementTree as ET

data_as_string = """<?xml version="1.0"?>
<!DOCTYPE my_doc [
 <!ENTITY newline "&#10;">
]>

<root attr="hello &newline; world !!!" attr1="hello &#10; world !!!" ></root>
"""

root = ET.fromstring(data_as_string)

print root
print root.attrib

for k,v in root.attrib.items():
    print "%s => %s" % (k, v)

Does know a solution for this?

Thanks, Gerald

0

There are 0 answers