Download presentation
Presentation is loading. Please wait.
Published byLynette Jones Modified over 8 years ago
1
CSD 340 (Blum)1 Making and Reading from XML Files Chapter 14 of Beginning JavaScript (Paul Wilton)
2
CSD 340 (Blum)2 File/New/File
3
CSD 340 (Blum)3 Choose an XML File template and click Open
4
CSD 340 (Blum)4 Start of XML File
5
CSD 340 (Blum)5 Design tags and enter data.
6
CSD 340 (Blum)6 In the Data view
7
CSD 340 (Blum)7 Save file.
8
CSD 340 (Blum)8 Saving File
9
CSD 340 (Blum)9 Enter more data and save
10
CSD 340 (Blum)10 State Capital Quiz design
11
CSD 340 (Blum)11 Code for reading XML file for State data and initializing arrays
12
CSD 340 (Blum)12 Declare and instantiate arrays for state names and capitals var QUIZ_SIZE=5; var MyStateName = new Array(50); var MyStateCapital = new Array(50);
13
CSD 340 (Blum)13 //loads data from xml file into the arrays (IE only) function LoadStateArray() { var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = false; xmlDoc.load("States.xml"); Declare and instantiate and ActiveX that can parse an XML file. Setting the async property to false means that the code has to wait for a response. Since the next line of code is about loading the xml file, that is what we are waiting for. Load the XML file.
14
CSD 340 (Blum)14 Webopedia definition of ActiveX
15
CSD 340 (Blum)15 Webopedia definition of asynchronous
16
CSD 340 (Blum)16 for(i=0; i< xmlDoc.getElementsByTagName("state").length; i++) { MyStateName[i] = xmlDoc.getElementsByTagName("state")[i].getElementsByTagNam e("stateName")[0].firstChild.nodeValue; MyStateCapital[i] = xmlDoc.getElementsByTagName("state")[i].getElementsByTagNam e("stateCapital")[0].firstChild.nodeValue; } //end of for loop } //end of function Loop through the “state” elements. Initialize the elements of the arrays from the data in the XML file.
17
CSD 340 (Blum)17 Whatis definition of tree
18
CSD 340 (Blum)18 References Beginning JavaScript, Paul Wilton http://www.webopedia.com http://www.whatis.com
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.