XML 文件和資料XML Documents and Data

.NET Framework 提供一組完整且整合的類別,好讓您輕鬆地建置可感知 XML 的應用程式。The .NET Framework provides a comprehensive and integrated set of classes that enable you to build XML-aware apps easily. 下列命名空間中的類別支援 XML 的剖析與撰寫、記憶體中 XML 資料的編輯、資料驗證和 XSLT 轉換。The classes in the following namespaces support parsing and writing XML, editing XML data in memory, data validation, and XSLT transformation.

如需完整清單,請在 .NET API 瀏覽器搜尋 "System.Xml"。For a full list, search for "System.Xml" on the .NET API browser.

這些命名空間中的類別支援全球資訊網協會 (W3C) 的建議。The classes in these namespaces support World Wide Web Consortium (W3C) recommendations. 例如:For example:

.NET Framework 中的 XML 類別提供以下優點:The XML classes in the .NET Framework provide these benefits:

  • 生產力。Productivity. LINQ to XML (C#)LINQ to XML (Visual Basic) 可輕鬆地透過 XML 編寫程式,並提供類似於 SQL 的查詢體驗。LINQ to XML (C#) and LINQ to XML (Visual Basic) makes it easier to program with XML and provides a query experience that is similar to SQL.

  • 擴充性。Extensibility. .NET Framework 中的 XML 類別可利用抽象基底類別和虛擬方法進行擴充。The XML classes in the .NET Framework are extensible through the use of abstract base classes and virtual methods. 例如,您可以建立將快取資料流儲存在本機磁碟之 XmlUrlResolver 類別的衍生類別。For example, you can create a derived class of the XmlUrlResolver class that stores the cache stream to the local disk.

  • 可外掛式架構。Pluggable architecture. .NET Framework 提供的架構可讓元件在其中彼此互相利用,而且資料也可以在不同的元件之間進行資料流處理。The .NET Framework provides an architecture in which components can utilize one another, and data can be streamed between components. 例如,類似 XPathDocumentXmlDocument 的資料存放區可透過 XslCompiledTransform 類別進行轉換,接著輸出可以資料流方式傳輸至另一個存放區,或當做 Web 服務的資料流傳回。For example, a data store, such as an XPathDocument or XmlDocument object, can be transformed with the XslCompiledTransform class, and the output can then be streamed either into another store or returned as a stream from a web service.

  • 效能。Performance. 為了提高應用程式效能,.NET Framework 中的某些 XML 類別可支援資料流形式的模型,並擁有下列特性:For better app performance, some of the XML classes in the .NET Framework support a streaming-based model with the following characteristics:

    • 順向的最小快取、提取模型剖析 (XmlReader)。Minimal caching for forward-only, pull-model parsing (XmlReader).

    • 順向驗證 (XmlReader)。Forward-only validation (XmlReader).

    • 資料指標樣式導覽,可將節點的建立最小化為單一虛擬節點,同時提供文件的隨機存取 (XPathNavigator)。Cursor style navigation that minimizes node creation to a single virtual node while providing random access to the document (XPathNavigator).

    為了要在每次需要 XSLT 處理時都提高效能,您可以使用 XPathDocument 類別,它是最佳化的唯讀 XPath 查詢存放區,其設計目的是要與 XslCompiledTransform 類別有效率地一起運作。For better performance whenever XSLT processing is required, you can use the XPathDocument class, which is an optimized, read-only store for XPath queries designed to work efficiently with the XslCompiledTransform class.

  • 與 ADO.NET 整合。Integration with ADO.NET. XML 類別與 ADO.NET 緊密整合在一起,可讓關聯式資料和 XML 結合在一起。The XML classes and ADO.NET are tightly integrated to bring together relational data and XML. DataSet 類別是一項擷取自資料庫的記憶體中資料快取。The DataSet class is an in-memory cache of data retrieved from a database. DataSet 類別可使用 XmlReaderXmlWriter 類別來讀取及寫入 XML,將其內部的關聯式結構描述結構保存為 XML 結構描述 (XSD),還可以推斷 XML 文件的結構描述結構。The DataSet class has the ability to read and write XML by using the XmlReader and XmlWriter classes, to persist its internal relational schema structure as XML schemas (XSD), and to infer the schema structure of an XML document.

本節內容In This Section

XML 處理選項 討論用來處理 XML 資料的選項。XML Processing Options Discusses options for processing XML data.

處理記憶體內的 XML 資料 討論用來處理記憶體內 XML 資料的三個模型:LINQ to XML (C#)LINQ to XML (Visual Basic)XmlDocument 類別 (根據 W3C 文件物件模型) 和 XPathDocument 類別 (根據 XPath 資料模型)。Processing XML Data In-Memory Discusses the three models for processing XML data in-memory: LINQ to XML (C#) and LINQ to XML (Visual Basic), the XmlDocument class (based on the W3C Document Object Model), and the XPathDocument class (based on the XPath data model).

XSLT 轉換XSLT Transformations
說明如何使用 XSLT 處理器。Describes how to use the XSLT processor.

XML 結構描述物件模型 (SOM)XML Schema Object Model (SOM)
說明藉由提供 XmlSchema 類別來載入和編輯結構描述,用以建置及管理 XML 結構描述 (XSD) 的類別。Describes the classes used for building and manipulating XML Schemas (XSD) by providing an XmlSchema class to load and edit a schema.

XML 與關聯式資料和 ADO.NET 的整合XML Integration with Relational Data and ADO.NET
說明 .NET Framework 如何透過 DataSet 物件和 XmlDataDocument 物件,啟用即時、同步方式來存取關聯式及階層式表示的資料。Describes how the .NET Framework enables real-time, synchronous access to both the relational and hierarchical representations of data through the DataSet object and the XmlDataDocument object.

管理 XML 文件中的命名空間Managing Namespaces in an XML Document
說明 XmlNamespaceManager 類別如何用來儲存及維護命名空間資訊。Describes how the XmlNamespaceManager class is used to store and maintain namespace information.

System.Xml 類別中的類型支援Type Support in the System.Xml Classes
說明 XML 資料類型如何對應到 CLR 類型、如何轉換 XML 資料類型,以及 System.Xml 類別中的其他類型支援功能。Describes how XML data types map to CLR types, how to convert XML data types, and other type support features in the System.Xml classes.

ADO.NETADO.NET
提供如何使用 ADO.NET 來存取資料的相關資訊。Provides information on how to access data using ADO.NET.

安全性Security
提供 .NET Framework 安全性系統的概觀。Provides an overview of the .NET Framework security system.