in memory generated XML contains \r\n characters

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<font size=2>
Hi all,
Im trying to serialize a tree object as XML and then persist the XML (in memory) into a SQL table.Im using the code below to generate the XML, a sample piece of generated  XML is :
"<?xml version="1.0" encoding="utf-8"?><DTreeNodeOfOBSTeam xmlns:xsi="<a title="http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance " xmlns:xsd=" http://www.w3.org/2001/XMLSchema rn http://www.w3.org/2001/XMLSchema rn
.... "
if you note youll see 1- <font face="Times New Roman" size=3>the whole text is wrapped in double quotes and i</font><font face="Times New Roman" size=3>t has rn characters. these make the string unreadable for my stored proc which accepts a text parameter to update the table. I assume I can solve this by removing the double quotes and rn characters but I dont know how! Please let me know how I can fix this issue or if Im doing anything wrong.</font>
<font face="Times New Roman" size=3>Thanks,</font>
<font face="Times New Roman" size=3>Code used to generate XML:</font>

System.Xml.Xsl.</font><font color="#008080" size=2>XslCompiledTransform</font><font size=2> transformer = </font><font color="#0000ff" size=2>new</font><font size=2> System.Xml.Xsl.</font><font color="#008080" size=2>XslCompiledTransform</font><font size=2>();
</font><font color="#008000" size=2> </font><font size=2>transformer.Load(mPath);
</font><font color="#008080" size=2>MemoryStream</font><font size=2> msOut = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>MemoryStream</font><font size=2>();
</font><font color="#008080" size=2>MemoryStream</font><font size=2> msIn = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>MemoryStream</font><font size=2>(); </font><font size=2>
m_data.ExportToMem(msIn);
msIn.Position = 0;
</font><font color="#008080" size=2>XmlReader</font><font size=2> xmlIn = </font><font color="#008080" size=2>XmlReader</font><font size=2>.Create(msIn);
xmlIn.MoveToContent();
transformer.Transform(xmlIn, </font><font color="#0000ff" size=2>null</font><font size=2>, msOut);
msIn.Close();
xmlIn.Close();
</font><font color="#0000ff" size=2>byte</font><font size=2>[] bytes = msOut.ToArray();
</font><font color="#0000ff" size=2>string</font><font size=2> transformedXml = </font><font color="#008080" size=2>Encoding</font><font size=2>.UTF8.GetString(bytes); </font><font size=2>

msOut.Close();
</font>

View the full article
 
Back
Top