Mercurial > bitten > bitten-test
changeset 338:808afc6850c1
Include CDATA in representation of parsed XML. Closes #99. Thanks to Sven Reimers for the report and patch.
author | cmlenz |
---|---|
date | Mon, 13 Feb 2006 12:21:15 +0000 |
parents | 5c0625957185 |
children | 6469c692c603 |
files | bitten/util/xmlio.py |
diffstat | 1 files changed, 11 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/bitten/util/xmlio.py +++ b/bitten/util/xmlio.py @@ -228,6 +228,13 @@ >>> xml.attr['foo'] = 'bar' >>> print xml <root foo="bar"/> + + CDATA sections are included in the text content of the element returned by + `gettext()`: + + >>> xml = parse('<root>foo<![CDATA[ <bar> ]]>baz</root>') + >>> xml.gettext() + 'foo <bar> baz' """ __slots__ = ['_node', 'attr'] @@ -273,11 +280,12 @@ def gettext(self): """Return the text content of this element. - This concatenates the values of all text nodes that are immediate - children of this element. + This concatenates the values of all text and CDATA nodes that are + immediate children of this element. """ return ''.join([c.nodeValue.encode('utf-8') - for c in self._node.childNodes if c.nodeType == 3]) + for c in self._node.childNodes + if c.nodeType in (3, 4)]) def write(self, out, newlines=False): """Serializes the element and writes the XML to the given output