Sunday, 2 November 2014

Why WriteAllText Method Saves XML with special Characters?



When saving the XML string as a file, I get a wrong output XML with special characters. The "<" and ">" tags are replace with &lt; and &gt; respectively.


XML String:



<string xmlns="http://smartpark.com/">
<DocumentElement>
<SpaceInfo>
<R_Numb>490</R_Numb>
<FirstName>Michael</FirstName>
<LastName>Jones</LastName>
<Unit>311</Unit>
<Type>RG</Type>
<Location>FLOOR 1</Location>
<Feature>C</Feature>
<Space>100</Space>
<Status>Assigned</Status>
<DateAssigned>2014-09-24T00:00:00-05:00</DateAssigned>
</SpaceInfo>
</DocumentElement>
</string>


Saving Method:



System.IO.File.WriteAllText(Server.MapPath("testing.xml"), urlText,Encoding.UTF8);

No comments:

Post a Comment