PDA

View Full Version : XML in PHP


Dr. Klahn
11-23-2007, 06:55 PM
So here's what I'm trying to do.

I've got an app that stores a bunch of data as xml in the database that I'm needing to pull some of it as variables in a PHP app I'm writing.

Problem: I'm not very good in PHP, so I'm basically banging my head against the wall. :wall:

Here's the code that's calling the xml. I've created an xml file with one of the entries for the moment so I can test with less variables (the database)
<?php
// include XJConf class file
include_once 'XJConf/XJConf.php';

// load facade
XJConfLoader::load('XJConfFacade');
$conf = new XJConfFacade();

// attach definitions to parser
$conf->addDefinition('defs.xml');

// parse XML
$conf->parse('retreat1.xml');

// access XML element values
echo $conf->getConfigValue('title') . " starts " . $conf->getConfigValue('start')
. " and ends " . $conf->getConfigValue('end') . ".";
?>

I'm getting the following error when I run that code:
Parse error: syntax error, unexpected T_STRING in (path)/XJConf.php on line 8

Here's the beginning of that file (line 8 is the namespace line):
<?php
/**
* Class loader for all XJConf classes.
*
* @author Frank Kleine <frank.kleine@schlund.de>
* @package XJConf
*/
namespace net::xjconf;
/**
* Class loader for all XJConf classes.
*
* The class loader takes care that all class files are only loaded once. It
* allows all classes to include the required files without knowing where they
* reside or if they have been loaded before.
*
* @package XJConf
*/
class XJConf

XJConf is a package that I downloaded to get the XML parsing. So - Questions are:
1 - Any clue what's wrong and/or how to fix?
2 - Anyone have a maybe better way to parse the xml file to get the elements loaded into the PHP prog as variables?

Thanks!

Tazz
11-23-2007, 11:24 PM
Im not familiar with XJConf, and from reading a little on its site I see that they haven't fully tested it on mysql.

How bout a link to the XML file your trying to pull the data from and a list of the data that your wanting to store and echo back out in the php?

Dr. Klahn
11-24-2007, 12:07 AM
I can do that.

Honestly in a bit over my head in this whole project, so appreciating any help that you guys can send my way. =)

xml example:
http://www.slpm.org/RetreatSignUp/retreat1.xml
That's basically the format of the xml that is stored in 1 field in the database that I'm using. The principal fields that I know I'm going to end up wanting are: id, start, end, title, details.
(As a bonus, start and end are in Unix timecodes. If there's a nice way to format those when I display them on a page in PHP, I'd appreciate a quick point to some info on that. I'm guessing that's something that php can do pretty natively when I do the php print command, but I haven't gotten into that, yet)

Danke!
Joe