by Rahul Kumar Gupta
Dec 15, 2006
Page 4 of 4
Global Methods and Properties
Table 7 lists namespace global methods and properties with their descriptions and accompanying examples.
If ignoreComments is true, XML comments are ignored when constructing new XML objects.
XML.ignoreComments = false; var xmlElement = <author> <!-- info line --> Rahul Gupta </author>; for each (var xmlElements in xmlElement.*) alert(" Element = "+ xmlElements);
If ignoreProcessingInstructions is true, XML-processing instructions are ignored when constructing new XML objects.
XML.ignoreProcessingInstructions= false; var xmlElement = <publishing> <?process author="yes"?> <author type="freelance">Rahul Gupta </author> </publishing>; for each (var xmlElements in xmlElement.*) alert(" Element = "+ xmlElements);
If ignoreWhitespace is true, insignificant whitespace characters are ignored when processing or constructing new XML objects. Whitespace characters are defined to be space (\u0020), carriage return (\u000D), line feed (\u000A), and tab (\u0009).
Advantages and Limitations of E4X
One more ECMAScript technique for handling XML is object mapping. You can map XML data onto a set of ECMAScript objects, manipulate those objects directly, and then map them back to XML. This approach has the advantage of allowing ECMAScript programmers to use their existing knowledge, but it has some problems. For example, an ECMA native object can't preserve the order of the original XML data. As E4X evolves, this approach will mature and become standardized. Table 8 summarizes the advantages and limitations of E4X.
As of now (Nov. 2006), Mozilla, FireFox 1.1 +, and Safari provide limited support. IE7 doesn't support E4X, but it is becoming standard so in future all browser should support it.
In general, the size of the code you produce when using E4X for a requirement tends to be smaller than the code generated with other XML-related technologies.
Both development and maintenance costs are lower than other related technologies such as XSLT, XML queries, or DOM routines.
E4X is lighter weight than similar technologies so it has better performance.
Table 8. Advantages and Limitations of E4X
The author wishes to thank his colleagues Mr. Saurabh Bhatnagar, Tarun Gera, and Sumit Gupta for their valuable contributions as reviewers for this article.
Rahul Kumar Gupta has more than nine years' experience in the IT industry, particularly working with EAI, J2EE, design patterns, UML Java, RMI, Servlets, JSP, application servers, C, CORBA, WAP, and J2ME. He currently works with Indian IT company HCL Technologies Limited, NOIDA (India).