Retrive Xpath for given text value from XML file.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ehasas
    New Member
    • Aug 2007
    • 3

    #1

    Retrive Xpath for given text value from XML file.

    Hello,
    I am trying to retrieve Xpath from the XML file for a given node value. I am doing this in VB and using "Microsoft XML, v4.0" library for XML parsing.

    How to find xpath from the xml data if we have a text value of node in VB?
    Also how can we find the Root Node of any XML data in VB?

    Please revet.
    Thanks in anticipation

    -ehasas
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    To be honest, I don't remember which functions Microsoft XML v 4.0 uses.

    Pseudocode might go something like:
    Dim text = "text I'm searching for";
    Dim target = document.Select SingleNode("//*[text()="+text+"]");

    Dim xpath = target.Name();
    while (target.Parent != NULL){
    target = target.Parent;
    xpath = target.Name() + "/" + xpath;
    }

    Comment

    Working...