473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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.newDocumentBuilder();
Document doc = builder.parse(in.xml);
FileWriter file = new FileWriter(out.xml);

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

XMLInputStreamFactory ifactory =
XMLInputStreamFactory.newInstance();
XMLInputStream istream = ifactory.newInputStream(doc);

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

XMLOutputStreamFactory ofactory =
XMLOutputStreamFactory.newInstance();
XMLOutputStream output =
ofactory.newOutputStream(new PrintWriter(file,true));
output.add(istream);
output.flush();
output.close();

Jul 20 '05 #1
3 3284


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.news.adelphia.net>,
Mike Kennedy <mi**@cosx.com> 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
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...
4
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...
1
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...
5
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...
6
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...
34
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...
2
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...

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.