[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
Transitional//EN",

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd");
      doc.setDocType(docType);
      Element root = doc.getRootElement();
      Element head = new Element("head");
      head.addContent(new Element("title").setText("Blah"));
      root.addContent(head);
      Element body = new Element("body");
      body.addContent(new Element("p").setText("" © blah blah"));
      root.addContent(body);
      String newItem = args[0];
      XMLOutputter outputter = new XMLOutputter("  ", true);
      outputter.setTextNormalize(false);
      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"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Blah</title>
  </head>
  <body>
    <p>&amp;quot; &amp;#169; blah blah</p>
  </body>
</html>

> 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
this
> (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?

--SNIP--
> > 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?
--SNIP--

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

--SNIP--
> > 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).
--SNIP--

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

How can I output an amphersand verbatim?

Regards

Empty




More information about the jdom-interest mailing list