Read generated XML file.

        :param xml_file: path to xml file
        :type xml_file: str

        :rtype: declarations tree
503422
def read_xml_file(self, xml_file):
        

        assert self.__config is not None

        ffname = self.__file_full_name(xml_file)
        self.logger.debug("Reading xml file: [%s]", xml_file)
        decls = self.__dcache.cached_value(ffname, self.__config)
        if not decls:
            self.logger.debug("File has not been found in cache, parsing...")
            decls, _ = self.__parse_xml_file(ffname)
            self.__dcache.update(ffname, self.__config, decls, [])
        else:
            self.logger.debug(
                "File has not been changed, reading declarations from cache.")

        return decls
1289300
def read(self, f):
        
        self.clear_document()

        g = Graph()
        g.parse(f, format='xml')

        for n in g.namespaces():
            ns = n[1].toPython()
            if not ns.endswith(('#', '/', ':')):
                ns = ns + '/'
            self._namespaces[n[0]] = ns
            # Extend the existing namespaces available
            XML_NS[n[0]] = ns

        self._read_sequences(g)
        self._read_component_definitions(g)
        self._extend_component_definitions(g)
        self._read_models(g)
        self._read_module_definitions(g)
        self._extend_module_definitions(g)
        self._read_annotations(g)
        # Last as this needs all other top level objects created
        self._read_collections(g)
844737
def xmltreefromfile(filename):
    """"""
    try:
        return ElementTree.parse(filename, ElementTree.XMLParser(collect_ids=False))
    except TypeError:
        return ElementTree.parse(filename, ElementTree.XMLParser())
303948
def to_xml(self, xml_declaration=True):
        
        xml = ET.tostring(self.xml()).decode('utf-8')
        return '<?xml version="1.0" encoding="UTF-8"?>{}'.format(xml) if xml_declaration else xml
414157
def report_xml():
    
    arguments = docopt.docopt(report_xml.__doc__, version='cr-rate 1.0')
    with use_db(arguments['<session-file>'], WorkDB.Mode.open) as db:
        xml_elem = _create_xml_report(db)
        xml_elem.write(
            sys.stdout.buffer, encoding='utf-8', xml_declaration=True)
1237112
def _parse(cls, xml_path):
    
    try:
      parsed_xml = parse(xml_path)
    # Minidom is a frontend for various parsers, only Exception covers ill-formed .xml for them all.
    except Exception as e:
      raise cls.XmlError('Error parsing xml file at {0}: {1}'.format(xml_path, e))
    return parsed_xml
513890
def get_xml_child(source, path):
  
  if isinstance(path, (tuple, list)):
    return source.find(*path)
  else:
    return source.find(path)
741067
def generate(basename, xml_list):
    ''''''

    generate_shared(basename, xml_list)
    for xml in xml_list:
        generate_message_definitions(basename, xml)
1246216
def readDoc(cur, URL, encoding, options):
    
    ret = libxml2mod.xmlReadDoc(cur, URL, encoding, options)
    if ret is None:raise treeError('xmlReadDoc() failed')
    return xmlDoc(_obj=ret)
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
610185
def import_from_xml(self, xml):
        '''
        
        '''
        self._import_orgid(xml)
        self._import_parents_from_xml(xml)
        self._import_instances_from_xml(xml)
        self._import_common_name(xml)
        self._import_synonyms(xml)
        self._import_dblinks(xml)
927332
def parse(self, file):
        '''
        
        '''
        parser = make_parser()
        self.clear()

        class Extractor(xml.sax.ContentHandler):

            def __init__(self, parent):
                self.parent = parent

            def startElement(self, name, attrs):
                attribs = {}
                for attrname in attrs.getNames():
                    attrvalue = attrs.get(attrname)
                    attribs[attrname] = attrvalue
                self.parent.StartTag(name, attribs)

            def characters(self, text):
                self.parent.NewData(text)

            def endElement(self, name):
                self.parent.EndTag(name)
        parser.setContentHandler(Extractor(self))
        # OFFLINE MODE
        parser.setFeature(handler.feature_external_ges, False)
        fob = open(file, 'r')
        parser.parse(fob)
        return self.piece
567182
def load_xml_attrs(self):
        

        attrs_list = list()

        if hasattr(self, 'xml_element'):
            xml_attrs = self.xml_element.attrib

            for variable, value in iter(xml_attrs.items()):
                uri, tag = Element.get_namespace_and_tag(variable)
                tag = tag.replace('-', '_')
                attrs_list.append(tag)
                setattr(self, tag, value)

            self.attrs = attrs_list

        return self.attrs
187259
def tarfile_xml_generator(fname):
    
    tf = tarfile.open(fname, mode='r')
    try:
        tarinf = tf.next()
        while tarinf is not None:
            if tarinf.isfile() and tarinf.name[-4:] == '.xml':
                fbuf = tf.extractfile(tarinf)
                yield TarXML(name=tarinf.name, xml=fbuf.read())
            tarinf = tf.next()
            # Kludge around tarfile memory leak, cf
            # http://blogs.it.ox.ac.uk/inapickle/2011/06/20/high-memory-usage-when-using-pythons-tarfile-module/
            tf.members = []
    finally:
        tf.close()
1192010
def getFile(self, file_xml_uri):
		
		find = re.match('/fmi/xml/cnt/([\w\d.-]+)\.([\w]+)?-*', file_xml_uri)

		file_name = find.group(1)
		file_extension = find.group(2)
		file_binary = self._doRequest(is_file=True, file_xml_uri=file_xml_uri)
		return (file_name, file_extension, file_binary)
159706
def htmlReadFile(filename, encoding, options):
    
    ret = libxml2mod.htmlReadFile(filename, encoding, options)
    if ret is None:raise treeError('htmlReadFile() failed')
    return xmlDoc(_obj=ret)
506653
def xml_records(filename):
    
    with Evtx(filename) as evtx:
        for xml, record in evtx_file_xml_view(evtx.get_file_header()):
            try:
                yield to_lxml(xml), None
            except etree.XMLSyntaxError as e:
                yield xml, e