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><rec ord/><record/></root>";
string myDoc = "<doc myXml='" + Converter.escap eMyXml (myXml ) + "'/>";
Sure, you should always use XmlTextWriter if you want to construct/write
some XML, here is a simple example:
string myXml = "<root><rec ord/><record/></root>";
StringWriter stringWriter = new StringWriter();
XmlTextWriter xmlWriter = new XmlTextWriter(s tringWriter);
xmlWriter.Write StartElement("d oc");
xmlWriter.Write AttributeString ("myXml", myXml);
xmlWriter.Write EndElement();
xmlWriter.Flush ();
xmlWriter.Close ();
string xml = stringWriter.To String();
Console.WriteLi ne("XML created is:\r\n{0}", xml);
Result then is e.g.
<doc myXml="<root ><reco rd/><reco rd/></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/