xml-serialization

.Net: how do you convert a class properties to output xml element?

Hello, all. I seem to forgot the process and how to set a class property to xml element or attribute by setting attribute on the property member. So you can write out the object to xml. I'm not sure I'm making any sense here but hopefully someone know what I'm talking about and point me to a how-to or tutorial or MSDN document. Thank ...

Ruby on Rails Advanced JSON Serialization

I'm looking to render an index of all articles along with a full article via json in my rails app, but I'm having a little trouble figuring out how to do it. Here is my controller now: if params[:id] @article = Article.find(params[:id]) else @article = Article.published.not_draft.by_recent.first end respond_to do |format| for...

Is it possible to deserialize XML into List<T>?

Given the following XML: <?xml version="1.0"?> <user_list> <user> <id>1</id> <name>Joe</name> </user> <user> <id>2</id> <name>John</name> </user> </user_list> And the following class: public class User { [XmlElement("id")] public Int32 Id { get; set; } [XmlElement("name")] public Strin...

Any way to make XmlSerializer output xml in a defined order?

Currently I'm using XmlSerializer to serialize and deserialize an object. The xml is generated in an undefined order which is understandable but makes it annoying when comparing versions of the object, since the order of properties is different each time. So for instance I can't use a normal diff tool to see any differences. Is there an...

How do I add a namespace while doing XmlSerialization with an XmlWriter?

I am using the XmlWriter in conjunction with Xml Serialization. I am able to output the XML fine, but how to include the xmlns attribute with the XmlWriter seems to be escaping me. To write the start of the document I use the following: Writer.WriteStartDocument(); Writer.WriteStartElement("urlset","http://www.sitemaps.org/sch...

Java DomImplementationLS.

I'm looking to create XML Document objects in Java and serialize them to a byte array (prior to sending them across a TCP connection). I currently have code that looks like this: public byte [] EncapsulateThingy( ThingyType thingy ) { parser.reset(); // parser is a pre-existing DocumentBuilder object Document doc = parser.newDo...

How can I get XmlSerializer to encode bools as yes/no?

I'm sending xml to another program, which expects boolean flags as "yes" or "no", rather than "true" or "false". I have a class defined like: [XmlRoot()] public class Foo { public bool Bar { get; set; } } When I serialize it, my output looks like this: <Foo><Bar>true</Bar></Foo> But I would like it to be this: <Foo><Bar>yes</...

Omitting all xml namespaces when serializing an object?

The code looks like this: StringBuilder builder = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; using (XmlWriter xmlWriter = XmlWriter.Create(builder, settings)) { XmlSerializer s = new XmlSerializer(objectToSerialize.GetType()); s.Serialize(xmlWriter, objectToSer...

Polymorphic Types and IXmlSerializable

The XML serialization in .NET allows polymorphic objects through the extraTypes[] parameter of the XmlSerializer constructor. It also allows customization of XML serialization for types that implement IXmlSerializable. However, I’m unable to combine these two features – as demonstrated in this minimal example: using System; using Syste...

Use XML serialization to serialize a collection without the parent node

Let's say I have a class; public class Car { public List<Pasenger> Passengers {get; set;} } I want to serialize this to XML such that Passengers are child nodes of Car and there is no intervening Passengers node. In other words I want the output to look like this; <Car> <Passenger>...</Passenger> <Passenger>...</Passenger> <...

How to customize WCF XML serialization

We have an existing SOAP web service interface that we want to implement using WCF for a new application. This seems to work fine except for one small detail. The XML namespace of the return type of a function must be different than the XML namespace of the web service itself. And for the life of me, I can't get it to work. I've recreat...

Strategy for XmlSerialisation with an Interface?

I've got an interface that two classes implement at the moment. The data for these classes is read in from an xml file. e.g. [Serializable] public interface IMyInterface { } [Serializable] public class MyClass1 : IMyInterface { } [Serializable] public class MyClass2 : IMyInterface { } I want to infer the type from the Xml, is there...

xml parsing / querying performance question for asp.net

I have to port a smaller windows forms application (product configurator) to an asp.net app which will be used on a large company's website, demand should be moderate because it's for a specialized product line. I don't have access to a database and using XML is a requirement from their web developers. There are roughly 30 different p...

How to control XML Serialization behavior on xsi:nill=

I'm working on a Webservice to share data between 2 ERP-systems. First ERP calls the webservice, which serializes the data-object and sends it to the second ERP. A data object looks like this: <xs:complexType name="Parent"> <xs:sequence> <xs:element ref="ta:ReceiptLine" maxOccurs="unbounded"/> </xs:sequence> </x...

C# XML Serialization - Leading Question Marks

Problem By leveraging some samples I found online here, I've written some XML serialization methods. Method1: Serialize an Object and return: (a) the type, (b) the xml string Method2: Takes (a) and (b) above and gives you back the Object. I noticed that the xml string from the Method1 contains a leading '?'. This seems to be fine wh...

Using NameValueCollection in C# webservice gives not XML serializable error

I am getting this error message when I try to "Add Web Reference" to my ASMX proxy project: **"To be XML serializable, types which inherit from ICollection must have an implementation of Add(System.String) at all levels of their inheritance hierarchy. System.Collections.Specialized.NameValueCollection does not implement Add(System.St...

XML Serialization - Missing Namespace Prefix at client end

I have created a .NET web service that returns an object, say Class "getResponse". The WS returns the following response ... <getResponse xmlns="http://tempuri.org/getCustomer/wsdl/"&gt; <Result xmlns="http://tempuri.org/getCustomer/"&gt; <ResultCode>OK</ResultCode> <ErrorsList/> </Result> </getResponse> while th...

c# inheriting generic collection and serialization...

Hi, The setup: class Item { private int _value; public Item() { _value = 0; } public int Value { get { return _value; } set { _value = value; } } } class ItemCollection : Collection<Item> { private string _name; public ItemCollection() { _name = string.Empty; } public string ...

Exception when trying to deserialize a xml file

Im trying to deserialize an XML file with XmlSerializer, however im getting this exception: "There is an error in XML document (1, 2)" The innerexception is: "<Mymessage xmlns='http://MyMessages/'&gt; was not expected." Which is the very first line in the XML file. my guess is that it has something to do with the xmlns. I...

How to have ADO.NET consume persisted XML ADO recordset for updates

I am working on a .NET 2.0 conversion of a multi-layer client-server application. For the time-being, we're converting the server-side to .NET but leaving client apps in COM (VB6). My current work is focused on getting data to/from the detached COM based clients. The current version under development is using ADO(COM) recordsets persis...