How to change inner content of HTML tag using HTMLDocument?
I want to change the inner content of an HTML tag from a HTMLDocument. The tag is like
<span id ="id1">Replace me</span>.
So I want to change the text "Replace me" inside the span tag and replace it with an other text.
I can get the span element using
HTMLDocument.getElement("id1")
I have tried many things with the Element instance i got from getElement. But I find no way to change the inner content of the HTML element. Any ideas?
[483 byte] By [
J-Braina] at [2007-11-27 5:48:41]

# 2
Thanks for the answer, but I already checked the Document na dhTMLDocument classes. The major problem I have is that I want the inner part of an HTML tag. Currently I don't find any useful function in SWING to get this inner part of the HTML tag and modify it without parsing the string of the tag myself and replace the whole tag.
# 4
I just found out that the main Problem may be that the HTMLReader class which is an inner class of HTMLDocument and which is used to build the document model does not support the <span> tag:
http://www.lightdev.com/doc/shtm/rel/help/topic16/topic74/topic77.htm
So that may be the core of the problem.
# 5
OK, the problem is that HTMLDocument.HTMLReader does not read the span tag correctly. If I use the div Tag instead it works using setInnerHTML as I thought at the beginning.Unfortunately HTML.TAG.SPAN exists, but HTMLReader does not know the span tag... curious...
# 6
If I use JDK 1.5 the SPAN tag works, so I checked the core of the problem which is inserting HTML code in an HTML tag.
setInnerHTML works fine for block tags like DIV but not if the tag is a leaf element like the SPAN tag. I have tried to use the following code for leaf elements:
Element elem = m_htmlDocument.getElement(id);
int nStartOffest = elem.getStartOffset();
int nEndOffset = elem.getEndOffset();
int nLength = nEndOffset - nStartOffest;
m_htmlDocument.replace(nStartOffest, nLength, html, elem.getAttributes());
This works, but only if the new HTML string does not contain HTML tags like a link <href..... >. If the string contains HTML tags the replace method masks all characters like < or >. So the link is not shown as link in the HTML page but as HTML text.
The next thing I have tried is using
m_htmlDocument.setOuterHTML(elem, html);
This works too but it replaces the whole original HTML element like the SPAN tag.
So there is still the question how to insert HTML text into a leaf Element in a HTMLDocument.