xml-serialization

XML Serialization vs Reflection in C#

XML Serialization from MSDN: Serializes and deserializes objects into and from XML documents. The XmlSerializer enables you to control how objects are encoded into XML. Reflection from MSDN Reflection provides objects (of type Type) that encapsulate assemblies, modules and types. You can use reflection to dynamicall...

XML serialisation won't write out lazy-evaluated property

Following on from a previous question, I am having trouble combining the Lazy<T> generic that was suggested with my XML Serialization. Here is the functionality I am using for Lazy<T>: public struct Lazy<T> where T : class, new() { private T _Value; public bool HasValue { get { return (_Value !=...

Force XML elements to match the class order when serializing.

Is there a way to force XML elements generated from XML serialisation to be ordered in the same way as defined in the object class? i.e. class SerializableClass { [XmlElement("Element.1")] public List<string> Element1 { get { return _Element1; } set { _Element1 = value; } } private List<string> _...

XML Serialization - XmlCDataSection as Serialization.XmlText

I am having problems serializing a cdata section using c# I need to serialize XmlCDataSection object property as the innertext of the element. The result I am looking for is this: <Test value2="Another Test"> <![CDATA[<p>hello world</p>]]> </Test> To produce this, I am using this object: public class Test { [System.Xml.Serial...

How do I make XmlSerialiser not start with <?xml ?> ?

The file format I'm working with (OFX) is XML-like and contains a bunch of plain-text stuff before the XML-like bit begins. It doesn't like having between the plain-text and XML parts though, so I'm wondering if there's a way to get XmlSerialiser to ignore that. I know I could go through the file and wipe out that line but it would be s...

.net xml serializer not encoding some characters

I a class containing multiple properties of type string. One of the values contains a character of hex value 96. If I serialize the class to xml, the xml serializer does not encode that character, and if I view the xml in various tools such as IE or SQLServer with OpenXML, it complains that the character is invalid in an xml document. ...

XmlSerializer , base64 encode a String member

Consider a simple case public class Test { public String myString; } Is there any way I can tell XmlSerializer to base64 encode myString when serializing it ? ...

XmlSerialization and xsi:SchemaLocation (xsd.exe)

I used xsd.exe to generate a C# class for reading/writing GPX files. How do I get the resultant XML file to include the xsi:schemaLocation attribute eg. I want the following but xsi:schemaLocation is always missing <?xml version="1.0"?> <gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/20...

Web Method is returning XML, how should I read data from xml?

I have added web service reference in visual studio. I am able to see xml return value from web method. How should I read data from returned XML of service? ...

How do I read in a DataSetName from an XML File using ReadXML() in .Net?

I've written a DataSet to a XML file using .WriteXML(FileName), and the DataSetName property of the dataset is the top-level tag in the file. However, when I try to read the file into a different DataSet using .ReadXML(FileName), the DataSetName isn't changed to the value of the top-level tag. Am I doing something wrong, or is ReadXML no...

How to workaround the XmlSerialization issue with type name aliases (in .NET)?

I have a collection of objects and for each object I have its type FullName and either its value (as string) or a subtree of inner objects details (again type FullName and value or a subtree). For each root object I need to create a piece of XML that will be xml de-serializable. The problem with XmlSerializer is that i.e. following obje...

How do I control the <?xml ?> part of xml serialization with .NET?

I am using this method to serialize my object: public static string XmlSerialize(object o) { var stringWriter = new StringWriter(); var xmlSerializer = new XmlSerializer(o.GetType()); xmlSerializer.Serialize(stringWriter, o); string xml = stringWriter.ToString(); stringWriter.Close(); return xml; } It makes XML...

Use multiple namespaces when deserializing with .NET XmlSerializer

I'm trying to deserialize XML with two namespaces, like this <records xmlns="http://www.foo.com/xml/records/1.1"&gt; <record xmlns="http://www.foo.com/xml/record/1.1"&gt; and sometimes an older version <records xmlns="http://www.foo.com/xml/records/1.1"&gt; <record xmlns="http://www.foo.com/xml/record/1.0"&gt; My Records.cs...

Is there a way to get xsd.exe to generate classes with "internal" scope?

I've got a DLL that contains some XSD-generated classes. Unfortunately, XSD.exe makes those classes public, which results in "Missing XML comment for publicly visible type or member XYZ" warnings. Plus, I'd rather not expose those classes from my DLL. Is there a way, short of manually editing the generated .cs, to make those classes i...

When serializing a custom generic collection to Xml how do I add an attribute to the generated collection element.

When serializing a custom generic collection to Xml how do I add an attribute to the generated collection element. Currently I have: <RootObject> <Id>1</Id> <Items> <MyCollectionItem/> <MyCollectionItem/> </Items> </RootObject> What I need is: <RootObject> <Id>1</Id> <Items Name="My collection name"> <MyCollec...

C# class referenced from web service not deserializing properly

I have a web service that's serializing a class (class is from the web service) into an MSMQ, then a windows service is checking the queue and deserializing. The windows service has a web reference to get the class. If I deserialize inside the web service, everything comes out fine. However, when I deserialize from the windows service...

XmlRoot() for Xml Serilization does not work

I'm trying to get my httphandler to print out an XML file with the format: <ScheduledShows> <ScheduledShowElement>...</ScheduledShowElement> <ScheduledShowElement>...</ScheduledShowElement> <ScheduledShowElement>...</ScheduledShowElement> </ScheduledShows> But for some reason, the attribute XmlRoot("ScheduledShowElement") ...

WCF XmlSerialization Attribute(POST)

I currently have a WCF service to consume a remote REST service with the following: [ServiceContract] [XmlSerializerFormat] public interface IMyApi { [OperationContract] [WebGet( ResponseFormat = WebMessage.Xml, UriTemplate = "RemoteServicePage.jsp")] MyNewClass Send(); } The nice part about this is the XmlSerializerFormat attr...

Multiple name spaces in a soap fault message causing FaultException deserialization to fail

We're connecting to a web service and the fault message we're getting back isn't deserializing (at all), and no version of class that I can make will deserialize correctly. We have no control over the server side of things. The server does not allow for discovery, so adding ?WSDL to the end of the URL of the endpoint results in an error,...

Mapping a class and xml file using serialization

If I create a class in C#, how can I serialize/deserialize it to a file? Is this somethat that can be done using built in functionality or is it custom code? ...