How to use XMLTextWriter with XML Namespaces in VB.NET

You can use the XMLTextWriter class to create XML content that uses a namespace. The code lies used to illustrate the idea are taken from the article How to use XMLTextWriter to create an XML document in VB.NET, and you can find more information about XML namespaces from the article How to use XML Namespaces in XML document.

C# in Depth, 3rd EditionManaged Windows VPS Hosting

The XmlTextWriter includes an overloaded version of the WriteStartElement() method that accepts a namespace URI. Here’s how it works:

Dim Ns as String = “”


W.WriteStartElement(“BooksList”, Ns)

‘ Write the first book.

W.WriteStartElement(“Book” , Ns)