Fix [Fatal Error] :2:6: The processing instruction target matching [xX][mM][lL] is not allowed.

Exception:
Fatal Error] :2:6: The processing instruction target matching "[xX][mM][lL]" is not allowed.
org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 6; The processing instruction target matching "[xX][mM][lL]" is not allowed.
	at java.xml/com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:262)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:342)
	at org.code2care.java.examples.SAXParseExceptionExample.main(SAXParseExceptionExample.java:21)

The most common reason for his error is that the XML file you are trying to parse using the SAXParser is not correct. All XML files that should start with the string <?xml, there should be nothing before this text in your .XML file, not even spaces or new lines.

 
<?xml version="1.0" encoding="UTF-8"?>
<employees>
    <employee>
        <name>Sam Jose</name>
        <dob>1990-05-15</dob>
        <city>New York</city>
    </employee>
    <employee>
        <name>Adam Kale</name>
        <dob>1985-11-30</dob>
        <city>Chicago</city>
    </employee>
    <employee>
        <name>Mike Smith</name>
        <dob>1992-07-10</dob>
        <city>London</city>
    </employee>
</employees>

If you look closely at the above employees.xml file, you will notice that there is a new line character before the start of the <?xml tag, which will cause this issue. Just remove it and you are good to go!

Fix - Fatal Errorhe processing instruction target matching the processing instruction target matching x m l is not allowed

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!