The following function combines the two existing methods to support the SetAttribute.
void SetAttribute(
System.Xml.XPath.XPathNavigator navigator,
String prefix, String localName,
String namespaceURI,
String value)
{
if (navigator.CanEdit == true)
{
// Check if given localName exist
if (navigator.MoveToAttribute(localName, namespaceURI))
{
// Exist, so set current attribute with new value.
navigator.SetValue(value);
// Move navigator back to beginning of node
navigator.MoveToParent();
}
else
// Does not exist, create the new attribute
navigator.CreateAttribute(prefix, localName, namespaceURI, value);
}
}
Happy coding,
Edwin