Yeah, E4X Can Do (Some Of) That

| | Comments (0) | TrackBacks (0)

Some interesting comments on E4X. I agree with some of the points, at least the ones I understand. And of the ones I do understand, some can be implemented this way.

In brief, you can use an XMLList as a container, literally its <></>. There is a toXMLString(), and you can set properties on the xml object to change how it is serialized. Lastly, elements can be created using the bracket inclusion mechanism. Also works for attributes and attribute values.

The code:

function buildItems() {
  return <>
           <item>Hello</item>
           <item>World!</item>
         </>;
}
var doc = <mydocument>{buildItems()}</mydocument>;

print( "appended child elements")
print( doc );

print();
print( "to xml string")
print( doc.toXMLString() );

var foo = "foo";

doc.item += <{foo}/>

print();
print( "dyanmic element creation??")
print( doc );

The output:

  appended child elements
  <mydocument>
    <item>Hello</item>
    <item>World!</item>
  </mydocument>

  to xml string
  <mydocument>
    <item>Hello</item>
    <item>World!</item>
  </mydocument>

  dyanmic element creation??
  <mydocument>
    <item>Hello</item>
    <item>World!</item>
    <foo/>
  </mydocument>

Also see Deciphering E4X and the 1060 E4X Tutorial.

0 TrackBacks

Listed below are links to blogs that reference this entry: Yeah, E4X Can Do (Some Of) That.

TrackBack URL for this entry: http://www.manamplified.org/cgi-bin/mt-tb.cgi/320

Leave a comment