dflow Posted August 13, 2008 Share Posted August 13, 2008 hi im interested in a script that lets you search multiple XML sources by dates anyone have script that loops through a number of xml sources? Link to comment https://forums.phpfreaks.com/topic/119484-php-search-many-xml-script/ Share on other sites More sharing options...
ignace Posted August 13, 2008 Share Posted August 13, 2008 this is a bad question, we don't write scripts for others nor do we share therefor i shall give you the first pieces and you shall have to figure out how it will work further on $xml = xml_parser_create(); $dir = "path/fo/xml/directory"; $dh = opendir($dir); if ($dh) { while ($file = readdir($dh)) { if ($file != "." && $file != "..") { $path = $dir . DIRECTORY_SEPARATOR . $file; $data = file_get_contents($path); if (0 !== xml_parse($xml, $data)) { // i gave you the first pieces, the rest of the puzzle shall you have to figure out by yourself } } } } Link to comment https://forums.phpfreaks.com/topic/119484-php-search-many-xml-script/#findComment-615544 Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 Or use SimpleXML and loop through everything, sort of like: foreach (glob('your/directory/*.xml') AS $filename) { $data = file_get_contents($filename); $sxml = new SimpleXML($data); //etc etc } Link to comment https://forums.phpfreaks.com/topic/119484-php-search-many-xml-script/#findComment-615547 Share on other sites More sharing options...
dflow Posted September 15, 2008 Author Share Posted September 15, 2008 thx guys im trying this out Link to comment https://forums.phpfreaks.com/topic/119484-php-search-many-xml-script/#findComment-641600 Share on other sites More sharing options...
DarkWater Posted September 15, 2008 Share Posted September 15, 2008 I don't know what I was thinking. The 3rd line should be: $sxml = simplexml_load_string($data); Sorry. Link to comment https://forums.phpfreaks.com/topic/119484-php-search-many-xml-script/#findComment-641609 Share on other sites More sharing options...
dflow Posted September 15, 2008 Author Share Posted September 15, 2008 would you say this is correct? <?php $query="SELECT * FROM Suppliers WHERE CITY='Barcelona'"; $result = mysql_query($query) or die(mysql_error()); $array = array(); while($row = mysql_fetch_assoc($result)) { $array[] = $row["XML_PATH"]; } ?> <?php foreach (glob('$array[]') AS $filename) { $data = file_get_contents($filename); $sxml = simplexml_load_string($data); //etc etc }?> or did i mess it up? Link to comment https://forums.phpfreaks.com/topic/119484-php-search-many-xml-script/#findComment-641613 Share on other sites More sharing options...
DarkWater Posted September 15, 2008 Share Posted September 15, 2008 Nah, you messed it up. >_< <?php $query="SELECT * FROM Suppliers WHERE CITY='Barcelona'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { foreach (glob("{$row['XML_PATH']}/*") AS $filename) { $data = file_get_contents($filename); $sxml = simplexml_load_string($data); //etc etc } } ?> Link to comment https://forums.phpfreaks.com/topic/119484-php-search-many-xml-script/#findComment-641616 Share on other sites More sharing options...
dflow Posted September 15, 2008 Author Share Posted September 15, 2008 any idea why i get this error? Warning: file_get_contents(/root) [function.file-get-contents]: failed to open stream: Permission denied in im using a url with all the login information Link to comment https://forums.phpfreaks.com/topic/119484-php-search-many-xml-script/#findComment-641624 Share on other sites More sharing options...
dflow Posted September 15, 2008 Author Share Posted September 15, 2008 ok fixed this apparently empty fields raise this error so i filled them up now ill need to parse the data, and as they are different xml schemas this will be a challenge, including different date formats any suggestions how to tackle this? Link to comment https://forums.phpfreaks.com/topic/119484-php-search-many-xml-script/#findComment-641628 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.