xml-serialization

Replacement for XML Serialization

I have code using XmlSerializer to serialize/deserialize a data structure for persistance. I've read and heard in several places here on StackOverflow that XmlSerializer is one or more of: Bad Poorly supported/implemented Possibly won't be supported into the future My question is two-fold; is any of the above true, and if so, what al...

How do I serialize all properties of an NHibernate-mapped object?

I have some web methods that return my objects back as serialized XML. It is only serializing the NHibernate-mapped properties of the object... anyone have some insight? It seems to be that the web methods are actually serializing the NHibernate proxies instead of my classes. I've tried using [XMLInclude] and [XMLElement], but the pro...

Typed Dataset with null values to XML

When a typed DataSet is written to XML using ds.GetXml the columns with null values are removed from the XML. I know this is because the schema is not written etc. but is there a way to override this without having to parse through the DataSet and convert all database nulls to empty string before writing the XML? EDIT: additional info...

Deserializing xml with namespace prefixes that are undefined

The Xml response I receive is as follows: <response> <item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="java:com.someDomain.item"> <name>some name</disc-name> <description>some description</disc-desc> </item> <item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="java:com.someDomai...

Bug in Sgen.exe

It seems that sgen.exe could not generate generic type XmlSerializer, right? My genereic type: [Serializable] [XmlRoot(ElementName = "Masterx")] public class Masterx<T> where T : class, new() {....} Serializer code: protected virtual List<T> ParseXMLToObject<T>(string resultXML) where T : class, new() { //return ParseXM...

How to deserialize into a List<String> using the XmlSerializer in C#

I'm trying to deserialize the XML below into class, with the "Components" deserialized into a List of type String, but can't figure out how to do so. The deserializer is working fine for all the other properties, but not "Components". Anyone know how to do this? <ArsAction> <CustomerName>Joe Smith</CustomerName> <LoginID>jdsmith</...

Can I make the default collection editor and/or a custom UIEditor envoke the set accessor for a property?

I'm writing a plug-in for an application where I have a custom class that attributes the native objects of the program. The API allows me to read and write keyed strings directly to and from the objects in the native file. So rather then reading and writing to private fields in the Get and Set accessors of each property I'm reading and w...

XML Serialize generic list of serializable objects

Can I serialize a generic list of serializable objects without having to specify their type. Something like the intention behind the broken code below: List<ISerializable> serializableList = new List<ISerializable>(); XmlSerializer xmlSerializer = new XmlSerializer(serializableList.GetType()); serializableList.Add((ISerializable)Pers...

XML complexType with element that ends up as "XmlElement"

In my XSD, I have something similar to this: <?xml version="1.0" encoding="utf-8" ?> <schema xmlns:jump="testThingy" elementFormDefault="qualified" targetNamespace="testThingy" xmlns="http://www.w3.org/2001/XMLSchema"&gt; <element name="command" type="jump:commandType" /> <complexType name="loginType"> <sequence> <element ...

Public fields/properties of a class derived from BindingList<T> wont serialize

I'm trying to serialize a class that derives from BindingList(Floor), where Floor is a simple class that only contains a property Floor.Height Here's a simplified version of my class [Serializable] [XmlRoot(ElementName = "CustomBindingList")] public class CustomBindingList:BindingList<Floor> { [XmlAttribute("publicField")] publ...

Wrapping Serialized Properties in Additional Elements with .NET XML Serialization

Hello everyone, I am using C# + VSTS2008 + .Net 3.0 to do XML serialization. The code works fine. Here below is my code and current serialized XML results. Now I want to add two additional layers to the output XML file. Here is my expected XML results. Any easy way to do this? I am not sure whether NestingLevel could help to do this. I...

Removing Wrapper Elements from XML-Serialized Array

I am using VSTS2008 + C# + .Net 3.0. I am using below code to serialize XML, and my object contains array type property, but there some additional elements' layer (in my sample, MyInnerObject and MyObject) generated which I want to remove from the generated XML file. Any ideas? Current generated XML file, <?xml version="1.0"?> <MyClass...

Wrapping Serialized Array Elements with the Name of the Array

Hello everyone, I am using VSTS2008 + C# + .Net 3.0. I am using below code to serialize XML, and my object contains array type property, and I want to add an additional elements' layer ("MyInnerObjectProperties" element layer in my expected results below, and I want to make "MyInnerObjectProperties" element as parent element for all My...

Placing a Property into a Different XML Namespace with XML Serialization

I am using VSTS2008 + C# + .Net 3.0. I am using below code to serialize XML, here is my current code and serialized XML file. My purpose is I want to make MyInnerObjectProperties belongs to a special XML namespace (http://foo/2009) and making this namespace as default namespace. Any ideas how to implement this? Current output: <?xml ve...

Inject XML attribute into serialization

I am trying to serialize an array and want to attach an attribute to the array. For example, the output I want is: <ArrayOfThingie version="1.0"> <Thingie> <name>one</name> </Thingie> <Thingie> <name>two</name> </Thingie> </ArrayOfThingie> This is just a primitive array, so I don't want to define the attribute for the ...

Serialize Complex Type System.Nullable<System.DateTime>

I want to serialize DateTime so that when DateTime is null I dont get the tag itself. I have also set bool specified for the above but my problem is DateTime being of value type it will never be null hence the bool specified will always be true for it. I even tried replacing DateTime to System.Nullable but I get Serialization Error whe...

XML Serialization of List<T> - XML Root

First question on Stackoverflow (.Net 2.0): So I am trying to return an XML of a List with the following: public XmlDocument GetEntityXml() { StringWriter stringWriter = new StringWriter(); XmlDocument xmlDoc = new XmlDocument(); XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);...

Inheritance casting problem with Generics and XmlSerializer

How do I cast an instance of an object and actually make it that type of object? I have a class myClass1 that is the base class for myClass2 and myClass3. I want to use myClass1 for auditing, for auditing all I want is the data from myClass1. Because myClass2 and myClass3 inherit from myClass1 you can set an instance of myClass1 to an...

XMLSerializer Deserialize List<T> issue

When i run the following code to serialize the facbook users, the code generated is something like: <?xml version="1.0"?> <ArrayOfUser xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="fbapp"> <user> <user xmlns="http://api.facebook.com/1.0/"&gt; ...

What is an efficient way to render a large XML collection in ruby/rails?

I'm trying to render a large (ish) array of objects as a plist in Ruby on Rails. The collection currently contains up to 200 objects, each of which is essentially a record (dictionary of keys/values). The overall result format is a plist (as used by Apple) but logically it is not much different from any XML document. The problem I've hi...