Creating XML

The native XML API that ships with Flash is very rudimentary, including only an XML class and an XMLNode class; using these classes to construct an XML document can be cumbersome as it requires even the creation of text nodes that need to be appended to elements in order to construct a common type of XML document. With ASDK XML, the same document can be constructed with significantly less code due to its developer friendly API. The example below demonstrates creating a simple XML document that represents the colors of a rainbow.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import asdk.xml.*;

var document = new Document();

var rainbow = new Element( "rainbow" );
document.addChild( rainbow );

var colors = new Element( "colors" );
rainbow.addChild( colors );

var purple = new Element( "color", "purple" );
colors.addChild( purple );

var blue = new Element( "color", "blue" );
colors.addChild( blue );

var green = new Element( "color", "green" );
colors.addChild( green );

var yellow = new Element( "color", "yellow" );
colors.addChild( yellow );

var orange = new Element( "color", "orange" );
colors.addChild( orange );

var red = new Element( "color", "red" );
colors.addChild( red );

The example above is straight forward; create a document, create elements and append each node to its parent. Notice, however, that the ASDK XML API does not require creating a separate text node for elements that contain text. Using the standard Flash XML API would require an additional 14 lines of code to create and append text nodes to the raw elements. This significantly reduces the amount of code that is required when constructing a document.