Reputation: 10672
I want to add attributes only when it is not exist.
Upvotes: 1
Views: 1625
Reputation: 71
Check out: http://egeveke.blogspot.com/2006/09/xpathnavigator-missing-setattribute.html
Basically you use MoveToAttribute, testing if it was successful. If not, then it does not exist and you can create. Remember to either start with a clone of you navigator, or move back to the parent when you are successful.
if (nav.MoveToAttribute())
{
// exists
nav.MoveToParent();
}
else
{
nav.CreateAttribute(...);
}
Upvotes: 2
Reputation: 99
Use "HasAttributes" property on the Xpathnavigator object to check whether it has any attributes and then continue to do your operation. Hope this helps!!
Upvotes: 0
Reputation: 50018
Check out Insert XML Data using XPathNavigator. Specifically the section Inserting Attribute Nodes
Upvotes: 0