Search code examples
.netvb.netxmlwriter

Why does every XML file I create with .net's XMLWriter fail W3C validation?


The W3C validator tells me

Line 256, Column 12: non SGML character number 0

Both errors occur at the very end of the file.

Here is my abbreviated code:

            dim writer as XmlWriter
            dim xmlSettings as new XmlWriterSettings
            xmlSettings.Encoding = Encoding.UTF8
            xmlSettings.CheckCharacters = true
            xmlSettings.ConformanceLevel = ConformanceLevel.Document
            xmlSettings.Indent = true

            writer = XmlWriter.Create("D:\somedata.xml", xmlSettings)

            writer.WriteStartDocument()
            writer.WriteStartElement("listings")

            while invReader.Read( )

                writer.WriteStartElement("listing")

                'a bunch of .writeElementString calls here

                writer.WriteEndElement()
            end while       
            writer.WriteEndElement()
            writer.WriteEndDocument()
            writer.Close()

Solution

  • It looks like you are trying to write out a character that the validator thinks is illegal

    Check out this link for an example of your error:

    http://forums.htmlhelp.com/index.php?showtopic=11270