xml-serialization

Save XML file on Android device and read it

拟墨画扇 提交于 2020-03-06 02:18:30
问题 I have issues with storing and reading an XML file on my Acer Iconia Tab A 100. The steps I followed are: 1) Plug in the tab to my system. 2) Copy test.xml file from my laptop to Acer Iconia Tab/ SDCard/ mydir/test.xml 3) Try to open this file in Android code, as follows: File testFile = null; File dir = new File(android.os.Environment.getExternalStorageDirectory(),"mydir"); if(dir.exists()) testFile = new File(dir, "test.xml"); if (testFile != null) Log.d ("File length="+testFile.length());

Save XML file on Android device and read it

僤鯓⒐⒋嵵緔 提交于 2020-03-06 02:17:47
问题 I have issues with storing and reading an XML file on my Acer Iconia Tab A 100. The steps I followed are: 1) Plug in the tab to my system. 2) Copy test.xml file from my laptop to Acer Iconia Tab/ SDCard/ mydir/test.xml 3) Try to open this file in Android code, as follows: File testFile = null; File dir = new File(android.os.Environment.getExternalStorageDirectory(),"mydir"); if(dir.exists()) testFile = new File(dir, "test.xml"); if (testFile != null) Log.d ("File length="+testFile.length());

XML API Request returns “d3p1” for arrays or sub-classes

╄→尐↘猪︶ㄣ 提交于 2020-03-04 15:33:07
问题 Using Postman, C#, .NET Framework 4.7 I make a GET request from Postman with content-accept set to "application/xml" and my .NET Framework Web API will respond with XML (brilliant!). I have not needed to serialize anything manually as .NET Framework serializes my response object with when I return Request.CreateResponse(HttpStatusCode.OK, myResponse) . However, it seems to include extra things which I am not familiar with and I am wondering if they can be removed via Global.asax settings or

Xml Serializing ICollection

半世苍凉 提交于 2020-02-24 19:32:07
问题 We're working on a project with a modestly-complex model, the core class of which has a number of properties that are lists of other associated classes. We're using EF 6 (code first) on the back end, and, following guidance on how to construct classes for that environment, we heavily leveraged ICollection<T> : public class Product { // a few normal properties public string Name { get; set; } public string Description { get; set; } public string Code { get; set; } // a large list of

Serialize string property as attribute, even if string is empty

倖福魔咒の 提交于 2020-02-18 08:10:50
问题 public class Hat { [XmlTextAttribute] public string Name { get; set; } [XmlAttribute("Color")] public string Color { get; set; } } var hat1 = new Hat {Name="Cool Hat", Color="Red"}; var hat2 = new Hat {Name="Funky Hat", Color=null}; This is what I get (notice missing color-attribute on Funky Hat): <Hats> <Hat Color="Red">Cool Hat</Hat> <Hat>Funky Hat</Hat> </Hats> This is what I want: <Hats> <Hat Color="Red">Cool Hat</Hat> <Hat Color="">Funky Hat</Hat> </Hats> How can I force the serializer

Serialize string property as attribute, even if string is empty

旧城冷巷雨未停 提交于 2020-02-18 08:09:27
问题 public class Hat { [XmlTextAttribute] public string Name { get; set; } [XmlAttribute("Color")] public string Color { get; set; } } var hat1 = new Hat {Name="Cool Hat", Color="Red"}; var hat2 = new Hat {Name="Funky Hat", Color=null}; This is what I get (notice missing color-attribute on Funky Hat): <Hats> <Hat Color="Red">Cool Hat</Hat> <Hat>Funky Hat</Hat> </Hats> This is what I want: <Hats> <Hat Color="Red">Cool Hat</Hat> <Hat Color="">Funky Hat</Hat> </Hats> How can I force the serializer

XML serialization of a Dictionary with a custom IEqualityComparer

天涯浪子 提交于 2020-02-15 09:15:59
问题 I want to serialize a Dictionary that has a custom IEqualityComparer . I've tried using DataContractSerializer but I can't get the Comparer to be serialized. I can't use BinaryFormatter because of this. I can always do something like: var myDictionary = new MyDictionary(deserializedDictionary, myComparer); But that means I'd need twice the memory the dictionary uses. 回答1: Why does the custom Comparer even need to be serialized? Here is a test case that works for me. using System; using System

Serialize list of interfaces using XML Serialization

核能气质少年 提交于 2020-02-05 06:26:30
问题 I have the class below which I need to serialize using the XML Serializer I know that the XML serializer does not like interfaces However, our coding standards normally involve always coding to interfaces not concrete classes I thought of a way to be able to stream this list without changing the types which would cause many compilation issues, as well as breaking our standards My idea is to have a property which reads the Meters list and casts to concrete classes then to totally ignore meters

How to generate XML Schema from C# type with XSD.exe such that [XmlAttribute] property is mapped to required XML attribute?

倾然丶 夕夏残阳落幕 提交于 2020-02-02 10:17:45
问题 Put it simply, when I use XSD.exe (that comes with Visual Studio 2012) to generate XML schema file from this class: [Serializable] public class Person { [XmlAttribute] public string Name { get; set; } [XmlAttribute] public int Age { get; set; } } I get this as the result: <?xml version="1.0" encoding="utf-8"?> <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Person" nillable="true" type="Person" /> <xs:complexType name="Person"> <xs

How to generate XML Schema from C# type with XSD.exe such that [XmlAttribute] property is mapped to required XML attribute?

牧云@^-^@ 提交于 2020-02-02 10:16:24
问题 Put it simply, when I use XSD.exe (that comes with Visual Studio 2012) to generate XML schema file from this class: [Serializable] public class Person { [XmlAttribute] public string Name { get; set; } [XmlAttribute] public int Age { get; set; } } I get this as the result: <?xml version="1.0" encoding="utf-8"?> <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Person" nillable="true" type="Person" /> <xs:complexType name="Person"> <xs