I’m trying to remove all elements that have attribute value that doesn’t start with specific text
Thanks to Jon Skeet I got the first part however some elements doesn’t contain this attribute, therefore I got NullReferenceExpection with the message: “Object reference not set to an instance of an object”
I added an extra check for null value but it still doesn’t work any idea?
elements =(from el in xmlFile.Root.Elements(elementName)
where ( !el.Attribute(attributeName).Value.Equals(DBNull.Value)
&& !el.Attribute(attributeName).Value.StartsWith(searchBeforeStar))
select el);
You have to test if your node contains the attribute before testing it.
Add
el.Attribute(attributeName) != null: