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. Querying with an XML document

Querying with an XML document

Scheduled Pinned Locked Moved XML / XSL
questioncsharpasp-netxml
12 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.
  • L led mike

    XPath

    //Country/Continent/text()[ancestor::*/CNo/text() = '?']

    replace the '?' charcter with the number for the selected country

    led mike

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

    Mike, Your query won't work. Since you know the country you can find the 'Country' child node of the parent (which happens to be 'Country' too), and, then, you can access its sibling 'Continent' node: //Country[Country='Afghanistan']/Continent

    V L 3 Replies Last reply
    0
    • G George L Jackson

      Mike, Your query won't work. Since you know the country you can find the 'Country' child node of the parent (which happens to be 'Country' too), and, then, you can access its sibling 'Continent' node: //Country[Country='Afghanistan']/Continent

      V Offline
      V Offline
      vinusk
      wrote on last edited by
      #4

      Thanks Mike, Will try out the solution you have suggested. Is there anyway I can do this using XMLTextReader... Regards, Vinu

      L G 2 Replies Last reply
      0
      • G George L Jackson

        Mike, Your query won't work. Since you know the country you can find the 'Country' child node of the parent (which happens to be 'Country' too), and, then, you can access its sibling 'Continent' node: //Country[Country='Afghanistan']/Continent

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #5

        George L. Jackson wrote:

        Your query won't work.

        It worked when I ran it. Is that what you mean?

        led mike

        1 Reply Last reply
        0
        • V vinusk

          Thanks Mike, Will try out the solution you have suggested. Is there anyway I can do this using XMLTextReader... Regards, Vinu

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #6

          vinusk wrote:

          can do this using XMLTextReader...

          I have not used XMLTextReader much so I do not know, but typically if you are going to query XML you use a DOM and SelectNodes(). I would normally use XmlDocument for that.

          led mike

          1 Reply Last reply
          0
          • G George L Jackson

            Mike, Your query won't work. Since you know the country you can find the 'Country' child node of the parent (which happens to be 'Country' too), and, then, you can access its sibling 'Continent' node: //Country[Country='Afghanistan']/Continent

            L Offline
            L Offline
            led mike
            wrote on last edited by
            #7

            Here is another

            //Country[CNo = '?']/Continent/text()

            XPath is pretty nice eh? :-D I always run these before I post them.

            led mike

            G V 2 Replies Last reply
            0
            • L led mike

              Here is another

              //Country[CNo = '?']/Continent/text()

              XPath is pretty nice eh? :-D I always run these before I post them.

              led mike

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

              :-> My bad! Your code didn't seem correct to me. I am sorry.

              L 1 Reply Last reply
              0
              • G George L Jackson

                :-> My bad! Your code didn't seem correct to me. I am sorry.

                L Offline
                L Offline
                led mike
                wrote on last edited by
                #9

                George L. Jackson wrote:

                Your code didn't seem correct to me.

                No sweat. It never seems right to me that's why I always run it. :laugh:

                led mike

                V 1 Reply Last reply
                0
                • V vinusk

                  Thanks Mike, Will try out the solution you have suggested. Is there anyway I can do this using XMLTextReader... Regards, Vinu

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

                  If you are using .NET Framework 1.1, it is XmlTextReader. If you are using .NET Framework 2.0, it is XmlReader. Anyway, you query differently with XmlTextReader/XmlReader since it uses a pull technique. However, you can get the same results but you have to do more coding. http://www.codeproject.com/useritems/XmlTextReader.asp[^]

                  1 Reply Last reply
                  0
                  • L led mike

                    George L. Jackson wrote:

                    Your code didn't seem correct to me.

                    No sweat. It never seems right to me that's why I always run it. :laugh:

                    led mike

                    V Offline
                    V Offline
                    vinusk
                    wrote on last edited by
                    #11

                    Thanks Mike and George. I will try it out and revert back. With warm regards, Vinu

                    1 Reply Last reply
                    0
                    • L led mike

                      Here is another

                      //Country[CNo = '?']/Continent/text()

                      XPath is pretty nice eh? :-D I always run these before I post them.

                      led mike

                      V Offline
                      V Offline
                      vinusk
                      wrote on last edited by
                      #12

                      Thanks got it working.:)

                      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