예제 #1
0

<?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
*/
예제 #2
0

<?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/");
echo "\n<h2>\$parser->XML_PullParser_nextElement</h2>\n";
while ($token = $parser->XML_PullParser_getToken()) {
    $date = $parser->XML_PullParser_getElement('date');
    while ($_ns_ = $parser->XML_PullParser_nextElement()) {
        $attr_array = $parser->XML_PullParser_getAttributes($_ns_);
        $text = $parser->XML_PullParser_getAttrVal('month', $attr_array);
        echo "Month: {$text}\n";
    }
}
echo "\n</pre>\n";
/*
Result
The scond month is missing because the month for How Green Was My Valley is not
qualfied by a namespace
Month: Apr
Month:
Month: June
*/
예제 #3
0
<?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
Date: Apr 25 1939
예제 #4
0
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/xtitle/|" . "http://room535.org/movies/mov/|http://room535.org/movies/star/|http://room535.org/movies/dates/");
while ($token = $parser->XML_PullParser_getToken()) {
    // since XML_PullParser_getElement has not been called
    // XML_PullParser_setAttrLoop_elcd will use $token
    $attr_vals = $parser->XML_PullParser_setAttrLoop_elcd();
    while ($at = $parser->XML_PullParser_nextAttr()) {
        if ($at[2]) {
            echo "{$at['0']}: {$at['2']}\n";
        }
        foreach ($at[1] as $attr_name => $attr_value) {
            $name = "";
            if (preg_match('/DAY/i', $attr_name)) {
                $name = "day";
            }
            if (preg_match('/month/i', $attr_name)) {
                $name = "month";
            }
            if ($name) {
                echo "{$name}:  " . $parser->XML_PullParser_getAttrVal($name, $at[1]) . "\n";
            }
            if ($at[0] == 'LEADING_MAN') {
                echo "\n";
            }
        }
    }
}
echo "\n</pre>\n";
예제 #5
0
<?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();
$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 "<pre>\n<h2>XML_PullParser_getAttrValues</h2>\n";
while ($token = $parser->XML_PullParser_getToken()) {
    $attr_vals = $parser->XML_PullParser_setAttrLoop_elcd($token);
    while ($_ns_ = $parser->XML_PullParser_nextAttr()) {
        if ($_ns_[0] == 'DATE') {
            $month = $parser->XML_PullParser_getAttrVal('month', $_ns_[1]);
            $day = $parser->XML_PullParser_getAttrVal('day', $_ns_[1]);
            echo $_ns_[0] . " {$month} {$day} " . $_ns_[2] . "\n";
        } else {
            echo $_ns_[0] . " " . $_ns_[2] . "\n";
        }
    }
    echo "\n";
}
echo "</pre>\n";
/*
Result
This missing items in these results occur where there is no namespace qualifying the element or attribute.

MOVIE
TITLE Gone With The wind