Include a namespace prefix when serializing or deserializing

In order to include a namespace prefix when serializing a class we must add an xmlns property of type XmlNamespaceDeclaration to the class and then add a prefix in the class constructor.

Imports System.Xml.Serialization

    <Serializable(), XmlRoot("navigation", Namespace:="<a href="http://www.tla.com/">http://www.tla.com</a>")>
    Public Class Navigation
        ''' <summary>
        ''' Add a namespace declaration so that we can use a prefix for this class.
        ''' </summary>
        ''' <remarks>
        ''' See <a href="http://msdn.microsoft.com/en-us/library/vstudio/system.xml.serialization.xmlnamespacedeclarationsattribute(v=vs.90).aspx">http://msdn.microsoft.com/en-us/library/vstudio/system.xml.serialization.xmlnamespacedeclarationsattribute(v=vs.90).aspx</a>
        ''' and <a href="http://stackoverflow.com/questions/1254544/how-do-i-specify-xml-serialization-attributes-to-support-namespace-prefixes-duri">http://stackoverflow.com/questions/1254544/how-do-i-specify-xml-serialization-attributes-to-support-namespace-prefixes-duri</a> </remarks>
        <XmlNamespaceDeclarations> Public xmlns As New XmlSerializerNamespaces

        Public Sub New()
            'Add thenamespace prefix
            xmlns.Add("tla", "<a href="http://www.tla.com/">http://www.tla.com</a>")
        End Sub

    End Class

    <XmlType("heading")>
    Public Class Heading

        Public Sub New()
   'Default constructor
        End Sub

        Private myQuestions As List(Of Question)
        ''' <summary>
        ''' Flat sequence of questions.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks>Using the XmlElementAttribute markup renders the list as a flat sequence.</remarks>
        <XmlElementAttribute("question", GetType(Question))>
        Public Property Questions() As List(Of Question)
            Get
                If myQuestions Is Nothing Then myQuestions = New List(Of Question) 'Lazy loading
                Return Me.myQuestions
            End Get
            Set(value As List(Of Question))
                Me.myQuestions = value
            End Set
        End Property
  
    End Class

    <XmlType("question")>
    Public Class Question
 
        <XmlAttribute()> Public Property id() As String
  
    End Class