472,127 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

Omit BOM in XMLDocument.save

How do I get the following code to not put the Unicode BOM in the file. If
the attribute ecoding=UTF-8 exists, it will put the BOM in the file.

objXMLDocument = New XmlDocument

objXMLDocument.Load("C:\test.xml")
'change the xml file
objXMLDocument.Save("C:\test.xml")

Nov 12 '05 #1
6 11201
Hi Scot

If you are persisting as UTF-8, then of course you will have the byte order
mark. Could you explain what the problem is with it?

One thing you could do is use an encoding like ISO-8859-1 if you don't want
the BOM.

Nigel Armstrong

"Scot" wrote:
How do I get the following code to not put the Unicode BOM in the file. If
the attribute ecoding=UTF-8 exists, it will put the BOM in the file.

objXMLDocument = New XmlDocument

objXMLDocument.Load("C:\test.xml")
'change the xml file
objXMLDocument.Save("C:\test.xml")

Nov 12 '05 #2
Nigel Armstrong wrote:
If you are persisting as UTF-8, then of course you will have the byte order
mark. Could you explain what the problem is with it?

One thing you could do is use an encoding like ISO-8859-1 if you don't want
the BOM.


Btw, in UTF-8 BOM is actually optional. One can supress BOM's output
using new UTF8Encoding(false) constructor.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #3
Oleg

Thanks for the info. Very useful.

Nigel Armstrong

"Oleg Tkachenko [MVP]" wrote:
Nigel Armstrong wrote:
If you are persisting as UTF-8, then of course you will have the byte order
mark. Could you explain what the problem is with it?

One thing you could do is use an encoding like ISO-8859-1 if you don't want
the BOM.


Btw, in UTF-8 BOM is actually optional. One can supress BOM's output
using new UTF8Encoding(false) constructor.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #4
The destination for my XML file is a company that uses Java and they are
having troubles with the BOM.

Forgive my ignorance, but could you explain how to use that object with the
code I provided. I don't really understand how to use that object with the
xmldocument.

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:e7**************@TK2MSFTNGP10.phx.gbl...
Nigel Armstrong wrote:
If you are persisting as UTF-8, then of course you will have the byte order mark. Could you explain what the problem is with it?

One thing you could do is use an encoding like ISO-8859-1 if you don't want the BOM.


Btw, in UTF-8 BOM is actually optional. One can supress BOM's output
using new UTF8Encoding(false) constructor.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #5
Scot wrote:
The destination for my XML file is a company that uses Java and they are
having troubles with the BOM.

Forgive my ignorance, but could you explain how to use that object with the
code I provided. I don't really understand how to use that object with the
xmldocument.


Something like

XmlTextWriter w =
new XmlTextWriter("C:\test.xml", new UTF8Encoding(false));
objXMLDocument.Save(w);
w.Close();

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #6
Hi Scot

This sample illustrates the point that Oleg was making:

HTH

Nigel Armstrong

Dim d As New System.Xml.XmlDocument
d.LoadXml("<root><child/></root>")
Dim tw As New IO.StreamWriter("C:\test.xml", False, New
System.Text.UTF8Encoding(False))
d.Save(tw)
tw.Close()

"Scot" wrote:
The destination for my XML file is a company that uses Java and they are
having troubles with the BOM.

Forgive my ignorance, but could you explain how to use that object with the
code I provided. I don't really understand how to use that object with the
xmldocument.

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:e7**************@TK2MSFTNGP10.phx.gbl...
Nigel Armstrong wrote:
If you are persisting as UTF-8, then of course you will have the byte order mark. Could you explain what the problem is with it?

One thing you could do is use an encoding like ISO-8859-1 if you don't want the BOM.


Btw, in UTF-8 BOM is actually optional. One can supress BOM's output
using new UTF8Encoding(false) constructor.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com


Nov 12 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Francesc Guim Bernat | last post: by
1 post views Thread by Francesc Guim Bernat | last post: by
2 posts views Thread by Tom Pearson | last post: by
5 posts views Thread by Jack Fox | last post: by
1 post views Thread by Gustaf | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.