Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

[jdom-interest] Text replacement

Leonardo Barbosa

2006-05-05

Replies:

Hi!

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 like
<a href="#" onclick="javascript:openLink($REPLACE_THIS);">

bu could be in the text of some <script> tag for example:
<script>
funcion onclick(){
     opeanUrl("REPLACE_THIS");
}
</script>

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

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

<chamada>
2         <a href="#" onclick="openLink($REPLACE_THIS);">$REPLACE_THIS</a>
</chamada>


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 ElementFilter("chamada"));
        while (chamadaIterator.hasNext()) {
               Element chamadaTag = (Element) chamadaIterator.next();
               chamadaTag.setTextReplacement("$REPLACE_THIS", " http://www.thinkgeek.org");
        }

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 document.

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 elements.

Thanks in advance,
Leonardo Barbosa
lsbarbosa@gmail.com

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.