Questions tagged [xml-serialization]

This tag refers to serialization technologies which use XML as a data format.

This tag refers to serialization technologies which use XML as a data format. In the context of .NET, it refers to the XmlSerializer class, less so to the DataContractSerializer class, still less to the SoapFormatter class.

4687 questions
51
votes
5 answers

What are the differences between the XmlSerializer and BinaryFormatter

I spent a good portion of time last week working on serialization. During that time I found many examples utilizing either the BinaryFormatter or XmlSerializer. Unfortunately, what I did not find were any examples comprehensively detailing the…
ahsteele
  • 26,243
  • 28
  • 134
  • 248
50
votes
2 answers

Is there a reason why a base class decorated with XmlInclude would still throw a type unknown exception when serialized?

I will simplify the code to save space but what is presented does illustrate the core problem. I have a class which has a property that is a base type. There are 3 derived classes which could be assigned to that property. If I assign any of the…
Tedford
  • 2,842
  • 2
  • 35
  • 45
50
votes
1 answer

using XmlArrayItem attribute without XmlArray on Serializable C# class

I want XML in the following format: ... ...
Sarah Vessels
  • 30,930
  • 33
  • 155
  • 222
50
votes
12 answers

PHP Object as XML Document

What is the best way to take a given PHP object and serialize it as XML? I am looking at simple_xml and I have used it to parse XML into objects, but it isn't clear to me how it works the other way around.
Sam McAfee
  • 10,057
  • 15
  • 60
  • 64
47
votes
7 answers

How to decode string to XML string in C#

I have a string (from a CDATA element) that contains description of XML. I need to decode this string into a new string that displays the characters correctly using C# Existing String: <?xml version="1.0" encoding="UTF-8"…
user31673
  • 13,245
  • 12
  • 58
  • 96
46
votes
7 answers

XmlSerializer won't serialize IEnumerable

I have an invocation logger that is intended to record all method calls along with the parameters associated with the method using XmlSerializer. It works well for most of the calls, but it throws an exception for all methods that has a parameter of…
uni
  • 613
  • 1
  • 7
  • 11
46
votes
3 answers

Generating XML file using XSD file

How do you generate an XML file from an XSD file?
sachin kulkarni
  • 2,618
  • 7
  • 28
  • 33
45
votes
5 answers

How to keep XmlSerializer from killing NewLines in Strings?

Suppose I have a simple Class with just one Member a String. public class Abc { private String text; public String Text { get { return this.text; } set { this.text = value; } } } Now when I serialize and then…
Thomas
  • 793
  • 1
  • 8
  • 16
44
votes
5 answers

Java Serialization vs JSON vs XML

I am wondering what serialized mechanism should we choose when dealing with object transferring over the network. What are the pros and cons ? I know most of the time we use JSON or XML for AJAX since the transfer format are pretty much Javascript…
peter
  • 8,333
  • 17
  • 71
  • 94
43
votes
5 answers

Force XML serialization to serialize readonly property

In C#, I have a class which has a derived property that should be serialized via XML. However, XML serialization (by default) doesn't serialize read=only properties. I can work around this by defining an empty setter like so: public virtual string…
Chris
  • 27,596
  • 25
  • 124
  • 225
43
votes
7 answers

Most elegant XML serialization of Color structure

One problem bugged me enough to register on Stack Overflow. Currently if I want to serialize Color to XML string as named color, or #rrggbb, or #aarrggbb, I do it like this: [XmlIgnore()] public Color color; [XmlElement(ElementName =…
Dialecticus
  • 16,400
  • 7
  • 43
  • 103
43
votes
2 answers

Serializing object with no namespaces using DataContractSerializer

How do I remove XML namespaces from an object's XML representation serialized using DataContractSerializer? That object needs to be serialized to a very simple output XML. Latest & greatest - using .Net 4 beta 2 The object will never need to be…
42
votes
5 answers

DataContractSerializer - how can I output the xml to a string (as opposed to a file)

I had a quick question regarding the datacontractserializer. Maybe it's more of a stream question. I found a piece of code that writes the xml to a filestream. I basically don't want the file and just need the string output. public static string…
Hcabnettek
  • 12,678
  • 38
  • 124
  • 190
41
votes
6 answers

Serializing a Nullable in to XML

I am trying to serialize a class several of the data-members are Nullable objects, here is a example [XmlAttribute("AccountExpirationDate")] public Nullable AccountExpirationDate { get { return userPrincipal.AccountExpirationDate; } …
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
41
votes
4 answers

How to add attributes for C# XML Serialization

I am having an issue with serializing and object, I can get it to create all the correct outputs except for where i have an Element that needs a value and an attribute. Here is the required output: Retrieve
user107779
  • 41
  • 1
  • 2
  • 8