Thanks for that! Its really helped.
The reason for the XML in the attribute is that I am passing it as a
parameter to a stored procedure which then uses openxml to read from it.
--
McGeeky
http://mcgeeky.blogspot.com
"Martin Honnen" <mahotrash@yahoo.de> wrote in message
news:eVfL6UFRGHA.6084@TK2MSFTNGP14.phx.gbl...[color=blue]
>
>
> McGeeky wrote:
>
>[color=green]
>> 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 ) + "'/>";[/color]
>
> 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/[/color]