308 CHAPTER 10 USING FLASH TO DISPLAY XML If a title exists, the code creates a new element and adds an idattribute: var newDVD:XMLNode = oXML.createElement(”DVD”); newDVD.attributes.id = rootNode.childNodes.length + 1; It sets the value of the attribute to one more than the number of elements in the XML tree. The next code block creates a new element and uses appendChild() to add the text from the title_txt component: var newDVDTitle:XMLNode = oXML.createElement(”title”); newDVDTitle.appendChild(oXML.createTextNode(title_txt.text)); newDVD.appendChild(newDVDTitle); The code repeats this process for the
and nodes: if (format_txt.text.length > 0) { var newDVDFormat:XMLNode = oXML.createElement(”format”); newDVDFormat.appendChild(oXML.createTextNode(format_txt.text)); newDVD.appendChild(newDVDFormat); } if (genre_txt.text.length > 0) { var newDVDGenre:XMLNode = oXML.createElement(”genre”); newDVDGenre.appendChild(oXML.createTextNode(genre_txt.text)); newDVD.appendChild(newDVDGenre); } Finally, the code appends the element to the root node, reloads the List component, and clears the values in the text field: rootNode.appendChild(newDVD); loadList(null); clearTextInputs(); Editing an existing node uses a different block of code that s easier to interpret. First, the code finds the child node index for the selected node so it can select the node again after the update: var selectedNodeIndex:Number = Number(selectedDVDNode.attributes.id)-1; Then it checks whether appropriate text has been entered into the TextField component and changes the nodeValue accordingly: if (title_txt.text.length > 0) { selectedDVDNode.childNodes[0].firstChild.nodeValue = title_txt.text; } if (format_txt.text.length > 0) { selectedDVDNode.childNodes[1].firstChild.nodeValue = format_txt.text; } if (genre_txt.text.length > 0) { selectedDVDNode.childNodes[2].firstChild.nodeValue = genre_txt.text; }
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.
This entry was posted
on Friday, November 30th, 2007 at 8:25 pm and is filed under Tomcat.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.