Return identity details for the element as XML nodes
12952
def _as_rdf_xml(self, ns):
        
        self.rdf_identity = self._get_identity(ns)
        elements = []
        elements.append(ET.Element(NS('sbol', 'persistentIdentity'),
                                   attrib={NS('rdf', 'resource'):
                                           self._get_persistent_identitity(ns)}))
        if self.name is not None:
            name = ET.Element(NS('dcterms', 'title'))
            name.text = self.name
            elements.append(name)
        if self.display_id is not None:
            display_id = ET.Element(NS('sbol', 'displayId'))
            display_id.text = self.display_id
            elements.append(display_id)
        if self.version is not None:
            version = ET.Element(NS('sbol', 'version'))
            version.text = self.version
            elements.append(version)
        if self.was_derived_from is not None:
            elements.append(ET.Element(NS('prov', 'wasDerivedFrom'),
                                       attrib={NS('rdf', 'resource'): self.was_derived_from}))
        if self.description is not None:
            description = ET.Element(NS('dcterms', 'description'))
            description.text = self.description
            elements.append(description)
        for a in self.annotations:
            elements.append(a._as_rdf_xml(ns))
        return elements
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
1363815
def asXML( self, doctag=None, namedItemsOnly=False, indent="", formatted=True ):
        
        nl = "\n"
        out = []
        namedItems = dict((v[1],k) for (k,vlist) in self.__tokdict.items()
                                                            for v in vlist)
        nextLevelIndent = indent + "  "

        # collapse out indents if formatting is not desired
        if not formatted:
            indent = ""
            nextLevelIndent = ""
            nl = ""

        selfTag = None
        if doctag is not None:
            selfTag = doctag
        else:
            if self.__name:
                selfTag = self.__name

        if not selfTag:
            if namedItemsOnly:
                return ""
            else:
                selfTag = "ITEM"

        out += [ nl, indent, "<", selfTag, ">" ]

        for i,res in enumerate(self.__toklist):
            if isinstance(res,ParseResults):
                if i in namedItems:
                    out += [ res.asXML(namedItems[i],
                                        namedItemsOnly and doctag is None,
                                        nextLevelIndent,
                                        formatted)]
                else:
                    out += [ res.asXML(None,
                                        namedItemsOnly and doctag is None,
                                        nextLevelIndent,
                                        formatted)]
            else:
                # individual token, see if there is a name for it
                resTag = None
                if i in namedItems:
                    resTag = namedItems[i]
                if not resTag:
                    if namedItemsOnly:
                        continue
                    else:
                        resTag = "ITEM"
                xmlBodyText = _xml_escape(_ustr(res))
                out += [ nl, nextLevelIndent, "<", resTag, ">",
                                                xmlBodyText,
                                                "</", resTag, ">" ]

        out += [ nl, indent, "</", selfTag, ">" ]
        return "".join(out)
1086393
def GetElementNSdict(self, elt):
        '''
        '''
        d = self.ns_cache.get(id(elt))
        if not d:
            if elt != self.dom: d = self.GetElementNSdict(elt.parentNode)
            for a in _attrs(elt):
                if a.namespaceURI == XMLNS.BASE:
                    if a.localName == "xmlns":
                        d[''] = a.nodeValue
                    else:
                        d[a.localName] = a.nodeValue
            self.ns_cache[id(elt)] = d
        return d.copy()
378559
def toxml(self):
        

        return '<DerivedParameter name="{0}"'.format(self.name) +\
          (' dimension="{0}"'.format(self.dimension) if self.dimension else '') +\
          (' value="{0}"'.format(self.value) if self.value else '') +\
          '/>'
732280
def _to_DOM(self):
        
        root_node = ET.Element('station')
        created_at_node = ET.SubElement(root_node, "created_at")
        created_at_node.text = \
            timeformatutils.to_ISO8601(self.created_at)if self.created_at is not None else 'null'
        updated_at_node = ET.SubElement(root_node, "updated_at")
        updated_at_node.text = \
            timeformatutils.to_ISO8601(self.updated_at)if self.updated_at is not None else 'null'
        station_id_node = ET.SubElement(root_node, 'id')
        station_id_node.text = str(self.id)
        station_id_node = ET.SubElement(root_node, 'external_id')
        station_id_node.text = str(self.external_id)
        station_name_node = ET.SubElement(root_node, 'name')
        station_name_node.text = str(self.name) if self.name is not None else 'null'
        lat_node = ET.SubElement(root_node, 'lat')
        lat_node.text = str(self.lat)
        lon_node = ET.SubElement(root_node, 'lon')
        lon_node.text = str(self.lon)
        alt_node = ET.SubElement(root_node, 'alt')
        alt_node.text = str(self.alt) if self.alt is not None else 'null'
        rank_node = ET.SubElement(root_node, 'rank')
        rank_node.text = str(self.rank) if self.rank is not None else 'null'

        return root_node
86348
def _get_xml_dom(self):
        
        if self.site_control == SITE_CONTROL_NONE and \
           any((self.domains, self.header_domains, self.identities)):
            raise TypeError(BAD_POLICY)

        policy_type = minidom.createDocumentType(
            qualifiedName='cross-domain-policy',
            publicId=None,
            systemId='http://www.adobe.com/xml/dtds/cross-domain-policy.dtd'
        )
        policy = minidom.createDocument(
            None,
            'cross-domain-policy',
            policy_type
        )

        if self.site_control is not None:
            control_element = policy.createElement('site-control')
            control_element.setAttribute(
                'permitted-cross-domain-policies',
                self.site_control
            )
            policy.documentElement.appendChild(control_element)

        for elem_type in ('domains', 'header_domains', 'identities'):
            getattr(self, '_add_{}_xml'.format(elem_type))(policy)

        return policy
113305
def xml(self):
        

        xml = '<inasafe_provenance>\n'
        for step in self.steps:
            xml += step.xml
        xml += '</inasafe_provenance>\n'
        return xml
199127
def xmltreefromstring(s):
    """"""
    if sys.version < '3':
        #Python 2
        if isinstance(s,unicode): #pylint: disable=undefined-variable
            s = s.encode('utf-8')
        try:
            return ElementTree.parse(StringIO(s), ElementTree.XMLParser(collect_ids=False))
        except TypeError:
            return ElementTree.parse(StringIO(s), ElementTree.XMLParser()) #older lxml, may leak!!!!
    else:
        #Python 3
        if isinstance(s,str):
            s = s.encode('utf-8')
        try:
            return ElementTree.parse(BytesIO(s), ElementTree.XMLParser(collect_ids=False))
        except TypeError:
            return ElementTree.parse(BytesIO(s), ElementTree.XMLParser())
508902
def getElement(self, node, name, nsuri=None, default=join):
        """"""
        nsmatch = self.nsUriMatch
        ELEMENT_NODE = node.ELEMENT_NODE
        for child in node.childNodes:
            if child.nodeType == ELEMENT_NODE:
                if ((child.localName == name or name is None) and
                    (nsuri is None or nsmatch(child.namespaceURI, nsuri))
                    ):
                    return child
        if default is not join:
            return default
        raise KeyError, name
1047920
def xml(self):
        
        root = super(GenericLayerMetadata, self).xml
        return prettify_xml(ElementTree.tostring(root))
871393
def from_xml_node(cls, node):
        """"""
        return cls(name=node.find("Name").text,
                bit_position=int(node.find("Bitposition").text),
                bit_size=int(node.find("Bitsize").text),
                factor=float(node.find("Factor").text),
                offset=float(node.find("Offset").text),
                min_value=float(node.find("Minimum").text),
                max_value=float(node.find("Maximum").text))
705641
def toXml(self):
        
        xtoolbar = ElementTree.Element('toolbar')
        
        prof = self._currentProfile
        if prof is not None:
            xtoolbar.set('current', prof.name())
        
        for profile in self.profiles():
            profile.toXml(xtoolbar)
        
        return xtoolbar
1209736
def xml(self):
        

        root = super(ImpactLayerMetadata, self).xml
        provenance_path = self._special_properties['provenance']
        provenance_element = root.find(provenance_path, XML_NS)

        # find the provenance parent tag
        if provenance_element is not None:
            # there is already a provenance tag so we remove it
            provenance_parent = provenance_element.getparent()
            provenance_parent.remove(provenance_element)
        else:
            # find the parent using the provenance path minus one level
            provenance_parent = '/'.join(provenance_path.split('/')[:-1])
            provenance_parent = root.find(provenance_parent, XML_NS)

        # generate the provenance xml element
        provenance_element = ElementTree.fromstring(self.provenance.xml)
        provenance_parent.append(provenance_element)
        return prettify_xml(ElementTree.tostring(root, 'unicode'))
1362574
function xmlparse(xml) {
	xml = xml.trim();

	// strip comments
	xml = xml.replace(/<!--[\s\S]*?-->/g, '');

	return document();

	/**
	 * XML document.
	 */

	function document() {
		return {
			declaration: declaration(),
			root: tag(),
		};
	}

	/**
	 * Declaration.
	 */

	function declaration() {
		var m = match(/^<\?xml\s*/);
		if (!m) return;

		// tag
		var node = {
			attributes: {},
		};

		// attributes
		while (!(eos() || is('?>'))) {
			var attr = attribute();
			if (!attr) return node;
			node.attributes[attr.name] = attr.value;
		}

		match(/\?>\s*/);

		return node;
	}

	/**
	 * Tag.
	 */

	function tag() {
		var m = match(/^<([\w-:.]+)\s*/);
		if (!m) return;

		// name
		var node = {
			name: m[1],
			attributes: {},
			children: [],
		};

		// attributes
		while (!(eos() || is('>') || is('?>') || is('/>'))) {
			var attr = attribute();
			if (!attr) return node;
			node.attributes[attr.name] = attr.value;
		}

		// self closing tag
		if (match(/^\s*\/>\s*/)) {
			return node;
		}

		match(/\??>\s*/);

		// content
		node.content = content();

		// children
		var child;
		while ((child = tag())) {
			node.children.push(child);
		}

		// closing
		match(/^<\/[\w-:.]+>\s*/);

		return node;
	}

	/**
	 * Text content.
	 */

	function content() {
		var m = match(/^([^<]*)/);
		if (m) return m[1];
		return '';
	}

	/**
	 * Attribute.
	 */

	function attribute() {
		var m = match(/([\w:-]+)\s*=\s*("[^"]*"|'[^']*'|\w+)\s*/);
		if (!m) return;
		return {name: m[1], value: strip(m[2])};
	}

	/**
	 * Strip quotes from `val`.
	 */

	function strip(val) {
		return val.replace(/^['"]|['"]$/g, '');
	}

	/**
	 * Match `re` and advance the string.
	 */

	function match(re) {
		var m = xml.match(re);
		if (!m) return;
		xml = xml.slice(m[0].length);
		return m;
	}

	/**
	 * End-of-source.
	 */

	function eos() {
		return 0 == xml.length;
	}

	/**
	 * Check for `prefix`.
	 */

	function is(prefix) {
		return 0 == xml.indexOf(prefix);
	}
}
1240094
def get_result_xml(result):
    
    result_xml = Element('result')
    for name, value in [('name', result['name']),
                        ('type', ResultType.get_str(result['type'])),
                        ('severity', result['severity']),
                        ('host', result['host']),
                        ('test_id', result['test_id']),
                        ('port', result['port']),
                        ('qod', result['qod'])]:
        result_xml.set(name, str(value))
    result_xml.text = result['value']
    return result_xml
1169546
def parse_xml_node(self, node):
        '''

        '''
        self.id = node.getAttributeNS(RTS_NS, 'id')
        self._config_data = []
        for d in node.getElementsByTagNameNS(RTS_NS, 'ConfigurationData'):
            self._config_data.append(ConfigurationData().parse_xml_node(d))
        return self