Hi,
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");
Element1.SetAttributeNode(Value1);
Value1.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");

doc.AppendChild(rootElement);

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

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

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

elementWithAttribute.Attributes.Append(valueAttribute);

rootElement.AppendChild(elementWithAttribute);

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, networking, learning, and sharing knowledge.