473,769 Members | 4,167 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 11391
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
3255
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 class, the output is:
1
2458
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
2
22746
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 a stream then reload it the stream. However If I do this I have suddenly lost the root element ...
5
3610
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 things? Trying to figure out how to change and save the xmlDocument. It I put a button OUTSIDE of the...
5
3620
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 wondering what is the best way to do this?
4
4180
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 the 'r' prefix don't, which is correct. Is there any way to stop the XmlNode/XmlWriter from...
0
1990
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
2119
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 using XmlDocument.Save(); That is, the input file is not XML, and the Load() method is obviously
1
7743
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 another process." The following is the test program public class XmlTest
0
9579
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10035
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8862
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7396
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5436
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3948
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3551
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2810
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.