
237
9
Integrating XML into JavaScript
ExtendScript defines the XML object, which allows you to process XML with your JavaScript scripts. This
feature offers a subset of the functionality specified by the ECMA-357 specification (E4X). For more
information on this standard, see:
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-357.pdf
The XML Object
The XML object represents an XML element node in an XML tree. The topmost XML object for an XML file
represents the root node. It acts as a list, which contains additional
XML objects for each element. These in
turn contain
XML objects for their own member elements, and so on.
The child elements of an element tree are available as properties of the
XML object for the parent. The
name of the property corresponds to the name of the element. Each property contains an array of
XML
objects, each of which represents one element of the named type.
For example, suppose you have the following, minimal XML code:
<rootElement>
<elementA>
<elementB></elementB>
</elementA>
<elementA>
<elementB></elementB>
</elementA>
</rootElement>
In a JavaScript script, the XML object that you create from this XML code represents the root element:
var myRoot = new XML ( "<rootElement> <elementA> <elementB></elementB> </elementA>
<elementA> <elementB></elementB> </elementA>
</rootElement>");
You can assign a constant to an XML value directly. The following implicitly creates the XML object
assigned to
myRoot:
var myRoot = <rootElement>
<elementA>
<elementB></elementB>
</elementA>
<elementA>
<elementB></elementB>
</elementA>
</rootElement> ;
The object myRoot contains a property named elementA, which contains two XML objects for the two
instances of that element. Each of these, in turn, contains an
elementB property, which contains one
empty
XML object:
var elemB1 = myRoot.elementA[0].elementB[0];
Comentários a estes Manuais