Serializes and deserializes objects into and from XML documents. The XmlSerializer enables you to control how objects are encoded into XML.
Questions tagged [xmlserializer]
1432 questions
6
votes
5 answers
XmlSerializer define default value
We have an xml document with some user settings. We just added a new setting (which is not found in legacy xml documents) and the XmlSerializer automatically sets it to false.
I tried DefaultValueAttribute but it doesn't work. Any idea on how I can…

Carlo
- 25,602
- 32
- 128
- 176
6
votes
1 answer
Symfony Serializer XML add custom attribute to root node
When generating an XML file with Serializer component (in Symfony4) I want to add a custom attribute to the root node but I can't figure out how to.
The docs mention how to name the root node, but not how to add custom attributes.
In my service I…

Miguel
- 201
- 1
- 7
6
votes
1 answer
Is there a way to avoid self-closing tags when using XML Serialization?
I am working with VB.NET and I am facing a problem with XML serialization. When empty values exists in the object I am serializing, the XML file contains the following tags:
instead of:
I know that it's the same, but…

Pan
- 61
- 2
6
votes
3 answers
Troubles wtih comments in XmlSerialzier
I try to load a XML file with this code:
XmlSerializer xmlSerializer = new XmlSerializer(typeof(MyObject));
StreamReader reader = new StreamReader(fileName);
object myobject = xmlSerializer.Deserialize(reader);
When the file contains a comment like…

Dav
- 61
- 1
- 2
6
votes
5 answers
How can I override the serialized name of each list item in a List() in c#?
I have a struct more or less like this:
[Serializable]
[XmlRoot("Customer")]
public struct TCustomer
{
string CustomerNo;
string Name;
}
I sometimes serialize this this struct to XML as a single object, which works fine, but I also sometimes…

Thomas Kjørnes
- 1,928
- 1
- 17
- 17
6
votes
1 answer
How to serialize dynamic object to xml c#
I have a object {System.Collections.Generic.List

Lucio Zenir
- 365
- 2
- 8
- 18
6
votes
1 answer
Performance: XmlSerializer vs XmlReader vs XmlDocument vs XDocument
I'm working on a little web project and would like to read/write to an XML file. Performance is my first priority.
I've come to this great post on comparing the mentioned approaches except XmlSerializer.
I prefer XmlSerializer since it makes the…

Kamyar
- 18,639
- 9
- 97
- 171
6
votes
4 answers
How to output hex numbers via XML Serialization in c#?
I've got a few classes and structures that I use XML serialization to save and recall data, but a feature that I'd like to have is to output integers in hex representation. Is there any attribute that I can hang on these structure to make that…

Gio
- 4,099
- 3
- 30
- 32
6
votes
1 answer
how to remove namespace from XML root element?
is there a simple way to remove the namespace from the XML root element. I have tried with
[XmlRootAttribute("MCP", Namespace = "", IsNullable = false)]
on the serializable class. But no use. still getting the same result.
sample…

RameshVel
- 64,778
- 30
- 169
- 213
6
votes
3 answers
Rename class when serializing to XML
I'm trying to serialize the Outer class shown below, and create an XElement from the serialized XML. It has a property which is of type Inner. I'd like to change the name of both Inner (to Inner_X) and Outer (to Outer_X).
class Program
{
static…

Ben L
- 1,302
- 11
- 23
6
votes
4 answers
How do I stop an empty tag from being emitted by XmlSerializer?
I have an object like this,
public class UserObj
{
public string First {get; set;}
public string Last {get; set;}
public addr Address {get; set;}
}
public class addr
{
public street {get; set;}
public town {get; set;}
}
Now…

John
- 1,852
- 4
- 26
- 49
6
votes
2 answers
How does DataContractSerializer write to private fields?
I understand how XMLSerializer could work by using reflection to figure out what public read/write fields or properties it should be using to serialize or de-serialize XML. Yet XMLSerializer requires that the fields be public and read/write.…

Eric Anastas
- 21,675
- 38
- 142
- 236
6
votes
2 answers
How can I validate the output of XmlSerializer?
In C# / .NET 2.0, when I serialize an object using XmlSerializer, what's the easiest way to validate the output against an XML schema?
The problem is that it is all too easy to write invalid XML with the XmlSerializer, and I can't find a way to…

Tim Jansen
- 3,330
- 2
- 23
- 28
6
votes
1 answer
XmlSerializer not serializing two enum attributes
We are currently trying to serialize a set of objects to xml using the XmlSerializer.Serialize
We have tested the XmlSerializer with the following stubs
private static void TestMethod()
{
ChartContentConfig Config = new ChartContentConfig();
…

Matt W
- 323
- 3
- 14
6
votes
2 answers
How can I deserialize heterogeneous child nodes into a collection, using XmlSerializer?
I'm using C#/.NET to deserialize a XML file that looks akin to this:
""
""
""
...
…

Craig
- 1,890
- 1
- 26
- 44