McGeeky wrote:
Does the .Net library have a conversion method that does this? Note that I
want to construct the resulting XML string myself without having to use an
XmlDocument.
E.g.
string myXml = "<root><record/><record/></root>";
string myDoc = "<doc myXml='" + Converter.escapeMyXml (myXml ) + "'/>";
Sure, you should always use XmlTextWriter if you want to construct/write
some XML, here is a simple example:
string myXml = "<root><record/><record/></root>";
StringWriter stringWriter = new StringWriter();
XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
xmlWriter.WriteStartElement("doc");
xmlWriter.WriteAttributeString("myXml", myXml);
xmlWriter.WriteEndElement();
xmlWriter.Flush();
xmlWriter.Close();
string xml = stringWriter.ToString();
Console.WriteLine("XML created is:\r\n{0}", xml);
Result then is e.g.
<doc myXml="<root><record/><record/></root>" />
So .NET provides all what you need. Only I have doubts that putting XML
escaped into an attribute is usually a good idea as that way it loses
its structure and is plain text for any XML tool.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/