xml-serialization

In C# how can I deserialize an XML document containing a list of elements without a surrounding list element

Hopefully a question with a very simple answer, but it's not one that I've been able to find. I have a small XML document that looks roughly like this: <aa> <bb><name>bb1</name></bb> <bb><name>bb2</name></bb> <bb><name>bb3</name></bb> </aa> I have classes that represent aa and bb [XmlRoot("aa")] public class aa { [XmlArray("b...

Why does the XmlRoot attribute gets ignored in WCF and how to overcome this

We've observed that when we expose a WCF service which uses classes decorated with various xml serialisation attributes, despite the fact that we use the XmlSerializerFormat attribute on the interface any XmlRoot attribute on any of the operation's parameters gets completely ignored. The namespace of the parameters is always that of the...

XML Deserialization Producing Incorrect Results

I am an XML beginner, using C# .NET 2.0/Visual Studio 2005. What I have is a data sample in XML that I'd like to convert into strongly typed data structures. I also have an XSD for that file that I ran through the Visual Studio xsd.exe to generate the code for it. I ran it against System.Xml.Serialization.XmlSerializer It did a decen...

HR-XML Error, trying to deserialize XML examples

The HR-XML 3.0 spec provides WSDL's to generate their entities. I'm trying to deserialize their example xml in their documentation, but it's not working. Candidate.CandidateType candidate = null; string path = "c:\\candidate.xml"; XmlSerializer serializer = new XmlSerializer(typeof(Candidate.CandidateType), "http...

.NET Serialize XmlNode problem

So I am trying to simply decorate a class to serialize it as XML. Here's an example of my problem. [XmlElement("Dest")] public XmlNode NewValue { get; set; } The real problem here is that sometimes in this implementation the XmlNode can be an XmlElement or XmlAttribute. when it's an element this code works fine, but when it comes ...

Read XML into xsd.exe generated classes. Good idea?

I have a fairly complex XML coming my way and I have the XSD for it. I generated classes via xsd.exe and read XML into the class structure via the XmlSerializer described here. It works great. However, this is the first time I've done it this way and I'll be reading in tons of XML files going forward from various sources. How reliabl...

C# Output XML from Linq to Response.OutputStream

Is there a simpler way to output a Linq to SQL table to XML (eventually to a web page?) Unfortunately, I am not using MVC, but I could put a reference to it in my aspx C# page. I have this: var myView = (from x in db.myTable where x.Name.Contains("Bob") select new person {Name = x.Name, Job = x.Job).Take(...

Is an Incremental Approach Possible for This Case?

I'm taking data from an XML file of records that I'm using System.Xml.Serialization.XmlSerializer to deserialize into strongly-typed data structures. Each record that I run through is getting converted to another format and written to another file. I dislike the idea of storing the whole XML file in memory without need, but it's not cr...

.NET XmlSerializer and multiple references to the same object

My repository has List<Student>, List<Course> and List<Enrolment> where an Enrolment has Enrolment.Student and Enrolment.Course which are references one of the students or courses in the two previous lists. When I use XmlSerializer on my repository it outputs redundant data as it serializes all properties of each student in List<Stude...

C# XML Serialization with numerous elements of data

I have some XML that I am trying serialize like so: string Value = @"<MSG> <ABCID> <ID>0123456789A</ID> <ID>0123456790B</ID> </ABCID> <DATETIME>2010-01-07T13:00:09</DATETIME> ...

XMLSerializer not serializing DateTime

Input...note that comment is generated code from the xsd tool. It's in a 31,834 line file and proprietary, but I put a rough approximation in here. [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.1432")] [System.SerializableAttribute()] [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)] pub...

WCF with Message Serialization

Hi, I'm write a simple wcf service that submit request to some gateway to be processed. The request are being executed by executing something like that: I'm writing a WCF service that submit a request to some service which expect to get something like this: gatewayService.SendRequest(request); where gatewayService is the WCF proxy ...

partial xml serialization/deserialization

is it possible to partially (de)/serialize an object from/into a string? class Foo { Bar Bar{get;set;} string XmlJunkAsString{get;set;} } so ultmately, we would want the string below to work... <Foo><Bar></Bar><XmlJunkAsString><xml><that/><will/><not/><be/><parsed/></xml></XmlJunkAsString></Foo> and ultimately we could...

"Ambiguous Constructor Reference" XmlSerializer

I am trying to serialize a List<MyObject>. When I create my XmlSerializer as such: XmlSerializer xmlSerializer = new XmlSerializer(List<MyObject>); I get the following error: Ambiguous Constructor Reference How can I fix this so I can serialize and deserialize my list? ...

Correct way to use XmlSerialization with frequent serializations

I have a list box that when an item is selected or deselected I want to save the changes to an xml file (so it is always up-to-date on the file and the user does not need a "save" button). While testing I occasionally am hitting this IOException: The process cannot access the file 'C:\MyPath\MyFile.xml' because it is being used by anot...

How do I handle unicode user input in Scala safely (esp XML entities)

On my website I have a form that takes in some textual user input. All works fine for "normal" characters. However when unicode characters are input... well, the plot thickens. User inputs something like やっぱ死にかけてる This comes in to the server as text containing XML entity refs &#12420;&#12387;&#12401;&#27515;&#12395;&#12363;&#12369;&...

Xml Serialization of a List where the parent element has additional elements

How would this be achieved in C# xml serializable class(s)? <Category Attrib1="Value1" Attrib2="Value2"> <Item>Item1</Item> <Item>Item2</Item> <Item>Item3</Item> <Item>Item4</Item> </Category> Inheriting Category from List<Item> results in the two Category properties being ignored by the xml serializer. If Category is compose...

Serialize enum as int

I am looking to return the following class through a web service, which includes an enum type as one of its members. [Serializable, XmlRoot("GeoCoordinate")] public class GeoCoordinate { public enum AccuracyLevel { Unknown = 0, Country = 1, Region = 2, SubRegion = 3, Town = 4, Post...

serializing a datatable for later reuse

Hi everyone, I have a populated DataTable I'd like to serialize to a file for later use. I've been looking over the options involved with this and wondered if someone could point me in the right direction. What I'll be creating are two methods-- one for writing the datatable to a file, and another for creating a new datatable using th...

How can I serialize an object with a Dictionary<string,object> property?

In the example code below, I get this error: Element TestSerializeDictionary123.Customer.CustomProperties vom Typ System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyT...