xml-serialization

XmlSerializer: remove unnecessary xsi and xsd namespaces

Is there a way to configure the XmlSerializer so that it doesn't write default namespaces in the root element? What I get is this: <?xml ...> <rootelement xmlns:xsi="..." xmlns:xsd="..."> </rootelement> and I want to remove both xmlns declarations. Duplicate of: How to serialize an object to XML without getting xmlns=”…”? ...

Serialize an arbitary string to XML in .NET

What is the best way to serialize an arbitary string (into an XML attribute or XML node) to a XML stream so that the XML stays valid (special characters, newlines etc. must be encoded somehow). ...

.Net Release build working slower than Debug

I am experiencing a weirdest thing for the last couple of days. I found out that my Release build actually executes slower than the Debug version. 1. The problem I finally stripped all stuff from my entry point (Main) in my Windows Forms exe, leaving only this: [STAThread] static void Main(params string[] args) { Stopwatch sw ...

How do I deserialize XML without knowing the type beforehand?

Say I have a couple of basic objects like so: [Serializable] public class Base { public string Property1 { get; set; } public int Property2 { get; set; } } [Serializable] public class Sub: Base { public List<string> Property3 { get; set; } public Sub():base() { Property3 = new List<string>(); } ...

Wrapping Arbitrary XML within XML

I need to embed arbitrary (syntactically valid) XML documents within a wrapper XML document. The embedded documents are to be regarded as mere text, they do not need to be parseable when parsing the wrapper document. I know about the "CDATA trick", but I can't use that if the inner XML document itself contains a CDATA segment, and I nee...

Serialise object to XmlDocument

In order to return useful information in SoapException.Detail for an asmx web service, I took an idea from WCF and created a fault class to contain said useful information. That fault object is then serialised to the required XmlNode of a thrown SoapException. I'm wondering whether I have the best code to create the XmlDocument - here ...

Formatting element/attribute values with XML Serialization

I have a class that represents credit card details. To represent valid from and expiration months and years I am using four properties of type int: public int ValidFromMonth { get; set; } public int ValidFromYear { get; set; } public int ExpiresEndMonth { get; set; } public int ExpiresEndYear { get; set; } I am XML Serializing this c...

Apache webservice deserialization problem in .NET

Hi, i have big problem with deserialization of XML response from third-party webservice. here is xml response <?xml version="1.0" encoding="utf-8"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchem...

Problem using XmlSerializer to Serialize/Deserialize a class between a Silverlight Library and an MVC App

Here is my situation: I have a solution with three projects: 1) Silverlight App, 2) Silverlight Library, 3) the Asp.net-MVC Web App. In the Silverlight Library I have a class called "MyClass". In the Silverlight App I serialize that class to XML using XmlSerializer and send the XML back to the database. I retrieve and deserialize tha...

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

Hi, 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 <myElement name="foo">bar</myElement> I use a class for myElement with a XmlAttribute for the "name", but how to refer ...

How do I serialize an object into an XDocument?

I have a class that is marked with DataContract attributes and I would like to create an XDocument from objects of that class. Whats the best way of doing this? I can do it by going via an XmlDocument but this seems like an unnecessary step. ...

Serialise to XML and include the type of the serialised object

In a previous question about serialising an object to an XmlDocument in C#, I needed to serialise some fault information to an XmlDocument that was returned from a asmx-style webservice call. On the client I need to de-serialise the XmlDocument back to an object. This is straightforward enough if you know the type, but I realised I wan...

How to serialize XML to generic collection when namespace is specified

Lets say I have the following XML file: <?xml version="1.0" encoding="utf-8"?> <Customers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Customer.xsd"> <Customer> <FirstName></FirstName> <LastName></LastName> </Customer> <Customer> <FirstName></FirstName> <LastName></...

How to deserialize Enumerable.ToList<>() to List<>

I'm trying to build an object that looks something like this: public class MyObject { private IList<AnotherObject> items; public List<AnotherObject> Items { return items.AsEnumerable().ToList<AnotherObject>(); } } I'm using NHibernate as my DAL and have it mapping directly to the items field and all that wo...

how to remove default xmlns entries when serializing a class

I've instantiated a class that is serializable, and I'm serializing it to a file, but it is always putting the following attributes in my root element: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" How can I stop that? ...

How to serialize classes that were not designed to be serialized?

I need to save some classes and data structures to a file. My first reflex was to use XML or Binary serialization but this is turning into a nightmare. I have a set of classes that were not meant to be serialize (private setters, no parameterless constructors, no Serialization attribute, dictionaries, etc.). Considering that I cannot cha...

Exception when serializing WPF contols

I have an Application (an appointment manager) which lets the user create usercontrols in a stackpanel per button click and the user can enter data into the usercontrols. So far so good. I serialized the stackpanel with XamlWriter.Save(). But then when I try to load it again the next time the application starts with XamlReader.Load() I ...

XML HTTP POST integration in .NET

I'm working on a .NET project that integrates with an external company. This company will be sending us XML messages via HTTP POST (raw XML, not SOAP). There are basically three different types of XML messages they will be sending us, which all have their own XSDs. There is no inheritance hierarchy between these XSDs, they are all bas...

C#: Deserialise XML File error (think it's a namespace issue - cant for the life of me work it out though)

Hey all, I'm deserialising an XML file which comes from a webservice of one of our clients. Problem is, after creating the class with xsd.exe I deserialise the file and get the usual "There is an error in XML document (2, 2)." visual studio error. This, I presume is line 2, which points to the namespace declarations: Top of XML file:...

What causes this error message? The remote server returned an error: (422) Unprocessable Entity.

I try to submit a request to a REST API using WCF; here's what I've done: namespace Sample { [ServiceContract] [XmlSerializerFormat] public interface ISampleApi { [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "users.xml", ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFor...