xml-serialization

Implementing IXmlSerializable on a collection object

被刻印的时光 ゝ 提交于 2020-01-10 03:03:34
问题 I have an xml file looking somewhat like this: <xml> <A>value</A> <B>value</B> <listitems> <item> <C>value</C> <D>value</D> </item> </listitems> </xml> And I have a two objects representing this xml: class XmlObject { public string A { get; set; } public string B { get; set; } List<Item> listitems { get; set; } } class Item : IXmlSerializable { public string C { get; set; } public string D { get; set; } //Implemented IXmlSerializeable read/write public void ReadXml(System.Xml.XmlReader reader

Encoding binary data within XML: Are there better alternatives than base64?

笑着哭i 提交于 2020-01-10 02:53:33
问题 I want to encode and decode binary data within an XML file (with Python, but whatever). I have to face the fact that an XML tag content has illegal characters. The only allowed ones are described in XML specs: Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] Which means that the unallowed are: 29 Unicode control characters are illegal (0x00 - 0x20) ie ( 000xxxxx ) except 0x09, 0x0A, 0x0D Any Unicode character representation above 2 bytes (UTF-16+) is illegal (U

Suppress xsi:nil but still show Empty Element when Serializing in .Net

烂漫一生 提交于 2020-01-09 10:22:26
问题 I have a c# class that has 20+ string properties. I set about a fourth of those to an actual value. I would like to serialize the class and get an output of <EmptyAttribute></EmptyAttribute> for a property public string EmptyAttribute {get;set;} I do not want the output to be <EmptyAttribute xsi:nil="true"></EmptyAttribute> I am using the following class public class XmlTextWriterFull : XmlTextWriter { public XmlTextWriterFull(string filename) : base(filename,Encoding.UTF8) { } public

Suppress xsi:nil but still show Empty Element when Serializing in .Net

自古美人都是妖i 提交于 2020-01-09 10:22:17
问题 I have a c# class that has 20+ string properties. I set about a fourth of those to an actual value. I would like to serialize the class and get an output of <EmptyAttribute></EmptyAttribute> for a property public string EmptyAttribute {get;set;} I do not want the output to be <EmptyAttribute xsi:nil="true"></EmptyAttribute> I am using the following class public class XmlTextWriterFull : XmlTextWriter { public XmlTextWriterFull(string filename) : base(filename,Encoding.UTF8) { } public

Suppress xsi:nil but still show Empty Element when Serializing in .Net

情到浓时终转凉″ 提交于 2020-01-09 10:22:14
问题 I have a c# class that has 20+ string properties. I set about a fourth of those to an actual value. I would like to serialize the class and get an output of <EmptyAttribute></EmptyAttribute> for a property public string EmptyAttribute {get;set;} I do not want the output to be <EmptyAttribute xsi:nil="true"></EmptyAttribute> I am using the following class public class XmlTextWriterFull : XmlTextWriter { public XmlTextWriterFull(string filename) : base(filename,Encoding.UTF8) { } public

xsd in .net framework

一世执手 提交于 2020-01-07 08:48:12
问题 I have xsd file. I want to generate my entity model from this schema and serialize and deserialize. What is the recomanded .net framework and C# way to do so? I know JAXB from java. Can I use entity framework? is there another framework? 回答1: Xsd.exe is your friend. It generates c# classes from your schema. It's a command-line tool bundled into VisualStudio: open a Vsiaul Studio command prompt, then xsd.exe /? for details Alternately, Xsd2Code does the same kind of job but integrates better

xsd in .net framework

你说的曾经没有我的故事 提交于 2020-01-07 08:47:07
问题 I have xsd file. I want to generate my entity model from this schema and serialize and deserialize. What is the recomanded .net framework and C# way to do so? I know JAXB from java. Can I use entity framework? is there another framework? 回答1: Xsd.exe is your friend. It generates c# classes from your schema. It's a command-line tool bundled into VisualStudio: open a Vsiaul Studio command prompt, then xsd.exe /? for details Alternately, Xsd2Code does the same kind of job but integrates better

Create xml format c# [closed]

半城伤御伤魂 提交于 2020-01-06 20:00:50
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . I want to make xml format like this in c# <?xml version='1.0' encoding='us-ascii'?> <root> <key value="22.wav"> <Index>1</Index> <Index>20</Index> <Index>21</Index> </key> <key value="EFG.wav"> <Index>5</Index> <Index>22</Index> </key> </root> How do i form like this please help me 回答1: You could

Generate XML from C# Class with specific attributes

流过昼夜 提交于 2020-01-06 18:39:50
问题 I am stuck with an issue regarding XML serialization of a class in c#: What i Want is the XML in the format below <?xml version="1.0" encoding="utf-8"?> <MyClass:Req xsi:schemaLocation="http://www.Test.com/MyClass.xsd" xmlns:TestClass="http://www.Test.com/MyClass" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.Test.com/MyClass"> <head> <hA>01</hA> </head> <body> <R1>0</R1> <R3 /> <R4 /> </body> </MyClass:Req> All the XMLNS attributes are required and need to be

How to send XML in a URI for posting to a Web API app?

时间秒杀一切 提交于 2020-01-06 18:13:02
问题 I need to send a uri to a Controller method in my my Web API app which has the following signature: public HttpResponseMessage PostXMLFile(string serialNum, string siteNum, XElement xElement) Or should it be this instead: public HttpResponseMessage PostXMLFile(string serialNum, string siteNum, List<XElement> xElements) ? Anyway, as you can see, it can't be just the XML, but must have the serialNum and siteNum args, too. I'm assuming the uri can look like this: http://<machineName>:<port>/api/