hey i have an xml file thats used by a few of my ASP.NET pages and i want to use the same data in PHP.
my XML file is
And i want to return an array of <link></link> but i can only seem to print out just the values.
PHP Code:
<?
$open_stack = array();
$parser = xml_parser_create();
xml_set_element_handler($parser,"start_handler","end_handler");
xml_set_character_data_handler($parser,"character_handler");
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parse($parser,implode('',file("article.xml"))) or die(format_error($parser));
xml_parser_free($parser);
$data = array();
function start_handler($p,$name,$atts){
global $open_stack;
$open_stack[] = array($name,"");
}
function character_handler($p,$txt){
global $open_stack;
$cur_index = count($open_stack)-1;
$open_stack[$cur_index][1].=$txt;
}
function end_handler($p,$name){
global $open_stack;
$el = array_pop($open_stack);
/*i think its something to do with this seciton but im not sure */
if($name =="Title")
print "<b>$el[1]</b><br/>";
if($name=="URL"){
print "<i>$el[1]</i><p>";
}
}
function format_error($p){
$code = xml_get_error_code($p);
$str = xml_error_string($p);
$line = xml_get_current_line_number($p);
return "XML ERROR ($code): $str at line $line";
}
?>
really confused about it and want to learn how to use XML in php properly. Thanks