Subj : Re: Getting an XmlObject from E4X changes top level element to xml-fragment
To : netscape.public.mozilla.jseng
From : torntrousers
Date : Wed Mar 16 2005 01:01 am
Hi, I'm still stuck with this so if anyone has any pointers I'd really
appreciate it.
It looks like getting an XmlObject is always losing the top level
element, as demonstrated by the code below. The print from the script
and of jsResult show the correct XML:
but getting that as an XmlObject looses the top level element and a
print shows:
Thanks for any help,
...ant
public static void main(String[] args) {
Context cx = Context.enter();
try {
Scriptable scope = cx.initStandardObjects(null, true);
StringBuffer sb = new StringBuffer();
sb.append("function foo() {\n");
sb.append("var xml = ;");
sb.append("java.lang.System.out.println(xml);");
sb.append("return xml;\n");
sb.append("}\n");
String script = sb.toString();
Script compiledScript = cx.compileString(script,"bla",1,null);
compiledScript.exec(cx, scope);
Function foo = (Function) scope.get("foo", scope);
Scriptable jsResult = (Scriptable) foo.call(cx, scope, scope,
new Object[] {});
System.out.println("jsResult:\n" + jsResult);
Wrapper wrap = (Wrapper) ScriptableObject.callMethod(jsResult,
"getXmlObject", new Object[0]);
XmlObject xmlObject = (XmlObject) wrap.unwrap();
System.out.println("xmlObject:\n" + xmlObject.xmlText());
} finally {
Context.exit();
}
}
.