Working with XML and JavaScript Example . writersWF.xml <?xml version="1.0" ?> <!DOCTYPE writers [ <!ELEMENT writers (EnglishLanguage)> <!ELEMENT EnglishLanguage (fiction)> <!ELEMENT fiction (pen)> <!ELEMENT pen (name+)> <!ELEMENT name (#PCDATA)> ]> <writers> <EnglishLanguage> <fiction> <pen> <name>Jane Austin</name> <name>Rex Stout</name> <name>Dashiell Hammett</name> </pen> </fiction> </EnglishLanguage> </writers> 267 Will this new validated file work with the example scripts provided previously? You bet! In all of the previous files showing how JavaScript parses XML files, substitute writersWF.xml for the original writers.xml in this line: <xml ID="writersXML" SRC="writers.xml"></xml> When you re-run the script in IE5+ on your Windows PC, you will see exactly the same results. The only difference is that now your XML file is well formed. XHTML Using XML, HTML, and JavaScript together can be a bit confusing. You might want to take a look at XHTML, where you will find better integration between XML and HTML. XHTML brings well- formed code to HTML. At the same time, you can insert JavaScript into the middle of XHTML pages for adding dynamic action. A good place to start is with XHTML, by Chelsea Valentine and Chris Minnick (New Riders, 2001). Summary To say that this chapter just scratched the surface of XML is an understatement. However, under- standing even a little of how JavaScript and XML work together is a preview of the direction of the W3C DOM and the future of JavaScript. The capability to pull data out of an XML file is a bit easier than pulling it out of a database using PHP, ASP, or CGI as intermediaries. Using server-side Java- Script and a well-formed XML file, you can perform just about anything that you can with files stored in more traditional databases. (Getting data into an XML file and storing it, though, is a horse of a different color.) At the point of this writing, all of JavaScript and the W3C DOM are on the verge of providing a robust language for manipulating data stored in XML files. Designers are encouraged to follow the changes and to see how XML can be used effectively for their clients, and many clients are now demanding the XML structures for their data. Taking some time to learn more about XML is essential for keeping up with all of the changes taking place on the web, especially in storing and retrieving structured data.