xml-serialization

How to implement xml serialization for custom types?

I have some types that I want to serialize/deserialize and generate a UI based on the selected object. The UI will also change the object which in turn I will have to serialize to store it in my app. So: [obj_apple stored in the app] -> select obj_apple -> deserialize -> show in UI -> use the UI to change obj_apple -> deselect obj_appl...

User Defined XML Serialization

I have the following structure in C#: [Serializable] public struct Line { public Line(Point startPoint, Point endPoint) { StartPoint = startPoint; EndPoint = endPoint; } public Point StartPoint; public Point EndPoint; } which I use in another class, that is XmlSer...

Javascript library for exporting XML

Hi, I'm currently using couchdb to store documents as JSON. One of my clients needs to grab XML (for now). Anyone know any good javascript libraries that can take a javascript object (or json string) and export valid xml? Thanks! ...

How should you implement Serialization? (interface/convention wise)

I implement an xml serialization based on Marc's answer. Should this be part of the class itself, ie Apple.Serialize/Deserialize? Although Deserialize would be static in that case, as you might not have an instance to call it on. Or should I have another class for Serialize/Deserialize? If so, these seem to be generic enough? What sho...

Can I use a C# collection to hold class instances with self-referential relationships?

Hi, I need to model in memory a collection web files, but that relationships between them. That is file A (e.g. html) may have a link to file B (e.g. css) and file C (e.g. javascript). Also file D may also require file B. If I wanted to delete file A I would need to make sure any files it uses (e.g. file B) is not also being used ...

Help Merging XML Data

I have two XMLDocuments that contain some similar information but there are other nodes that contain different information between the two. I am using XMLSerialization to put my data into a structure as shown here I know you can merge XML files by using a DataSet as shown here but I want to somehow serialize the first document I see in...

How to exclude null properties when using XmlSerializer

I'm serializing a class like this public MyClass { public int? a { get; set; } public int? b { get; set; } public int? c { get; set; } } All of the types are nullable because I want minimal data stored when serializing an object of this type. However, when it is serialized with only "a" populated, I get the following xml ...

XmlSerializer Performance Issue when Specifying XmlRootAttribute

I'm currently having a really weird issue and I can't seem to figure out how to resolve it. I've got a fairly complex type which I'm trying to serialize using the XmlSerializer class. This actually functions fine and the type serializes properly, but seems to take a very long time in doing so; around 5 seconds depending on the data in ...

Why does XMLSerializer take DefaultValue Attribute of base class to serialize

using System.ComponentModel; using System.IO; using System.Xml.Serialization; namespace SerializerTest { static class Program { static void Main() { using (TextWriter textWriter = new StreamWriter("data.xml")) { Data data = new Data(); new XmlSerializer(typeof(Data)).Serialize(textWriter, data); textW...

c# serialize second level element to property

I am trying to create serializable class but I want to map second level element to my property of class. What's the best way of doing this. Example xml & class <SearchResult> <Head> <Title q="test">My search Result</Title> </Head> <Results> <Result>...</Result> <Result>...</Result> <Result>...</Result> </Results> </SearchRe...

Need help Serializing System.Data.OracleClient.OracleCommand to XML?

Trying to write a list of oracle commands to XML but keep getting this error. This is driving me crazy. Thanks in advance. "There was an error reflecting type 'System.Data.OracleClient.OracleCommand'." Friend Sub WriteDataToFile(ByVal Commands As List(Of System.Data.OracleClient.OracleCommand)) Try Dim PathName As String...

C# Castle ActiveRecord: How to elegantly (XML) serialize ActiveRecord objects?

Hello, I'm having a difficult time finding information on how to elegantly serialize ActiveRecord objects. We would like to use XML as the format because we need to output our objects in such a way that another program will be able to feasibly parse them. XML-Serialization is usually very easy and straightforward to implement, but the ...

c# - how do I serialize an Array<> to XML? (getting "You must implement a default accessor on System.Array because it inherits from ICollection.")

Hi - I'm a bit stumped here. I just really want to XML Serialize an Array<> but I'm getting: "You must implement a default accessor on System.Array because it inherits from ICollection." A snippet from my code is below. Any idea? Array a = Files.ToArray(); XmlSerializer serializer = new XmlSerializer(typeof(Array)); TextW...

DeSerialize DataTable Row Collection into List<T>

I have a DataTable with rows of data. I have a class with properties that match the row column names. How can I have a List that is populated from the DataTable Row information? Do I call something like (MyType)new XmlSerializer(typeof(MyType)).Deserialize(new XMLReader(Table.WriteXML())); ...

XML Serialization of Derived Classes

I have an array of elements that I need to serialize using XmlSerializer. The problem I'm having is I have 2 derived classes, and serializing them so they have an element name of the common base, doesn't seem to work. So, this is how the XML should look: <Root> <Base> foo </Base> </Root> Instead, I'm getting <Root> <Derived...

{"<user xmlns=''> was not expected.} Deserializing Twitter XML

So im pulling in the XML from Twitter via OAuth So Im doing a request to http://twitter.com/account/verify%5Fcredentials.xml Which returns the following XML <?xml version="1.0" encoding="UTF-8"?> <user> <id>16434938</id> <name>Lloyd Sparkes</name> <screen_name>lloydsparkes</screen_name> <location>Hockley, Essex, UK</location>...

How to XML deserialize an object of Unknown Type?

I want to save my object to hard disk (like cache) with XmlSerializer. In this case, I don't have any problem. However, when I want to deserialize this XML to an object, I get an error. Is there any way to deserialize XML to an unknown object or to an object that I created? ...

From raw xml (no schema) to c# class?

I have an xml file that I would like to generate a c# class for. Is there any quick and easy way to do this? I don't have a schema to go with my xml file, it's just raw xml. Any ideas? Thanks. ...

Using .Net XmlSerialize for strings with embedded <cr><lf> loses <cr> when deserializing

The following (abysmal) code demonstrates how standard serialize/de-serialize in VB loses the CR when on de-serialize. This can be overcome by applying 'XmlAttribute(DataType:="string")' to Description. Why does it do this? I would like to fix this without applying a 'LF' -> 'CR''LF' in every affected class. This is fixing a bug in exist...

Using StringWriter for XML Serialization

I'm currently searching for an easy way to serialize objects (in C# 3). I googled some examples and came up with something like: MemoryStream memoryStream = new MemoryStream ( ); XmlSerializer xs = new XmlSerializer ( typeof ( MyObject) ); XmlTextWriter xmlTextWriter = new XmlTextWriter ( memoryStream, Encoding.UTF8 ); xs.Serialize ( x...