Tuesday, 9 December 2014

Get value of xml element in one line of code



What would be the best way to get a value of an xml element with one line of code?


I have XMl that looks like this:



<Property name="id" value="blahblahblahblah"/>


I would like to get just the blahblahblahblah portion and store it into a string variable.


right now I am able to get this line of xml by using XElement.



var teID = from el in linkedTeethInfo.DescendantsAndSelf("Property") where (string)el.Attribute("name") == "id" select el.Attributes("value").ToString();


Normally i would think that i could just add .value but that is not the case. Any ideas?


No comments:

Post a Comment