IS 337: Website Administration

Lecture for November 10: Data from XML

+
-

Topics

Storing Data

  • Observe: Urlacher's inventory not in session.
  • Could it?

Storing Data in XML

  • You're in charge! toggle
    • You get to make up the tags in the XML.
    • You get to specify the xpaths to get data.
  • XML support built into PHP. toggle
    • SimpleXML
    • XMLReader, XMLWriter
    • XSL, XSLT

OOP in PHP

  • PHP is an object-oriented language (PHP 5 much more so).
  • Creating an object: new ClassName($args)
  • Accessing methods: $o->method($args)

SimpleXML

  • simplexml_load_file($filename)
  • new SimpleXMLElement($xmlstr)
  • $simple_xml->xpath($xpath)
  • Magically use element names! toggle
    • $simple_xml->element
    • $simple_xml->{'element'}
  • Elements that occur more than once magically turn into arrays!

Readings and Resources

Quick Written Assignment for Next Time

Suppose $xml holds a SimpleXML object. Write a foreach loop that loops over the course elements (directly under the root) and prints the title element of each course.

Creative © 2007 Calvin College and Jeremy D. Frens.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.