O'Reilly logo

Moodle JavaScript Cookbook by Alastair Hole

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing XML with DataSource

Many websites and web services make data available in XML format (as RSS, for example). In this recipe, will load an XML file, parse the contents, and display it within a text box.

How to do it...

  1. In this example, we will use the following three files:
    • data.xml: A very simple example XML data file with the following contents:
    <?xml version="1.0" encoding="UTF-8" ?>
    <list>
    <item>Item One</item>
    <item>Item Two</item>
    <item>Item Three</item>
    <item>Item Four</item>
    <item>Item Five</item>
    <item>Item Six</item>
    <item>Item Seven</item>
    <item>Item Eight</item>
    <item>Item Nine</item>
    <item>Item Ten</item>
    </list>
    
    • datasource_xml.php: A PHP page with an input button for initiating the request and a text area to display the results: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required