i recently purchased “A First Look at ADO.NET and System.Xml v2.0” and have finally had some time to start wading through it. it would appear that finally something i have wanted to happen with XML and .Net is going to be implemented in this release, namely that XML will be a fully supported relational data store (in the same ranks as any other RDBMS), and the way that XML data is handled will be almost completely transparent to both the application and the programmer. a little background on my love/hate relationship with XML. i picked up XML pretty early on, long before the .Net betas came out, long before XML's true potential was even dreamed about. this was back when i was living in an ASP/HTML/VB 6 world. i immediately realized the importance of the language, however finding practical applications of it back then was rare, so it kind of fell by the wayside. here we are 4 years later and look at what it has become...in a word, it's THE answer to so many things. i love XML...i think it's the greatest thing since sliced bread.
i absolutely abhor working with it though...i would rather write my own custom binary serialization sinks than manually work with XML documents, which in my opinion is still very much how it is even with .Net. XML in .Net isn't strongly typed, extracting information from it is a real pain (i have a laundry list)...all in all i simply prefer working with RDBMS's for data storage, even though there is so much more flexibility with XML. XML is suffering from a similar quandry that Java is, there are so many bolt ons that it seems just as you learn one, it's either replaced, updated, retired, etc. i simply don't have time to learn each and every new add on that comes out. take SOAP for instance...does anyone out there really code up SOAP messages by hand? this is one subset of XML that .Net does a great job of hiding the specifics of behind the scenes. i've seen SOAP messages, and i can certainly read them, but what is more important to me as a developer is that they do their job, and make mine a little easier.
it's the same with SQL Server...i know about extents and pages and GAM's and that the maximum width of a table is 8092 bytes (minus 32 for overhead)...but in the end i don't really care about that stuff, i just want SQL Server to do it's job quickly and effeciently and not to complain too much when i tell it what to do. this is what i have been wanting for so long with XML, let it sit behind the scenes and make our lives easier with as little manual intervention from my part as possible. which brings me to some of the new features in System.Xml v 2.0...
- XML data storage will be integrated with a range of data sources and will expose a programming model similar to the ADO.NET model we've all grown to love (think DataAdapters and DataSets, but based on the XML model).
- Built in support for XQuery and XML Views. SQL Server has had this type of funcitionality for a while now (distributed query processing over multiple data sources via MSXML 3.0). version 2.0 will initally support distributed query processing over SQL Server and XML documents, with more to come i am sure. “updategrams“ will carry over from the SQL world into XML Views.
- XML Documents will have their own SQL data type (xml) to allow for native storage/querying directly in SQL Server
- The expected performance gains any major release of a technology should have.
- XML content can be edited with change control built in (updates, deletes, inserts will all be tracked giving us something like transactional support in SQL Server).
- XML Views, which is a mapping of relational data types and XML data type defs allowing relational data stored in SQL Server to be viewed and handled as XML.
- an XMLAdapter class that mirrors the DataAdapter class in ADO.NET. this will connect an XML doc to a database via an XML View allowing data to be read and changes persisted to the database via auto gen of SQL statements.
- full built-in support for XQuery via a new XQueryProcessor class (i know i personally didn't care for XPath statements too much, namely the lack of stong typing)
it's good to see that .Net will be on par with the emerging specs coming from the W3C (namely the XML Information Set), XML has changed quite a bit since its' inception in the late 90's. as i've said before, what really has my attention is that XML is becoming a first class data provider in .Net, and as such, working with it is becoming more transparent. this is very important if you look at what XML has become, namely an information integrator between relational data, objects, documents, web services, etc.
as i get further into the book i am sure i will blog more comments...i can already tell that 2.0 will be a huge release for programmers like myself who appreciate the power of XML, but don't particularly enjoy working with it.
Addendum 1/22/2004
One of the problems with the current API-based approach of programming against XML is that these APIs tend to abuse strings to represent the literals of the various (non-string) types such as documents and queries that the API exposes. As an example let us consider how to program against the XML data model using the System.Xml library of .NET. In the code below the SelectNodes method of the XmlDocument class takes a string argument that represents an XPath expression that will be executed against the document instance. Similarly, the SelectSingleNode method on XmlElement takes a string which is an XPath expression intended to select XmlNodes:
int GetTotalByZip(XmlDocument d, int zip) {
int total = 0;
string q = string.Format("orders/order[@zip={0}]/item", zip);
foreach (XmlElement x in d.SelectNodes(q)) {
XmlNode price = x.SelectSingleNode("price");
XmlNode qty = x.SelectSingleNode("quantity");
int p = Decimal.Parse(price.InnerText);
int q = Decimal.Parse(qty.InnerText);
total += p*q;
}
return total;
}Using strings to represent XPath programs is not only pretty clumsy (i.e. using String.Format to pass parameters from C# to XPath) but also annihilates all possibilities for static checking. Perhaps more importantly passing strings that represent programs is often a security risk ("script code injection"). Also note that because result values are also passed as strings, XmlDocument programming involves a lot of expensive string to type coercions.



No comments yet