xmlserializer

How to XML-serialize a dictionary

喜你入骨 提交于 2019-12-17 06:46:23
问题 I have been able to serialize an IEnumerable this way: [XmlArray("TRANSACTIONS")] [XmlArrayItem("TRANSACTION", typeof(Record))] public IEnumerable<BudgetRecord> Records { get { foreach(Record br in _budget) { yield return br; } } } However, I realised that now I need a dictionary containing a collection Dictionary<string, RecordCollection> (RecordCollection implements IEnumerable). How can I achieve that? 回答1: Take a look at the following blog post http://blogs.msdn.com/b/psheill/archive/2005

How to insert a node in a large document using XmlSerializer

雨燕双飞 提交于 2019-12-14 04:19:17
问题 I have a large XML document and I want to use the XmlSerializer class to insert new elements whose content comes from a .NET class instance generated using xsd.exe. This is a follow-up to the question How to deserialize a node in a large document using XmlSerializer, and uses the same xsd and generated classes that are described in that question. Let's say that in my sample XML I want to exchange my Ford car for a BMW. I've tried the following code: static string XmlContent = @" <RootNode

XMLSerialization Nesting

こ雲淡風輕ζ 提交于 2019-12-14 02:45:44
问题 I'm doing some XML Serialization and trying to get the output like so: <Claim> <Source>...</Source> <Vehicle>...</Vehicle> <ThirdParty>...</ThirdParty> <ThirdParty>...</ThirdParty> <ThirdParty>...</ThirdParty> </Claim> However my output is: <Claim> <Source>...</Source> <Vehicle>...</Vehicle> <ThirdParty> <ThirdParty>...</ThirdParty> <ThirdParty>...</ThirdParty> <ThirdParty>...</ThirdParty> </ThirdParty> </Claim> The Third Parties are nested inside the List instead of Claim, how can I get the

Is there a way to avoid self-closing tags when using XML Serialization?

假装没事ソ 提交于 2019-12-14 00:56:26
问题 I am working with VB.NET and I am facing a problem with XML serialization. When empty values exists in the object I am serializing, the XML file contains the following tags: <tagName/> instead of: <tagName></tagName> I know that it's the same, but I want the start tag to close appropriately. 回答1: They are the same and it makes no difference. Any parser or reader understands the meaning, so why is this so important to change? I find the current behavior better as it will result in smaller

Ignore a property when serializing to XML

泪湿孤枕 提交于 2019-12-13 19:20:24
问题 I have a base class that has MANY big classes inside it. For example, Let's say Person class. Inside it, there is a Payment Class, inside there is a CreditCard class, and so on... I am trying to serialize Person class, and I would like to exclude certain classes inside it. In this example, I am trying to serialize Person class and ignore the ENTIRE payment class. This is what I did so far, but it's not working. Can you guys help me figure out how I can achieve this? Thanks XmlAttributes att =

how to deserialize xml to list in RestSharp?

梦想的初衷 提交于 2019-12-13 17:25:16
问题 My XML: <result> <document version="2.1.0"> <response type="currency"> <currency> <code>AMD</code> <price>85.1366</price> </currency> </response> <response type="currency"> <currency> <code>AUD</code> <price>31.1207</price> </currency> </response> </document> </result> My Class: public class CurrencyData { public string Code { get; set; } public string Price { get; set; } } My deserializer calling: RestClient.ExecuteAsync<List<CurrencyData>>... If i renamed class CurrencyData to Currency then

XML Serialization error - Invalid or missing value of the choice identifier 'ItemsElementName' of type 'ItemsChoiceType[]'

二次信任 提交于 2019-12-13 15:38:00
问题 I am trying to serialize an object to be passed to a web service and getting the error above. I can see when debugging that the value is present in the object itself but it doesn't seem to be picking this up: string[] tradeAreas = new string[] {"Area1", "Area2", "Area3", "Area4"}; //RetrieveMarketResultsFor ItemsChoiceType[] choices = new ItemsChoiceType[] { ItemsChoiceType.area }; MarketResultIdentifier mri = new MarketResultIdentifier { ItemsElementName = choices, Items = tradeAreas,

There is an error in XML document (0, 0) during deserialization

浪子不回头ぞ 提交于 2019-12-13 15:26:17
问题 i have the following code to for xml serialization. public class FormSaving { private string major; public string Majorversion { get; set; } } private void SaveButton_Click(object sender, RoutedEventArgs e) { string savepath; SaveFileDialog DialogSave = new SaveFileDialog(); // Default file extension DialogSave.DefaultExt = "txt"; // Available file extensions DialogSave.Filter = "XML file (*.xml)|*.xml|All files (*.*)|*.*"; // Adds a extension if the user does not DialogSave.AddExtension =

Writing CDATA in ASP.NET WebApi

烂漫一生 提交于 2019-12-13 07:07:22
问题 Im using the setting: formatters.XmlFormatter.UseXmlSerializer = true; The class i try to serailize is quite simple: public class MyClass { public MyClass() { CDATA = "<![CDATA[<link>MyLink</link>]]>" [XmlText] public string CDATA { get; set; } } I want this to be serialized into something like: <MyClass> <![CDATA[<link>MyLink</link>]]> </MyClass> But instead get: <MyClass> <![CDATA[<!link>MyLink<!/link>]]> </MyClass> So how can i prevent this? Or is there a better way using the ASP.NET

XmlSerializers with addin outlook

本秂侑毒 提交于 2019-12-13 05:05:59
问题 I’m trying to create add-in for outlook and have issue with deserialization and antivirus program. I’ve noticed that when my add-in tried to deserialize any data, .NET framework created temporary dll in “C:\Users\{UserName}\AppData\Local\Temp\" folder. This dll existed very short time, but from time to time antivirus locked it and add-in thrown error message that file is used by another process . I’m tried to get rid of temporary dll and found recommendations to use sgen tool for creation of