xml-serialization

How do I specify XML serialization attributes to support namespace prefixes during deserialization in .NET?

I have a following XML: <person xmlns:a="http://example.com" xmlns:b="http://sample.net"&gt; <a:fName>John</a:fName> <a:lName>Wayne</a:lName> <b:age>37</b:age> </person> How do I define XML serialization attributes on a class to support described scenario? ...

How can I deserialize a list of DateTime objects?

If I have the following XML segment: <Times> <Time>1/1/1900 12:00 AM</Time> <Time>1/1/1900 6:00 AM</Time> </Times> What should the corresponding property look like that, when deserialization occurs, accepts the above XML into a list of DateTime objects? This works to deserialize the XML segment to a list of string objects: [XmlA...

ASMX Web service not serializing abstract base class

I have an abstract class. Let's call it Lifeform. It looks something like: public abstract class Lifeform { public virtual int Legs { get; set; } public virtual int Arms { get; set; } public virtual bool Alive { get; set; } } (The virtual attribute is due to the fact that I'm using nHibernate, which whines if they're not v...

Putting each attribute on a new line during xml serialization

Lets say I have a DOM object (or a string containing xml). Is it in any way possible to serialize the xml in such a way that each attribute appears on a new line? This is the output I want: <parent> <anElement attrOne="1" attrTwo="2" attrThree="3" /> </parent> Preferred if the solution a part of the ...

How do you find out when you've been loaded via XML Serialization?

I'm trying to load a tree of objects via XML serialisation, and at the moment it will load the objects in, and create the tree quite happily. My issue revolves around the fact that these classes support a level of auditing. What I'd like to be able to do is call some method on each object after it has finished being loaded. For the sake...

How do I set the dataProvider for an <s:List> component to be an XML file?

I've got the latest Beta of Adobe Flash Builder 4. I want to use a <s:List> component, and specify the dataProvider as being an XML file. However, after loads of research (including looking at doc links off labs.adobe.com), I still can't figure out how to do it. The XML file will look something like this: <?xml version="1.0" encoding...

Encoding special characters in xml

How to encode special characters in xml? e.g: i have a special character mu in my xml, transformation will fail due to this character any info would be helpful Thanks Preetham ...

Xml Serialization inside a collection

XmlRoot does not seem to work with classes that are contained within a collection. Here are the classes I have defined: [XmlRoot("cars")] public class CarCollection : Collection<Car> { } [XmlRoot("car")] public class Car { [XmlAttribute("make")] public String Make { get; set; } [XmlAttribute("model")] public String Model { get...

Custom xml de/serialization in ConfigurationSection (like using IConfigurationSectionHandler)

I would like to use my own custom XML format in my Web.config. In .Net 1.1 I was using IConfigurationSectionHandler combined with XmlSerializer. Because IConfigurationSectionHandler is depreciated, I want to do the same with ConfigurationSection. I tried it like this: protected override void DeserializeSection(System.Xml.XmlReader r...

reading xstream generated xml into .net

We'd like to generate xml using xstream implemented with java. We'd then like to consume that xml in a .net application and have it deserialized into c# classes. has anyone had success in doing this? is there a framework available on the C# side that will make it easier and more robust than something we'd have to roll-up? ...

.NET XML Serialization Helper Class

I Collected the info from one of the previous StackoverFlow Q & A that The following items can be serialized using the XmLSerializer class: •Public read/write properties and fields of public classes •Classes that implement ICollection or IEnumerable •XmlElement objects •XmlNode objects •DataSet objects My Question i...

XML Serialization of KeyValuePairCollection - Only One Entry is getting serialized When Only One Entry is Present

This is my KeyValue collection KeyValuePairCollection<int,string> KV=new KeyValuePairCollection<int,string>(); KV.Key = 1; KV.Value = "Chapter1"; KV.Key = 2; KV.Value = "Chapter2"; KV.Key = 3; KV.Value="Chapter3"; I serialized the collection using the code below StreamWriter txtWrt=null; string m_ArraylstfileName = @"d:\XML\Generics...

XSD.exe /dataset is not creating enumerations from my xsd file

I have created an XSD and have run XSD.exe on top of that .xsd file. It seems that my simple types that are restricted to enumeration values are not being generated as enums in the outputted .cs file. For example, my xsd looks like this: <xs:element name="ItemList" nillable="false"> <xs:complexType> <xs:sequence minOccurs="1" maxOc...

C# XML Serialization of an array - Skip "empty" string values

I want to skip the empty element creation in XML file during the xml Serialization in C#. Ex : ArrayElements elm = new ArrayElements { Items =new string[] "Item1", " ", "Item2", " ", " ", "Items" } }; During the serialization it should skip the empty strings. This is my class : [Serializable] public class ArrayElements { [Xml...

Getting bad generated code from "Update Service Reference"

In VB.NET (using Visual Studio 2008) my WCF service has an interface something like: <ServiceContract()> _ Public Interface IThingService <OperationContract()> _ Function GetThingByNumber(ByVal thingNumber As MyKeyClass) As Thing <OperationContract()> _ Function GetThing(ByVal thingId As Guid) As Thing ' ... End Inter...

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 initialize readonly fields. But if you need to serialize a class like this to XML, using eith...

Suppress Null Value Types from Being Emitted by XmlSerializer

Please consider the following Amount value type property which is marked as a nullable XmlElement: [XmlElement(IsNullable=true)] public double? Amount { get ; set ; } When a nullable value type is set to null, the C# XmlSerializer result looks like the following: <amount xsi:nil="true" /> Rather than emitting this element, I wou...

Roundtrip XML Serialization of DateTime and xsd:date?

OK, what am I missing here? MSDN says the following with regard to DateTimeSerializationMode: In versions 2.0 and later of the .Net Framework, with this property set to RoundtripDateTime objects are examined to determine whether they are in the local, UTC or an unspecified time zone, and are serialized in such a way that ...

DataContractSerializer XML double the size of XML serializer output - Is this really faster and more scalable?

I'm upgrading a restful service, and am now using the DataContractSerializer to output the response. The previous version just used custom serialization w/ XmlSerializer. Because that version used attributes a lot, and DCS never does, I'm seeing that the new response size is 1.5x the size of the previous version when compressed with gz...

Is there a standard or guideline for creating XML files?

I’m curious if there is standard or guideline for determining what types of things should be attributes vs elements within the xml file. I’m also curious about creating xmlarray and xmlarrayitem lists using XMLSerializer. For example if I have the following: <SomeBaseTag> <Item1 Attr11=”one” Attr12=”two” /> <Item1 Attr11=”one” A...