[jdom-interest] & problems
Edelson, Justin
Justin.Edelson at mtvn.com
Wed Sep 7 07:10:21 PDT 2005
Actually, I think this is pretty well addressed in the FAQ: http://jdom.org/docs/faq.html#a0290
________________________________
From: jdom-interest-bounces at jdom.org on behalf of Dirk Schumacher
Sent: Wed 9/7/2005 5:29 AM
To: jdom-interest at jdom.org
Subject: [jdom-interest] & problems
Hello,
well I was scanning through the archives but I was not successful
finding what I need.
I have Element with text which need to have a pure '&' outputted.
Well, we know, '&' will automatically converted to the 5 letters:
"&".
This is not always what I want. And I does not make sense to me.
Why is this problem so often ignored in so many articles/tutorials?
Just imagine. Having user input into a textarea which targets to be
displayed on a html page.
I am having a xml skeleton to put the input between the body tag.
The program automatically converts i.e. " to "
adding it then to an Element.
Ok, whenever jdom approches an '&' it will change it to &
for sure.
What is the workaround for having Text(parts) not to be changed, i.e.:
p.setText(" little indented text.");
outputting
" little indented text."
Which classes in jdom are responsible for changing this String's
'&'s to "&"s. I tried to overwrite the XmlOutputter but the
methods seem to be never called except in the main by program:
outputter.output((Element)e, (OutputStream)System.out);
Is probably possible to put it through xslt to resolve entities.
I would not want to do that. It would be lots of overhead and runtime
cost. Which is actually not needed for all other data than the &.
If you have further questions just mail I appreciate all hints I can
get.
The code:
--------------------------------------------------------------
import java.io.IOException;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
public class Joint6TestMain {
public static void main(String[] args) throws IOException {
Element e = new Element("body");
e.addContent("When I was young I loved to watch Simon & Simon");
e.addContent(new Element("br"));
e.addContent("seems to work correct!");
Element p = new Element("p");
e.addContent(p);
p.setText(" little indented text.");
e.addContent("makes me crazy!");
e.addContent(new Element("br"));
e.addContent("\u0026 is ok - & bothers me");
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
outputter.output(e, System.out);
}
}
--------------------------------------------------------------
The Output:
--------------------------------------------------------------
<body>
When I was young I loved to watch Simon & Simon
<br />
seems to work correct!
<p>&nbsp;little indented text.</p>
makes me crazy!
<br />
& is ok - &#38; bothers me
</body>
--------------------------------------------------------------
What I want:
--------------------------------------------------------------
<body>
When I was young I loved to watch Simon & Simon
<br />
seems to work correct!
<p> little indented text.</p>
makes me crazy!
<br />
& is ok - & bothers me
</body>
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20050907/bc6cf086/attachment.htm
More information about the jdom-interest
mailing list