Why E4X?

E4X makes it easier for us to use XML.

E4X is simpler

If you have ever tried to parse and manipulate XML with JavaScript, you will find E4X easier to use.

Without E4X, you must use an XML library (or XML component) to interact with XML.

The syntax of these libraries or components and how they work in different browsers are all different.

Without E4X

The following example is a browser instance of a cross-batch feature group, which can load an XML document ("note.xml") into an XML parser and display the note messages:

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 Yourself

Using E4X

This example serves the same purpose as the previous example, but uses E4X:

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

Is it not simpler?