Use et to read in a xml file, or string, into a Element object.

    :param filename: File to parse.
    :return: lxml._elementTree object or None
516090
def read_xml(filename):
    
    parser = et.XMLParser(remove_blank_text=True)
    isfile=False
    try:
        isfile = os.path.exists(filename)
    except ValueError as e:
        if 'path too long for Windows' in str(e):
            pass
        else:
            raise
    try:
        if isfile:
            return et.parse(filename, parser)
        else:
            r = et.fromstring(filename, parser)
            return r.getroottree()
    except IOError:
        log.exception('unable to open file [[}]'.format(filename))
    except et.XMLSyntaxError:
        log.exception('unable to parse XML [{}]'.format(filename))
        return None
    return None
153605
def htmlCtxtReadFile(self, filename, encoding, options):
        
        ret = libxml2mod.htmlCtxtReadFile(self._o, filename, encoding, options)
        if ret is None:raise treeError('htmlCtxtReadFile() failed')
        __tmp = xmlDoc(_obj=ret)
        return __tmp
844405
def createFileParserCtxt(filename):
    
    ret = libxml2mod.xmlCreateFileParserCtxt(filename)
    if ret is None:raise parserError('xmlCreateFileParserCtxt() failed')
    return parserCtxt(_obj=ret)
96253
def fromxml(node):
        """"""
        if not isinstance(node,ElementTree._Element): #pylint: disable=protected-access
            node = parsexmlstring(node)
        if node.tag.lower() != 'meta':
            raise Exception("Expected meta tag but got '" + node.tag + "' instead")

        key = node.attrib['id']
        if node.text:
            value = node.text
        else:
            value = None
        operator = 'set'
        if 'operator' in node.attrib:
            operator= node.attrib['operator']
        if operator == 'set':
            cls = SetMetaField
        elif operator == 'unset':
            cls = UnsetMetaField
        elif operator == 'copy':
            cls = CopyMetaField
        elif operator == 'parameter':
            cls = ParameterMetaField
        return cls(key, value)
181143
def from_file(filename):
        

        spec = Spec()
        with open(filename, "r", encoding="utf-8") as f:
            parse_context = {"current_subpackage": None}
            for line in f:
                spec, parse_context = _parse(spec, parse_context, line)
        return spec
811634
def load(self, filename):
        
        #if LXE and self.mode != Mode.XPATH:
        #    #workaround for xml:id problem (disabled)
        #    #f = open(filename)
        #    #s = f.read().replace(' xml:id=', ' id=')
        #    #f.close()
        #    self.tree = ElementTree.parse(filename)
        #else:
        self.tree = xmltreefromfile(filename)
        self.parsexml(self.tree.getroot())
        if self.mode != Mode.XPATH:
            #XML Tree is now obsolete (only needed when partially loaded for xpath queries)
            self.tree = None
492171
def get_element(text_or_tree_or_element):
    
    if isinstance(text_or_tree_or_element, ET.Element):
        return text_or_tree_or_element
    elif isinstance(text_or_tree_or_element, ET.ElementTree):
        return text_or_tree_or_element.getroot()
    elif isinstance(text_or_tree_or_element, (unicode, bytes)):
        return ET.fromstring(text_or_tree_or_element)
    else:
        return ET.parse(text_or_tree_or_element).getroot()
852213
def convert_odt_to_text(filename: str = None,
                        blob: bytes = None,
                        config: TextProcessingConfig = _DEFAULT_CONFIG) -> str:
    
    # We can't use exactly the same method as for DOCX files, using docx:
    # sometimes that works, but sometimes it falls over with:
    # KeyError: "There is no item named 'word/document.xml' in the archive"
    with get_filelikeobject(filename, blob) as fp:
        z = zipfile.ZipFile(fp)
        tree = ElementTree.fromstring(z.read('content.xml'))
        # ... may raise zipfile.BadZipfile
        textlist = []  # type: List[str]
        for element in tree.iter():
            if element.text:
                textlist.append(element.text.strip())
    return '\n\n'.join(textlist)
542353
def fromFile(filename):
        
        xdata = None
        ydata = None

        # try parsing an XML file
        try:
            xdata = ElementTree.parse(filename).getroot()
        except StandardError:
            xdata = None

        if xdata is None:
            # try parsing a yaml file
            if yaml:
                with open(filename, 'r') as f:
                    text = f.read()

                try:
                    ydata = yaml.load(text)
                except StandardError:
                    return None
            else:
                log.warning('Could not process yaml builder!')

        # load a yaml definition
        if type(ydata) == dict:
            typ = ydata.get('type')
            module = ydata.get('module')
            builder = Builder.plugin(typ, module)
            if builder:
                return builder.fromYaml(ydata, os.path.dirname(filename))
            else:
                log.warning('Could not find builder: {0}'.format(typ))

        # load an xml definition
        elif xdata is not None:
            typ = xdata.get('type')
            module = xdata.get('module')
            builder = Builder.plugin(typ, module)
            if builder:
                return builder.fromXml(xdata, os.path.dirname(filename))
            else:
                log.warning('Could not find builder: {0}'.format(typ))

        return None
348399
def Element(cls, s, *args):
        """"""
        sargs = []
        for arg in args:
            if type(arg) == etree._Element:
                sargs.append(etree.tounicode(arg))
            else:
                sargs.append(arg)
        if type(s) == etree._Element:
            t = etree.tounicode(s)
        else:
            t = s
        if len(args) == 0:
            return XML.fromstring(t)
        else:
            return XML.fromstring(t % tuple(sargs))
142410
def load(filename):
        
        # parse a zipped file
        if zipfile.is_zipfile(filename):
            zfile = zipfile.ZipFile(filename, 'r')
            try:
                xml = ElementTree.fromstring(zfile.read('scaffold.xml'))
            except StandardError:
                logger.exception('Failed to load scaffold: {0}'.format(filename))
                zfile.close()
                return None
            zfile.close()

        # parse a standard xml file
        else:
            try:
                xml = ElementTree.parse(filename).getroot()
            except StandardError:
                logger.exception('Failed to load scaffold: {0}'.format(filename))
                return None

        # generate a scaffold
        scaffold = Scaffold()
        scaffold.setSource(filename)
        scaffold.setName(xml.get('name', 'Missing'))
        scaffold.setGroup(xml.get('group', 'Default'))
        scaffold.setLanguage(xml.get('lang', 'Python'))
        scaffold.setIcon(xml.get('icon', ''))

        # define properties
        xprops = xml.find('properties')
        if xprops is not None:
            for xprop in xprops:
                scaffold.addProperty(Property.fromXml(xprop))

        return scaffold
657801
def parseFilename(filename):
    

    # Parse out any extension specified in filename
    _indx = filename.find('[')
    if _indx > 0:
        # Read extension name provided
        _fname = filename[:_indx]
        _extn = filename[_indx + 1:-1]
    else:
        _fname = filename
        _extn = None

    return _fname, _extn
423456
def readFile(filename, encoding, options):
    
    ret = libxml2mod.xmlReadFile(filename, encoding, options)
    if ret is None:raise treeError('xmlReadFile() failed')
    return xmlDoc(_obj=ret)
1245892
def load(source):
    
    parser = get_xml_parser()
    return etree.parse(source, parser=parser).getroot()
61821
public static XNElement parseXML(String fileName) throws IOException, XMLStreamException {
        try (InputStream in = new FileInputStream(fileName)) {
            return parseXML(in);
        }
    }
73160
def xml_open(filename, expected_root=None):
    """"""

    # Is the file a zip (.twbx or .tdsx)
    if zipfile.is_zipfile(filename):
        tree = get_xml_from_archive(filename)
    else:
        tree = ET.parse(filename)

    # Is the file a supported version
    tree_root = tree.getroot()
    file_version = Version(tree_root.attrib.get('version', '0.0'))

    if file_version < MIN_SUPPORTED_VERSION:
        raise TableauVersionNotSupportedException(file_version)

    # Does the root tag match the object type (workbook or data source)
    if expected_root and (expected_root != tree_root.tag):
        raise TableauInvalidFileException(
            "'{}'' is not a valid '{}' file".format(filename, expected_root))

    return tree
538366
def parseEntity(filename):
    
    ret = libxml2mod.xmlParseEntity(filename)
    if ret is None:raise parserError('xmlParseEntity() failed')
    return xmlDoc(_obj=ret)