<?php require_once "XML_PullParser_NS.inc"; XML_PullParser_excludeBlanks(true); XML_PullParser_trimCdata(true); XML_PullParser_excludeBlanksStrict(true); $tags = array("Movie"); $child_tags = array('date', 'title'); $parser = new XML_PullParser_NS("Movies.xml", $tags, $child_tags); $parser->XML_PullParser_setCurrentNS("http://room535.org/movies/title/|" . "http://room535.org/movies/mov/|http://room535.org/movies/star/|http://room535.org/movies/dates/"); echo "\n<h2>XML_PullParser_getAttrValues</h2>\n"; while ($token = $parser->XML_PullParser_getToken()) { $title = $parser->XML_PullParser_getText('title'); $year = $parser->XML_PullParser_getText('date'); $attr_vals = $parser->XML_PullParser_getAttrValues(array('date' => $token)); $month = $parser->XML_PullParser_getAttrVal('month', $attr_vals[0]); $day = $parser->XML_PullParser_getAttrVal('day', $attr_vals[0]); echo "{$title} "; echo "{$month} {$day} {$year}\n"; } /* Result Notice that there is no month or day for How Green Was My Valley. This is because they are not qualfied by a namespace Gone With The wind Apr 25 1939 How Green Was My Valley 1941 Jurassic Park June 15 1993 */
<?php require_once "XML_PullParser_NS.inc"; XML_PullParser_excludeBlanks(true); echo "<pre>\n"; $tags = array("Movie"); $child_tags = array('date'); $parser = new XML_PullParser_NS("Movies.xml", $tags, $child_tags); $parser->XML_PullParser_setCurrentNS("http://room535.org/movies/title/|" . "http://room535.org/movies/mov/|http://room535.org/movies/star/|http://room535.org/movies/dates/"); while ($token = $parser->XML_PullParser_getToken()) { $title = $parser->XML_PullParser_getText('title'); $leading_man = $parser->XML_PullParser_getText('leading_man'); $leading_lady = $parser->XML_PullParser_getText('leading_lady'); $year = $parser->XML_PullParser_getText('date'); $attr_array = $parser->XML_PullParser_getAttributes('date'); $month = $parser->XML_PullParser_getAttrVal('month', $attr_array); $day = $parser->XML_PullParser_getAttrVal('day', $attr_array); echo "Title: {$title}\n"; echo "Date: {$month} {$day} {$year}\n"; echo "Leading Lady: {$leading_lady}\n"; if ($leading_man) { echo "Leading Man: {$leading_man}\n"; } echo "\n\n"; exit; } echo "\n</pre>\n"; /* Result Title: Gone With The wind