Flash - XML TutorialPower of AttributesSo far we have learnt what childNodes are, XML elements or textnodes. We have learnt what is the relationship to each other: parent, child, firstChild, lastChild, nextSibling or previousSibling. But one element is missing, which is the attribute. Before we go further, we will look at the syntax of the attribute.
<?xml version="1.0"?>
<models>
<susan name="Susan Black" language="german"> //name and language attributes
Susan Black
age: 21
eye color: dark blue
hair color: black
foreign language: german
</susan>
<models>
Attributes are added to nodes and the attribute content is always in quotations. Each attribute of one node should always have its unique name. We should not name Susan Black and german with the same attribute unless we put the text together under one attribute name. How do we parse XML to get to attributes? This is shown in the actionscript below. function listItems(model01){ var fItem = model01.firstChild.attributes; textField1.htmlText=fItem.name; textField2.htmlText = fItem.language; } We just add the attributes property to a node name. If the node has an attribute we have to specify it by naming the attribute as shown here with model01.firstChild.attributes.name. If we want only lower case we add that: model01.firstChild.attributes.name.toLowerCase();. Here is how that little xml file will be parsed by the script as shown.
Before we create our final search engine file we need to learn about the use of HTML in XML and how the flashplayer handles that.
|