I'm trying to read LandXML files but there is diffirent versions of the LandXML namespace.
The 1.0 version of my LandXML file starts like this (the 2 first lines):
<?xml version="1.0" encoding="ISO-8859-1"?>
<LandXML xmlns="http://www.landxml.org/schema/LandXML-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.landxml.org/schema/LandXML-1.0 http://www.landxml.org/schema/LandXML-1.0/LandXML-1.0.xsd" date="2007-12-13" time="07:35:59" version="1.0">
The 1.1 version of LandXML file starts like this (the 2 first lines):
<?xml version="1.0" encoding="utf-8"?>
<LandXML xsi:schemaLocation="http://www.landxml.org/schema/LandXML-1.1 http://www.landxml.org/schema/LandXML-1.1/LandXML-1.1.xsd" date="2011-04-01" time="11:48:40" version="1.1" xmlns="http://www.landxml.org/schema/LandXML-1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
My code for reading 'Alignment' from the file:
Dim doc As XmlDocument = New XmlDocument()
doc.Load(OpenFileDialog.FileName)
Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(doc.NameTable)
nsmgr.AddNamespace("ns", "http://www.landxml.org/schema/LandXML-1.0")
Dim nodeList As XmlNodeList = doc.SelectNodes("//ns:Alignment", nsmgr)
For Each node As XmlNode In nodeList
Dim nameAttribute As String = node.Attributes.GetNamedItem("name").Value
msgbox(nameAttribute)
Next
This code will only work if with the 1.0 version file. If I change the nsmgr.AddNamespace line to LandXML-1.1 the code will only work with the 1.1 version file. How can I solve this? Is there a way to read the namespace version from the file and put that version into the nsmgr.AddNamespace line?