Subj : Different handling of XML literals in Spidermonkey and Rhino To : netscape.public.mozilla.jseng From : Martin Honnen Date : Sat Mar 26 2005 06:36 pm Section 11.1.4 XML Initialiser of E4X says: An XML initialiser is an expression describing the initialization of an XML object, written in a form of a literal. It may specify an XML element, an XML comment, an XML PI, or a CDATA section using ordinary XML syntax. Consequently I have tried the following with Spidermonkey, using literals for the different kind of nodes: js> var god = Kibo; js> god.nodeKind() element js> var comment = ; js> comment.nodeKind() comment js> var pi = ; js> pi.nodeKind() processing-instruction js> var cdata = All for Kibology.]]>; js> cdata.nodeKind() text Thus with Spidermonkey it seems a literal doesn't have to be well-formed markup in the sense of the XML specification (where you would always need to have a root element) but you can use a snippet of markup for the specific node types. However when I try the same with Rhino (Rhino 1.6 release 1 2004 11 30) I am only able to use a literal for an element successfully, for the other attempts to have a literal solely creating a comment or a processing instruction of a CDATA text node Rhino gives errors or hangs: js> var god = Kibo; js> god.nodeKind() element js> var comment = ; comment.nodeKind() js: "", line 3: uncaught JavaScript runtime exception: TypeError: Cannot call method "nodeKind" of undefined js> var pi = ; pi.nodeKind() hangs js> var cdata = All for Kibology.]]>; cdata.nodeKind() hangs Trying to understand which behaviour is correct I have looked closer at section 11.1.4 XML, the production for XML initialiser is XMLInitialiser : XMLMarkup XMLElement so any attempts not to use an element in the literal should be covered by the production XMLMarkup on which the sections says: The production XMLInitialiser : XMLMarkup is evaluated as follows: 1. Let markup be a string literal containing the same sequence of characters as XMLMarkup 2. Return a new XML object created as if by calling the XML constructor with argument markup (section 13.4.2) which then means the markup string is passed to ToXML as defined in section which would require to parse markup Looking at that it seems Spidermonkey behaves correctly while Rhino has bugs, it should be able to handle the literals/initializers for comments, processing instructions, and cdata sections. However, I am not sure how the default for XML.ignoreComments/ignoreProcessingInstructions come into play here and what is really supposed to happen. What do other think, does Rhino have a bugs? For instance when I change the ignoreComments setting I still get the error: Rhino 1.6 release 1 2004 11 30 js> XML.ignoreComments true js> XML.ignoreComments = false; false js> var comment = ; comment.nodeKind() js: "", line 3: uncaught JavaScript runtime exception: TypeError: Cannot call method "nodeKind" of undefined -- Martin Honnen http://JavaScript.FAQTs.com/ .