[ACCEPTED]-How to select a specific node with LINQ-to-XML-linq-to-xml
Accepted answer
Assuming the ID is unique:
var result = xmldoc.Element("Customers")
.Elements("Customer")
.Single(x => (int?)x.Attribute("ID") == 2);
You could also 2 use First
, FirstOrDefault
, SingleOrDefault
or Where
, instead of Single
for different 1 circumstances.
I'd use something like:
dim customer = (from c in xmldoc...<Customer>
where c.<ID>.Value=22
select c).SingleOrDefault
Edit:
missed the c# tag, sorry......the 1 example is in VB.NET
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.