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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. XML / XSL
  4. Problem with XPathNavigator

Problem with XPathNavigator

Scheduled Pinned Locked Moved XML / XSL
helpxml
8 Posts 3 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.
  • R Offline
    R Offline
    RoadieGS
    wrote on last edited by
    #1

    I am attempting to extract some data from the xml below with the following code: XPathDocument xmlDoc = new XPathDocument(URL that I supply); XPathNavigator nav = xmlDoc.CreateNavigator(); nav.Select("/ISBNdb/BookList/BookData/AuthorsText"); Console.WriteLine(nav.Value); The problem is the value returned is all of the elements concatenated together: Applied Microsoft. NET framework programming in Microsoft Visual Basic. NETJeffrey Richter, Francesco BalenaRedmond, Wash. : Microsoft Press, c2003. I have tried everthing and have no idea why I am getting this behavior. Any help would be greatly appreciated. Thanks. Gary This is the xml that is loaded into the XPathDocument: Applied Microsoft. NET framework programming in Microsoft Visual Basic. NET Jeffrey Richter, Francesco Balena Redmond, Wash. : Microsoft Press, c2003. -- modified at 10:50 Friday 5th May, 2006

    J 1 Reply Last reply
    0
    • R RoadieGS

      I am attempting to extract some data from the xml below with the following code: XPathDocument xmlDoc = new XPathDocument(URL that I supply); XPathNavigator nav = xmlDoc.CreateNavigator(); nav.Select("/ISBNdb/BookList/BookData/AuthorsText"); Console.WriteLine(nav.Value); The problem is the value returned is all of the elements concatenated together: Applied Microsoft. NET framework programming in Microsoft Visual Basic. NETJeffrey Richter, Francesco BalenaRedmond, Wash. : Microsoft Press, c2003. I have tried everthing and have no idea why I am getting this behavior. Any help would be greatly appreciated. Thanks. Gary This is the xml that is loaded into the XPathDocument: Applied Microsoft. NET framework programming in Microsoft Visual Basic. NET Jeffrey Richter, Francesco Balena Redmond, Wash. : Microsoft Press, c2003. -- modified at 10:50 Friday 5th May, 2006

      J Offline
      J Offline
      Josh Smith
      wrote on last edited by
      #2

      You should use the XPathNodeIterator which is returned from the Select method, not the Value of the navigator.

      private void Form1_Load(object sender, System.EventArgs e)
      {
      XPathDocument xmlDoc = new XPathDocument("..\\..\\data.xml");
      XPathNavigator nav = xmlDoc.CreateNavigator();
      XPathNodeIterator iter = nav.Select("/ISBNdb/BookList/BookData/AuthorsText");
      while( iter.MoveNext() )
      Console.WriteLine(iter.Current.Value);
      }

      Josh

      R 1 Reply Last reply
      0
      • J Josh Smith

        You should use the XPathNodeIterator which is returned from the Select method, not the Value of the navigator.

        private void Form1_Load(object sender, System.EventArgs e)
        {
        XPathDocument xmlDoc = new XPathDocument("..\\..\\data.xml");
        XPathNavigator nav = xmlDoc.CreateNavigator();
        XPathNodeIterator iter = nav.Select("/ISBNdb/BookList/BookData/AuthorsText");
        while( iter.MoveNext() )
        Console.WriteLine(iter.Current.Value);
        }

        Josh

        R Offline
        R Offline
        RoadieGS
        wrote on last edited by
        #3

        I tried that as well. I got the same exact result. Did it work correctly for you?

        J 1 Reply Last reply
        0
        • R RoadieGS

          I tried that as well. I got the same exact result. Did it work correctly for you?

          J Offline
          J Offline
          Josh Smith
          wrote on last edited by
          #4

          Yes

          R 1 Reply Last reply
          0
          • J Josh Smith

            Yes

            R Offline
            R Offline
            RoadieGS
            wrote on last edited by
            #5

            VS 2003 or VS 2005? I am using 2003. Any thoughts on why it would work for you and not me? Thanks!

            J 1 Reply Last reply
            0
            • R RoadieGS

              VS 2003 or VS 2005? I am using 2003. Any thoughts on why it would work for you and not me? Thanks!

              J Offline
              J Offline
              Josh Smith
              wrote on last edited by
              #6

              2003. I don't know what the difference could be. I posted the exact code that worked for me, so it must be an Act of God. :doh: Josh

              R 1 Reply Last reply
              0
              • J Josh Smith

                2003. I don't know what the difference could be. I posted the exact code that worked for me, so it must be an Act of God. :doh: Josh

                R Offline
                R Offline
                RoadieGS
                wrote on last edited by
                #7

                I enjoyed the sense of humor.

                G 1 Reply Last reply
                0
                • R RoadieGS

                  I enjoyed the sense of humor.

                  G Offline
                  G Offline
                  George L Jackson
                  wrote on last edited by
                  #8

                  I tried Josh's code in 1.1 and it worked as advertised!

                  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