Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Parsing an XML File from a StreamReader

Posted on 2009-07-16
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 15

Accepted Solution

jinal earned 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

618 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