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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.