XML - E4X
E4X adds direct support for XML to JavaScript.
E4X Example
var employees=
;
document.write(employees.person.(name == "Tove").age);
This example only works in Firefox!
XML as a JavaScript Object
E4X is an official JavaScript standard that adds direct support for XML.
With E4X, you can declare XML object variables in the same way you declare Date or Array object variables:
var x = new XML()
var y = new Date()
var z = new Array()
E4X is an ECMAScript (JavaScript) standard
ECMAScript is the official name of JavaScript. ECMA-262 (JavaScript 1.3) was standardized in December 1999.
E4X is an extension to JavaScript that adds direct support for XML. ECMA-357 (E4X) was standardized in June 2004.
The ECMA organization (founded in 1961) is dedicated to standardization in information and communication technology (ICT) and consumer electronics (CE). The standards established by ECMA include:
- JavaScript
- C# Language
- International character sets
- Optical Discs
- Magnetic Tapes
- Data compression
- Data Communication
- And so on...
Without Using E4X
The following example is a cross-browser example that loads an existing XML document ("note.xml") into an XML parser and displays the message description:
Example
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 »
Using 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);
Much simpler, isn't it?
Browser support
Firefox is currently the only browser with fairly good support for E4X.
Currently, there are no browsers supporting E4X, including Opera、Chrome or Safari。
So far, there are no signs of E4X support in Internet Explorer either.
The Future of E4X
E4X has not gained widespread support. Perhaps it offers too few practical features and has not yet been addressed by other solutions: