xml-serialization

Which characters are Invalid (unless encoded) in an XML attribute?

I can't believe I can't find this information easily accessible, so: 1) Which characters cannot be incorporated in an XML attribute without entity-encoding them? Obviously, you need to encode quotes. What about < and >? What else? 2) Where exactly is the official list? ...

Can I make XmlSerializer ignore the namespace on deserialization?

Can I make XmlSerializer ignore the namespace (xmlns attribute) on deserialization so that it doesn't matter if the attribute is added or not or even if the attribute is bogus? I know that the source will always be trusted so I don't care about the xmlns attribute. ...

Xml Serialization without Disposing

using (var file_stream = File.Create("users.xml")) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close(); } Using the above code works perfectly. However, when I shorten it to: var serializer = new...

What is an object graph and how do I serialize one

Hi I've been reading lately about serialization. I've read that when I use XmlSerialization I cannot serialize object graphs. What is an object graph and why I cannot serialize it simply? Kind Regards PK ...

How can I do to bind an arbitrary element with CDATA in serialize of XML_Serializer? :php

$serializer = new XML_Serializer($options); $serializer->serialize($some_array); $output = $serializer->getSerializedData(); I want to surround an arbitrary element generating XML with an above cord in CDATA, but I can't do it. Will not there be any good method? XML_SERIALIZER_OPTION_CDATA_SECTIONS = true When I used it with this opti...

How to add an attribute to a serialized XML node?

Assume I have a C# class like this: [XmlRoot("floors")] public class FloorCollection { [XmlElement("floor")] public Floor[] Floors { get; set; } } And I want to serialize it and send to a REST API using WCF. But before sending I need adding an attribute to the floors node in this way: <floors type="array">...</floors> Any id...

Which One Better Handles Versioning? XmlSerializer vs. DataContractSerializer?

In need to serialize an object and it's possible that the assembly version changed while deserialization. Additionally it can happen, that the object changes a bit. The XmlSerializer does not store type information and if the object changes a bit, it just does not fail, but the XmlSerializer can not serialize private or internal propert...

XmlSerializer Could Not Find File C:\Windows\Temp\*.dll

I have an ASP.NET 2.0 web application running on a shared server of a well known web hosting provider. Occasionally I seem to be getting errors like this: Could not find file 'C:\WINDOWS\TEMP\lxnmfrsz.dll'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for m...

XmlSerializer.Deserialize() isn't deserializing a List<T> correctly

I am new to the C# XmlSerializer so I might be missing something basic here. The problem I am running into is that I have one class that has a List<T> of another class. When I serialize the main class the XML looks beautiful and all the data is intact. When I deserialize the XML, the data in the List<T> disappears and I am left with a...

How to serialize a list of lists with the type of custom object?

Here is the code: [XmlRoot("Foo")] class Foo { [XmlElement("name")] string name; } [XmlRoot("FooContainer")] class FooContainer { [XmlElement("container")] List<List<Foo>> lst { get; set; } } XmlSerializer s = new XmlSerializer(typeof(FooContainer)); -->Can't pass thr...

XmlSerializer and Collection property with private setter

Say I have a simple class like so [Serializeable] public class MyClass { public MyClass() { this.MyCollection = new List<int>(); } public List<int> MyCollection { get; private set;} } If I try to deserialize this using XmlSerializer I get an error saying that MyCollection is readonly and cannot be assigned to....

XML Serialization is slow

I've inherited a project where the application's data model is an XML document. The developers before me had created an object model based on this xml's schema, and then coded against the object model. After several years of maintenance, this application has gradually started to show its age. The team leader has said that the key reason...

Best way to implement IXmlSerializable ReadXml() using XPath

Hi, I'm implementing the ReadXml() method of IXmlSerializable and I figure using XPath is probably the nicest way to do this. However, ReadXml() needs to handle the reader position properly. So given that my WriteXml() produces something like this: <ObjectName> <SubNode>2</SubNode> <SubNode>2</SubNode> </ObjectName> Is there a ...

PHP hand-made serialization trouble.

In my task would be very nice to write a kind of objects serialization (for XML output). I've already done it, but have no idea, how to avoid recursive links. The trouble is that some objects must have public(!) properties with links to their parents (it's really nessecary). And when I try to serialize a parent object which agregates so...

How to use default XML serialization from within custom XML serialization methods

I have a class in .NET that implements IXmlSerializable. I want to serialize its properties, but they may be complex types. These complex types would be compatible with XML serialization, but they don't implement IXmlSerializable themselves. From my ReadXml and WriteXml methods, how do I invoke the default read/write logic on the XmlR...

Is XML Serialization really different from XML databinding, and if so, how?

There's a related question What is the preferred Java XML binding framework? In the answer currently ranked 2nd there, the poster drew a distinction between XML Serialization, and Java/XML data binding. As best I can tell, XML data binding means "creating an in-memory object graph from an XML document". And XML Serialization means "cr...

C# XML Serialization of double[] to single space-delimited element

I am writing an app in C# to serialize and array of double or float to a single XML element that is a space-delimited list of the values in the array. double[] d = new double[4] { 1.0, 2.0, 3.0, 4.0 }; to the XML element: <ArrayOfDouble type="double">1.0 2.0 3.0 4.0</ArrayOfDouble> I am trying to use the XmlSerializer to perform th...

Serializing a List<T> to XML with inheritance

I've run into some problems when trying to serialize my object to XML. The problem appears when trying to serialize a "Profiles" property which is a List of Profile items. Profile is my own type. The Profile type should ideally be abstract, but it isn't, since XML serialization demands a parameterless ctor. The Profiles property contains...

export null values to xml from a dataset

If you have a null value in a field in a dataset and export it to xml it does "remove" the field tag .. anyway to avoid this.. ...

CS2000: Compiler initialization failed unexpectedly

I have a WPF .NET 3.5 SP1 application that is in use on at least hundreds if not thousands of machines at this point. The application stores a tree structure in XML that is loaded at startup. As soon as I try to load the xml via serialization, boom. It only happens on one end user machine. He has admin rights, plenty of disk space, m...