Neolane - JavaScript API - v6.1.0

Unknown
Introduction to E4X
E4X is a JavaScript extension that enables you to manipulate XML objects directly in scripts.

This document deals with the most common concepts used. For more information, refer to the ECMA-357 specification: http://www.ecma-international.org/publications/standards/Ecma-357.htm.

XML type
var myXml = <root>
      <item id="1"/>
      <item id="2">
        text
      </item>
    </root>
      
Substitution
var myTag = "delivery"
var myXml = <{myTag} id="42">Hello</{myTag}>

var myValue = "123"
var myXml = <toto id={myValue}>Hello</toto>

var myContent = "Hello"
var myXml = <toto id="123">{myContent}</toto>

var mySubXml = <b>world</b>
var myXml = <toto id="123">Hello {mySubXml}</toto>
      
Accessors
Returns the name of the element
myXml.name()
            

Returns the parent or null

myXml.parent()
            

Access an attribute or text of an element

var myXml =
  <article id="123" operator-id="456">
    <title>Hello</title>
      My Content
  </article>

myXml.@id // "123"
myXml.@['operator-id'] // "456"
myXml.title // "Hello"
      

Test for an attribute or a sub-element.

myXml.attribute('id').length() == 0  // attribute is missing
myXml.child('title').length() == 0   // element is missing
Enumeration
var myXml = <root><item id="1"/><item id="2"/></root>
for each (var x in myXml.item)
  logInfo(x.@id)
      
Insertion
myXml.appendChild(<something id="1"/>blah blah</something>)
      
Search
Retrieve the list of employees named 'John':
var john = e.employee.(name == "John")
      

Retrieve the list of employees with ID 0 or 1:

var twoemployees = e.employee.(@id == 0 || @id == 1)
      

Retrieve the name of employee with identifier 1:

var emp = e.employee.(@id == 1).name
      
Conversion
var str = myXml.toXMLString()
var myXml = new XML(str)
      
Miscellaneous
              typeof(<toto/>) // "xml"

jsapi-en

previous page start next page