473,573 Members | 4,503 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Omit BOM in XMLDocument.sav e

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.x ml")
'change the xml file
objXMLDocument. Save("C:\test.x ml")

Nov 12 '05 #1
6 11366
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.x ml")
'change the xml file
objXMLDocument. Save("C:\test.x ml")

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(fa lse) 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(fa lse) 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!P LEASEtkachenko. com> wrote in message
news:e7******** ******@TK2MSFTN GP10.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(fa lse) 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(fa lse));
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.XmlD ocument
d.LoadXml("<roo t><child/></root>")
Dim tw As New IO.StreamWriter ("C:\test.xm l", False, New
System.Text.UTF 8Encoding(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!P LEASEtkachenko. com> wrote in message
news:e7******** ******@TK2MSFTN GP10.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(fa lse) constructor.

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


Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3246
by: Francesc Guim Bernat | last post by:
Dear Colleagues, i'm developing a C++ .NET based application that works with System.Xml library. My problem appears when i try to save a document througt XmlDocument->Save method, because it seems to add some strange characters at the beginning of the saved XML document. For instance, if first i print the document throught System::Console...
1
2446
by: Francesc Guim Bernat | last post by:
Dear Colleagues, i'm developing a C++ .NET based application that works with System.Xml library. My problem appears when i try to save a document througt XmlDocument->Save method, because it seems to add some strange characters at the beginning of the saved XML document. For instance, if first i print the document throught...
2
22512
by: Tom Pearson | last post by:
I have created an XmlDocument and can see that this is correctly formed and has a root element If I Save the doc to a file and reload it all works o If I dump the doc to a stream, again using the Save method, and write this to a file I can then reload this correctly. However since I have no need to write the data to file I want to save it as...
5
3592
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an instruction document (not data based) - same as using an xml web control. The resulting html is on the client? but what about the server side of...
5
3606
by: Jack Fox | last post by:
I'm still new to Xml, but finding it very useful. Conceptually what I want to do is compress an XmlDocument, save it to SQL Server as image data, read it back and restore it to an XmlDocument. I'm a bit bewildered by the choices available (XmlSerialization, XmlWriter, Xml on SQL Server) and do not have any experience with them, so I was...
4
4172
by: David Grogan | last post by:
Hi, 2 questions.... 1. I'm parsing an XHTML document that contains both the default namespace (xmlns="http://www.w3.org/1999/xhtml") and a custom one (xmlns:r="...") - both of these being attributes of <html>. When I then insert new XmlNodes into the DOM the HTML tags all end up getting an unnecesarry 'xmlns' attribute added, elements with...
0
1978
by: Pierre | last post by:
Hi, I'm trying to select specific nodes from a XmlDocument filled with a serialized object and to insert these nodes into another XmlDocument. The object is well serialized (see below). From a normal XmlDoc to another I don't have any issue, the nodes are copied but then with this serialized object it doesn't seem to work. The C# code:
1
2107
by: Gustaf | last post by:
I have a class that contains a certain kind of XML document. The input file is *not* an XmlDocument, but when loaded, I want it to work like the XmlDocument class, like: MyDocument doc = new MyDocument(); doc.Load("input.txt"); // doc is now an XmlDocument // Query or modify the XmlDocument as usual doc.Save("output.xml"); // doc saved...
1
7709
by: liuhengyi | last post by:
Hi, I have a test program that creates 5 threads and each thread uses XmlDocument.Save(filename) to save a Xml dom to a file. I have put the lock statement around the Save to prevent from concurrently updating. However I'm still seeing "System.IO.IOException: The process cannot access the file "c:\file1.xml" because it is being used by...
0
7741
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8165
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7730
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5252
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
984
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.