xml-serialization

Xml Serialisation - Default Constructor

时间秒杀一切 提交于 2019-12-25 13:15:38
问题 I have a number of classes which derive from an abstract base class. These derived classes need to be serialised to XML however, they do not have a parameter-less constructor. There are a large number of derived class, so I would prefer not to have to go back and add a parameter-less constructor to them all. I am hoping there's something I can do with the base class that will allow them to be serialised without having to modify each individual class. Anyone got any idea's on how this can be

How to serialize an included object/property as a root?

回眸只為那壹抹淺笑 提交于 2019-12-25 08:28:04
问题 I've got a tough problem. Let's say I have a class named ObjectHost , containing a property of type BusinessObject , which itself contains some properties (let's say a Name and a Town as strings). The code would be : public class ObjectHost { public BusinessObject Data { get; set; } public ObjectHost() { Data = null; } public ObjectHost(BusinessObject ei) { Data = ei; } public override string ToString() { return (Data == null) ? "null" : Data.ToString(); } } When serializing, it will produce

How to locally save model object on MVC 4?

和自甴很熟 提交于 2019-12-25 06:57:52
问题 I have a model on MVC project and suitable xml document , which gets from web service and it will be deserialized with type of my model. And I will get deserialized object and work with it. How to save locally changes in this model object? 回答1: The design of your persistence layer depends alot on the purpose of your applciation, and the lifetime of the objects persisted. A NoSQL solution would provide a simple way to serialize/deserialize objects your application. MVC 4 pushes Entity

How to XML serialize and deserialize an instance of Dictionary <type, List<Action<T>>>?

情到浓时终转凉″ 提交于 2019-12-25 06:55:26
问题 I want to serialize and deserialize my dictionary object of type Dictionary <type, List<Action<T>>> . I tried using XMLserializer - it fails. Cannot serialize member MyClass.MyDictionary of type System.Collections.Generic.Dictionary‘2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], because it implements IDictionary. I am using .NET framework 4.0. What is

Serialize Base Class Implementation for all “new” Properties

て烟熏妆下的殇ゞ 提交于 2019-12-25 06:10:06
问题 I have a bunch of classes that were auto-generated from an XSD, and provided to me in a compiled DLL for which I don't have the source code. I have a need to add interfaces to each of the types, which resulted in code such as the following: public interface IBar { string SomeProperty { get; set; } } public interface IFoo<TBar> where TBar : IBar { TBar Bar { get; set; } } public class BarWrapper : BarFromXSD, IBar { } public class FooWrapper : FooFromXSD, IFoo<BarWrapper> { [XmlElement("bar")]

Serialize Base Class Implementation for all “new” Properties

夙愿已清 提交于 2019-12-25 06:08:23
问题 I have a bunch of classes that were auto-generated from an XSD, and provided to me in a compiled DLL for which I don't have the source code. I have a need to add interfaces to each of the types, which resulted in code such as the following: public interface IBar { string SomeProperty { get; set; } } public interface IFoo<TBar> where TBar : IBar { TBar Bar { get; set; } } public class BarWrapper : BarFromXSD, IBar { } public class FooWrapper : FooFromXSD, IFoo<BarWrapper> { [XmlElement("bar")]

C# Deserialize XML to object: There is an error in XML document (3, 2)

风流意气都作罢 提交于 2019-12-25 05:29:12
问题 I'm trying to deserialize XML into a C# object I am getting the error:There is an error in XML document (3, 2). Cannot seem to fix it! Here is the code: The XSD is: <?xml version="1.0" encoding="utf-8" ?> <!--Created with Liquid XML Studio 2012 Developer Edition (Trial) 10.0.2.3955 (http://www.liquid-technologies.com)--> <xs:schema xmlns:tns="http://www.adamroe.com/xsd/cameras.xsd" elementFormDefault="qualified" targetNamespace="http://www.adamroe.com/xsd/cameras.xsd" xmlns:xs="http://www.w3

net xmlserializer : keeping attributes order

人盡茶涼 提交于 2019-12-25 05:22:30
问题 I can sucessfully able to write my class Item in a xml file. But the orders of atttributes change... Suppose I have Item class class Item { Name Price Id } when I write it to xml file using .net xmlserializer I get different order from my class decleration such as <Item Price="y" Name="x" Id="z" /> But I want it like this [ keep decleration order] <Item Name="x" Price="y" Id="z" /> How can İ do it in NET? 回答1: You shouldn't be concerend with the order. If you are, then you are not processing

net xmlserializer : keeping attributes order

泪湿孤枕 提交于 2019-12-25 05:22:13
问题 I can sucessfully able to write my class Item in a xml file. But the orders of atttributes change... Suppose I have Item class class Item { Name Price Id } when I write it to xml file using .net xmlserializer I get different order from my class decleration such as <Item Price="y" Name="x" Id="z" /> But I want it like this [ keep decleration order] <Item Name="x" Price="y" Id="z" /> How can İ do it in NET? 回答1: You shouldn't be concerend with the order. If you are, then you are not processing

Serialize a generic collection specifying element names for items in the collection

♀尐吖头ヾ 提交于 2019-12-25 04:49:07
问题 I have a simple class derived from a generic list of string as follows: [Serializable] [System.Xml.Serialization.XmlRoot("TestItems")] public class TemplateRoleCollection : List<string> { } when I serialize this, I get the following XML: <TestItems> <string>cat</string> <string>dog</string> <string>wolf</string> </TestItems> Is there any way to override the xml element name which is used for serializing items in the collection? I would like the following xml to be produced: <TestItems>