Convert XMLDocument to String

Posted by mnh on Stack Overflow See other posts from Stack Overflow or by mnh
Published on 2010-03-09T07:31:26Z Indexed on 2010/03/09 7:36 UTC
Read the original article Hit count: 444

Filed under:
|
|
|
|

Here is how I'm currently converting XMLDocument to String

StringWriter stringWriter = new StringWriter();
XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);

xmlDoc.WriteTo(xmlTextWriter);

return stringWriter.ToString();

The problem with this method is that if I have " ((quotes) which I have in attributes) it escapes them.

For Instance:

<Campaign name="ABC">
</Campaign>

Above is the expected XML. But it returns

<Campaign name=\"ABC\">
</Campaign>

I can do String.Replace "\" but is that method okay? Are there any side-effects? Will it work fine if the XML itself contains a "\"

© Stack Overflow or respective owner

Related posts about c#

Related posts about xmldocument