Config with XML files
| From: | Marcus Krause | Date: | Tue, 27 Jul 2004 15:34:20 +0000 |
| Subject: | Config with XML files | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-13876@lists.php.net to get a copy of this message | ||
Hello!
I'm having some trouble with Config parsing XML-configuration-files.
First, I'm using
Config v. 1.10.2,
XML_Parser v. 1.2.0
XML_Util v. 0.6.1
The XML file was build via Config & contains
-----------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<database>
<local>
<type>pgsql</type>
<db>Database</db>
<host>localhost</host>
<user>User</user>
<pass>Password</pass>
</local>
</database>
-----------------------------------------------------------------
a copy of the xml-file can be found here:
<http://home.vrweb.de/~buddy/pear/test_db.xml>
& was build with:
-----------------------------------------------------------------
include_once'Config.php';
$settings = array( 'local'=> array( 'type' => 'pgsql',
'db' => 'Database',
'host' => 'localhost',
'user' => 'User',
'pass' => 'Password'));
$c = new Config();
$root =& $c->parseConfig($settings,'PHPArray');
if (PEAR::isError($root)) die($root->getMessage());
$root->writeDatasrc('test_db.xml','XML',array('name'=>'database'));
-----------------------------------------------------------------
I'm trying to retrieve data with:
-----------------------------------------------------------------
function get_dsn($str_section = 'local',$str_dbconfig = 'test_db.xml') {
$c = new Config();
$root =& $c->parseConfig($str_dbconfig,'XML');
if (PEAR::isError($root)) die($root->getMessage());
$sql_section =& $root->getItem('section',$str_section);
$sql_dir_type =& $sql_section->getItem('directive','type');
$sql_type = $sql_dir_type->getContent();
$sql_dir_db =& $sql_section->getItem('directive','db');
$sql_db = $sql_dir_db->getContent();
$sql_dir_host =& $sql_section->getItem('directive','host');
$sql_host = $sql_dir_host->getContent();
$sql_dir_user =& $sql_section->getItem('directive','user');
$sql_user= $sql_dir_user->getContent();
$sql_dir_pass =& $sql_section->getItem('directive','pass');
$sql_pass= $sql_dir_pass->getContent();
$str_dsn =
$sql_type."://".$sql_user.":".$sql_pass."@".$sql_host."/".$sql_db;
return $str_dsn;
}
-----------------------------------------------------------------
but it doesn't work!
PEAR raises no errors, the file can be found & is accessible!
var_dump($root) provides no output! Therefore I think that "parseConfig"
fails.
My Questions:
Do I call "parseConfig" in the right way?
Do I really retrieve the data of the XML-file in that way I'm trying it?
Is the XML-File perhaps corrupted?
I've no idea!