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 :-
[xml]
<cfsavecontent variable="local.body">
<?xml version="1.0"?>
<html><body>
Just a test Email!
</body></html>
</cfsavecontent>
[/xml]
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 :-
[xml]
<cfsavecontent variable="local.body"><?xml version="1.0"?>
<html><body>
Just a test Email!
</body></html>
</cfsavecontent>
[/xml]
Its little things like this that sometimes eat up all your day.
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 🙂
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
sorry the snippet did not got properly pasted:
S2
1400312
T
MA
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 🙂
The frustrating thing is that web services will come back with such a general message like “400 bad request”. Grrrr!
OK…took out all the whitespace, but I am still getting the error. Any ideas?
@Sonya, did you try doing a trim() as well?
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
@Dima, can I have a look at your code?
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
@Dima, I dont think that should make a difference. Did you test it out?
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
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…
Thanks a lot ..
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.
Thanx for the reply…..it solved my pblm….just edit the file using text and remove white spaces from the beginning.
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.
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.
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.
thank you …you saved me
Thanks!
Exactly fixed it, thanks for saving me some time!! Happy Holidays!
Thank You!
Thanks a lot
Hi its really helpful for me to save my whole day. Thanks a lot.