how to read value of an xml node (single) using linq to xml

Posted by Wondering on Stack Overflow See other posts from Stack Overflow or by Wondering
Published on 2010-05-08T12:32:48Z Indexed on 2010/05/08 12:38 UTC
Read the original article Hit count: 438

Filed under:
|
|
|

Hi All, I have a xml structure similar to below one:

              <test>
                <test1>test1 value</test1>
               </test>

Now I am reading the value of node using below LINQ to xml code.

        var test = from t in doc.Descendants("test") select t.Element("test1").Value;
        Console.WriteLine("print single node value");
        Console.WriteLine(test);

above code works fine, but here I have one single node, but to retrive value I am using foreach loop, which I dont think is good..any better way of doing the same thing without a foreach loop Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ