xml-serialization

Custom DateTime XML Serialization

I would like to be able to Serialize a DateTime with a specific Time Zone that is not the server, nor is it client time. Basically, any time zone. Is it possible to override the DateTime serialization, in .Net2.0 webservices? I compile an xmlschema using xsd.exe, so I made an attempt using XmlSchemaImporter. The OnSerialize examples s...

Can XmlSerializer deserialize into a Nullable<int>?

I wanted to deserialize an XML message containing an element that can be marked nil="true" into a class with a property of type int?. The only way I could get it to work was to write my own NullableInt type which implements IXmlSerializable. Is there a better way to do it? I wrote up the full problem and the way I solved it on my blog. ...

How to serialize to dateTime

Working to get DateTimes for any time zone. I'm using DateTimeOffset, and a string, and an XmlElement attribute. When I do, I get the following error: [InvalidOperationException: 'dateTime' is an invalid value for the XmlElementAttribute.DataType property. dateTime cannot be converted to System.String.] System.Xml.Serializ...

tilde in XML

Is tilde a legitimate character in an XML SOAP message? I get a SAXParseException:Content not allowed in prolog. I included most of the SOAP message just in case I'm barking up the wrong tree. POST /... HTTP/1.0 Content-Type: text/xml; charset=utf-8 Accept: application/soap+xml, application/dime, multipart/related, text/* User-Agent: ...

De Serializing a list of strings without creating a new class?

I have an XML configuration file with a collection of strings like so: <SomeSetting>value</SomeSetting> <SomeOtherSetting>value</SomeOtherSetting> <TypesOfThings> <Thing>Type 1</Thing> <Thing>Type 2</Thing> <Thing>Type 3</Thing> </TypesOfThings> These 'Things' become options in the front end of the app for the user to choose fro...

De/Serialize directly To/From XML Linq

Is there any way to de/serialize an object without round-tripping a XmlDocument/temp string? I am looking for something like the following: class Program { static void Main(string[] args) { XDocument doc = new XDocument(); MyClass c = new MyClass(); c.SomeValue = "bar"; doc.Add(c); Conso...

How to suppress XML tag for list property

Is it possible to avoid list property tags when serializing? //[Serializable()] - removed, unnecessary public class Foo { protected List<FooBar> fooBars = new List<FooBar>(); public virtual List<FooBar> FooBars { get { return fooBars; } set { fooBars = value; } } } // [Serializable()] - removed, unnecessary public class FooBar ...

XmlSerialization of collections

I want to serialize the following Xml structure: <XmlRootElement> <Company name="Acme Widgets LLC"> <DbApplication name="ApplicationA" vendor="oracle"> <ConnSpec environment="DEV" server="DBOraDev1201" database="AppA" userId="MyUser" ...

FileNotFound exception when using XmlSerializer

When trying to serialize a type (a generic List<T> which T is a class marked with XmlRootAttribute) into XML using XmlSerializer, a FileNotFoundException is thrown (sometimes) and serialization fails. It seems that XmlSerializer tries to create a temporary file with a random file name in the Temp folder of user under which the applicati...

Obsolete attribute causes property to be ignored by XmlSerialization

I'm refactoring some objects that are serialized to XML but need to keep a few properties for backwards compatability, I've got a method that converts the old object into the new one for me and nulls the obsolete property. I want to use the Obsolete attribute to tell other developers not to use this property but it is causing the propert...

XML Serialization and Schema without xsd.exe

i use xml-serialization for the reading of my Config-POCOs. to get intellisense support in visual studio for xml files i need a schema file. i can create the schema with xsd.exe mylibrary.dll , this works fine. but i want that the schema is always created if i serialize an object to the filesystem. is there any way without using xsd.e...

Best approach for passing XML to a webservice?

I have XML files in a directory that I wish to get over to a webservice on a server that will validate them and return a true/false as to whether they are valid in construct and values etc. Reason for server side processing is that the validation rules may change from time to time and need to adjust in one place as opposed to all client ...

How to write out the contents of a string to XML without the codes...?

I have a string that has angle brackets in it like this: <element1>my text here</element1> The string literally looks like this when I write it to console or my dataGridView or anywhere else. However, I'm trying to write this as part of an XML document. Everything is fine except that in the xml file that is written, the above show...

XML serialization of a Dictionary with a custom IEqualityComparer

Hi, I want to serialize a Dictionary that has a custom IEqualityComparer. I've tried using DataContractSerializer but I can't get the Comparer to be serialized. I can't use BinaryFormatter because of this. I can always do something like: var myDictionary = new MyDictionary(deserializedDictionary, myComparer); But that means I'd need...

What's a good way to serialize Delphi object tree to XML--using RTTI and not custom code?

What's a good way to serialize a Delphi object tree to XML--using RTTI and not custom code? I would have loved to find that this feature is already built into Delphi, but it doesn't seem to be. I've found a few components (posted, below) that seem like they might perform this function. Have you used any of them or some other offering?...

How to deserialize only part of an XML document in C#

Hi everyone, Here's a fictitious example of the problem I'm trying to solve. If I'm working in C#, and have XML like this: <?xml version="1.0" encoding="utf-8"?> <Cars> <Car> <StockNumber>1020</StockNumber> <Make>Nissan</Make> <Model>Sentra</Model> </Car> <Car> <StockNumber>1010</StockNumber> <Make>Toyota</Ma...

How can I use IEnumerable interface and at the same time, have XMLSerializer not use GetEnumerator()?

I have a class that parses very large file (that can't fit in memory) and I'm currently utilizing the IEnumerable interface to use foreach so I can easily grab the parsed contents of the file line by line. Currently, I'm trying to write this to file using an XMLSerializer. It insists on enumerating the class and in my case, this means ...

.net: Best solution for XmlSerializer and System.Drawing.Color

System.Drawing.Color objects apparently won't serialize with XmlSerializer. What is the best way to xml serialize colors? ...

XmlSerialize a custom collection with an Attribute

I've got a simple class that inherits from Collection and adds a couple of properties. I need to serialize this class to XML, but the XMLSerializer ignores my additional properties. I assume this is because of the special treatment that XMLSerializer gives ICollection and IEnumerable objects. What's the best way around this? Here's som...

C# Serialization XML

Hello Everybody, just a simple question. Is there an attribute to skip empty arrays in the xml-serialization of c#? This would increase human-readability of the xml-output. Thanks in advance Matze ...