I'm pretty printing XHTML, and things I've addText()ed don't look
"pretty". Hopefully this stuff will survive being mailed:

...
<body>this is in the wrong place
  <div>
    <span>whatever</span>
  </div>so is this
</body>

A human who coded this document would have put "this is in the wrong
place" on the line after <body>, indented at the same level as the <div>.
"so is this" would be on the line after </div>, indented at the same
level.

Is this a bug, or somehow by design? Or am I just missing some option on
OutputFormat?

Here's the code. Sorry it's mangled, sorry if it breaks some rule, sorry
for my entire life.

public class Test
{
        public static void main(String args[])
                throws IOException
        {
                Document document =
DocumentFactory.getInstance().createDocument();
                document.addDocType("html", "-//W3C//DTD XHTML 1.0
Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";);

                Element bodyElement = document.addElement("body");
                bodyElement.addText("is this in its right place?");

bodyElement.addElement("div").addElement("span").addText("whatever");
                bodyElement.addText("what about this stuff?");

                StringWriter prettyPrintedPage = new StringWriter();
                OutputFormat format = OutputFormat.createPrettyPrint();
                format.setXHTML(true);
                format.setExpandEmptyElements(true);
                format.setIndent("\t");
                HTMLWriter htmlWriter = new HTMLWriter(prettyPrintedPage,
format);
                htmlWriter.write(document);
                htmlWriter.flush();

                System.out.println(prettyPrintedPage);
        }
}

Thanks.


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to