Buyanaa FreeDom
Buyanaa FreeDom

Reputation: 9

Read XML values using XmlDocument

I want to read value of this xml. For example get the value of *ram:Receive_Time*.

<?xml version="1.0"?>
<rsm:BidNoticeInformationDocumentResponse xmlns:rsm="urn:mn:org:eppd:data:standard:BidNoticeInformationDocumentResponse:1" xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:9" xmlns:ram="urn:mn:org:eppd:data:standard:ReusableAggregateBusinessInformationEntity:1" xmlns:sbd="urn:mn:org:eppd:data:standard:BidNoticeInformationResponse:1" xmlns:bdh="urn:mn:org:eppd:data:standard:BusinessDocumentHeaderSchemaModule:1" xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:mn:org:eppd:data:standard:BidNoticeInformationDocumentResponse:1..\Schema\DocSchema\BidNoticeInformationProxy.xsd">
  <bdh:BusinessDocumentHeader>
    <bdh:ResultDocument>
      <ram:Receive_Time>2013-06-12 11:03:06</ram:Receive_Time>
      <ram:Result_Code>0000</ram:Result_Code>
      <ram:Result_Message>SUCCESS</ram:Result_Message>
      <ram:TransmissionID>K20130612110301SSSSS</ram:TransmissionID>
    </bdh:ResultDocument>
  </bdh:BusinessDocumentHeader>
  <sbd:BidNoticeInformationResponse>
    <sbd:BidNoticeDocument>
      <ram:Name>Test Bid(Bid Number : 20110300001-00)</ram:Name>
      ....

I tried this method. But value is getting empty.

Dim xmlDoc As New XmlDocument()
        xmlDoc.Load("BidNoticeInformationResponse.xml")
        'MsgBox(xmlDoc.InnerXml)

        Dim sr As New System.IO.StringReader(xmlDoc.InnerXml)
        Dim doc As New Xml.XmlDocument
        doc.Load(sr)
        Dim reader As New Xml.XmlNodeReader(doc)

        While reader.Read()
            If (reader.IsStartElement) Then
                If (reader.Prefix & ":" & reader.LocalName = "ram:Receive_Time") Then
                    MsgBox(reader.Value)
                End If
            End If
        End While

Upvotes: 0

Views: 576

Answers (2)

Buyanaa FreeDom
Buyanaa FreeDom

Reputation: 9

In this case I've got the answer. It's working fine.

While reader.Read()

Dim type = reader.NodeType

If (type = XmlNodeType.Element) Then

If (reader.Prefix & ":" & reader.LocalName = "bdh:ResultDocument") Then
reader.ReadStartElement()
If (reader.Name = "ram:Receive_Time") Then
lblReceiveTime.Text = reader.ReadInnerXml.ToString.Trim
End If

If (reader.Name = "ram:Result_Code") Then
lblResultCode.Text = reader.ReadInnerXml.ToString.Trim
End If

If (reader.Name = "ram:Result_Message") Then
lblResultMessage.Text = reader.ReadInnerXml.ToString.Trim
End If

If (reader.Name = "ram:TransmissionID") Then
lblTransmissionID.Text = reader.ReadInnerXml.ToString.Trim
End If
End If
....

Upvotes: 0

CloudyMarble
CloudyMarble

Reputation: 37566

Try this (untested):

Sub Main()
    Dim xml = XDocument.Load("YourXmlDoc")
    Console.WriteLine("ram:Receive_Time: " & xml.<rsm:BidNoticeInformationDocumentResponse>.<bdh:BusinessDocumentHeader>.<bdh:ResultDocument>.<ram:Receive_Time>.Value)    
End Sub

And take a look at the doumentation

Upvotes: 1

Related Questions