Forum Moderators: coopster
For example in this code, what should I do to get the info in the media node:
<media:player url="http://youtube.com/?v=hjlQfMECSdA"/>
<media:thumbnail url="http://sjl-static10.sjl.youtube.com/vi/hjlQfMECSdA/2.jpg" width="120" height="90"/>
thanks!
File: xml_parser.inc
<?php
//////////////////////////////////////////////////////////////
// //
//XML Parser (PHP 4, PHP 5) //
// //
// -------------------------------------------------------- //
// //
// Parameters: //
// $xmllink //
// //
// Accepted Arguments: //
// $xmllink = "example_records/example_page_data.xml"; //
//parsexml($xmllink); //
// //
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
// Note: This code was written by me (Mr Michael Hurt) utilizing //
// examples found on the official PHP website and the aid of //
// expertise provided by members of webmasterworld.com. The use of //
// this code is only permitted so long as this notice remains intact //
// and is not removed or altered. This code is concidered community //
// software and cannot be licenced or restricted in any way shape or //
// form. //
//////////////////////////////////////////////////////////////
// Create Stack
function startTag($parser, $name, $attrs) {
global $stack;
$tag = array("name" => $name, "attrs" => $attrs);
array_push($stack, $tag);
}
function cdata($parser, $cdata) {
global $stack;
$stack[count($stack)-1]['cdata'] .= $cdata;
}
function endTag($parser, $name) {
global $stack;
$stack[count($stack)-2]['children'][] = $stack[count($stack)-1];
array_pop($stack);
}
// Parse XML
function parsexml($xmllink) {
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "cdata");
$data = xml_parse($xml_parser,file_get_contents($xmllink));
if(!$data) die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
xml_parser_free($xml_parser);
}
?>
<?php
//////////////////////////////////////////////////////////////
// //
// Stack Sorter (PHP 4, PHP 5) //
// XML Content Management System //
// //
// -------------------------------------------------------- //
// //
// Parameters: //
// $stack //
// //
// Accepted Arguments: //
// $container = sortStack($stack); //
// //
// Return Type: //
// Multi-Dimensional Array (index/assoc) //
// //
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
// Note: This code was written by me (Mr Michael Hurt) utilizing //
// examples found on the official PHP website and the aid of //
// expertise provided by members of webmasterworld.com. The use of //
// this code is only permitted so long as this notice remains intact //
// and is not removed or altered. This code is concidered community //
// software and cannot be licenced or restricted in any way shape or //
// form. //
//////////////////////////////////////////////////////////////
// Sort Stack
function sortStack($stack) {
$container = array();
$count1 = 0;
$count2 = 0;
$keyTest1 = 0;
$keyTest2 = 0;
$sample = "";
// Detect Duplicate Keys
function checkKeys($sample, $testString) {
$i=0;
for ($x=0; $x<sizeof($sample); $x++) {
if ($sample[$x][name] == $testString) {
$i++;
}
}
if ($i > 1) {
return true;
}
else {
return false;
}
}
// Store Tags and Data
for($i = 0; $i < sizeof($stack[0][children]); $i++) {
$valname = $stack[0][children][$i][name];
for($x = 0; $x < sizeof($stack[0][children][$i][children]); $x++) {
$valname2 = $stack[0][children][$i][children][$x][name];
// detect duplicate keys
$sample = $stack[0][children];
$keyTest1 = checkKeys($sample, $valname);
if ($keyTest1 == true) {
$container[strtolower($valname)][$count1][$valname2] = $stack[0][children][$i][children][$x][cdata];
}
else {
$container[strtolower($valname)][$valname2] = $stack[0][children][$i][children][$x][cdata];
}
for($y = 0; $y < sizeof($stack[0][children][$i][children][$x][children]); $y++) {
$valname3 = $stack[0][children][$i][children][$x][children][$y][name];
// detect duplicate keys
$sample = $stack[0][children][$i][children];
$keyTest2 = checkKeys($sample, $valname2);
if ($keyTest2 == true) {
$container[strtolower($valname2)][$count2][$valname3] = $stack[0][children][$i][children][$x][children][$y][cdata];
}
else {
$container[strtolower($valname2)][$valname3] = $stack[0][children][$i][children][$x][children][$y][cdata];
}
}
if ($keyTest2 == true) {
$count2++;
}
}
if ($keyTest1 == true) {
$count1++;
}
}
return $container;
}
?>