XML E4X


May 27, 2021 19:00 XML


Table of contents


XML - E4X


E4X adds direct support for XML to JavaScript.


E4X instance

var employees=
<employees>
<person>
<name>Tove</name>
<age>32</age>
</person>
<person>
<name>Jani</name>
<age>26</age>
</person>
</employees>;

document.write(employees.person.(name == "Tove").age);

This example applies only to Firefox!

Try it out . . .



XML as a JavaScript object

E4X is the official JavaScript standard, with added direct support for XML.

With E4X, you can declare an XML object variable by declaring a Date or Array object variable:

var x = new XML()

var y = new Date()

var z = new Array()

The E4X is an ECMAScript standard

ECMAScript is the official name for JavaScript. EcMA-262 (JavaScript 1.3) was standardized in December 1999.

E4X is an extension of JavaScript that adds direct support for XML. The ECMA-357 (E4X) was standardized in June 2004.

The ECMA Organization (established in 1961) is dedicated to the standardization of information and communications technology (ICT) and consumer electronics (CE). The ECMA standards are:

  • Javascript
  • The language of C
  • The international character set
  • Disc
  • Tape
  • Data compression
  • Communication
  • Wait a minute...

The E4X is not used

The following example is a cross-browser instance that loads an existing XML document ("note.xml") into the XML parser and displays a message description:

var xmlDoc;
//code for Internet Explorer
if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("note.xml");
displaymessage();
}
// code for Mozilla, Firefox, etc.
else (document.implementation && document.implementation.createDocument)
{
xmlDoc= document.implementation.createDocument("","",null);
xmlDoc.load("note.xml");
xmlDoc.onload=displaymessage;
}

function displaymessage()
{
document.write(xmlDoc.getElementsByTagName("body")[0].firstChild.nodeValue);
}

Try it out . . .

Use E4X

The following example is the same as the one above, but uses E4X:

var xmlDoc=new XML();
xmlDoc.load("note.xml");
document.write(xmlDoc.body);

It's much easier, isn't it?


Browser support

Firefox is currently the only browser with better support for E4X.

Opera, Chrome, or Safari are not currently supported by E4X.

So far, there is no indication of E4X support in Internet Explorer.


The future of the E4X

The E4X does not receive widespread support. Perhaps it provides too few practical features to be covered by other solutions: