Using the XML Parser Xtra
545
The following Lingo statement uses the
makeList()
command to convert the parsed data to a
property list:
theList = gParserObject.makeList()
If you choose to make a property list with the
makeList()
command, 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 statements that create a property list from a string of XML data would look
like the following example:
global gParserObject
gParserObject = new(xtra "xmlparser")
errCode = gParserObject.parseString(member("XMLtext").text)
theList = gParserObject.makeList()
After this code has been executed, the variable
gParserObject
contains the parsed node structure
of the XML document, and the variable
theList
is a property list that contains all the
information in the document broken into property name and value pairs. All the regular Lingo
commands and functions for sorting and accessing lists can work normally with
theList
.
Using XML document nodes
The XML document can contain different types of nodes. Each node can contain different kinds
of data, depending on the node type. You should check the node type before accessing its data so
you know what type of data to expect. Nodes are read-only, so you can retrieve the type, but you
cannot set it.
Содержание DIRECTOR MX-USING DIRECTOR MX
Страница 1: ...Using Director MX Macromedia Director MX...
Страница 12: ...Contents 12...
Страница 156: ...Chapter 4 156...
Страница 202: ...Chapter 6 202...
Страница 244: ...Chapter 7 244...
Страница 292: ...Chapter 10 292...
Страница 330: ...Chapter 12 330...
Страница 356: ...Chapter 13 356...
Страница 372: ...Chapter 14 372...
Страница 442: ...Chapter 16 442...
Страница 472: ...Chapter 18 472...
Страница 520: ...Chapter 19 520...
Страница 536: ...Chapter 20 536...
Страница 562: ...Chapter 23 562...
Страница 566: ...Chapter 24 566...
Страница 602: ...Chapter 27 602...