<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.2873" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=860124120-05052006>I was actually suggesting (as did Thomas) to not use 
JDOM at all and just use regex across the whole document. But now you're saying 
that the replacement text is somehow related to the context within the XML 
document.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=860124120-05052006></SPAN></FONT>&nbsp;</DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=860124120-05052006>Can you provide some more detail?</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=860124120-05052006></SPAN></FONT>&nbsp;</DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=860124120-05052006>And please respond to the list, not to me 
individually.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=860124120-05052006></SPAN></FONT>&nbsp;</DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=860124120-05052006>Justin</SPAN></FONT></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Leonardo Barbosa 
[mailto:lsbarbosa@gmail.com] <BR><B>Sent:</B> Friday, May 05, 2006 4:38 
PM<BR><B>To:</B> Edelson, Justin<BR><B>Subject:</B> Re: [jdom-interest] Text 
replacement<BR></FONT><BR></DIV>
<DIV></DIV>Thanks Justin!<BR><BR>Infact, the problem with creating the string 
and using replaceAll is that I don't have the output ready at this time. I'm 
iterating over the &lt;chamada&gt; tags and, for each one, I need to replace all 
ocurrences of $REPLACE_THIS with a spacific value, for that &lt;chamada&gt; tag. 
To be more specific, each &lt;chamada&gt; tag has a url associated with it, 
according to it's position in the XML. <BR><BR>So, to replace using replaceAll, 
wouldnt I need to create an String out using XMLOutputter for each 
&lt;chamada&gt; tag, and them use the SAXParser to create the JDOM model again, 
and atach this new JDOM model to the old one? <BR><BR>I mean, I can't reaplace 
in the and, when I finish processing the document, beacause its the same string 
$REPLACE_ALL with diferent values.. I could ask the client to use diferente 
names, but i could generate errors, I upset him :-) <BR><BR>Thanks again for 
your help,<BR>Leonardo Barbosa.<BR><BR>
<DIV><SPAN class=gmail_quote>On 5/5/06, <B class=gmail_sendername>Edelson, 
Justin</B> &lt;<A href="mailto:Justin.Edelson@mtvn.com">Justin.Edelson@mtvn.com 
</A>&gt; wrote:</SPAN>
<BLOCKQUOTE class=gmail_quote 
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
  <DIV style="DIRECTION: ltr">
  <DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>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</FONT></SPAN></DIV>
  <DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff 
  size=2>string.replaceAll("\$REPLACE_THIS", 
  replacementString);</FONT></SPAN></DIV>
  <DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>(because 
  replaceAll expects a RegEx, you need to escape the dollar 
  sign)</FONT></SPAN></DIV>
  <DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff 
  size=2></FONT></SPAN>&nbsp;</DIV>
  <DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>Doing this 
  wouldn't even require "tidying" up the doc.</FONT></SPAN></DIV>
  <DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff 
  size=2></FONT></SPAN>&nbsp;</DIV><BR>
  <DIV lang=en-us dir=ltr align=left>
  <HR>
  <FONT face=Tahoma size=2><B>From:</B> <A 
  onclick="return top.js.OpenExtLink(window,event,this)" 
  href="mailto:jdom-interest-bounces@jdom.org" 
  target=_blank>jdom-interest-bounces@jdom.org</A> [mailto:<A 
  onclick="return top.js.OpenExtLink(window,event,this)" 
  href="mailto:jdom-interest-bounces@jdom.org" 
  target=_blank>jdom-interest-bounces@jdom.org</A>] <B>On Behalf Of </B>Leonardo 
  Barbosa<BR><B>Sent:</B> Friday, May 05, 2006 2:10 PM<BR><B>To:</B> <A 
  onclick="return top.js.OpenExtLink(window,event,this)" 
  href="mailto:jdom-interest@jdom.org" 
  target=_blank>jdom-interest@jdom.org</A><BR><B>Subject:</B> [jdom-interest] 
  Text replacement<BR></FONT><BR></DIV></DIV>
  <DIV style="DIRECTION: ltr"><SPAN class=e id=q_10b05f8cbf26b6e3_1>
  <DIV></DIV>Hi!<BR><BR>I'm new to jdom and xml, so sorry if this is non 
  sense.<BR>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 
  <BR>&lt;a href="#" onclick="javascript:openLink($REPLACE_THIS);"&gt;<BR><BR>bu 
  could be in the text of some &lt;script&gt; tag for 
  example:<BR>&lt;script&gt;<BR>funcion onclick(){<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
  opeanUrl("REPLACE_THIS"); <BR>}<BR>&lt;/script&gt;<BR><BR>There only one more 
  thing: It needs to be inside some tag, the one that defines the link 
  url:<BR><BR>&lt;chamada&gt;<BR>1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  &lt;a href="#" onclick="openLink($REPLACE_THIS);"&gt;click here&lt;/a&gt; 
  <BR>&lt;/chamada&gt;<BR><BR>&lt;chamada&gt;<BR>2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  &lt;a href="#" 
  onclick="openLink($REPLACE_THIS);"&gt;$REPLACE_THIS&lt;/a&gt;<BR>&lt;/chamada&gt;<BR><BR><BR>Is 
  there a way to do this with jdom API, without getting all Descendents from the 
  tag &lt;chamada&gt; and looking inside its Text and Attributes ?<BR>something 
  like:<BR><BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Iterator chamadaIterator = 
  root.getDescendants (new ElementFilter("chamada"));<BR>&nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp; while (chamadaIterator.hasNext()) {<BR>&nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Element chamadaTag = 
  (Element) chamadaIterator.next();<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; chamadaTag.setTextReplacement("$REPLACE_THIS", 
  " <A onclick="return top.js.OpenExtLink(window,event,this)" 
  href="http://www.thinkgeek.org" 
  target=_blank>http://www.thinkgeek.org</A>");<BR>&nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp; }<BR><BR>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 <SPAN>whole </SPAN>document.<BR><BR>I no that it seeas to be lazyness 
  :-)<BR>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. <BR><BR>Thanks in advance,<BR>Leonardo Barbosa<BR><A 
  onclick="return top.js.OpenExtLink(window,event,this)" 
  href="mailto:lsbarbosa@gmail.com" 
  target=_blank>lsbarbosa@gmail.com</A><BR><BR></SPAN></DIV></BLOCKQUOTE></DIV><BR></BODY></HTML>