xml-serialization

XmlSerializer construction with same named extra types

Hey, I am hitting trouble constructing an XmlSerializer where the extra types contains types with the same Name (but unique Fullname). Below is an example that illustrated my scenario. Type definitions in external assembly I cannot manipulate: public static class Wheel { public enum Status { Stopped, Spinning } } public static class...

Providing better WSDL from C# SOAP

I'm pulling together some services in C# that have to match specific data format; e.g. string lengths, various enumerations and formatting. I have the back-up approach to validate post the SOAP call and respond with friendly messages and pre-defined error codes, but I would like to place additional information into the WDSL (so it is cl...

XML Serialization in C# without XML attribute nodes

Hello, I have an XML document format from a legacy system that I have to support in a future application. I want to be able to both serialize and deserialize the XML between XML and C# objects, however, using the objects generated by xsd.exe, the C# serialization includes the xmlns:xsi..., xsi:... etc XML attributes on the root element...

How can I force the use of an xsi:type attribute?

How can I force .NET's XmlSerializer to add an xsi:type="FooClass" to a member/node of type FooClass? The scenario is a currently-released app, where in v.1 : FooClass inherits FooBaseClass FooPropertyA is on FooBaseClass FooPropertyB is on FooClass FooBaseClass is decorated with [XmlInclude(typeof(FooClass))] BazClass has member Foo ...

XmlSerializer Deserializing Array/List of Multiple Objects at Root

I'm trying to deserialize the following XML output: <?xml version="1.0" encoding="ISO-8859-1"?> <Foo> <Val>Data1</Val> </Foo> <Foo> <Val>Data2</Val> </Foo> (This is output from a hardware device, and cannot be changed) I have an XML type defined as: [XmlType(AnonymousType=true, Namespace="")] public class Foo { ...

Control XML Serialization from DataSet -- Attributes on "TableName element"

Hope I chose the correct forum. I have a dataset object with one table that comes to me from a common custom component's GetDS method. I need to pass XML to another process (chunked as byte array). I have it all working but the XML is missing some attributes that the consuming process expects. I create a dataset object and can control ...

Generating XML for ActiveRecord associations using batched find

I have a controller that returns XML for a has_many association in the most straight-forward but inefficient way possible: @atoms = @molecule.atoms.find(:all, :include => :neutrons) render :xml => @atoms.to_xml(:root => 'atoms') This fetches and instantiates all objects at once. To make this more memory efficient I'd like to use Act...

Linq2Sql Entity class cannot be serialized after adding an association.

I am making ajax calls to my webservice (using MS ajax framework - Telerik comps uses it actually). I am returning one of the Entity classes generated by the dbml. It used to work fine, but when I added the associations it started throwing an exception on the server, saying "a circular reference was detecting when serializing type " I w...

Conditional serialization over each item of a List

I would like to control Xml serialization over each item of a List, suppose you have this : public class Item { [XmlElement("id")] public int Id { get; set; } [XmlElement("label")] public string Label { get; set; } #region Conditional serialization public bool ShouldSerializeLabel() { ...

NHibernate: How do I XmlSerialize an ISet<T>?

Given: I'm trying to create a REST API using ASP.NET MVC. I'm using NHibernate in my data access layer. Problem: I'm can't XmlSerialize ISet properties. I get errors like the following: Cannot serialize member [namespace].[entity].[property] of type Iesi.Collections.Generic.ISet`1[[namespace].[entity], [assembly], Ver...

Can't access Element after DataContractSerializer

I have a simple object I'm trying to serialize using DataContractSerializer. In my unit test, I'm trying to verify the xml contains the right value for the product/sku node. My product class: [DataContract(Namespace = "http://foo.com/catalogue/") partial class Product { [DataMember(Name = "sku")] public virtual string ProductSKU...

C# XML Deserialization W/ Default Values

I've got an object that is being serialized / deserialized via the XmlSerializer in C#, .NET 3.5. One of the properties (and more in the future) is a collection: List where T is an enum value. This serializes / deserializes fine. We are also using a "default values" mechanism to provide default values for the object, in case the seriali...

Serialization Proxy with XMLEncoder/Decoder

Hi everyone! How can I implement a Serialization Proxy that can be used with a XMLEncoder/Decoder? The classic one (the Bloch one, I mean) doesn't work... ...

How to save a human readable file

Currently i have an application that reads and writes several properties from one or two basic classes to a .txt file using the Binary Serializer. I've opened up the .txt file in NotePad and as it's formatted for the application it's not very readable to the human eye, not for me anyway =D I've heard of using XML but pretty much most o...

What is the most memory-efficient way to emit XML from a JAXP SAX ContentHandler?

I have a situation similar to an earlier question about emitting XML. I am analyzing data in a SAX ContentHandler while serializing it to a stream. I am suspicious that the solution in the linked question -- though it is exactly what I am looking for in terms of the API -- is not memory-efficient, since it involves an identity transform ...

Custom Serialization using XmlSerializer

I have a class that I need to do some custom XML output from, thus I implement the IXmlSerializable interface. However, some of the fields I want to output with the default serialization except I want to change the xml tag names. When I call serializer.Serialize, I get default tag names in the XML. Can I change these somehow? Here is my...

Is it possible to customize the namespace prefix that JAXB uses when marshalling to a String?

For example, I've got a simple schema which imports another schema. The second schema (urn:just:attributes, just-attributes.xsd) just defines an attribute group. <?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/MySchema" xmlns:tns="http://www.exampl...

Store custom application settings in XML

Hi everybody, please help. I have this code, it's my class to serialize\deserialize application settings. public static MyConfigClass myConfigClass = new MyConfigClass(); private static String myConfigFileName = AppDomain.CurrentDomain.BaseDirectory + "\\ApplicationConfig.xml"; [XmlRoot("EvaStartupData")] [Serializab...

What is the proper way to prepare XML data for serialization/deserialization.

<?xml version="1.0" encoding="utf-8" ?> <Hero> <Legion> <Andromeda> <SpellOne> <Name>Comet</Name> <Icon>Images/Spell/Andromeda/Spell1.gif</Icon> <Action>Target Unit</Action> <Description>Andromeda rips a comet from her dimension to hurl at an enemy, damaging and stunning them.</Description>...

When serializing/deserializing XML data, do the XML elements and the class attributes have the same name?

For example: Here's a simple class. class Hero { public string faction; public string name; public HeroType herotype; } And here's the XML counterpart. <Hero> <android> <Faction>evil</Faction> <nombre>android</nombre> </android> </Hero> Do the attributes have to be exactly the same in order to s...