How to read a Version element value from an XML file

gracuarce

New Member
I'm trying to read the version of an xml file:\[code\]<Order xsi:schemaLocation="urn:schemas-basda-org:2000:purchaseOrder:xdr:3.01 order-v3.xsd urn:schemas-bossfed-co-uk:OP-Order-v1 OP-Order-v1.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:schemas-basda-org:2000:purchaseOrder:xdr:3.01"> <OrderHead> <Schema> <Version>3.05</Version> </Schema> <Parameters> <Language>en-GB</Language> <DecimalSeparator>.</DecimalSeparator> <Precision>12.1</Precision> </Parameters> <OrderCurrency> <Currency Code="GBP">GB Pounds</Currency> </OrderCurrency> </OrderHead>\[/code\]The code I'm trying to use is:\[code\]Dim m_xmld As XmlDocumentDim m_nodelist As XmlNodeListDim m_node As XmlNode'Create the XML Documentm_xmld = New XmlDocument()'Load the Xml filem_xmld.Load(fileLocation)'Show all data in your xmlMessageBox.Show(m_xmld.OuterXml)'Get the list of name nodesm_nodelist = m_xmld.SelectNodes("/Order/OrderHead/Schema")For Each m_node In m_nodelist GetXmlVersion = m_node.Attributes.GetNamedItem("Version").ValueNext\[/code\]But, it doesent pull anything.i changed it to:\[code\]Public Shared Function GetXmlVersion (ByVal fileLocation As String) As String Dim m_xmld As XmlDocument = New XmlDocument() m_xmld.Load (fileLocation) GetXmlVersion = m_xmld.SelectSingleNode ("/Order/OrderHead/Schema/Version").InnerTextEnd Function\[/code\]and i just get NullReferenceException was UnhandledObject reference not set to an instance of an object.because the m_xmld.selectsinglenode is null
 
Back
Top