YouTip LogoYouTip

Xml E4X

```html XML E4X

XML E4X

-- Learn not only technology, but also dreams!

XML Tutorial

XML JavaScript

Advanced XML

XML - E4X


E4X adds direct support for XML to JavaScript.


E4X Example

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 works only in Firefox!

Try it Β»

XML as a JavaScript Object

E4X is an official JavaScript standard that adds direct support for XML.

Using E4X, you can declare XML object variables in the same way as declaring 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), specializes in standards for information and communications technology (ICT) and consumer electronics (CE). Standards made by ECMA include:

  • JavaScript
  • C# language
  • International character set
  • Optical disc
  • Magnetic tape
  • Data compression
  • Data communication
  • etc...

Without E4X

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

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()
{
docu
```
← Xml SummaryXml Editors β†’