LINQ to XML Changes in Orcas Beta1
[updated with the public download location and resolution of the "XNamespace.Blank" issue]
As S. Somasegar announced, Orcas Beta 1 is ready to ship and is available for download. There are some new (and renewed) features in LINQ to XML that you can check out in this release, and some minor changes introduced in response to reviews and comments:
The "renewed" feature is XStreamingElement. As we noted previously, it was removed after the May 2006 CTP to keep the slate clean for possibly incompatible changes to support streaming. At the end of the discussion we concluded that XStreamingElement is necessary and that the original design made sense.
We added LoadOptions and SaveOptions flags on the Load() and Save() methods instead of the booleans used in previous releases. There are not very many options supported at the moment, mainly PreserveWhitespace on load and DisableFormatting on save. This allows us to add more options as demand warrants without adding new overloads.
We did reverse one previously discussed decision and added the capability to keep track of the line number in the XML data source from which each node was parsed. This is a fairly expensive option, since it creates an annotation on every XObject subclass in the tree. There is also a LoadOption to preserve the base URI of a subtree that is loaded. Both options are specified in the LoadFlags.
The somewhat cosmetic changes are:
- XName.NamespaceUri was renamed to XName.NamespaceName, because namespace names don't have the exact same semantics as URIs and we pass them as strings rather than Uri objects.
- The "No Namespace Namespace" now lives in XNamespace.Blank rather than XNamespace.Xmlns. We determined that this improves usability. [Update: Apparently not; after hearing your feedback we decided to change it to "XNamespace.None". "NoNamespace" is probably a bit more accurate, but redundant. "Empty" isn't quite right because it implies that there are no names in an "empty" namespace, but there usually are. This change will be available in Beta2 in a few months.]
- XName now implements ISerializable (but this is the only LINQ to XML class that does!). This is because XName has proven to be convenient in various applications that must deal with XML global name - local name pairs conveniently yet efficiently even if they do not require the rest of the LINQ to XML functionality, and supporting ISerializable allows calls with XName arguments to be remotable.
- XElement and XDocument support IXmlSerializable, to make LINQ to XML a convenient API for working with the XML sent to or received from seb services calls.
There is one somewhat hidden change: Save() is no longer implemented with a recursive algorithm, which means that you will not get an unrecoverable stack overflow exception when serializing a very deeply nested XML document.
The planned LINQ to XML work is very close to being done, and there won't be much in the way of new LINQ to XML features new in Orcas Beta 2 in a few months. The work underway focuses on a) performance optimization (but LINQ to XML is already measurably faster than DOM for almost all of the scenarios in our test suite), b) server-side security hardening (to both allow DTDs to be processed by default yet mitigate well known DTD-based denial of service attacks) and c) a better story for binding LINQ to XML objects to WPF GUI controls.
Please try out this API with real data and real application requirements, and let us know of any issues. There is time and talent available to respond to customer needs, so make them known! The final Orcas RTM schedule is not public, but we're definitely approaching the endgame, so the sooner the LINQ to XML team gets feedback, the more likely it is to be reflected in the final product.
Comments
Anonymous
April 23, 2007
"The default namespace declaration now lives in XNamespace.Blank rather than XNamespace.Xmlns. We determined that this improves usability. " Why not in XNamespace.Default? "Blank" is definitely not what I would look for.Anonymous
April 23, 2007
Thanks for the comment. I don't think "Default" is the right word because that has a different meaning in the XML namespaces spec, but we will reconsider "Blank". What about XNamespace.Empty ?Anonymous
April 24, 2007
"Empty" namespaces would be namespaces that have no members, by my thinking. http://www.w3.org/TR/REC-xml-names/ .. The W3C spec seems to use "Default". Is it possible you're thinking of the difference between "xmlns" (the default namespace attribute) and "http://blah" (the namespace name)? If so, perhaps DefaultName would work, to distinguish the two?Anonymous
April 25, 2007
Now that Visual Studio Orcas Beta 1 is available, there are several great new posts about Orcas in generalAnonymous
April 25, 2007
Now that Visual Studio Orcas Beta 1 is available, there are several great new posts about Orcas in generalAnonymous
May 01, 2007
After an enjoyable and extremely educational 2 1/2 years on the core XML team in SQL Data Programmability