diff --git a/pypeg2/xmlast.py b/pypeg2/xmlast.py
index 0145a34..bd981c4 100644
--- a/pypeg2/xmlast.py
+++ b/pypeg2/xmlast.py
@@ -120,14 +120,15 @@ def thing2xml(thing, pretty=False, object_names=False):
tree = create_tree(thing, None, object_names)
try:
if lxml:
- return etree.tostring(tree, pretty_print=pretty)
+ txt = etree.tostring(tree, pretty_print=pretty)
except NameError:
if __debug__:
if pretty:
warnings.warn("lxml is needed for pretty printing",
ImportWarning)
etree.indent(tree)
- return etree.tostring(tree)
+ txt = etree.tostring(tree)
+ return txt
def create_thing(element, symbol_table):
diff --git a/samples/sample1.py b/samples/sample1.py
index b61de35..8f72a13 100644
--- a/samples/sample1.py
+++ b/samples/sample1.py
@@ -58,8 +58,9 @@ pyPEG contains an XML backend, too:
>>> del f[2]
>>> from pypeg2.xmlast import thing2xml
+>>> import sys
>>> xml = thing2xml(f, pretty=True)
->>> print(xml.decode()) # doctest: +ELLIPSIS
+>>> print(xml.decode(), end="") # doctest: +ELLIPSIS
@@ -68,7 +69,6 @@ pyPEG contains an XML backend, too:
do_this
do_that
-
The XML backend can read XML text and create things:
diff --git a/samples/sample2.py b/samples/sample2.py
index 4e73952..ac3f6c4 100644
--- a/samples/sample2.py
+++ b/samples/sample2.py
@@ -65,7 +65,6 @@ pyPEG contains an XML backend, too:
-
In this sample the tree contains named objects only. Then we can output object
names as tag names. Spaces in names will be translated into underscores.
@@ -82,7 +81,6 @@ names as tag names. Spaces in names will be translated into underscores.
-
"""
from __future__ import unicode_literals, print_function