3
votes

i have a xml file like this

<?xml version="1.0"?>
<test>Total</test>
<books>
    <mybook id="1">
        <blabla>jkjk</blabla>
    </mybook>¨
</books>

If I parse it like that with simpleXML

$xml = simplexml_load_file($filename); 

it says

simplexml_load_file() [function.simplexml-load-file]: ./uploads/test.xml:3: parser error : Extra content at the end of the document

But if a remove the

<test>Total</test>

at the begining of the xml file it works....

any ideas ?? thank you

3

3 Answers

13
votes

You need to have a root element in your xml, i.e.

<document>
    <test>Total</test>
    <books>
        <mybook id="1">
            <blabla>jkjk</blabla>
        </mybook>
    </books>
</document>
2
votes

Your XML is invalid. XML must have one and only one root element.

The "extra content" the parser is complaining about is the <books> element.

2
votes

It is what it writes. Extra content.

And what is it? ¨ after </mybook>. So the file isn't valid. If you want it valid, it'd look like:

    <bookinfo>
   <test>Total</test>
    <books>
        <mybook id="1">
            <blabla>jkjk</blabla>
        </mybook>
    </books>
    </bookinfo>

A note: an XML has to be always ONE, exactly one root element.