ag har följande kodphp och xml....
<code>
<?php
function startElement($parser, $name, $attrs=''){
global $artikelnummer,$current_tag;
$current_tag=$name;
switch($name){
case 'MAST':
$artikelnummer[$attrs['ARTIKELNUMMER']]=$attrs['URL'];
break;
default:
break;
}
}
function endElement($parser, $name, $attrs=''){
global $current_tag;
switch($name){
default:
break;
}
}
function characterData($parser, $data){
global $current_tag;
switch($current_tag){
default:
break;
}
}
$xml_file = 'mast.xml'; // Du kan anv?nda en URL h?r om du vill (och om din PHP-konfiguration till?ter;)
$type = 'UTF-8';
$xml_parser = xml_parser_create($type);
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
xml_set_element_handler($xml_parser, 'startElement','endElement');
xml_set_character_data_handler($xml_parser, 'characterData');
if (!($fp = fopen($xml_file, 'r'))) {
die("Could not open $xml_file for parsing!\n");
}
$current_index=0;
while ($data = fread($fp, 4096)) {
if (!($data = utf8_encode($data))) {
echo 'ERROR'."\n";
}
if (!xml_parse($xml_parser, $data, feof($fp))) {
die("XML error".xml_error_string(xml_get_error_code($xml_parser)));
}
}
xml_parser_free($xml_parser);
echo '<table border="1">';
foreach ( $artikelnummer as $key => $value ) {
echo "<tr>";
echo "<td>$key</td>";
echo "<td>$value</td>";
echo "</tr>\n";
}
echo'</table><hr>';
?>
</code>
till följande xml-fil:
<code>
<master>
<mast artikelnummer="7772030" url="/parkstolpar_varm.html"/>
<mast artikelnummer="7772031" url="/parkstolpar_kall.html"/>
</master>
</code>
Men jag får detta felmess:
XML errornot well-formed (invalid token)
Nån som vill hjälpa mig?
mvh icaaq