[jdom-interest] Turning of entity expansion

ion vnhu38f93 at subdimension.com
Tue Sep 3 23:21:57 PDT 2002

Here is an example, consider the following simple program:

import java.io.*; import org.jdom.*;
import org.jdom.input.*; import org.jdom.output.*;
public class test {
   public static void main(String args[]) {
      Document doc = new Document(new Element("html"));
      DocType docType = new DocType("html", "-//W3C//DTD XHTML 1.0

      Element root = doc.getRootElement();
      Element head = new Element("head");
      head.addContent(new Element("title").setText("Blah"));
      Element body = new Element("body");
      body.addContent(new Element("p").setText("" © blah blah"));
      String newItem = args[0];
      XMLOutputter outputter = new XMLOutputter("  ", true);
      try {
         outputter.output(doc, new FileWriter((newItem+".html")));
      } catch(Exception e) { System.err.println(e.getMessage());}

(I apologise for the crapness of it, I quickly created it)
Which is some program, that could perhaps be used to output
templates for some html page, or more realistically include input
from some other XML file. Executing this like this:

java test test

produces the output file test.html:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    <p>&amp;quot; &amp;#169; blah blah</p>

> JDOM at all.  They are expanded by the parser before JDOM ever "sees"
them.  So
> to keep your original character entities intact, you would have to address
> (in some way that I can't answer) by tweaking the parser you use.

Ok, so it was my parser expanding the character entities but...

Amphersands have been expanded to "&amp;", why is this?

> > That's overstating it a bit, no? He's asking for a particular one of two
> > forms that are completely equivalent in XML's eyes, right?

This is a very good point, if they ARE equivalent then there should be the
option to output either form.

> > misunderstanding of XML. But there are certainly reasonable cases where
> > something else might care, and you might want to have control over this
> > (irrespective of this particular case).

Definately. But it seems as though the only case is the amphersand.  Is this

How can I output an amphersand verbatim?



More information about the jdom-interest mailing list