[jdom-interest] Text replacement

Edelson, Justin Justin.Edelson at mtvn.com
Fri May 5 14:47:59 PDT 2006


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.
 
Can you provide some more detail?
 
And please respond to the list, not to me individually.
 
Justin

________________________________

From: Leonardo Barbosa [mailto:lsbarbosa at gmail.com] 
Sent: Friday, May 05, 2006 4:38 PM
To: Edelson, Justin
Subject: Re: [jdom-interest] Text replacement


Thanks Justin!

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
<chamada> tags and, for each one, I need to replace all ocurrences of
$REPLACE_THIS with a spacific value, for that <chamada> tag. To be more
specific, each <chamada> tag has a url associated with it, according to
it's position in the XML. 

So, to replace using replaceAll, wouldnt I need to create an String out
using XMLOutputter for each <chamada> tag, and them use the SAXParser to
create the JDOM model again, and atach this new JDOM model to the old
one? 

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 :-) 

Thanks again for your help,
Leonardo Barbosa.


On 5/5/06, Edelson, Justin <Justin.Edelson at mtvn.com > wrote: 

	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
	
	
	
	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 at gmail.com
	
	


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


More information about the jdom-interest mailing list