xml-serialization

C# How to copy nodes between two identical xsd generated classes.

Whats the fastest or perhaps optimal way to read elements, node, attributes from a source class, which represents a chunk of xml, and write then back into a resultant class from the same schema. I've got a requirement for a way to read incoming xml messages, parse them with this xpath path expression language we have invented, and then...

Xmlserializer not serializing base class members

I'm having this very odd issue while trying to serialize a class for logging using XmlSerializer. The code was generated by the wsdl.exe tool. The class that gets serialized as is declared as follows: [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] [System.SerializableAttribute()] [System.Diagnostics.Debugger...

Why can't a dictionary object be XmlSerialized in C#?

It seems that serialization is very straightforward. Assuming that both the key and value are serializable, what could be simpler than representing key-value pairs in XML?! To all the commenters: First of all, I appreciate your answers, But- I am less interested in workoraunds (There is indeed plenty of SerializableDictionary implementa...

Serializing Java objects to xml and back (XML configuration)

I am looking for a XML serialization framework which has an option for a XML configuration instead of annotation to name classes and fields. I looked at Simple and XStream but I didn't find a method to do it. I suppose I could use Spring IOC and XStreams aliasing, but if there's any frameworks, which could do this for me, it would of co...

XmlTypeAttribute does not change name of type

I'm working on a project that calls a web service using WSE3. The types originally generated using VS2005 have been modified over time. Now, I need to change the name of the type in the SOAP message. I gather that should be done using XmlTypeAttribute, but that does not affect the type name. As an experiment, I used XmlElementAttribu...

Problem with XML Serialization: Must implement default access descriptor in ....

Hello. I have an excepction while trying to serialize an Stack in Visual Studio 2008, C# 3.5 Here is some sample code. > 1 CardDN kk = new CardDN(12, CardDN.SuitType.Clubs); > 2 Stack<CardDN> kk1 = new Stack<CardDN>(); > 3 kk1.Push(kk); > 4 > 5 XmlSerializer serializerk = new XmlSerializer(kk1.GetType()); > 6 S...

DeSerialize XML into Class, Subclass & Properties making SubClass not null

I have some XML that I am de-serializing and all works fine apart from one of my properties in the serialized class is also a class for example; Person.Address.Postcode. Address is a property in Person class but Address is a class with properties such as Postcode. If the incoming XML does not contain Address information and deserializa...

.Net XML Serialization based on an XSD?

Hi, I've been serialising and deserialising .net objects using the XmlSerializer class without problem, however we now need somebody else to look at that data to perform some analysis on it. In order to help with that we've produced an XSD based on our class like so: xsd.exe /t:DataClass Assembly.exe The start of the XSD looks like th...

Alternative in ActionScript for "DataMember" in C#

Hi there, currently I'm translating an app from C# into ActionScript (Silverlight to Flex) and I need to serialize some XML content in ActionScript. Now, unfortunately I need the variables to have an other name than the nodes in the XML file. I tried a workaround with getters and setters. It worked for setting the variables, but I fail...

Question about XmlSerializer in .NET

I have the following classes in C# that I want to serialize: Item ProjectItem : Item Folder : Item Project (Contains a collection of Item, that may be either a ProjectItem or a Folder) When I serialize a "Project", I get the following... <Project> <Item xsi:type="Folder"> <Name>MyFolder</Name> </Item> </...

Using "FOR XML" with XML Serialization with DATETIME type

I'm having issues trying to add some dates to a pre-existing class that is loaded via XML Serialisation, and it's not doing what I thought it should do. I knocked up a basic test with SQL of (where EffectiveFrom and EffectiveTo are declared as DATETIME) SELECT o.EffectiveFrom AS [@EffectiveFrom], o.EffectiveTo AS [@EffectiveTo], FROM...

How to get xml in a required format when serializing an object using XML serialization in .Net

How do I get the attributes to the inner element rather than root element? [XmlRoot("Root")] public class Test { string type=null; int value=0; public string Type { get { return type; } set { type=value; } } [XmlAttribute] public int Value { get { return type; } set { type=...

magic name to suppress XmlSerialization of an empty List.

Given the correct "MagicName" (it was something like "CanSerialize"), the following code would suppress xml for empty lists. What was that magic name? public class MyClass { public List<int> MyList{ get; set; } public bool MyListMagicName() { return MyList.Count != 0; } public MyClass() { MyList = new List<int>(); } } ...

How to use .NET XML serialization without a guaranteed schema

Basically, I have some xml I need to deserialize. At the time I write my code, I'll know the structure of the XML, but I'd like to be able to make simple changes to the xml without having to update the serialization code. Example: <foo> <bar/> </foo> I'd like to be able to deserialize foo, even if i add an additional node which is ...

XStream-like XML serialization for Jython objects?

Jython is great for creating custom data structures on need basis, but how to store their instances? Apparently it's possible to do it via java.io.Serializable, but ObjectStreams are not human readable; I would prefer XML. I naïvely tried XStream to serialize a simple object created in Jython and translated to Java with PyObject's __toj...

.net XML Serialization - Storing Reference instead of Object Copy

In .Net/C# Application, I have data structures which have references to each other. When I serialize them, .Net Serializes all references with separate object copies. In Following Example, I am trying to serialize to Array of 'Person' A 'Person' may have reference to another person. public class Person { public string Name; pub...

XmlSerializer with new enum values

We use xml serialization / deserialization extensively in our project to pass data between multiple application. We have a common xsd that we generate c# classes from then use XmlSerializer to go from xml to objects and back. The problem we are having is when one app is updated to add new enum values but the other app is not updated ye...

How to set root node name when XmlSerializing an array?

I have an array of objects which I want to serialize as XML. These objects are annotated to set XML node names but I was wondering how to set the name of the XML root node. The code looks like this: // create list of items List<ListItem> list = new List<ListItem>(); list.Add(new ListItem("A1", new Location(1, 2))); list.Add(new ListIte...

Best way to generate a hash signature (HMAC) for XMLSerialized objects in .NET?

I need to generate a HMAC for objects that I am serializing using the XMLSerializer found in the .NET framework. Each object will contain a property called "HMAC" that will contain a hash of the object's values itself but excluding the "HMAC" field. I've found this question that mentions a built-in solution within the CLR but doesn't ela...

XMl Serialization of Linq-to-Sql objects?

I am working on an Audit Log for an application that uses Linq-To-Sql. I want to serialise an object to stores its values in a XML column in a SQL Server databse. My problem is that when I try to serialize a Linq-To-Sql obejct that it attempts to serialize all associated entities and entity sets. My first attempt at a solution was t...