开发者

I have a custom type which I want to serialize, this custom type accepts input which might consists of escape chars

I have a custom type which I want to serialize, this custom type accepts input which might consists of escape chars.

M1_Serilizer(MyCustomType customTypeObj)
{
    XmlSerializer serializer = new XmlSerializer(typeof(MyCustomType));
    StringWriter sw = new StringWriter(CultureInfo.InvariantCulture);
    serializer.Serialize(sw, customTypeObj);
    string str= sw.ToString();
    M2_Deserializer(str);
}

M2_Deserializer(string str)
{
    XmlSerializer serializer = new XmlSerializer(typeof(MyCustomType));
    StringReader sr = new StringReader(str);
    MyCustomType customTypeObj = (MyCustomType)serializer.Deserialize(sr);
}

----------Exception details----------

When client configues input obj as <FieldName>PRINTLINE00</FieldName>

<FieldValue>DENIAL STATE 217</FieldValue>, I get an exception when the same data deserialised:

Exception is:- Message: There is an error in XML document (6, 22).

 String:
 <?xml version="1.0" encoding="utf-16"?>

 <InputEntry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema">
     <Fields>
         <Field>
             <FieldName>PRINTLINE00</Fiel开发者_StackOverflow社区dName>
             <FieldValue>&#x1B;DENIAL STATE 217</FieldValue>
        </Field>
     </Fields>
 </InputEntry>

 --------------------

When escape type chars are part of the CustomTypeObj, on deserialization it throws an exception.

Question 1) How do I overcome this?,

Question 2) I should use StringReader and StringWriter and not memorystream or other ways. StringWriter/reader will only serve my internal functionality.

Question 3) How can these escape chars be handled?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜