.NET Framework 为 <simpleContent> 元素提供部分绑定支持。
简单内容扩展始终通过 .NET Framework 中的类定义完全表示。 简单内容限制不能被识别。
说明
XML 架构定义语言使用 <simpleContent> 元素定义不包含子元素的复杂类型。 包含简单内容(属性和/或正文文本)的复杂类型是使用 <simpleContent> 元素下的 <extension> 或 <restriction> 元素,通过扩展或限制从基类型派生的。
Xsd.exe 不识别简单内容限制。 简单内容扩展始终通过 .NET Framework 中的类定义完全表示。 当从 XML 架构文档生成源代码时,Xsd.exe 会生成一个公共字段,其类型与 <extension> 元素的 base 属性指定的基类型相对应。 有关 XML 架构中的内置简单类型与 .NET Framework 类型之间的绑定,请参见《.NET Framework 开发人员指南》中的“XML 架构 (XSD) 类型与 .NET Framework 类型之间的数据类型支持”。
简单内容扩展和限制在架构对象模型中分别由类 XmlSchemaSimpleContentExtension 和 XmlSchemaSimpleContentRestriction 表示,也可以由 XmlSchemaSimpleContent 类表示。
这些类的对象可以用来以编程方式创建架构对象模型,该模型与定义包含简单内容的复杂类型的 XSD 文档对应。
示例
输入 XML 架构文档:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://example.org/" xmlns="http://example.org/" elementFormDefault="qualified">
<xsd:element name="Distance">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:float">
<xsd:attribute name="units" type="xsd:string"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>
基于前面的 XML 架构文档生成的 C# 类:
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://example.org/", IsNullable=false)]
public class Distance {
[System.Xml.Serialization.XmlAttributeAttribute()]
public string units;
[System.Xml.Serialization.XmlTextAttribute()]
public System.Single Value;
}
基于通过前面的 C# 源代码编译得到的程序集生成的 XML 架构元素和复杂类型:
<xs:element name="Distance" type="tns:Distance" />
<xs:complexType name="Distance">
<xs:simpleContent>
<xs:extension base="xs:float">
<xs:attribute name="units" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
可能的属性 | 绑定支持 |
---|---|
id |
Xsd.exe 实用工具会忽略旨在提供唯一标识符的 id 属性。 |
可能的父元素:<complexType>
可能的子元素:<annotation>、<extension>、<restriction>
请参见
参考
版权所有 (C) 2007 Microsoft Corporation。保留所有权利。