xml-serialization

JAXB Work-Flow - How Do You Jump into Using JAXB

The JAXB documentation is like a text-book, and I simply don't have to time to learn everything JAXB before I need to use it. I have an XSD, if I want to use JAXB to marshal and un-marshal what is the workflow? I don't need any specifics just a high level view. What I know already: 1. JAXB can be used to take objects and create XML do...

How do I serialize multple objects with the same base class to xml?

Here's the code I'm using. I keep getting xml document errors [Serializable] [XmlRoot("Command")] public class Command { [XmlElement("CommandType")] public CommandType CommandType { get; set; } } [Serializable] [XmlRoot("DelayCommand")] [XmlInclude(typeof(Command))] public class DelayCommand : Command { [XmlElement("Delay")...

Proxy not getting attributes on virtual properties?

Using DynamicProxy 2.2 I think I'm seeing this issue: "Inheritable attributes on virtual properties not available on proxy" http://support.castleproject.org/projects/DYNPROXY/issues/view/DYNPROXY-ISSUE-109 I've got a base class with a virtual property. The property is marked with [XmlIgnore]. If I serialize a derived class, the prop...

XML Serialization of the default values of optional attributes

I have a set of classes build using xsd.exe, and I am trying to serialise them. However, an attribute is not being included in the resulting XML. Here is part of the schema where the problem lies. <xsd:element name="Widget"> <xsd:complexType> /* sequence removed for brevity */ <xsd:attribute name="Version" type="Vers...

Serialize to specific XSD using XmlSerializer

I have a business specific, internal XSD which we are using to represent a business-level exception (that is: not necessarilly one in code, but an error in a process) so that different business units can inform eachother when inter-unit processes have failed. I have been tasked with writing a component to log these exceptions, along wit...

Change class signature, process old xml serialized instances

Let's assume I have got a class like: public class SomeObject { public Guid InternalId { get; set; } public string Address { get; set; } } I store instances of this object into the ASP.NET profile. It get's XML serialized and everything is fine. Now I want to reduce the size of the profile, and I want to replace the long prope...

How can I fix the web reference proxy that Visual Studio generated to handle jagged arrays?

It seems there is a known bug in wsdl.exe, the tool that Visual Studio uses to generate web service proxies. With certain XSD schemas the tool will generate classes that can't be deserialized from the XML. As far as I'm concerned that's unacceptable, but I don't know how to fix it. I will describe my case in detail, hopefully somebody...

Serializing Dictionary<string, object> when dictionary was initialized with case insensitive string comparer

I am serializing a Dictionary to XML. When I create a new dictionary I use the constructor to provide EqualityComparer without casing for instance var tabs = new Dictionary<string,Tab>(StringComparer.OrdinalIgnoreCase); I then serialize to XML and when I deserialize information about casing is lost - the deserialization is made to the...

How can I add knowledge of namespaces before I deserialize XML

I've found several examples of creating XmlSerializerNamespaces and adding 1 to many namespaces, then serializing based on the object and the list of namespaces. I can't find any examples of where I have an XML string and I need to deserialize and I want to utilize the namespaces. I've tried reading the string into an XmlTextReader and...

XmlSerializer: How can I allow a property to deserialize, but then stop it from serializing?

That is, I'd like my data to go one way - feed into a class, but then prevent it from saving out during a serialize operation. What's the best way to go about that? ...

How to access a type defined in another schema when the only sub-element is ##any

I am creating a schema where the root element is defined in schema1.xsd. The definition of this element has a sub-element of 'ID', followed by this: <xsd:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> I need to access an element defined in schema2.xsd. How do I do this? Originally, I tried extend...

Populating parent + child objects from SQL Server 2008 (via XML?)

I have simple DAL that consists of a SalesEnquiry object, which includes a List<T> of a Vehicle object, which is used to process incoming enquiries (XML) and write them to a DB. So far so good. However, I'm writing another app that further processes data in this DB, so I'm wanting to use these same DAL objects to retrieve and manipulate...

XmlSerializer special characters

Hi All, Currently I have the following code: namespace ConsoleApplication2 { class Program { static void Main(string[] args) { var myObject = new MyObject() {Text = "€ 232.22"}; StringBuilder sb = new StringBuilder(); var xmlWriterSettings = new XmlWriterSettings(); ...

Xml DeSerialization from an internal node

I'm working on getting my .net object serialized\deserialized. As a requirement for our XML files, the object must be inside a master node named "MyCompany", here is an example for the file: <?xml version="1.0" encoding="utf-8"?> <mycompany> <station> <serial>VAA008090067</serial> </station> </mycompany> I'm running into an i...

How to serialize two object with `one-to-many` relationship?

I have two classes: Lookup and LookupItem that Lookup has a member named Items that is a collection of LookupItems. I'm not able to serialize Lookup or LookupItem. With the first I get error The type LookupItem was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically. and with the secon...

Why is XML serialzation suggested over SOAP and binary serialzation?

I'm trying to serialize a string with some escape characters (\0). But when I deserialise it throws an exception. //XML serialization private static void M1() { string str = "\0AC"; StringWriter sw = new StringWriter(); XmlSerializer serializer = new XmlSerializer(typeof(String)); ...

Converting Serialized Java Classes Between XML and Binary

I am using Java native serialization along with a dynamic proxy to save the parameters and returns of a series of method calls to a file. I would like to convert the binary file that is generated to and from XML. Is this something that I will need to reinvent, or are there already tools out there that can do this? ...

Is it possible to serialize a .NET object in XML without the type as the element root?

Suppose I have a collection in a class that I'd like to have serialized to XML: [Serializable] public class DriveReport : IXmlSerializable { public int Capacity { get; set; } public int FreeSpace { get; set; } public char DriveLetter { get; set; } //Assume that the appropriate IXMLSerializable methods are here, where //t...

Handling XML Serialization of read-only fields in C#

I've got a class that has a read-only property defined that is actually a reference to a very mutable object, and I'm wondering what the best way to handle the serialization of it is. For example: public class classA { public readonly classB B = new classB(); } public class classB { public string Name = "Test"; } This can be ser...

Serialize an IntPtr using XmlSerializer

I'm wondering why the IntPtr type is not supported by the XmlSerializer implementation. When I try to serialize a class including a field of IntPtr type, the serialization fails telling me that IntPtr is not supported, and ignore that member. To workaround this, I translate the IntPtr value to a Int64... but is it a good idea? It should...