Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 17th, 2004, 09:09 AM
Registered User
 
Join Date: Aug 2004
Location: Kangaroo Point, QLD, Australia.
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:.

Reply With Quote
  #2 (permalink)  
Old August 17th, 2004, 10:46 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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.
Reply With Quote
  #3 (permalink)  
Old August 24th, 2004, 08:23 AM
Registered User
 
Join Date: Aug 2004
Location: Kangaroo Point, QLD, Australia.
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:.

Reply With Quote
  #4 (permalink)  
Old August 31st, 2004, 04:44 PM
Authorized User
 
Join Date: Jul 2004
Location: , , .
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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:56 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.