xmlserializer

XmlSerializer and OnSerializing/OnSerialized alternatives

北慕城南 提交于 2019-12-11 06:15:06
问题 I have various complex objects that often have collections of other complex objects. Sometimes I only want to load the collections when they're needed so I need a way to keep track of whether a collection has been loaded (null/empty doesn't necessarily mean it hasn't been loaded). To do this, these complex objects inherit from a class that maintains a collection of loaded collections. Then we just need to add a call to a function in the setter for each collection that we want to be tracked

VB.NET XML Serialize a List of Inherited Objects

会有一股神秘感。 提交于 2019-12-11 05:21:39
问题 I'm trying to serialize a list of inherited objects. I can serialize each object individually when its declared according to its true type, but when its a list of the base type the serializer gets confused because its expecting to serialize a "base" object but then see different objects that had inherited the "base" object. Any ideas on how to easily solve this? I've done a bunch of reading and have not found an elegant easy to maintain way to do this. Trying to serialize: 'Define a list of

Configure ASP.NET Web API to send empty tags for null values

非 Y 不嫁゛ 提交于 2019-12-11 04:48:49
问题 I am new to ASP.NET Web API. I have configured my application to use XMLSerializer as GlobalConfiguration.Configuration.Formatters.XmlFormatter.UseXmlSerializer = true; For Simplicity say my Controller returns an instance of class Account public class Account { public int AccountId {get;set;} public string AccountName {get;set;} public string AccountNickName {get;set;} } I get this when as XML response when AccountNickName (which is optional) has a value <Account> <AccountId>1</AccountId>

Serializing IXmlSerializable Types Using XmlSerializer in WCF

纵然是瞬间 提交于 2019-12-11 04:38:33
问题 Thoroughly frustrated with the DataContractSerializer, I'm trying to get up and running in WCF using IXmlSerializable types with XmlSerializer. I've implemented IXmlSerializable and XmlSchemaProvider in my class to be serialized and declared [XmlSerializerFormat] for my OperationContract. Using a complex schema, I get the following error on trying to view the WSDL: "Schema type information provided by IXmlSerializable is invalid: Reference to undeclared attribute group

c# xml deserialization to object with colon and hyphen in xsi:type value

拥有回忆 提交于 2019-12-11 02:58:01
问题 I have an issue when I try to deserialize my XML File to an object using the XmlSerializer class. My XML file looks like this: <fx:FIBEX xmlns:fx="http://www.asam.net/xml/fbx" xmlns:ho="http://www.asam.net/xml" xmlns:ethernet="http://www.asam.net/xml/fbx/ethernet" xmlns:it="http://www.asam.net/xml/fbx/it" xmlns:service="http://www.asam.net/xml/fbx/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="" VERSION="4.1.0"> <fx:ELEMENTS> <fx:CLUSTERS> <fx:CLUSTER xsi

C# how to deserialize an xml tag embedded in text?

 ̄綄美尐妖づ 提交于 2019-12-11 01:33:12
问题 I am trying to deserialize the output of .NET's XML doc comment using an XmlSerializer. For reference, the output of xml documentation looks like: <?xml version="1.0"?> <doc> <assembly> <name>Apt.Lib.Data.Product</name> </assembly> <members> <member name="P:MyNamespace.MyType.MyProperty"> <summary>See <see cref="T:MyNamespace.MyOthertype"/> for more info</summary> </member> ... </members> </doc> The object I'm using to generate the serializer is: [XmlRoot("doc")] public class XmlDocumentation

A Generlized XML serializer but not working on JObject

假装没事ソ 提交于 2019-12-11 01:03:38
问题 I have a function which serializes any object into xml. private string ConvertToXml(object obData) { var x = new System.Xml.Serialization.XmlSerializer(obData.GetType()); var myStr = string.Empty; try { using (var ms = new MemoryStream()) { x.Serialize(ms, obData); ms.Position = 0; var sr = new StreamReader(ms); myStr = sr.ReadToEnd(); _log.DebugFormat("Converted XML output of record:: {0}", myStr); } } catch (Exception e) { _log.WarnFormat("Object Conversion to XML Document Failed ..{0} and

xmlserializer not correctly deserializing schema with import

半城伤御伤魂 提交于 2019-12-11 00:26:29
问题 I've been trying to deserialize an xml file in C# with classes generated from schemas in xsd.exe. Unfortunately only part of the file is being properly deserialized, the rest is returned as null for reasons I can't work out. My process is as follows: Starting with the myschema.xsd file from which the C# code is generated: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mc="myschema:common" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ttl

Deserializing xml to class, trouble with list<>

a 夏天 提交于 2019-12-10 13:57:00
问题 I have the following XML <map version="1.0"> <properties> <property name="color" value="blue" /> <property name="size" value="huge" /> <property name="texture" value="rugged" /> </properties> </map> I am trying to write classes that I can deserialize this into, this is what I have: [XmlRoot("map")] public class MyMap { [XmlAttribute("version")] public decimal Version { get; set; } [XmlElement("properties")] public List<MyProperty> Properties { get; set; } } public class MyProperty {

How can I validate the output of XmlSerializer?

穿精又带淫゛_ 提交于 2019-12-10 04:34:00
问题 In C# / .NET 2.0, when I serialize an object using XmlSerializer, what's the easiest way to validate the output against an XML schema? The problem is that it is all too easy to write invalid XML with the XmlSerializer, and I can't find a way to validate the XML that does not look cumbersome. Ideally I would expect to set the schema in the XmlSerializer or to have a XmlWriter that validates. 回答1: What about reading it in again using a validating reader Here's a quick stab at it Stream stream =