Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XML data parsing

XML data parsing

Scheduled Pinned Locked Moved XML / XSL
csharpxmljsonquestion
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bemahesh
    wrote on last edited by
    #1

    Hi, I have a windows application that calls a web service. Web service returns a string response like I have to parse this string and get the values returned in etc. Number of ids returned by web service will depend on ABC number being passed. if user passed let's say 10 as ABC number then 10 ID's will be returned with string repeated 10 times with separatge Unique ID in each string. I want to retrive these values from the string that I have up in this message. How can I do that. Also, I am using vb.net. I would appreciate code sample in vb.net etc. Thanks Needy

    D 1 Reply Last reply
    0
    • B bemahesh

      Hi, I have a windows application that calls a web service. Web service returns a string response like I have to parse this string and get the values returned in etc. Number of ids returned by web service will depend on ABC number being passed. if user passed let's say 10 as ABC number then 10 ID's will be returned with string repeated 10 times with separatge Unique ID in each string. I want to retrive these values from the string that I have up in this message. How can I do that. Also, I am using vb.net. I would appreciate code sample in vb.net etc. Thanks Needy

      D Offline
      D Offline
      Dustin Metzgar
      wrote on last edited by
      #2

      Take the string that you get back and turn it into an XmlDocument:

      Dim s as String = ...
      Dim doc as XmlDocument = New XmlDocument()
      doc.LoadXml(s)

      The difficulty is in the namespace. You have to take a few extra steps to do an XPath:

      Dim xnm as XmlNamespaceManager
      xnm = new XmlNamespaceManager(doc.NameTable)
      xnm.AddNamespace("v1", "http://abc/2005/response")
      Dim nodes as XmlNodeList
      nodes = doc.SelectNodes("//v1:ABCs/v1:ABC", xnm)

      This gives you a collection of the "v1:ABC" nodes. Run that code and you'll see that nodes.Count is equal to the number of those "v1:ABC" nodes.


      Logifusion[^]

      B 1 Reply Last reply
      0
      • D Dustin Metzgar

        Take the string that you get back and turn it into an XmlDocument:

        Dim s as String = ...
        Dim doc as XmlDocument = New XmlDocument()
        doc.LoadXml(s)

        The difficulty is in the namespace. You have to take a few extra steps to do an XPath:

        Dim xnm as XmlNamespaceManager
        xnm = new XmlNamespaceManager(doc.NameTable)
        xnm.AddNamespace("v1", "http://abc/2005/response")
        Dim nodes as XmlNodeList
        nodes = doc.SelectNodes("//v1:ABCs/v1:ABC", xnm)

        This gives you a collection of the "v1:ABC" nodes. Run that code and you'll see that nodes.Count is equal to the number of those "v1:ABC" nodes.


        Logifusion[^]

        B Offline
        B Offline
        bemahesh
        wrote on last edited by
        #3

        it is giving me a null reference exception. when i get a count on nodes selected, it gives me number of nodes correctly. However, when i try to loop through the node list i am not able to get the values of the nodes Dim xNode As XmlNode Dim ValuesString As String For Each xNode In nodes ValuesString = xNode.Attributes.GetNamedItem("v1:ABC").Value Next I will want to receive these values and store them in database Please let me know what is wrong with my code. Line in bold is is where i am getting null reference exception. Thanks Needy

        D 1 Reply Last reply
        0
        • B bemahesh

          it is giving me a null reference exception. when i get a count on nodes selected, it gives me number of nodes correctly. However, when i try to loop through the node list i am not able to get the values of the nodes Dim xNode As XmlNode Dim ValuesString As String For Each xNode In nodes ValuesString = xNode.Attributes.GetNamedItem("v1:ABC").Value Next I will want to receive these values and store them in database Please let me know what is wrong with my code. Line in bold is is where i am getting null reference exception. Thanks Needy

          D Offline
          D Offline
          Dustin Metzgar
          wrote on last edited by
          #4

          Instead of "v1:ABC", you should be asking for the attribute "v1:ID". That's the name of the attribute.


          Logifusion[^]

          B 1 Reply Last reply
          0
          • D Dustin Metzgar

            Instead of "v1:ABC", you should be asking for the attribute "v1:ID". That's the name of the attribute.


            Logifusion[^]

            B Offline
            B Offline
            bemahesh
            wrote on last edited by
            #5

            I just found that out while debugging. thank you so much for your response. Out of curioucity, can I automatically fill up a datatable or dataset out of it? Because I will be calling a stored procedure to update the database with the ID values pulled from the xml string. thanks a lot for your response. I was stuck on this issue for a long time. Thanks Needy -- modified at 16:38 Thursday 22nd June, 2006

            D 1 Reply Last reply
            0
            • B bemahesh

              I just found that out while debugging. thank you so much for your response. Out of curioucity, can I automatically fill up a datatable or dataset out of it? Because I will be calling a stored procedure to update the database with the ID values pulled from the xml string. thanks a lot for your response. I was stuck on this issue for a long time. Thanks Needy -- modified at 16:38 Thursday 22nd June, 2006

              D Offline
              D Offline
              Dustin Metzgar
              wrote on last edited by
              #6

              Yes, you can create a DataSet off of the same string:

              Dim ds As DataSet = New DataSet()
              ds.ReadXml(New StringReader(s))

              Where "s" is the string again. StringReader is in the System.IO namespace. Just use the debugger to examine the contents of the DataSet. You'll see tables in there matching the XML elements.

              B 1 Reply Last reply
              0
              • D Dustin Metzgar

                Yes, you can create a DataSet off of the same string:

                Dim ds As DataSet = New DataSet()
                ds.ReadXml(New StringReader(s))

                Where "s" is the string again. StringReader is in the System.IO namespace. Just use the debugger to examine the contents of the DataSet. You'll see tables in there matching the XML elements.

                B Offline
                B Offline
                bemahesh
                wrote on last edited by
                #7

                v1:tcid="11111" xmlns:v1="http://abc/2005/response"> Hi, Dustin. I learned how to deal with node lists from your posts yesterday. I apprecidate your help. I need to get the value in which is basically v1:tcid="11111", Please shed the light again. Thanks Needy

                D 1 Reply Last reply
                0
                • B bemahesh

                  v1:tcid="11111" xmlns:v1="http://abc/2005/response"> Hi, Dustin. I learned how to deal with node lists from your posts yesterday. I apprecidate your help. I need to get the value in which is basically v1:tcid="11111", Please shed the light again. Thanks Needy

                  D Offline
                  D Offline
                  Dustin Metzgar
                  wrote on last edited by
                  #8

                  Well, v1:ABCMerchant is your document element. You could either ask for the document element, or search for it with XPath. doc.DocumentElement.Attributes("v1:tcid") -or- doc.SelectSingleNode("ABCMerchant", xnm).Attributes("v1:tcid") You should do some reading up on XPath: http://www.w3schools.com/xpath/default.asp[^]


                  Logifusion[^]

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups