Re: XmlTextWriter.WriteString and quoted chars

Christoph <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.general
Message-ID <[email protected]>
Sam,

The WriteRaw method on the XmlTextWrite will write out the string as you are
you are passing in, i.e. without making any conversions:

StringWriter sw = new StringWriter( new StringBuilder() );
XmlTextWriter xw = new XmlTextWriter( sw );
xw.Formatting = Formatting.Indented;
xw.WriteStartDocument();
xw.WriteStartElement( "", "foo", "");
xw.WriteRaw( " raw &amp; raw " );
xw.WriteEndElement();
Console.WriteLine( sw.GetStringBuilder().ToString() );

prints out:
<?xml version="1.0" encoding="utf-16"?>
<foo> raw &amp; raw </foo>

HTH,
Christoph Schittko
Software Architect
Mshow - a division of InterCall

----- Original Message -----
From: "Sam Gentile" <[email protected]>
To: <[email protected]>
Sent: Thursday, June 13, 2002 10:06 AM
Subject: [DOTNET] XmlTextWriter.WriteString and quoted chars


> This is a pretty simple question but I want to be able to write out
"&amp;"
> as part of an Xml string. The doc says:
> WriteString does the following
>
> The characters &, <, and > are replaced with &amp;, &lt;, and &gt;,
> respectively.
> So I get &amp;amp.
>
> How can I escape the characters?
>
>
>
> ---------------------
> Sam Gentile
> .NET Consultant
> Co-author: Wrox Visual C++ .NET: A primer for C++ developers
> BLOG: http://radio.weblogs.com/0105852/
> http://www.project-inspiration.com/sgentile/DotNet.htm
> http://www.project-inspiration.com/sgentile/
> ---------------------------
>
>
>
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at
http://explorer.msn.com/intl.asp.
>
> You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.