|
13 | 13 | fromhtml5lib.tokenizerimportHTMLTokenizer
|
14 | 14 | fromhtml5libimporttreebuilders,serializer,treewalkers
|
15 | 15 | fromhtml5libimportconstants
|
| 16 | +fromhtml5libimportutils |
16 | 17 |
|
17 | 18 | defparse():
|
18 | 19 | optParser=getOptParser()
|
@@ -108,7 +109,14 @@ def printOutput(parser, document, opts):
|
108 | 109 |
|
109 | 110 | ifdocumentisnotNone:
|
110 | 111 | ifopts.xml:
|
111 |
| -sys.stdout.write(document.toxml("utf-8")) |
| 112 | +tb=opts.treebuilder.lower() |
| 113 | +iftb=="dom": |
| 114 | +document.writexml(sys.stdout,encoding="utf-8") |
| 115 | +eliftb=="lxml": |
| 116 | +importlxml.etree |
| 117 | +sys.stdout.write(lxml.etree.tostring(document)) |
| 118 | +eliftb=="etree": |
| 119 | +sys.stdout.write(utils.default_etree.tostring(document)) |
112 | 120 | elifopts.tree:
|
113 | 121 | ifnothasattr(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")
|
|