XML Java Questions

D

D-Dog

Hi,
I'm just getting started with XML and have been trying to write out
my xml document to a file. The data itself looks correct, but I have
two formatting questions:

1. Each tag has a 'word:' appended to the beginning of it. For
example:

<word:Comment> ............................. </word:Comment>

How do I remove the 'word:' from the front of each tag? It's like that
for all of them.

2. Try as I might, I have not been able to get indenting to work.
I've searched the net in vain, and all tell me to set the following
properties on my transformer:

transformer.setOutputPropety(OutputKeys.INDENT,"yes");
transformer.setOutputPropety("{http://xml.apache.org/xslt}indent-amount","4");

Unfortunately, all of the tags continue to be lined up along the left
side with no indenting. Am I missing something? I snipped out the
rest of the code that sets up the transformer so as not to clutter this
post, but if you need more info, I will repost it.

Thank you very much for any help you can provide.

Dennis
 
D

D-Dog

Followup:

After some more research, I located a bug report against java 1.5.0_04
that had to do with the indenting problem. There were two things that
needed to be done to workaround:

1. Wrap the output stream with a writer OutputStreamWriter , so the
StreamResult would look something like:

File file = new File(filename);
Result result = new StreamResult(new OutputStreamWriter(new
FileOutputStream(file),"utf-8"));

Just sending in a File object directly into StreamResult caused
problems.

2. Set the transformerFactory attribute to something like:

transformFac.setAttribute("indent-number", new Integer(2));

After both of these are setup, the previous two lines remain unchanged:

transformer.setOutputProperty(OutputKeys.INDENT,"yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","4");


Still looking for an answer to one of the original problems: ie.
<word:/Comment>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top