Preserving whitespaces in dom4j.

Discussion in 'Java' started by Kimos, Apr 14, 2004.

  1. Kimos

    Kimos Guest

    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.
     
    Kimos, Apr 14, 2004
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.