
Using XML parser objects
421
The following example shows a short XML document:
<?xml version="1.0"?>
<e1><tagName attr1="val1" attr2="val2"/><e2>element 2</e2><e3>element 3</e3>
</e1>
The following example is the same XML with its tree structure shown more clearly:
<?xml version="1.0"?>
<e1>
<tagName attr1="val1" attr2="val2"/>
<e2>element 2</e2>
<e3>element 3</e3>
</e1>
There are two ways to access a parsed XML document. You can use the
makeList()
method to
convert the document into a nested property list and use the list-access methods of Lingo or
JavaScript syntax, or you can use the special script methods of XML Parser Xtra to access the
parsed data directly.
The following script statement uses the
makeList()
method to convert the parsed data to a
property list:
theList = gParserObject.makeList()
If you choose to make a property list with the
makeList()
method, the result is a nested property
list, reflecting the tree structure of the XML.
Each element in the document is represented by its own property list, with another property list
for each child element that it contains. The name of the element is the property name, and the
content of the element is the property value. Attributes of an element are stored in a child list with
the name !ATTRIBUTES. The property list of attributes contains the name of each attribute and
its value. Character data has the property name !CHARDATA, and the value is the string
representation of the character data. A processing instruction is a property with the name
!PROCINST; its value is another two-element property list. The first property of this sublist is
NAME, and the value is the string that represents the name of the processing instruction. The
second property of the sublist has the name TEXT and contains the rest of the text in the
processing instruction.
The property list resulting from the previous XML example would look like the following code:
["ROOT OF XML DOCUMENT": ["!ATTRIBUTES": [:], "e1": ["!ATTRIBUTES": [:],
"tagName": ["!ATTRIBUTES": ["attr1": "val1", "attr2": "val2"]], "e2":
["!ATTRIBUTES": [:], "!CHARDATA": "element 2"], "e3": ["!ATTRIBUTES": [:],
"!CHARDATA": "element 3"]]]]
The following example is the same property list with its nested structure shown more clearly:
["ROOT OF XML DOCUMENT": ["!ATTRIBUTES": [:],
"e1": ["!ATTRIBUTES": [:],
"tagName": ["!ATTRIBUTES": ["attr1": "val1", "attr2": "val2"]],
"e2": ["!ATTRIBUTES": [:], "!CHARDATA": "element 2"],
"e3": ["!ATTRIBUTES": [:], "!CHARDATA": "element 3"]
]
]]
Together, the Lingo or JavaScript syntax statements that create a property list from a string of
XML data would look like the following examples:
global gParserObject
gParserObject = new(xtra "xmlparser")
Summary of Contents for DIRECTOR MX 2004-USING DIRECTOR
Page 1: ...DIRECTOR MX 2004 Using Director...
Page 16: ...16 Chapter 1 Introduction...
Page 82: ...82 Chapter 3 Sprites...
Page 98: ...98 Chapter 4 Animation...
Page 134: ...134 Chapter 5 Bitmaps...
Page 242: ...242 Chapter 10 Sound and Synchronization...
Page 274: ...274 Chapter 11 Using Digital Video...
Page 290: ...290 Chapter 12 Behaviors...
Page 302: ...302 Chapter 13 Navigation and User Interaction...
Page 334: ...334 Chapter 15 The 3D Cast Member 3D Text and 3D Behaviors...
Page 392: ...392 Chapter 16 Working with Models and Model Resources...
Page 418: ...418 Chapter 18 Movies in a Window...
Page 446: ...446 Chapter 22 Managing and Testing Director Projects...