示例#1
0
    def _parseStream(self, fp, file, absUrl, internalOwnerDoc):
        reader = Reader(validate=0, keepAllWs=0, catName=None,
                        saxHandlerClass=ExtXmlDomGenerator, parser=None)
        reader.handler.extinit(file, absUrl, reader.parser, self)
        if internalOwnerDoc is not None:
            ownerDoc = internalOwnerDoc.document
        else:
            ownerDoc = None
        try:
            tree = reader.fromStream(fp, ownerDoc)
            fp.close()
        except SAXParseException as errInst:
            fp.close()
            raise GenXmlIfError(
                "%s: SAXParseException: %s" %
                (file, str(errInst)))

        treeWrapper = reader.handler.treeWrapper

        # XInclude support
        if self.processXInclude:
            if internalOwnerDoc is None:
                internalOwnerDoc = treeWrapper.getTree()
            self.xInclude(treeWrapper.getRootNode(), absUrl, internalOwnerDoc)

        return treeWrapper
示例#2
0
 def _parseStream (self, fp, file, absUrl, internalOwnerDoc):
     reader = Reader(validate=0, keepAllWs=0, catName=None, 
                     saxHandlerClass=ExtXmlDomGenerator, parser=None)
     reader.handler.extinit(file, absUrl, reader.parser, self)
     if internalOwnerDoc != None: 
         ownerDoc = internalOwnerDoc.document
     else:
         ownerDoc = None
     try:
         tree = reader.fromStream(fp, ownerDoc)
         fp.close()
     except SAXParseException, errInst:
         fp.close()
         raise GenXmlIfError, "%s: SAXParseException: %s" %(file, str(errInst))
示例#3
0
 def _parseStream (self, fp, file, absUrl, internalOwnerDoc):
     reader = Reader(validate=0, keepAllWs=0, catName=None, 
                     saxHandlerClass=ExtXmlDomGenerator, parser=None)
     reader.handler.extinit(file, absUrl, reader.parser, self)
     if internalOwnerDoc != None: 
         ownerDoc = internalOwnerDoc.document
     else:
         ownerDoc = None
     try:
         tree = reader.fromStream(fp, ownerDoc)
         fp.close()
     except SAXParseException, errInst:
         fp.close()
         raise GenXmlIfError, "%s: SAXParseException: %s" %(file, str(errInst))
示例#4
0
 def fromSax(cls, input, sax_parser):
     "Build a MathDOM from input using sax_parser."
     dom_builder = Reader(parser=sax_parser)
     return cls( dom_builder.fromString(input) )
示例#5
0
 def fromSax(cls, input, sax_parser):
     "Build a MathDOM from input using sax_parser."
     dom_builder = Reader(parser=sax_parser)
     return cls(dom_builder.fromString(input))
示例#6
0
 def __build_sax_reader(input_type):
     if input_type == 'mathml':
         return Reader()
     else:
         sax_class = SaxTerm.for_input_type(input_type)
         return Reader(parser=sax_class())
示例#7
0
    from parser import SaxHandler
    handler = SaxHandler(normalize_space=0, include_comment=1)
    # do not perform Namespace processing 
    parser.setFeature(feature_namespaces, 0)
    # add lexical handler for comments,  entities, dtd and cdata
    parser.setProperty(property_lexical_handler, handler)
    parser.setContentHandler(handler)
    parser.parse(root)
    return handler.get_tree()


if __name__ == '__main__':
    from xml.dom.ext import StripXml, PrettyPrint
    from xml.dom.ext.reader.Sax2 import Reader
    import sys
    reader = Reader()
    file = open(sys.argv[1],'r')
    fragment = reader.fromStream(file)
    d = StripXml(fragment)
    file.close()
    tree = tree_from_dom(d)
    file = open(sys.argv[2],'r')
    fragment = reader.fromStream(file)
    d = StripXml(fragment)
    file.close()
    tree2 = tree_from_dom(d)
    from objects import repr
    print 'Source tree', repr(tree)
    print 'Destination tree', repr(tree2)
    #from ezs import EzsCorrector
    #strategy = EzsCorrector()
示例#8
0
    from xmldiff.parser import SaxHandler
    handler = SaxHandler(normalize_space=0, include_comment=1)
    # do not perform Namespace processing
    parser.setFeature(feature_namespaces, 0)
    # add lexical handler for comments,  entities, dtd and cdata
    parser.setProperty(property_lexical_handler, handler)
    parser.setContentHandler(handler)
    parser.parse(root)
    return handler.get_tree()


if __name__ == '__main__':
    from xml.dom.ext import StripXml, PrettyPrint
    from xml.dom.ext.reader.Sax2 import Reader
    import sys
    reader = Reader()
    file = open(sys.argv[1], 'r')
    fragment = reader.fromStream(file)
    d = StripXml(fragment)
    file.close()
    tree = tree_from_dom(d)
    file = open(sys.argv[2], 'r')
    fragment = reader.fromStream(file)
    d = StripXml(fragment)
    file.close()
    tree2 = tree_from_dom(d)
    from xmldiff.objects import repr
    print 'Source tree', repr(tree)
    print 'Destination tree', repr(tree2)
    #from ezs import EzsCorrector
    #strategy = EzsCorrector()