xml-deserialization

XML Parsing and deserialization

╄→гoц情女王★ 提交于 2019-12-17 20:27:23
问题 I have a xml file which Im reading it from my class <Testclasses> <Class>new SomeClass1()</class> <class>new SomeClass2()</class> </Testclasses> so i have a method in the class which takes an argument as an object as below public List<Object> retriveValuesFromXml(){ .... This method parses the values from xml and reads the different object and returns a list of objects. } @Test public void someMethod1(){ ArrayList<Object> list_of_objects= retriveValuesFromXml(); for(Object x :list_of_objects)

fast way to deserialize XML with special characters

帅比萌擦擦* 提交于 2019-12-17 18:59:51
问题 I am looking for fast way to deserialize xml, that has special characters in it like ö. I was using XMLReader and it fails to deserialze such characters. Any suggestion? EDIT: I am using C#. Code is as follows: XElement element =.. //has the xml XmlSerializer serializer = new XmlSerializer(typeof(MyType)); XmlReader reader = element.CreateReader(); Object o= serializer.Deserialize(reader); 回答1: I'd guess you're having an encoding issue, not in the XMLReader but with the XmlSerializer. You

deserializing enums

ぐ巨炮叔叔 提交于 2019-12-17 16:32:45
问题 I have an xml in which one of the elements has an attribute that can be blank. For e.g., <tests> <test language=""> ..... </test> </tests> Now, language is enum type in the classes created from the schema. It works fine if the language is specified, it fails to deserialize if it is blank (as shown in example). Edit: Code for deserialization: XmlSerializer xmlserializer = new XmlSerializer(type); StringReader strreader = new StringReader(stringXML); Object o = serializer.Deserialize(strreader)

Unable to generate a temporary class (result=1). error CS0030: Cannot convert type 'Type[]' to 'Type'?

☆樱花仙子☆ 提交于 2019-12-17 15:36:18
问题 I get this error after I created a class from my xsd file using the xsd.exe tool. So I searched the net and found a solution. Here is the link: http://satov.blogspot.com/2006/12/xsdexe-generated-classes-causing.html Problem is that this makes the code run, but somehow the deserialized data seems corrupt. I did what the site suggests and in the end the 2nd array dimension is always empty (see the comments of the site, somebody also had this problem). Question is, how do I solve this issue now?

How to convert an xml string to a dictionary?

旧巷老猫 提交于 2019-12-17 01:39:19
问题 I have a program that reads an xml document from a socket. I have the xml document stored in a string which I would like to convert directly to a Python dictionary, the same way it is done in Django's simplejson library. Take as an example: str ="<?xml version="1.0" ?><person><name>john</name><age>20</age></person" dic_xml = convert_to_dic(str) Then dic_xml would look like {'person' : { 'name' : 'john', 'age' : 20 } } 回答1: This is a great module that someone created. I've used it several

deserializing CDATA with JacksonXML - UnrecognizedPropertyException

独自空忆成欢 提交于 2019-12-13 07:13:07
问题 I am using jackson libraries (2.5.2) and trying to deserialize some XML that actually has CDATA section. It seems that Jackson 2.5 added support for CDATA. Here is my class that has the CDATA: public class Certificate { @JacksonXmlProperty(localName = "name", isAttribute = true) private String name; @JacksonXmlCData private String data; @JacksonXmlProperty(localName = "date-added", isAttribute = true) @JsonFormat(pattern = "EEE MMM d HH:mm:ss z yyyy") private Date dateAdded; @JsonFormat

Deserialize XML does not populate array

久未见 提交于 2019-12-13 06:59:30
问题 I have the XML Below and the C# Code. The array of Childconainer's is not being deserialized? I expect to get a list of them but i get 0. C# Class and deserialize method using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using System.Xml.Serialization; using System.IO; namespace MESMsgTester { public class BscLineageResponse { public class BSCLineageResponse { public mes_message mes_message { get; set; } } public class mes_message { public

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

C# Xml Deserialize plus design suggestions

断了今生、忘了曾经 提交于 2019-12-13 02:59:38
问题 In my project I need to build a generic deserializer that should be backward compatible. Example: The XML looks like <PolicyDef name = "sample" type="type1"> <Options ......> </PolicyDef> The "type" is enum - PolicyTypes e.g public Enum PolicyTypes { type1 = 0, type2 = 1 } The PolicyDef class is defined as [XmlRoot("PolicyDef")] public class PolicyDef { private string policyName; private PolicyTypes policyType; public PolicyDefinition() { } [XmlAttribute] public string Name { get { return