But it doesn't work like the sample code!
Posted: Tue Oct 24, 2006 6:40 pm
feyd | Please use
and the XML file
It is probably something stupid I'm doing.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am trying to use XML to store data then read it in a different page and parse it using the xml_parse_into_struct. The examples use both file_get_contents and fopen/fread. I get different results retrieving the XML.
file_get_contents gives a list of the data but no tags
fopen opens the file but fread returns FALSE but errno is not set
any help would be greatly appreciated
Dave
Here is my code. This is code just to test the function before I clean it up and put it into the app so you may think it is sloppy.Code: Select all
<?PHP
$FTxt = "testcall.xml";
echo "Filesize = ".filesize($FTxt)."<br>";
// if (!$Fl = fopen($FTxt, 'r')) {
// echo "<Font color=\"red\" size=\"+1\">";
// echo "Error: Cannot open file ($FTxt) for reading.<br>";
// echo "Error: Error is ".$errmsg."(".$errno.").</Font><br>";
// $err = 1;
// }
// else {
$XmlData = file_get_contents($FTxt);
// $XmlData = fread($F1, filesize($FTxt));
// if ($XmlData === FALSE) {
// echo "<Font color=\"red\" size=\"+1\">";
// echo "Error: Cannot read to file ($FTxt) - Original eMail<br>";
// echo "Error: Error is ".$errmsg."(".$errno.").</Font><br>";
// }
// fclose($Fl);
// }
echo "<Pre>".$XmlData."</Pre><br>";
// Code from php.net
// $simple = "<para><note>simple note</note></para>";
$p = xml_parser_create();
xml_parse_into_struct($p, $XmlData, $vals, $index);
xml_parser_free($p);
echo "Index array<Pre>";
print_r($index);
echo "\nVals array\n";
print_r($vals);
echo "</Pre>";
?>Code: Select all
<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<dispatcher>
<type>incident</type>
<nature>IncidentType</nature>
<agency>IncidentAgency</agency>
<municipality>IncidentMunicipality</municipality>
<houseno>IncidentHouseNo</houseno>
<street>IncidentStreet</street>
<cross1>IncidentCrossSt1</cross1>
<cross2>IncidentCrossSt2</cross2>
<crosssts>IncidentCrossSts</crosssts>
<units>IncidentUnit</units>
<timeout>IncidentTimeOut</timeout>
<datetime>IncidentDatePrt</datetime>
<filenname>IncidentFile</filename>
</dispatcher>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]