本主题专门介绍一项旧有技术。现在应通过使用以下链接来创建 XML Web 服务和 XML Web 服务客户端: Windows Communication Foundation.
.NET Framework 不为 <appinfo> 元素提供绑定支持。
当从 XML 架构文档生成源代码时,Xsd.exe 会忽略 <appinfo> 元素及其内容。
说明
当从 XML 架构文档生成源代码时,Xsd.exe 会忽略 <appinfo> 元素及其内容。这对于 <appinfo> 元素的父级 <annotation> 同样适用。
一个例外是下面两个实体之间的对应关系:
XmlNamespaceDeclarationsAttribute 类型的特性,应用于 XmlSerializerNamespaces 类型的字段或属性。
包含在 <appinfo> 元素中的 .NET Framework 特定 XML 元素 <keepNamespaceDeclarations>。
XmlSerializerNamespaces 对象用于存储前缀与前缀表示的命名空间之间的一组映射。annotation/appinfo/keepNamespaceDeclarations
元素的文本是 XmlSerializerNamespaces 字段或属性的名称。此转换是双向进行的,即从 XSD 文件到代码以及从代码到 XSD 文件,这样可以控制命名空间前缀。
示例
输入 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# 类相同。
可能的特性 | 绑定支持 |
---|---|
source |
由于 .NET Framework 不绑定 <appinfo> 元素,因此它不绑定该元素的 source 特性。 |
可能的父元素:<annotation>
**可能的子元素:**无限多