c# - Deserilization of XML file with  Reserved characters -
when serialize object in xml file reserved characters mentioned in xml below under element "jobdesc"
deserializing of same xml file these characters gives me
error:-system.invalidoperationexception unhandled
q. have deserialize object...what doing wrong???????
xml file
<?xml version="1.0"?> <datacheck xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <joblist> <job> <jobid>500</jobid> <jobdate>1/1/2013</jobdate> <jobdesc>test app </jobdesc> </job> </joblist> </datacheck> serialize code in c#
xmlserializer ser = new xmlserializer(typeof(datacheck)); using (filestream objfs = new filestream(@"c:\\test.xml", filemode.create)) { ser.serialize(objfs, objdatacheck); } deserialize code in c#
datacheck dc;
filestream fs1 = new filestream(@"c:\test.xml", filemode.open); xmlserializer xs = new xmlserializer(typeof(datacheck)); dc = (datacheck)xs.deserialize(fs1);
that not valid xml. characters may not present in xml, either entity references (like ) nor actual characters.
this xml can made valid using cdata:
<?xml version="1.0"?> <datacheck xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <joblist> <job> <jobid>500</jobid> <jobdate>1/1/2013</jobdate> <jobdesc><![cdata[test app ]]></jobdesc> </job> </joblist> </datacheck>
Comments
Post a Comment