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
32
votes
4 answers

How to rename XML attribute that generated after serializing List of objects

I am serializing List of objects List , and XmlSerializer generates attribute, I want rename it or remove it. Can it be done with creating new class that encapsulated List as field? [XmlRoot("Container")] …
ilann
  • 453
  • 3
  • 10
  • 15
31
votes
2 answers

ShouldSerialize*() vs *Specified Conditional Serialization Pattern

I am aware of both of the ShouldSerialize* pattern and the *Specified pattern and how they work, but is there any difference between the two? Are there any "gotchas" using one method vs the other when certain things should be serialized…
JNYRanger
  • 6,829
  • 12
  • 53
  • 81
30
votes
3 answers

Prevent XmlSerializer from formatting output

When using the default settings with the XmlSerializer it will output the XML as a formated value. IE: something along these lines.
Maxim Gershkovich
  • 45,951
  • 44
  • 147
  • 243
30
votes
7 answers

How can I XML Serialize a DateTimeOffset Property?

The DateTimeOffset property I have in this class doesn't get rendered when the data is represented as Xml. What do I need to do to tell the Xml serialization to render that proper as a DateTime or DateTimeOffset? [XmlRoot("playersConnected")] public…
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
30
votes
8 answers

Remove whitespaces in XML string

How can I remove the whitespaces and line breaks in an XML string in Python 2.6? I tried the following packages: etree: This snippet keeps the original whitespaces: xmlStr = ''' ''' xmlElement…
desolat
  • 4,123
  • 6
  • 36
  • 47
30
votes
5 answers

XmlSerializer: The string '' is not a valid AllXsd value

I'm getting this message,"The string '7/22/2006 12:00:00 AM' is not a valid AllXsd value.", when deserializing an XML, the element contains a date, this is the property that is supposed to be mapped to the…
ryudice
  • 36,476
  • 32
  • 115
  • 163
30
votes
2 answers

How do you use XMLSerialize for Enum typed properties in c#?

I have a simple enum: enum simple { one, two, three }; I also have a class that has a property of type simple. I tried decorating it with the attribute: [XmlAttribute(DataType = "int")]. However, it fails when I try to serialize it using…
Rhubarb
  • 3,893
  • 6
  • 41
  • 55
30
votes
4 answers

Is it possible to customize the namespace prefix that JAXB uses when marshalling to a String?

For example, I've got a simple schema which imports another schema. The second schema (urn:just:attributes, just-attributes.xsd) just defines an attribute group.
user197614
30
votes
6 answers

Slow SoapHttpClientProtocol constructor

I'm doing some experiments with Microsoft Dynamics CRM. You interact with it through web services and I have added a Web Reference to my project. The web service interface is very rich, and the generated "Reference.cs" is some 90k loc. I'm using…
friism
  • 19,068
  • 5
  • 80
  • 116
29
votes
9 answers

How do I map XML to C# objects

I have an XML that I want to load to objects, manipulate those objects (set values, read values) and then save those XMLs back. It is important for me to have the XML in the structure (xsd) that I created. One way to do that is to write my own…
Ragoler
  • 1,261
  • 4
  • 15
  • 20
29
votes
3 answers

xml serialization - remove namespace

I am serializing an object using c#. I am getting result in this format given bellow
Pankaj
  • 4,419
  • 16
  • 50
  • 72
29
votes
7 answers

How to make a value type nullable with .NET XmlSerializer?

Let's suppose I have this object: [Serializable] public class MyClass { public int Age { get; set; } public int MyClassB { get; set; } } [Serializable] public class MyClassB { public int RandomNumber { get; set; } } The XmlSerializer…
Jean-Francois
  • 1,332
  • 3
  • 17
  • 24
29
votes
1 answer

how to deserialize an xml node with a value and an attribute using asp.net serialization

I have 4 small classes to deserialize xml from an incomming xml poll, to usable classes to build up the poll. now, i know how to set a property from a class, to match a certain attribute or element in the xml, and if that element is just a string…
Sander
  • 13,301
  • 15
  • 72
  • 97
28
votes
1 answer

Preserve serialization-order of members in CodeDOM

I know we can enforce generating the members within the classes in the same order as within the members-collection as stated on MSDN. However I look for some code that also adds a serialization-attribute providing the order of those members. So this…
MakePeaceGreatAgain
  • 35,491
  • 6
  • 60
  • 111
27
votes
4 answers

Suppressing namespace prefixes in ElementTree 1.2

In python 2.7 (with etree 1.3), I can suppress the XML prefixes on elements like this: Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin Type "help", "copyright",…
jterrace
  • 64,866
  • 22
  • 157
  • 202