xml-serialization

How do I write objects for easy XML Serialization in VB.NET?

北慕城南 提交于 2019-12-18 07:06:34
问题 I'm writing a small application in VB.NET and I would like some of the classes to be able to write themselves out to XML to serve as a "save" feature. I have seen XSD files used to generate VB classes that can serialize themselves into and out of XML very easily. How would I do this if I do have any pre-existing XML format that I need to conform to as I'm just creating the classes myself? 回答1: Use the System.Xml and System.Xml.Serialization namespaces. They describe classes that you can use

Generating an Xml Serialization assembly for a custom XmlSerializer

旧时模样 提交于 2019-12-18 07:05:32
问题 I have methods in my class for serializing/deserializing using a different XML structure than what would be produced with the default serializer. The methods create an XmlSerializer for my type but with a whole bunch of overrides. When these methods are called I guess internally .NET still generates a serialization assembly but I would like to generate this assembly after compilation so it's not generated at runtime. How can I generate a serialization assembly for this custom serialization?

Indent text in xml serialization of string property?

蹲街弑〆低调 提交于 2019-12-18 06:56:59
问题 I have a string property which will contain text with newlines. This text has some of the properties of HTML text in that whitespace is disregarded. If I serialize this type using XML serialization, the newlines are serialized properly, but the indentation is "wrong". I want the serialization process to indent the lines to keep the formatting of the XML, since those whitespace characters will be disregarded later anyway. Here's an example LINQPad program: void Main() { var d = new Dummy(); d

XmlSerializer with new enum values

China☆狼群 提交于 2019-12-18 06:31:08
问题 We use xml serialization / deserialization extensively in our project to pass data between multiple application. We have a common xsd that we generate c# classes from then use XmlSerializer to go from xml to objects and back. The problem we are having is when one app is updated to add new enum values but the other app is not updated yet. Now the app that is not updated tries to deserialize the xml and fails because it doesn't know about the new enum. If we have app1 and app2, things are

How do I stop an empty tag from being emitted by XmlSerializer?

狂风中的少年 提交于 2019-12-18 06:18:05
问题 I have an object like this, public class UserObj { public string First {get; set;} public string Last {get; set;} public addr Address {get; set;} } public class addr { public street {get; set;} public town {get; set;} } Now when I use XmlSerializer on it and street and town are empty I get this in the XML output, <Address /> Is there a way not to output this empty tag? Thanks 回答1: You may implement IXmlSerializable and implement the serialization routine on your own. This way, you can avoid

Which XML serialization library for Scala?

眉间皱痕 提交于 2019-12-18 05:25:07
问题 I'm looking for xml serialization library for scala. For json serialization I use lift-json, and would like my xml serialization library to be similar, that means: automatic serialization of case classes (without any format definition) smart serialization of scala types: collections, options etc. ability to define formats for other datatypes to adjust a way they are serialized deserialization not based on implicits but rather on class name (sometimes I have only class/class name of type which

Changing the XML structure generated by XmlSerializer in C#

孤者浪人 提交于 2019-12-18 05:20:35
问题 I have classes as follows namespace Coverage { public class ClassInfo { public string ClassName; public int BlocksCovered; public int BlocksNotCovered; public ClassInfo() {} public ClassInfo(string ClassName, int BlocksCovered, int BlocksNotCovered) { this.ClassName = ClassName; this.BlocksCovered = BlocksCovered; this.BlocksNotCovered = BlocksNotCovered; } } public class Module { public List<ClassInfo> ClassInfoList; public int BlocksCovered; public int BlocksNotCovered; public string

Deserialization Error: The XML element 'name' from namespace '' is already present in the current scope

血红的双手。 提交于 2019-12-18 04:55:10
问题 This is my first time using XML Serialization and this is driving me absolutely nuts after 2 days of trying to troubleshoot this. I get this error when the deserialization kicks in: The XML element 'name' from namespace '' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the element. The error happens on this line in my code: Album album = (Album)serializer.Deserialize(reader); I not sure why. There is no dup "name" node so I just don't

.Net XmlSerializer: deserialize CDATA being inner text

若如初见. 提交于 2019-12-18 04:18:14
问题 I have a problem with CDATA deserialization using standard .Net XmlSerializer. Update : I get XML from external system and I can't influence it's format so I can't make CData be enclosed in a separate Element of Attribute. Serialization gives this: <?xml version="1.0" encoding="utf-16"?> <MyClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><![CDATA[Hello, world!]]></MyClass> Deserialization does not restore object to it's original state.

Serialize class to XML?

ぃ、小莉子 提交于 2019-12-18 03:36:10
问题 I have the follow class and the list that holds it: public class Transport { public string TransportType { get; set; } public string Mode { get; set; } public class Coordinates { public float ID { get; set; } public float LocX { get; set; } public float LocY { get; set; } public float LocZ { get; set; } public ObjectState State { get; set; } public List<int[]> Connections = new <int[]>(); } } public enum ObjectState { Fly, Ground, Water } public static List<Transport> Tracking = new List