code_junkie

How to determine if XElement.Elements() contains a node with a specific name?

Nov 11th, 2011
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.20 KB | None | 0 0
  1. <Order>
  2. <Phone>1254</Phone>
  3. <City>City1</City>
  4. <State>State</State>
  5. </Order>
  6.  
  7. bool hasCity = OrderXml.Elements("City").Any();
  8.  
  9. from x in XDocument
  10. where x.Elements("City").Count > 0
  11. select x
Add Comment
Please, Sign In to add comment