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
40
votes
3 answers

What is an object graph and how do I serialize one

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?
pkolodziej
  • 1,347
  • 3
  • 17
  • 24
40
votes
5 answers

Is htmlentities() sufficient for creating xml-safe values?

I'm building an XML file from scratch and need to know if htmlentities() converts every character that could potentially break an XML file (and possibly UTF-8 data)? The values will be from a twitter/flickr feed, so I need to be sure-
John Himmelman
  • 21,504
  • 22
  • 65
  • 80
40
votes
1 answer

Using XmlSerializer with an array in the root element

I have an XML document similar to the following: ... ...
Hand-E-Food
  • 12,368
  • 8
  • 45
  • 80
38
votes
6 answers

Why is the XmlWriter always outputting utf-16 encoding?

I have this extension method public static string SerializeObject(this T value) { var serializer = new XmlSerializer(typeof(T)); var settings = new XmlWriterSettings { …
Glenn Slaven
  • 33,720
  • 26
  • 113
  • 165
37
votes
1 answer

Serializing a list of Key/Value pairs to XML

I have a list of key/value pairs I'd like to store in and retrieve from a XML file. So this task is similar as described here. I am trying to follow the advice in the marked answer (using a KeyValuePair and a XmlSerializer) but I don't get it…
Slauma
  • 175,098
  • 59
  • 401
  • 420
36
votes
2 answers

.net XML Serialization - Storing Reference instead of Object Copy

In .Net/C# Application, I have data structures which have references to each other. When I serialize them, .Net Serializes all references with separate object copies. In Following Example, I am trying to serialize to Array of 'Person' A 'Person'…
Palani
  • 8,962
  • 11
  • 53
  • 62
35
votes
1 answer

XML Serialization question - How to Serialize Element, Attribute and Text from One Object

I'm new into XML Serialization using .NET and after working with it for some time I'm quite fuzzled now. I can serialize elements with attributes containing other elements but how can I serialize something like
Haiko Wick
  • 407
  • 1
  • 5
  • 13
35
votes
3 answers

Convert an org.w3c.dom.Node into a String

Sorry I'm a Java/XML newbie - and can't seem to figure this one out. It seems it's possible to convert a Document object to a string. However, I want to convert a Node object into a string. I am using org.ccil.cowan.tagsoup Parser for my…
ragebiswas
  • 3,818
  • 9
  • 38
  • 39
34
votes
5 answers

Immutability and XML Serialization

I have several classes that are immutable once their initial values are set. Eric Lippert calls this write-once immutability. Implementing write-once immutability in C# usually means setting the initial values via the constructor. These values…
dthrasher
  • 40,656
  • 34
  • 113
  • 139
33
votes
2 answers

How do I add a attribute to a XmlArray element (XML Serialization)?

How do I add a attribute to a XmlArray element ( not to XmlArrayItem ) while serializing the object?
123Developer
  • 1,463
  • 3
  • 17
  • 24
32
votes
6 answers

Convert XML to String and append to page

I want to convert an xml element like this: ​B0013FRNKG​​ to string in javascript I used XMLSerializer: new XMLSerializer().serializeToString(xml); the string only shows on alert() and in the console. On the page it just says [object…
rzcl
  • 323
  • 1
  • 3
  • 4
32
votes
2 answers

Change the order of elements when serializing XML

I need to serialize an Object to XML and back. The XML is fix and I can't change it. I fail to generate this structure after bookingList. How can I "group" these elements to appear as a LIST and keep & before this List…
Hannes_hal
  • 637
  • 1
  • 7
  • 13
32
votes
5 answers

How can I serialize internal classes using XmlSerializer?

I'm building a library to interface with a third party. Communication is through XML and HTTP Posts. That's working. But, whatever code uses the library does not need to be aware of the internal classes. My internal objects are serialized to XML…
Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123
32
votes
9 answers

How to deserialize only part of an XML document in C#

Here's a fictitious example of the problem I'm trying to solve. If I'm working in C#, and have XML like this: 1020 Nissan
Mike
  • 5,560
  • 12
  • 41
  • 52
32
votes
4 answers

Prevent timezone conversion on deserialization of DateTime value

I have a class that I serialize/deserialize using XmlSerializer. This class contains a DateTime field. When serialized, the DateTime field is represented by a string that includes the offset from GMT, e.g 2010-05-05T09:13:45-05:00. When…
Odrade
  • 7,409
  • 11
  • 42
  • 65