?
Solved

Parsing an XML File from a StreamReader

Posted on 2009-07-16
2
Medium Priority
?
1,254 Views
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'?>
<?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>

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

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
        '?propertyName=VCAT&messagetype=RESULT&transactionId=50&Status=SUCCESS
        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
        Try
            ReadXML(reader)
            If IsNumeric(pmsId) Then
                OC.NewRecord()
                OC.pmsID = CLng(pmsId)
                OC.MemberNr = memberNr
                OC.messageType = resultMsgType
                OC.TransID = CLng(Request.QueryString("transactionId"))
                OC.Save()
            Else
                ER.NewRecord()
                ER.ErrorText = "pmsId=" & pmsId & ", memberNr=" & memberNr & ", ResultMsgType=" & resultMsgType
                ER.ErrorLocation = "PageLoad"
                ER.Save()
            End If
        Catch ex As Exception
 
            ER.NewRecord()
            ER.ErrorText = ex.Message
            ER.ErrorLocation = "PageLaod"
            ER.Save()
        End Try
 
    End Sub
    Private Sub ReadXML(ByVal inReader As StreamReader)
        Try
            Dim m_xmld As XmlDocument
            Dim m_node As XmlNode
            resultMsgType = ""
            pmsId = ""
            memberNr = ""
 
            m_xmld = New XmlDocument()
            m_xmld.Load(inReader)
            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.NewRecord()
            ER.ErrorText = ex.Message
            ER.ErrorLocation = "ReadXML"
            ER.Save()
        End Try
    End Sub
End Class

Open in new window

0
Comment
Question by:RDWaibel
[X]
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
2 Comments
 
LVL 15

Accepted Solution

by:
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
        doc.LoadXml(str)
        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

0
 
LVL 14

Author Closing Comment

by:RDWaibel
ID: 31604335
BEERS on ME!

Works perfectly!

Thank you SO MUCH!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

765 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