xml-serialization

How to make XML deserialization faster?

不羁岁月 提交于 2021-01-27 05:38:16
问题 I have the following piece of code public static object XmlDeserialize(string xml, Type objType) { StringReader stream = null; XmlTextReader reader = null; try { XmlSerializer serializer = new XmlSerializer(objType); stream = new StringReader(xml); // Read xml data reader = new XmlTextReader(stream); // Create reader return serializer.Deserialize(reader); } finally { if(stream != null) stream.Close(); if(reader != null) reader.Close(); } } The object itself has been generated via xsd.exe and

How to make XML deserialization faster?

青春壹個敷衍的年華 提交于 2021-01-27 05:34:11
问题 I have the following piece of code public static object XmlDeserialize(string xml, Type objType) { StringReader stream = null; XmlTextReader reader = null; try { XmlSerializer serializer = new XmlSerializer(objType); stream = new StringReader(xml); // Read xml data reader = new XmlTextReader(stream); // Create reader return serializer.Deserialize(reader); } finally { if(stream != null) stream.Close(); if(reader != null) reader.Close(); } } The object itself has been generated via xsd.exe and

Serialize XML with XML string

旧时模样 提交于 2021-01-21 07:43:48
问题 I have to produce the following XML <object> <stuff> <body> <random>This could be any rondom piece of unknown xml</random> </body> </stuff> </object> I have mapped this to a class, with a body property of type string. If I set the body to the string value: " <random>This could be any rondom piece of unknown xml</random> " The string gets encoded during serialization. How can I not encode the string so that it gets written as raw XML? I will also want to be able to deserialize this. 回答1:

Predefine XML namespaces for DataContractSerializer

此生再无相见时 提交于 2020-12-25 00:02:57
问题 I'm building a self hosted WCF service. I'm building a special data structure for a very flexible transport of data. So far I test if my structure is serializable using the DataContractSerializer. That works fine and I'm happy about that, but there is something annoying me: In my XML output are dozens redefined xmlns attributes e.g.: xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:b="http://www.w3.org/2001/XMLSchema" This should be better defined once in the root

Predefine XML namespaces for DataContractSerializer

試著忘記壹切 提交于 2020-12-24 23:56:07
问题 I'm building a self hosted WCF service. I'm building a special data structure for a very flexible transport of data. So far I test if my structure is serializable using the DataContractSerializer. That works fine and I'm happy about that, but there is something annoying me: In my XML output are dozens redefined xmlns attributes e.g.: xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:b="http://www.w3.org/2001/XMLSchema" This should be better defined once in the root

How to customize dictionary serialization with DataContractSerializer?

狂风中的少年 提交于 2020-07-22 22:11:17
问题 Dictionary serialization with DataContractSerializer generate below data. How to replace d2p1:KeyValueOfintint , d2p1:Key and d2p1:Value with our own attributes / tags / identifier. Serializing Dictionary in [CashCounter], Output Generate after Serialization given below <CashCounter xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DictionarySerlization"> <BankNote xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> <d2p1

Using XML decorations to specify default values during de-serialization

久未见 提交于 2020-06-09 16:57:11
问题 I have a problem deserializing some XML; the XML supplied by a third party is quite verbose, so if there is no value set for an particular element, it will supply and empty element (e.g. <element1 /> ). This is a problem for certain elements, for example, those that are meant to store integers. I have control over the third party, so I could either get them to specify a default value ( <myinteger>0</myinteger> ) or I can get them to omit these elements entirely. Both of these should avoid the

Using XML decorations to specify default values during de-serialization

好久不见. 提交于 2020-06-09 16:56:09
问题 I have a problem deserializing some XML; the XML supplied by a third party is quite verbose, so if there is no value set for an particular element, it will supply and empty element (e.g. <element1 /> ). This is a problem for certain elements, for example, those that are meant to store integers. I have control over the third party, so I could either get them to specify a default value ( <myinteger>0</myinteger> ) or I can get them to omit these elements entirely. Both of these should avoid the

Using XML decorations to specify default values during de-serialization

亡梦爱人 提交于 2020-06-09 16:56:07
问题 I have a problem deserializing some XML; the XML supplied by a third party is quite verbose, so if there is no value set for an particular element, it will supply and empty element (e.g. <element1 /> ). This is a problem for certain elements, for example, those that are meant to store integers. I have control over the third party, so I could either get them to specify a default value ( <myinteger>0</myinteger> ) or I can get them to omit these elements entirely. Both of these should avoid the