xml-serialization

How to stop XmlSerializer from adding newlines to blank elements

I am serializing an object like this: XmlSerializer serializer = new XmlSerializer(obj.GetType()); using (StringWriter writer = new StringWriter()) { serializer.Serialize(writer, obj); return writer.ToString(); } (having created the nodes like this) XmlElement newchild = doc.CreateElement(nodename); newchild.Inner...

XML Deserializer / XSD tool / object arrays

I have an XSD, and used the xsd.exe tool to create c# classes. In a webservice I am accepting in the MessageContract an instance of one of these created objects. The relevant portion of the xsd to this question is here: <xs:element name="Tasks"> <xs:complexType> <xs:sequence> <xs:element ref="Task" maxOccurs="un...

.Net class with NHibernate and XmlSerializer

Have a .net class that I want to persist/retrieve to/from Oracle 11g database using NHibernate. Contains an array of objects that NHibernate insists must be the interface type IDictionary, ISet, or IList. I also need to serialize the class to XML using XmlSerializer, however, XmlSerializer cannot serialize members of type IList (for exa...

Derived type unknown to WSE 3.0 web service

I have a WSE 3.0 based web service, and a WinForms client application that makes use of the types defined in that service's References.cs, but subclasses them to provide some additional functionality required by the client. However, when I pass an instance of the subclass back to the web service, even though I explicitly cast back to th...

Generating Java Exceptions from XSD / binding Exceptions with JAXB2

For webservices we usually generate java beans with the maven-jaxb2-plugin and use JAXB2 marshalling in Spring. I am wondering how to handle (SOAP-)faults that are declared in the WSDL/XSD best. In the application I would like to use Java exceptions that are marshalled to the faults. Is this possible? I haven't found a way to generate ex...

How do I have to change this XML string so that XDocument.Parse reads it in?

In the following code, I serialize an object into an XML string. But when I try to read this XML string into an XDocument with XDocument.Parse, it gives me this error: Invalid data at root level. The XML is: <?xml version="1.0" encoding="utf-8"?> <Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://ww...

XMLSerializer is not writing elements in a list

I am writing a program that will basically make a xml copy of most things in the local computer SAM store for users. Currently it only prints a XMLElement for each user but it does not print the attributes for them. <?xml version="1.0" encoding="utf-8"?> <WindowsUserList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="...

Serializing a Nullable<DateTime> in to XML

I am trying to serialize a class several of the data-members are Nullable objects, here is a example [XmlAttribute("AccountExpirationDate")] public Nullable<DateTime> AccountExpirationDate { get { return userPrincipal.AccountExpirationDate; } set { userPrincipal.AccountExpirationDate = value; } } However at runtime I get the e...

XmlSerializer not observing default namespace?

I have this class: [Serializable] public class Element { [XmlAttribute("maxOccurs")] public int MaxOccurs{get; set;} [XmlAttribute("minOccurs")] public int MinOCcurs{get; set;} [XmlAttribute("name")] public string Name{get; set;} [XmlAttribute("nillable")] publ...

Deserialize xml into a Linq to SQL object

I need to read in XML data posted from external systems, which will be formatted roughly as follows: <Applicant> <FirstName>John</FirstName> <LastName>Smith</LastName> <Address>12 Main St</Address> </Applicant> This is a direct mapping of my Linq to SQL Applicant class, excluding a few properties. What's the best way to deseria...

C# XML string element with Name attribute

Hi, I am trying to create a c# object for serialization/deserialization with a string property. The property needs to generate an element and also have an attribute: eg: ... <Comment Name="CommentName"></Comment> ... If the property is a string, I cant see how to add the attribute, and if the comment is an object with Name and Value...

C# XML Insert comment into XML after xml tag

I am using a C# object to Serialize/Deserialize XML. I would like to add a comment to the XML file whilst serializing, this comment will be a basic <!-- comment --> after the standard xml tag <?xml version="1.0" encoding="UTF-8"?> This comment does not need to be deserialized, its a basic comment to indicate the product and version th...

Best way to present the user the XML values of a file ?

Hey Team, I got a XML File, looking familiar to this : <root> <carnumber>12</carnumber> <carcolor>2</carcolor> <cartype>5</cartype> </root> Like you see I got some Elements with values/text in it. The car element for example can take values from 1 to 1000. But the element carcolor can take values from 1 - 5 and the cartype from 1 -...

C# XML Object Serialization: setting xmlns root attribute

I am serializing an object to xml and would like to set an xmlns attribute to the root node. eg: ... <root xmlns="[specified url]"> ... </root> I cant seem to have an xmlns property/attribute on the member or seem to add the namespace when serializing without a prefix? Any ideas? ...

Serialize all properties of class to XML

I have a load of classes and I need to generate an XML schema for these classes. The easiest way I can think to do this is to create the classes, serialize as XML and then run XSD on this XML. However, if I don't set the properties of a class, no XML node is created and therefore the XSD doesn't pick it up. Is there a way for me to te...

C# serialization dropping property in subclass?

When I try to serialize a populated instance of type List<C>() where: public class A<T> : List<T> { [XmlAttribute("Name")] public string Name {get; set;} public A() {} } public class B { [XmlAttribute("Other")] public string OtherPCO { get; set:} } public class C : A<B> { } The serialization drops the Name pr...

Why does MSBuild put *.XmlSerializers.dll assembly in the root folder of published web application?

I have a build process which takes my VS 2008 .NET 2.0 ASP.NET project and builds it using MSBuild. The project contains ASPX files, plus a web service, and also connects to another web service ;) All seems to work well except MSBuild puts the *.XmlSerializers.dll assembly file into the folder _PublishedWebsites\MySite rather than in _P...

Is it possible to instruct WCF not to serialize fields, which values are the default for the field type?

Dear ladies and sirs. Inspecting the soap-xml produced by WCF I notice that many fields appear with their default values. Is it possible to instruct WCF somehow to omit such fields in serialization? Thanks. ...

Why must I remove the xmlns attribute to deserialize my XML file?

Problem I'm using Xsd2Code (a .NET class generator for XSD schema) on a simple settings file schema. For some reason, when I attempt to use the built-in LoadFromFile() or Deserialize() methods, I get an exception that seems to be related to the xmlns attributes in my XSD and XML files. If I remove these attributes, the exception goes aw...

What would be the best way to validate XML?

Hi I been looking at XML Serialization for C# and it looks interesting. I was reading this tutorial http://www.switchonthecode.com/tutorials/csharp-tutorial-xml-serialization and of course you can de serialize it back to a list of objects. So I am wondering would it be better to de serialize it back to to a list of objects and then go...