How to remove the attribute from XmlDocument if attribute exists in the document? Please help. I am using RemoveAttribute but how can I check if it exists.
root.RemoveAttribute(fieldName);
Thanks..
<?xml version="1.0" standalone="yes" ?>
<Record1>
<Attribute1 Name="DataFieldName" Value="Pages" />
</Record1>
I am trying to remove attribute named "DataFieldName".
youcan use XmlNamedNodeMap.RemoveNamedItem Method (name) to do it. It can be used to Attributes.It will return the XmlNode removed from this XmlNamedNodeMap or a null reference (Nothing in Visual Basic) if a matching node was not found.
Not sure exactly what you're trying to do, so here's two examples.
Removing the attribute:
Setting the attribute to an empty string:
Edit: I can try to modify my code if you elaborate on your original request. An XML document can only have one root node and yours appears to be record1. So does that mean your entire file will only contain a single record? Or did you mean to have something like