xml-serialization

How to serialize xml array AND class properties using C# XML serialization

I have a class that is inherited from List<T> and also has some properties, like this: [Serializable] public class DropList : List<DropItem> { [XmlAttribute] public int FinalDropCount{get; set;} } This class is serialized to xml as part of a larger class: [Serializable] public class Location { public DropList DropList{get...

Xml Serialization - Render Empty Element

I am using the XmlSerializer and have the following property in a class public string Data { get; set; } which I need to be output exactly like so <Data /> How would I go about achieving this? ...

XMLSerialize Exception

Hello. I am serializing a class and I get the following exception: You must implement a default accessor on System.Configuration.SettingsPropertyCollection because it inherits from ICollection. when the following line is executed: XmlSerializer xs = new XmlSerializer(typeof(CustomConfiguration)); Any help? public class CustomC...

Dump a Java HashMap<K,V> to XML and back

Hi, does anyone know of a good library or method of converting the contents of a HashMap to XML and then parsing this to reconstruct the HashMap? ...

XML Serialization and namespace prefixes

I'm looking for a way with C# which I can serialize a class into XML and add a namespace, but define the prefix which that namespace will use. Ultimately I'm trying to generate the following XML: <myNamespace:Node xmlns:myNamespace="..."> <childNode>something in here</childNode> </myNamespace:Node> I know with both the DataContract...

How to keep XmlSerializer from killing NewLines in Strings?

Suppose I have a simple Class with just one Member a String. public class Abc { private String text; public String Text { get { return this.text; } set { this.text = value; } } } Now when I serialize and then deserialize it with the questionable XmlSerializer any text containing newlines ('\r\n' or En...

XmlIgnoreAttribute, only used during serialization, not during deserialization?

Am I right in understanding the .NET XmlIgnoreAttribute, which says: Instructs the Serialize method of the XmlSerializer not to serialize the public field or public read/write property value. that: The property will be deserialized, if present in the XML file? The property will not be serialized to a new XML file? The reason I'...

Casting xml to inherited class

I have 2 class: public class ClassA public class ClassB (from another namespace) : ClassA I have xml files fill with ClassA. How to cast it to ClassB while deserialization. is it possible ?? ...

Basic serialization throws an 'Invalid XML' error

I have the following class structure (not simplified btw): [Serializable] [XmlInclude(typeof(Twitter))] [XmlInclude(typeof(LinkedIn))] public abstract class SocialNetworkBase : ISocialNetwork { public abstract string UserName { get; set; } } public class Twitter : SocialNetworkBase { public override string UserName { get; set; ...

How to set a value for a string in a really complicated c# partial class for a web service with xml-seriaisation? (I think)

Hi I'm new to C# and I'm using MS VS2008 Express on XP32. I have this class, auto-generated from a wsdl: public partial class PartDataSetType { private object[] partDataSetField; /// [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] [System.Xml.Serialization.XmlArrayItemAttribute("Entit...

How can I tweek Xstream to handle XML to Java objects that include attributes and values?

For example, how would form an object from XML written like this? <name length="4">Ryan</name> I would normally alias a class using an annotation to "name" and then have a length and a field for the name. However, this will not work because the second field has no name. *Edit confusing wording ...

How to embed xml in xml

I need to embed an entire well-formed xml document within another xml document. However, I would rather avoid CDATA (personal distaste) and also I would like to avoid the parser that will receive the whole document from wasting time parsing the embedded xml. The embedded xml could be quite significant, and I would like the code that wi...

Exposing a subset of bean properties as XML response of REST service

I'm not sure how to best explain this, so this may be a bit long, please bear with me. Let's say I have a java bean with a bunch of properties: public interface Customer { public String getFirstName(); public String getLastName(); public Address getAddress(); // embedded bean with its own properties ... // lots more } ...

VB .NET XmlIgnoreAttribute if value is 0 or false

I am trying to ignore a property value (XML Attribute for serialization) if the value is not set. This is easy with most classes using the special PropertyNameSpecified boolean but it doesn't work with some base types that always have a value such as integer and boolean. An integer that has never been set explicitly will still have a v...

ESE column type to XmlSerialize arbitrary objects

What's the best ESE column type to XmlSerialize an object to my ESE DB? Both "long binary" and "long ASCII text" work OK. Reason for long binary: absolutely sure there's no characters conversation. Reason for long text: the XML is text. It seems MSDN says the 2 types only differ when sorting and searching. Obviously I'm not going to ...

Serializing a DataType="time" field using XmlSerializer

Hi, I'm getting an odd result when serializing a DateTime field using XmlSerializer. I have the following class: public class RecordExample { [XmlElement("TheTime", DataType = "time")] public DateTime TheTime { get; set; } [XmlElement("TheDate", DataType = "date")] public DateTime TheDate { get; set; } public sta...

XML Serialization is not including milliseconds in datetime field from Rails model

By default, the datetime field from the database is being converted and stripping off the milliseconds: some_datetime => "2009-11-11T02:19:36Z" attribute_before_type_cast('some_datetime') => "2009-11-11 02:19:36.145" If I try to overrride the accessor for this attribute like; def some_datetime attribute_before_type_cast('some_datet...

.NET XmlSerializer to Element FormDefault=Unqualified XML?

I use C# code more-or-less like this to serialize an object to XML: XmlSerializer xs1 = new XmlSerializer(typeof(YourClassName)); StreamWriter sw1 = new StreamWriter(@"c:\DeserializeYourObject.xml"); xs1.Serialize(sw1, objYourObjectFromYourClassName); sw1.Close(); I want it to serialize like this: <ns0:Header xmlns:ns0="https:/...

Xml Serialization for Unusual Connection Protocol

In my application I have a PacketList class and Packet class. I'd like to be able to use the serialization helpers on PacketList to come up with something like the desired output, but have no idea what direction to go in. I am writing a program to imitate a server which has a peculiar protocol for sending data. Client sends data with f...

XML: How to reprepresent objects with multiple occurences?

hi, i need to save objects that can occur multiple times. each object is marked with unique identifier. when it is serialized first time all its properties are written. after that only references are used. <actionHistory> <add> <figure id="1" xsi:type="point"> <position x="1" y="2" /> </figure> </add> <change> ...