473,796 Members | 2,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

encoding="UTF-8" being deleted when generating file from DOM

I have an XML Snippet <?xml version="1.0" encoding="UTF-8"?> and when I
convert the entire xml file to a DOM and then generate a new file from
the DOM, results in <?xml version="1.0"?> .
Any thoughts?

My sample code snippet is:

DocumentBuilder builder = factory.newDocu mentBuilder();
Document doc = builder.parse(i n.xml);
FileWriter file = new FileWriter(out. xml);

// Create an XMLInputStream using the DOM we've changed

XMLInputStreamF actory ifactory =
XMLInputStreamF actory.newInsta nce();
XMLInputStream istream = ifactory.newInp utStream(doc);

// Create an XMLOutputStream to generate a new output file
// using the file created earlier

XMLOutputStream Factory ofactory =
XMLOutputStream Factory.newInst ance();
XMLOutputStream output =
ofactory.newOut putStream(new PrintWriter(fil e,true));
output.add(istr eam);
output.flush();
output.close();

Jul 20 '05 #1
3 3320


Mike Kennedy wrote:
I have an XML Snippet <?xml version="1.0" encoding="UTF-8"?> and when I
convert the entire xml file to a DOM and then generate a new file from
the DOM, results in <?xml version="1.0"?> .
Any thoughts?


That is allowed, encoding UTF-8 or UTF-16 has to recognized by any XML
parser without the encoding being specified.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Martin, thanks. But I'm wondering why the encoding="UTF-8" is being
stripped when the DOM is used to regenerate the xml. It's there in the
original xml file and then when I generate a new xml doc from the DOM,
it's not there.

--Mike

Martin Honnen wrote:


Mike Kennedy wrote:
I have an XML Snippet <?xml version="1.0" encoding="UTF-8"?> and when
I convert the entire xml file to a DOM and then generate a new file
from the DOM, results in <?xml version="1.0"?> .
Any thoughts?

That is allowed, encoding UTF-8 or UTF-16 has to recognized by any XML
parser without the encoding being specified.


Jul 20 '05 #3
In article <ZK************ ******@news2.ne ws.adelphia.net >,
Mike Kennedy <mi**@cosx.co m> wrote:
Martin, thanks. But I'm wondering why the encoding="UTF-8" is being
stripped when the DOM is used to regenerate the xml.


Because it makes no difference to the document. Just as if you had
six spaces between attributes in the input, there's no reason to
suppose that there will be six spaces in the output.

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!
Jul 20 '05 #4

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

Similar topics

5
5291
by: F. GEIGER | last post by:
Dear all, never thought that this could happen to me: I accidently deleted a ..py-file before I could back it up :-( However, the .pyc file is still there. Can I restore the .py file from the .pyc file somehow? Many thanks in advance Franz GEIGER
4
3732
by: Doug R | last post by:
Hello, I could use a little help from you Gurus out there. I have an aplication that watches a directory and detects when a PGP encrypted file lands in the directory and starts a process that decrypts it and parses the resulting contents. I am using the FileSystemWatcher's Created event to detect when the file arrives. The problem I have is that these files are large(5-10 megs) and they are being transfered over a limited pipe. I...
1
239
by: TT (Tom Tempelaere) | last post by:
Hi people We have a strange (unexpected) problem with our application configuration file. When we place the config file in the same directory as the assembly it is deleted when we build our project. The name of the config file is "App.exe.config" with App the name of our application (the executable is App.exe) We tested the same thing in another project (which is totally different), and there the file is _not_ deleted. However, the file is...
5
13713
by: Trowa | last post by:
Hi, I'm trying to use FileSystemWatcher to determine when a new file has been added to a directory. However, after the file has been added, I need to process the file. This results in a problem if the file is large and takes time to copy, as the events appear to get received before the copy is finished. I've tried listening to the Created event, as well as the Changed event (which gets fired multiple times) based on the last write...
6
13732
by: Chad Crowder | last post by:
Getting the following error on my production server whether the file exists or not: "System.IO.IOException: Cannot create a file when that file already exists." Here's the code generating the error (seems to be happening when I try creating a directory) If dirmgr.Exists("s:\blah\" & txt_name.Text) Then lblerror.Text = lblerror.Text & "Unable to build physical path. " &
34
2816
by: Ross Reyes | last post by:
HI - Sorry for maybe a too simple a question but I googled and also checked my reference O'Reilly Learning Python book and I did not find a satisfactory answer. When I use readlines, what happens if the number of lines is huge? I have a very big file (4GB) I want to read in, but I'm sure there must be some limitation to readlines and I'd like to know how it is handled by python. I am using it like this:
2
2320
by: Shoaib Ahmed | last post by:
I have deleted the .MDF file accidently. I have never created a backup early on. Can any body tell me, where this MDF is gone after delete? I am using SQL Server 2000 Enterprise Manager.
0
9685
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
9531
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10187
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
6795
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5446
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...
1
4120
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
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
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.