[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

write xml file

Posted on 2006-04-10
10
Medium Priority
?
381 Views
Last Modified: 2012-05-05
to write a the new dom to a file use:

http://javaalmanac.com/egs/javax.xml.transform/WriteDom.html

but how can I write file with encoding such as "UTF-8"?
0
Comment
Question by:keepworking
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 16422706
it'll be utf8 by default i think
0
 

Author Comment

by:keepworking
ID: 16422937
thanks objects:

when I use the following method to create and write data to xml file, it works for English data, but when I use it to write data in German or Ascian language, it doesn't work, error:java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence.

----------------------------------------------------------------------------------------------
to create a new dom

http://javaalmanac.com/egs/javax.xml.parsers/CreateDom.html?l=rel

to add nodes to new doc

http://javaalmanac.com/egs/org.w3c.dom/AddNode.html

to write a the new dom to a file use:

http://javaalmanac.com/egs/javax.xml.transform/WriteDom.html
--------------------------------------------------------------------------------------------------------
0
 
LVL 92

Expert Comment

by:objects
ID: 16423019
try:

Properties props = new Properties();
props.setProperty("encoding", "UTF-8");
xformer.setOutputProperties(props);
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:keepworking
ID: 16423076
import java.util.Properties;

I did, same error.

thanks
0
 
LVL 9

Assisted Solution

by:Manikandan Thiagarajan
Manikandan Thiagarajan earned 500 total points
ID: 16423613
Properties props = new Properties();
props.setProperty("characterEncoding", "utf-8");

try this one
0
 
LVL 2

Assisted Solution

by:borislavmarkov
borislavmarkov earned 500 total points
ID: 16424096
I suggest to add your strings to a Vector and see how they will be serialized with java XML serializator.
With JDK1.4 you can do:

       XMLEncoder enc = new XMLEncoder(new FileOutputStream("d:\\out.xml"));

        Vector v= new Vector();
        v.add("\u00e4");
        v.add("\u0333");
        enc.writeObject(v);
        enc.flush();
        System.out.println("v = " + v);

Then take the result and see it.
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 500 total points
ID: 16425106
Try


Result result = new StreamResult(new OutputStreamWriter(new FileOutputStream("x.xml"), "UTF-8"));
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question