parser error : Detected an entity reference loop

While importing a rather large XML-document (45MB+) into a database today, I ran into a weird problem on one specific server. The server runs SUSE Enterprise and presented an error that neither other test server gave. After a bit of digging around on the web I were able to collect enough information from several different threads about what could be the source of the problem.

It seems that the limit was introduced in libxml2 about half a year ago to avoid some other memory problems, but this apparently borked quite a few legitimate uses. As I have very little experience with administrating SUSE Enterprise based servers, I quickly shrugged off trying to update the packages and possibly recompiling PHP. Luckily one of the comments in a thread about the problem saved the day.

If you find yourself running into this message; swap your named entities in the XML file (such as < and >) to numeric entities (such as < and >). This way libxml2 just replaces everything with the byte value while parsing instead of trying to be smart and keep an updated cache.

3 thoughts on “parser error : Detected an entity reference loop”

  1. Thanks a lot! i had the same problem from php on debian etch, but the numeric entities tip did the trick!
    thanks again

  2. Here I am in 2016 and this was exactly what I needed to fix my problem. Was trying to parse a 33mb ONIX file and got this weird error. I was creating my ONIX file from a larger (780mb) file so I had to use `` to manually convert the entities.


Leave a Reply

Your email address will not be published. Required fields are marked *