Generating an Xml Serialization assembly as part of my build

As Martin has explained in his answer, turning on generation of the serialization assembly through the project properties is not enough because the SGen task is adding the /proxytypes switch to the sgen.exe command line. Microsoft has a documented MSBuild property which allows you to disable the /proxytypes switch and causes the SGen Task to … Read more

Deciding on when to use XmlDocument vs XmlReader

I’ve generally looked at it not from a fastest perspective, but rather from a memory utilization perspective. All of the implementations have been fast enough for the usage scenarios I’ve used them in (typical enterprise integration). However, where I’ve fallen down, and sometimes spectacularly, is not taking into account the general size of the XML … Read more

Why isn’t there an XML-serializable dictionary in .NET?

I know this has been answered before, but since I have a very concise way (code) for doing IDictionary serialization with the DataContractSerializer class (used by WCF, but could and should be used anywhere) I couldn’t resist contributing it here: public static class SerializationExtensions { public static string Serialize<T>(this T obj) { var serializer = … Read more

XML Serialize generic list of serializable objects

I have an solution for a generic List<> with dynamic binded items. class PersonalList it’s the root element [XmlRoot(“PersonenListe”)] [XmlInclude(typeof(Person))] // include type class Person public class PersonalList { [XmlArray(“PersonenArray”)] [XmlArrayItem(“PersonObjekt”)] public List<Person> Persons = new List<Person>(); [XmlElement(“Listname”)] public string Listname { get; set; } // Konstruktoren public PersonalList() { } public PersonalList(string name) { … Read more

JAXB: How to ignore namespace during unmarshalling XML document?

Here is an extension/edit of VonCs solution just in case someone doesn´t want to go through the hassle of implementing their own filter to do this. It also shows how to output a JAXB element without the namespace present. This is all accomplished using a SAX Filter. Filter implementation: import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.XMLFilterImpl; … Read more

Serialize Property as Xml Attribute in Element

You will need wrapper classes: public class SomeIntInfo { [XmlAttribute] public int Value { get; set; } } public class SomeStringInfo { [XmlAttribute] public string Value { get; set; } } public class SomeModel { [XmlElement(“SomeStringElementName”)] public SomeStringInfo SomeString { get; set; } [XmlElement(“SomeInfoElementName”)] public SomeIntInfo SomeInfo { get; set; } } or a more … Read more

Force XmlSerializer to serialize DateTime as ‘YYYY-MM-DD hh:mm:ss’

In the past, I’ve done the following to control datetime serialization: Ignore the DateTime property. Create a dummy string property that serializes/deserializes the way I want Here is an example: public class SomeClass { [XmlIgnore] public DateTime SomeDate { get; set; } [XmlElement(“SomeDate”)] public string SomeDateString { get { return this.SomeDate.ToString(“yyyy-MM-dd HH:mm:ss”); } set { … Read more