|
13 | 13 | from html5lib.tokenizer import HTMLTokenizer |
14 | 14 | from html5lib import treebuilders, serializer, treewalkers |
15 | 15 | from html5lib import constants |
| 16 | +from html5lib import utils |
16 | 17 |
|
17 | 18 | def parse(): |
18 | 19 | optParser = getOptParser() |
@@ -108,7 +109,14 @@ def printOutput(parser, document, opts): |
108 | 109 |
|
109 | 110 | if document is not None: |
110 | 111 | if opts.xml: |
111 | | - sys.stdout.write(document.toxml("utf-8")) |
| 112 | + tb = opts.treebuilder.lower() |
| 113 | + if tb == "dom": |
| 114 | + document.writexml(sys.stdout, encoding="utf-8") |
| 115 | + elif tb == "lxml": |
| 116 | + import lxml.etree |
| 117 | + sys.stdout.write(lxml.etree.tostring(document)) |
| 118 | + elif tb == "etree": |
| 119 | + sys.stdout.write(utils.default_etree.tostring(document)) |
112 | 120 | elif opts.tree: |
113 | 121 | if not hasattr(document,'__getitem__'): |
114 | 122 | document = [document] |
@@ -152,7 +160,7 @@ def getOptParser(): |
152 | 160 | help="Time the run using time.time (may not be accurate on all platforms, especially for short runs)") |
153 | 161 |
|
154 | 162 | parser.add_option("-b", "--treebuilder", action="store", type="string", |
155 | | - dest="treebuilder", default="simpleTree") |
| 163 | + dest="treebuilder", default="etree") |
156 | 164 |
|
157 | 165 | parser.add_option("-e", "--error", action="store_true", default=False, |
158 | 166 | dest="error", help="Print a list of parse errors") |
|
0 commit comments