barneycarroll Posted March 10, 2010 Share Posted March 10, 2010 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 Link to comment https://forums.phpfreaks.com/topic/194798-php-to-interpret-raw-xml-%E2%80%94-impossible/ Share on other sites More sharing options...
jl5501 Posted March 10, 2010 Share Posted March 10, 2010 the simplexml_load_file manual page has examples just like yours which work. So I can see no reason why you are having problems. http://php.net/manual/en/book.simplexml.php Link to comment https://forums.phpfreaks.com/topic/194798-php-to-interpret-raw-xml-%E2%80%94-impossible/#findComment-1024371 Share on other sites More sharing options...
barneycarroll Posted March 11, 2010 Author Share Posted March 11, 2010 Hey jl5501, thanks for the sanity check — was fairly certain I'd RTFMed! FWIW XML is indeed UTF-8 without BOM, passes W3's validator. php v5.2.11. Clues == 0… Link to comment https://forums.phpfreaks.com/topic/194798-php-to-interpret-raw-xml-%E2%80%94-impossible/#findComment-1024562 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.