xml-serialization

XML Serialization of an object initialized as array

狂风中的少年 提交于 2019-12-20 04:17:49
问题 My question is probably arising from a basic misunderstanding of XML serialization, but anyways... I'm trying to serialize a class containing an object which was initialized with an array using XMLSerializer class. Minimal example: using System; using System.IO; using System.Xml.Serialization; namespace XMLSerializationTest { class Program { static void Main(string[] args) { try { string xmlFileName = Environment.CurrentDirectory + @"\somename.xml"; XmlSerializer writer = new XmlSerializer

C# Get all text from xml node including xml markup using Visual studio generated class

浪尽此生 提交于 2019-12-20 04:10:26
问题 Using xml to c# feature in visual studio converted the below xml markup into C# class. <books> <book name="Book-1"> <author> <name>Author-1<ref>1</ref></name> </author> </book> <book name="Book-2"> <author> <name>Author-1<ref>1</ref></name> </author> </book> </books> The converted class contains [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] public partial class booksBookAuthorName { private byte refField; // 1 private string[] textField; // 2 What we need is Author-1<ref>1

Replacing TXMLDocument (DOM-based) XML-generation with a solution that is able to write to a stream while the XML file is generated

风流意气都作罢 提交于 2019-12-20 03:17:14
问题 I have a whole lot of code which generates a XML using TXMLDocument, that looks like this: function Obj.SaveToXmlNode(XmlNode: IXmlNode; SubnodeName: string): IXmlNode; begin Result := XmlNode.AddChild(SubnodeName); SaveFieldToXmlNode(Result, 'FIELD1', 'Value1', 'PrevValue1'); SaveFieldToXmlNode(Result, 'FIELD2', 'Value2', 'PrevValue2'); //... end; with function SaveFieldToXmlNode(XmlNode: IXmlNode; FieldName: string; NewVal: Variant; OldVal: Variant): IXmlNode; var FieldNode: IXMLNode; begin

Multiple name spaces in a soap fault message causing FaultException deserialization to fail

℡╲_俬逩灬. 提交于 2019-12-20 02:54:20
问题 We're connecting to a web service and the fault message we're getting back isn't deserializing (at all), and no version of class that I can make will deserialize correctly. We have no control over the server side of things. The server does not allow for discovery, so adding ?WSDL to the end of the URL of the endpoint results in an error, not a WSDL. [Fiddler][1] shows the Fault message coming back looks like: <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:eGov="http://eGov.gov

How do I get the XMLSerializer to add namespaces to attributes in nested objects?

二次信任 提交于 2019-12-20 01:35:36
问题 This is what I get: <ex:test soap:mustUnderstand="1" xmlns:ex="http://www.example.com/namespace"> <ex:A Type="lorem">ipsum</ex:A> </ex:test> This is what I want: (Note that the Type-attribute is prefixed with ex.) <ex:test soap:mustUnderstand="1" xmlns:ex="http://www.example.com/namespace"> <ex:A ex:Type="lorem">ipsum</ex:A> </ex:test> This is my code: [XmlType(Namespace = "http://www.example.com/namespace")] [XmlRoot("ex", Namespace = "http://www.example.com/namespace")] public class

Prevent XmlSerializer from formatting output

天涯浪子 提交于 2019-12-19 12:24:27
问题 When using the default settings with the XmlSerializer it will output the XML as a formated value. IE: something along these lines. <?xml version="1.0" encoding="utf-8"?> <ArrayOfStock xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Stock> <ProductCode>12345</ProductCode> <ProductPrice>10.32</ProductPrice> </Stock> <Stock> <ProductCode>45632</ProductCode> <ProductPrice>5.43</ProductPrice> </Stock> </ArrayOfStock> How does one prevent any

XML Serialization List of Objects

自闭症网瘾萝莉.ら 提交于 2019-12-19 10:52:15
问题 Looking at the Microsoft article on XML Serialization: https://msdn.microsoft.com/en-us/library/58a18dwa.aspx They give an example under "Serializing an Array of Objects" as below: public class PurchaseOrder { public Item [] ItemsOrders } public class Item { public string ItemID public decimal ItemPrice } With output: <PurchaseOrder> <Items> <Item> <ItemID>aaa111</ItemID> <ItemPrice>34.22</ItemPrice> </Item> <Item> <ItemID>bbb222</ItemID> <ItemPrice>2.89</ItemPrice> </Item> </Items> <

Can you force the serialization of an enum value into an integer? [duplicate]

℡╲_俬逩灬. 提交于 2019-12-19 10:51:05
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: How do I serialize an enum value as an int? Hi, all! I'm wondering if there's a way to force the serialization of an enum value into its integer value, instead of its string representation. To put you into context: We're using, in a web application that heavily relies on web services, a single baseclass for all our request headers, independantly of the type of request. I want to add a Result field to the header,

get xml as string instead of class with xstream

隐身守侯 提交于 2019-12-19 10:39:13
问题 I have xml something like <parent> <message> <type>15</type> </message> </parent> Instead of creating a message object inside parent object, I need to represent message just as a String . So , when I do parent.message , the output is <type> 15 </type> instead of a message object. 回答1: The idia is to build up the xml of message by processing the HierarchicalStreamReader . If you go down into <messsage> by calling reader.goDown() unfortunately reader.getValue() does not return the whole content

JAXB inheritance in MOXY

大兔子大兔子 提交于 2019-12-19 08:54:16
问题 I have two classes: package a; class A { private <type> fieldOfClassA; // getters, and setters } package b; class B extends A{ private <type> fieldOfClassB; // getters, and setters } I want to marshal class B to an xml element and add the attribute fieldOfClassB, and fieldOfClassA from class A but it prints the following warning message during marshalling: Ignoring attribute [fieldOfClassA] on class [b.B] as no Property was generated for it. Note that the two class is from two different