Removing duplicate namespaces in XML Literals (Shyam Namboodiripad)

A common problem that one often runs into with XML literals and the LINQ to XML API is duplicate XML namespaces. Consider the following example. The code imports a default XML namespace – “hello”. Code: Imports <xmlns=“hello“> Module Module1     Sub Main()         Dim x = <A>                     <%= <B></B> %>                 </A>         Console.WriteLine(“x:”)… Read more

VB XML Cookbook, Recipe 7: Enumerating Large XML Files (Doug Rothaus)

VB XML Cookbook, Recipe 7: Enumerating Large XML Files (Doug Rothaus) It’s been a while since I wrote one of these XML cookbook entries. Here’s some info on a common problem: Really big XML files. I’m going to show you two things in this recipe. The first is a tip on reading very large XML… Read more

Using HTML entities in XML Literals (Avner Aharoni)

One of the common use-cases of XML literals is creating HTML. However, HTML entities cannot be used in XML literals since LINQ to XML directly supports only the Data type definitions (DTD) defined in the XML 1.0 spec. You can read more about it here. The workaround is to use the Unicode representation of the… Read more

Editing XML Literals Embedded Expressions in Visual Basic 2010 (Avner Aharoni)

The implicit line continuation feature in Visual Basic 2010 provided an opportunity to improve the code editing experience in XML literals embedded expressions. In Visual Studio 2008, pressing Enter inside an embedded expression would result in the cursor being positioned to the left of the end embedded expression tag. In Visual Studio 2010, pressing Enter… Read more

Fun With Dynamic Objects (Doug Rothaus)

A while back, I remember being asked if there was a simple way to expose a source XML document as an object with properties. That is, if the root XML element had a child element <Name>Doug</Name>, then the object would have a Name property that was a string and returned “Doug”. The catch was that… Read more