Reputation: 299
I am assigning some string value to an attribute of the node which contains & symbol. In the Xml output I am getting ampersand in place of & How can I avoid that?
Here is the code that I have written :
XmlAttribute attr=doc.CreateAttribute("name");
attr.Value ="me&mine";
node.Attributes.Append(attr);
itemnode.AppendChild(node);
doc.Save(path);
I am getting output like
<add name="me&mine"/>
Upvotes: 1
Views: 4744
Reputation: 62532
That's the correct behaviour! If your encoding didn't take place you end up with badly formed xml.
When you load the XML back into your application the &
will be converted back to a &
character without you having to do anything about it.
Upvotes: 2
Reputation: 38129
That would be the correct output (in fact, it would be invalid as XML if the ampersand wasn't encoded)
Upvotes: 6