PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
bind xml to the datagrid

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Structures
View previous topic :: View next topic  
Author Message
jacks.9@osu.edu



Joined: 04 Jul 2007
Posts: 5

PostPosted: Wed Jul 04, 2007 5:14 pm    Post subject: bind xml to the datagrid Reply with quote

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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 998

PostPosted: Wed Jul 04, 2007 6:00 pm    Post subject: Reply with quote

Documentation for this driver is indeed poor, right. But basically, this driver works like the other ones do:
$datagrid->bind($xml, $options, 'XML');
with $xml being a string with XML tags and $options being an (probably empty) array of options.

There are some options for this driver, c.p.:
http://pear.php.net/manual/en/package.structures.structures-datagrid.structures-datagrid-datasource.xml.php

I have added an item about writing an example for this driver to my TODO list.
Back to top
View user's profile Send private message
jacks.9@osu.edu



Joined: 04 Jul 2007
Posts: 5

PostPosted: Wed Jul 04, 2007 8:14 pm    Post subject: Reply with quote

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&amp;id=123</url>
<latitude>30.287739</latitude>
<longitude>-97.8022</longitude>
</result>


Thank you,

Guy
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 998

PostPosted: Wed Jul 04, 2007 11:05 pm    Post subject: Reply with quote

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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 998

PostPosted: Wed Jul 04, 2007 11:50 pm    Post subject: Reply with quote

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
View user's profile Send private message
jacks.9@osu.edu



Joined: 04 Jul 2007
Posts: 5

PostPosted: Thu Jul 05, 2007 5:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 998

PostPosted: Thu Jul 05, 2007 6:23 pm    Post subject: Reply with quote

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
View user's profile Send private message
jacks.9@osu.edu



Joined: 04 Jul 2007
Posts: 5

PostPosted: Sat Jul 07, 2007 6:03 pm    Post subject: Reply with quote

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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 998

PostPosted: Sun Jul 08, 2007 1:53 pm    Post subject: Reply with quote

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
View user's profile Send private message
jacks.9@osu.edu



Joined: 04 Jul 2007
Posts: 5

PostPosted: Mon Jul 09, 2007 12:14 pm    Post subject: Reply with quote

The new driver works! Thank you so much.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Structures All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software