xml-serialization

XmlSerialization Collection as Array

﹥>﹥吖頭↗ 提交于 2019-12-30 05:04:07
问题 I'm trying to serialize a custom class that needs to use multiple elements of the same name. I've tried using xmlarray, but it wraps them in another elements. I want my xml to look like this. <root> <trees>some text</trees> <trees>some more text</trees> </root> My code: [Serializable(), XmlRoot("root")] public class test { [XmlArray("trees")] public ArrayList MyProp1 = new ArrayList(); public test() { MyProp1.Add("some text"); MyProp1.Add("some more text"); } } 回答1: Try just using [XmlElement

Can XmlSerializer deserialize into a Nullable<int>?

余生长醉 提交于 2019-12-30 05:01:05
问题 This is duplicate of Can XmlSerializer deserialize into a Nullable<int>? but I need a solution that neither change xml document nor forces me to implement IXmlSerializable interface. I dont want to implement IXmlSerializable because I have many additional elements beside <number > that get deserialized correctly. My xml can contain either element <number>4</number> or <number/> <root> ... either <number>4</number> or <number/> ... [other elements] </root> Class public class root { public int?

How to return xml as UTF-8 instead of UTF-16

久未见 提交于 2019-12-30 01:58:11
问题 I am using a routine that serializes <T> . It works, but when downloaded to the browser I see a blank page. I can view the page source or open the download in a text editor and I see the xml, but it is in UTF-16 which I think is why browser pages show blank? How do I modify my serializer routine to return UTF-8 instead of UTF-16? The XML source returned: <?xml version="1.0" encoding="utf-16"?> <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org

c++ linux library for creating an xml and reading from an xml (serialize/ deserialize)

拜拜、爱过 提交于 2019-12-29 09:41:34
问题 I am working in Ubuntu. I have a .h file with a class and a lot of nested classes. I would like to create an XML file from an object. Can someone please give me a library that creates XML files, serializes, and deserializes objects? I am compiling with g++. 回答1: Try libxml2. But it seems like you want to serialize and desirialize an object from and to XML. Boost::serialization might come in handy. it also supports serialization from and to XML. Here you can find an example for Boost:

c++ linux library for creating an xml and reading from an xml (serialize/ deserialize)

放肆的年华 提交于 2019-12-29 09:41:32
问题 I am working in Ubuntu. I have a .h file with a class and a lot of nested classes. I would like to create an XML file from an object. Can someone please give me a library that creates XML files, serializes, and deserializes objects? I am compiling with g++. 回答1: Try libxml2. But it seems like you want to serialize and desirialize an object from and to XML. Boost::serialization might come in handy. it also supports serialization from and to XML. Here you can find an example for Boost:

How to serialize multiple objects into an existing XmlDocument, without having the namespaces on each component?

霸气de小男生 提交于 2019-12-29 09:15:14
问题 How to serialize multiple objects into a existing XmlDocument in .Net/C#? I have a XmlDocument, which already contains data. I have multiple objects. Now I want to serialize them one by one and add them to the XmlDocument (AppendChild). This is how it should be: <?xml version="1.0" encoding="utf-8" standalone="yes"?> <project> <mySettings>...</mySettings> <component_1> anydata </component_1> ... <component_x> anydata </component_x> </project> When I use the XmlSerializer I get this definition

In .NET XML deserialization, how can I allow polymorphic use of Array types?

落爺英雄遲暮 提交于 2019-12-29 08:02:03
问题 Example Schema: <complexType name="Dog">...</complexType> <complexType name="Cat">...</complexType> <complexType name="ArrayOfDog"> <sequence> <element name="Dog" type="tns:Dog minOccurs="0" maxOccurs="unbounded" /> </sequence> </complexType> <complexType name="Foo"> <sequence> <element name="Bar" type="string"/> <element name="Baz" type="anyType"/> </sequence> </complexType> Running this through .NET's wsdl.exe generates code similar to the following: [System.Xml.Serialization

In .NET XML deserialization, how can I allow polymorphic use of Array types?

我们两清 提交于 2019-12-29 08:01:28
问题 Example Schema: <complexType name="Dog">...</complexType> <complexType name="Cat">...</complexType> <complexType name="ArrayOfDog"> <sequence> <element name="Dog" type="tns:Dog minOccurs="0" maxOccurs="unbounded" /> </sequence> </complexType> <complexType name="Foo"> <sequence> <element name="Bar" type="string"/> <element name="Baz" type="anyType"/> </sequence> </complexType> Running this through .NET's wsdl.exe generates code similar to the following: [System.Xml.Serialization

Deserializing nested xml into C# objects

给你一囗甜甜゛ 提交于 2019-12-29 07:03:16
问题 I am retrieving xml data from an http web request and deserializing the data into objects. Here is a sample xml structure. <users> <user> <name>...</name> <orders> <order> <number>...</number> </order> ... </orders> </user> <user> <name>...</name> <orders></orders> </user> ... </users> I have four classes public class Users { [XmlElement("user")] public User[] UserList { get; set; } } public class User { [XmlElement("name")] public string Name { get; set; } [XmlArray("orders")] public Orders

XML serialization, encoding

元气小坏坏 提交于 2019-12-29 06:39:12
问题 using System; public class clsPerson { public string FirstName; public string MI; public string LastName; } class class1 { static void Main(string[] args) { clsPerson p=new clsPerson(); p.FirstName = "Jeff"; p.MI = "A"; p.LastName = "Price"; System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(p.GetType()); x.Serialize(Console.Out, p); Console.WriteLine(); Console.ReadLine(); } } taken from http://support.microsoft.com/kb/815813 1) System.Xml.Serialization