Ninjakreborn Posted January 31, 2007 Share Posted January 31, 2007 I am going to have series of general questions on PHP/XML parsing so I was going to keep it all in one thread here. I am currently trying the Expat library in PHP to parse the xml (or trying to). I have recently looked up about SimpleXML and I tried to look for it in my info page. Below is some information from my INI file pertaining to XML:[quote]xmlXML Support activeXML Namespace Support activeEXPAT Version 1.95.6xmlrpccore library version xmlrpc-epi v. 0.51php extension version 0.51author Dan Libbyhomepage http://xmlrpc-epi.sourceforge.netopen sourced by Epinions.comxsltXSLT support enabledBackend SablotronSablotron Version 0.97[/quote]I am under the impression, by looking at the information below that I do not have SimpleXML on this server. What exactly is XMLRPC is that the library I am looking for. This is the first question I had, I am working on the one with the Expat now, I am going to have question's later, probably quite a few so instead of starting multiple threads, I will keep it all into one thread. So my question is based on showing the above information from my INI file, does it have support for SimpleXML? Quote Link to comment https://forums.phpfreaks.com/topic/36484-php-xml-parsing/ Share on other sites More sharing options...
Ninjakreborn Posted January 31, 2007 Author Share Posted January 31, 2007 Ok, I have discovered some things. For one, I looked at my previous question, I figured that out.I am 100% amazed at the power of the Expat library. I dug into it, and got a skeleton that actually worked, and did some playing with it, so I was able to single out a couple of specific questions, I need some advice on. Here is my code for example.Example XML File[code]<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE tv SYSTEM "xmltv.dtd"><tv source-info-url="http://labs.zap2it.com/" source-info-name="TMS Data Direct Service" generator-info-name="XMLTV" generator-info-url="http://www.xmltv.org/"> <channel id="I45654.labs.zap2it.com"> <display-name>52 ESPNU</display-name> <display-name>52 ESPNU GA60311:-</display-name> <display-name>52</display-name> <display-name>ESPNU</display-name> <display-name>ESPN University</display-name> <display-name>Sports Satellite</display-name> </channel> <programme start="20070128230000 -0500" stop="20070129003000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">Women's College Basketball</title> <sub-title lang="en">Michigan State at Rutgers</sub-title> <category lang="en">Sports event</category> <category lang="en">Basketball</category> <episode-num system="dd_progid">SP184406.0000</episode-num> <subtitles type="teletext" /> </programme> <programme start="20070129003000 -0500" stop="20070129020000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">Women's College Basketball</title> <sub-title lang="en">North Carolina at Maryland</sub-title> <category lang="en">Sports event</category> <category lang="en">Basketball</category> <episode-num system="dd_progid">SP185707.0000</episode-num> <subtitles type="teletext" /> </programme> <programme start="20070129020000 -0500" stop="20070129033000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">High-School Basketball</title> <sub-title lang="en">St. John's (D.C.) vs. Mount St. Joseph's (Md.)</sub-title> <date>20070127</date> <category lang="en">Sports event</category> <category lang="en">Basketball</category> <category lang="en">Series</category> <episode-num system="dd_progid">EP800174.1088</episode-num> <previously-shown /> <subtitles type="teletext" /> </programme> <programme start="20070129033000 -0500" stop="20070129050000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">High-School Basketball</title> <sub-title lang="en">Dematha (Md.) vs. Towson Catholic (Md.)</sub-title> <date>20070127</date> <category lang="en">Sports event</category> <category lang="en">Basketball</category> <category lang="en">Series</category> <episode-num system="dd_progid">EP800174.1089</episode-num> <previously-shown /> <subtitles type="teletext" /> </programme> <programme start="20070129050000 -0500" stop="20070129060000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">Who's Number 1?</title> <sub-title lang="en">Greatest College Basketball Players</sub-title> <date>20070115</date> <category lang="en">Sports non-event</category> <category lang="en">Limited Series</category> <episode-num system="dd_progid">EP733145.0046</episode-num> <episode-num system="onscreen">07004</episode-num> </programme> <programme start="20070129060000 -0500" stop="20070129073000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">College Basketball</title> <sub-title lang="en">Syracuse at Louisville</sub-title> <category lang="en">Sports event</category> <category lang="en">Basketball</category> <episode-num system="dd_progid">SP185446.0000</episode-num> <previously-shown /> <subtitles type="teletext" /> </programme> <programme start="20070129073000 -0500" stop="20070129090000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">High-School Basketball</title> <sub-title lang="en">St. John's (D.C.) vs. Mount St. Joseph's (Md.)</sub-title> <date>20070127</date> <category lang="en">Sports event</category> <category lang="en">Basketball</category> <category lang="en">Series</category> <episode-num system="dd_progid">EP800174.1088</episode-num> <previously-shown /> <subtitles type="teletext" /> </programme> <programme start="20070129090000 -0500" stop="20070129103000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">High-School Basketball</title> <sub-title lang="en">Dematha (Md.) vs. Towson Catholic (Md.)</sub-title> <date>20070127</date> <category lang="en">Sports event</category> <category lang="en">Basketball</category> <category lang="en">Series</category> <episode-num system="dd_progid">EP800174.1089</episode-num> <previously-shown /> <subtitles type="teletext" /> </programme> <programme start="20070129103000 -0500" stop="20070129120000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">Women's College Basketball</title> <sub-title lang="en">North Carolina at Maryland</sub-title> <category lang="en">Sports event</category> <category lang="en">Basketball</category> <episode-num system="dd_progid">SP185707.0000</episode-num> <previously-shown /> <subtitles type="teletext" /> </programme> <programme start="20070129120000 -0500" stop="20070129123000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">Bill Self Show</title> <desc lang="en">Head coach Bill Self discusses the week in Kansas basketball.</desc> <category lang="en">Sports talk</category> <category lang="en">Basketball</category> <category lang="en">Limited Series</category> <episode-num system="dd_progid">SH796411.0000</episode-num> </programme> <programme start="20070129123000 -0500" stop="20070129143000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">College Hockey</title> <sub-title lang="en">Holy Cross vs. Quinnipiac</sub-title> <desc lang="en">From the TD Banknorth Sports Center in Hamden, Conn.</desc> <date>20070128</date> <category lang="en">Sports event</category> <category lang="en">Hockey</category> <category lang="en">Series</category> <episode-num system="dd_progid">EP047985.0934</episode-num> <previously-shown /> <subtitles type="teletext" /> </programme> <programme start="20070129143000 -0500" stop="20070129160000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">College Basketball</title> <sub-title lang="en">Syracuse at Louisville</sub-title> <category lang="en">Sports event</category> <category lang="en">Basketball</category> <episode-num system="dd_progid">SP185446.0000</episode-num> <previously-shown /> <subtitles type="teletext" /> </programme> <programme start="20070129160000 -0500" stop="20070129173000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">College Basketball</title> <sub-title lang="en">Michigan State at Ohio State</sub-title> <category lang="en">Sports event</category> <category lang="en">Basketball</category> <episode-num system="dd_progid">SP185706.0000</episode-num> <previously-shown /> <subtitles type="teletext" /> </programme> <programme start="20070129173000 -0500" stop="20070129180000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">ESPNU Recruiting Insider</title> <desc lang="en">Analysts discuss top high-school prospects and their college choices.</desc> <category lang="en">Sports talk</category> <category lang="en">Football</category> <category lang="en">Special</category> <episode-num system="dd_progid">SH855565.0000</episode-num> </programme> <programme start="20070129180000 -0500" stop="20070129190000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">ESPNU Bracketbusters Selection Show</title> <category lang="en">Sports non-event</category> <category lang="en">Basketball</category> <category lang="en">Special</category> <episode-num system="dd_progid">SH894959.0000</episode-num> </programme> <programme start="20070129190000 -0500" stop="20070129210000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">College Basketball</title> <sub-title lang="en">Hampton at North Carolina A&T</sub-title> <category lang="en">Sports event</category> <category lang="en">Basketball</category> <episode-num system="dd_progid">SP185899.0000</episode-num> </programme> <programme start="20070129210000 -0500" stop="20070129230000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">College Basketball</title> <sub-title lang="en">Mississippi Valley State at Grambling State</sub-title> <category lang="en">Sports event</category> <category lang="en">Basketball</category> <episode-num system="dd_progid">SP185900.0000</episode-num> <subtitles type="teletext" /> </programme> <programme start="20070129230000 -0500" stop="20070130010000 -0500" channel="I45654.labs.zap2it.com"> <title lang="en">College Basketball</title> <sub-title lang="en">Pepperdine at Santa Clara</sub-title> <category lang="en">Sports event</category> <category lang="en">Basketball</category> <episode-num system="dd_progid">SP185901.0000</episode-num> <subtitles type="teletext" /> </programme></tv>[/code]PHP File[code]<?php// Build an array with all the channel names.$channels = array ("I11187", "I11829", "I11269", "I11768", "I11993", "I19556", "I11490", "I11479", "I11959", "I23319", "I18774", "I11287", "I12553", "I24634", "I23324", "I22564", "I23327", "I23328", "I23329", "I10240", "I10244", "I10241", "I18429", "I16585", "I24553", "I10243", "I10021", "I12852", "I16374", "I10142", "I10145", "I10139", "I10161", "I10162", "I10035", "I10057", "I10051", "I10153", "I11097", "I11163", "I11164", "I11207", "I10149", "I10989", "I14321", "I14909", "I10918", "I16409", "I45654", "I10179", "I12444", "I16485", "I12410", "I14899", "I14776", "I16011", "I20789", "I10986", "I16361", "I10138", "I11218", "I44228", "I11180", "I16331", "I11150", "I16615", "I18327", "I16617", "I16618", "I18284", "I16616", "I18544", "I18179", "I11158", "I14902", "I14771", "I12574", "I26784", "I10093", "I12131", "I10171", "I11006", "I16123", "I30103", "I21450", "I19059", "I18332", "I25354", "I31634", "I19283", "I18644", "I21852", "I21063", "I24935", "I24248", "I29323", "I28452", "I12324", "I16345", "I10239", "I11118", "I15377", "I27773", "I19247", "I18715", "I19979", "I25238"); // Build the file name's dynamically based on the above file names.// register empty array to hold the upcoming information$files = array();// run through all the channels, assining there full file names into an arrayforeach ($channels as $k) { $files[] = $k . ".labs.zap2it.com.xml"; // assign each file name into the files array}// attempt to create an xml parserif (!$parser = xml_parser_create()) { exit("There was a problem creating the parser");}// Functions To go into the element handlers, later on// variables to pass to user functions// function to start searchingfunction starttag($parser, $element_name, $attributes) { case}// function to end searchingfunction endtag($parser, $element_name) {}// function to take data from tagsfunction tagdata($parser, $data) { echo $data; echo "<br />";}xml_set_element_handler($parser, "starttag", "endtag");xml_set_character_data_handler($parser, "tagdata");// use the file array created earlier to get to work// create an array to hold information on all the currently playing shows// from all the xml file's$nowplaying = array();//foreach ($files as $k => $v) { // run through all the file'secho "Start File";echo "<br />";echo "<br />"; if (!$open = fopen("I10021.labs.zap2it.com.xml", "r")) { // opening them // we can't do anything if any file's didn't open, because we don't have all the // necessary data, so kill the script exit("File could not be opened"); } while ($data = fread($open, 4096)){ if (!xml_parse($parser, $data, feof($open))) { $reason = xml_error_string(xml_get_error_code($parser)); $reason .= xml_get_current_line_number($parser); die($reason); } }echo "End File";echo "<br />";echo "<br />";//}// close foreach ?>[/code][b]Notes[/b]* There are a total of 100+ files* I need to run through them in a foreachI am not to that step, and I am trying to do something else (get an understanding of how the basic structure works)I understand this, but here are my questions.1. I understand how to set a foreach for the start tag, and do what is necessary for that, how does the start tag, understand what is happening on the data. I don't understand there relationship.For example, I need to tell it at the start tag, to do this, this, and this to the data. How do I tell it to do that, since the data function is seperate?2. I need to find the starttime/stoptime of each programmer. Even when I dump all the data, the start/stop time doesn't come up. How do I, or what can I change with my code, to give me access to that information so I can test the proper calculations?3. I don't understand what is happening when I put it in a foreach. Doing it this way I have something to work with. However when I throw a foreach around it using the file names in the array, it doesn't work. It goes through file one, starts up the second file, and put's out a message that says everything else is junk (something php throws out), then stops anything else from happening. How can I get a foreach loop to work around this once I get it doing exactly what I want on the first file?Thank you for the help. Quote Link to comment https://forums.phpfreaks.com/topic/36484-php-xml-parsing/#findComment-173738 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.