472,958 Members | 2,316 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 3263


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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.