[英]How to use XSD.exe with attributeGroup ref
I'm having trouble using xsd.exe while using a attributeGroup
with ref
. 我在使用带有ref
的attributeGroup
时使用xsd.exe时遇到问题。 I use it to generate C# classes. 我用它来生成C#类。
Here's my XSD: 这是我的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
. 生成的类缺少PersonBaseAttributes
Name
和Born
字段。 Is my XSD incorrect or doesn't xsd.exe know how to handle it? 我的XSD不正确或xsd.exe不知道如何处理它?
And if xsd.exe cannot handle it, is there any other way to do it? 如果xsd.exe无法处理它,还有其他方法吗?
I execute it like this: 我这样执行:
xsd.exe foo.xsd /c
I have the same problem. 我也有同样的问题。 I think xsd.exe does not support nested attributeGroups: https://social.msdn.microsoft.com/Forums/en-US/707c8a47-a29f-4262-b052-ac66dc99d604/nested-xml-attribute-groups?forum=asmxandxml 我认为xsd.exe不支持嵌套的attributeGroups: https ://social.msdn.microsoft.com/Forums/en-US/707c8a47-a29f-4262-b052-ac66dc99d604/nested-xml-attribute-groups?forum=asmxandxml
The XML Schema looks correct to me, an element Boss
or Sales
without the attributes Name
and Born
would be invalid against the schema (eg, oXygen does require these attributes when supplied with your schema). 对于我来说,XML Schema看起来是正确的,没有Name
和Born
属性的元素Boss
或Sales
对于模式是无效的(例如,oXygen在提供模式时确实需要这些属性)。
Note that the generated code is made of partial classes. 请注意,生成的代码由部分类组成。 Could the tool have generated the other attributes somewhere else? 该工具是否可以在其他地方生成其他属性?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.