Preserving whitespaces in dom4j.

K

Kimos

Hi, all.

I'm creating 'struts-config.xml' generator with dom4j.
The process is..
1. Read 'struts-config.xml' and parse with dom4j.
2. Add some elements to that.
3. Write it to 'struts-config.xml'.

I've tested like followings.

SAXReader reader = new SAXReader();
reader.setStripWhitespaceText(false);
reader.setIgnoreComments(false);
Document doc = reader.read(new File("struts-config.xml"));
System.out.println(doc.asXML());

When 'struts-config.xml' has no DTD declaration,
This code works very well.
All white spaces are preserved and xml is exactly same to original.

But when 'struts-config.xml' has DTD declaration,
the white spaces are removed.

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

How can I solve this problem?

I use JDK1.4.2 and dom4j 1.4.

Thanks in advance.
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top