E4X

  • Enlace amigable (slug) de la revisión: E4X
  • Título de la revisión: E4X
  • Id de la revisión: 71652
  • Creada:
  • Creador: Nsertzen
  • ¿Es la revisión actual? No
  • Comentario New page: <breadcrumbs></breadcrumbs> '''ECMAScript for XML''' ('''E4X''') is a programming language extension that adds native [[XML]] support to [[JavaScript]]. It does this by providing access to...

Contenido de la revisión

ECMAScript for XML (E4X) is a programming language extension that adds native XML support to JavaScript. It does this by providing access to the XML document in a form that feels natural for ECMAScript programmers. The goal is to provide an alternative, simpler syntax for accessing XML documents than via DOM interfaces.

E4X is standardized by Ecma International in ECMA-357 standard (currently in its second edition, December 2005).

E4X is implemented (at least partially) in SpiderMonkey (Gecko's JavaScript engine) and in Rhino (JavaScript engine written in Java).

Note: In Gecko 1.8 based browsers such as Firefox 1.5, E4X is already partially enabled for web page authors. To fully enable E4X, the <script> element needs to have the MIME type "text/javascript;e4x=1" (i.e. have an attribute of the form type="text/javascript;e4x=1"). The difference between the two modes is that without the "e4x=1" MIME type, any statement-level XML/HTML comment literals (<!--...-->) are ignored for backwards compatibility with the comment hiding trick, and CDATA sections (<![CDATA{{mediawiki.external('...')}}]>) are not parsed as CDATA literals (which leads to a JS syntax error in HTML since HTML's <script> element produces an implicit CDATA section, and therefore cannot contain explicit CDATA sections).

someone verify the above

Known bugs and limitations

  • It is not currently possible to access a DOM object through E4X ({{template.Bug(270553)}})
  • E4X doesn't support parsing XML declaration (<?xml version=...?>) (see {{template.Bug(336551)}}). You may get SyntaxError "xml is a reserved identifier" (despite the XML being in a string).

Workaround:

var response = xmlhttprequest.responseText; // bug 270553
response = response.replace('<?xml version="1.0"?>', ""); // bug 336551
var e4x = new XML(response);

Resources

{{ wiki.languages( { "it": "it/E4X", "fr": "fr/E4X", "ja": "ja/E4X", "ko": "ko/E4X", "pl": "pl/E4X" } ) }}

Fuente de la revisión

<p>
<b>ECMAScript for XML</b> (<b>E4X</b>) is a programming language extension that adds native <a href="es/XML">XML</a> support to <a href="es/JavaScript">JavaScript</a>. It does this by providing access to the XML document in a form that feels natural for ECMAScript programmers. The goal is to provide an alternative, simpler syntax for accessing XML documents than via <a href="es/DOM">DOM</a> interfaces.
</p><p>E4X is standardized by Ecma International in <a class="external" href="http://www.ecma-international.org/publications/standards/Ecma-357.htm">ECMA-357 standard</a> (currently in its second edition, December 2005).
</p><p>E4X is implemented (at least partially) in <a href="es/SpiderMonkey">SpiderMonkey</a> (<a href="es/Gecko">Gecko</a>'s JavaScript engine) and in <a href="es/Rhino">Rhino</a> (JavaScript engine written in Java).
</p>
<div class="note"><b>Note:</b> In Gecko 1.8 based browsers such as Firefox 1.5, E4X is already partially enabled for web page authors. To fully enable E4X, the <code>&lt;script&gt;</code> element needs to have the MIME type "text/javascript;e4x=1" (i.e. have an attribute of the form <code>type="text/javascript;e4x=1"</code>). The difference between the two modes is that without the "e4x=1" MIME type, any statement-level XML/HTML comment literals (<code><span class="plain">&lt;!--...--&gt;</span></code>) are ignored for backwards compatibility with the comment hiding trick, and CDATA sections (<code>&lt;![CDATA{{mediawiki.external('...')}}]&gt;</code>) are not parsed as CDATA literals (which leads to a JS syntax error in HTML since HTML's <code>&lt;script&gt;</code> element produces an implicit CDATA section, and therefore cannot contain explicit CDATA sections).
<p><span class="comment">someone verify the above</span>
</p>
</div>
<h3 name="Known_bugs_and_limitations"> Known bugs and limitations </h3>
<ul><li> It is not currently possible to access a DOM object through E4X ({{template.Bug(270553)}})
</li><li> E4X doesn't support parsing XML declaration (<code>&lt;?xml version=...?&gt;</code>) (see {{template.Bug(336551)}}). You may get SyntaxError "xml is a reserved identifier" (despite the XML being in a string).
</li></ul>
<p>Workaround:
</p>
<pre class="eval">var response = xmlhttprequest.responseText; // bug 270553
response = response.replace('&lt;?xml version="1.0"?&gt;', ""); // bug 336551
var e4x = new XML(response);
</pre>
<h3 name="Resources"> Resources </h3>
<ul><li> See the list of <a href="Special:Tags?tag=E4X&amp;language=es">E4X-related pages</a> on MDC.
</li><li> <a class="external" href="http://www.ecma-international.org/publications/standards/Ecma-357.htm">ECMA-357 standard</a>
</li><li> <a class="external" href="http://developer.mozilla.org/presentations/xtech2005/e4x/">Brendan's presentation</a>
</li><li> <a class="external" href="http://www.faqts.com/knowledge_base/index.phtml/fid/1762">E4X at faqts.com</a>
</li></ul>
{{ wiki.languages( { "it": "it/E4X", "fr": "fr/E4X", "ja": "ja/E4X", "ko": "ko/E4X", "pl": "pl/E4X" } ) }}
Revertir a esta revisión