2017-05-17 41 views
2

我在使用xsd.exe時遇到問題,同時使用attributeGroupref。我用它來生成C#類。如何使用XSD.exe和attributeGroup參考

這裏是我的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> 

它產生這兩個類:

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; 
     } 
    } 
} 

生成的類是缺少從場PersonBaseAttributesNameBorn我的XSD是不正確的還是xsd.exe不知道如何處理它?

如果xsd.exe無法處理它,有沒有其他的方式來做到這一點?

我執行這樣的:

xsd.exe foo.xsd /c 
+0

我有同樣的問題。你有沒有設法找到解決方案? –

+0

@ParvSharma - 不幸的不是。在我的情況下,我們手動做了。 – smoksnes

回答

1

XML架構相貌端正對我來說,一個元素BossSales沒有屬性NameBorn將針對該架構無效(例如,氧確實需要這些屬性當提供你的模式時)。

請注意,生成的代碼由部分類組成。該工具是否可以在其他地方生成其他屬性?

+0

不幸的是沒有其他的類/文件生成。 – smoksnes