DollarThief Posted August 27, 2009 Share Posted August 27, 2009 An XML file like this one loads perfectly with $xml = simplexml_load_file(data.xml); <?xml version="1.0" encoding="iso-8859-1"?> <container> <content> Content Goes Here </content> </container> But an XML file like this one fails to load and throws up "Warning: simplexml_load_file() [function.simplexml-load-file]: data.xml:3: parser error : Extra content at the end of the document" <?xml version="1.0" encoding="iso-8859-1"?> <content> Content Goes Here </content> <content2> More Content Goes Here </content2> I'm assuming the problem is that the second example has 2 root elements, but I'm wondering if there is a workaround. The XML files are used by a flash app that requires that they be formatted as in the second example. Quote Link to comment https://forums.phpfreaks.com/topic/172077-simplexml-error-when-loading-file-that-does-not-use-a-container/ Share on other sites More sharing options...
btherl Posted August 27, 2009 Share Posted August 27, 2009 You could add a container before passing the string to simplexml. Quote Link to comment https://forums.phpfreaks.com/topic/172077-simplexml-error-when-loading-file-that-does-not-use-a-container/#findComment-907314 Share on other sites More sharing options...
ignace Posted August 27, 2009 Share Posted August 27, 2009 I'm assuming the problem is that the second example has 2 root elements, but I'm wondering if there is a workaround. The XML files are used by a flash app that requires that they be formatted as in the second example. There isn't you need a root element. You can re-use content to define extra content like I did in the below example: <?xml version="1.0" encoding="iso-8859-1"?> <container> <content>Content Goes Here</content> <content>More Content Goes Here</content> </container> echo $root->content[0] /* content goes here */, $root->content[1]; /* more content goes here */ Quote Link to comment https://forums.phpfreaks.com/topic/172077-simplexml-error-when-loading-file-that-does-not-use-a-container/#findComment-907424 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.