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. How to get XPath to XML node from treeview node?

How to get XPath to XML node from treeview node?

Scheduled Pinned Locked Moved Visual Basic
xmltutorialdatabasedata-structuresjson
3 Posts 2 Posters 2 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.
  • K Offline
    K Offline
    korell
    wrote on last edited by
    #1

    I have a treeview that was populated by using a recursive function to add nodes from an XML document to the tree. I want the user to be able to right-click on any node and get the xpath to that node (similar to the "Copy XPath" function in Altova XMLSpy.) At first I thought I could just use the XMLSpy API and call that function, but apparently it's not available. Has anybody written a "GetXPath" function, or have an idea how to approach this problem? By the way, using TreeView.SelectedNode.FullPath is not going to work in this case since it does not return a node index. For the example below, Treeview.SelectedNode.FullPath would simply return "/Report/Section/Content/Item/Title/Item", but I need "/Report/Section/Content/Item[3]/Title/Item" <Report>      <Section>           <Title>                <Item>Header</Item>           </Title>           <Content>                <Item>                     <Title>                          <Item>Title 1</Item>                     </Title>                </Item>                <Item>                     <Title>                          <Item>Title 2</Item>                     </Title>                </Item>                <Item>                     <Title>                   &n

    D 1 Reply Last reply
    0
    • K korell

      I have a treeview that was populated by using a recursive function to add nodes from an XML document to the tree. I want the user to be able to right-click on any node and get the xpath to that node (similar to the "Copy XPath" function in Altova XMLSpy.) At first I thought I could just use the XMLSpy API and call that function, but apparently it's not available. Has anybody written a "GetXPath" function, or have an idea how to approach this problem? By the way, using TreeView.SelectedNode.FullPath is not going to work in this case since it does not return a node index. For the example below, Treeview.SelectedNode.FullPath would simply return "/Report/Section/Content/Item/Title/Item", but I need "/Report/Section/Content/Item[3]/Title/Item" <Report>      <Section>           <Title>                <Item>Header</Item>           </Title>           <Content>                <Item>                     <Title>                          <Item>Title 1</Item>                     </Title>                </Item>                <Item>                     <Title>                          <Item>Title 2</Item>                     </Title>                </Item>                <Item>                     <Title>                   &n

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

      What about storing navigation information, for instance some index, in the Tag property of the Node? Regards: Didi

      K 1 Reply Last reply
      0
      • D DidiKunz

        What about storing navigation information, for instance some index, in the Tag property of the Node? Regards: Didi

        K Offline
        K Offline
        korell
        wrote on last edited by
        #3

        Thanks Didi, That's almost exactly what I did, except I store the entire XPath in the Name property of the treenode. Every time a treenode gets created, I call a function GetXPath(tvwNode, xmlNode) that stores the XPath for that node in the treeview node Name property. Sacha

        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