XML parsen geht nicht?

wachteldonk

Erfahrenes Mitglied
Hallo,

ich erstelle wie folgt meine XML Datei

Code:
echo "<helplinks>";
while($rs = mysql_fetch_object($result))
	{
	echo "<entry>";
	echo "	<HELPSPREADID>".$rs->HELPSPREADID."</HELPSPREADID>";
	echo "	<title type=\"text\">".iconv("UTF-8","latin1",$rs->title)."</title>";
	echo "	<text type=\"text\">".iconv("UTF-8","latin1",$rs->text)."</text>";
	echo "	<url type=\"text\">".$rs->url."</url>";
	echo "	<gruppe type=\"text\">".iconv("UTF-8","latin1",$rs->gruppe)."</gruppe>";
	echo "	<datumzeit_add>".$rs->datumzeit_add."</datumzeit_add>";
	echo "	<datum_add>".$rs->fdatum_add.$trenner,"</datum_add>";
	echo "<entry>";
	}
echo "</helplinks>";

und will es hiermit parsen

Code:
<?

class XMLParser
{
    /**
     * @var string
     * @access protected
     */
    var $current = '';

    /**
     * @var boolean
     * @access protected
     */
    var $found = false;

    /**
     * @var array
     * @access protected
     */
    var $result = array();

    /**
     * @access public
     */
    function XMLParser()
    {
        $this->__construct();
    }

    /**
     * @access public
     */
    function __construct()
    {
        $this->parser = xml_parser_create();
        xml_set_object($this->parser, $this);
        xml_set_element_handler($this->parser, 'startElement', 'endElement');
        xml_set_character_data_handler($this->parser, 'characterData');
    }

    /**
     * @param  string  $xml_data
     * @access public
     */
    function parse($xml_data)
    {
        xml_parse($this->parser, $xml_data);
        xml_parser_free($this->parser);
        return $this->result;
    }

    /**
     * @param  object  $parser
     * @param  string  $name
     * @param  array   $attribs
     * @access protected
     */
    function startElement($parser, $name, $attribs) {
        $this->current = $name;
        if ($this->current == 'ENTRY') {
            $this->found = true;
            $this->result[count($this->result)] = array();
        } elseif ($this->found and $this->current == 'LINK') {
            $this->result[count($this->result) - 1][$attribs['REL']] = $attribs['HREF'];
        }
    }

    /**
     * @param  object  $parser
     * @param  string  $name
     * @access protected
     */
    function endElement($parser, $name) {
        if ($name == 'ENTRY') {
            $this->found = false;
        }
    }

    /**
     * @param  object  $parser
     * @param  string  $data
     * @access protected
     */
    function characterData($parser, $data) {
        if ($this->found) {
            $this->result[count($this->result) - 1][strtolower($this->current)] = $data;
        }
    }
}
?>

ich erhalte aber nur ein leeres array

Code:
		while($line = fgets($fp,4096))
			{
			$xml_data .= $line;
			}
		$xmlParser = New XMLParser();
		$data = $xmlParser->parse($xml_data);
print_r($data);
		return $data;

bzw. nur der letzte Wert ist vorhanden:(

Was mach ich falsch?
 
Zuletzt bearbeitet:
Hallo,

ich habe den Verdacht das es mi Umbrüchen zusammenhängt. Wenn ich \n hinter jedem <xxx>Data</xxx> hinzufüge , ehe ich nur den ersten Eitrag
 
Zurück