December 04, 2003 12:12 AM

What’s New for XML Developers in .NET 2.0

The next version of the .NET Framework adds a lot of new capability for working with XML.
DevConnections
Rating: (0)

DataStream

LANGUAGES: C#

ASP.NETVERSIONS: 1.0 | 1.1

 

What's New for XML Developers in .NET 2.0

The next version of the .NET Framework adds a lot of newcapability for working with XML.

 

 

Ina recent issue of this column, I gave you a quick overview of the newfeatures in ADO.NET 2.0 for data access. Now I want to cover what is new on theXML side of the data access equation in .NET 2.0. XML usage for a variety ofdata scenarios continues to grow by leaps and bounds. There is just no betterapproach to bringing together heterogeneous data than working with it in theform of XML. As such, Microsoft continues to try to make the XML management capabilitiesof .NET more and more powerful to make your life easier.

 

The information I'll be covering in this article comesfrom a combination of the documentation from the Alpha of .NET Whidbey (2.0)released at the Professional Developers Conference (PDC) in October, PDC talksI attended, and info from the book AFirst Look at ADO.NET and System.Xml v2.0, by Alex Homer, Dave Sussman, andMark Fussell from Addison-Wesley. I'll be covering two key areas that include arange of new classes and capabilities: enhancements to the XML document modeland integration of XQuery and native XML types in SQL Server Yukon (the nextversion of SQL Server due out at the same time as .NET 2.0). This is not acomprehensive list of the changes that touch XML development in .NET 2.0, butshould give you a good idea of the new capabilities to come.

 

XPathDocument on Steroids

If you are a .NET XML developer, hopefully you are alreadyfamiliar with and using the XPathNavigator and XPathDocument whenever you can.This model for dealing with XML was introduced in .NET 1.0 as a powerful newalternative to working with the DOM. In .NET 1.X, the XPathDocument is alightweight, read-only storage approach that exposes an XPathNavigator fortraversing and querying the underlying data. You can also obtain anXPathNavigator from an XmlDocument or XmlDataDocument, allowing you to approachwritable stores with the same traversal and query model.

 

In .NET 2.0, XPathDocument has a new and more attractivesibling, XPathDocument2. This new class, in coordination with several other newclasses, gives you the ability to make modifications to the data stored in thedocument, allowing you to make updates and track changes for each node in thetree. The XPathEditor class works as a writable cursor into the data stored inan XPathDocument2 instance, and you can have multiple XPathEditors workingagainst the same document at the same time. The XPathChangeNavigator classgives you a quick and easy way to iterate through only the nodes that havechanged in a document that is being modified. The combination of these classesgives a lighter weight, higher performance approach to navigating, accessing,and updating data stored as an XML InfoSet.

 

In a lot of situations, it is more convenient for anapplication or business layer to retrieve and manipulate data in the form ofXML rather than relational tables, even if that data is originating from arelational data source. In ADO.NET, we have this great model of being able towork with a DataSet that is independent of the data source that populated itand that can keep track of changes so those changes can be used to performupdates to the original or other data sources. To tie the source-independentDataSet with a specific data source for retrievals or updates, we have theSqlDataAdapter to act as the mediator between the two worlds.

 

If you are currently getting XML data out of SQL Server,you have two main options: get it back as an XmlReader from the managed SQLprovider, or get it back as a raw string of XML. In the former case, you thenhave to iterate through the reader to push the results into one of the XMLdocument models available in .NET before you can do any meaningful manipulationof the data. In the latter case, you have to load the string into an XML document,resulting in significant parsing expense.

 

What is really needed, and is part of the new feature setof .NET 2.0, is an XmlAdapter class that functions in a similar fashion to theSqlDataAdapter class. The XmlAdapter in .NET 2.0 will bridge the gap between anXPathDocument2 instance and the SQL Server queries that are used to retrieveand update the underlying data. The XmlAdapter uses a set of XML mapping filesto specify which fields in the SQL Query map to which elements in the XMLschema being retrieved. The mechanisms used for this are very similar to themapping files used for ObjectSpaces, which I mentioned in the ADO.NET 2.0overview, so the skills for working with XmlAdapter mapping files will bemostly transferable to working with the object mapping files in ObjectSpaces.

 

The combination of XPathDocument2 and its associatedclasses and the XmlAdapter really gives you a whole new approach to considerfor working with XML data that I have only scratched the surface of here. Ifyou want to read more, I recommend the book mentioned in the intro, plus getyour hands on the bits as soon as possible and start to play around.

 

Expanding Choices for Server or Middle Tier XML Storage andQuery

A significant portion of data that is retrieved andmanipulated as XML today actually comes from relational data sources. Databasesare made for storing and retrieving data, and they still provide the bestperformance and options for doing that on the server side, even if theapplication intends to manipulate the data as XML. SQL Server Yukon willsupport XML as a native data type for columns, which opens a whole new realm ofpossibilities for offloading some of the XML manipulation and querying from theapplication to the database server. Through the XmlAdapter and XPathDocument2you have a bunch of new options for how that data gets into your applicationand is stored. But what is also needed are some more powerful options forquerying that data as XML.

 

When you work with XML today, the closest equivalent toperforming a SQL query on relational data is performing a node selection on XMLdata using XPath and one of the available document objects or XSLT in yourapplication code. A dedicated language and query processor is really needed formore powerful querying of complex documents, and is in the works. The W3C hasbeen working on the XQuery language specification for a while, and it shouldbecome an approved Recommendation by the time .NET 2.0 and SQL Server Yukonrelease. XQuery provides a more SQL-like language for querying a document orset of documents to retrieve nodes or produce new documents based on theselection. XQuery uses XPath syntax for node selection, so many of yourexisting skills will be transferable. But there is a lot to XQuery beyond justspecifying XPath selection criteria, so standby for yet another XML languagethat you will need to learn to take advantage of the new capabilities.

 

.NET 2.0 and SQL Server Yukon both include newcapabilities to support the XQuery language. On the .NET side, there is anXQueryProcessor class that will allow you to perform XQuery queries against XMLdocuments of the various forms that .NET supports. On the SQL Server side, youwill be able to issue a query against native xml typed fields and XML viewsusing XQuery. Surrounding these capabilities are a number of new classes thatlet you capitalize on the choice to store and query XML data on the client orserver side.

 

.NET 2.0 and SQL Server Yukon will usher in significantnew capabilities for data access on both the relational and XML side of thehouse. The existing capabilities of .NET will still work, your apps are notgoing to break, and you don't have to learn all this new stuff right away. Butif you have felt the pain of developing XML applications that really need amore integrated approach to XML, you will see the benefits of these newcapabilities and probably can't wait to get your hands on them.

 

Brian Noyes is a consultant, trainer, speaker,and writer with IDesign, Inc. (http://www.idesign.net),a .NET focused architecture and design consulting firm. Brian specializes indesigning and building data-driven distributed applications. He has over 12years' experience in programming, engineering, and project management, and is acontributing editor and writer for C#PRO, asp.netPRO, and other publications. Contacthim at mailto:brian.noyes@idesign.net.

 

 

 

 

Add a Comment

There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement




Comments from the DevConnections Community

Join our community of development pros.

Windows problem

I all, I have a problem on my Windows Vista that began afetr the purchase of an external Hard Disk Freecom. A few days afetr the purchase I discon...

Most Recent Posts

GOOGLE LINKS
SPONSORED LINKS
FEATURED LINKS