XML - E4XE4X 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 only works in Firefox! Try it »XMLE4X as a JavaScript object is the official JavaScript standard that adds direct support for XML. Using E4X, you can declare XML object variables 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 a JavaScript extension that adds direct support for XML. ECMA-357 (E4X) was standardized in June 2004. The ECMA organization (founded in 1961) is dedicated to the standardization of information and communications technology (ICT) and consumer electronics (CE). The standards set by ECMA are: JavaScript, C# language, international character set, compact disk, tape data compression, data communication, etc... E4X is not used. The following example is a cross-browser example. The example loads an existing XML document ("note.xml ") to the XML parser and displays the message Description: Example
var xmlDoc;//code for Internet Explorerif (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 »
The following example is the same example as above, but using E4X:
var xmlDoc=new XML();xmlDoc.load("note.xml");document.write(xmlDoc.body);
Much simpler, isn't it?
Firefox is currently the only browser that supports E4X well.
Currently there is no support for E4X in Opera , Chrome or Safari .
So far, there is no sign of support for E4X in Internet Explorer .
E4X is not widely supported. Perhaps it provides too few practical features and has not yet been covered by other solutions:
For complete XML processing, you also need to learn XML DOM and XPath
For accessing XMLHttpRequests, JSON is the preferred format.
For simple document processing, JQuery is the easier choice.