xmlserializer

Better IXmlSerializable format?

旧城冷巷雨未停 提交于 2019-11-28 14:35:18
I have an interface IInput that is preventing the XmlSerializer from serializing the class natively (because it doesnt like interfaces). I found a hack/workaround that attempts to just create the underlying implementation when deserializing and then casts that back to the interface. The deserializer knows the underlying implementation because its encoded as a attribute AssemblyQualifiedName In order to take advantage of this technique I have to implement IXmlSerializable, but only 1 property really needs help ( IInput Input ), I wish for all the other ones to act as if they were normal. Here

Serializing an array of multiple types using XmlSerializer

≡放荡痞女 提交于 2019-11-28 13:13:48
I'm trying to use XMLSerializer to generate XML such as the following, where the contents of <create> is an array, but the elements can be of differing types (in this case <vendor> , <customer> , and <asset> ). Is this possible? ... <create> <vendor> <vendorid>Unit - A-1212</vendorid> <name>this is the name8</name> <vcf_bill_siteid3>FOOBAR8</vcf_bill_siteid3> </vendor> <customer> <CUSTOMERID>XML121</CUSTOMERID> <NAME>XML Customer 111</NAME> </customer> <asset> <createdAt>San Jose</createdAt> <createdBy>Kevin</createdBy> <serial_number>123456789</serial_number> </asset> </create> .... Assuming

How/why does XmlSerializer treat a class differently when it implements IList<T>?

南楼画角 提交于 2019-11-28 11:37:08
问题 XmlSerializer is calling IList<T>.Add() on my class and I don't understand why. I have a custom class (one of several classes in a hierarchy) containing data that I am converting to and from XML using XmlSerializer . In a previous version of my code, these classes did not implement any interfaces, and XML serialization and deserialization both seemed to work as expected. I'm now working on some other code that uses the data contained in this class, and I thought it would be helpful if I could

How to serialize property of type Object with XmlSerializer

早过忘川 提交于 2019-11-28 11:25:34
I have a property: public object Tag but it can contain finite number of types, unfortunately without base type (except object type). But when I serialize the object with this property, it doesn't get serialized. Is there a way to instruct XmlSerializer with possible types? I don't recommend this, but yes, you can use [XmlElement] etc to tell it about multiple candidate types for a member: public class Test { private static void Main() { var ser = new XmlSerializer(typeof (Test)); var obj = new Test {Value = "abc"}; ser.Serialize(Console.Out, obj); obj = new Test { Value = 123 }; ser.Serialize

Deserializing XML with unknown element order

放肆的年华 提交于 2019-11-28 11:01:56
问题 I'm trying to implement a client for a service with a really deficient spec. It's SOAP-like, although it has no WSDL or equivalent file. The spec also doesn't provide any information about the correct ordering of elements - they're listed alphabetically in the spec, but the service returns an XML parse error if they're out of order in the request (said order to be derived by examining the examples). I can work with this for submitting requests, even if it's a pain. However, I don't know how

C# Xml Serializing List<T> descendant with Xml Attribute

时光毁灭记忆、已成空白 提交于 2019-11-28 10:57:18
Morning Guys, I have a collection that descends from List and has a public property. The Xml serializer does not pick up my proeprty. The list items serialize fine. I have tried the XmlAttribute attribute to no avail. Do you guys have a solution? public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { var people = new PersonCollection { new Person { FirstName="Sue", Age=17 }, new Person { FirstName="Joe", Age=21 } }; people.FavoritePerson = "Sue"; var x = new XmlSerializer(people.GetType()); var b

XSD.EXE + JSON.NET - How to deal with xxxSpecified generated members?

可紊 提交于 2019-11-28 10:16:19
问题 When using XSD.EXE to generate classes from an XML Schema, it generates xxxSpecified members of any primitives of a given object: <xs:complexType name ="Foo"> <xs:all> <xs:element name ="Count" type = "xs:integer"/> </xs:all> </xs:complexType> ....generates: public class Foo { public int Count { get; set; } public bool CountSpecified { get; set; } } It appears the latest version of JSON.NET can automatically set these properties when deserializing. string request = "{ Count : 10 }"; var

XmlSerializer + Polymorphism

删除回忆录丶 提交于 2019-11-28 05:05:04
问题 Given a (contrived) base class, and a sub class we want to serialize via WCF using the XmlSerializer. We decorate a collection (see the response class) as per the article: http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlelementattribute.aspx (see remarks section). Issue is that although the correct WSDL seems to be generated, SVCUtil generates a class file where the GetUserResponse class contains a property named Items. Is this to do with applying [XmlElement] to an array?

Prefix SOAP XML Instead direct namespace

三世轮回 提交于 2019-11-28 04:36:03
问题 I am working with one of our partner to integrate our business services. I am using WCF (.Net 3.5) to communicate with partner web service. I think partner web service is written in Java. Using SVC util I generated proxy class. Instead DataContract serializer, svcutil used xmlserializer. But WSDL provided by partner and the web service response SOAP xml does not match. Since the partner not interested in changing the wsdl, I have changed downloaded WSDL manually to match the response. That

Cannot deserialize XML into a list using XML Deserializer

倖福魔咒の 提交于 2019-11-28 02:27:19
This follows on from my previous question Serialize list of interfaces using XML Serialization public class MeterWalkOrder { public MeterWalkOrder() { Meters = new List<IMeter>(); } public String Name { get; set; } [XmlIgnore] public List<IMeter> Meters { get; set; } [XmlArrayItem(ElementName = "Meter")] [XmlArray(ElementName = "Meters")] public List<Meter> SerializableMeters { get { return Meters.Cast<Meter>().ToList(); } set { Meters = new List<IMeter>(value); } } } public interface IMeter { int MeterID { get; set; } } public class Meter : IMeter { public int MeterID { get; set; } public