SUMMARY
In this chapter, we looked at the XPathDocument2 class members and how these properties and methods can be put to work. We saw how the XPathEditor turns the XPathDocument2 into an editable XML store. The XPathEditor, a descendant of the XPathNavigator2 class, provides a very efficient and usable model by combining XPath Select statements that can select nodes with the update methods of the XPathEditor. This XML cursor-based API approach to editing XML documents is set to replace the current XmlDocument DOM API as the preferred way to update in-memory XML documents.
The XPathDocument2 also provides many features that make it a better XML store than the XmlDocument. Based on the XPath (and hence XQuery) data model, it is the optimum store for fast, efficient XPath, XSLT, and XQuery queries. It supports change tracking at the node level by storing original and current values for each node, which are exposed via the XPathChangeNavigator class. This allows you to iterate over changes that have occurred in your XML document. The XPathChangeNavigator also allows you to select changed nodes and then either accept or reject these node changes as required.
We then looked at the XmlSchemaSet class, which is a replacement for the XmlSchemaCollection. It provides faster and more conformant validation of W3C XML schemas against an XPathDocument2 class. This enables you to edit the document with an XPathEditor and then validate or revalidate it according to a schema. We saw that, from an API perspective, the XmlSchemaSet is similar to the XmlSchemaCollection—with the main difference being an explicit Compile method.
Several examples demonstrated the events that are surfaced from the XPathDocument2 class. When combined with the XPathChangeNavigator, these enable you to apply business rules to changes on an XML document and allow you to roll back changes that do not conform to the business rules.
All in all, you should now be able to see why, because of the significant number of features and the XPath-based selection and editing model, the XPathDocument2 class is set to become the preferred XML store in the .NET Framework.
In the next chapter, we'll dive in even deeper to look at the XmlAdapter and SqlXml classes in version 2.0 of System.Xml and the .NET Framework.
 |