C#.Net - Getting Data from XML String

Good Day Experts!

I have been trying to find the best way to extract data from an XML string.  Unfortunately, I have not been able to getting any of the examples to work that I have found on the Net.  That coupled with the fact that it has to be done in C#.Net puts me behind the 8ball.  

Do you have any easy to understand/use example references?

I have attached a file with a screen print of the XML.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
First read to understand the terminology of XML:

Then look at this great tutorial for how to read XML in C#:

Let me know if you have more questions.
Fernando SotoRetiredCommented:

You can also use Linq to XML. If you already know Linq then it will be easier seeming you already know Linq language.

Getting Started with Link to XML

If you post which nodes you wish to get from the XML I can write up some Linq queries to help.
Jimbo99999Author Commented:
Hey Fernando:

I have the XML in the file attached to the opening question with a note in it pointing to which node I have to get to.

I do not know Linq...that would be great if you could outline as I always like to add new things to the toolbox.

Thanks for the help,
Fernando SotoRetiredCommented:
Hi Jimbo99999;

Here is how you can use Linq to XML to get the values of LMiles.
// Load the XML document from the file system
var xdoc = XDocument.Load(@"C:\Working Directory\xml10115.xml");
// If the XML document is in a string variable in the program then use this line and not the above
var xdoc = XDocument.Parse(VariableNameHere);

// Because the document uses Namespaces we need the default Namespace to access LMiles nodes
XNamespace dns = "http://pcmiler.alk.com/APIs/v1.0";
// Get LMiles nodes using Linq query
var result = (from lm in xdoc.Descendants(dns + "LMiles")
              select lm.Value).ToList();

// Seeming there are two LMiles nodes I was not sure if you wanted the other one as well.
// The nde values will always be in XML document order so if you want the second node value
// just access the second value in the result list like the following.
String LMilesVal = result[1];

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jimbo99999Author Commented:

Thanks for the Linq to XML assistance.  I will try it out now!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.