Having looked at various popular modules for working with XML / XPath, I have not yet seen a direct way to achieve this.
Essentially, the interface will look something like this:
my $xpath = get_path($node1, $node2);
... which returns the relative path from $ node1 to $ node2.
I include my own time in the calculation of "efficiency" - I will take any existing solution to this problem. Otherwise, I would like to know some of the pitfalls that can be encountered in any "obvious" home solutions.
At the top of my head, I could just imagine the first search for $ node2 in the descendants of $ node1, and then with the error that the fighters $ node1 do the same. How I fear it will be just as resource intensive?
In my particular use case, I can assume that the absolute paths of both $ node1 and $ node2 are known. Given this, I would like to think that there is some kind of “XPath math” that can be done between two full paths without having to run all over the tree, but I don’t know what this process will look like.
Summarizing:
1) Do any existing CPAN modules do what I want to do easily?
2) If not, what is the effective way to do this?
source share