xml-serialization

Ignore a property during xml serialization but not during deserialization

我与影子孤独终老i 提交于 2019-12-17 08:56:09
问题 In C#, how can I make XmlSerializer ignore a property during serialization but not during deserialization? (Or how do I do the same with Json.net?) To prevent a property from being serialized, you can add the XmlIgnore attribute: [XmlIgnore] public int FooBar {get;set;} This will cause the <FooBar> tag to be omitted during serialization. However, this also means that the <FooBar> tag will be ignored during deserialization. In my case, I accept an array of items from user in the request, and

How to add attributes for C# XML Serialization

血红的双手。 提交于 2019-12-17 07:21:23
问题 I am having an issue with serializing and object, I can get it to create all the correct outputs except for where i have an Element that needs a value and an attribute. Here is the required output: <Root> <Method>Retrieve</Method> <Options> <Filter> <Times> <TimeFrom>2009-06-17</TimeFrom> </Times> <Document type="word">document name</Document> </Filter> </Options> </AdCourierAPI> I can build all of it but can not find a way to set the Document type attribute, here is a segment of the object

How to add attributes for C# XML Serialization

落爺英雄遲暮 提交于 2019-12-17 07:21:07
问题 I am having an issue with serializing and object, I can get it to create all the correct outputs except for where i have an Element that needs a value and an attribute. Here is the required output: <Root> <Method>Retrieve</Method> <Options> <Filter> <Times> <TimeFrom>2009-06-17</TimeFrom> </Times> <Document type="word">document name</Document> </Filter> </Options> </AdCourierAPI> I can build all of it but can not find a way to set the Document type attribute, here is a segment of the object

How to XML-serialize a dictionary

喜你入骨 提交于 2019-12-17 06:46:23
问题 I have been able to serialize an IEnumerable this way: [XmlArray("TRANSACTIONS")] [XmlArrayItem("TRANSACTION", typeof(Record))] public IEnumerable<BudgetRecord> Records { get { foreach(Record br in _budget) { yield return br; } } } However, I realised that now I need a dictionary containing a collection Dictionary<string, RecordCollection> (RecordCollection implements IEnumerable). How can I achieve that? 回答1: Take a look at the following blog post http://blogs.msdn.com/b/psheill/archive/2005

How to serialize an object to XML without getting xmlns=“…”?

无人久伴 提交于 2019-12-17 03:58:42
问题 Is there a way for me to serialize an object in .NET without the XML Namespaces automatically serializing also? It seems that by default .NET believes the XSI and XSD namespaces should be included, but I don't want them there. 回答1: Ahh... nevermind. It's always the search after the question is posed that yields the answer. My object that is being serialized is obj and has already been defined. Adding an XMLSerializerNamespace with a single empty namespace to the collection does the trick. In

How do you find out when you've been loaded via XML Serialization?

感情迁移 提交于 2019-12-17 03:42:12
问题 I'm trying to load a tree of objects via XML serialisation, and at the moment it will load the objects in, and create the tree quite happily. My issue revolves around the fact that these classes support a level of auditing. What I'd like to be able to do is call some method on each object after it has finished being loaded. For the sake of argument, assume I have a fairly generic object tree with differing classes at different levels, like: <Customer name="Foo Bar Inc."> <Office IsHq="True">

Convert xml to string with jQuery

放肆的年华 提交于 2019-12-17 03:09:16
问题 I'm loading an xml file with jQuery ajax loader, and need to convert it to a string so that I can save it out again using PHP post variables. What is the best way to do this? <script type='text/javascript'> jQuery.ajax({ type: "GET", url: "data.xml", dataType: "xml", success: parseXML }); function parseXML(xml) { var xml_string = jQuery(xml).text(); // (This doesn't work- returns tagless, unformatted text) alert(xml_string); } </script> 回答1: Here it is: <script type='text/javascript'>

Serialize an object to string

两盒软妹~` 提交于 2019-12-17 02:41:21
问题 I have the following method to save an Object to a file: // Save an object out to the disk public static void SerializeObject<T>(this T toSerialize, String filename) { XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType()); TextWriter textWriter = new StreamWriter(filename); xmlSerializer.Serialize(textWriter, toSerialize); textWriter.Close(); } I confess I did not write it (I only converted it to a extension method that took a type parameter). Now I need it to give the xml

How to convert class Array to XML file in C# dynamically?

喜夏-厌秋 提交于 2019-12-14 03:27:04
问题 I trying to setting up a Xml file whose data are in class array format. The Basic class format is OrderTemplate Class public partial class OrderTemplate { public int Id { get; set; } public int? OrderNumberCounterId { get; set; } public int? SerialCounterId { get; set; } public string Name { get; set; } public string Description { get; set; } public int? Critical { get; set; } public Counter OrderNumberCounter { get; set; } public ICollection<OperationTemplate> OperationTemplate { get; set; }

WCF Service via JavaScript with XML - Array parameters

99封情书 提交于 2019-12-14 03:14:52
问题 I'm using JavaScript to communicate to a WCF service via XML (I can't use JSON). This has been working well so far for WCF methods which expose arguments of "primitive" data types, but now I need to call a WCF method which accepts an array. I've been unable to figure out how to tweak my XML properly. For example, a WCF method with two parameters accepts: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <MySimpleMethod xmlns="http://tempuri.org/"> <parameter1>value<