Opened 8 years ago

Closed 8 years ago

#6214 closed defect (fixed)

ExportToGML does not provide GML namespace declaration

Reported by: tomkralidis Owned by: hobu
Priority: normal Milestone: 2.1.0
Component: OGR_SF Version: unspecified
Severity: normal Keywords: gml namespace


(inspired by


import xml.etree.ElementTree as etree
import ogr

geom_wkt = 'POINT (30 10)'
geom = ogr.CreateGeometryFromWkt( geom_wkt )

gml = geom.ExportToGML()


e = etree.fromstring(gml)


Traceback (most recent call last):
  File "", line 12, in <module>
    e = etree.fromstring(gml)
  File "/usr/lib/python2.7/xml/etree/", line 1300, in XML
  File "/usr/lib/python2.7/xml/etree/", line 1642, in feed
  File "/usr/lib/python2.7/xml/etree/", line 1506, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: unbound prefix: line 1, column 0

This breaks XML parsers which expect namespace prefixes to be bound. So a result like:

<gml:Point xmlns:gml=""><gml:coordinates>30,10</gml:coordinates></gml:Point> would work (actual namespace TBD per the GML version[s] supported).

Change History (1)

comment:1 by Even Rouault, 8 years ago

Component: PythonBindingsOGR_SF
Milestone: 2.1.0
Resolution: fixed
Status: newclosed

Implemented per trunk r31431 "GML: add NAMESPACE_DECL=YES option to OGR_G_ExportToGMLEx() to add xmlns:gml= or declaration; Also accept GML2 or GML32 as valid valiues for FORMAT option (#6214)"

See commit for how to use from Python. I didn't add the namespace declaration by default because it might cause very verbose output if the output is aggregated.

Note: See TracTickets for help on using tickets.