VB 9.0 Xml features – latest update

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">

            <Name>Erik Meijer</Name>






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:

Dim Person = <Person Dept="SQL Server">

            <Name>Erik Meijer</Name>





Person.<Name>.Value = "Mike Champion"



The output is:

Erik Meijer

SQL Server

Mike Champion


We plan to include these changes in the next CTP. As always feedback is welcome.


Avner Aharoni

Comments (17)

  1. Bill McCarthy asked me to post Xml axis members example using namespaces. So I updated the sample from…

  2. Why use the "<", ">" and "@" conventions?

    I’ve been playing with the XSD.EXE utility that has the /C option (generates managed classes from schemas/XML instances) and the classes it generates seems to work quite nicely despite the fact that it makes use of properties to represent elements/attributes.

  3. Geoff says:

    Is it possible to make "value" the default member so instead of writing:



    you can optionally write:



  4. Erik Meijer says:

    To: Johan Myburg

    If you have an XSD and it happens to be one that XSD.exe can handle then surely there is no need to mess around with XML. The less I have to deal with XML explicitely the better!


    However, the scenario that we are trying to enable is when you do care about XML, when you have no schema at all, or when you have a document centric schema.


    Makes sense?

  5. Erik Meijer says:

    Hi Geoff,


    Are you a VB6 guy 🙂


    Deafult properties without parameters are extremely nasty, as section section 9.7.4 of the Visual Basic 8 spec says:


    Because a default property with no index parameters would cause an ambiguous situation when assigning instances of the containing class, default properties must have index parameters.


    Hope this helps!



  6. Geoff says:


    No I’m not a vb6 guy(ouch), but I’m ashamed to say that I’ve only had a chance to memorize up to 9.7.3 of the VB8 spec to this point :p

    While I did recognize the possible ambiguity when posting the suggestion, I figured that with all the compiler magic happening to get his done anyway (inferred types/late binding and who knows what else) that this ambiguity could be resolved somehow.  As they say, there are always exceptions to the rule.

    In any event, im glad they decided to take your head out of "The Box" (yes, that is a reference to VBTV) to help out with the new features in VB9 – xml literals and the other dynamic  typing features you are working on, IMHO, will make VB9 a monster to be reckoned with.


  7. Jonathan Allen says:

    It looks like we now have 3 distinct patterns for accessing members.

    Pattern 1: variable char member




    Pattern 2: variable open_char member close_char


    Pattern 3: variable open_char_1 open_char_2 member close_char



    I don’t like the dot+angle-bracket+angle-bracket syntax. The only place we are using something similar is the late-bound function calls where the function name is only known at run time.

    I would prefer that you picked something that matched one of the first 2 patterns; either dropping the dot before the angle bracket, or by using another character.




  8. XmlTeam says:

    Hi Joshua, long time no seen, I am glad to see that you are following our VB Xml features!

    Our design goal is to make the Xml axis members experience as close as possible to regular CLR members, so users have a very easy learning curve. Our preference was to avoid the special syntax for Xml members, however because of the ambiguity and double colon problems we had to choose special syntax.

    We want users to continue using the most intuitive way to access members, which is the “Dot”. Our plan is to add the known Xml members to the intellisense drop down so that the Xml members and the new syntax are easily discoverable. We hope that the new syntax will contribute the intellisense experience since the Xml members will show up in the same area due to the sorting of the intellisense members.


  9. Dave McMahon says:

    Hi Avner,

    My URL is a general blog on the Visual Studio 9.0 Overview with some comments on the XML features.  Hope you find some of it useful and your feedback is welcome


    Dave Mc

  10. @ Head says:

    Erik Meijer and Brian Beckman have put out a new paper on XML and LINQ and VB.&#160; It’s a good short read…

  11. Antimail says:

    Latest LINQ CTP released for download.

    The list of goodies is here:

    What’s new?

    Enhanced DLinq…

  12. I hope you already had the chance to download the latest LINQ CTP. This CTP contains important improvements…

  13. Un nouveau CTP de LINQ (VB et C#) a &#233;t&#233; publi&#233; la semaine derni&#232;re. LINQ a &#233;t&#233; rendu public lors du PDC…

  14. “ Typed XML programmer, where have you have been in the last few weeks? ” This series of blog posts has

  15. By Amanda Silver I just wanted to let you know that we’re working furiously on turning the VB9 features

Skip to main content