Robert Koberg wrote:
> On Tue, 2008-07-01 at 23:23 +0100, Kieran Topping wrote:
>
>> True although - interestingly - I've yet to meet a parser that disallows it.
>>
>> However, I don't want this to cause any confusion, so - for the sake of
>> argument - feel free to replace "<xml/>" with
>> "<root-element-of-your-choice/>" (as per the attached java)
>>
>> The result is the same - i.e. this issue is independent of the xml
>> content (in fact, in my example java, the parser doesn't even get as far
>> as trying to parse the "xml").
>>
>
> OK. But aren't you just creating a String? Are you building some kind of
> DOM in your script?
>
I'm not quite sure what you mean by
"aren't you just creating a String?"
The following line:
Object xml = cx.newObject(scope, "XML", new Object []
{"<root-element-of-your-choice/>"});
is intended to create a javascript object of type XML.
ScriptableObject.putProperty(scope, "xml", xml);
places this object in scope.
Object result = cx.evaluateString(scope, "var x =
xml.name();", "<cmd>", 1, null);
is merely intended to show the sort of thing that I might then want to
do with this object inside a script.
Kieran
>
>> Regards,
>> Kieran
>>
>>
>> Robert Koberg wrote:
>>
>>> Hi,
>>>
>>> <xml/> is an illegal element name in an XML document.
>>>
>>> best,
>>> -Rob
>>>
>>>
>>> On Tue, 2008-07-01 at 22:07 +0100, Kieran Topping wrote:
>>>
>>>
>>>> Hello,
>>>>
>>>> I am attempting to create an XML object, put it in scope, and then
>>>> execute a script in this scope.
>>>> However, when I run the attached simple java class, I get the following
>>>> exception:
>>>>
>>>> Exception in thread "main" java.lang.IllegalStateException
>>>> at
>>>> org.mozilla.javascript.ScriptRuntime.getTopCallScope(ScriptRuntime.java:2986)
>>>> at
>>>> org.mozilla.javascript.ScriptRuntime.searchDefaultNamespace(ScriptRuntime.java:1145)
>>>> at
>>>> org.mozilla.javascript.xmlimpl.XMLLibImpl.getDefaultNamespace(XMLLibImpl.java:328)
>>>> at
>>>> org.mozilla.javascript.xmlimpl.XMLLibImpl.getDefaultNamespaceURI(XMLLibImpl.java:313)
>>>> at
>>>> org.mozilla.javascript.xmlimpl.XMLLibImpl.parse(XMLLibImpl.java:405)
>>>> at
>>>> org.mozilla.javascript.xmlimpl.XMLLibImpl.ecmaToXml(XMLLibImpl.java:438)
>>>> at
>>>> org.mozilla.javascript.xmlimpl.XMLObjectImpl.ecmaToXml(XMLObjectImpl.java:800)
>>>> at org.mozilla.javascript.xmlimpl.XML.jsConstructor(XML.java:217)
>>>> at
>>>> org.mozilla.javascript.xmlimpl.XMLObjectImpl.execIdCall(XMLObjectImpl.java:591)
>>>> at
>>>> org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:127)
>>>> at
>>>> org.mozilla.javascript.BaseFunction.construct(BaseFunction.java:328)
>>>> at org.mozilla.javascript.Context.newObject(Context.java:1406)
>>>> at AddXmlToScope.main(AddXmlToScope.java:10)
>>>>
>>>> When parsing xml, XMLLibImpl checks to see whether there is a "default
>>>> namespace" set up. In order to do this,
>>>> ScriptRuntime.searchDefaultNamespace() attempts to examine
>>>> Context.currentActivationCall and Context.topCallScope. However, because
>>>> the XML object is being created outside of a script, these values are
>>>> both null. This results in the IllegalStateException being thrown, as
>>>> detailed above.
>>>>
>>>> Does anyone know whether this is this a bug, or is it me attempting to
>>>> do something that I'm not really allowed to?
>>>>
>>>> Or is there a step that I'm missing in my java?
>>>>
>>>> Many thanks in advance,
>>>>
>>>> Kieran
>>>>
>>>>
>>>> plain text document attachment (AddXmlToScope.java)
>>>> import org.mozilla.javascript.*;
>>>> public class AddXmlToScope {
>>>> public static void main (String [] argv)
>>>> throws Exception
>>>> {
>>>> Context cx = Context.enter();
>>>> try {
>>>> Scriptable scope = cx.initStandardObjects();
>>>> // Create an XML object.
>>>> Object xml = cx.newObject(scope, "XML", new Object []
>>>> {"<xml/>"});
>>>> // Put the XML object in scope.
>>>> ScriptableObject.putProperty(scope, "xml", xml);
>>>> // Run a script in this scope. The script will have access
>>>> // to the "xml" property.
>>>> Object result = cx.evaluateString(scope, "var x =
>>>> xml.name();", "<cmd>", 1, null);
>>>> } finally {
>>>> Context.exit();
>>>> }
>>>> }
>>>> }
>>>> _______________________________________________
>>>> dev-tech-js-engine-rhino mailing list
>>>> [email protected]
>>>> https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
>>>>
>>>>
>>> _______________________________________________
>>> dev-tech-js-engine-rhino mailing list
>>> [email protected]
>>> https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
>>>
>>>
>>>
>>>
>> plain text document attachment (AddXmlToScope.java)
>> import org.mozilla.javascript.*;
>> public class AddXmlToScope {
>> public static void main (String [] argv)
>> throws Exception
>> {
>> Context cx = Context.enter();
>> try {
>> Scriptable scope = cx.initStandardObjects();
>> // Create an XML object.
>> Object xml = cx.newObject(scope, "XML", new Object []
>> {"<root-element-of-your-choice/>"});
>> // Put the XML object in scope.
>> ScriptableObject.putProperty(scope, "xml", xml);
>> // Run a script in this scope. The script will have access
>> // to the "xml" property.
>> Object result = cx.evaluateString(scope, "var x = xml.name();",
>> "<cmd>", 1, null);
>> } finally {
>> Context.exit();
>> }
>> }
>> }
>> _______________________________________________
>> dev-tech-js-engine-rhino mailing list
>> [email protected]
>> https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
>>
>
>
>
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino