This post is just a little tip that I think can take a lot of time in trying to solve.

I was building a variable , using cfsavecontent, to process later on and there was absolutely nothing wrong with the code according to me, as below :-


<cfsavecontent variable="local.body">

<?xml version="1.0"?>
<html><body>
Just a test Email!
</body></html>
</cfsavecontent>

As you can see, its pretty hard to say if there is anything wrong with the code above. But I kept getting the error as soon the variable was passed to XmlParse().

After about 15 minutes, I google’d it and immediately came up with this post from Ben.Thanks Ben!

So, the solution is, there should be no characters (not even white space) before the starting XML. Or do a Trim() before passing it on to the XmlParse() but sometimes that option is not available because XmlParse could be sitting inside a service layer somewhere.

So, the code above really should be like this, notice the starting XML immediately after cfsavecontent :-


<cfsavecontent variable="local.body"><?xml version="1.0"?>
<html><body>
Just a test Email!
</body></html>
</cfsavecontent>

Its little things like this that sometimes eat up all your day.

Tagged with:  

25 Responses to The Processing Instruction Target Matching “[xX][mM][lL]” is Not Allowed

  1. Ben Nadel says:

    Another place where this has gotten me and is harder to debug is when you post SOAP XML to a web service using . Be sure to TRIM() the XML value you pass or the SOAP API might not parse it 🙂

    • Pallavi Verma says:

      Hi Ben,
      I am Pallavi I need your help in executing 1 xml through SOAP, I am getting this same error tried by removing spaces too, still getting this exception. It would be kind of you if you could help.
      Pasting you the snippet of request xml that I am trying.

      S2
      1400312
      T
      MA

  2. Anuj Gakhar says:

    Thats right Ben. I always do that as a practice , but sometimes it just completely slips your mind, thats when posts like these come handy 🙂

  3. Ben Nadel says:

    The frustrating thing is that web services will come back with such a general message like “400 bad request”. Grrrr!

  4. Sonya says:

    OK…took out all the whitespace, but I am still getting the error. Any ideas?

  5. Anuj Gakhar says:

    @Sonya, did you try doing a trim() as well?

  6. Dima says:

    Hi,

    I still get this error message.
    I don’t have any characters or white space before <?xml….

    I added .trim() call before parsing the file. I, also, validated the xml file for well-formness in XML Spy.

    Are there any other ideas for fixing this error?

    I declare multiple schemas to validate the file. They are declared in the root element after the main xml declaration

    Any help would be appreciated
    Thanks

  7. Anuj Gakhar says:

    @Dima, can I have a look at your code?

  8. Dima says:

    Would it matter to a parser if the string that contains contents of xml file is all in upper case?

    I think this is the issue for me.
    I havent tested it yet

  9. Anuj Gakhar says:

    @Dima, I dont think that should make a difference. Did you test it out?

  10. Dima says:

    After some tests I found out that
    the first line in the XML file

    must be in lower case. Otherwise the same error shows up:
    “The Processing Instruction Target
    Matching “[xX][mM][lL]” is Not Allowed”
    Also the tags in the schema should be the same case as the tags in the XML file.

    Thanks for your help

  11. jks says:

    I had this weird error and was searching the net for some answers….and found this site!! Thank you soo much – you solved my problem!!! i should have searched the net before…

  12. Nitheesh R says:

    Thanks a lot ..

  13. Horn says:

    Thank you all. I happened to stumble into that annoying mistake too. Emacs showed me that there’d been a full line of white spaces in the beginning of my XML file. No idea why i didn’t notice that in other text editors.

  14. Ankit Maheshwari says:

    Thanx for the reply…..it solved my pblm….just edit the file using text and remove white spaces from the beginning.

  15. Direct mail says:

    I too came up with the same error where it showed that the processing instruction was not allowed while I was trying to construct a similar variable as yours. Since I could not find anything particularly wrong about the code, I had to stop the work. Now that you have come up with the solution for this, I was able to rectify the situation. I never thought that the presence of characters before the starting XML would create such an obstruction.

  16. Pavel M. says:

    I was playing about with the eBay developer web services and found out that the xmlns set on the root element was invalid. This resulted in the above error.

    Here’s the xml:

    But if you try and go to the URL in the xmlns you will see it’s page not found. And this was causing the problem.

    In PHP I just did a string replace to eliminate it just because I needed a very quick fix.
    Hope this helps someone.

  17. Asma Khanam says:

    One more reason for failure of parsing could be the doctype. For example if the xml file contains a doctype element
    and .dtd is not found. then also it will through the same error. Simply thing to avoid this error is just replace the line with empty space.

  18. ruwantha86 says:

    thank you …you saved me

  19. Anthony says:

    Exactly fixed it, thanks for saving me some time!! Happy Holidays!

  20. George says:

    Thank You!

  21. anuranisham says:

    Thanks a lot

  22. Firoz says:

    Hi its really helpful for me to save my whole day. Thanks a lot.

Leave a Reply

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 445 other subscribers

© 2011 Anuj Gakhar
%d bloggers like this: