xml problem

sek

Member
Joined
Jul 2, 2009
Messages
10
Programming Experience
Beginner
Hi,

I am getting one problem with xml file after generation.
<?xml version="1.0" encoding="utf-8"?>

some junk characters are coming before <?xml.... tag like above.

its happening when i mentioned encoding attribute.

here below is my code to set the encoding type.

Dim xw As XmlTextWriter = Nothing
xw = New XmlTextWriter(filename, System.Text.Encoding.UTF8)
xw.Formatting = Formatting.Indented
xw.WriteStartDocument()
xw.WriteDocType("cXML", Nothing, "http://xml.cxml.org/schemas/cXML/1.2.020/InvoiceDetail.dtd", Nothing)


i need encoding attribute compulsary in <?xml ... tag.

how to avoid these junk characters???

Thanks in advance.
 
Those junk-characters are normally appearing within an UTF-8 encoded file...at least I've seen them there some times. And since you're writing an UTF-8 encoded file it's most properly that one...

Bobby
 
It appears you're seeing the byte order mark to tell systems whether to use little-endian or Big-Endian encoding. You can turn this off by setting the encoderShouldEmitUTF8Identifier property to False.

A quick test using this looked right.

VB.NET:
		Dim xw As XmlTextWriter = Nothing
		Dim enc As New System.Text.UTF8Encoding(False)
		xw = New XmlTextWriter("C:\Temp\bom.xml", enc)
		xw.Formatting = Formatting.Indented
		xw.WriteStartDocument()
		xw.WriteDocType("cXML", Nothing, "http://xml.cxml.org/schemas/cXML/1.2.020/InvoiceDetail.dtd", Nothing)
 
Back
Top