308 CHAPTER 10 (Managed web hosting) USING FLASH TO DISPLAY

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<br /> <format> and <genre> 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 <DVD> 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; } <br />Searching for affordable and proven webhost to host and run your servlet applications? Go to <a href="http://linux.g5websitehosting.com">Linux Web Hosting</a> services and you will find it. </p> <p class="postmetadata alt"> <small> This entry was posted on Friday, November 30th, 2007 at 8:25 pm and is filed under <a href="http://www.tomcatjavahosting.com/category/tomcat/" title="View all posts in Tomcat" rel="category tag">Tomcat</a>. You can follow any responses to this entry through the <a href='http://www.tomcatjavahosting.com/tomcat/308-chapter-10-managed-web-hosting-using-flash-to-display/feed/'>RSS 2.0</a> feed. You can <a href="#respond">leave a response</a>, or <a href="http://www.tomcatjavahosting.com/tomcat/308-chapter-10-managed-web-hosting-using-flash-to-display/trackback/" rel="trackback">trackback</a> from your own site. </small> </p> </div> </div> <!-- You can start editing here. --> <!-- If comments are open, but there are no comments. --> <h3 id="respond">Leave a Reply</h3> <form action="http://www.tomcatjavahosting.com/wp-comments-post.php" method="post" id="commentform"> <p><input type="text" name="author" id="author" value="" size="22" tabindex="1" /> <label for="author"><small>Name (required)</small></label></p> <p><input type="text" name="email" id="email" value="" size="22" tabindex="2" /> <label for="email"><small>Mail (will not be published) (required)</small></label></p> <p><input type="text" name="url" id="url" value="" size="22" tabindex="3" /> <label for="url"><small>Website</small></label></p> <!--<p><small><strong>XHTML:</strong> You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> </small></p>--> <p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p> <p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" /> <input type="hidden" name="comment_post_ID" value="389" /> </p> </form> </div> <hr /> <div id="footer"> <!-- If you'd like to support WordPress, having the "powered by" link someone on your blog is the best way, it's our only promotion or advertising. --> <p> Java Web Hosting, Subdomain, Vps Hosting, Cpanel, Programming Blog is proudly powered by <a href="http://www.visionwebhosting.net/">cheap hosting</a> <br /><a href="feed:http://www.tomcatjavahosting.com/feed/">Entries (RSS)</a> and <a href="feed:http://www.tomcatjavahosting.com/comments/feed/">Comments (RSS)</a>. <!-- 22 queries. 0.052 seconds. --> </p> </div> </div> <!-- Gorgeous design by Michael Heilemann - http://binarybonsai.com/kubrick/ --> </body> </html>