I have this xml structure:
<Departments>
<Department Id="a Guid" IsVisible="True" />
</Departments>
I have created the xml file with:
<Departments />
Now I want to add a bool value to IsVisible for a certain Id
If that Id does not exist in the xml file I want to make an insert creating
a new Department with Id + IsVisible.
My first problem starts here:
XElement dep= xDoc.Descendants("Departments").Descendants("Department")
.Where(d => d.FirstAttribute.Value == Id).FirstOrDefault();
if (dep != null)
{
// The node <Department ... /> exist
}
Error message: The Id does not exist in the current context
Of course it does not but that is the reason why I want to check for....
Also how can I check for the Id and compare it with my Id from another List?
Above I ask .Value == Id but I want also compare the value and if its true return the node.
Really I have an XLinq book before me but nothing helped. What a bad buy with non-practical samples (Linq for Visual C# 2008)