xml-serialization

XmlSerializer and controlling namespace in XmlAnyElement

using dotnet 2.0. Code to illustrate : Class1 c1 = new Class1(); c1.SomeInt = 5; XmlDocument doc = new XmlDocument(); doc.LoadXml("<anode xmlns=\"xyz\" ><id>123</id></anode>"); c1.Any = new XmlElement[1]; c1.Any[0] = (XmlElement)doc.DocumentElement; XmlSerializer ser = new XmlSerializer(typeof(Class1)); XmlSerializ...

.NET XML Serialization without <?xml> root node

Hi, I'm trying to generate XML like this: <?xml version="1.0"?> <!DOCTYPE APIRequest SYSTEM "https://url"&gt; <APIRequest> <Head> <Key>123</Key> </Head> <ObjectClass> <Field>Value</Field </ObjectClass> </APIRequest> I have a class (ObjectClass) decorated with XMLSerialization attributes like this: [XmlRoot("ObjectC...

What is MyAssembly.XmlSerializers.dll generated for?

I am working on a project which generates an assembly. I just noticed that an additional assembly *.XmlSerializers.dll is being generated. Why this file is auto generated and what it is used for? ...

How to emit bare XML for a [WebGet] method in WCF?

How can I define a [OperationContract] [WebGet] method to return XML that is stored in a string, without HTML encoding the string? The application is using WCF service to return XML/XHTML content which has been stored as a string. The XML does not correspond to any specific class via [DataContract]. It is meant to be consumed by an XSL...

How do I stop my System.Messaging.MessageQueue from wrapping my strings in XML?

I need to communicate with a legacy application from my C# app via the Windows Message Queue. The legacy application expects plain string messages in a particular private queue, but I can't seem to stop the System.Messaging.MessageQueue from wrapping my message in XML! The code I'm testing is very simple: MessageQueue myQueue = new Me...

How to apply multiple xml namespaces to the same class with the XML Serializer

Hey! I'm trying to generate a proxy class with WCF which, when serialized, converts and instance of the class below into the XML below. However, when I try to apply namespaces to the classes, they're inserted incorrectly, or not at all. What am I doing wrong? How can I fix this? Many thanks in advance. Class Structure: [XmlRoot] pu...

Why isn't my DbNull a singleton when I deserialise it using XmlSerialiser?

I've always assumed that DbNull.value was a singleton. And thus you could do things like this: VB.NET: If someObject Is DbNull.Value Then ... End if C#: If (someObject == DbNull.Value) { ... } But recently, I serialised a DbNull instance using the XmlSerialiser and suddenly it wasn't a singleton any more. Type comparison o...

Serialization and Deserialization into an XML file, C#

I have the following code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ConsoleApplication28 { class Program { static void Main() { List<string> dirs = FileHelper.GetFilesRecursive(@"c:\Documents and Settings\bob.smith\Desktop\Test"); foreach...

deserializing XML with dynamic types / converting string to System.Type

Hmmm I'm not sure if i titled this question properly or am asking it properly, but here goes. I've got serialized objects (in XML) stored in a database, along with a string/varchar indicating the type. Right now i am doing this: (because i have a finite number of different types) Dim deserializer as XmlSerializer If datatable("type...

Implementing IXmlSerializable for Classes Containing Collections

I need to be able to Xml Serialize a class which is internal, so I must implement IXmlSerializable. This class has a two strings and a List in it. I know to read and write the strings using WriteElementString & ReadElementContentAsString. However, I'm lost on how to read & write the List in the ReadXml & WriteXml methods. How do I do...

How can I transform XML into a List<string> or String[]?

How can I transform the following XML into a List<string> or String[]: <Ids> <id>1</id> <id>2</id> </Ids> ...

Deserializing XML to Objects defined in multiple schemas

I have an XML document containing types from 2 XML schemas. One (theirs.xsd) is a proprietary schema that I am integrating with (and cannot edit). To do this I am defining my own type (mine.xsd) that is an element within an 'any' element is the proprietary type. I use Visual Studio's xsd.exe to generate C# classes from the schemas. H...

Can't deserialize XML in WCF REST service

Hey everyone, I've just started playing with the REST starter kit, and I've hit a road block trying to build my own service. I'm trying to create a service for account management, and I can't get the service to serialize my objects, throwing the following error: Unable to deserialize XML body with root name 'CreateAccount' and root n...

Generating XSD for serialized XML

Currently, I have an xml file that looks like this... <ArrayOfService> <Service> <Name> Something </Name> <Id> 8003 </Id> </Service> </ArrayOfService> This is automatically generated from a class that looks like this... public class Service{ public string Name; public int Id; p...

Serialiser library for Silverlight

I'm developing a modular app using prism in SL3, one of the modules is responsible for persisting the application settings in the isolated storage (so that when you open the app next time, you continue where you were). It works perfectly, except that I don't like the way dependencies are wired now. I want to have a type-agnostic settin...

XmlSerializer serializing sub objects

How do you serialize the following [XmlRoot("response")] public class MyCollection<T> { [XmlElement("person", Type = typeof(Person))] public List<T> entry; public int startIndex; } where T can be a class like public class Person { public string name; } into <response> <startIndex>1</startIndex> <entry> <...

Web services - XmlInclude in a derived class instead of a base class?

Hi, I am using an abstract class as a parameter in a web service call. Currently, I am including an XmlInclude of a derived class in the base class, like so: [XmlInclude(typeof(DerivedClass))] public abstract class BaseClass { } However, I'd rather not include all of the derived types in the base class. In http://www.pluralsight...

XStream fromXML() exception

I am trying to deserialize a string in Java using the XStream package. The XStream package can serialize my class fine. I get the XML (cannot change format of XML) from a server and try to save its node information to the corresponding variables in a certain class. My function is at the bottom and I tried to register a new converter for ...

Error in my XML?

I have the following code: public class DeserializeAndCompare { public static List<string> IntoXML() { List<string> PopList = new List<string>(); XmlSerializer serializer = new XmlSerializer(PopList.GetType()); string k = FileToolBox.position0; FileStream filestreamer = new FileStream(k.ToString(...

Is xs:choice an equivalent of C++ enumeration?

We have a lot of serialization done through MS XML 4. When we serialize C++ enums we use a table to translate each possible value to a string and them store that string as an attribute value. When we deserialize we read that attribute value, compare it against all items in the table and retrieve the corresponding enum value. If we fail t...