Im some what new to xml but I've put together a basic xml parsing script, and for some reason, on data like ->
<description>It&apos;s been a few days since...</description>
the parser thinks its 3 lines. Its parsing a new line on htmlentities like &apos;
So with the above line the looped output is like ->

Data --> It
Data --> '
Data --> s been a few days since

Here is a downsized version of the script Im working with ->
---------------------
<?php

class XMLParser
{
var $xmlparser;

function XMLParser()
{
$this->xmlparser = xml_parser_create();
xml_set_object($this->xmlparser, $this);
xml_set_element_handler($this->xmlparser, 'start_tag', 'ending_tag');
xml_set_character_data_handler($this->xmlparser, 'character_handler');
xml_parser_set_option ($this->xmlparser, XML_OPTION_CASE_FOLDING, FALSE);
}

function parse($data)
{
xml_parse($this->xmlparser, $data);
}

function parse_File($xmlfile)
{
$fp = fopen($xmlfile, 'r');
while ($xmldata = fread($fp, 4096))
{
// parse the data chunk
if (!xml_parse($this->xmlparser, $xmldata))
{
// if parsing fail print the error description and line number
echo 'ERROR: ';
echo xml_error_string(xml_get_error_code($this->xmlparser)) . '<br>';
echo 'Line: ';
echo xml_get_current_line_number($this->xmlparser) . '<br>';
echo 'Column: ';
echo xml_get_current_column_number($this->xmlparser) . '<br>';
}
}

fclose($fp);
}

function start_tag($xmlparser, $tag, $attributes)
{
echo 'Opening tag: ' . $tag . "\n";
}

function ending_tag($xmlparser, $tag)
{
echo 'Ending tag: ' . $tag . "\n";
}

function character_handler($xmlparser, $data)
{
echo 'Data --> ' . $data . "\n";
}

function close_Parser()
{
xml_parser_free($this->xmlparser);
}
}

?>
-----------------

Thanks for any input you may provide.

--
Gerard Samuel
http://www.trini0.org:81/
http://dev.trini0.org:81/



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to