linq – Xpath best practices – Education Career Blog

I have a readonly xml file and I have a set of xpath values.
I need to create a function which would take in the xpath and return the value(s) corresponding to the xpath.

I am a little confused regarding what would be the best way to proceed. The options I am thinking are using the regular XPathDocument/Navigator/Iterator classes or using LINQ to xml.

The function I am trying to implement is:

T GetString(string inputXpath) where T could be bool/string/array etc.

Can someone help?Also, this function is going to be called all across the application, so performance might be a consideration.

Thank you!


What you want to write will just return:


Obviously, T must be just… object 🙂

Read the XpathNavigator.Evaluate() documentation here.

Leave a Comment