Subj : Re: Use DOM-object in Rhino To : netscape.public.mozilla.jseng From : Martin Honnen Date : Tue Jan 18 2005 01:42 pm Matthias wrote: > I want to execute Java-Script-Functions of a HTML-page without a > browser in a Java application. The Java-Script functions use and > manipulate values of the Document Object Model (DOM) of the Webpage. Sounds like what HttpUnit does (tries to do): > In http://groups.google.com/groups?q=DOM+Rhino&hl=de&lr=&selm=8ur47h%24luc%241%40nnrp1.deja.com&rnum=2 > someone says that the following code would work: > Scriptable jsObject = Context.toObject(myDocument, scope); > scope.put("document", scope, jsObject); > > But when I test it with my JDOM document as myDocument the document > variables like document.elementname are not recognized. Well there is no magic possible to have any object model implemented by getting something into Rhino, if you use a org.jdom.Document then if scripting it with JavaScript in Rhino the properties and methods are those defined in the Java API so you could for instance then call document.removeContent(); in the script as that is a method In addition I think Rhino makes Java getter/setter available as properties in JavaScript e.g. document.rootElement = someElement should be possible. But the browser like HTML Level 0 DOM of making document.elementName properties available for e.g. is not implemented in JDOM and thus if you script a JDOM Document in Rhino there is no magic to suddenly have those. -- Martin Honnen http://JavaScript.FAQTs.com/ .