Parse a document fragment from a string, returning the fragment node.
(self, string)
| 616 | return self.parseString(file.read()) |
| 617 | |
| 618 | def parseString(self, string): |
| 619 | """Parse a document fragment from a string, returning the |
| 620 | fragment node.""" |
| 621 | self._source = string |
| 622 | parser = self.getParser() |
| 623 | doctype = self.originalDocument.doctype |
| 624 | ident = "" |
| 625 | if doctype: |
| 626 | subset = doctype.internalSubset or self._getDeclarations() |
| 627 | if doctype.publicId: |
| 628 | ident = ('PUBLIC "%s" "%s"' |
| 629 | % (doctype.publicId, doctype.systemId)) |
| 630 | elif doctype.systemId: |
| 631 | ident = 'SYSTEM "%s"' % doctype.systemId |
| 632 | else: |
| 633 | subset = "" |
| 634 | nsattrs = self._getNSattrs() # get ns decls from node's ancestors |
| 635 | document = _FRAGMENT_BUILDER_TEMPLATE % (ident, subset, nsattrs) |
| 636 | try: |
| 637 | parser.Parse(document, True) |
| 638 | except: |
| 639 | self.reset() |
| 640 | raise |
| 641 | fragment = self.fragment |
| 642 | self.reset() |
| 643 | ## self._parser = None |
| 644 | return fragment |
| 645 | |
| 646 | def _getDeclarations(self): |
| 647 | """Re-create the internal subset from the DocumentType node. |
no test coverage detected