System.Xml 类中的类型支持Type Support in the System.Xml Classes

在 .NET Framework 2.0 版中,核心 XML 类已得到增强,具有类型支持功能。In the .NET Framework version 2.0, the core XML classes have been enhanced to include type support features. XmlReaderXmlWriterXPathNavigator 类具有类型支持功能,可以在 XML 架构类型和公共语言运行库 (CLR) 类型之间转换。The XmlReader, XmlWriter, and XPathNavigator classes include type support features including the ability to convert between XML Schema types and common language runtime (CLR) types.

在 .NET Framework 2.0 版中,XmlReaderXmlWriterXPathNavigator 类已得到增强,具有类型支持功能。In the .NET Framework version 2.0, the XmlReader, XmlWriter, and XPathNavigator classes have been enhanced to include type support features.

  • XmlReaderXPathNavigator 类均包含 SchemaInfo 属性,用于返回节点的架构信息。The XmlReader and XPathNavigator classes each include a SchemaInfo property that returns the schema information on a node.

  • ReadContentAs 和 ReadElementContentAs 以及 XmlReader 类的方法在一个方法调用中,读取文本值并将它转换为 CLR 值。The ReadContentAs and ReadElementContentAs and methods on the XmlReader class read a text value and convert it to a CLR value in a single method call.

  • 在写出 XML 时,WriteValue 类的 XmlWriter 方法将 CLR 类型转换为 XML 架构类型。The WriteValue method on the XmlWriter class converts a CLR type to an XML Schema type when writing out XML.

  • XPathNavigator 类的 ValueAs 和 TypedValue 属性在一个方法调用中,返回节点值并将它转换为 CLR 值。The ValueAs and TypedValue properties on the XPathNavigator class return a node value and convert it to a CLR value in a single method call.

备注

在 .NET Framework 1.0 版中,需要使用 XmlConvert 类在 XML 架构和 CLR 类型之间进行转换。In the .NET Framework version 1.0 the XmlConvert class was needed to convert between XML Schema and CLR types.

本节内容In This Section

将 XML 数据类型映射到 CLR 类型Mapping XML Data Types to CLR Types
介绍 XML 数据类型与 CLR 类型的默认映射。Describes the default mappings of XML data types to CLR types.

XML 类型支持实现说明XML Type Support Implementation Notes
介绍一些类型支持实现的详细信息。Discusses some of the type support implementation details.

XML 数据类型转换Conversion of XML Data Types
描述如何使用 XmlConvert 类在 XML 架构和 CLR 类型之间进行转换。Describes how to use the XmlConvert class to convert between XML Schema and CLR types.

使用 XPathNavigator 访问强类型 XML 数据Accessing Strongly Typed XML Data Using XPathNavigator