Greeting Page | Table Page | New Node Page | Form Page

This page shows how to add a span of HTML from an external resource into a page at runtime. The file addme.txt contains the HTML to be inserted.

If you can modify the HTML in the addme.txt, be sure that resulting span has valid tags. Missing end tags can cause the page to fail.

The html for the span is:
<span id="spanInsertHere">placeholder</span>
            
Below is the span with the inserted HTML:

placeholder that will be replaced

After the html is read in from a file into a string, the following methods parse the string and add it to a HTML element.
 private boolean setParsedData(HTMLObject owner,
                               HTMLElement element,
                               String text) {
   boolean parsed = false;
   Node parent = element.getParentNode();
   if (text == null) {
     text = new String();
   }
   if (text.indexOf("<") &;gt; -1 && text.indexOf(&qout;>") > -1) {
     parsed = true;
     XMLCUtil.getFirstText(element).setData(&qout;&qout;);
     parent.insertBefore(parseTextToNode(owner, text), element);
     parent.removeChild(element);
   } else {
     XMLCUtil.getFirstText(element).setData(text);
   }
   return parsed;
 }

  private Node parseTextToNode(HTMLObject owner, String text) {
    HTMLParser parser   = null;
    Node newNode        = null;
    Element node        = null;
    StringReader reader = new StringReader("<span id=\"textIn\">" + text + "</span>");
    try {
      parser = new HTMLParser(reader, "source");
      node = owner.createElement("span");
      newNode = parser.parseNode(node);
    } catch (java.io.IOException e) {
      e.printStackTrace();
    }
    return newNode;
  }
            

Enhydra | Lutris | Borland | JBuilder

Feedback on the Enhydra Tools for JBuilder