xml-serialization

How to change XML root name with XML Serialization?

Hi I am trying to change the root name when doing XML serialization with C#. It always takes the class name and not the name I am trying to set it with. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Serialization; using System.IO; namespace ConsoleApplication1 { class Prog...

How does XML Serialization know where to put the attribute?

I am trying to figure out how to do XML serialization. This is how I want my XML document too look like in the end <course> <name></name> <backgroundColor></backgroundColor> <fontColor></fontColor> <sharingKey></sharingKey> <task id=""> <taskName></taskName> <description></description> </task> ...

System.InvalidOperationException was unhandled - XMl Serialization C#

Hi I made an xml document by using XML Serialization. It looks like this <?xml version="1.0" encoding="utf-8"?> <Course xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; <courseName>Comp 1510</courseName> <backgroundColor>#ffffff</backgroundColor> <fontColor>#ffffff</fontColor...

How to insert XML comments in XML Serialization?

Hi I want to add at the top of my xml file some notes for the user who reads it. I am not sure how to do this though with xml serialization. I was looking at this post http://stackoverflow.com/questions/2086326/c-xml-insert-comment-into-xml-after-xml-tag XDocument document = new XDocument(); document.Add(new XComment("Product XY Vers...

remove xml declaration from the generated xml document using java

String root = "RdbTunnels"; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.newDocument(); Element rootElement = document.createElement(root); document.appendChild(rootElement); Outp...

.NET XML Serialization and Null Collections

I have a class with some collections in them, and I would like to serialize instances of this class to XML without having to initialize the collections to be empty, and without having to implement IXmlSerializable. I don't care if it creates empty elements, or doesn't create the elements at all. Just that it works without having to ini...

NHibernate and XML Serialization with IList<T>

I've recently started using NHibernate, and on the whole like it a lot. Until I ran into a problem with needing to serialize to XML and back. I have a class that has a many to many relationship, so have an IList in the parent class to hold the list of child objects. Class parentClass{ IList<childClass> childList; string varA; s...

Single stream, multiple XmlWriters

Is it possible to have a single stream and have more than one XmlWriter write to that stream and end up with well-formed XML? I have an object hierarchy in which each object is solely and fully responsible for serializing itself. My latest attempt has been to create a stream at the highest level, then pass that stream reference down an...

XmlSerializerFormat not nested XML

Hi, For my project I am using XmlSerializerFormat for serialization. I have a class for example: [SoapInclude(typeof(Thing))] [SoapType("Thing", "TheNs", IncludeInSchema = true)] public class Thing { [SoapElement(IsNullable = true, DataType = "string")] public string ThingName = "aap"; } [SoapType("Transportation", "TheNs", IncludeI...

Is there any way to stop a method being called at compile-time?

I have some classes, which have several methods which I don't really want to be there, but are there simply because the XML Serializer needs them. Is there anyway to generate compile-time errors/warnings if they get called from user-code? I am aware that I can implement IXmlSerializable, and I am also aware that I can separate out the c...

Using XmlSerializer on a class with anonymous methods

I want to serialize a class which uses an anonymous function in its implementation. The compiler is generating an inner class to implement the anonymous function. The serializer fails with the error: "MyClass+<>c__DisplayClass2 is inaccessible due to its protection level. Only public types can be processed." public class MyClass { ...

C#/.NET XML Serializer - using a property as element name

Warning -- I'm not an xml guru. Here is what I have: <Fields> <Field name="BusinessName" look-up="true">My Business</Field> <Field name="BusinessType" look-up="false">Nobody really knows!</Field> </Fields> This maps back to: [XmlArrayItem(ElementName = "Field")] public List<UserInfoField> Fields; and [Serializable, XmlRoot("F...

How to serialize a class that contains objects of other classes (recursive serializing?)

How can I do this? Or will the serializer automatically go with recursion, and serialize all those child objects into XML? Give me an example how would you serialize classes that contain other classes' objects in themselves! That was the core of this question! I've tried this, and it didn't output anything (except the XML header) to th...

Ruby Hash & Array to xml

I'm using ActiveSupport's to_xml to generate some xml from a hash. I have need for the this ruby: :Shipment => { :Packages => [ {:weight => '5', :type => 'box'}, {:weight => '3', :type => 'tube'} ] } To generate this xml: <Shipment> <Package> <weight>5</weight> <type>box</type> </Package> <Package> <wei...

Where to place the pre-generated serialization assembly?

I am trying to speed up the start-up of my Click-Once (.net 2.0 in VS2008) app by shipping the pre-generated XML serialization assemblies. So to test my scenario, I set VS2008 to break when an exception is thrown. Even though, the XML Serialization assemblies are there, there is still an exception, saying that it can't find or load t...

Make a Custom Class Serializable in Objective-c/iPhone?

How can I make my own custom class serializable? I specifically want to write it to a file on iPhone, just plist and thee class is just a simple instance class, just NSStrings and maybe a NSUrl. ...

Rails compatible .NET xml serialization

I am writing an ASP.NET MVC 2 site with REST endpoints. I want to consume this service with ActiveResource in a Rails web application. So far, I've managed to get routes setup in ASP.NET MVC that match the ActiveResource conventions. But where I'm having problems is with de-serializing the data that ActiveResource sends to the REST se...

C# - Deserialize a class with an internal constructor

I am working on a drag and drop system for my WPF App. The way it works is: I take the dragged Item Serialize it to xml When it gets dropped I deserialize it again. This worked fine in my test app. However, now that I am trying to do it in my real app, I have hit a snag. The class I am trying to deserialize (Microsoft.TeamFou...

XML Serialization - Is it possible to serialize a model in this way?

I have the following model: public class ABaseObject { private Guid id = Guid.NewGuid(); public ABaseObject() { } public Guid ID { get { return id; } } } public class ADerivedObject : ABaseObject { public ADerivedObject() { } public string Name { get; set; } } public class AObjectCollection<T> { ...

Difference between NonSerialized and Xml.Serialization.XmlIgnore?

We're serializing/deserializing a class from XML and but there are properties and fields in the class which we want to exclude. The System.NonSerialized and System.Xml.Serialization.XmlIgnore attributes seem to do the job but what's the difference between them? It seems we can use XmlIgnore on either properties or fields of the class. B...