xml-serialization

Control XML serialization of Dictionary<K, T>

北战南征 提交于 2019-12-24 23:15:38
问题 I'm investigating about XML serialization, and since I use lot of dictionary, I would like to serialize them as well. I found the following solution for that (I'm quite proud of it! :) ). [XmlInclude(typeof(Foo))] public class XmlDictionary<TKey, TValue> { /// <summary> /// Key/value pair. /// </summary> public struct DictionaryItem { /// <summary> /// Dictionary item key. /// </summary> public TKey Key; /// <summary> /// Dictionary item value. /// </summary> public TValue Value; } ///

Javascript XMLSerializer case sensitive

别来无恙 提交于 2019-12-24 23:04:52
问题 I'm generating a KML document in Javascript and i'm trying to use XMLSerializer to generate the XML file but it's generating all lower case tags even though i create the tags in capital in the DOM. Is it the DOM that mangles the capitalization or the XMLSerializer? Is there any way to get around it or am I missing something? I've tried this in both Chrome and Firefox. The KML document is to be imported into Google Earth and it seems it doesn't accept lower case tags. 回答1: Based on testing in

How to Deserialize XML in c# having child nodes of same type

不想你离开。 提交于 2019-12-24 19:56:27
问题 I need to deserialize bellow XML. The chapter element can have multiple child chapter element in it.I have tried to deserialize the XML using XmlSerializer. All the elements are deserializing as expected but the issue is that the child Chapter array is not deserializing, am I missing something here? Please help. <Survey> <SurveyResults> <Subject> <Chapter> <ChapterIterationName /> <Questions /> <Chapter> <ChapterName>CHAPTER 1</ChapterName> <ChapterIterationName /> <Questions> <Question>

Weird behavior during Image byte array serialization

无人久伴 提交于 2019-12-24 19:03:40
问题 I've run into an annoying problem with some code I use to serialize an image's byte array to XML and back again, when reading the bytes back after deserialization there are constant changes in certain bytes. My code is image format agnostic but for the case in point i'm using a PNG image (i've tested on several png files). The serialize code: var serializer = new XmlSerializer(instance.GetType()); using (var sw = new StringWriter()) { serializer.Serialize(sw, instance); return sw.ToString();

Is XML Serialization in .Net case sensitive?

夙愿已清 提交于 2019-12-24 16:27:30
问题 I did not find any documentation which explicitly states whether XML serialization is case-sensitive or not. Suppose I have following class: class Test { public int Field; public string field; } Will I have any problems when XML serializing this class becuase it contains two fields having same name differing only in case? CLARIFICATION: I KNOW its bad to have two fields with same name differing only by case and i am NOT designing such a beast. I am battling a beast let loose on me by another

XmlSerializer attribute namespace for element type dt:dt namespace

前提是你 提交于 2019-12-24 16:26:07
问题 I'm looking for the XmlSerializer functionality to re-create some namespace/type info in my output XML. So I have to replicate XML output like this to an old COM application: <Amount dt:dt="int">500</Amount> <StartTime dt:dt="dateTime">2014-12-30T12:00:00.000</StartTime> I currently set the attributes of my properties like so: [XmlElement(ElementName = "Amount", Namespace = "urn:schemas-microsoft-com:datatypes", DataType = "int", Type = typeof(int))] public int Amount{ get; set; } With my

Serialize object along with static member variables to XML [duplicate]

断了今生、忘了曾经 提交于 2019-12-24 16:16:52
问题 This question already has answers here : Serialize a Static Class? (6 answers) Closed 6 years ago . I have the following object that contains a static member variable. What I would like to do is serialize this object and save it to XML. Unfortunately, the code below does not seem to do the job. I would appreciate any help in getting this working please. [Serializable] public class Numbers { public int no; public static int no1; public SubNumbers SubNumber; } [Serializable] public class

Property of a List<T> Not Deserialized

早过忘川 提交于 2019-12-24 13:42:50
问题 The property FilePattern does not get deserialized from the xml: <Parser FilePattern='*'/> [Serializable(), XmlRoot("Parser")] public class Parser : List<System.DateTime> { private string _FilePattern; [XmlAttribute()] public string FilePattern { get { return _FilePattern; } set { _FilePattern = value; } } } private void ParserTest() { Parser Parser = Serialization.Deserialize("<Parser FilePattern='*'/>", typeof(Parser)); // Here, Parser.FilePattern is null } Parser is just a class. How can I

.NET XML serialization

荒凉一梦 提交于 2019-12-24 12:43:38
问题 I would like to serialize and deserialize mixed data into XML. After some searches I found out that there were two ways of doing it: System.Runtime.Serialization.Formatters.Soap.SoapFormatter and System.Xml.Serialization.XmlSerializer . However, neither turned out to match my requirements, since: SoapFormatter doesn't support serialization of generic types XmlSerializer refuses to serialize types that implement IDictionary , not to mention that it's far less easy-to-use than "normal"

How to Serialize/DeSerialize a Dictionary variable?

删除回忆录丶 提交于 2019-12-24 11:58:33
问题 I have a Dictionary variable, the program reads XML files, and then instantiates objects stored in the Dictionary variable by type for performance. I would like to store the Dictionary variable to memcache for reuse, but, because the Dictionary variable and instantiated objects are reference types, when I operate instantiated objects to change some value, the cache value of memcache also changed. Code like the following. Dictionary variable and XPathNavigator variable of class can't serialize