| View previous topic :: View next topic |
| Author |
Message |
jacks.9@osu.edu
Joined: 04 Jul 2007 Posts: 5
|
Posted: Wed Jul 04, 2007 5:14 pm Post subject: bind xml to the datagrid |
|
|
Hi,
I have been using the datagrid with mysql for a while now without any problem. I want to bind the datagrid to xml. Does anyone know how to do this? I can't find any tutorials online about this.
Thank you,
Guy |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
|
| Back to top |
|
 |
jacks.9@osu.edu
Joined: 04 Jul 2007 Posts: 5
|
Posted: Wed Jul 04, 2007 8:14 pm Post subject: |
|
|
Thank you. That works. However, I must now be using the addColumn function wrong since the datagrid is rendering an empty table -->
| Code: | $this->PearStructuresDatagrid->addColumn('job title', '/response/results/resultjobtitle');
|
The xml feed looks like this:
| Quote: | <?xml version="1.0" encoding="ISO-8859-1" ?>
<response>
<query>Java Developer</query>
<location>San Francisco, CA</location>
<dupefilter>true</dupefilter>
<totalresults>2315</totalresults>
<start>1</start>
<end>10</end>
<results>
<result>
<jobtitle><![CDATA[Chief Executive]]></title>
<company><![CDATA[ABC Corporation]]></title>
<city>City Name</city>
<state>ST</state>
<country>US</country>
<source>Job Site</source>
<date>Thu, 13 Jan 2006 23:47:44 GMT</date>
<snippet><![CDATA[All about my interests and hobbies]]></snippet>
<url>http://www.domain.com/jobdetail.html?x=y&id=123</url>
<latitude>30.287739</latitude>
<longitude>-97.8022</longitude>
</result> |
Thank you,
Guy |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Wed Jul 04, 2007 11:05 pm Post subject: |
|
|
| jacks.9@osu.edu wrote: | | Thank you. That works. However, I must now be using the addColumn function wrong since the datagrid is rendering an empty table -->[...] |
I'll get back to you about this tomorrow or at least in the next days. I can't test your example currently because XML_XPath requires PHP 4 while I have PHP 5 installed.
BTW: Your XML has 4 errors: Two missing closing tags, and two wrong closing tags. |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Wed Jul 04, 2007 11:50 pm Post subject: |
|
|
Okay, the older XML_XPath version 1.2.2 works also on PHP 4. Your XML needs the four mentioned fixes, and it needs to have at least two <result> tags. That's because XML_Unserializer behaves differently if there is only one <result> tag. Once this XML format is ready, you can do this:
| Code: |
$res = $dg->bind($xml, array('xpath' => '/response/results'), 'XML');
|
The 'xpath' option will extract the relevant parts from the XML string. You don't need to call addColumn() yourself. |
|
| Back to top |
|
 |
jacks.9@osu.edu
Joined: 04 Jul 2007 Posts: 5
|
Posted: Thu Jul 05, 2007 5:19 pm Post subject: |
|
|
thank you for all of your help so far. That xml was just a snippet. You can click on the link below to see the full xml. Just open up the html source.
http://guy.lifeagora.com/job_boards/organizationJobs/170
The following is the entire function that i am using. As you can see in the url, I am getting the following error --> http://guy.lifeagora.com/job_boards/organizationJobs/170
| Code: | private function __createIndeedJobBoard($strIndeedXmlRequest,
$intNumRowsPerPage=15){
echo($strIndeedXmlRequest);
$xml = simplexml_load_file($strIndeedXmlRequest);
$strXml = $xml->asXML();
echo($strXml);
$this->PearStructuresDatagrid->init($intNumRowsPerPage);
//$driver =
// $this->PearStructuresDatagrid->dataSourceFactory($strIndeedXmlRequest);
//$this->PearStructuresDatagrid->bindDataSource($driver);
$this->PearStructuresDatagrid->bind($strXml, array('xpath' => '/response/results'), 'XML');
//$this->PearStructuresDatagrid->setDefaultSort(
// array('post_date' => 'ASC'));
//Add columns to the datagrid
//$this->PearStructuresDatagrid->addColumn('job title', '/response/results/resultjobtitle');
//$this->PearStructuresDatagrid->addColumn('City', 'city');
$datagrid = $this->PearStructuresDatagrid->getDatagrid();
return $datagrid;
} |
Thank you,
Guy |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Thu Jul 05, 2007 6:23 pm Post subject: |
|
|
Would it be possible that you have neither the error_reporting = E_ALL setting nor the XML_XPath package installed? If that's the case, then the missing package is the reason.
XML_XPath 1.2.3 is only compatible to PHP 5 (at least it is marked that way), but XML_XPath 1.2.2 also works with PHP 5. If you install this package, your code should work. (I have tried my life of code from yesterday with your full XML string and it works here.)
I'll prepare a reasonable implementation of the XPath stuff for PHP 5 in the next days. You can then install the new version of the XML DataSource and your script will work without XML_XPath being installed. |
|
| Back to top |
|
 |
jacks.9@osu.edu
Joined: 04 Jul 2007 Posts: 5
|
Posted: Sat Jul 07, 2007 6:03 pm Post subject: |
|
|
Thank you for all of your help. My server admin is looking into what you said. Hopefully we will get this working this weekend. I'll let you know what happens.
Have a good weekend
Thanks,
Guy |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Sun Jul 08, 2007 1:53 pm Post subject: |
|
|
FYI: The new version of the driver is almost ready. It now supports PHP 5 without the need of having XML_Serializer and XML_XPath installed. You can also specify a filename now (previously only strings were allowed in the bind() call).
Download:
http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid/DataSource/XML.php?view=log
Please note that we might change some (internal) details before a new release, but it should be working for you anyway. |
|
| Back to top |
|
 |
jacks.9@osu.edu
Joined: 04 Jul 2007 Posts: 5
|
Posted: Mon Jul 09, 2007 12:14 pm Post subject: |
|
|
| The new driver works! Thank you so much. |
|
| Back to top |
|
 |
|