xmlserializer

Will XmlSerializer ever create empty documents

浪尽此生 提交于 2019-12-02 06:30:51
问题 Alright, The following code I've had in production for over a year with no changes. It has been working quite well. Within the past month more then a handful machines report that the xml documents are completely empty. They do not even contain a xml header . I cannot duplicate the files suddenly being empty, nor can i suggest a way for it to happen. I am hoping someone has had a similar issue that they solved. Most of the machine that have been using this code have been using it for about a

XmlSerializer equivalent of IExtensibleDataObject

做~自己de王妃 提交于 2019-12-02 05:36:25
问题 With DataContracts you can derive from IExtensibleDataObject to allow round-tripping to work without losing any unknown additional data from your XML file. I can't use DataContract because I need to control the formatting of the output XML. But I also need to be able to read a future version of the XML file in the old version of the app, without losing any of the data from the XML file. e.g. XML v1: <Person> <Name>Fred</Name> </Person> XML v2: <Person> <Name>Fred</Name> <Age>42</Age> </Person

How to get an XML node value as string when deserializing

主宰稳场 提交于 2019-12-02 04:39:29
I am sending a XML to a aspnet core web api. The value for the namespace prefix cfdi: is defined in a containing node: <cfdi:Comprobante> <cfdi:Conceptos> </cfdi:Conceptos> <cfdi:Addenda> <bfa2:AddendaBuzonFiscal version="2.0" xmlns:bfa2="http://www.buzonfiscal.com/ns/addenda/bf/2"><bfa2:TipoDocumento nombreCorto="FAC" descripcion="Factura"/><bfa2:CFD totalConLetra="CINCUENTA Y DOS MIL QUINIENTOS OCHENTA Y NUEVE PESOS 64/100 M.N." observaciones="OBSERVACIONES"/><bfa2:Extra atributo="ClaveTransportista" valor="00328"/><bfa2:Extra atributo="NoRelacionPemex" valor="1-2"/> <bfa2:Extra atributo=

How to deserialize a node in a large document using XmlSerializer

岁酱吖の 提交于 2019-12-02 04:12:38
I have a large XML document that I have loaded into an XmlDocument and I want to use the XmlSerializer class to deserialize selected elements from it into a .NET class generated using xsd.exe. Here's an MCVE of what I've tried so far; the xsd and generated class are at the end of the post. As noted in the comments in the code, I am getting an InvalidOperationException - <Cars xmlns:'http://MyNamespace' /> was not expected : static string XmlContent = @" <RootNode xmlns=""http://MyNamespace""> <Cars> <Car make=""Volkswagen"" /> <Car make=""Ford"" /> <Car make=""Opel"" /> </Cars> </RootNode>";

Serializing objects to xml in C#

妖精的绣舞 提交于 2019-12-02 03:33:23
问题 I have a simple class Student under namespace School. namespace XmlTestApp { public class Student { private string studentId; public string FirstName; public string MI; public string LastName; public Student() { //Just provided for making Serialization work as obj.GetType() needs parameterless constructor. } public Student(String studentId) { this.studentId = studentId; } } } Now when i serialize this, i get this as serialized xml: <?xml version="1.0" encoding="utf-8"?> <Student xmlns:xsi=

XmlSerializer equivalent of IExtensibleDataObject

我怕爱的太早我们不能终老 提交于 2019-12-02 02:20:33
With DataContracts you can derive from IExtensibleDataObject to allow round-tripping to work without losing any unknown additional data from your XML file. I can't use DataContract because I need to control the formatting of the output XML. But I also need to be able to read a future version of the XML file in the old version of the app, without losing any of the data from the XML file. e.g. XML v1: <Person> <Name>Fred</Name> </Person> XML v2: <Person> <Name>Fred</Name> <Age>42</Age> </Person> If reading an XML v2 file from v1 of my app, deserializing and serializing it again turns it into an

How to XML serialize an array of Lists of objects?

帅比萌擦擦* 提交于 2019-12-01 22:40:11
问题 I am trying to save an array of lists of an object in C# with in a xml file. I succeeded to save a array of an object and a list of objects but not an array of lists of an object. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace expirement { public class Box { public int x; public Box(int a) { x = a; } public Box() { } } public class Program { static void Main(string[] args) { List<Box>[] MainArr = new List<Box>[1]; MainArr[0] = new List<Box>();

How to XML serialize an array of Lists of objects?

[亡魂溺海] 提交于 2019-12-01 21:38:35
I am trying to save an array of lists of an object in C# with in a xml file. I succeeded to save a array of an object and a list of objects but not an array of lists of an object. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace expirement { public class Box { public int x; public Box(int a) { x = a; } public Box() { } } public class Program { static void Main(string[] args) { List<Box>[] MainArr = new List<Box>[1]; MainArr[0] = new List<Box>(); Box Box1 = new Box(1); MainArr[0].Add(Box1); System.Xml.Serialization.XmlSerializer writer = new System

Implementing IXmlSerializable Requires Collection Property to Have Setter

不羁岁月 提交于 2019-12-01 21:18:20
I have a collection property that is of a custom type which inherits from BindingList. Currently, this property gets serialized via XmlSerializer even though it has no Setter. I now am trying to implement IXmlSerializable on this custom collection class and see that the WriteXml() and ReadXml() interface methods only get called if my collection property has a Setter. Why does serialization ignore this property now unless there is a Setter when before it serialized correctly without one. To Reproduce: First, have a class called "Item": public class Item { public Item() {} // Generates some

Use C# XmlSerializer to write in chunks for large sets of objects to avoid Out of Memory

半世苍凉 提交于 2019-12-01 20:19:43
I like how XmlSerialize works, so simple and elegant and with attributes =p However, I am running into Out of Memory issue while building up a collection of all my objects prior to serializing to xml file. I am populating an object from a SQL database and intend to write the object out to XML using XmlSerialize. It works great for small subsets but if I try to grab all the objects from the DB I reach an Out of Memory exception. Is there some ability of XmlSerialize that would allow me to grab batches of 100 objects out of the database, then write them, grab the next batch of 100 objects and