xml-serialization

Suppress xsi:nil but still show Empty Element when Serializing in .Net

I have a c# class that has 20+ string properties. I set about a fourth of those to an actual value. I would like to serialize the class and get an output of <EmptyAttribute></EmptyAttribute> for a property public string EmptyAttribute {get;set;} I do not want the output to be <EmptyAttribute xsi:nil="true"></EmptyAttribute> ...

Serialize property even empty

How can I tell to the XmlSerializer to serialize a string property that is empty? [XmlElement("description")] public string Description { get; set; } ...

How to load TreeView Serialization into GridView

From a TreeView, I get this XML serialized: <?xml version="1.0" encoding="utf-16"?><node text="&lt;span id='c6f5ab9e-d08f-448a-9143-02d174317c07' oncontextmenu=&quot;SetContextMenu(this.id, event);return false;&quot; &gt;Zürich&lt;/span&gt;" value="c6f5ab9e-d08f-448a-9143-02d174317c07" navigateurl="" populateondemand="False" showcheckbo...

[NonSerialized] in C++/CLI

When I'm trying serialize a class containing this property: [NonSerialized] property System::Collections::ObjectModel::ReadOnlyCollection<String^>^ IgnoredWords I get a compilation error saying: fatal error C1093: API call 'DefineCustomAttribute' failed '0x801311c0' How do I tell the serializer that I do not want to serializ...

deserialize the XML Document --- Need Help

I am using the below code snippet now to deserialize the XML document ... [WebMethod] public XmlDocument OrderDocument(XmlDocument xmlDoc) { XmlSerializer serializer = new XmlSerializer(typeof(sendOrder.Order)); string xmlString = xmlDoc.OuterXml.ToString(); byte[] buffer = ASCIIEncoding.UTF8.GetBytes(xmlString); MemoryS...

Different options for XmlSerialization and derived type

I have the following object graph: public class BaseType { } public class DerivedType : BaseType { } When I pass DerivedType to XmlSerializer I need to have it reflect on BaseType instead of DerivedType. Is there a way to control this with attributes without implementing IXmlSerializer on DerivedType? ...

Prevent XmlSerializer from emitting xsi:type on inherited types

I have managed to serialize a class that inherits from a base class to XML. However, the .NET XmlSerializer produces an XML element that looks as follows: <BaseType xsi:Type="DerivedType" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; This, however, causes the receiving end of a web service to choke and produce an error tha...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that are stored in the collection (primarily their IDs, and not the remaining contents of each element). Anyone have an idea of how I might go...

Easier way to serialize C# class as XML text

While trying to answer another question, I was serializing a C# object to an XML string. It was surprisingly hard; this was the shortest code snippet I could come up with: var yourList = new List<int>() { 1, 2, 3 }; var ms = new MemoryStream(); var xtw = new XmlTextWriter(ms, Encoding.UTF8); var xs = new XmlSerializer(yourList.GetType(...

sqlalchemy REST serialization

Reading the doc of sqlalchemy, i saw the serialization part. I'm wondering about a possibility to use an xml serializer for matching sa models with Rest webservices like Jax-RS There is a django extension which deal with that : django_roa Do you know if that kind of thing has already been developped for sqlalchemy or if is it possible to...

.NET CF 3.5 Reducing Xml Property Name Lengths

Hi there, I've currently got a class similar to this: public class myClass { **[XmlElement("mcp")]** public int MyClassProperty; } This is to try and reduce the length of the property name for when the class is serialized in a web service call. However I want the class which references myClass via the web service to use MyClassProper...

Deserialize XML with ampersand using XmlSerializer()

The following code breaks when the XML has data like "Lord & Hogan". Any suggestions? Thanks, Ken private T GetResponse<T>(String apiObject, String query) { //Deserialize XML into the type specified. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(BuildRequestUri(apiObject, query)); using (Http...

The quest for 0x0B

I get this error when reading some data from an SQL column then converting it to XML: "System.InvalidOperationException: There is an error in XML document (182, 16). ---> System.Xml.XmlException: ' ', hexadecimal value 0x0B, is an invalid character." Fair enough, maybe the data is malformed. Except, how can I find the culprit row? S...

C#: serializing linq2sql entities to xml with child nodes.

Hey guys, I have a WPF application which tightly coupled to linq2sql through WCF. It now turns out the Customer would like some sort of Offline mode using an xml file structure. Lets say I have a Customers Table, Each Customer would have many Orders, with each order only belonging to one customer, so In my table design I would have a f...

Any benefit to using default attribute when minOccurs attribrute is > 1?

I came across a legacy XSD that has a bunch of lines like... <xs:element minOccurs="1" maxOccurs="1" default="true" name="Ready" type="xs:boolean" /> ...where minOccurs and maxOccurrs both equal 1, AND there is a default value. Is there any benefit to having the default attr...

.net xmlserializer error

The error is when the class gets serialized, I don't get a run time error or anything (unless I try to deserialize). When the XmlSerializer serializes my class, some times it adds some text at then end of the XML. This happens often at the very end: </RootNode>ootNode> Some times it's not at the end but in the middle, something like ...

Object XmlSerialization with protected property setters

Here is my object [Serializable()] public class PersistentObject { public virtual int ID { get { return id; } protected set { id = value;} } ... } When I try to serialize this to xml, I get an error "The Property or indexer PersistentObject.ID cannot be used in this con...

How can I deserialise an XML element into an array of elements with both attributes and text in C#?

I am having a problem trying to deserialise this XML: <?xml version="1.0" encoding="UTF-8"?> <links> <link title="ABC">http://abc.co.uk&lt;/link&gt; <link title="eBay">http://ebay.co.uk&lt;/link&gt; <link title="Best Damn Site on the Web">http://stackoverflow.com&lt;/link&gt; </links> Using the code: [XmlRoot("links")] pu...

Castor and sockets

I'm new to Castor and data binding in general. I'm working on an application that, in part, needs to take data off of a socket and unmarshall the data to make POJOs. Now, I've got the socket stuff down, and I've even generated and compiled java files thanks to Ant and Castor. Here's the problem: the data stream that I'll receive could b...

How would I robustly log binary or XML using slf4j/log4j/java.util.logging?

After doing logging for many years I have now reached a point where I need to be able to postprocess the log files with the long term goal of using the log files as a "transport medium" allowing me to persist objects et. al. so I can replay the backend requests. In order to do so I need to persist objects into a loggable form. The reco...