1 / 18

Making and Reading from XML Files

Making and Reading from XML Files. Chapter 14 of Beginning JavaScript (Paul Wilton). File/New/File. Choose an XML File template and click Open. Start of XML File. Design tags and enter data. In the Data view. Save file. Saving File. Enter more data and save. State Capital Quiz design.

Download Presentation

Making and Reading from XML Files

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Making and Reading from XML Files Chapter 14 of Beginning JavaScript (Paul Wilton)

  2. File/New/File

  3. Choose an XML File template and click Open

  4. Start of XML File

  5. Design tags and enter data.

  6. In the Data view

  7. Save file.

  8. Saving File

  9. Enter more data and save

  10. State Capital Quiz design

  11. Code for reading XML file for State data and initializing arrays

  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. //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. Webopedia definition of ActiveX

  15. Webopedia definition of asynchronous

  16. for(i=0; i< xmlDoc.getElementsByTagName("state").length; i++) { MyStateName[i] = xmlDoc.getElementsByTagName("state")[i].getElementsByTagName("stateName")[0].firstChild.nodeValue; MyStateCapital[i] = xmlDoc.getElementsByTagName("state")[i].getElementsByTagName("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. Whatis definition of tree

  18. References • Beginning JavaScript, Paul Wilton • http://www.webopedia.com • http://www.whatis.com

More Related