I program in C # and work with XDocument. You want to add an element to the tree if and only if there are no other elements that have the corresponding attribute value.
For example, is there a LINQ expression that I can use to look at the element below and see if the foo element with the same name already exists before I add it?
<people>
<foo Name="Bob"> </foo>
<foo Name="Larry"></foo>
<foo Name="Tom"></foo>
</people>
I want to do something like this ...
while(myXDocument.Element("people").Elements("foo").Attribute("Name").Contains(myName))
{
// modify myName and then try again...
}
source
share