本主题专门介绍一项旧有技术。现在应通过使用以下链接来创建 XML Web 服务和 XML Web 服务客户端: Windows Communication Foundation.
.NET Framework 不为 <annotation> 元素提供绑定支持。
当从 XML 架构文档生成源代码时,Xsd.exe 会忽略 <annotation> 元素及其内容。
说明
当从 XML 架构文档生成源代码时,Xsd.exe 会忽略 <annotation> 元素及其内容。因此,也不会支持子元素 <appinfo> 和 <documentation>。
Xsd.exe 只有在要确定下面两个实体之间的对应关系时才使用 <annotation> 元素:
XmlNamespaceDeclarationsAttribute 类型的特性,应用于 XmlSerializerNamespaces 类型的字段或属性。
包含在 <appinfo> 元素中的 .NET Framework 特定 XML 元素 <keepNamespaceDeclarations>。
XmlSerializerNamespaces 对象用于存储前缀与前缀表示的命名空间之间的一组映射。annotation/appinfo/keepNamespaceDeclarations
元素的文本是 XmlSerializerNamespaces 字段或属性的名称。此转换是双向进行的,即从 XSD 文件到代码以及从代码到 XSD 文件,这样可以控制命名空间前缀。
Example
输入 C# 类:
public class MyClass {
[XmlAttribute]
public string name;
public string xpath;
[XmlNamespaceDeclarationsAttribute]
public XmlSerializerNamespaces xmlns;
}
基于通过前面的 C# 源代码编译得到的程序集生成的 XML 架构文档:
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="MyClass" nillable="true" type="MyClass" />
<xs:complexType name="MyClass">
<xs:annotation>
<xs:appinfo>
<keepNamespaceDeclarations>xmlns</keepNamespaceDeclarations>
</xs:appinfo>
</xs:annotation>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="xpath" type="xs:string" />
</xs:sequence>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:schema>
基于前面的 XML 架构文档生成的 C# 类实际上与生成 XML 架构的原始 C# 类相同。
可能的特性 | 绑定支持 |
---|---|
id |
Xsd.exe 实用工具会忽略旨在提供唯一标识符的 id 特性。 |
**可能的父元素:**许多
可能的子元素:<appinfo>、<documentation>