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. XPath navigation with namespaces

XPath navigation with namespaces

Scheduled Pinned Locked Moved XML / XSL
xmlcomquestion
6 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.
  • S Offline
    S Offline
    Steven Campbell
    wrote on last edited by
    #1

    I have a program that uses xpath expressions to navigate an XPathDocument, e.g.

    dim iter as XPathNodeIterator = myNav.Select(myXpathExpression)

    Today, to make the XML source document easier to edit, I added a target namespace, i.e.

    <MyDocElement xmlns="http://x.y.com/abc/Mapping.xsd">

    . After I did this, my xpath expressions no longer work. Does anyone know what I need to do to make them work again? (Note that I am not using a namespace prefix).


    my blog

    D 1 Reply Last reply
    0
    • S Steven Campbell

      I have a program that uses xpath expressions to navigate an XPathDocument, e.g.

      dim iter as XPathNodeIterator = myNav.Select(myXpathExpression)

      Today, to make the XML source document easier to edit, I added a target namespace, i.e.

      <MyDocElement xmlns="http://x.y.com/abc/Mapping.xsd">

      . After I did this, my xpath expressions no longer work. Does anyone know what I need to do to make them work again? (Note that I am not using a namespace prefix).


      my blog

      D Offline
      D Offline
      DavidNohejl
      wrote on last edited by
      #2

      hi, I can remember I had similar problem long time ago... I can't recall how I solved that one, bt why are you not using namespace prefix? It should work with it and I see no reason why not to use it... :confused: best regards, David 'DNH' Nohejl Never forget: "Stay kul and happy" (I.A.)

      S 1 Reply Last reply
      0
      • D DavidNohejl

        hi, I can remember I had similar problem long time ago... I can't recall how I solved that one, bt why are you not using namespace prefix? It should work with it and I see no reason why not to use it... :confused: best regards, David 'DNH' Nohejl Never forget: "Stay kul and happy" (I.A.)

        S Offline
        S Offline
        Steven Campbell
        wrote on last edited by
        #3

        The xml file is large - originally generated, and then hand-modified. I do not want to use namespace prefixes unless I have to, as 1) they will bloat the file 2) it will take a while to edit the file


        my blog

        D 2 Replies Last reply
        0
        • S Steven Campbell

          The xml file is large - originally generated, and then hand-modified. I do not want to use namespace prefixes unless I have to, as 1) they will bloat the file 2) it will take a while to edit the file


          my blog

          D Offline
          D Offline
          DavidNohejl
          wrote on last edited by
          #4

          :doh: oh now I don't even know what I meant :confused: Try to add namespace prefix into XPath query. If it wont work say "DNH is idiot" (cuz i think there is no difference when you have namespace prefix in every element or only in parent) and look at link I provide you now; hopefully the answer will be here[^] I didn't read it all bt it looks promising. Here is quite late night so I'll leave it alone for now. plz if you'll find answer post it here.. In other case I'll look at it tomorrow... good luck, David Never forget: "Stay kul and happy" (I.A.)

          1 Reply Last reply
          0
          • S Steven Campbell

            The xml file is large - originally generated, and then hand-modified. I do not want to use namespace prefixes unless I have to, as 1) they will bloat the file 2) it will take a while to edit the file


            my blog

            D Offline
            D Offline
            DavidNohejl
            wrote on last edited by
            #5

            I finally found something what seems to be solution... [ snippet is from my website's rss feeder - i *think* it worked...] XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("ns",@"http://www.w3.org/1999/xhtml"); XmlNodeList newsNodes = doc.DocumentElement.SelectNodes("//ns:body/ns:form/ns:div[@class='parent']/ns:div[@class='contents']/ns:div[@class='news']",nsmgr); David Never forget: "Stay kul and happy" (I.A.)

            S 1 Reply Last reply
            0
            • D DavidNohejl

              I finally found something what seems to be solution... [ snippet is from my website's rss feeder - i *think* it worked...] XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("ns",@"http://www.w3.org/1999/xhtml"); XmlNodeList newsNodes = doc.DocumentElement.SelectNodes("//ns:body/ns:form/ns:div[@class='parent']/ns:div[@class='contents']/ns:div[@class='news']",nsmgr); David Never forget: "Stay kul and happy" (I.A.)

              S Offline
              S Offline
              Steven Campbell
              wrote on last edited by
              #6

              Yes! Thanks, that works great.


              my blog

              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