Parsing an XML File from a StreamReader

Posted on 2009-07-16
Last Modified: 2012-06-27
I have an interface that sends data to a web page (GXI.aspx) The XML Sent looks like :

<?xml version = '1.0'?>
<RESULT xmlns="result.fidelio.1.0" success="SUCCESS">
   <resultMessage>Successfully updated profile in Opera.</resultMessage>
      <ResultId resultMsgType="PROFILE">

I need a way to...
1)  Retrieve the <?LABEL Data
2)  Get the <ResultId resultMsgType >
3)  From the <ResultId>

My code is included below.
Imports System.IO

Imports system.xml

Partial Class GXI

    Inherits System.Web.UI.Page

    Dim pmsId As String, memberNr As String, resultMsgType As String

    Dim OC As New OperaComplete

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim ER As New GXIErrors

        Page.Response.ContentType = "text/xml"

        '// Read XML posted via HTTP


        Me.Label1.Text = Request.QueryString("propertyName")

        Me.Label2.Text = Request.QueryString("messageType")

        Me.Label3.Text = Request.QueryString("transactionId")

        Me.Label4.Text = Request.QueryString("Status")

        Dim reader As StreamReader = New StreamReader(Page.Request.InputStream)

        'Dim xmlText As String = reader.ReadToEnd



            If IsNumeric(pmsId) Then


                OC.pmsID = CLng(pmsId)

                OC.MemberNr = memberNr

                OC.messageType = resultMsgType

                OC.TransID = CLng(Request.QueryString("transactionId"))




                ER.ErrorText = "pmsId=" & pmsId & ", memberNr=" & memberNr & ", ResultMsgType=" & resultMsgType

                ER.ErrorLocation = "PageLoad"


            End If

        Catch ex As Exception


            ER.ErrorText = ex.Message

            ER.ErrorLocation = "PageLaod"


        End Try

    End Sub

    Private Sub ReadXML(ByVal inReader As StreamReader)


            Dim m_xmld As XmlDocument

            Dim m_node As XmlNode

            resultMsgType = ""

            pmsId = ""

            memberNr = ""

            m_xmld = New XmlDocument()


            m_node = m_xmld.SelectSingleNode("//RESULT/ResultIds/ResultId")

            resultMsgType = m_node.Attributes.GetNamedItem("resultMsgType").Value

            pmsId = m_node.ChildNodes.Item("pmsId").InnerText

            memberNr = m_node.ChildNodes.Item("memberNr").InnerText

        Catch ex As Exception

            Dim ER As New GXIErrors


            ER.ErrorText = ex.Message

            ER.ErrorLocation = "ReadXML"


        End Try

    End Sub

End Class

Open in new window

Question by:RDWaibel
LVL 15

Accepted Solution

jinal earned 500 total points
ID: 24871911

Dim str As String = "<?xml version = '1.0'?><?Label VCAT|RESULT|54|SUCCESS?><RESULT xmlns='result.fidelio.1.0' success='SUCCESS'><resortId>VCAT</resortId><resultMessage>Successfully updated profile in Opera.</resultMessage><ResultIds><ResultId resultMsgType='PROFILE'><pmsId>59020</pmsId><memberNr>SI-A-P-00120</memberNr></ResultId></ResultIds></RESULT>"

        Dim doc As New XmlDocument


        Dim node As XmlNode = doc.ChildNodes(1)  '<?Label VCAT|RESULT|54|SUCCESS?>

        Dim labelnodeval As String = node.InnerText

        Dim nodeResults As XmlNodeList = doc.DocumentElement.GetElementsByTagName("ResultId")

        If nodeResults.Count > 0 Then

            Dim valueofAttribute As String = nodeResults(0).Attributes("resultMsgType").InnerText

            Dim pmsId As String = nodeResults(0).ChildNodes(0).InnerText

            Dim memberNr As String = nodeResults(0).ChildNodes(1).InnerText

        End If

Open in new window

LVL 14

Author Closing Comment

ID: 31604335

Works perfectly!

Thank you SO MUCH!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows 10 IIS and Windows Authentication to SQL 21 53
Not showing page correctly 3 29
C# Single Form 8 26
Reset login password 4 25
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now