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. Visual Basic
  4. Parsing XML in VB.NET using XMLDocument

Parsing XML in VB.NET using XMLDocument

Scheduled Pinned Locked Moved Visual Basic
helpcsharpalgorithmsxml
3 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.
  • J Offline
    J Offline
    Jaggernaut
    wrote on last edited by
    #1

    Hello! I've got a piece of code where I need to parse a XML-file and store the data in a DataTable do modify and use the data from the file. I'm a bit stuck on the SelectNodes method. If I have a XML file that looks like this:

        146413
        DataExport
        1.0.0
        x4
        2011-08-23T00:01:45.2367404+02:00
    

    The following code works like a charm:

     Dim xd As XmlDocument
     Dim xnl As XmlNodeList
    
     xd = New XmlDocument()
     xd.Load(fileName)
     xnl = xd.SelectNodes("/MASTER.DATA/Envelope")
    

    BUT! The file doesn't exactly look like that. The MASTER.DATA actually looks like this:

    And all of a sudden I don't get bupkis with the above mentioned code. What am I doing wrong?? :confused: Any help is greatly appreciated. :) //Jagg

    Wexelblats algorithm: Pick two: 1. Good, 2. Fast, 3. Cheap

    L 1 Reply Last reply
    0
    • J Jaggernaut

      Hello! I've got a piece of code where I need to parse a XML-file and store the data in a DataTable do modify and use the data from the file. I'm a bit stuck on the SelectNodes method. If I have a XML file that looks like this:

          146413
          DataExport
          1.0.0
          x4
          2011-08-23T00:01:45.2367404+02:00
      

      The following code works like a charm:

       Dim xd As XmlDocument
       Dim xnl As XmlNodeList
      
       xd = New XmlDocument()
       xd.Load(fileName)
       xnl = xd.SelectNodes("/MASTER.DATA/Envelope")
      

      BUT! The file doesn't exactly look like that. The MASTER.DATA actually looks like this:

      And all of a sudden I don't get bupkis with the above mentioned code. What am I doing wrong?? :confused: Any help is greatly appreciated. :) //Jagg

      Wexelblats algorithm: Pick two: 1. Good, 2. Fast, 3. Cheap

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I'm not sure whether the dot in the name of your rootnode is allowed. I'd go for a name without a dot.

      (more stuff)

      The query below should work;

      xnl = xd.SelectNodes("//MASTERDATA/Envelope")

      Or, to get a specific piece;

      xnl = xd.SelectNodes("//MASTERDATA/Envelope[MessageId='146413']")

      Hope this helps :)

      Bastard Programmer from Hell :suss:

      J 1 Reply Last reply
      0
      • L Lost User

        I'm not sure whether the dot in the name of your rootnode is allowed. I'd go for a name without a dot.

        (more stuff)

        The query below should work;

        xnl = xd.SelectNodes("//MASTERDATA/Envelope")

        Or, to get a specific piece;

        xnl = xd.SelectNodes("//MASTERDATA/Envelope[MessageId='146413']")

        Hope this helps :)

        Bastard Programmer from Hell :suss:

        J Offline
        J Offline
        Jaggernaut
        wrote on last edited by
        #3

        Hi, thanks for the reply. However, that didn't work either. It works as soon as I remove all the other definitions (xmlns:xsi, xsi:schemaLocation and xmlns) from the MASTER.DATA (or MASTERDATA) but as soon as they are in the file it goes completely blank. I don't get any errors, I just don't find anything. Regarding removing the dot (MASTER.DATA) it's probably not possible, this file gets sent automatically from one of our back end systems. :sigh:

        Wexelblats algorithm: Pick two: 1. Good, 2. Fast, 3. Cheap

        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