Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 August 17th, 2004, 09:09 AM
Registered User
 
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting XPath Expression from XmlDocument ?

Hello,

Is there an easy way of getting an XPath expression to where you are in an XML document ? I am parsing an XMLDocument using an XmlTextReader. When I reach a new element, I`d like to be able to compute the XPath to that element as something like:

article[1]/section[2]/p[6]

Does anyone know of a simple solution

.:BoeManE:.

 
Old August 17th, 2004, 10:46 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

This isn't a definitive answer but...

You should be able to traverse backwards up thru the hierarchy by using ".ParentNode" or what ever the property is, and get the node index of each node in succession. That along with the name of the current node in the traversal process should get you what you need.
 
Old August 24th, 2004, 08:23 AM
Registered User
 
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by planoie
 This isn't a definitive answer but...

You should be able to traverse backwards up thru the hierarchy by using ".ParentNode" or what ever the property is, and get the node index of each node in succession. That along with the name of the current node in the traversal process should get you what you need.
Thank. I managed to do this with a bit of XPath manipulation. Turns out it was only 6 lines of code to do the whole calculations :)

.:BoeManE:.

 
Old August 31st, 2004, 04:44 PM
Authorized User
 
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 1 Time in 1 Post
Default

I am a little confused as to why you would want to do this. Can you post an example of what you did and/or are still trying to do?

The reason for my question is that a DataSet will read a XML file and parse it for you. This makes working with XML files a breeze, but if you have a specific reason for need the depth or something I would be interested in the design pattern.

Thanks,

www.CoderForRent.com
Get A Computer Job!





Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath 2.0 every expression stolte XSLT 5 November 24th, 2008 03:32 PM
XPath Expression NEO1976 XSLT 11 August 2nd, 2006 02:28 AM
Need help with XPATH Expression benomathew XSLT 1 May 12th, 2006 04:41 AM
Need help with XPATH Expression benomathew XML 1 May 9th, 2006 03:38 PM
Logical XPath Expression rohit72 XML 0 June 23rd, 2004 11:29 AM





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