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 DOM get current position Node

XML DOM get current position Node

Scheduled Pinned Locked Moved XML / XSL
xmlhtmldata-structureshelpquestion
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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    When i search a certain xml-file using "selectNodes("//ROOT/BLA")" and i receive the found nodes. Is it possible to get iterate through those found nodes and retrieve their current position in the xml-tree? (remember that this is DOM and not XSLT, so "position()" and all that crap won't work). Any help is greatly appriciated.

    P 1 Reply Last reply
    0
    • A Anonymous

      When i search a certain xml-file using "selectNodes("//ROOT/BLA")" and i receive the found nodes. Is it possible to get iterate through those found nodes and retrieve their current position in the xml-tree? (remember that this is DOM and not XSLT, so "position()" and all that crap won't work). Any help is greatly appriciated.

      P Offline
      P Offline
      Philip Fitzsimons
      wrote on last edited by
      #2

      by position I presume you mean name - you could use: XmlNodeList results = document.SelectNodes(""//root/bla"); foreach (XmlNode result in rtesults) {   Console.Write("found {0} value = '{1}'", GetNodeName(result), result.value); } string GetNodeName(XmlNode node) {   string result = node.LocalName;   if (node.Parent != null)     result = GetNodeName(node.Parent) + "/" + result;   return result; } if you want the position then just change the above function to count previousSiblings: string GetNodePosition(XmlNode node) {   int previousSiblings = 0;   for (XmlNode previous_node = node.PreviousSibling; previous_node != null; previous_node = previous_node.PreviousSibling)     previousSiblings++;   string result = previousSiblings.ToString();   if (node.Parent != null)     result = GetNodeName(node.Parent) + "/" + result;   return result; } hope this helps


      "When the only tool you have is a hammer, a sore thumb you will have."

      A 1 Reply Last reply
      0
      • P Philip Fitzsimons

        by position I presume you mean name - you could use: XmlNodeList results = document.SelectNodes(""//root/bla"); foreach (XmlNode result in rtesults) {   Console.Write("found {0} value = '{1}'", GetNodeName(result), result.value); } string GetNodeName(XmlNode node) {   string result = node.LocalName;   if (node.Parent != null)     result = GetNodeName(node.Parent) + "/" + result;   return result; } if you want the position then just change the above function to count previousSiblings: string GetNodePosition(XmlNode node) {   int previousSiblings = 0;   for (XmlNode previous_node = node.PreviousSibling; previous_node != null; previous_node = previous_node.PreviousSibling)     previousSiblings++;   string result = previousSiblings.ToString();   if (node.Parent != null)     result = GetNodeName(node.Parent) + "/" + result;   return result; } hope this helps


        "When the only tool you have is a hammer, a sore thumb you will have."

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        yeah...i thought i would have to write my own function to calculate the current position. I was hoping i overlooked something and that it was possible to retrieve the index/position directly from a found node. Thanks though, for your reply.

        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