Reading gml in c #

I have a problem reading some gml files in C #. My files have no schema or namespaces and look like a file from this question:

Parsing GML data using C # Linq for XML

only without this circuit:

<gml:Polygon srsName='http://www.opengis.net/gml/srs/epsg.xml#4283'> <gml:outerBoundaryIs> <gml:LinearRing> <gml:coord> <gml:X>152.035953</gml:X> <gml:Y>-28.2103190007845</gml:Y> </gml:coord> <gml:coord> <gml:X>152.035957</gml:X> <gml:Y>-28.2102020007845</gml:Y> </gml:coord> <gml:coord> <gml:X>152.034636</gml:X> <gml:Y>-28.2100120007845</gml:Y> </gml:coord> <gml:coord> <gml:X>152.034617</gml:X> <gml:Y>-28.2101390007845</gml:Y> </gml:coord> <gml:coord> <gml:X>152.035953</gml:X> <gml:Y>-28.2103190007845</gml:Y> </gml:coord> </gml:LinearRing> </gml:outerBoundaryIs> </gml:Polygon> 

When I try to read a document using the XDocument.Load method, I get an exception: 'gml' namespace is not defined .

I have many gml files, so I don’t want to add schemas and namespaces to all my files. Does anyone know how to read my files?

+6
c # xml gml-geographic-markup-lan
source share
3 answers

Use XmlTextReader with XmlNamespaceManager. See an example on MSDN: http://msdn.microsoft.com/en-us/library/system.xml.xmlnamespacemanager.xmlnamespacemanager.aspx

+6
source share

If you do not declare the namespace associated with the "gml" prefix, your text is not valid Xml + namespaces.

You can implement the step of the preliminary process that did something like (pseudocode):

 string text = ReadFromFile(); text = text.replace(" srsName=", " xmlns:gml="); xmlDocument.LoadXml(text); 
+2
source share

You can add your namespace and enter it programmatically.

Upload the file to a line using File.ReadAllText(filename) , add the necessary information about the type and namespace and XDocument.Parse it using XDocument.Parse instead of Load .

+1
source share

All Articles