xmlserializer

Preserve whitespace-only element content when deserializing XML using XmlSerializer

丶灬走出姿态 提交于 2019-12-10 03:54:38
问题 I have a class InputConfig which contains a List<IncludeExcludeRule> : public class InputConfig { // The rest of the class omitted private List<IncludeExcludeRule> includeExcludeRules; public List<IncludeExcludeRule> IncludeExcludeRules { get { return includeExcludeRules; } set { includeExcludeRules = value; } } } public class IncludeExcludeRule { // Other members omitted private int idx; private string function; public int Idx { get { return idx; } set { idx = value; } } public string

Performance: BinaryFormatter vs. XmlSerializer

℡╲_俬逩灬. 提交于 2019-12-10 03:26:40
问题 I read very often that the BinaryFormatter has better performance then XmlSerializer. Out of curiosity, I wrote a test-app. a wtf moment... why is Xml so much faster than Bin (especially the deserialization)? using System; using System.Collections.Generic; using System.Runtime.Serialization; using System.Xml.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.IO; namespace SerPlayground { class Program { static void Main(string[] args) { var items = new List

Using XmlAttributeOverrides on Nested Properties

旧巷老猫 提交于 2019-12-09 19:41:59
问题 I am trying to use XmlAttributeOverrides to control which class properties appear in the xml after the class has been serialized. It works on properties that are on the "root" class but not on nested properties. Here is a simple example to illustrate what I'm trying to accomplish. My class hierarchy is as follows: public class Main { public string Name { get; set; } public Location Address { get; set; } } public class Location { public string StreetAddress { get; set; } public Contact

Ignoring specified encoding when deserializing XML

我的未来我决定 提交于 2019-12-08 18:55:38
问题 I am trying to read some XML received from an external interface over a socket. The problem is that the encoding is specified wrong in the XML-header (it says iso-8859-1, but it is utf-16BE). It is documented that the encoding is utf-16BE, but apparently they forgot to set the correct encoding. To ignore the encoding when I deserialize I use a StringReader like this: private static T DeserializeXmlData<T>(byte[] xmlData) { var xmlString = Encoding.BigEndianUnicode.GetString(xmlData); using

Xmlserializer to C# object, store original XML element

﹥>﹥吖頭↗ 提交于 2019-12-08 05:46:26
Is it possible to store the original XML element in a C# class, for example? Original XML: <data someattributea="" someattributeb="" someattributec="" /> C# using System; using System.Xml.Serialization; using System.Collections.Generic; namespace Xml2CSharp { [XmlRoot(ElementName="data")] public class Data { [XmlAttribute(AttributeName="someattributea")] public string Someattributea { get; set; } [XmlAttribute(AttributeName="someattributeb")] public string Someattributeb { get; set; } [XmlAttribute(AttributeName="someattributec")] public string Someattributec { get; set; } public sourceXML {

Serialize parallel arrays to XML in C# in a specific order

别说谁变了你拦得住时间么 提交于 2019-12-08 05:46:01
问题 I'm currently tasked with sending data to a web service that has a very odd way of specifying lists. I am not in control of the schema, and my attempts to make the other party change the schema have failed. So I'm pretty much stuck with this. The way their schema is defined is this (only the relevant bit is included): <xs:element name="Part"> <xs:complexType> <xs:sequence> <xs:element name="List"> <xs:complexType> <xs:sequence maxOccurs="4"> <xs:element name="Name" type="xs:string" /> <xs

Failing to read XML content using XmlSerializer

雨燕双飞 提交于 2019-12-08 04:02:43
问题 I got this in my class: namespace MSAToolsLibrary.PublisherEntry { [XmlRoot(ElementName = "PublisherDatabase", Namespace = "http://www.publictalksoftware.co.uk/msa")] public class PublisherData { public PublisherData() { //_Publishers = new List<Publisher>(); _PublishersDictionary = new Dictionary<string, Publisher>(); } public List<Publisher> Publishers { get { return _PublishersDictionary.Select(x => x.Value).ToList(); } set { _PublishersDictionary = value.ToDictionary(x => x.Name, x => x);

Tuple cannot be serialized because it does not have a parameterless constructor

烈酒焚心 提交于 2019-12-08 02:41:03
问题 I am trying to serialize an instance of the QDatatables class provided below, but I am getting error : An exception of type 'System.InvalidOperationException' occurred in System.Xml.dll but was not handled in user code Additional information: There was an error reflecting type 'System.Collections.ObjectModel.ObservableCollection`1[DataRetrieval.Model.QDatatable]'. StackTrace: at System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model,

Forcing ASMX proxy to use XmlSerializer instead of DataContractSerializer

一世执手 提交于 2019-12-07 12:46:17
问题 We were given external SOAP services that we have to consume in our project. All of these provide WSDL data, but a lot of them are not .NET services (most of them were written in Java). We have generated a number of client proxies with wsdl.exe tool. This tool does what it's supposed to do, it creates proxies for us to consume. The problem appears once we try to call methods on these services using generated proxies. We intercept all SOAP requests for logging purposes and XML data looks

extra closing bracket in xml

喜欢而已 提交于 2019-12-07 06:28:58
问题 I am using this example to save some variables to an xml file: how do I set the current class to the return types results This is my code for the settings file: using System; using System.IO; using System.Xml.Serialization; namespace ssscc.Settings { public class AppSettings { public string ReceiptLine1 { set; get; } public string ReceiptLine2 { set; get; } public string ReceiptLine3 { set; get; } public string ReceiptLine4 { set; get; } public string ReceiptLine5 { set; get; } public string