Out of the Angle Brackets
For those who do not know me yet, my name is Avner Aharoni and I am a program manager in the WebData Xml team. I am working on the VB 9.0 Xml features that I believe will make VB the most productive language with which to program Xml.
We heard from many people who tried the VB 9.0 January preview that the late-bound properties we added to XLinq objects in VB 9.0 are confusing. One reason is that it is hard to know if a certain property name refers to the underlying object property or to the elements with that name, which makes writing and reading code harder. In addition, the way we chose to disambiguate between XLinq object properties and the Xml late bound properties by calling the “Element” method was unsatisfactory, since the developer needs extra knowledge to use this feature, and needs to know which properties exist on the XLinq objects to get it right. Consider the following example:
Dim Person = <Person Dept="SQL Server">
The output is:
Person 'This is the name of the person element
<Name>Erik Meijer</Name> 'This is the "Name" element itself
To fix this issue we introduced a new syntax for these late-bound properties. Angle brackets now wrap the Xml member name so it is clear that the name refers to the elements with that name. For example Person.<Name> returns the elements called Name in the above document. To unify the syntax we are also using angle brackets for the Descendants method. For example Person...<Name> returns all the descendants of the Person element with the element name “Name”. You can read more about it in Erik Meijer's post on lambda-the-ultimate . As a very nice side effect, we do not require any more double-colon for the namespace prefix, since the Xml name is enclosed in the angle brackets. We also renamed the feature to “Xml axis members” or just “axis members” to make it clearer.
In addition to this change in the axis members’ syntax, we are planning to change the binding of the Xml attribute member “@” to XLinq’s “Attributes” method as opposed to the “Attribute” method as the compiler did in the January CTP. As a result, all of the axis members now return IEnumerable(Of XElement) or IEnumerable(Of XAttribute). This aspect is important since we have added a .Value extension property on these IEnumerables that will get the first object in the enumerable (either XElement or XAttribute) and call the underlying .Value property on that object. If the result is an empty collection, we return Nothing. The following example illustrates how all these changes come together to provide a very nice programming interface with XLinq objects:
Person.<Name>.Value = "Mike Champion"
We plan to include these changes in the next CTP. As always feedback is welcome.
“ Typed XML programmer, where have you have been in the last few weeks? ” This series of blog posts has
By Amanda Silver I just wanted to let you know that we’re working furiously on turning the VB9 features