xml-serialization

Using generics with XmlSerializer

Hi, When using XML serialization in C#, I use code like this: public MyObject LoadData() { XmlSerializer xmlSerializer = new XmlSerializer(typeof(MyObject)); using (TextReader reader = new StreamReader(settingsFileName)) { return (MyObject)xmlSerializer.Deserialize(reader); } } (and similar code for deserializ...

Virtual properties duplicated during serialization when XmlElement attribute used

The Goal: XML serialize an object that contains a list of objects of that and its derived types. The resulting XML should not use the xsi:type attribute to describe the type, to wit the names of the serialized XML elements would be an assigned name specific to the derived type, not always that of the base class, which is the default be...

NSKeyedArchiver to serialize to GPX XML

I have a Location class that contains a lat/lon as well as an elevation and timestamp: @interface Location : NSObject <NSCoding> { double lon; double lat; double ele; NSDate *time; NSDateFormatter *gpxDateFormatter; } I want to be able to serialize an NSMutableArray containing an arbitrary number of these Location objects into ...

Is there anything like ISerializable that works for XMLSerializer?

I've got a class which implements it's own (de)serialization via XLINQ, and I'd like to have clients of my class which attempt to XMLSerialze my class to have my XLINQ method called instead. Is that possible? ...

In Protobuf-net how can I pass an array of type object with objects of different types inside, knowing the set of potential types in advance.

I am trying to migrate existing code that uses XmlSerializer to protobuf-net due to the increased performance it offers, however I am having problems with this specific case. I have an object[] that includes parameters that are going to be sent to a remote host (sort of a custom mini rpc facility). I know the set of types from which the...

Howto serialize a List<T> in Silverlight?

I have a struct called coordinate which is contained in a list in another class called segment. public struct Coordinate { public double Latitude { get; set; } public double Longtitude { get; set; } public double Altitude { get; set; } public DateTime Time { get; set; } } public class Segment { private List<Coordina...

How to serialize List<object>

I am writing common functions to serialize the given object and List<object> as follows public string SerializeObject(Object pObject)// for given object { try { String XmlizedString = null; MemoryStream memoryStream = new MemoryStream(); XmlSerializer xs = new XmlSerializer(typeof(pObject)); XmlTe...

Is there a way to make a serialized member to serialize as an attribute?

Is there a way to make a serialized member to serialize as an attribute: <Serializable> Public Class Person Public Property Name As String End Class I want than when this class is xml-serialized, it should produce: <Person Name="John Doe" /> And what I mean is that instead of the Name property should be serialized as an elemen...

How to add XmlInclude attribute dynamically

I have the following classes [XmlRoot] public class AList { public List<B> ListOfBs {get; set;} } public class B { public string BaseProperty {get; set;} } public class C : B { public string SomeProperty {get; set;} } public class Main { public static void Main(string[] args) { var aList = new AList(); ...

Overriding to_xml for collection of ActiveRecord objects

Okay, I know you can override the to_xml method for a single instance of ActiveRecord object and it works just fine for me. But how would I go about overriding the to_xml method for collection of objects? Suppose for Task model instance, I implemented to_xml which looks like this. def to_xml super(:methods => [:tag_list], :include =>...

How can I get XmlSerializer deserialize attributes from multiple namespaces?

I have a schema from a third party that I've generated c# objects from using Xsd2Code (other options like xsd.exe, xmlspy etc either crashed or spewed 40mb of code that required their library to work) Anyway, here's an example of a problem element from the schema: <xsd:schema xmlns:ns1="something" xmlns:ns2="somethinelse" targetNamesp...

XML documentation to context sensitive help

These days a number of commercial and open source tools have been developed for this purpose. However(unfortunately), non of them meet my requirement for specific problem I am dealing with. Currently, I am working on a project that exposes a different classes and functions to user as scripting interface. the user can use the objects from...

Automatically minifying attribute/element names when using XmlSerializer

When serializing a C# class using XmlSerializer, the attributes/elements representing the properties of the class will have the same names as they do in the source code. I know you can override this by doing like so: [XmlAttribute("num")] public int NumberOfThingsThatAbcXyz { get; set; } I'd like the generated XML for my classes to b...

Parsing third-party XML

What path would you took to parse a large XML file (2MB - 20 MB or more), that does not have a schema (I cannot infer one with XSD.exe because the file structure is odd, check the snippet below)? Options 1) XML Deserialization (but as said, I don't have a schema and XSD tool complains about the file contents), 2) Linq to XML, 3) loadin...

Implementing IXmlSerializable on a generated class that has XmlTypeAttribute

Basically, the initial problem is I need to make a boolean value serialize as 0 or 1. The solution I found was to implement IXmlSerializable, which I did. Unfortunately the class I'm trying to serialize is generated code off a schema and has an XmlTypeAttribute on it. When I try to (de)serialize the object with the XmlSerializer created ...

There is an error in XML document (5, 14)

why I get There is an error in XML document (5, 14) while Iam trying to Deserialize an XML document.? This is the XML document: <?xml version="1.0"?> <Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; <FirstName>Khaled</FirstName> <LastName>Marouf</LastName> </Customer><...

How to deserialize MXML with PHP?

Hello, I have an array structure that have to be converted to MXML. I know of PEAR XML_Serialize extension but it seems the output format it produces is a bit different. PHP generated XML: <zone columns="3"> <select column="1" /> <select column="4" /> </zone> MXML format: <mx:zone columns="3"> <mx:select colu...

Serialize an array of objects as Xxxxs rather than ArrayOfXxxx

I'm using ASP.NET MVC with XmlResult from MVCContrib. I have an array of Xxxx objects, which I pass into XmlResult. This gets serialized as: <ArrayOfXxxx> <Xxxx /> <Xxxx /> <ArrayOfXxxx> I would like this to look like: <Xxxxs> <Xxxx /> <Xxxx /> <Xxxxs> Is there a way to specify how a class gets serialized when it is part ...

VB.NET, make a function with return type generic ?

Currently I have written a function to deserialize XML as seen below. How do I change it so I don't have to replace the type every time I want to serialize another object type ? The current object type is cToolConfig. How do I make this function generic ? Public Shared Function DeserializeFromXML(ByRef strFileNameAndPath As Strin...

Issue allowing custom Xml Serialization/Deserialization on certain types of field

I've been working with Xml Serialization/Deserialization in .net and wanted a method where the serialization/deserialization process would only be applied to certain parts of an Xml fragment. This is so I can keep certain parts of the fragment in Xml after the deserialization process. To do this I thought it would be best to create a ne...