286 CHAPTER 9 STATE NAVIGATION PATTERN else (Web design course)

286 CHAPTER 9 STATE NAVIGATION PATTERN else if( element.nodeName == “element”) { if( objData.formNode != null) { var elementIdentifier = element.attributes.getNamedItem( “id”).nodeValue; if( element.childNodes[ 0] != null) { var elementValue = element.childNodes[ 0].nodeValue; objData.formNode.elements[ elementIdentifier].value = elementValue; } } } } }, loadForm : function( xmlState) { this.verify = this.extractFormData; var objData = new Object(); XMLIterateElements( this, objData, xmlState); }, The implementation of the method loadFormis relatively Spartan, and is used to prepare the iteration of the XML file by using the standard function XMLIterateElementsand the user- defined function extractFormData. The assignment of the this.verify method is used to determine whether an iterated XML element is of interest to the user. The creation of the objDatavariable is required for the function XMLIterateElements and will contain the found data. The combination of objData and the this.verify method deserialize XML content into JavaScript data members. The function XMLIterateElements is used to process an XML file and is implemented as follows: function XMLIterateElements( objVerify, objData, element) { objVerify.verify( element, objData); for( var i = 0; i < element.childNodes.length; i ++) { XMLIterateElements( objVerify, objData, element.childNodes[ i]); } } The function XMLIterateElements has three parameters. The parameter objVerify is an object instance that is called to process an XML element. The parameter objData is a data object that is manipulated by the objVerify.verify method. An object instance is used so that a verify implementation can access the data members of a current object instance. The parameter element represents an XML node. After having called the objVerify.verify method, the child nodes of the element XML node are iterated, and for every iteration the function XMLIterateElementsis called recursively. The result is that for each and every element, the method objVerify.verify is called. The purpose of objData is to allow the method objVerify. verify to assign some data members that can be referenced at some later point, during and after the iteration of all the XML elements. Let s look back at the implementation of loadForm. Notice that it is calling the function XMLIterateElements and that the objVerify.verify method refers to the method extractFormData. Looking at the implementation of extractFormData, you can see that a
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Leave a Reply