<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7226.0">
<TITLE>[jdom-interest] &amp; problems</TITLE>
</HEAD>
<BODY>
<DIV id=idOWAReplyText42136 dir=ltr>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2>Actually, I think this is
pretty well addressed in the FAQ: <A
href="http://jdom.org/docs/faq.html#a0290">http://jdom.org/docs/faq.html#a0290</A></FONT></DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> jdom-interest-bounces@jdom.org on behalf
of Dirk Schumacher<BR><B>Sent:</B> Wed 9/7/2005 5:29 AM<BR><B>To:</B>
jdom-interest@jdom.org<BR><B>Subject:</B> [jdom-interest] &amp;
problems<BR></FONT><BR></DIV>
<DIV>
<P><FONT size=2>Hello,<BR><BR>well I was scanning through the archives but I was
not successful<BR>finding what I need.<BR><BR>I have Element with text which
need to have a pure '&' outputted.<BR>Well, we know, '&' will
automatically converted to the 5 letters:<BR>"&amp;".<BR><BR>This is not
always what I want. And I does not make sense to me.<BR>Why is this problem so
often ignored in so many articles/tutorials?<BR><BR>Just imagine. Having user
input into a textarea which targets to be<BR>displayed on a html page.<BR><BR>I
am having a xml skeleton to put the input between the body tag.<BR>The program
automatically converts i.e. " to &quot;<BR>adding it then to an
Element.<BR><BR>Ok, whenever jdom approches an '&' it will change it to
&amp;<BR>for sure.<BR><BR>What is the workaround for having Text(parts) not
to be changed, i.e.:<BR>p.setText("&nbsp;little indented
text.");<BR>outputting<BR>"&nbsp;little indented text."<BR><BR>Which classes
in jdom are responsible for changing this String's<BR>'&'s to "&amp;"s.
I tried to overwrite the XmlOutputter but the<BR>methods seem to be never called
except in the main by program:<BR>outputter.output((Element)e,
(OutputStream)System.out);<BR><BR>Is probably possible to put it through xslt to
resolve entities.<BR>I would not want to do that. It would be lots of overhead
and runtime<BR>cost. Which is actually not needed for all other data than the
&.<BR><BR>If you have further questions just mail I appreciate all hints I
can<BR>get.<BR><BR>The
code:<BR>--------------------------------------------------------------<BR>import
java.io.IOException;<BR>import org.jdom.Element;<BR>import
org.jdom.output.Format;<BR>import org.jdom.output.XMLOutputter;<BR><BR>public
class Joint6TestMain {<BR><BR> public static void
main(String[] args) throws IOException
{<BR><BR> Element e = new
Element("body");<BR>
e.addContent("When I was young I loved to watch Simon &
Simon");<BR> e.addContent(new
Element("br"));<BR>
e.addContent("seems to work
correct!");<BR> Element p = new
Element("p");<BR>
e.addContent(p);<BR>
p.setText("&nbsp;little indented
text.");<BR><BR> e.addContent("makes
me crazy!");<BR> e.addContent(new
Element("br"));<BR>
e.addContent("\u0026 is ok - &#38; bothers
me");<BR><BR> XMLOutputter outputter =
new
XMLOutputter(Format.getPrettyFormat());<BR>
outputter.output(e, System.out);<BR>
}<BR>}<BR>--------------------------------------------------------------<BR>The
Output:<BR>--------------------------------------------------------------<BR><body><BR>
When I was young I loved to watch Simon &amp; Simon<BR> <br
/><BR> seems to work correct!<BR> <p>&amp;nbsp;little
indented text.</p><BR> makes me crazy!<BR> <br
/><BR> &amp; is ok - &amp;#38; bothers
me<BR></body><BR>--------------------------------------------------------------<BR><BR>What
I
want:<BR>--------------------------------------------------------------<BR><body><BR>
When I was young I loved to watch Simon &amp; Simon<BR> <br
/><BR> seems to work correct!<BR> <p>&nbsp;little
indented text.</p><BR> makes me crazy!<BR> <br
/><BR> &amp; is ok - & bothers
me<BR></body><BR><BR><BR>_______________________________________________<BR>To
control your jdom-interest membership:<BR><A
href="http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com">http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com</A><BR></FONT></P></DIV>
</BODY>
</HTML>