(self, source, parser=None)
Load external XML document into element tree.

        *source* is a file name or file object, *parser* is an optional parser
        instance that defaults to XMLParser.

        ParseError is raised if the parser fails to parse the document.

        Returns the root element of the given source document.
Load external XML document into element tree.
Load external XML document into element tree .
def parse(self, source, parser=None):
        """Load external XML document into element tree.

        *source* is a file name or file object, *parser* is an optional parser
        instance that defaults to XMLParser.

        ParseError is raised if the parser fails to parse the document.

        Returns the root element of the given source document.

        """
        close_source = False
        if not hasattr(source, "read"):
            source = open(source, "rb")
            close_source = True
        try:
            if parser is None:
                # If no parser was specified, create a default XMLParser
                parser = XMLParser()
                if hasattr(parser, '_parse_whole'):
                    # The default XMLParser, when it comes from an accelerator,
                    # can define an internal _parse_whole API for efficiency.
                    # It can be used to parse the whole source without feeding
                    # it with chunks.
                    self._root = parser._parse_whole(source)
                    return self._root
            while True:
                data = source.read(65536)
                if not data:
                    break
                parser.feed(data)
            self._root = parser.close()
            return self._root
        finally:
            if close_source:
                source.close()
def parse ( self , source , parser = None ) : close_source = False if not hasattr ( source , "read" ) : source = open ( source , "rb" ) close_source = True try : if parser is None : # If no parser was specified, create a default XMLParser parser = XMLParser ( ) if hasattr ( parser , '_parse_whole' ) : # The default XMLParser, when it comes from an accelerator, # can define an internal _parse_whole API for efficiency. # It can be used to parse the whole source without feeding # it with chunks. self . _root = parser . _parse_whole ( source ) return self . _root while True : data = source . read ( 65536 ) if not data : break parser . feed ( data ) self . _root = parser . close ( ) return self . _root finally : if close_source : source . close ( )