xml-serialization

C# XML Serialization and Decimal Value

风格不统一 提交于 2019-12-24 02:09:07
问题 I am using XmlSerializer to serialize a C# object that contains a decimal to a string of xml e.g. AnObject.ADecimalValue I am finding the precision is varying in particular even if I explicitly round as below some values are getting output with four values after the point e.g. 12564.39 gets output as 12564.3900 AnObject.ADecimalValue = decimal.Round(AnObject.ADecimalValue, 2); The serializing code is below. XmlSerializer serializer = new XmlSerializer(typeof(AnObject)); using (StringWriter

Serialization on classes that implement IEnumerator

≯℡__Kan透↙ 提交于 2019-12-24 00:59:59
问题 I have written a program which will serialize and de-serialize, it does this fine (I plan on implementing it on the subclasses once I get it properly working on one). However I have run into trouble when I decided I wanted to be able to iterate through the results using a Foreach . After this didn't work I to find out had to implement the IEnumerator and IEnumerable interfaces and add the required methods to my class. So I have, and this does allow me to loop through my collections. The

XmlSerializer and IEnumerable: Serialization possible w/o parameterless constructor: Bug?

ε祈祈猫儿з 提交于 2019-12-24 00:52:54
问题 In our project we extensivly use the XmlSerializer. By chance I found a class w/o a parameterless contructor. I thought this must break the serialization process but it did not. By investigating this issue I found out, that the XmlSerializer behaves strange when serializing/deserializing an IEnumerable : All elements of the enumerable are serialized The class is required to implement an Add(object) method It ignores all other properties that may be in this class. It calls a getter with this

“406 Not Acceptable” when trying to configure XML marshalling over HTTP for a Spring Web MVC service

僤鯓⒐⒋嵵緔 提交于 2019-12-24 00:33:30
问题 A toy example that captures the issue I am having is on github. In a nutshell I have a service that needs to marshal XML back over HTTP. I am trying to set that up using Spring Web MVC. The response object that needs to get marshalled back is JAXB2-generated from a schema (thus is missing @XmlRootElement tag but the package where it is generated has an ObjectFactory which provides the means to generate JAXBElement-s, which make XML marshallers happy). I tried different spring context

XMLWriter extends attribute name with zdef?

你说的曾经没有我的故事 提交于 2019-12-24 00:14:26
问题 I try to serialize some config classes to xml config files using the XMLMapper. but I have some trouble with the attribute generation. Actually the generated XML is perfect, but XMLMapper adds sometimes a prefix to my attribute names. e.g. <Config zdef-2031720317:value="0"> instead of <Config value="0"> This is really bad because i can't process the xml Structure afterwards with XOM anymore :( Where is this effect coming from? I found already the fact that the xml generator seems to auto fix

Deserializing duplicate XML elements with unique attributes

走远了吗. 提交于 2019-12-24 00:12:25
问题 I have the following XML structure: <Response> <Value Name="ID">1</Value> <Value Name="User">JSmith</Value> <Value Name="Description">Testing 123</Value> </Response> How can I deserialize this so that the value names are properties on the class, and the text values are the values of the properties? Note that the value names never change, so Name="ID" will always exist, for example. Here is my class so far: [Serializable] [XmlRoot("Response")] public class ReportingResponse { // [What goes

XmlTypeAttribute does not change name of type

这一生的挚爱 提交于 2019-12-23 21:22:40
问题 I'm working on a project that calls a web service using WSE3. The types originally generated using VS2005 have been modified over time. Now, I need to change the name of the type in the SOAP message. I gather that should be done using XmlTypeAttribute, but that does not affect the type name. As an experiment, I used XmlElementAttribute on a property of that class, and that did change the name of the element generated for that property. The generated object has been extended using partial

How to serialize class hierarchies whose classes refer to each to other, but avoiding XmlInclude?

我的梦境 提交于 2019-12-23 21:18:46
问题 I have a hierarchy of classes that I want to serialize using the XmlSerializer class and its related attributes. There is a base abstract class and then quite a few derived classes (in my code below, I've reduced the number of derived classes to five, but there are many more in the actual code). The classes form a hierarchy and frequently contain references to instances of classes in the hierarchy. public abstract class BaseType { // Only classes in my assembly can derive from this class

Declare [XmlElement(IsNullable = true)] at class level

故事扮演 提交于 2019-12-23 19:36:36
问题 Is there a way to declare [XmlElement(IsNullable = true)] at class level so that all properties in the class will be XML serialized, even if they are null? e.g. public BankAccount BankAccount { get; set; } Should result in <BankAccount xsi:nil="true" /> , rather than the default missing element. I tried this but the compiler (correctly) states that the attribute is not valid for class declarations. The reason for this is that I don't want to have to specify this for all properties. Edit: This

Simple XML Framework : Having an “inline like” behaviour for objects in ElementMap

那年仲夏 提交于 2019-12-23 19:22:24
问题 i am trying to serialize an Hashmap of custom Objects on Android to get an xml like : <ROWSET> <ROW num="0"> <Name>foo</Name> <FNAME>bar</FNAME> <BIRTH>01/01/2000</BIRTH> <Num>4376484</NUM> </ROW> <ROW num="1"> <Name>bar</Name> <FNAME>foo</FNAME> <BIRTH>02/02/2000</BIRTH> <NUM>4376484</NUM> </ROW> </ROWSET> I created an inner class that contains only the Hashmap that i'm interested in, as i was unable to serialize it the way it is (and read that it's not possible) added an object to test like