Jump to content

PHP to interpret raw XML — impossible?


barneycarroll

Recommended Posts

Hi folks,

 

I'm a PHP novice — built sites using it before but always relied upon file system for content management — now I'm developing something slightly more complex and I want to use XML for data storage.

 

My predicament: PHP trips up if I ask it to interpret raw XML.

 

Relevant PHP code (line numbers added for convenience):

14	if(strtolower($filename)==='meta.xml'){
15		$meta = simplexml_load_file($path.$filename);

 

XML file meta.xml:

<?xml version="1" encoding="utf-8"?>
<meta>
<name>3-of-hearts</name>
<title>3 of Hearts</title>
<description>A playing card stuck to a wall with a hand-written pencil inscription on masking tape immediately beneath</description>
</meta>

 

Error output:

Warning: simplexml_load_file() [function.simplexml-load-file]:

:1: parser error : Malformed declaration expecting version in [code=php:0] on line 15

Warning: simplexml_load_file() [function.simplexml-load-file]: <?xml version="1" encoding="utf-8"?> in [code=php:0] on line 15

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in [code=php:0] on line 15

 

When I google these errors, I mostly find people with encoding errors or badly formed declarations, who are incidentally writing their XML out with PHP before interpreting it — something I didn't find mentioned in my skim through the docs simplexml parser entries.

 

Is it possible to use simple unscripted valid XML files in PHP, or is the syntax conflict between PHP's short tag and the XML declaration tag, '<?'…'?>' inevitable?

 

 

Regards,

Barney

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.