xml-serialization

What is the benefit of turning Generate Serialization Assemblies off?

岁酱吖の 提交于 2019-12-23 07:37:05
问题 The Generate Serialization Assemblies option in Visual Studio creates a MyAssembly.XmlSerializers.dll when my project is built. This question (https://stackoverflow.com/questions/934411/what-is-myassembly-xmlserializers-dll-generated-for) indicates a reason why it's there in the first place, and some of the answers provide ways to turn it off, but my question is why would you choose to turn it off? Does having it turned on cause problems in certain situations (and, if so, what are those

XML Serialization of Class Which Has a Member Extended From an Abstract Type

对着背影说爱祢 提交于 2019-12-23 06:57:55
问题 I run into an InvalidOperationException when attempting to run this code. Example Code using System; using System.Collections.Generic; using System.IO; using System.Xml.Serialization; namespace XMLSerializationExample { class Program { static void Main(string[] args) { Caravan c = new Caravan(); c.WriteXML(); } } [XmlRoot("caravan", Namespace="urn:caravan")] public class Caravan { [XmlElement("vehicle")] public Auto Vehicle; public Caravan() { Vehicle = new Car { Make = "Suzuki", Model =

Easy XML Serializer for Java

烈酒焚心 提交于 2019-12-23 06:06:03
问题 I'm looking for a way to serialize Java objects into XML for use by a RESTful web service. I don't have an XSD. I have looked at the following: JAXB - fairly heavy weight with annotations required on classes and also an ObjectFactory class and/or a jaxb.index file Simple - requires annotations but no other config classes/files. Unfortunately it can't serialize Sets. XStream - no annotations etc. required, but doesn't support generics Does anyone else have any suggestions? 回答1: My vote would

Wrapping Serialized Properties in Additional Elements with .NET XML Serialization

点点圈 提交于 2019-12-23 04:03:35
问题 I am using C# + VSTS2008 + .Net 3.0 to do XML serialization. The code works fine. Here below is my code and current serialized XML results. Now I want to add two additional layers to the output XML file. Here is my expected XML results. Any easy way to do this? I am not sure whether NestingLevel could help to do this. I want to find an easy way which does not change the structure of MyClass and MyObject. Expected XML serialization result, <?xml version="1.0"?> <MyClass xmlns:xsi="http://www

Deserializing XML into class obj in C#

孤街浪徒 提交于 2019-12-23 03:13:35
问题 This is one of the entries I have in a huge XML file of over 200 such entries. <TradeFills> <TradeFill> <Broker>xxx</Broker> <CustomerAccount/> <qwFillTransID>xxxxxxxxxxxxxxxxxxx</qwFillTransID> <qwPrevTransID>xxx</qwPrevTransID> <qwGroupTransID>xxxxxxxxxxxxxxxxx</qwGroupTransID> <GroupTransID>xxxxxxxx</GroupTransID> <TransID>x</TransID> <Service>xxxxxxxxxxxxxxxx</Service> <Symbol>xx</Symbol> <Exchange>xxxxx</Exchange> <InstClass>xxxxxxxx</InstClass> <InstSubClass>xxxxxxx</InstSubClass>

Encoding special characters in xml

人盡茶涼 提交于 2019-12-23 02:22:25
问题 How to encode special characters in xml? e.g: i have a special character mu in my xml, transformation will fail due to this character any info would be helpful Thanks Preetham 回答1: If you are building up your XML via string concatenation then you need to stop doing that and start using a library (e.g. DOM) in your language to create the XML. The library will handle encoding correctly. 回答2: Any valid UTF-8 character should be fine in XML, and any XML processing tool (including XSLT) should

XmlSerializer doesn't serialize everything in my class

旧巷老猫 提交于 2019-12-23 02:17:54
问题 I have a very basic class that is a list of sub-classes, plus some summary data. [Serializable] public class ProductCollection : List<Product> { public bool flag { get; set; } public double A { get; set; } public double B { get; set; } public double C { get; set; } } ... // method to save this class private void SaveProductCollection() { // Export case as XML... XmlSerializer xml = new XmlSerializer(typeof(ProductCollection)); StreamWriter sw = new StreamWriter("output.xml"); xml.Serialize(sw

XmlSerialization with a singleton

无人久伴 提交于 2019-12-23 00:26:43
问题 Serialization woes continue... I'm trying to serialize a class, instances of which share between them common objects (a binder of sorts). So, objects A, B, C share object Binder1, and objects D and E - Binder2, and so on... I'm serializing objects A,B,C,D,E. Typically, this binder object is passed in a constructor - not with the serializer though, since it needs a parameterless constructor. ISeriazable seems to have something that works for singletons - IObjectReference interface, where the

Cannot parse simple XML into an object?

岁酱吖の 提交于 2019-12-23 00:22:51
问题 XML <MeterWalkOrder> <Name>Red Route</Name> <Meters> <Meter> <MeterID>1</MeterID> <SerialNumber>12345</SerialNumber> </Meter> <Meter> <MeterID>2</MeterID> <SerialNumber>SE</SerialNumber> </Meter> </Meters> </MeterWalkOrder> I cannot get simple XML into an object using any serializer var xml = File.ReadAllText("WalkOrder.xml"); var xmlSerializer = new NFormats.Xml.XmlSerializer(); var obj = xmlSerializer.Deserialize<MeterWalkOrder>(new StringReader(xml)); I just get back 2 meter objects that

SimpleFramwork XML: Element with Inner Text and Child Elements

こ雲淡風輕ζ 提交于 2019-12-22 18:29:12
问题 I have the following situtation in deserializing xml using SimpleFramework of specific format that cannot be changed... <Question ID="Q1"> THIS INNER TEXT IS THE ISSUE <Criteria Type="Normal" Source="OEM"> <Value Type="0">45.7</Value> <Value Type="100">42.7</Value> </Criteria> <Criteria Type="Impact" Source="OEM"> <Value Type="0">45.7</Value> <Value Type="100">42.7</Value> </Criteria> <!-- CRITERIA CAN HAVE ANY NUMBER --> </Question> and here is the class I wrote for Question @Root (name=