Here's how I convert between W3C DOM and E4X in ESXX:
/** Utility method that converts a W3C DOM Node into an E4X XML object.
*
* @param node The Node to be converted.
*
* @param cx The current JavaScript context.
*
* @param scope The current JavaScript scope.
*
* @return A Scriptable representing an E4X XML object.
*/
public static Scriptable domToE4X(org.w3c.dom.Node node, Context cx,
Scriptable scope) {
if (node == null) {
return null;
}
return cx.newObject(scope, "XML", new org.w3c.dom.Node[] { node });
}
/** Utility method that converts an E4X XML object into a W3C DOM Node.
*
* @param node The E4X XML node to be converted.
*
* @return A W3C DOM Node.
*/
public static org.w3c.dom.Node e4xToDOM(Scriptable node) {
return org.mozilla.javascript.xmlimpl.XMLLibImpl.toDomNode(node);
}
Robert Koberg wrote:
> Sorry, I gave up on E4X a while ago. Maybe check out what apache's BSF
> does with org.mozilla.javascript.xmlimpl.XML or XMLObject?
>
> best,
> -Rob
>
>
> On Sep 5, 2008, at 11:01 AM, Carlos Montagut wrote:
>
>> Hi Rob,
>>
>> > Why not just use the axiom document in rhino?
>>
>> Well, I wanted to use inside the script all the functionally provided
>> by E4X... In some cases the full payload will generated by the script,
>> so E4X was a very easy way to generate them.
>>
>> When I return a XML from JavaScript and I get it in Java, the object I
>> get is an org.mozilla.javascript.xmlimpl.XML (which I don't have
>> access, is not a public class).
>>
>> Do you know which object should I instatiate in the Java side, that
>> once I pass it to the Scope, in the JavaScrit side I see it as an XML
>> of E4X (I could create this kind of object from using the AXIOM doc)?
>> At least something that is not a serialized string that I should parse
>> again...
>>
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino