XML Parsing Error: junk after document element

Since I had to go through about 20 pages to find the cause of this error, I figured I’d throw up one more with the cause that I found. Hopefully it’ll help somebody spend less time debugging the problem than I had to spend.

I’ve got a PHP script outputting XML that’s called from an Ajax script. When I was testing the PHP output I got the error XML Parsing Error: junk after document element after trying to add another section to the XML.

What turned out the be the cause is that in adding the section I wound up with two root elements, so in effect there weren’t any root elements. I wrapped the whole thing in another element and it worked perfectly, 20 minutes later.

Question, Comments...

Do you have more questions. Please either leave a comment below or join us in our new forum.

Leave a Reply