Convert dict to XML

    Args:
        spec(dict): dict to convert
        full_document(bool): whether to add XML headers

    Returns:
        lxml.etree.Element: XML tree
974141
def dict_to_xml(spec, full_document=False):
    

    middle = xmltodict.unparse(spec, full_document=full_document, pretty=True)
    return lxml.etree.fromstring(middle)
346991
def xml(self):
        
        try:
            from lxml import etree
            return etree.fromstring(self.content)
        except ImportError as ie:
            raise DependencyException(ie)
900632
def _xml_convert(self, element):
        

        children = list(element)

        if len(children) == 0:
            return self._type_convert(element.text)
        else:
            # if the fist child tag is list-item means all children are list-item
            if children[0].tag == "list-item":
                data = []
                for child in children:
                    data.append(self._xml_convert(child))
            else:
                data = {}
                for child in children:
                    data[child.tag] = self._xml_convert(child)

            return data
267954
def elementtree_to_dict(element):
    """"""
    d = dict()
    if hasattr(element, 'text') and element.text is not None:
        d['text'] = element.text

    d.update(element.items())  # element's attributes

    for c in list(element):  # element's children
        if c.tag not in d:
            d[c.tag] = elementtree_to_dict(c)
        # an element with the same tag was already in the dict
        else:
            # if it's not a list already, convert it to a list and append
            if not isinstance(d[c.tag], list):
                d[c.tag] = [d[c.tag], elementtree_to_dict(c)]
           # append to the list
            else:
                d[c.tag].append(elementtree_to_dict(c))
    return d
1131741
def md_from_etree(self, md_element, context=''):
        
        md = {}
        # grab all understood attributes into md dict
        for att in ('capability', 'change', 'hash', 'length', 'path', 'mime_type',
                    'md_at', 'md_completed', 'md_from', 'md_until'):
            xml_att = self._xml_att_name(att)
            val = md_element.attrib.get(xml_att, None)
            if (val is not None):
                md[att] = val
        # capability. Allow this to be missing but do a very simple syntax
        # check on plausible values if present
        if ('capability' in md):
            if (re.match(r"^[\w\-]+$", md['capability']) is None):
                raise SitemapParseError(
                    "Bad capability name '%s' in %s" %
                    (capability, context))
        # change should be one of defined values
        if ('change' in md):
            if (md['change'] not in ['created', 'updated', 'deleted']):
                self.logger.warning(
                    "Bad change attribute in <rs:md> for %s" %
                    (context))
        # length should be an integer
        if ('length' in md):
            try:
                md['length'] = int(md['length'])
            except ValueError as e:
                raise SitemapParseError(
                    "Invalid length element in <rs:md> for %s" %
                    (context))
        return(md)
125816
def to_etree(xml):
        
        if isinstance(xml, OneLogin_Saml2_XML._element_class):
            return xml
        if isinstance(xml, OneLogin_Saml2_XML._bytes_class):
            return OneLogin_Saml2_XML._parse_etree(xml, forbid_dtd=True)
        if isinstance(xml, OneLogin_Saml2_XML._text_class):
            return OneLogin_Saml2_XML._parse_etree(compat.to_bytes(xml), forbid_dtd=True)

        raise ValueError('unsupported type %r' % type(xml))
257350
def etree_to_dict(element):
    
    i = dict(element.items())
    content = element.text.strip() if element.text else None
    i.update({'content': content}) if content else None

    if len(element.getchildren()):
        for child in element.iterchildren():
            tag = child.tag.split('}', 1)[-1]
            new = etree_to_dict(child)
            content = _make_content(i, tag, new)
            i.update({tag: content}) if content else None

            tag = 'content'
            new = child.tail.strip() if child.tail else None
            content = _make_content(i, tag, new)
            i.update({tag: content}) if content else None
    elif content and not set(i).difference(['content']):
        # element is leaf node and doesn't have attributes
        i = content

    return i
224573
def to_xml(self):
        
        ret = '<exif>'
        for k in self.__dict__:
            ret += '<%s>%s</%s>' % (k, self.__dict__[k], k)
        ret += '</exif>'
        return ret
327102
def parseelement(elem):
    '''
    
    '''
    xml = '<%(tag)s>%(content)s</%(tag)s>' % {'tag' : elem.tag, 'content' : elem.text}
    et = etree.fromstring(xml)
    replaceelement(elem, et)
1079898
def convert_html_to_xml(self):
        

        if hasattr(self, 'content') and self.content != '':
            regex = r'<(?!/)(?!!)'
            xml_content = re.sub(regex, '<xhtml:', self.content)
            return xml_content
        else:
            return ''
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)
1313400
def parsexml(Class, node, doc, **kwargs):#pylint: disable=bad-classmethod-argument
        """"""
        if not kwargs: kwargs = {}
        if 'offset' in node.attrib:
            kwargs['offset'] = int(node.attrib['offset'])
        if 'ref' in node.attrib:
            kwargs['ref'] = node.attrib['ref']
        return super(PhonContent,Class).parsexml(node,doc, **kwargs)
1047427
def _xml_to_dict(xmltree):
    '''
    
    '''
    if sys.version_info < (2, 7):
        children_len = len(xmltree.getchildren())
    else:
        children_len = len(xmltree)

    if children_len < 1:
        name = xmltree.tag
        if '}' in name:
            comps = name.split('}')
            name = comps[1]
        return {name: xmltree.text}

    xmldict = {}
    for item in xmltree:
        name = item.tag
        if '}' in name:
            comps = name.split('}')
            name = comps[1]
        if name not in xmldict:
            if sys.version_info < (2, 7):
                children_len = len(item.getchildren())
            else:
                children_len = len(item)

            if children_len > 0:
                xmldict[name] = _xml_to_dict(item)
            else:
                xmldict[name] = item.text
        else:
            if not isinstance(xmldict[name], list):
                tempvar = xmldict[name]
                xmldict[name] = []
                xmldict[name].append(tempvar)
            xmldict[name].append(_xml_to_dict(item))
    return xmldict
1295308
def to_xml(options = {})
      require 'rexml/document'

      xml =  REXML::Document.new
      xml << REXML::XMLDecl.new('1.0','UTF-8')

      root = REXML::Element.new('bibtex:file')
      root.add_namespace('bibtex', 'http://bibtexml.sf.net/')

      each { |e| root.add_element(e.to_xml(options)) if e.is_a?(Entry) }

      xml.add_element(root)
      xml
    end
1086995
def _get_xml_doc(self, endpoint, query, is_post=False):
        
        response = self._get_response(endpoint, query, is_post=is_post)
        return minidom.parse(response.text)
1121178
def rsxml_to_xml(sexp)
      # visit the rsxml, prefix the element tags with "t" namespace prefix, and camelcase
      # all QName local_parts
      transform_visitor = Rsxml::Visitor::BuildRsxmlVisitor.new() do |context, element_name, attrs|
        t_element_name = camelize_qname(apply_namespace(element_name, "t", Rews::SCHEMA_TYPES))
        t_attrs = Hash[attrs.map{|attr_name,v| [camelize_qname(attr_name), v]}]
        [t_element_name, t_attrs]
      end

      xrsxml = Rsxml::Sexp.traverse(sexp, transform_visitor).sexp
      Rsxml.to_xml(xrsxml, :ns=>{"t"=>Rews::SCHEMA_TYPES, "wsdl"=>Rews::SCHEMA_MESSAGES})
    end
1257654
def toXml(self, xparent):
        
        for key, value in self.items():
            elem = ElementTree.SubElement(xparent, 'entry')
            typ = type(elem).__name__

            elem.set('key', key)
            elem.set('type', typ)

            if typ in DataSet._xmlTypes:
                DataSet._xmlTypes[typ][0](elem, value)
            else:
                elem.set('value', nstr(value))