Tuesday, January 03, 2012

Message: The entity "nbsp" was referenced, but not declared.

While parsing an XML using Stax I encountered this error.

Even though the data was inside CDATA tags it was still giving this error which was puzzling. On further analysis I found out that Control Characters (^M) was causing this problem.

To fix it in Unix/Linux, just remove control characters and I found this nifty command to do it:
tr -d "\r" < inputfile > outputfile