xml-deserialization

How to define multiple names for XmlElement field?

自闭症网瘾萝莉.ら 提交于 2019-11-27 02:04:24
I have a XML document provided by client applications to my C# application. This is how a client sends the XML file: <?xml version="1.0" encoding="utf-8"?> <SomeAccount> <parentId>2380983</parentId> <!-- more elements --> </SomeAccount> And a C# class that supports the XML deserialization: [XmlRoot] public class SomeAccount { [XmlElement("parentId")] public long ParentId { get; set; } //rest of fields... } But there are some clients whose system send the XML in this way (note the upper case in LeParentId ): <?xml version="1.0" encoding="utf-8"?> <SomeAccount> <LeParentId>2380983</LeParentId> <

Why does the OnDeserialization not fire for XML Deserialization?

安稳与你 提交于 2019-11-26 16:58:46
问题 I have a problem which I have been bashing my head against for the better part of three hours. I am almost certain that I've missed something blindingly obvious... I have a simple XML file: <?xml version="1.0" encoding="utf-8"?> <WeightStore xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Records> <Record actual="150" date="2010-05-01T00:00:00" /> <Record actual="155" date="2010-05-02T00:00:00" /> </Records> </WeightStore> I have a simple

using XmlArrayItem attribute without XmlArray on Serializable C# class

大憨熊 提交于 2019-11-26 12:40:09
问题 I want XML in the following format: <configuration><!-- Only one configuration node --> <logging>...</logging><!-- Only one logging node --> <credentials>...</credentials><!-- One or more credentials nodes --> <credentials>...</credentials> </configuration> I\'m trying to create a class Configuration that has the [Serializable] attribute. To serialize the credentials nodes, I have the following: [XmlArray(\"configuration\")] [XmlArrayItem(\"credentials\", typeof(CredentialsSection))] public

How to define multiple names for XmlElement field?

跟風遠走 提交于 2019-11-26 09:53:52
问题 I have a XML document provided by client applications to my C# application. This is how a client sends the XML file: <?xml version=\"1.0\" encoding=\"utf-8\"?> <SomeAccount> <parentId>2380983</parentId> <!-- more elements --> </SomeAccount> And a C# class that supports the XML deserialization: [XmlRoot] public class SomeAccount { [XmlElement(\"parentId\")] public long ParentId { get; set; } //rest of fields... } But there are some clients whose system send the XML in this way (note the upper

How to deserialize xml to object [duplicate]

醉酒当歌 提交于 2019-11-26 00:53:13
问题 This question already has an answer here: Convert XML String to Object 13 answers <StepList> <Step> <Name>Name1</Name> <Desc>Desc1</Desc> </Step> <Step> <Name>Name2</Name> <Desc>Desc2</Desc> </Step> </StepList> I have this XML, How should i model the Class so i will be able to deserialize it using XmlSerializer object? 回答1: Your classes should look like this [XmlRoot("StepList")] public class StepList { [XmlElement("Step")] public List<Step> Steps { get; set; } } public class Step {

Is it possible to deserialize XML into List<T>?

孤街醉人 提交于 2019-11-26 00:42:21
问题 Given the following XML: <?xml version=\"1.0\"?> <user_list> <user> <id>1</id> <name>Joe</name> </user> <user> <id>2</id> <name>John</name> </user> </user_list> And the following class: public class User { [XmlElement(\"id\")] public Int32 Id { get; set; } [XmlElement(\"name\")] public String Name { get; set; } } Is it possible to use XmlSerializer to deserialize the xml into a List<User> ? If so, what type of additional attributes will I need to use, or what additional parameters do I need

How to Deserialize XML document

拥有回忆 提交于 2019-11-25 21:38:01
问题 How do I Deserialize this XML document: <?xml version=\"1.0\" encoding=\"utf-8\"?> <Cars> <Car> <StockNumber>1020</StockNumber> <Make>Nissan</Make> <Model>Sentra</Model> </Car> <Car> <StockNumber>1010</StockNumber> <Make>Toyota</Make> <Model>Corolla</Model> </Car> <Car> <StockNumber>1111</StockNumber> <Make>Honda</Make> <Model>Accord</Model> </Car> </Cars> I have this: [Serializable()] public class Car { [System.Xml.Serialization.XmlElementAttribute(\"StockNumber\")] public string StockNumber

How to deserialize xml to object [duplicate]

岁酱吖の 提交于 2019-11-25 19:08:35
This question already has an answer here: Convert XML String to Object 12 answers <StepList> <Step> <Name>Name1</Name> <Desc>Desc1</Desc> </Step> <Step> <Name>Name2</Name> <Desc>Desc2</Desc> </Step> </StepList> I have this XML, How should i model the Class so i will be able to deserialize it using XmlSerializer object? dknaack Your classes should look like this [XmlRoot("StepList")] public class StepList { [XmlElement("Step")] public List<Step> Steps { get; set; } } public class Step { [XmlElement("Name")] public string Name { get; set; } [XmlElement("Desc")] public string Desc { get; set; } }