How to get XPath to XML node from treeview node?
-
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
-
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
-
What about storing navigation information, for instance some index, in the Tag property of the Node? Regards: Didi
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