How to use XSD.exe with attributeGroup ref

Viewed 754

I'm having trouble using xsd.exe while using a attributeGroup with ref. I use it to generate C# classes.

Here's my XSD:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           elementFormDefault="qualified"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           version="1.0">

  <xs:attributeGroup name="PersonBaseAttributes">
    <xs:attribute name="Name" type="xs:string" use="required" /> <!-- Missing in .CS -->
    <xs:attribute name="Born" type="xs:dateTime" use="required" /> <!-- Missing in .CS -->
  </xs:attributeGroup>

  <xs:attributeGroup name="SalesAttributes">
    <xs:attributeGroup ref="PersonBaseAttributes" />
    <xs:attribute name="Sales" type="xs:int" use="required" />
  </xs:attributeGroup>

  <xs:attributeGroup name="BossAttributes">
    <xs:attributeGroup ref="PersonBaseAttributes" />
    <xs:attribute name="Department" type="xs:string" use="required" />
  </xs:attributeGroup>

  <xs:element name="Boss" nillable="true" type="BossPerson" />
  <xs:element name="Sales" nillable="true" type="SalesPerson" />
  <xs:complexType name="SalesPerson">
    <xs:attributeGroup ref="SalesAttributes" />
  </xs:complexType>
    <xs:complexType name="BossPerson">
    <xs:attributeGroup ref="BossAttributes" />
  </xs:complexType>
</xs:schema>

It generates these two classes:

public partial class SalesPerson {

    private int salesField;

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public int Sales {
        get {
            return this.salesField;
        }
        set {
            this.salesField = value;
        }
    }
}

public partial class BossPerson {

    private string departmentField;

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string Department {
        get {
            return this.departmentField;
        }
        set {
            this.departmentField = value;
        }
    }
}

The generated classes are missing the fields Name and Born from PersonBaseAttributes. Is my XSD incorrect or doesn't xsd.exe know how to handle it?

And if xsd.exe cannot handle it, is there any other way to do it?

I execute it like this:

xsd.exe foo.xsd /c
2 Answers
Related