xml-serialization

Invalid character while converting from JSON to XML using jsonlib

南楼画角 提交于 2019-12-13 17:30:38
问题 I'm trying to convert a JSON string to XML using jsonlib in Java. JSONObject json = JSONObject.fromObject(jsonString); XMLSerializer serializer = new XMLSerializer(); String xml = serializer.write( json ); System.out.println(xml); The error that I get is nu.xom.IllegalNameException: 0x24 is not a legal NCName character The problem here is that I have some properties in my JSON that are invalid XML characters. eg. I have a property named "$t". The XMLSerializer throws the exception while

How to serialize a .NET object and assign to a string variable? [duplicate]

半腔热情 提交于 2019-12-13 17:24:49
问题 This question already has answers here : Can I Serialize XML straight to a string instead of a Stream with C#? (4 answers) Closed 3 years ago . How do I serialize a .NET object into XML and assign the XML string to variable? Example: private void SerializeObject(string filename) { Console.WriteLine("Writing With Stream"); XmlSerializer serializer = new XmlSerializer(typeof(OrderedItem)); OrderedItem i = new OrderedItem(); i.ItemName = "Widget"; i.Description = "Regular Widget"; i.Quantity =

Using BinaryFormatter and XmlSerializer interchangeably

随声附和 提交于 2019-12-13 16:52:22
问题 I've inherited a large amount of code that uses BinaryFormatter for serialization, that I now need to debug. All the serialization code currently expects an IFormatter. I had a idea to replace the BinaryFormatter with an XmlSerializer, to make examining the serialized output easier, but they aren't compatible (no common base or interface). Is there a standard approach to this e.g. make the parameter some kind of generic serializer that my code can use? Ideally I'd like to create whichever

LinkedList cannot be serialised?

谁说我不能喝 提交于 2019-12-13 14:42:19
问题 Here are my classes: http://pastebin.com/3dc5Vb1t When I try to run BookStore b = new BookStore(); b.LoadFromXML(Server.MapPath("list.xml")); Label1.Text = b.ToString(); I get the following error: You must implement a default accessor on System.Collections.Generic.LinkedList`1[[Book, App_Code.cxsacizw, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]] because it inherits from ICollection. The error source is XmlSerializer s = new XmlSerializer(typeof(BookStore)); When I tried to look

Polymorphic XML serialization/deserialization

情到浓时终转凉″ 提交于 2019-12-13 12:11:54
问题 I have: public class B { public string Some { get; set; } } public class D : B { public string More { get; set; } } [KnownType(typeof(D))] public class X { public B[] Col { get; set; } } I want to automatically read/write XML exactly like: <X> <Col> <B Some="val1" /> <D Some="val2" More="val3" /> </Col> </X> Neither XmlSerializer not DataContractSerializer helped me. This XML structure is mandatory. So question is: can this be achieved or i have to parse that XML manually? Thanks, Andrey 回答1:

XmlSerializer Giving a Null exception in c#

吃可爱长大的小学妹 提交于 2019-12-13 10:42:12
问题 A gold medal to the person who can tell me why this isnt working. FYI it has no inner exception text so its not helping me at all... XmlSerializer x = new XmlSerializer(typeof(DownloadedSite)); My innerexception is just Null. My error is: {"Object reference not set to an instance of an object."} Here is my class: namespace WayBackMachine.Business.Obj { using System; using System.Xml.Serialization; using System.Linq; using System.Collections.Generic; [Serializable] [XmlRoot("DownloadedSite")]

Serialize derived class root as base class name with type

天大地大妈咪最大 提交于 2019-12-13 07:13:08
问题 I am somehow not able to achieve this serialization. I have these classes public class Data { [XmlElement("Name")] public string Name { get; set; } } [XmlRoot("Data")] public class DataA : Data { [XmlElement("ADesc")] public string ADesc { get; set; } } [XmlRoot("Data")] public class DataB : Data { [XmlElement("BDesc")] public string BDesc { get; set; } } When I serialize either DataA or DataB I should get the XMLs in the below structure: <Data xmlns:i="http://www.w3.org/2001/XMLSchema

Mapping web form data to repeated XML elements

泄露秘密 提交于 2019-12-13 07:08:28
问题 I have gone all over the web looking for an answer to this, and have not been able to find one anywhere. I'm trying to build a web form that uses XSLT to generate XML data. I'm basing it on other forms that do the same thing, and have gotten small test structures to work fine. However, I am running into all sorts of problems when I try to map it to repeated elements. Here's a quick overview of what I have. I have an XSLT file that looks similar to this (disclaimer: lines excluded for brevity;

Writing CDATA in ASP.NET WebApi

烂漫一生 提交于 2019-12-13 07:07:22
问题 Im using the setting: formatters.XmlFormatter.UseXmlSerializer = true; The class i try to serailize is quite simple: public class MyClass { public MyClass() { CDATA = "<![CDATA[<link>MyLink</link>]]>" [XmlText] public string CDATA { get; set; } } I want this to be serialized into something like: <MyClass> <![CDATA[<link>MyLink</link>]]> </MyClass> But instead get: <MyClass> <![CDATA[<!link>MyLink<!/link>]]> </MyClass> So how can i prevent this? Or is there a better way using the ASP.NET

XML Field - Query

若如初见. 提交于 2019-12-13 06:46:21
问题 I'm not able to build a correct syntaxt in order to execute any query on my sql sever 2008 related to XML fields. I've a simple table with fields such as Idproduct, ProductName and XmlProduct. ..And XmlProduct field looks like following: <DynamicProfile xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/WinTest"> <AllData xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> <d2p1:KeyValueOfstringstring> <d2p1:Key>MyFirstKey<