• 0

C#: Getting an XPath expression from XmlDocument ?


Question

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

5 answers to this question

Recommended Posts

  • 0

You'll have to implement your own tracking code. XmlReader is just a forward reading XML scanner, that also checks for correctness of the XML file, but nothing more. There are derived classes that perform validation too, but that's about it.

  • 0
  Tom Servo said:
You'll have to implement your own tracking code. XmlReader is just a forward reading XML scanner, that also checks for correctness of the XML file, but nothing more. There are derived classes that perform validation too, but that's about it.

I was afraid of that. :cry:

Thanks for your help though!

.:BoeManE:

  • 0

Check this out (a link that just might help). It helped me with some stuff I was doing and it comes straight from a microsoft dude. Some of the code didn't work for me in C#. It's cool thought cause it'll give you the path from any given node. However, I think you have to have an XmlDocument loaded and not an XmlReader.

  • 0
  MrRogers said:
Check this out (a link that just might help). It helped me with some stuff I was doing and it comes straight from a microsoft dude. Some of the code didn't work for me in C#. It's cool thought cause it'll give you the path from any given node. However, I think you have to have an XmlDocument loaded and not an XmlReader.

Thank you very much. I will definately have a closer look at this!

.:BoeManE:.

  • 0
  boemane said:
Thank you very much. I will definately have a closer look at this!

.:BoeManE:.

Hey.

I have now fixed the problem. I managed to reduce the code calculate the xpath expression to only 6 lines!

If anyone is interested, drop me a line joachim (at) devsiden (dot) info

.:BoeManE:.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.