I am writing some data to a particular xml file .There is one element for which the attribute value contains & ,
eg :

XmlAttribute value=doc.CreateAttribute("Value");

Output: <Element1 Value="&amp;quot;">

What is the escape sequence for printing an & in an xml file ??

Recommended Answers

All 2 Replies

When you are setting the value of the attribute, you don't have to worry about the xml escape sequence, just the c# escape sequence \". Try the following code:

var doc = new XmlDocument();

var rootElement = doc.CreateElement("root");


var elementWithAttribute = doc.CreateElement("child");

var valueAttribute = doc.CreateAttribute("value");

valueAttribute.Value = "&\"Hello World\"";



var xmlStr = doc.InnerXml;

// at this point, the value of xml string is: 
// <root><child value="&amp;&quot;Hello World&quot;" /></root>

hey thank yo so much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.