Skip to content

Commit

Permalink
Merge pull request #4 from seantis/master
Browse files Browse the repository at this point in the history
Add kml xmlns if no namespace/prefix is used for kml
  • Loading branch information
cleder committed Aug 29, 2013
2 parents 7051e2d + 0b1534c commit f5c9a81
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions fastkml/kml.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ class KML(object):
ns = None

def __init__(self, ns=None):
""" The namespace (ns) may be empty ('') if the 'kml:' prefix is
undesired. Note that all child elements like Document or Placemark need
to be initialized with empty namespace as well in this case.
"""
self._features =[]
if ns == None:

if ns is None:
self.ns = config.NS
else:
self.ns = ns
Expand Down Expand Up @@ -101,6 +107,13 @@ def from_string(self, xml_string):

def etree_element(self):
root = etree.Element('%skml' % self.ns)

# self.ns may be empty, which leads to unprefixed kml elements.
# However, in this case the xlmns should still be mentioned on the kml
# element, just without prefix.
if not self.ns:
root.set('xmlns', config.NS[1:-1])

for feature in self.features():
root.append(feature.etree_element())
return root
Expand Down Expand Up @@ -797,7 +810,7 @@ def __init__(self, ns=None, id=None, elements=None):

def etree_element(self):
element = super(UntypedExtendedData, self).etree_element()

for subelement in self.elements:
element.append(subelement.etree_element())

Expand All @@ -806,7 +819,7 @@ def etree_element(self):
def from_element(self, element):
super(UntypedExtendedData, self).from_element(element)
self.elements = []

for subelement in element:
el = UntypedExtendedDataElement(self.ns)
el.from_element(subelement)
Expand Down

0 comments on commit f5c9a81

Please sign in to comment.