Wriju's BLOG

.NET, Cloud and everything

VB.NET 9.0: XML Literal

This is the one feature which can make VB.NET developers feel better than C# folks. I have seen people complaining about MS saying that MS has done lot for C# but not equally for VB.NET. One of the biggest was Refractoring. There are so many such. But this feature is just “SPELLBOUND” when I first experienced it.


Today, people handle XML from .NET in many ways. One approach is they simply concatenate the string to create XML string and end up writing to a file. Another is they generate DataSet/DataTable and uses WriteXml() method to write Xml to a file. More sophisticated way is to use System.Xml namespace and build Xml step by step in strongly typed manner. But this one is something which is simply amazing.


In Visual Studio 2008 if you write something using System.Xml.Linq


Dim _xml2 = New XElement(“ProcessList”, _

                New XElement(“Process”, _

                    New XAttribute(“ThreadCount”, “2”), “Some Process”))


You can also write,


Dim _xml = <Processes>

               <Process ThreadCount=2>Some Name</Process>




These two statements are identical. Second one looks like an ASP.NET page but it is actually XElement object. But the feeling you will get as if you are writing an Xml in a XML Editor.


Coolest ever.

Today I found an article with very detailed discussion http://geekswithblogs.net/Silverlight2/archive/2008/03/30/xml-literals-and-embedded-expressions.aspx