Autor Zpráva
aNonym
Profil *
zdar lidičky mam problem z parsovanim xml kod:
<?php
$file = "data.xml";
$map_array = array(
    "BOLD"     => "B",
    "EMPHASIS" => "I",
    "LITERAL"  => "TT"
);

function startElement($parser, $name, $attrs) 
{
    global $map_array;
    if (isset($map_array[$name])) {
        echo "<$map_array[$name]>";
    }
}

function endElement($parser, $name) 
{
    global $map_array;
    if (isset($map_array[$name])) {
        echo "</$map_array[$name]>";
    }
}

function characterData($parser, $data) 
{
    echo $data;
}

$xml_parser = xml_parser_create();
// use case-folding so we are sure to find the tag in $map_array
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
    die("could not open XML input");
}

while ($data = fread($fp, 4096)) {
    if (!xml_parse($xml_parser, $data, feof($fp))) {
        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);
?> 


vypis : text Bold XML error: junk after document element at line 2

teda z prveho tagu načita text ale dalej to nejde (kod je priamo z php.net )
nightfish
Profil
XML error: junk after document element at line 2
a ukázka toho dokumentu by nebyla? případně proč nepoužít simplexml?
aNonym
Profil *
dokument je uplne banalny
<BOLD> toto </BOLD>
<EMPHASIS> no tak toto </EMPHASIS>
<LITERAL> isufgh iusefiu sefi </LITERAL>


na ten simplexml sa mrknem
nightfish
Profil
aNonym
tohle ale není správně sestavený XML element - chybí mu kořenová značka (obal všech těch dalších elementů)
aNonym
Profil *
nightfish
dík moc vyriešené

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0