xmlserializer

XmlSerializer won't serialize IEnumerable

谁都会走 提交于 2019-11-27 17:07:32
问题 I have an invocation logger that is intended to record all method calls along with the parameters associated with the method using XmlSerializer. It works well for most of the calls, but it throws an exception for all methods that has a parameter of IEnumerable type. For example, void MethodWithPlace( Place value ) would be serialized, but void MethodWithPlace( IEnumerable<Place> value ) would not. The exception is System.NotSupportedException: Cannot serialize interface System.Collections

xmlserializer strips xlink from xlink:html svg image tag

天大地大妈咪最大 提交于 2019-11-27 16:49:50
问题 I'm creating a javascript interface to dynamically add xlinked images to a map of a classroom. //declare the xlink namespace in the svg header xmlns:xlink="http://www.w3.org/1999/xlink" ... //the code to append the image var temp = document.createElementNS(svgns,"image"); temp.setAttributeNS(null,"x","0"); temp.setAttributeNS(null,"y","0"); temp.setAttributeNS(null,"height","80"); temp.setAttributeNS(null,"width","40"); temp.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",

C# - XML serialization of derived classes

六月ゝ 毕业季﹏ 提交于 2019-11-27 15:06:36
问题 I'm trying to serialize a List of multiple elements (Suppliers, Customers, Products, etc), all deriving from the same class (MasterElement) public class XMLFile { [XmlArray("MasterFiles")] public List<MasterElement> MasterFiles; ... } [XmlInclude(typeof(Supplier))] [XmlInclude(typeof(Customer))] public abstract class MasterElement { public MasterElement() { } } [XmlType(TypeName = "Supplier")] public class Supplier: MasterElement { public string SupplierID; public string AccountID; } [XmlType

Use the XmlInclude or SoapInclude attribute to specify types that are not known statically

一个人想着一个人 提交于 2019-11-27 12:57:55
I've got a very strange problem when working with .NET's XmlSerializer . Take the following example classes: public class Order { public PaymentCollection Payments { get; set; } //everything else is serializable (including other collections of non-abstract types) } public class PaymentCollection : Collection<Payment> { } public abstract class Payment { //abstract methods } public class BankPayment : Payment { //method implementations } AFAIK, there are three different methods to solve the InvalidOperationException that's caused by the serializer not knowing about the derived types of Payment .

XmlSerializer startup HUGE performance loss on 64bit systems

六月ゝ 毕业季﹏ 提交于 2019-11-27 12:45:24
I am experiencing a really HUGE performance loss while calling a simple XmlSerializer.Deserizlize() on a class with lots of fields. NOTE : I'm writing the code without Visual Studio, at home, so it may have some errors. My serializable class is flat and has hundreds of fields: [Serializable] class Foo { public Foo() { } [XmlElement(ElementName = "Field1")] public string Field1; // [...] 500 Fields defined in the same way [XmlElement(ElementName = "Field500")] public string Field500; } My application deserializes an input string (even small): StringReader sr = new StringReader(@"<Foo><Field1

Serialize object to element with attributes and children

做~自己de王妃 提交于 2019-11-27 12:33:14
问题 I wish to define classes that will produce the following xml using System.Xml.Serialization.XmlSerializer. I am struggling to get the items list, with attributes that does not contain a child 'container' element for 'item' elements. <?xml version="1.0" ?> <myroot> <items attr1="hello" attr2="world"> <item id="1" /> <item id="2" /> <item id="3" /> </items> </myroot> 回答1: with XmlSerializer things are either lists or they have members. To do that you need: [XmlRoot("myroot")] public class

XML (de)serialization invalid string inconsistent in c#?

烂漫一生 提交于 2019-11-27 11:58:55
问题 In C# (.net 4.0 and 4.5 / vs2010 and vs12) when I serialize an object containing a string having an illegal character using XMLSerializer, no error is thrown. However, when I deserialize that result, an "invalid character" error is thrown. // add to XML Items items = new Items(); items.Item = "\v hello world"; // contains "illegal" character \v // variables System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Items)); string tmpFile = Path

Wrap properties with CData Section - XML Serialization C#

旧时模样 提交于 2019-11-27 09:50:30
I need to serialize my object in such a way that the properties I want, would get wrapped around CData sections. I was hoping I could do something like this : public class Order { [JsonProperty] public int OrderId { get; set; } [JsonProperty] public string Name { get; set; } [JsonProperty] public int Type { get; set; } [JsonProperty] public decimal Amount { get; set; } [JsonProperty] public DateTime Date { get; set; } [DataMember] [JsonProperty] **[WrapCData]** public List<Option> ListB { get; set; } [DataMember] public List<string> ListC { get; set; } **[WrapCData]** public Product Product {

XmlInclude : List and array

半世苍凉 提交于 2019-11-27 08:58:08
问题 I have an object that have variables as object , and I want to serialize it in XML. To do so, I've added some XmlInclude attributes in order to manage all the types that can be used. [Serializable] [XmlInclude(typeof(short[]))] [XmlInclude(typeof(ushort[]))] [XmlInclude(typeof(int[]))] [XmlInclude(typeof(uint[]))] [XmlInclude(typeof(ulong[]))] [XmlInclude(typeof(long[]))] [XmlInclude(typeof(byte[]))] [XmlInclude(typeof(decimal[]))] [XmlInclude(typeof(float[]))] [XmlInclude(typeof(double[]))]

XML attribute not getting namespace prefix

ぃ、小莉子 提交于 2019-11-27 08:06:20
问题 I need to generate the following XML during serialization: (fragment) <IncidentEvent a:EventTypeText="Beginning" xmlns:a="http://foo"> <EventDate>2013-12-18</EventDate> <EventTime>00:15:28</EventTime> </IncidentEvent> The class in question looks like this: public class IncidentEvent { public string EventDate { get; set; } public string EventTime { get; set; } [XmlAttribute("EventTypeText", Namespace = "http://foo")] public string EventTypeText { get; set; } } It appears that the serializer is