Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 10th, 2009, 08:38 PM
Registered User
 
Join Date: Dec 2009
Posts: 3
Thanks: 4
Thanked 0 Times in 0 Posts
Default How to get full path of an XML node?

Hi,

Is there a technique to return the fullpath of an XML node? Ideally, I could use something similar to the treeview controls .GetFullPath method. Any guidance greatly appreciated.

My objective is to dynamically discover the lowest level in the XML structure to guide subsequent processing. The 'fullpath' approach is the best method I can think of at the moment. If anyone can provide an alternate method to 'skin the cat' I'd love to hear it.

Thanks,

Scott
 
Old December 11th, 2009, 05:28 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The question is often asked, and different people who ask it want different things. Some people want:

a/b/c/d/e

that is, a path containing the names of the ancestor elements (easily achieved in XSLT 2.0 with string-join(ancestor-or-self::*/name(), '/')).

Some people want

a[1]/b[3]/d[4]

that is, a path that identifies an element uniquely.

And in either case, people may or may not want the result to be namespace-sensitive. This is where things get difficult: name() returns a lexical QName that cannot be used to retrieve the node again unless you know the original namespace bindings. If you want a path that can be evaluated without a namespace context, then you have two choices:

*[1]/*[3]/*[4]

or

*[namespace-uri()='http://1/' and local-name()='a'][1]/*[namespace-uri()='http://2/' and local-name()='b'][3]/....
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
swheeler (December 11th, 2009)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting the full path of a folder vamshikrishnaD ASP.NET 1.0 and 1.1 Professional 3 August 2nd, 2007 09:16 PM
Retrieve numbered node path from xml jeft0nes XSLT 6 July 20th, 2007 03:59 PM
how to call file using full path labby C# 2005 4 September 27th, 2006 11:25 PM
Retrive full path name from uploaded file itsp PHP How-To 3 June 10th, 2003 07:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.