xmlvb.netxmldocumentxmlroot

Can't see the XML root of my document


I'm trying to create a XML Document in VB.Net like this :

<?xml version="1.0" encoding="iso-8859-1"?>
<CDF>
</CDF>

To create this document, I use one of these two codes :

        Dim xd As New XmlDocument()
        Dim xmlPI As XmlProcessingInstruction = xd.CreateProcessingInstruction("xml", "version=""1.0"" encoding=""iso-8859-1""")

        Dim rootNode As XmlElement = xd.CreateElement("CDF")
        xd.InsertBefore(xmlPI, xd.DocumentElement)
        xd.AppendChild(rootNode)

        xd.Save(savePath)

Or :

Dim settings As New XmlWriterSettings()
settings.Indent = True
settings.Encoding = System.Text.Encoding.GetEncoding("ISO-8859-1")

Dim XmlWrt As XmlWriter = XmlWriter.Create(chemin, settings)

With XmlWrt
    .WriteStartDocument()
    .WriteComment("XML " & Date.Now)
    .WriteStartElement("CDF")
    .WriteEndElement()
    .WriteEndDocument()
    .Close()
End With

And all I get is this XML Document :

<?xml version="1.0" encoding="iso-8859-1"?>
<CDF />

Do you know where did I go wrong ? Usually, I manipulate XML Documents that are already created so I don't really know what is the best way to create a XML Doc. I think I've juste forgotten a basic thing but which one ?

Thanks.


Solution

  • This :

    <?xml version="1.0" encoding="iso-8859-1"?>
    <CDF />
    

    is equal to

    <?xml version="1.0" encoding="iso-8859-1"?>
    <CDF>
    </CDF>
    

    When you see node ending in /> means it is a self closing node.