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!

-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Java,
- Convert Java Map Collection Object to JSON String using Jackson
- Java Stream flatmap() Examples
- [Fix] Instant java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Years
- How to run Java Unit Test cases with Apache Maven?
- How to check if Java main thread is alive
- [Fix] java: incompatible types: incompatible parameter types in lambda expression error
- Parsing CSV file using Java code example (Comma Separated File)
- Unhandled exception type InterruptedException : Java Threads
- Native getClass() method from java.lang.Object Class Explained with examples.
- Java Jackson ObjectMapper Class with Examples
- Java 8 Streams map() with examples
- Java 8 - Convert List to Map Examples
- IntelliJ: Error: Could not find or load main class, java.lang.ClassNotFoundException
- Java Stream with Multiple Filters Example
- How to Clear StringJoiner in Java 8
- Spring 5 IoC Example with application Context XML (ClassPathXmlApplicationContext) and Gradle.
- How to get end of line (EOL) or new line character \r \n in Java
- Spring Boot CRUD Examples using JDBCTemplate
- Delete a File in Java with Examples
- Implementing Insertion Sort Algorithm in Java Program
- Java JDBC Batch Update Example with PreparedStatement
- Java JDBC Select Multiple Records from table as List using PreparedStatement
- [Hibernate] The method buildSessionFactory() from the type Configuration is deprecated
- How to fix Java HTTP java.net.UnknownHostException
- Java 8 Display time in 12 hour AM PM format
More Posts:
- Error code 0xCAA82EE2: Something went wrong (request timed out) [Microsoft] - Microsoft
- 10 ways to Convert String to a Number in JavaScript - JavaScript
- How to install Google Chrome using Mac Terminal - Google
- Install Docker Desktop on M1/M2 Apple Silicon ARM Chip Mac - Docker
- Implementing Merge Sort Algorithm in Java Program - Java
- Capture cURL Request Output to a File - cURL
- How to change the default location of Mac Screenshot - MacOS
- Fix: Error: Could not find or load main class org.gradle.wrapper. GradleWrapperMain - Gradle