| 47 | return self.toprettyxml("", "", encoding, standalone) |
| 48 | |
| 49 | def toprettyxml(self, indent="\t", newl="\n", encoding=None, |
| 50 | standalone=None): |
| 51 | if encoding is None: |
| 52 | writer = io.StringIO() |
| 53 | else: |
| 54 | writer = io.TextIOWrapper(io.BytesIO(), |
| 55 | encoding=encoding, |
| 56 | errors="xmlcharrefreplace", |
| 57 | newline='\n') |
| 58 | if self.nodeType == Node.DOCUMENT_NODE: |
| 59 | # Can pass encoding only to document, to put it into XML header |
| 60 | self.writexml(writer, "", indent, newl, encoding, standalone) |
| 61 | else: |
| 62 | self.writexml(writer, "", indent, newl) |
| 63 | if encoding is None: |
| 64 | return writer.getvalue() |
| 65 | else: |
| 66 | return writer.detach().getvalue() |
| 67 | |
| 68 | def hasChildNodes(self): |
| 69 | return bool(self.childNodes) |