xml-serialization

XML de-serialization using xml element/attributes

强颜欢笑 提交于 2019-12-13 06:09:08
问题 Need your help in setting the xml attributes for XML deserialization. This is my input xml: <form> <question id="QnA"> <answer>AnswerforA</answer> </question> <question id="QnB"> <answer>AnswerforB</answer> </question> <question id="QnC"> <answer>AnswerforC</answer> </question> </form> The ids of each question element tag correspond to a class property and its value is the innertext of the corresponding answer element. The .cs file will look like public class Test { private string qnaAns;

Serializing IEnumerable Containing Derived classes: Circular Reference Issue

China☆狼群 提交于 2019-12-13 05:49:48
问题 I am trying to serialize IEnumerable using the following code. I am getting the following exception. There was an error generating the XML document. "A circular reference was detected while serializing an object of type DBML_Project.FixedBankAccount."}. Why does this error come? How to correct it? Note: I am already using InheritanceMapping attribute. public class BankAccountAppService { public RepositoryLayer.ILijosBankRepository AccountRepository { get; set; } public void

Outputting XMLSerializer().serializeToString String to User Savable Text Window

纵然是瞬间 提交于 2019-12-13 05:15:47
问题 I am currently using the following code to display the XML code from part of the DOM. var sXML = new XMLSerializer().serializeToString(document.getElementsByTagName("TopElementOfBlockOfInterest")[0]); var win; var doc; win = window.open("", "", "",false); doc = win.document; doc.open("text/plain"); doc.write(sXML); doc.close(); What I see is XML code. However, when I choose "Save As" on Firefox 20.0, what is saved is an html file. Is there a way to display the XML string in a form in which

System.InvalidOperationException when reading from xml in WP8

旧街凉风 提交于 2019-12-13 05:07:31
问题 This is a follow-up question from How to create an empty xml in Windows Phone 8. I did this to create the xml: public void create() { List<DataModel> __dataList = new List<DataModel>(); XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.Indent = true; using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("Data.xml", FileMode.Create)) { XmlSerializer

Generise : Deserialize Xml to a specific class of an inherited class

陌路散爱 提交于 2019-12-13 04:45:51
问题 Input pre-processed xml files to map a specific transaction type Say I have transactionTypeA transactionTypeB transactionTypeC, (all inherited from TransactionTypes). the following code, just for reference, is good for a specific transaction type. for example, mapping xml data into transactionTypeA: byte[] byteArray = Encoding.UTF8.GetBytes(xmlContent); MemoryStream tempMemoryStream = new MemoryStream(byteArray); DataContractSerializer serializer = new DataContractSerializer(typeof

How to create an empty xml in Windows Phone 8

不问归期 提交于 2019-12-13 04:40:36
问题 I'm creating an empty xml file in my WP8 app like this public static bool create() { Dictionary<string, object> __data = new Dictionary<string, object>(); XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.Indent = true; using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("Data.xml", FileMode.Create)) { XmlSerializer serializer = new XmlSerializer

C# XmlSerializer from Entity Framework

别来无恙 提交于 2019-12-13 03:50:30
问题 I have 2 classes: [XmlInclude(typeof(Item))] public class A { public int Id { get; set; } [XmlArray("Items")] [XmlArrayItem("Item")] public virtual List<Item> Items { get; set; } = new List<Item>(); } public class Item { public int Id { get; set; } [XmlIgnore] public virtual A a { get; set; } } I'm using this method inside my DbContext : public virtual DbSet<A> A { get; set; } public IQueryable<A> GetA() { return A; } Now I want to export data to XML: Type[] types = { typeof(Item) }; var

Is this a sound approach to working with Serialized XML from a 3rd party object that I don't fully understand?

吃可爱长大的小学妹 提交于 2019-12-13 03:48:19
问题 I have Serialized Instance Data from a 3rd party application, it is in XML and I want to load it into an object and work with it. I generated a XSD off the the XML and it works great. The XML represents the state of a form the user filled out. The first time I generated the XSD, I hadn't filled out the whole form -the form instance being what is serialized. I went back and filled out the whole form, so that all the controls I need are present, and created a new XSD, and used XSD2Code to

XML Serialization vs Reflection in C#

只愿长相守 提交于 2019-12-13 03:43:38
问题 XML Serialization from MSDN: Serializes and deserializes objects into and from XML documents. The XmlSerializer enables you to control how objects are encoded into XML. Reflection from MSDN Reflection provides objects (of type Type) that encapsulate assemblies, modules and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object and invoke its methods or access its fields and properties . If you are

How do I deserialize this simple xml config with the XmlSerializer class?

江枫思渺然 提交于 2019-12-13 02:48:42
问题 I have the following xml I'd like to deserialize into a class <?xml version="1.0" encoding="utf-8" ?> <root> <element1>String1</element1> <element2>String2</element2> </root> I am trying to serialize it into the following class: [XmlRoot("root")] public class root { [XmlElement("element1")] internal string element1 { get; set; } [XmlElement("element2")] internal string element2 { get; set; } } When I try deserializing it using the following code, the config object is instantiated, but the