Out of the corner of my eye

Non Sibi, Sed Omnibus

Out of the corner of my eye header image 2

DOMDocument::LoadXML Extra content at the end of the document in Entity…

February 19th, 2008 · 5 Comments

This is one of those tricky XML things that can trip up the unwary. Looks like a lot of people have had trouble with this as there’s plenty of hits on Google with people asking questions but I couldn’t find an answer.

You’ll be seeing something like:

Warning: DOMDocument::load() [function.load]: Extra content at the end of the document in Entity, line…

The reason this happens is because your XML is in fact not well-formed. Because in XSL you often use HTML tags in your XML, it can catch you out though.

My problem was I had a table with some results in it from XML. The XML was well-formed because the table tag was the root of the document. However I then added some more markup after the table, and got the “extra content at the end of the document” warning. It took a few minutes of head scratching before I realised what the problem was - I was thinking of it in terms of the output I wanted: an html fragment, not what it actually was: an XML document. Tags are arbitrary in XML so the table tag was the doc’s root node. To stop the warning, all I had to do was move the extra content inside the root of the document, which I did by adding a div around everything.

Hope this helps other people learning the dark arts of XSL transforms!

Tags: Web dev

5 responses so far ↓

  • 1 Brad // Jun 7, 2008 at 4:53 am

    Just started learning XML and how to store variables in XML and then call them up in my PHP docs. YOU ROCK FOR THIS BLOG! :-)
    (I was just clueless!)

  • 2 Patrick Reilly // Jul 7, 2008 at 8:20 am

    Gah! That’s such a simple explanation for such an annoying concept. It can’t have multiple root nodes, so if you have two nodes inside the document laying side by side, they conflict, and it gives you this error.
    Thanks for the solution!

  • 3 Madhup // Sep 18, 2008 at 1:36 am

    excellent man

  • 4 typografia // Dec 18, 2008 at 11:17 am

    Thanks, simple but helpful post :)

  • 5 Kurt // Dec 24, 2008 at 1:10 pm

    Thank you!!!!!

Leave a Comment