xml woes

  • Thread starter Thread starter Mike Fellows
  • Start date Start date
M

Mike Fellows

im using the following code to create an xml file


Dim xml_text_writer As New XmlTextWriter("c:\meh.xml", Text.Encoding.UTF8)
xml_text_writer.Formatting = Formatting.Indented
xml_text_writer.Indentation = 4
xml_text_writer.QuoteChar = "'"
xml_text_writer.WriteStartDocument(True)
xml_text_writer.WriteStartElement("Order")
*More XML stuff here
xml_text_writer.WriteEndElement()
xml_text_writer.WriteEndDocument()
xml_text_writer.Flush()
xml_text_writer.Close()

however doing this creates me an xml file located at c:\meh.xml as it
should. however it puts 3 strange charachters at the start of the document
before the initial <

if i open the document in notepad it looks perfect but doesnt function
correctly, if i select all and copy and paste to a new document it works as
it should.

ive been working on this all day and only just thought to do a file compare
using visualdiff and it show the initial line with 3 additional strange
charachters

can anyone give me a pointer of what these are or even better how to get
rid of them

Thanks
 
Mike said:
im using the following code to create an xml file


Dim xml_text_writer As New XmlTextWriter("c:\meh.xml", Text.Encoding.UTF8)
xml_text_writer.Formatting = Formatting.Indented
xml_text_writer.Indentation = 4
xml_text_writer.QuoteChar = "'"
xml_text_writer.WriteStartDocument(True)
xml_text_writer.WriteStartElement("Order")
*More XML stuff here
xml_text_writer.WriteEndElement()
xml_text_writer.WriteEndDocument()
xml_text_writer.Flush()
xml_text_writer.Close()

however doing this creates me an xml file located at c:\meh.xml as it
should. however it puts 3 strange charachters at the start of the document
before the initial <

Those three bytes are the UTF-8 BOM (byte order mark).
If you don't want one then use
new UTF8Encoding(false)
instead of
Text.Encoding.UTF8
where you specify the encoding.
 
Back
Top