SAX parse XML text. @param file: Parse a python I{file-like} object. @type file: I{file-like} object. @param string: Parse string XML. @type string: str
(self, file=None, string=None)
| 113 | return (p, h) |
| 114 | |
| 115 | def parse(self, file=None, string=None): |
| 116 | """ |
| 117 | SAX parse XML text. |
| 118 | @param file: Parse a python I{file-like} object. |
| 119 | @type file: I{file-like} object. |
| 120 | @param string: Parse string XML. |
| 121 | @type string: str |
| 122 | """ |
| 123 | timer = metrics.Timer() |
| 124 | timer.start() |
| 125 | sax, handler = self.saxparser() |
| 126 | if file is not None: |
| 127 | sax.parse(file) |
| 128 | timer.stop() |
| 129 | metrics.log.debug('sax (%s) duration: %s', file, timer) |
| 130 | return handler.nodes[0] |
| 131 | if string is not None: |
| 132 | if isinstance(string, str): |
| 133 | string = string.encode() |
| 134 | parseString(string, handler) |
| 135 | timer.stop() |
| 136 | metrics.log.debug('%s\nsax duration: %s', string, timer) |
| 137 | return handler.nodes[0] |