xml-serialization

PHP Object as XML Document

半腔热情 提交于 2019-12-17 15:22:53
问题 What is the best way to take a given PHP object and serialize it as XML? I am looking at simple_xml and I have used it to parse XML into objects, but it isn't clear to me how it works the other way around. 回答1: take a look at PEAR's XML_Serializer package. I've used it with pretty good results. You can feed it arrays, objects etc and it will turn them into XML. It also has a bunch of options like picking the name of the root node etc. Should do the trick 回答2: I'd agree with using PEAR's XML

How do I serialize all properties of an NHibernate-mapped object?

时光总嘲笑我的痴心妄想 提交于 2019-12-17 13:58:47
问题 I have some web methods that return my objects back as serialized XML. It is only serializing the NHibernate-mapped properties of the object... anyone have some insight? It seems to be that the web methods are actually serializing the NHibernate proxies instead of my classes. I've tried using [XMLInclude] and [XMLElement], but the properties are still not serializing. I have a really horrible hackish way of getting around this, but I wondered if there was a better way! Something like this: <

How do I serialize all properties of an NHibernate-mapped object?

女生的网名这么多〃 提交于 2019-12-17 13:58:04
问题 I have some web methods that return my objects back as serialized XML. It is only serializing the NHibernate-mapped properties of the object... anyone have some insight? It seems to be that the web methods are actually serializing the NHibernate proxies instead of my classes. I've tried using [XMLInclude] and [XMLElement], but the properties are still not serializing. I have a really horrible hackish way of getting around this, but I wondered if there was a better way! Something like this: <

How can I rename class-names via Xml attributes?

戏子无情 提交于 2019-12-17 10:48:13
问题 Suppose I have an XML-serializable class called Song : [Serializable] class Song { public string Artist; public string SongTitle; } In order to save space (and also semi-obfuscate the XML file), I decide to rename the xml elements: [XmlRoot("g")] class Song { [XmlElement("a")] public string Artist; [XmlElement("s")] public string SongTitle; } This will produce XML output like this: <Song> <a>Britney Spears</a> <s>I Did It Again</s> </Song> I want to rename/remap the name of the class/object

Serializing a Nullable<DateTime> in to XML

不问归期 提交于 2019-12-17 10:47:30
问题 I am trying to serialize a class several of the data-members are Nullable objects, here is a example [XmlAttribute("AccountExpirationDate")] public Nullable<DateTime> AccountExpirationDate { get { return userPrincipal.AccountExpirationDate; } set { userPrincipal.AccountExpirationDate = value; } } However at runtime I get the error Cannot serialize member 'AccountExpirationDate' of type System.Nullable`1[System.DateTime]. XmlAttribute/XmlText cannot be used to encode complex types. However I

How can I transform XML into a List<string> or String[]?

这一生的挚爱 提交于 2019-12-17 10:46:17
问题 How can I transform the following XML into a List<string> or String[] : <Ids> <id>1</id> <id>2</id> </Ids> 回答1: It sounds like you're more after just parsing rather than full XML serialization/deserialization. If you can use LINQ to XML, this is pretty easy: using System; using System.Linq; using System.Xml.Linq; public class Test { static void Main() { string xml = "<Ids><id>1</id><id>2</id></Ids>"; XDocument doc = XDocument.Parse(xml); var list = doc.Root.Elements("id") .Select(element =>

.NET XML Serialization without <?xml> text declaration

寵の児 提交于 2019-12-17 10:46:11
问题 I'm trying to generate XML like this: <?xml version="1.0"?> <!DOCTYPE APIRequest SYSTEM "https://url"> <APIRequest> <Head> <Key>123</Key> </Head> <ObjectClass> <Field>Value</Field </ObjectClass> </APIRequest> I have a class (ObjectClass) decorated with XMLSerialization attributes like this: [XmlRoot("ObjectClass")] public class ObjectClass { [XmlElement("Field")] public string Field { get; set; } } And my really hacky intuitive thought to just get this working is to do this when I serialize:

Slow SoapHttpClientProtocol constructor

自闭症网瘾萝莉.ら 提交于 2019-12-17 10:21:23
问题 I'm doing some experiments with Microsoft Dynamics CRM. You interact with it through web services and I have added a Web Reference to my project. The web service interface is very rich, and the generated "Reference.cs" is some 90k loc. I'm using the web reference in a console application. I often change something, recompile and run. Compilation is fast, but newing up the web service reference is very slow, taking some 15-20 seconds: CrmService service = new CrmService(); Profiling reveals

Best solution for XmlSerializer and System.Drawing.Color

十年热恋 提交于 2019-12-17 09:40:29
问题 System.Drawing.Color objects apparently won't serialize with XmlSerializer. What is the best way to xml serialize colors? 回答1: The simplest method uses this at it's heart: String HtmlColor = System.Drawing.ColorTranslator.ToHtml(MyColorInstance); It will just convert whatever the color is to the standard hex string used by HTML which is just as easily deserialized using: Color MyColor = System.Drawing.ColorTranslator.FromHtml(MyColorString); That way you're just working with bog standard

Serializing a list of Key/Value pairs to XML

烈酒焚心 提交于 2019-12-17 09:37:45
问题 I have a list of key/value pairs I'd like to store in and retrieve from a XML file. So this task is similar as described here. I am trying to follow the advice in the marked answer (using a KeyValuePair and a XmlSerializer ) but I don't get it working. What I have so far is a "Settings" class ... public class Settings { public int simpleValue; public List<KeyValuePair<string, int>> list; } ... an instance of this class ... Settings aSettings = new Settings(); aSettings.simpleValue = 2;