DomParser - The entity name must immediately follow the '&' in the entity reference

504 Views Asked by At

I am trying to read an XML file which has & character. Due to this character we are getting "The entity name must immediately follow the '&' in the entity reference xml" error. I am aware that if you replace '&' with "&" we can resolve this issue. But in my case I don't have the control over XML creation, I only parse and use the already create XML. I am using DOM parser to parse the XML.

So I cannot add escape characters in XML to resolve the issue. Is there any way we can tell DOM parser to ignore these kind of special characters while parsing.

1

There are 1 best solutions below

0
Michael Kay On

You need to go back to the people who created this file and explain to them that it's useless if it's not well formed XML. It's like sending you something that claims to be an Excel spreadsheet but won't actually open in Excel (the only difference is that you can look at the not-quite-XML document and see what's wrong with it.) Don't accept shoddy data.