Create an ``lxml``-based XML DOM from the response. The tree
        will not have a root, so all queries need to be relative
        (i.e. start with a dot).
346991
def xml(self):
        
        try:
            from lxml import etree
            return etree.fromstring(self.content)
        except ImportError as ie:
            raise DependencyException(ie)
888736
function _nodeToXml (node, wrapped) {
        var
            name = node.localName(),
            attributes = node.attributes(),
            children = node.children(),
            text = node.textContent(),
            idx;
        wrapped.startElement({
            uri: "",
            localName: name,
            qName: name
        }, attributes);
        // Today the XmlConstNode may not have both children and textual content
        if (text) {
            wrapped.characters(text);
        } else {
            for (idx = 0; idx < children.length; ++idx) {
                _nodeToXml(children[idx], wrapped);
            }
        }
        wrapped.endElement();
    }
395390
def fromXml(cls, elem):
        
        if elem is None:
            return None

        addon = cls.byName(elem.tag)
        if not addon:
            raise RuntimeError('{0} is not a supported XML tag'.format(elem.tag))

        return addon.load(elem)
606460
def create_xml(self, useNamespace=False):
        """"""
        UNTL_NAMESPACE = 'http://digital2.library.unt.edu/untl/'
        UNTL = '{%s}' % UNTL_NAMESPACE

        NSMAP = {'untl': UNTL_NAMESPACE}

        if useNamespace:
            root = Element(UNTL + self.tag, nsmap=NSMAP)
        else:
            root = Element(self.tag)

        # Sort the elements by the index of
        # UNTL_XML_ORDER pre-ordered list.
        self.sort_untl(UNTL_XML_ORDER)
        # Create an XML structure from field list.
        for element in self.children:
            if useNamespace:
                create_untl_xml_subelement(root, element, UNTL)
            else:
                create_untl_xml_subelement(root, element)
        return root
4379
def get_xml(self, pretty=True):
        
        return etree.tostring(self.root, encoding="utf-8", pretty_print=pretty)
193085
def nodeToXML(nodeObject):
    

    xmlRoot = etree.Element(NODE + "node", nsmap=NODE_NSMAP)
    nameNode = etree.SubElement(xmlRoot, NODE + "name")
    nameNode.text = nodeObject.node_name
    urlNode = etree.SubElement(xmlRoot, NODE + "url")
    urlNode.text = nodeObject.node_url
    pathNode = etree.SubElement(xmlRoot, NODE + "path")
    pathNode.text = nodeObject.node_path
    capNode = etree.SubElement(xmlRoot, NODE + "capacity")
    capNode.text = str(nodeObject.node_capacity)
    sizeNode = etree.SubElement(xmlRoot, NODE + "size")
    sizeNode.text = str(nodeObject.node_size)
    if nodeObject.last_checked:
        checkedNode = etree.SubElement(xmlRoot, NODE + "lastChecked")
        checkedNode.text = nodeObject.last_checked.strftime(TIME_FORMAT_STRING)
    return xmlRoot
988340
def __build_lxml(target, source, env):
    
    from lxml import etree
    
    xslt_ac = etree.XSLTAccessControl(read_file=True, 
                                      write_file=True, 
                                      create_dir=True, 
                                      read_network=False, 
                                      write_network=False)
    xsl_style = env.subst('$DOCBOOK_XSL')
    xsl_tree = etree.parse(xsl_style)
    transform = etree.XSLT(xsl_tree, access_control=xslt_ac)
    doc = etree.parse(str(source[0]))
    # Support for additional parameters
    parampass = {}
    if parampass:
        result = transform(doc, **parampass)
    else:
        result = transform(doc)
        
    try:
        of = open(str(target[0]), "wb")
        of.write(of.write(etree.tostring(result, pretty_print=True)))
        of.close()
    except:
        pass

    return None
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)
911200
def XML(content, source=None):
    
    try:
        tree = ET.XML(content)
    except ET.ParseError as err:
        x_parse_error(err, content, source)
    return tree
1177198
def data(self, root, preserve_root=False):
        ''''''
        # If preserve_root is False, return the root element. This is easiest
        # done by wrapping the XML in a dummy root element that will be ignored.
        if preserve_root:
            new_root = root.makeelement('dummy_root', {})
            new_root.insert(0, root)
            root = new_root

        # If no children, just return the text
        children = [node for node in root if isinstance(node.tag, basestring)]
        if len(children) == 0:
            return self._fromstring(root.text)

        # Element names become object properties
        count = Counter(child.tag for child in children)
        result = self.dict()
        for child in children:
            if count[child.tag] == 1:
                result[child.tag] = self.data(child)
            else:
                result.setdefault(child.tag, self.list()).append(self.data(child))

        return result
1157214
private DavChild makeDavChild(final Collection<Element> responseElements) throws Throwable {
    if (responseElements == null) {
      // status 400
      return null;
    }

    DavChild dc = null;

    int count = 0; // validity
    for (Element resp: responseElements) {
      count++;

      if (XmlUtil.nodeMatches(resp, WebdavTags.responseDescription)) {
        // Has to be last
        if (responseElements.size() > count) {
          throw new Exception("Bad multstatus Expected " +
                                      "(response+, responsedescription?)");
        }

        continue;
      }

      if (!XmlUtil.nodeMatches(resp, WebdavTags.response)) {
        throw new Exception("Bad multstatus Expected " +
                                    "(response+, responsedescription?) found " + resp);
      }

      if (dc != null){
        throw new Exception("Bad multstatus Expected only 1 response");
      }

      dc = makeDavResponse(resp);
    }

    return dc;
  }
1092612
def to_xml(body_element):
    
    doctype = b"""<?xml version="1.0" encoding="UTF-8"?>\n"""
    if body_element is None:
        return succeed(b"")
    d = flattenString(None, body_element)
    d.addCallback(lambda flattened: doctype + flattened)
    return d
753508
def html(self):
        
        try:
            from lxml import html
            return html.fromstring(self.content)
        except ImportError as ie:
            raise DependencyException(ie)
936289
def _nav_to_tree(root):
    
    def expath(e, x):
        return e.xpath(x, namespaces=HTML_DOCUMENT_NAMESPACES)
    for li in expath(root, 'xhtml:ol/xhtml:li'):
        is_subtree = bool([e for e in li.getchildren()
                           if e.tag[e.tag.find('}')+1:] == 'ol'])
        if is_subtree:
            # It's a sub-tree and have a 'span' and 'ol'.
            itemid = li.get('cnx-archive-uri', 'subcol')
            shortid = li.get('cnx-archive-shortid')
            yield {'id': itemid,
                   # Title is wrapped in a span, div or some other element...
                   'title': squash_xml_to_text(expath(li, '*')[0],
                                               remove_namespaces=True),
                   'shortId': shortid,
                   'contents': [x for x in _nav_to_tree(li)],
                   }
        else:
            # It's a node and should only have an li.
            a = li.xpath('xhtml:a', namespaces=HTML_DOCUMENT_NAMESPACES)[0]
            yield {'id': a.get('href'),
                   'shortid': li.get('cnx-archive-shortid'),
                   'title': squash_xml_to_text(a, remove_namespaces=True)}
1352292
def from_xml(content_types_xml):
        
        types_elm = parse_xml(content_types_xml)
        ct_map = _ContentTypeMap()
        for o in types_elm.overrides:
            ct_map._add_override(o.partname, o.content_type)
        for d in types_elm.defaults:
            ct_map._add_default(d.extension, d.content_type)
        return ct_map
1311663
def restoreXml(self, xml):
        
        self.uiRecordTREE.restoreXml(xml.find('tree'))
        
        # restore the query
        xquery = xml.find('query')
        if xquery is not None:
            self.setQuery(Q.fromXml(xquery[0]))
205946
def xml(self, indent = ""):
        """"""
        xml = indent + "<" + self.__class__.__name__
        xml += ' id="'+self.id + '"'
        xml += ' name="'+xmlescape(self.name) + '"'
        xml += ' description="'+xmlescape(self.description) + '"'
        if self.paramflag:
            xml += ' flag="'+self.paramflag + '"'
        for key, v in self.kwargs.items():
            if key not in ('value','error','name','description','flag','paramflag', 'validator'):
                if isinstance(v, bool):
                    xml += ' ' + key + '="' + str(int(v))+ '"'
                elif isinstance(v, list):
                    xml += ' ' + key + '="'+xmlescape(",".join(v))+ '"'
                elif isinstance(v, str)  or ( sys.version < '3' and isinstance(v, unicode)): #pylint: disable=undefined-variable
                    xml += ' ' + key + '="'+xmlescape(v)+ '"'
                else:
                    xml += ' ' + key + '="'+xmlescape(str(v))+ '"'
        if self.hasvalue:
            if sys.version < '3':
                xml += ' value="'+xmlescape(unicode(self.value)) + '"' #pylint: disable=undefined-variable
            else:
                xml += ' value="'+xmlescape(str(self.value)) + '"'
        if self.error:
            xml += ' error="'+xmlescape(self.error) + '"'
        xml += " />"
        return xml