Error: The processing instruction target matching "[xX][mM][lL]" is not allowed

JavaXmlXslt

Java Problem Overview


This error,

> The processing instruction target matching "[xX][mM][lL]" is not allowed

occurs whenever I run an XSLT page that begins as follows:

<?xml version="1.0" encoding="windows-1256"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:include href="../header.xsl"/>
  <xsl:template match="/">
    <xsl:call-template name="pstyle"/>
    <xsl:call-template name="Validation"/>
    <xsl:variable name="strLang">
      <xsl:value-of select="//lang"/>
    </xsl:variable>
    <!-- ////////////// Page Title ///////////// -->
    <title>
	    <xsl:value-of select="//ListStudentFinishedExam.Title"/>
    </title>

Note: I removed any leading spaces before the first line, but the error still occurs!

Java Solutions


Solution 1 - Java

Xerces-based tools will emit the following error

The processing instruction target matching "[xX][mM][lL]" is not allowed.

when an XML declaration is encountered anywhere other than at the top of an XML file.

This is a valid diagnostic message; other XML parsers should issue a similar error message in this situation.

To correct the problem, check the following possibilities:

  1. Some blank space or other visible content exists before the <?xml ?> declaration.

Resolution: remove blank space or any other visible content before the XML declaration.

  1. Some invisible content exists before the <?xml ?> declaration. Most commonly this is a Byte Order Mark (BOM).

Resolution: Remove the BOM using techniques such as those suggested by the W3C page on the BOM in HTML.

  1. A stray <?xml ?> declaration exists within the XML content. This can happen when XML files are combined programmatically or via cut-and-paste. There can only be one <?xml ?> declaration in an XML file, and it can only be at the top.

Resolution: Search for <?xml in a case-insensitive manner, and remove all but the top XML declaration from the file.

Solution 2 - Java

Reason for me is 2 of following code in one xml

<?xml version="1.0" encoding="utf-8"?>

Solution 3 - Java

Check if you have this line repeated in your XML file

<?xml version="1.0" encoding="utf-8"?>

Solution 4 - Java

check your xml if your xml contain following line double remove one line(the duplicte line)

<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>

Remove the one duplicate line

<?xml version="1.0" encoding="utf-8"?>

Solution 5 - Java

Debug your XML file. Either there is space or added extra or fewer tags.

For better understanding build the project through the command line. Windows: gradlew build

In my case, AndroidManifest.xml has a blank space at the very first line

<Empty Row> // This Creates the issue 
<?xml version="1.0" encoding="utf-8"?>

Solution 6 - Java

There was auto generated Copyright message in XML and a blank line before <resources> tag, once I removed it my build was successful.

enter image description here

Solution 7 - Java

Another reason of the above error is corrupted jar file. I got the same error but for Junit when running unit tests. Removing jar and downloading it again fixed the issue.

Solution 8 - Java

in my case was a wrong path in a config file: file was not found (path was wrong) and it came out with this exception:

> Error configuring from input stream. Initial cause was The processing > instruction target matching "[xX][mM][lL]" is not allowed.

Solution 9 - Java

I had a similar issue with 50,000 rdf/xml files in 5,000 directories (the Project Gutenberg catalog file). I solved it with riot (in the jena distribution)

the directory is cache/epub/NN/nn.rdf (where NN is a number)

in the directory above the directory where all the files are, i.e. in cache

riot epub/*/*.rdf --output=turtle > allTurtle.ttl

This produces possibly many warnings but the result is in a format which can be loaded into jena (using the fuseki web interface).

surprisingly simple (at least in this case).

Solution 10 - Java

For PHP, put this line of code before you start printing your XML:

while(ob_get_level()) ob_end_clean();

Solution 11 - Java

In my case, I removed all blank space without needed code. And it worked

Solution 12 - Java

For my case, the tab is the trouble maker. Replace the tab with blank should resolve the issue

Solution 13 - Java

This error really break the memory efficiency of the XMLEventReader because fail when there is white spaces at the beginner of the input.

Any way, because is already coded to use it, I have to convert the InputStream or Reader source to String then call trim() to create another reader with this String to create the XML event reader.

Pseudocodes:

Reader reader = new StringReader(
        inputStreamToStringBuilder( getInputStream(), getContentCharset() )
                .toString().trim()
);
XMLEventReader eventReader = inputFactory.createXMLEventReader(reader);

Solution 14 - Java

It's worth checking your server's folders to see if there's a stray pom.xml hanging around.

I found that I had the problem everyone else described with a malformed pom.xml, but in a folder that I didn't expect to be on the server. An old build was sticking around unwelcome D:

Solution 15 - Java

just remove this line: <?xml version="1.0" encoding="utf-8"?> because this kind of error only come because of this line or you might also check the format of your line according the mentioned line in this answer.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEslam HamdyView Question on Stackoverflow
Solution 1 - JavakjhughesView Answer on Stackoverflow
Solution 2 - JavaAnuj JindalView Answer on Stackoverflow
Solution 3 - JavaKamau MbûguaView Answer on Stackoverflow
Solution 4 - JavaMazhar IqbalView Answer on Stackoverflow
Solution 5 - JavaChintan KhetiyaView Answer on Stackoverflow
Solution 6 - JavaHitesh SahuView Answer on Stackoverflow
Solution 7 - JavaPeter T.View Answer on Stackoverflow
Solution 8 - JavapikimotaView Answer on Stackoverflow
Solution 9 - Javauser855443View Answer on Stackoverflow
Solution 10 - JavaBeachhouseView Answer on Stackoverflow
Solution 11 - JavaAbir AhsanView Answer on Stackoverflow
Solution 12 - JavaRobinView Answer on Stackoverflow
Solution 13 - JavaDaniel De LeónView Answer on Stackoverflow
Solution 14 - JavaDan RaysonView Answer on Stackoverflow
Solution 15 - JavaKaranKulshresthaView Answer on Stackoverflow