Problem with XML <!DOCTYPE

Hello, I am trying to use XmlReader to parse an XML file. With many other XML files I have had no problems, but a file I have to work with begins as follows:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mT:stockItems [
    <!ENTITY % autoprintEnt SYSTEM "autoprint.ent">
< mT:stockItems xmlns=""

When I try to parse the file, I get an exception: error number 21 at line 4; “error in processing external entity reference”.

Does anyone know if there is a way around this? Suppressing the known errors would be an acceptable solution for this particular project.

My current thinking is to re-write the XML file, line by line, skipping lines 2 through 5, then parsing the new file - but I wondered if there was a more elegant way.

I think line 4 should read:


Unfortunately, this is a file that is incoming from a 3rd party, but I could ask them to check. But if I change the ‘%’ to ‘&’ I get different exceptions.

The original XML is legal according to the ‘Check This Document’ feature of my XML editor ‘EditiX’.

Try and remove that line and see what happens. It might work that way, so a simple ReplaceAll with empty string might solve all your issues.

Yes, removing the lines definitely fixes it and it is what I have been doing to continue development and pretend it is all great.

I guess the remaining question is, should the XmlReader class be triggering exceptions for legitimate XML?