xml-serialization

XmlSerialization of IXmlSerializable array

浪子不回头ぞ 提交于 2019-12-23 18:10:01
问题 I have a scenario where the Request objects are XML Serailized and sent back to a TCP server for getting processed. The serialization is done by a legacy framework. Needless to say, I can't make changes in the legacy framework. The legacy framework, however is smart enough to realize if a request object is implementing IXmlSerializable , in that case it takes the WriteXml method of the interface to do the serialization. I wanted to keep maximum control of the serailzation process in my hand,

How can I fix the web reference proxy that Visual Studio generated to handle jagged arrays?

不羁岁月 提交于 2019-12-23 12:19:08
问题 It seems there is a known bug in wsdl.exe, the tool that Visual Studio uses to generate web service proxies. With certain XSD schemas the tool will generate classes that can't be deserialized from the XML. As far as I'm concerned that's unacceptable, but I don't know how to fix it. I will describe my case in detail, hopefully somebody will be able to help me with it. Schema <!-- return type from the service operation --> <xs:complexType name="listAssetsQueryResults"> <xs:sequence> <xs:element

Custom XML serialization - Include class name

本秂侑毒 提交于 2019-12-23 11:57:10
问题 I'm after the following XML serialization output: <?xml version="1.0"?> <Message> <Version>1.0</Version> <Body> <ExampleObject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <EmampleOne>Hello!</EmampleOne> </ExampleObject> </Body> </Message> I have the following classes: [Serializable] public class Message<T> { public string Version { get; set; } public T Body { get; set; } } [Serializable] public class ExampleObject { public string

How can I override deserialization in C#

怎甘沉沦 提交于 2019-12-23 10:50:38
问题 I've got a class that will undergo certain version changes over the course of time. The data from inside this class is serialized and deserialized as part of the startup of my application. The problem I have is if I update the class by adding more properties, and then start the application, the old data does not get loaded properly. What I'm looking to do is override the deserialization step, I don't mind manually reconstructing the object from xml, as I have a version number stored and can

Is XmlReader.ReadString deprecated or obsoleted?

╄→гoц情女王★ 提交于 2019-12-23 09:30:00
问题 I'm wanting to use System.Xml.XmlReader.ReadString() , but I noticed it doesn't show up in Intellisense because the function is decorated with [EditorBrowsable(EditorBrowsableState.Never)] . Despite not being marked as [Obsolete] , I assume Microsoft doesn't want me to use it. I can't find any mention of this on MSDN. What should I be using instead? In ILSpy I see ReadElementContentAsString() and ReadContentAsString() . Is this what I want to use instead? I am using .Net 4.5. In case it's

XML serializing a list of a base class

元气小坏坏 提交于 2019-12-23 09:17:35
问题 I have class A inherits from class B . I have a list of class B that contains A and B items: List<B> myList = new List<B>(); myList.Add(new A()); When I try to serialize this list using XmlSerializable , an exception is thrown. If I define the list to of type B, then I do not get this exception. What is the best way to serialize the derived class? 回答1: XmlIncludeAttribute will do the trick. If you go to this url, you will find a code sample there too. Also, in the example the attribute is

ASP.NET Web API - XML in camelcase

霸气de小男生 提交于 2019-12-23 08:58:27
问题 We are using Web API with MVC 4, and are required to have our request/responses in camel case. We have done that for JSON with the following code: var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().Single(); jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); The same code unfortunately doesn't work for the XmlMediaTypeFormatter . What would be the most elegant workaround to format XML in camel case? 回答1: Solution 1 : Using

XML Serialization - XmlCDataSection as Serialization.XmlText

蓝咒 提交于 2019-12-23 08:26:21
问题 I am having problems serializing a cdata section using c# I need to serialize XmlCDataSection object property as the innertext of the element. The result I am looking for is this: <Test value2="Another Test"> <![CDATA[<p>hello world</p>]]> </Test> To produce this, I am using this object: public class Test { [System.Xml.Serialization.XmlText()] public XmlCDataSection value { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()] public string value2 { get; set; } } When using the

XML Serialization - XmlCDataSection as Serialization.XmlText

自作多情 提交于 2019-12-23 08:26:02
问题 I am having problems serializing a cdata section using c# I need to serialize XmlCDataSection object property as the innertext of the element. The result I am looking for is this: <Test value2="Another Test"> <![CDATA[<p>hello world</p>]]> </Test> To produce this, I am using this object: public class Test { [System.Xml.Serialization.XmlText()] public XmlCDataSection value { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()] public string value2 { get; set; } } When using the

XML Serialization - XmlCDataSection as Serialization.XmlText

放肆的年华 提交于 2019-12-23 08:25:13
问题 I am having problems serializing a cdata section using c# I need to serialize XmlCDataSection object property as the innertext of the element. The result I am looking for is this: <Test value2="Another Test"> <![CDATA[<p>hello world</p>]]> </Test> To produce this, I am using this object: public class Test { [System.Xml.Serialization.XmlText()] public XmlCDataSection value { get; set; } [System.Xml.Serialization.XmlAttributeAttribute()] public string value2 { get; set; } } When using the