Tool that can combine many XSD files into one?

What you can do is to create another new file called file.xsd containing all the schema names in it and then the trick is to name the last schema file with .\ as prefix. File.xsd <xsd xmlns=”http://microsoft.com/dotnet/tools/xsd/”> <generateClasses language=”CS” namespace=”MyNamespace”> <schema>First.xsd</schema> <schema>Second.xsd</schema> <!– more schema files here –> <schema>.\Third.xsd</schema> </generateClasses> </xsd> Now run the command … Read more

Using XmlSerializer with an array in the root element

You should use [XmlElement], and not [XmlArray] to decorate the Items property – it’s already an array, and you only want to set the element name. public class StackOverflow_12924221 { [XmlRoot(“scan_details”)] public class ScanDetails { [XmlElement(“object”)] public ScanDetail[] Items { get; set; } } public class ScanDetail { [XmlAttribute(“name”)] public string Filename { get; set; … Read more

Serializing a Nullable in to XML

If you just want it to work, then perhaps: using System; using System.ComponentModel; using System.Xml.Serialization; public class Account { // your main property; TODO: your version [XmlIgnore] public Nullable<DateTime> AccountExpirationDate {get;set;} // this is a shim property that we use to provide the serialization [XmlAttribute(“AccountExpirationDate”)] [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public DateTime AccountExpirationDateSerialized { get {return AccountExpirationDate.Value;} set … Read more

PHP Object as XML Document

I’d agree with using PEAR’s XML_Serializer, but if you want something simple that supports objects/arrays that have properties nested, you can use this. class XMLSerializer { // functions adopted from http://www.sean-barton.co.uk/2009/03/turning-an-array-or-object-into-xml-using-php/ public static function generateValidXmlFromObj(stdClass $obj, $node_block=’nodes’, $node_name=”node”) { $arr = get_object_vars($obj); return self::generateValidXmlFromArray($arr, $node_block, $node_name); } public static function generateValidXmlFromArray($array, $node_block=’nodes’, $node_name=”node”) { $xml=”<?xml … Read more

Is there a reason why a base class decorated with XmlInclude would still throw a type unknown exception when serialized?

The issue you are seeing is because the PaymentSummaryRequest is setting the Namespace. You can either remove the Namespace or add a Namespace to the PaymentSummary class: [XmlRoot(Namespace = Constants.Namespace)] [XmlInclude(typeof(xxxPaymentSummary))] public abstract class PaymentSummary { } As @Tedford mentions in his comment below the namespace is only required when using derived types. It looks … Read more

Using DataContractSerializer to serialize, but can’t deserialize back

Here is how I’ve always done it: public static string Serialize(object obj) { using(MemoryStream memoryStream = new MemoryStream()) using(StreamReader reader = new StreamReader(memoryStream)) { DataContractSerializer serializer = new DataContractSerializer(obj.GetType()); serializer.WriteObject(memoryStream, obj); memoryStream.Position = 0; return reader.ReadToEnd(); } } public static object Deserialize(string xml, Type toType) { using(Stream stream = new MemoryStream()) { byte[] data = … Read more