xmlserializer

Deserialization / model binding in MVC4 webapi does not work with arrays

和自甴很熟 提交于 2019-11-29 11:03:18
I'm using the new WebApi which is part of MVC4 beta. I have the following class: public class Voucher { public string Id { get; set; } public string TableId { get; set; } public Product[] Products { get; set; } } My controller looks like this: public class VouchersController : ApiController { public Voucher PostVoucher(Voucher voucher) { //.... } } On the client side I serialize the data using an XmlSerializer . The output looks like expected and the Products array is serialized. If I post the data and put a break point inside the PostVoucher method, I get the data for Id and TableId , but

How do I stop an empty tag from being emitted by XmlSerializer?

半城伤御伤魂 提交于 2019-11-29 10:38:22
I have an object like this, public class UserObj { public string First {get; set;} public string Last {get; set;} public addr Address {get; set;} } public class addr { public street {get; set;} public town {get; set;} } Now when I use XmlSerializer on it and street and town are empty I get this in the XML output, <Address /> Is there a way not to output this empty tag? Thanks You may implement IXmlSerializable and implement the serialization routine on your own. This way, you can avoid the element. An example here: http://paltman.com/2006/jul/03/ixmlserializable-a-persistable-example/ You can

change how XmlSerializer serializes empty elements

流过昼夜 提交于 2019-11-29 08:19:48
I am using the XmlSerializer. It serializes the object just fine but the client requires required empty elements to be in this format <star:Confirm/> . The serializer instead serializes the empty elements to <star:Confirm></star:Confirm> is there a way to change it to serialize the way the client requires. After trying different things I accidentally happened upon the solution. I set the XmlElementAttribute.IsNullable to true like the previous answer suggested. [System.Xml.Serialization.XmlElementAttribute(ElementName = "Confirm", IsNullable=true)] public ConfirmType Confirm { get { return

XML deserializing only works with namespace in xml

让人想犯罪 __ 提交于 2019-11-29 06:47:26
The most simple way I get ServiceStack xml deserialization to work is when the xml contains a namespace. However, the xml I receive do not contain namespaces. The most simple working example: [Serializable] public class test { } class Program { static void Main(string[] args) { string xml="<test xmlns=\"http://schemas.datacontract.org/2004/07/\"></test>"; var result = ServiceStack.Text.XmlSerializer.DeserializeFromString<test>(xml); } } However, that is not what I want. I want the following to deserialize, since that is the xml I get from several services: string xml="<test></test>"; But that

axis2 maven example

我的未来我决定 提交于 2019-11-29 06:15:59
问题 I try to use axis2 (1.5.1) version to generate java codes from wsdl files, but I can't figure out what is the correct pom.xml <build> <plugins> <plugin> <groupId>org.apache.axis2</groupId> <artifactId>axis2-wsdl2code-maven-plugin</artifactId> <version>1.5.1</version> <executions> <execution> <goals> <goal>wsdl2code</goal> </goals> <configuration> <wsdlFile>src/main/resources/wsdl/stockquote.wsdl</wsdlFile> <databindingName>xmlbeans</databindingName> <packageName>a.bc</packageName> <

Is there a way to avoid the XmlSerializer to not initialize a null property when deserializing?

喜你入骨 提交于 2019-11-29 04:01:27
I have this class: public class MySerializableClass { public List<MyObject> MyList { get; set; } } If MyList is null when MySerializableClass is serialized, I need to have it null when it's deserialised too, but the XmlSerializer always initializes it when it deserialises my class. Is there a way to avoid it initializing null properties? MyList is not even recorded in the serialized file when it's null. When I load it with null values, and save it again, MyList is not null anymore, it's serialized as a List<> with 0 items, but not null. Thanks. More info: An IsDeserializing property is not

XmlSerializer won't serialize IEnumerable

删除回忆录丶 提交于 2019-11-29 02:50:24
I have an invocation logger that is intended to record all method calls along with the parameters associated with the method using XmlSerializer. It works well for most of the calls, but it throws an exception for all methods that has a parameter of IEnumerable type. For example, void MethodWithPlace( Place value ) would be serialized, but void MethodWithPlace( IEnumerable<Place> value ) would not. The exception is System.NotSupportedException: Cannot serialize interface System.Collections.Generic.IEnumerable`1[[Place, Test, Version=0.0.0.0, Culture=neutral]]. What should I do to make it work

C# - XML serialization of derived classes

妖精的绣舞 提交于 2019-11-28 23:55:09
I'm trying to serialize a List of multiple elements (Suppliers, Customers, Products, etc), all deriving from the same class (MasterElement) public class XMLFile { [XmlArray("MasterFiles")] public List<MasterElement> MasterFiles; ... } [XmlInclude(typeof(Supplier))] [XmlInclude(typeof(Customer))] public abstract class MasterElement { public MasterElement() { } } [XmlType(TypeName = "Supplier")] public class Supplier: MasterElement { public string SupplierID; public string AccountID; } [XmlType(TypeName = "Customer")] public class Customer: MasterElement { public string CustomerID; public string

XML (de)serialization invalid string inconsistent in c#?

蹲街弑〆低调 提交于 2019-11-28 18:54:30
In C# (.net 4.0 and 4.5 / vs2010 and vs12) when I serialize an object containing a string having an illegal character using XMLSerializer, no error is thrown. However, when I deserialize that result, an "invalid character" error is thrown. // add to XML Items items = new Items(); items.Item = "\v hello world"; // contains "illegal" character \v // variables System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Items)); string tmpFile = Path.GetTempFileName(); // serialize using (FileStream tmpFileStream = new FileStream(tmpFile, FileMode.Open,

C# XmlSerializer BindingFailure

孤街醉人 提交于 2019-11-28 18:33:33
I get a BindingFailure on a line of code using the XmlSerializer: XmlSerializer s = new XmlSerializer(typeof(CustomXMLSerializeObject)); The assembly with display name CustomXMLSerializeObject.XmlSerializers' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly XMLSerializeObject.XmlSerializers, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. The error is quite long and goes on to explain pre-bind