Mam taki maly problem z XML Pareser :/
otoż skożystałem z manuala dodalem co potrzebne zeby generowalo mi plik RDF+XML i postanowilem odczytac zawartosc pliku XML, nie stety mimo że plik po niekąd odzczytało poprawnie (bez błedów) to błędy sie pojawiły - złamało szyk danych dzielac dane na pol po napotkaniu na symbol kodowany w utf-8 :/
<?php class Parser { var $att, $name, $title, $about, $description, $date, $index=0, $xml_parser, $tab, $tagname; function parser($file) { $this->xml_parser = xml_parser_create("UTF-8"); xml_set_object($this->xml_parser,$this); xml_set_element_handler($this->xml_parser, "startElement", "endElement"); xml_set_character_data_handler($this->xml_parser, 'elementContent'); xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, TRUE); xml_parser_set_option($this->xml_parser, XML_OPTION_SKIP_WHITE, TRUE); xml_parser_set_option($this->xml_parser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); } xml_error_string(xml_get_error_code($this->xml_parser)), xml_get_current_line_number($this->xml_parser))); } } xml_parser_free($this->xml_parser); } function startElement($parser, $name, $attrs) { $this->att[$this->index++]=$name; $this->tagname=$name; } function elementContent($parser, $data) { switch ($this->tagname){ case 'NAME' : $this->name[]=$data; break; case 'TITLE' : $this->title[]=$data; break; case 'ABOUT' : $this->about[]=$data; break; case 'DESCRIPTION' : $this->description[]=$data; break; case 'DATE' : $this->date[]=$data; break; } } function endElement($parser, $name){ $this->tagname==""; } function table(){ for ($i=0;$i<=($this->xml_parser);$i++){ $this->tab[$this->name[$i]]['name'] = $this->name[$i]; $this->tab[$this->name[$i]]['title'] = $this->title[$i]; $this->tab[$this->name[$i]]['about'] = $this->about[$i]; $this->tab[$this->name[$i]]['description'] = $this->description[$i]; $this->tab[$this->name[$i]]['date'] = $this->date[$i]; } return $this->tab; } function rdf_creator($site,$xhtml){ $tabs = $this->table(); $this->rdf .= '<?xml version="1.0"?>'."\n"; $this->rdf .= '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc= "http://purl.org/dc/elements/1.1/">'."\n"; $this->rdf .= '<rdf:Description rdf:about="'.$tabs[$site]['about'].'">'."\n"; $this->rdf .= '<dc:title>'.utf8_encode($tabs[$site]['title']).'</dc:title>'."\n"; $this->rdf .= '<dc:description>'.$tabs[$site]['description'].'</dc:description>'."\n"; $this->rdf .= '<dc:publisher>Refsnes Data as</dc:publisher>'."\n"; $this->rdf .= '<dc:date>'.$tabs[$site]['date'].'</dc:date>'."\n"; $this->rdf .= '<dc:type>Web Development</dc:type>'."\n"; $this->rdf .= '<dc:format>'.(($xhtml) ? "application/xhtml+xml" : "text/html").'</dc:format>'."\n"; $this->rdf .= '<dc:language>pl</dc:language>'."\n"; $this->rdf .= '</rdf:Description>'."\n"; $this->rdf .= '</rdf:RDF>'."\n"; } } ?>
oto plik xml
<?xml version="1.0" encoding="utf-8"?> <rdfmap> <site> <name>main</name> <title>połamalo dane1</title> <about>http://www.example.pl/index.html</about> <description>home</description> <date>2008-07-13</date> </site> <site> <name>kasy</name> <title>połamalo dane2</title> <about>http://www.example.pl/kasy.html</about> <description>kasy fdfd fł</description> <date>2008-07-13</date> </site> <site> <name>zestawy</name> <title>połamalo dane3</title> <about>http://www.example.pl/zestawy.html</about> <description>zestawy</description> <date>2008-07-13</date> </site> <site> <name>o nas</name> <title>połamalo dane4</title> <about>http://www.example.pl/onas.html</about> <description>onas</description> <date>2008-07-13</date> </site> </rdfmap>
tablica wynikowa powinna być :
Kod
Array(
[main] => Array(
[name] => main
[title] => połamalo dane1
[about] => http://www.example.pl/index.html
[description] => home
[date] => 2008-07-13
)
[kasy] => Array (
[name] => kasy
[title] => połamalo dane2
[about] => http://www.example.pl/kasy.html
[description] => kasy
[date] => 2008-07-13
)
....
)
[main] => Array(
[name] => main
[title] => połamalo dane1
[about] => http://www.example.pl/index.html
[description] => home
[date] => 2008-07-13
)
[kasy] => Array (
[name] => kasy
[title] => połamalo dane2
[about] => http://www.example.pl/kasy.html
[description] => kasy
[date] => 2008-07-13
)
....
)
a jest:
Kod
Array(
[main] => Array(
[name] => main
[title] => po <- brak dalszej czesci :/ przezucilo da do kolejnego elementu tablicy
[about] => http://www.example.pl/index.html
[description] => home
[date] => 2008-07-13
)
[kasy] => Array (
[name] => kasy
[title] => łamalo dane1 < dalszy ciąg danych a powinno być co innego :/
[about] => http://www.example.pl/kasy.html
[description] => kasy
[date] => 2008-07-13
)
....
)
[main] => Array(
[name] => main
[title] => po <- brak dalszej czesci :/ przezucilo da do kolejnego elementu tablicy
[about] => http://www.example.pl/index.html
[description] => home
[date] => 2008-07-13
)
[kasy] => Array (
[name] => kasy
[title] => łamalo dane1 < dalszy ciąg danych a powinno być co innego :/
[about] => http://www.example.pl/kasy.html
[description] => kasy
[date] => 2008-07-13
)
....
)
ma ktos pomysl jak to naprawić?