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
Post a Comment