Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Obtain Full Path of XML Node

From: Joe Kesselman <keshlam-nospam@-------.--->
To: NULL
Date: 4/5/2006 12:40:00 AM

> At the point in the For Next loop where objCustNode.nodeName is equal
> to "Tag3", I want to know what's it's FULL path is, ie,
> "//Tag1/Tag2/Tag3".

If you want absolute path, you want to start with /, not //

It's fairly trivial to implement a non-namespace-aware version of this, 
walking up the node's ancestors and building up the path. Note that at 
each level you need to count the number of preceeding instances of nodes 
with the same type and name, since what you really want is more like
	/Tag1[1]/Tag2[4]/Tag3[2]

Properly supporting namespaces, unfortunately, is uglier, since the 
normal XPath syntax requires that the namespace bindings be given as 
prefixes but provides no syntax for declaring those prefixes. The ugly 
workaround is to generate something more like
	/child::*[localname()="Tag1" and namespace()="http://whatever"][1]
for each step.

An XSLT implementation of the non-namespace-aware version appeared in my 
DeveloperWorks article on using stylesheets to debug other stylesheets. 
It shouldn't be hard to implement it in any other language, and 
off-the-shelf implementations probably do exist though I've had no 
reason to go looking for one recently. I don't use VB so I can't give 
you any specific advice for that environment.



-- 
() ASCII Ribbon Campaign  | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent