logo       

RE: Adding content to DOM tree on the fly: msg#00059

java.enhydra.general

Subject: RE: Adding content to DOM tree on the fly

Hi Boris,

There is some information here:
http://xmlc.enhydra.org/software/documentation/index.html

Also the Enhydra getting_started.pdf is a good tutorial.
Do you have this document? I'm not sure where it is anymore. It used to be
here:
http://www.webdocwf.org/

But it's not there anymore.. Anyone know where it is?

Here is one way to add text to a Table Cell.
It also shows how to add an extra cell to the table row.

For example:
<table>
<tr>
<td id="FirstCol">
[TEST DATA]
</td>
</tr>
</table>

Then after compiling with XMLC/Java you can use the td element as a "template".
Most of us change the contents of the cell, and then clone it and add it to
the docuemnent. When we are all done, we delete the original "template" cell.

For example:
// get the Template Cell, and get The Parent - the <tr> row element also.
HTMLTableCellElement templateCell = page.getElementFirstCol();
templateCell.removeAttribute("id");
Node cellParent = templateCell.getParentNode();

// change the text in the <td> template cell..
page.setTextFirstCol("This is some new text for this cell!");

// Here we clone the template cell, and add the clone to the row..

cellParent.appendChild(templateCell.cloneNode(true));

// Let's make a new Cell and add it to the same row..

page.setTextFirstCol("This is the 2nd cell");

// make another clone and add it to the row..

cellParent.appendChild(templateCell.cloneNode(true));

// At this time we have 3 cells in the row, the original template, and 2
clones..
// Remove the template since we don't need it any more..

cellParent.removeChild(templatCell);

// That's it..

This should be the result..

<table>
<tr>
<td>
This is some new text for this cell!
</td>
<td>
This is the 2nd cell
</td>
</tr>
</table>

That's the easy way.. you can also create a new <td> or a TEXT node from
scratch, but you will need to initialize it properly, setting it's parent etc.
Then you can append it to the DOM. I have not needed to do this, since it's
easier to clone existing elements, and delete the templates I don't need
anymore.

Hope this helps..

Mike Warne.







Mike Warne.

-----Original Message-----
From: Boris Klug [mailto:boris@xxxxxx]
Sent: Thursday, January 30, 2003 6:24 AM
To: enhydra@xxxxxxxxxxx
Subject: Enhydra: Adding content to DOM tree on the fly


Hello!

I want to add dynamic content to the DOM tree of a webpage, e.g. a
simple text into a table cell but also more complex stuff.

How do I do this? I tried to use LazyHTMLElement but it doesnt work for
my... Does anybody have to short code snippet which shows how to add
dynamic stuff to a Node?

Please reply also to my email address because I read this mailing list
only on www.enhydra.org and the postings views there are delayed.

Thank you in advance

_______________________________________________
Enhydra mailing list
Enhydra@xxxxxxxxxxx
http://www.enhydra.org/mailman/listinfo.cgi/enhydra


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise