[jdom-interest] [Q} & in data for addContent() and setText()

Alex Rosen arosen at silverstream.com
Wed Jan 16 11:08:51 PST 2002


If you take a look at XMLOutputter, it's supposed to convert & to & for
you automatically. There was a recent change to this code, however, so there
may be a bug. Which version of JDOM are you using, beta 7 or the latest CVS
code? Can you do a little investigation in XMLOutputter to see what exactly
is going on?

Alex

-----Original Message-----
From: jdom-interest-admin at jdom.org [mailto:jdom-interest-admin at jdom.org]On
Behalf Of Rob Mitchell
Sent: Monday, January 14, 2002 11:20 AM
To: jdom-interest at jdom.org
Subject: [jdom-interest] [Q} & in data for addContent() and setText()


Hi,

I checked FAQ on dom.org -- no good match.
Now, should I try to translate "&" to "&" when creating the XML document
from SQL?
I'm using JDBC to get data from some database.  Often, I get the ampersand
character in names from the resultset and format into XML like this:

  <cps:RECORD cps:RECORDCOUNT="1">
    <cps:orgnzn_name>B SCOTT & WHITE TRUST</cps:orgnzn_name>
    <cps:cps_id>23087</cps:cps_id>
     </cps:RECORD>

This output is from XMLOutputter

  String strText = null;
  try {
   XMLOutputter outputter = new XMLOutputter("  ", true);
   StringWriter writer = new StringWriter();
   outputter.output (aDoc, writer);

   writer.close();
   strText = writer.toString();

  } catch (java.io.IOException e) {
   ...
  } catch (Exception e) {
   ...
  }
  return strText;


When I try to apply XSL template, I get error because of the "&" character
in orgnzn_name in the XML, actually it doesn't even translate because the
engine thinks there's an invalid whitespace.
Suggestions welcome.
Thanks!

---
Rob Mitchell
rjmitchell at mediaone.net
Base Class Technologies, Inc.
Designing and developing Java/Oracle solutions for the Web







More information about the jdom-interest mailing list