c# - How to use LINQ to determine if specific attribute value exists? -


i programming in c# , working xdocument. want add element tree if , if there no other elements have matching attribute value.

for example, there linq expression can use @ element below , see if there exists foo element same name before add it?

<people>     <foo name="bob"> </foo>     <foo name="larry"></foo>     <foo name="tom"></foo> </people> 

i want this...

while(myxdocument.element("people").elements("foo").attribute("name").contains(myname)) {     // modify myname , try again... } 

this should work:

xelement.any(element => element.attribute("name").value == myname) 

it return true if there's attribute name equals myname


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -