Generate a KML Placemark element subtree.

        Returns:
            etree.Element: KML Placemark element
511474
def tokml(self):
        
        placemark = create_elem('Placemark')
        if self.name:
            placemark.set('id', self.name)
            placemark.name = create_elem('name', text=self.name)
        if self.description:
            placemark.description = create_elem('description',
                                                text=self.description)
        placemark.Point = create_elem('Point')

        data = [str(self.longitude), str(self.latitude)]
        if self.altitude:
            if int(self.altitude) == self.altitude:
                data.append('%i' % self.altitude)
            else:
                data.append(str(self.altitude))
        placemark.Point.coordinates = create_elem('coordinates',
                                                  text=','.join(data))

        return placemark
1136683
def xpath(self, xpath_str):
        
        return super(BaseOxmlElement, self).xpath(
            xpath_str, namespaces=nsmap
        )
725455
def etree(self):
        """"""
        if not hasattr(self, '_elements'):
            try:
                parser = lxml.html.HTMLParser(encoding=self.encoding)
                self._elements = lxml.html.fromstring(self.content, parser=parser)
            except LookupError:
                # lxml would raise LookupError when encoding not supported
                # try fromstring without encoding instead.
                # on windows, unicode is not availabe as encoding for lxml
                self._elements = lxml.html.fromstring(self.content)
        if isinstance(self._elements, lxml.etree._ElementTree):
            self._elements = self._elements.getroot()
        return self._elements
1297449
def create_element_dict(self):
        """"""
        untl_dict = {}
        # Loop through all UNTL elements in the Python object.
        for element in self.children:
            # If an entry for the element list hasn't been made in the
            # dictionary, start an empty element list.
            if element.tag not in untl_dict:
                untl_dict[element.tag] = []
            # Create a dictionary to put the element into.
            # Add any qualifier.
            element_dict = {}
            if element.qualifier is not None:
                element_dict['qualifier'] = element.qualifier
            # Add any children that have content.
            if len(element.contained_children) > 0:
                child_dict = {}
                for child in element.children:
                    if child.content is not None:
                        child_dict[child.tag] = child.content
                # Set the element's content as the dictionary
                # of children elements.
                element_dict['content'] = child_dict
            # The element has content, but no children.
            elif element.content is not None:
                element_dict['content'] = element.content
            # Append the dictionary element to the element list.
            untl_dict[element.tag].append(element_dict)

        return untl_dict
1364333
def to_etree(self):
        
        layers_attrib_val = ' '.join('//@layers.{}'.format(layer_id)
                                     for layer_id in self.layers)

        attribs = {
            '{{{pre}}}type'.format(pre=NAMESPACES['xsi']): self.xsi_type,
            'source': "//@nodes.{}".format(self.source),
            'target': "//@nodes.{}".format(self.target),
            'layers': layers_attrib_val}
        # an edge might belong to one or more layers
        non_empty_attribs = {key: val for (key, val) in attribs.items()
                             if val is not None}

        E = ElementMaker()
        edge = E('edges', non_empty_attribs)
        label_elements = (label.to_etree() for label in self.labels)
        edge.extend(label_elements)
        return edge
116902
def node(self, parent=None, tag='g', attrib=None, **extras):
        """"""
        if parent is None:
            parent = self.root
        attrib = attrib or {}
        attrib.update(extras)

        def in_attrib_and_number(key):
            return key in attrib and isinstance(attrib[key], Number)

        for pos, dim in (('x', 'width'), ('y', 'height')):
            if in_attrib_and_number(dim) and attrib[dim] < 0:
                attrib[dim] = -attrib[dim]
                if in_attrib_and_number(pos):
                    attrib[pos] = attrib[pos] - attrib[dim]

        for key, value in dict(attrib).items():
            if value is None:
                del attrib[key]

            attrib[key] = to_str(value)
            if key.endswith('_'):
                attrib[key.rstrip('_')] = attrib[key]
                del attrib[key]
            elif key == 'href':
                attrib[etree.QName('http://www.w3.org/1999/xlink',
                                   key)] = attrib[key]
                del attrib[key]
        return etree.SubElement(parent, tag, attrib)
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
921691
def update_xml_element(self):
        

        if not hasattr(self, 'xml_element'):
            self.xml_element = etree.Element(self.name, nsmap=NSMAP)

        self.xml_element.clear()
        self.xml_element.set('id', self.id)

        for child in self.children:
            child.update_xml_element()
            self.xml_element.append(child.xml_element)

        return self.xml_element
837588
def to_etree(self):
        
        attribs = {
            '{{{pre}}}type'.format(pre=NAMESPACES['xsi']): self.xsi_type,
            'namespace': self.namespace, 'name': self.name,
            'value': self.hexvalue, 'valueString': self.value}
        non_empty_attribs = {key: val for (key, val) in attribs.items()
                             if val is not None}
        E = ElementMaker()
        return E('labels', non_empty_attribs)
974277
def _elem_from_descendants(children_nodes, **options):
    
    for child in children_nodes:  # child should be a dict-like object.
        for ckey, cval in anyconfig.compat.iteritems(child):
            celem = ET.Element(ckey)
            container_to_etree(cval, parent=celem, **options)
            yield celem
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)
285044
def md_el(node_type, children=[], meta={}, al=nil)
		if  (e=children.first).kind_of?(MDElement) and 
			e.node_type == :ial then
			if al
				al += e.ial
			else
				al = e.ial
			end
			children.shift
		end 
		e = MDElement.new(node_type, children, meta, al)
		e.doc = @doc
		return e
	end
1083259
def root(self):
        
        self.xml_root = ElementTree.Element('interface')
        self.xml_root.set('type', self.type)
        if self.mac is not None:
            mac = ElementTree.SubElement(self.xml_root, 'mac')
            mac.set('address', self.mac)
        _source = ElementTree.SubElement(self.xml_root, 'source')
        _source.set(self.type, self.source)
        _model = ElementTree.SubElement(self.xml_root, 'model')
        _model.set('type', self.model)
        return self.xml_root
680199
def to_etree(self):
        
        nodes_attrib_val = ' '.join('//@nodes.{}'.format(node_id)
                                    for node_id in self.nodes)
        edges_attrib_val = ' '.join('//@edges.{}'.format(edge_id)
                                    for edge_id in self.edges)

        attribs = {
            '{{{pre}}}type'.format(pre=NAMESPACES['xsi']): self.xsi_type,
            'nodes': nodes_attrib_val, 'edges': edges_attrib_val}
        # a layer might have no nodes or edges attributed to it
        non_empty_attribs = {key: val for (key, val) in attribs.items()
                             if val is not None}

        E = ElementMaker()
        layer = E('layers', non_empty_attribs)
        label_elements = (label.to_etree() for label in self.labels)
        layer.extend(label_elements)
        return layer
7357
def encode(self):
        
        root_element = ElementTree.Element(self.TAG_NAME)
        for value in [value for value in self.__dict__.values() if isinstance(value, fields.Field)]:
            if value.required or value.value:
                root_element.append(value.encode())
        return root_element
1208749
def update_xml_element(self):
        

        if not hasattr(self, 'xml_element'):
            self.xml_element = etree.Element(self.name, nsmap=NSMAP)

        for element in self.xml_element:
            self.xml_element.remove(element)

        self.xml_element.tail = ''
        self.xml_element.text = self.convert_html_to_xml()

        return self.xml_element
1290020
def kml_ground_overlay(tile_coords, tile_url):
    
    return KML.GroundOverlay(
        KML.name(kml_element_name(tile_coords, "GO")),
        KML.drawOrder(tile_coords.zoom),
        KML.Icon(
            KML.href(tile_url)
        ),
        KML.LatLonBox(
            *kml_lat_lon_box(tile_coords.geographic_bounds())
        ),
    )