Ok XML Gurus, I need your help. I'm pretty new to these functions so I'm not exactly sure what they do or how I can modify them for my needs. Here's what I'm attempting.....I need to take an XML page and strip out the data. The function I have is fine, except if there's no data the XML page is printing out just a closing tag <tag /> which is throwing my array off. Here's the code....
function characterData($parser, $data)
{
$xmlstream[$i] = $data;
$i++
}
$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
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);
Then I have variables assigned from the array:
$State = $xmlstream[2];
$City = $xmlstream[4]; etc....
basically, whenever it hits an XML tag it's assigning a space to the array:
<tag1> Data1 </tag1>
<tag2> Data2 </tag2>
It will assign data fine only if there is an opening and closing tag, however if there is no data, the XML output is:
<tag1> Data1 </tag1>
<tag2> Data2 </tag2>
<tag3 / >
which is completely messing up my array count. Does this make sense?
Any help would be greatly appreciated!!!
Thanks!!
Lisa