4

My target is serialize c# classes to XML with attribute order like properties order in my classes. For this purporse I need add System.Xml.Serialization.XmlElementAttribute(Order=int) before other property in my class.

    [System.Xml.Serialization.XmlElementAttribute("F4INVAL", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
    public F4invalType[] F4INVAL {
        get {
            return this.f4INVALField;
        }
        set {
            this.f4INVALField = value;
        }
    }

I have XSD-file (f4form_2012_3.xsd).

Using Xsd.exe (http://msdn.microsoft.com/en-en/library/x6c1kb0s.aspx) I execute this scriptlet to generate a set of C# classes:

xsd f4form_2012_3.xsd /order /classes

I need to get class properties with C# attribute [System.Xml.Serialization.XmlElementAttribute(Order=1)]. And I do, but the first class' properties have this attribute.

The second and following classes don't have it.

Plase check f4form_2012_3.cs

What does it mean?

Adrian Salazar
  • 5,279
  • 34
  • 51
Peter Barbanyaga
  • 496
  • 7
  • 16
  • Your question is confusing. What is your objective? You need to generate XML from classes or classes from XML? – Alex Filipovici Dec 13 '12 at 13:01
  • @AlexFilipovici He wants to generate classes from XSD, so he can map a XML instance to CLR objects. – ken2k Dec 13 '12 at 13:02
  • I mean serialization process: XSD -> generate CLR C# Class -> serialize object to XML. Order of XML-attributes must be equals order of C# class properties. – Peter Barbanyaga Dec 13 '12 at 13:59

1 Answers1

1

This is because your F4ReportType complex type is the only type in your XSD that uses a xsd:sequence of elements. You cannot order properties generated from XML attributes, as attributes are not ordered in XML. Maybe you want to use XML elements instead.

ken2k
  • 48,145
  • 10
  • 116
  • 176
  • You are right, for example the class `F4inf1Type` also has order attributes. – Alex Filipovici Dec 13 '12 at 13:11
  • I mean serialization process: XSD -> generate CLR C# Class -> serialize object to XML. Order of XML-attributes must be equals order of C# class properties. – Peter Barbanyaga 18 mins ago – Peter Barbanyaga Dec 13 '12 at 14:24