xml-serialization

Class layout to serialize to this format

My XML looks like this: <cars year="2009"> <engineType name="blah"> <part type="metal"></part> </engineType> <makes> <make name="honda" id="1"> <models> <model name="accord" id="2"/> </models> </make> </makes> </cars> How do I create a class that when deserialized, will produ...

XmlSerializer is not acting like I think it should

I've used XmlSerializer for a bunch of years without any problem. I started a new project and the class I made extended List. When I went to serialize the data, I lost the properties I added to my class. Obviously, I can fix this by changing around my class so it doesn't extent List anymore. I really was just wondering why XmlSeriali...

XmlSerializer.Deserialize question

I am hoping someone has been through this pain ... I have a XML <data> <elmt1>Element 1</elmt1> <elmnt2>Element 2</elmnt2> <elmnt3>Element 3</elmnt3> </data> I need to deserialize to an object that serializes to a different root name with everything else remaining the same. for example, <dataNew> <elmt1>Element 1...

XML serialization of a collection in C#

I have two classes as follows: public class Info { [XmlAttribute] public string language; public int version; public Book book; public Info() { } public Info(string l, int v, string author, int quantity, int price) { this.language = l; this.version = v; b...

Ways to XML serialize multiple objects in C#

What are different ways in which we can XML serialize multiple objects of same/different types? For example, Generic List<T> for same type of objects and ArrayList for different type of objects. Also, which type of structures are XML serializable and which are not? It would be helpful if anyone can provide with sample piece of code or...

Why won't this XML deserialize properly?

Hi, Here's an example program showing what I'm trying to do: http://pastebin.com/m1de1f3ba The XML in the 'xml' string describes a list of items. The PersonI2 type should be considered as extending the Person type, and therefore I want the XmlSerializer to deserialize the PersonI2 entries in the XML as PersonI2 objects... instead, th...

A type of generic list deserialization class?

OK, so here's the story so far. I could already deserialize individual objects using XmlSerializer, but deserializing lists was proving to be a real headache. I started out by trying to serialize List<Foo> and the serializer serialized multiple <Foo> XML structures inside a root <ArrayOfFoo> element. That proved to be problematic to d...

Nested Classes w/ Same Name in Separate Assemblies Causing Serialization Headaches

I’m working with a poorly-engineered API. I have a class that I need to serialize, and I have control over the makeup of the class, but not the types that make up the properties the class is serialzing. An example is below: <Project> <SomeProperty1 /> <Install> <DefaultStep></DefaultStep> </Install> <Uninstall> <DefaultS...

How to handle XML Character reference in scala?

I am trying to generate some XML on-the-fly in Scala. I want to use a numeric character reference inside the XML and write out the resultant XML to an output stream. Example: val myXml = <body>Hello&#8198;World</body> val writer = new java.io.FileWriter("test") scala.xml.XML.write(writer, myXml, "utf-8", false, null) 8198 is unicode...

Xml Deserialization - Sequence of Mutiple Types

Given the following fragment where links is a sequence of unbounded imagelinks and documentlinks, what should the deserailized class be? <Values> <Links> <ImageLink>http://#&lt;/ImageLink&gt; <ImageLink>http://#&lt;/ImageLink&gt; <DocumentLink>http://#&lt;/DocumentLink&gt; </Links> </Values> Typically, if it wa...

Request for code review: does such XmlSerializer factory have any drawbacks?

Hi! People tend to recommend to cache XmlSerializer instances. Is this still actual? (if no, when has it become so?). Also I came up with the following code and ask to review it. Does it have any drawbacks? Will it use many threads\cores for different types? How can I improve it? The code: public static class SerializerFactory<T> ...

XmlSerializer chokes on xsi:type?

EDIT: See Pavel's answer below -- the 'type not recognized error' was caused by a mismatch between the class heirarchy in my parsing code (which I did not include here) and my XML schema. The 'type not recognized' error was something of a red herring, but once I fixed things the parsing works just fine. If you get to this question bec...

.NET XmlIgnore By Default?

Is there a way to have XmlSerializer ignore all members by default, unless I say otherwise? I have a base class and several derived classes with lots of members, but most I do not want to be serialized. Only a select few are acceptable for serialization. ...

What is the Jaxb equivalent of a CData Block?

I am looking to convert a class that looks like this ... public class Amenity { public String id; public String value; } into the following XML using JaxB annotations: <amenity id="id-string-here">value-string-here</amenity> Does anyone know what annotation to use on the value member variable to accomplish this? The closest I...

XmlMtomReader reading strategy

Consider the following code: Stream stream = GetStreamFromSomewhere(); XmlDictionaryReader mtomReader =XmlDictionaryReader.CreateMtomReader ( stream, Encoding.UTF8, XmlDictionaryReaderQuoatas.Max ); /// ... /// is there best way to read binary data from mtomReader's element?? string elementString = mtomReader.XmlReader.ReadElement...

Python XML Serializers

Can some recommend an XML serializer that is element or attribute centric, and that doesn't use key-value pairs. For example, GAE db.model has a to_xml() function but it writes out like this: <property name="firstname" type="string">John</property> <property name="lastname" type="string">Doe</property> <property name="city" typ...

how to create a class to XmlSerializer

I have the following xml format: <FavouriteSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; <Customer> <ID>12</ID> <ID>2</ID> <ID>5</ID> </Customer> <Supplier> <ID>158</ID> <ID>23</ID> <ID>598</ID> </Supplier> </FavouriteSettings> =========...

Deciding on when to use XmlDocument vs XmlReader

I'm optimizing a custom object -> XML serialization utility, and it's all done and working and that's not the issue. It worked by loading a file into an XmlDocument object, then recursively going through all the child nodes. I figured that perhaps using XmlReader instead of having XmlDocument loading/parsing the entire thing would be f...

XML Serialization of HTML

Okay this one DID it! Thanks to all of you! public class Result { public String htmlEscaped { set; get; } [XmlIgnore] public String htmlValue { set; get; } [XmlElement("htmlValue")] public XmlCDataSection htmlValueCData { get { XmlDocument _dummyDoc = new ...

Can I force JAXB not to convert " into &quot;, for example, when marshalling to XML?

I have an Object that is being marshalled to XML using JAXB. One element contains a String that includes quotes ("). The resulting XML has &quot; where the " existed. Even though this is normally preferred, I need my output to match a legacy system. How do I force JAXB to NOT convert the HTML entities? -- Thank you for the replies....