Replace every word with tag
<p><strong>JAVASCRIPT or JAVA solution needed</strong></p>

<p>The solution I am looking for could use java or javascript. I have the html code in a string so I could manipulate it before using it with java or afterwards with javascript.</p>

<p><em><strong>problem</em></strong></p>

<p>Anyway, I have to wrap each word with a tag. For example:</p>

<pre><code>&lt;html&gt; ... &gt;
Hello every one, cheers
&lt; ... &lt;/html&gt;
</code></pre>

<p>should be changed to</p>

<pre><code>&lt;html&gt; ... &gt;
&lt;word&gt;Hello&lt;/word&gt; &lt;word&gt;every&lt;/word&gt; &lt;word&gt;one&lt;/word&gt;, &lt;word&gt;cheers&lt;/word&gt;
&lt; ... &lt;/html&gt;
</code></pre>

<hr>

<p><strong>Why?</strong></p>

<p>This will help me use javascript to select/highlight a word. It seems the only way to do it is to use the function highlightElementAtPoint which I added in the <strong>JAVASCRIPT hint</strong>: It simply finds the element of a certain x,y coordinate and highlights it. I figured that if every word is an element, it will be doable.</p>

<p>The idea is to use this approach to allow us to detect highlighted text in an android WebView even if that would mean to use a twisted highlighting method. Think a bit more and you will find many other applications for this.</p>

<hr>

<p><strong>JAVASCRIPT hint</strong></p>

<p>I am using the following code to highlight a word; however, this will highlight the whole text belonging to a certain tag. When each word is a tag, this will work to some extent. If there is a substitute that will allow me to highlight a <em>word</em> at a certain position, it would also be a solution.</p>

<pre><code>function highlightElementAtPoint(xOrdinate, yOrdinate) {
    var theElement = document.elementFromPoint(xOrdinate, yOrdinate);
    selectedElement = theElement;
    theElement.style.backgroundColor = "yellow";
    var theName = theElement.nodeName;
    var theArray = document.getElementsByTagName(theName);
    var theIndex = -1;
    for (i = 0; i &lt; theArray.length; i++) {
        if (theArray[i] == theElement) {
            theIndex = i;
        }
    }
    window.androidselection.selected(theElement.innerHTML);
    return theName + " " + theIndex;
}
</code></pre>
