xml-serialization

.NET XmlSerializer and multiple references to the same object

我与影子孤独终老i 提交于 2020-01-29 06:53:39
问题 My repository has List<Student> , List<Course> and List<Enrolment> where an Enrolment has Enrolment.Student and Enrolment.Course which are references one of the students or courses in the two previous lists. When I use XmlSerializer on my repository it outputs redundant data as it serializes all properties of each student in List<Student> then again for every reference to those same students in List<Enrolment> . I'm looking for an elegant way to solve this. After deserialization I can fix the

.NET XmlSerializer and multiple references to the same object

ε祈祈猫儿з 提交于 2020-01-29 06:50:09
问题 My repository has List<Student> , List<Course> and List<Enrolment> where an Enrolment has Enrolment.Student and Enrolment.Course which are references one of the students or courses in the two previous lists. When I use XmlSerializer on my repository it outputs redundant data as it serializes all properties of each student in List<Student> then again for every reference to those same students in List<Enrolment> . I'm looking for an elegant way to solve this. After deserialization I can fix the

de-serialze a byte[] that was serialzed with XmlSerializer

有些话、适合烂在心里 提交于 2020-01-25 00:40:07
问题 I have a byte[] that was serialized with the following code: // Save an object out to the disk public static void SerializeObject<T>(this T toSerialize, String filename) { XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType()); TextWriter textWriter = new StreamWriter(filename); xmlSerializer.Serialize(textWriter, toSerialize); textWriter.Close(); } problem is the data serialized looks like this: iVBORw0KGgoAAAANSUhEUgAAAPAAAAFACAIAAAANimYEAAAAAXNSR0IArs4c6QAAAARnQU1BAACx.....

Writing JSON serializer

蹲街弑〆低调 提交于 2020-01-24 19:47:10
问题 If I want to develop a serializer for a language for which one doesnt exist already (e.g. ABAP), what could be the efforts involved in it? Does it involve merely writing "text equivalent" of ABAP serialzer - how would I tackle complex objects. What would be the best starting point for this? 回答1: Update: Starting with Releases 7.02 and 7.03/7.31 (kernel patch 116), JSON is supported natively in ABAP - check this blog by Horst Keller. You should search for ABAP and JSON using site:sap.com first

Custom XML-element name for base class field in serialization

允我心安 提交于 2020-01-24 00:30:09
问题 How can I change XML-element name for field inherited from base class while doing serialization? For example I have next base class: public class One { public int OneField; } Serialization code: static void Main() { One test = new One { OneField = 1 }; var serializer = new XmlSerializer(typeof (One)); TextWriter writer = new StreamWriter("Output.xml"); serializer.Serialize(writer, test); writer.Close(); } I get what I need: <?xml version="1.0" encoding="utf-8"?> <One xmlns:xsi="http://www.w3

How can I ignore properties according to their value with XmlSerializer

家住魔仙堡 提交于 2020-01-22 18:50:27
问题 I'd like the XML created by XmlSerializer to exclude properties if they have a default value. Is this possible with XmlSerializer or am I going to have to look into IXmlSerializable? For example, I may have the following class: public class PositionedObject { public float X { get; set; } public float Y { get; set;} } I'd like to tell the XmlSerializer that when it serializes an instance of PositionedObject, to not include X if the value is 0 (and same with Y if it is 0). 回答1: Just declare a

generate xml files based on my c# classes

南笙酒味 提交于 2020-01-22 18:42:12
问题 i have xml file that i need to update each and every time as per new client requirement. most of the time xml is not proper because of manual updation of xml file. I am thinking to write a program (web/windows) where proper validation is provided. and based on the input from ui I will going to create xml file. below is my sample xml file. <community> <author>xxx xxx</author> <communityid>000</communityid> <name>name of the community</name> <addresses> <registeredaddress> <addressline1>xxx<

Keep sort when deserialize and serialize XML using XmlSerializer

雨燕双飞 提交于 2020-01-21 18:51:56
问题 I have the following test XML string: <?xml version="1.0" encoding="UTF-8"?> <test id="myid"> <b>b1</b> <a>a2</a> <a>a1</a> <b>b2</b> </test> which I deserialize using this class: [XmlRoot(ElementName = "test")] public class Test { [XmlElement(ElementName = "a")] public List<string> A { get; set; } [XmlElement(ElementName = "b")] public List<string> B { get; set; } [XmlAttribute(AttributeName = "id")] public string Id { get; set; } } If I'm now going to serialize the object the result will be

How do I set the dataProvider for an <s:List> component to be an XML file?

♀尐吖头ヾ 提交于 2020-01-21 10:14:28
问题 I've got the latest Beta of Adobe Flash Builder 4. I want to use a <s:List> component, and specify the dataProvider as being an XML file. However, after loads of research (including looking at doc links off labs.adobe.com), I still can't figure out how to do it. The XML file will look something like this: <?xml version="1.0" encoding="ISO-8859-1"?> <imageList> <image location="path/to/file1.jpg" /> <image location="path/to/file2.jpg" /> <image location="path/to/file3.jpg" /> </imageList> 回答1:

How do I set the dataProvider for an <s:List> component to be an XML file?

陌路散爱 提交于 2020-01-21 10:14:12
问题 I've got the latest Beta of Adobe Flash Builder 4. I want to use a <s:List> component, and specify the dataProvider as being an XML file. However, after loads of research (including looking at doc links off labs.adobe.com), I still can't figure out how to do it. The XML file will look something like this: <?xml version="1.0" encoding="ISO-8859-1"?> <imageList> <image location="path/to/file1.jpg" /> <image location="path/to/file2.jpg" /> <image location="path/to/file3.jpg" /> </imageList> 回答1: