You can use the XNamespace class to create XML content that uses a namespace. You can find more information about XML namespaces from the article How to use XML Namespaces in XML document. When you want to use XNamespace class you should define an XNamespace object first. Then you should add this XNamespace object to the beginning of the element name every time you create an XElement (or an XAttribute) that you want to place in that namespace. Here’s an example:

C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development: Build applications with C#, .NET Core, Entity Framework Core, ASP.NET Core, and ML.NET using Visual Studio Code, 4th Edition
ASP.NET Core 3 and Angular 9: Full stack web development with .NET Core 3.1 and Angular 9, 3rd Edition
C# in Depth, 4th Edition


Dim Ns as XNamespace = “”

Dim Doc as XDocument = New XDocument(

New XDeclaration(“1.0”, “utf-8”, “yes”),

New XComment(“Created with the XDocument class.”),

New XElement(Ns + “BooksList”,

New XElement(Ns + “Book”,

New  XAttribute(“ISBN-13”, “978-0545139700),

New XAttribute(“Title”, “Harry Potter and the Deathly Hallows”),

New XElement(Ns+“Author”,”J.K. Rowling”),

New XElement(Ns+“Price”,”14.99),

New XElement(Ns+”Available”,”True”)