Re: [xmlc] Javascript output into XHTML
Erik Rasmussen <[email protected]> Thu, 15 Sep 2005 11:38:48 -0700 (PDT)
| Newsgroups | gmane.comp.java.enhydra.xmlc |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format...
------------=_1126810192-21748-138
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Excellent! You got it! Here's the working code, for
posterity:
---
import
org.enhydra.xml.xhtml.dom.xerces.XHTMLDocumentBase;
import
org.enhydra.xml.xhtml.dom.xerces.XHTMLScriptElementImpl;
import org.enhydra.xml.xmlc.html.HTMLObject;
// <--snip-->
final HTMLObject page;
// <--snip-->
final XHTMLDocumentBase documentBase =
(XHTMLDocumentBase) page.getDocument();
final XHTMLScriptElement script = new
XHTMLScriptElementImpl(documentBase, "", "script");
script.setAttribute("type", "text/javascript");
script.appendChild(page.createTextNode("/*"));
script.appendChild(page.createCDATASection("*/\n"+javascript+"\n/*"));
script.appendChild(page.createTextNode("*/"));
---
And just for humor value, I'll show the javascript
workaround I was using until you posted the answer...
(the Iterator class is moderately elegant, if you ask
me)
stupidXhtmlHack.js:
---
//
---------------------------------------------------------
// XML Entity avoidance
methods
//
---------------------------------------------------------
function Iterator(array)
{
this.array = array;
this.index = 0;
this.hasNext = Iterator_hasNext;
this.next = Iterator_next;
}
function Iterator_hasNext()
{
return this.index + 1 < this.array.length;
}
function Iterator_next()
{
this.index++;
return this.array[this.index];
}
function and(a, b)
{
return a && b;
}
function lessThan(a, b)
{
return a < b;
}
function lessThanOrEqual(a, b)
{
return a <= b;
}
function greaterThan(a, b)
{
return a > b;
}
function greaterThanOrEqual(a, b)
{
return a >= b;
}
---
:-)
Thanks!
Erik
--- Justin Akehurst <[email protected]> wrote:
> You can probably do something like this:
> 1) Create a new TextNode, with the contents "//",
> append as a child to
> <script> element.
> 2) Create a new CDataSection, with the contents of
> your script plus
> "//" at the end, append as a child to your <script>
> element.
>
> If the "//" doesn't work, try doing "/*" and then in
> the CData put
> "*/" as the first thing in there, plus your script,
> and end with "/*".
> Then create another TextNode with "*/" and append
> after the Cdata.
>
> -Justin
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
------------=_1126810192-21748-138
Content-Type: text/plain; name="message-footer.txt"
Content-Disposition: inline; filename="message-footer.txt"
Content-Transfer-Encoding: 8bit
--
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
------------=_1126810192-21748-138--