How to deserialized xml containing hexadecimal.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi i got error this error
{System.InvalidOperationException: There is an error in XML document (3, 19). ---> System.Xml.XmlException: , hexadecimal value 0x17, is an invalid character. Line 3, position 19.<br/>
at System.Xml.XmlTextReaderImpl.Throw(Exception e)<br/>
at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)<br/>
at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String[] args)<br/>
at System.Xml.XmlTextReaderImpl.ParseNumericCharRefInline(Int32 startPos, Boolean expand, StringBuilder internalSubsetBuilder, Int32& charCount, EntityType& entityType)<br/>
at System.Xml.XmlTextReaderImpl.ParseCharRefInline(Int32 startPos, Int32& charCount, EntityType& entityType)<br/>
at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)<br/>
at System.Xml.XmlTextReaderImpl.ParseText()<br/>
at System.Xml.XmlTextReaderImpl.ParseElementContent()<br/>
at System.Xml.XmlTextReaderImpl.Read()<br/>
at System.Xml.XmlTextReader.Read()<br/>
at System.Xml.XmlReader.ReadElementString()<br/>
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderInfoItemPropertySetExtraData.Read2_InfoItemPropertySetExtraData(Boolean isNullable, Boolean checkType)<br/>
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderInfoItemPropertySetExtraData.Read3_InfoItemPropertySetExtraData()<br/>
--- End of inner exception stack trace ---<br/>
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)<br/>
at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)<br/>
at ConsoleApplication1.Utils.DeserializeFromXml(String xml, Type objectType) in C:UsersAdministratordocumentsvisual studio 2010ProjectsConsoleApplication1ConsoleApplication1Utils.cs:line 46}


string text = "<?xml version=1.0 encoding=utf-16?>rn<InfoItemPropertySetExtraData xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema>rn <NameProperty>Form: Links&#x17;¹Oÿ¯úÿ¾@&#x1;</NameProperty>rn
<DescriptionProperty>Form: Links&#x17;¹Oÿ¯úÿ¾@&#x1;</DescriptionProperty>rn <DisplayNameProperty>Id</DisplayNameProperty>rn <IsTemplate>false</IsTemplate>rn</InfoItemPropertySetExtraData>";
var deserialized = Utils.DeserializeFromXml(text, typeof(InfoItemPropertySetExtraData));
public static object DeserializeFromXml(string xml, Type objectType)<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre if (xml == null)<br/>
<span style="white-space:pre throw new NullReferenceException("xml");<br/>
<br/>
<br/>
<span style="white-space:pre if (objectType == null)<br/>
<span style="white-space:pre throw new NullReferenceException("objectType");<br/>
<span style="white-space:pre
<br/>
<span style="white-space:pre XmlSerializer serializer;<br/>
<span style="white-space:pre using (var sr = new StringReader(xml))<br/>
<span style="white-space:pre {<br/>
try<br/>
{<br/>
serializer = new XmlSerializer(objectType);<br/>
return serializer.Deserialize(sr); // // Exception occurs from here<br/>
}<br/>
catch (Exception ex)<br/>
{<br/>
return null;<br/>
}<br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre }<br/>
<br/>



View the full article
 
Back
Top