xmlserializer

how to remove namespace from XML root element?

Hi, 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 class [Serializable] [XmlRootAttribute("MCP", Namespace = "", IsNullable = false)] public c...

c# XmlSerializer serialize generic List of interface

I'm trying to use the XmlSerializer to persist a List(T) where T is an interface. The serializer deos not like interfaces. I'm curious if there is a simple way to serialize a list of hetrogenous objects easily with XmlSerializer. Here's what I'm going for: public interface IAnimal { int Age(); } public class ...

XmlSerializer requires XmlInclude for public method with generic constraint if type in another assembly AND requires that type to be serialiable!

Consider the following. You have a class that you want to serialize with XmlSerializer which has a public generic method with a type constraint where the type is in a different assembly: using BarStuff; namespace FooStuff { public class Foo { ... public T GetBar<TBar, T>( string key ) where TBar : Bar<T> { ... } ...

XmlSerializer.Deserialize issue with either root element missing or element not expected

I'm having some issues deserializing an xml document. The document I am trying to deserialize is this: <slt:CreateGiftRegistryResponse xmlns:slt="http://WWW.example.com/"&gt; <slt:Response> <slt:ResponseCode>ERROR</slt:ResponseCode> <slt:ResponseDescription>Request unsuccessfull null</slt:ResponseDescription> </slt:Response></slt:Creat...

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 happen? ...

How To Deserialize Missing Boolean Field to TRUE

I'm deserializing a custom object from a file to an object in my app using the XmlSerializer. My issue is that I want a field in the object to default to "True" rather than "False" for a new property that doesn't exist in the file that I am deserializing from. By default, .Net is assigning this value to be false because it doesn't exis...

change how XmlSerializer serializes empty elements

I am using the XmlSerializer. It serializes the object just fine but the client requires required empty elements to be in this format <star:Confirm/>. The serializer instead serializes the empty elements to <star:Confirm></star:Confirm> is there a way to change it to serialize the way the client requires. ...

Property Should only Be Set by the Serializer

I have a class which communicates with an API and needs to do some transformations to any data it touches. This class is the equivalent too: public class SerializeMe { public SerializeMe(string someString) { _someString = someString; } private string _someString; public string TransformedValue { ...

Replacing XmlSerializer due to slow WPF application start-up

I have wrote a WPF application that reads a list of movies from a XML file at a network location. When I started investigating the slow start-up it turned out that XmlSerializer has a lot overhead. I have now used sgen to build the assemblies before I publish the project but I am now looking into a better solution. I have looked at the ...

XMLSerializer fails to deserialize a xml document

I am a newbie to C#. I have a java REST service which returns a xml response and I am trying to deserialize the xml document using C# XmlSerializer. A sample xml document response is pasted below. <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <ns2:Document xmlns:ns2="http://hxps.honeywell.com/model/impl" xmlns:ns3="http:/...

Using .NET XmlSerializer for xml with different polymorphic roots.

I have XML docs with different roots coming from one source. I have a XSD schema just like described in this question, with the abstract='true' root element 'BaseElem' of a Base type, plus additional root elements Elem1, Elem2, ... that extend the Base type and use substitutionGroup='BaseElement' attribute. xsd.exe generates BaseElem an...

How to generate xsi:nil element with attributes?

I have a WCF client that needs to generate a request containing this XML fragment : <reason xsi:nil="true" nullFlavor="NA" typeCode="RSON" /> The schema is determined by the server and isn't under my control. The generated proxy code has a class for the reason element containing (among other things) properties nullFlavor and typeCode....

Ignoring specified encoding when deserializing XML

I am trying to read some XML received from an external interface over a socket. The problem is that the encoding is specified wrong in the XML-header (it says iso-8859-1, but it is utf-16BE). It is documented that the encoding is utf-16BE, but apparently they forgot to set the correct encoding. To ignore the encoding when I deserialize ...