我在使用xsd.exe時遇到問題,同時使用attributeGroup
和ref
。我用它來生成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;
}
}
}
生成的類是缺少從場PersonBaseAttributes
Name
和Born
。 我的XSD是不正確的還是xsd.exe不知道如何處理它?
如果xsd.exe無法處理它,有沒有其他的方式來做到這一點?
我執行這樣的:
xsd.exe foo.xsd /c
我有同樣的問題。你有沒有設法找到解決方案? –
@ParvSharma - 不幸的不是。在我的情況下,我們手動做了。 – smoksnes