Jump to content

simpleXML error when loading file that does not use a container.


DollarThief

Recommended Posts

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.

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 */

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.