[jdom-interest] Text replacement

Edelson, Justin Justin.Edelson at mtvn.com
Fri May 5 12:14:15 PDT 2006

I'd first look at whether or not you need ANY kind of XML processing for
this. If all you are doing is replacing $REPLACE_THIS with some string,
then you could just get the template into a String object and do
string.replaceAll("\$REPLACE_THIS", replacementString);
(because replaceAll expects a RegEx, you need to escape the dollar sign)
Doing this wouldn't even require "tidying" up the doc.


From: jdom-interest-bounces at jdom.org
[mailto:jdom-interest-bounces at jdom.org] On Behalf Of Leonardo Barbosa
Sent: Friday, May 05, 2006 2:10 PM
To: jdom-interest at jdom.org
Subject: [jdom-interest] Text replacement


I'm new to jdom and xml, so sorry if this is non sense.
I read a xml template (a html to be true, transformed to XML using tidy)
file from my client, and want to change all ocurrences of one text to
something else. It will probably be inside some javascript, something
<a href="#" onclick="javascript:openLink($REPLACE_THIS);">

bu could be in the text of some <script> tag for example:
funcion onclick(){

There only one more thing: It needs to be inside some tag, the one that
defines the link url:

1         <a href="#" onclick="openLink($REPLACE_THIS);">click here</a> 

2         <a href="#"

Is there a way to do this with jdom API, without getting all Descendents
from the tag <chamada> and looking inside its Text and Attributes ?
something like:

        Iterator chamadaIterator = root.getDescendants (new
        while (chamadaIterator.hasNext()) {
               Element chamadaTag = (Element) chamadaIterator.next();
               chamadaTag.setTextReplacement("$REPLACE_THIS", "

I've searched the forum and found some ideas aboute html entities, but
it seams to be not the case, since I have one value for the whole

I no that it seeas to be lazyness :-)
But in fact I'm trying to avoid some desnecessary loop inside all
elements, all texts from theese elements, and all attributes from theese

Thanks in advance,
Leonardo Barbosa
lsbarbosa at gmail.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20060505/21f22797/attachment.htm

More information about the jdom-interest mailing list