xml-serialization

xmlns=''> was not expected. - There is an error in XML document (2, 2)

佐手、 提交于 2019-12-18 18:41:22
问题 Im trying to deserialize the response from this simple web service Im using the following code: WebRequest request = WebRequest.Create("http://inb374.jelastic.tsukaeru.net:8080/VodafoneDB/webresources/vodafone/04111111"); WebResponse ws = request.GetResponse(); XmlSerializer s = new XmlSerializer(typeof(string)); string reponse = (string)s.Deserialize(ws.GetResponseStream()); 回答1: Declaring XmlSerializer as XmlSerializer s = new XmlSerializer(typeof(string),new XmlRootAttribute("response"));

Xml Serialization - Render Empty Element

泪湿孤枕 提交于 2019-12-18 14:56:09
问题 I am using the XmlSerializer and have the following property in a class public string Data { get; set; } which I need to be output exactly like so <Data /> How would I go about achieving this? 回答1: I was recently doing this and there is an alternative way to do it, that seems a bit simpler. You just need to initialise the value of the property to an empty string then it will create an empty tag as you required; Data = string.Empty; 回答2: The solution to this was to create a

How can I get XmlSerializer to encode bools as yes/no?

烂漫一生 提交于 2019-12-18 13:02:10
问题 I'm sending xml to another program, which expects boolean flags as "yes" or "no", rather than "true" or "false". I have a class defined like: [XmlRoot()] public class Foo { public bool Bar { get; set; } } When I serialize it, my output looks like this: <Foo><Bar>true</Bar></Foo> But I would like it to be this: <Foo><Bar>yes</Bar></Foo> Can I do this at the time of serialization? I would prefer not to have to resort to this: [XmlRoot()] public class Foo { [XmlIgnore()] public bool Bar { get;

How to deserialize into a List<String> using the XmlSerializer

ぐ巨炮叔叔 提交于 2019-12-18 12:57:07
问题 I'm trying to deserialize the XML below into class, with the Components deserialized into a List<string> , but can't figure out how to do so. The deserializer is working fine for all the other properties, but not Components . Anyone know how to do this? <ArsAction> <CustomerName>Joe Smith</CustomerName> <LoginID>jdsmith</LoginID> <TicketGroup>DMS</TicketGroup> <Software>Visio 2007 Pro</Software> <Components> <Component>Component 1</Component> <Component>Component 2</Component> </Components>

Serializing an ArrayList with XmlSerializer

断了今生、忘了曾经 提交于 2019-12-18 09:13:32
问题 ı am working on a small c# project at visual studio 2010 and ı was trying to serialize an arraylist which has my object of People class. here is my code block FileStream fs = new FileStream("fs.xml", FileMode.OpenOrCreate, FileAccess.Write); XmlSerializer xml = new XmlSerializer(typeof(ArrayList)); xml.Serialize(fs,this.array); and I have an error message at last line that is "There was an error generating the XML document." can anyone help me put please? 回答1: The reason you are getting this

XML class generator for serialization

浪子不回头ぞ 提交于 2019-12-18 09:09:16
问题 Is there an easy way to construct class from a XML. The constructed class will be used to serialize and deserialize XML. I have an XML with lots of properties and elements defined. Do I need to manually create my class based on that XML? Or Is there a utility tool available to generate class from XML Thanks, Esen 回答1: Further on Willem's post: This will generate the XSD ( not dataset ) xsd.exe myCustom.xml This generates the C# class: xsd.exe myCustom.xsd /c 回答2: There's a round about way:

The quest for 0x0B

老子叫甜甜 提交于 2019-12-18 08:54:55
问题 I get this error when reading some data from an SQL column then converting it to XML: "System.InvalidOperationException: There is an error in XML document (182, 16). ---> System.Xml.XmlException: ' ', hexadecimal value 0x0B, is an invalid character." Fair enough, maybe the data is malformed. Except, how can I find the culprit row? SELECT * from Mytable where Column like '%' + char(0x0B)+'%' returns empty. (obviously I attempted all %+char , char, char+% combinations, just in case) 回答1:

XmlSerializer. Skip xml unknown node

大城市里の小女人 提交于 2019-12-18 08:26:41
问题 I have a problem with deserialization of my xml files. Let's pretend that we have a xml file and a class that we are using for deserialization to. For example: xml - <dataStore> <name>newDataStore1</name> <description>sdffasdfasdf</description> <type>Shapefile</type> <enabled>false</enabled> <workspace> <name>newTestWorkspace</name> <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="ht tp://192.168.6.71:8080/geoserver/rest/workspaces/newTestWorkspace.xml" type="app

How to tell XmlSerializer to serialize properties with [DefautValue(…)] always?

谁说我不能喝 提交于 2019-12-18 07:42:51
问题 I am using DefaultValue attribute for the proper PropertyGrid behavior (it shows values different from default in bold). Now if I want to serialize shown object with the use of XmlSerializer there will be no entries in xml-file for properties with default values. What is the easiest way to tell XmlSerializer to serialize these still? I need that to support "versions", so when I change default value later in the code - serialized property gets value it had serialized with, not "latest" one. I

How to tell XmlSerializer to serialize properties with [DefautValue(…)] always?

自闭症网瘾萝莉.ら 提交于 2019-12-18 07:42:23
问题 I am using DefaultValue attribute for the proper PropertyGrid behavior (it shows values different from default in bold). Now if I want to serialize shown object with the use of XmlSerializer there will be no entries in xml-file for properties with default values. What is the easiest way to tell XmlSerializer to serialize these still? I need that to support "versions", so when I change default value later in the code - serialized property gets value it had serialized with, not "latest" one. I