Link to home
Start Free TrialLog in
Avatar of JJKing
JJKingFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Get xml data

Hi

I have the following xml document and I want to retrieve the <env:identity> value. I am using VB.Net and have code to try and extract the data but I cannot seem to get it to work.

Any Ideas ?

<Envelope xmlns="http://www.intentia.com/MBM" xmlns:env="http://www.intentia.com/MBM_Envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://www.intentia.com/MBM Prototype_Order.xsd">
      <Header>
            <env:delivery>
                  <env:to>
                        <env:address>Movex</env:address>
                  </env:to>
                  <env:from>
                        <env:address>Eprocurement</env:address>
                  </env:from>
                  <env:reliability>
                        <env:sendReceiptTo>
                        </env:sendReceiptTo>
                        <env:receiptRequiredBy>
                        </env:receiptRequiredBy>
                  </env:reliability>
            </env:delivery>
            <env:properties>
                  <env:identity>100QDP
                  </env:identity>
                  <env:sentAt></env:sentAt>
                  <env:expiresAt>
                  </env:expiresAt>
                  <env:topic></env:topic>
            </env:properties>
            <env:manifest>
                  <env:reference uri="#BasdaOrder@1">
                        <env:description></env:description>
                  </env:reference>
            </env:manifest>
            <env:process>
                  <env:type>0</env:type>
                  <env:instance>
                  </env:instance>
                  <env:handle>
                  </env:handle>
            </env:process>
      </Header>
      <Body>
    <Order xmlns="urn:schemas-basda-org:2000:purchaseOrder:xdr:3.01" xmlns:xdr="XDR-compat-v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:schemas-basda-org:2000:purchaseOrder:xdr:3.01 Order-v3.xsd">
</Order>
</Body>
</Envelope>
Public Function RetrieveXMLNodeData() As String
        Try
            RetrieveXMLNodeData = Nothing
            Dim doc As New XmlDocument
            doc.Load(MyDocPath)
            Dim root As XmlElement = doc.DocumentElement
            Dim Nmspc = New XmlNamespaceManager(doc.NameTable)
            Nmspc.AddNamespace("A", "env:http://www.intentia.com/MBM_Envelope")
            RetrieveXMLNodeData = root.SelectSingleNode("A:properties/A:identity",  nmspc).InnerText
Catch ex As Exception
            Throw ex
        End Try
    End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dimitris
Dimitris
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JJKing

ASKER

Thanks for that it worked like a dream and I can edit the value as well