[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

recieving XML data from another system

I have a web form that I have created where I need to recieve data from a remote server. the server is being sent to me as XML data through a URL that I have. How do I send a request on page load for this data and then store the recieved XML data as a dataset or usable data on my web form? I have never done this before and have no idea how to begin.
0
NickMalloy
Asked:
NickMalloy
  • 2
1 Solution
 
Fred GoodwinVP of Software DevelopmentCommented:
is this an xml web service you are using?

the dataset has a readxml you can use.

Dim ds as dataset
ds = new dataset

ds.readxml("path to xml as string or xml stream")

That will make a table representation of the xml structure.  The DS will contain 1 to many tables that you can use just as you would any other datatable or dataset.  So you could bind the datatebles to datagrids or gridviews depending on your version of the framework.
0
 
NickMalloyAuthor Commented:
The person I am working with told me.  You can think of it as an XML web service – its doing the function like a XML web service would
0
 
Fred GoodwinVP of Software DevelopmentCommented:
so you can do something like this with a web service


        Dim dr As DataRow
        Dim dt As New DataTable
        Dim nodeChild As XmlNode
        Dim xdoc As New XmlDocument
        Dim MemberElem As XmlElement


   'PreAuthenticate the WebService
        Dim MyWebObj As WS.ClientInterviewWeb = New WS.WSCLass
        MyWebObj.PreAuthenticate() = True
        MyWebObj.Credentials = System.Net.CredentialCache.DefaultCredentials

        Try
           'call your function that returns XML.  This code calls a web method and passes it a param of 43
            xdoc.LoadXml(MyWebObj.WebServiceMethod(43))

            'Create the DataTable layout
            dt.Columns.Add(New DataColumn("MemberID", GetType(String)))
            dt.Columns.Add(New DataColumn("SSN", GetType(String)))
            dt.Columns.Add(New DataColumn("FirstName", GetType(String)))
            dt.Columns.Add(New DataColumn("LastName", GetType(String)))
            dt.Columns.Add(New DataColumn("MaidenName", GetType(String)))
            dt.Columns.Add(New DataColumn("BirthDate", GetType(String)))

            'parse the xml into a datatable.  This uses an XML structure that looks like this <xmlrow MEMBERID="1"  SSN="222-22-2222" FIRSTNAME="Joe" LASTNAME="Doe" MAIDENNAME="" />  
            'This is case sensitive.
            For Each nodeChild In xdoc.FirstChild.ChildNodes

                dr = dt.NewRow

                dr(0) = nodeChild.Attributes("MEMBERID").Value.ToString
                dr(1) = nodeChild.Attributes("SSN").Value.ToString
                dr(2) = nodeChild.Attributes("FIRSTNAME").Value.ToString
                dr(3) = nodeChild.Attributes("LASTNAME").Value.ToString
                dr(4) = nodeChild.Attributes("MAIDENNAME").Value.ToString
                dr(5) = nodeChild.Attributes("BIRTHDATE").Value.ToString

                dt.Rows.Add(dr)

            Next

        Catch ex As Exception
               throw ex
        Finally
            MyWebObj.Dispose()
        End Try

        Return dt
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now