473,507 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Obtain Full Path of XML Node

Hi All!

How can I obtain the full XML path of any given XML Node? For example,
if my XML document looks like this:

---BEGIN XML DOC---
<Tag1>
<Tag2>
<Tag3></Tag3>
</Tag2>
</Tag1>
---END XML DOC---

And my code looks like this:

---BEGIN VB6 CODE---
Dim objCustNode As MSXML2.IXMLDOMNode
Dim objCustNodeList As MSXML2.IXMLDOMNodeList

objCustXML.Load("myFile.xml")
Set objCustNodeList = objCustXML.selectNodes("//*")
For Each objCustNode In objCustNodeList
Debug.Print objCustNode.nodeName
Next
---END VB6 CODE---

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".

How can I do this? Thank you!

Apr 4 '06 #1
1 2398
> 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
Apr 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
7323
by: Sam | last post by:
Hi, I can use System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() to obtain the path for ILASM.exe, but how can I obtain the path to ILDASM.exe? Examples of the path I'm...
3
3148
by: Philipp Schumann | last post by:
Hi, I have several nested layers of <node> element that are processed by an XSLT template. Is there any possibility to determine the depth of a node in the overall nesting hierarchy? For...
15
1860
by: SFX | last post by:
If I have a session ID (string) can I somehow obtain the session object associated to that ID (it exist of course) ? I know this sounds wicked but I have a situation in which I have to make a...
1
2295
by: Angus Lepper | last post by:
I'm writing a stock ticker for a stock market simulation, and can load the data into the xmlreader in the first place, but can't figure out how to refresh/update the data in it. Any ideas? Code:...
13
9033
by: André Nogueira | last post by:
Hi there. I know you can view a node's fullpath property, but is it posible to select a node using its path? Like, tell the treeview that the node that should be selected is the node with the...
2
1644
by: Yarik | last post by:
Hello, I am not sure the subject of my post adequately describes the problem I am trying to solve, so I think a specific example would be helpful. Let's say there are XML descriptions of...
1
4430
by: VictorG | last post by:
Hello, The below C# code works fine in obtaining the windows user's account SID when the user is local to the machine. It throws a "Not Found" exception when trying top obtain the SID for a...
3
4316
by: xeqister | last post by:
Hi, I have a DB2 database (version 7) running on Windows 2000 server and recently facing problem to backup my database. I got an error "Disk was full" after half way running the backup. My...
2
2125
by: kumho | last post by:
Anyone knows how to obtain the full path of the processes running and the modules loaded into the processes by using WMI and Batch..? And then I wanna display them with a tree structure as below:...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.