The Processing Instruction Target Matching "[xX][mM][lL]" is Not Allowed

Posted May 18, 2006 at 7:18 AM

Tags: ColdFusion, XStandard WYSIWYG

I am starting to learn more about SOAP and XML in ColdFusion. Until now, I just haven't had much use of it. But now, I am dealing with web services that require SOAP requests and responses. Heck, I didn't even realize that ColdFusion has built in SOAP functions. But that's beside the point. I was trying to use the CFXML to create an XML object when I kept getting this error: ( The processing instruction target matching "[xX][mM][lL]" is not allowed ).

This error couldn't be less obvious. Luckily, after some quick googling I found the answer. Well, maybe not the answer, but a solution. It had to do with the document type declaration at the top: It was not the very first thing in the document - white space was. To fix this, I had to change the tag layout a bit to make the doc type come first:

 Launch code in new window » Download code as text file »

  • <cfxml variable="REQUEST.Response"
  • ><?xml version="1.0" encoding="UTF-8"?>
  • <soap:Envelope
  • ...
  • ...
  • </cfxml>

As you can see, I wrap the end ">" of the CFXML tag to the next line so that there is no white space between it and the "<?" of the document type declaration. Another solution to this would be to do a CFSaveContent and then do a CFXml on the Trim() of that variable. Or even perhaps XmlParse on the Trim() of it.

No matter what, it's fun to be getting in to the SOAP stuff. I am working on a ColdFusion solution for the XStandard WYSIWYG editor. I thought the XStandard editor was cool before but now, I am really seeing how amazing powerful and yet flexible it is.

Download Code Snippet ZIP File

Post Comment  |  Ask Ben  |  Other Searches  |  Print Page





Reader Comments

Aug 11, 2006 at 3:38 AM // reply »
1 Comments

Thx that's help me to


Aug 16, 2006 at 7:48 AM // reply »
74 Comments

No problem my man. Please feel free to contact me directly if you ever are stumped on a problem.


Dec 2, 2006 at 11:34 PM // reply »
1 Comments

Thanks for the information.
Really helped me a lot. I had unknowingly added blank space at the start of "<?xml version="1.0" encoding="ISO-8859-1"?>"
line in my web.xml file of the Tomcat server.

Saved alot of time...


Jan 3, 2007 at 6:56 AM // reply »
1 Comments

An easier method is to simply use the 'trim' function :)

Example:
xmlParse(trim(myXMLdoc))


Jan 3, 2007 at 7:11 AM // reply »
7,572 Comments

Neil,

True, Trim() is good so long as you have a stored XML string such as one stored via the CFSaveContent tag. However, this would require one extra step (the creation of the string THEN the parsing of it). But just taking out the white space in the beginning you can create AND parse the string in one step.

Both good options, especially depending on where you get the XML string from.


Jul 15, 2007 at 11:34 PM // reply »
1 Comments

I got the same error when I modified a common xml document in Eclipse.
Finally I fixxed it by removing the leading space of the first line.


Aug 6, 2007 at 8:59 AM // reply »
1 Comments

thanks for that, I had a comment at the start of my XML file and got this error, you just saved me a load of time.


Nov 16, 2007 at 4:11 AM // reply »
1 Comments

Thanks a lot.. first thing when i got this error was to google and find out the solution..
finding out the white space would have consumed a lot of time...!!!
Thanks..!


Jun 22, 2008 at 1:29 PM // reply »
3 Comments

Ben, thanks for the post. I ran into the exact same error last night because I mistakenly placed a comment before the XML declaration. When I went to Google for assistance, it was nice to see someone I know pop up at the top of the list. ;-)


Jun 23, 2008 at 6:00 PM // reply »
7,572 Comments

@Matt,

Glad to help. Missed you at CFUNITED, my man.


Jun 27, 2008 at 5:35 AM // reply »
3 Comments

Heh. *Someone* had to work that week! ;-)


Jun 27, 2008 at 8:11 AM // reply »
7,572 Comments

Ha ha, thanks for taking one for the team :)


Jul 2, 2008 at 6:17 AM // reply »
3 Comments

Why don't Adobe do the trimming of CR's etc as part of the function invocation.??


Jul 2, 2008 at 8:19 AM // reply »
7,572 Comments

@Martin,

That's not a bad idea. That would be cool as part of XmlParse().


Jul 31, 2008 at 2:59 AM // reply »
1 Comments

Thanks, helped me to quickly fix this issue (and move on to the next one ...).


Aug 1, 2008 at 2:28 PM // reply »
1 Comments

Hey that did the trick... And I'm way off ColdFusion BTW (Doing some EJB over NB).

Thanks!


Jan 5, 2009 at 2:14 AM // reply »
1 Comments

thanks a lot.. Really its a superb post. Got stuck from 2 hours, After seeign this sloved in few seconds..

Thnaks a lot :) :)


Jan 28, 2009 at 9:24 AM // reply »
2 Comments

You rock! This is the 2nd stumper you have solved for me this week! Keep on blogging!!!!


Jan 28, 2009 at 9:26 AM // reply »
7,572 Comments

@MDriscoll,

Awwwww yeaaaaah!


Jan 28, 2009 at 3:57 PM // reply »
14 Comments

Thank you thank you! these are the small things that can eat your whole day, or make it - in this case you just made mine much easier!


May 29, 2009 at 10:48 AM // reply »
1 Comments

It can happens even if you have more than one prolog in the same xml
so remove all "<?xml ... ?>" after the first!!

bye


May 29, 2009 at 2:56 PM // reply »
1 Comments

I concur with @Massimiliano. I ran into this last week. I generate temporary XML files with randomized names. The directory filled up and some of the "randomly named" files were reused, and the files were getting appended to. So there were basically two, well-formed xml bodies in one document. This was the error I got.


Jun 1, 2009 at 8:30 AM // reply »
7,572 Comments

@Massimiliano, @Brian,

Interesting guys; I never thought of that case scenario. Thanks for pointing it out.


Jul 25, 2009 at 3:38 AM // reply »
1 Comments

Thanks for your Help ...

Its done now ..

It works for me ..


Aug 14, 2009 at 3:08 AM // reply »
1 Comments

This was something I never knew with XMLs, until I read your post! Thanks a lot! Helped me!


JB
Sep 11, 2009 at 9:55 AM // reply »
1 Comments

I came across your post after pulling out most of my hair.
Thanks for this post, you saved the last few strands. It works fine now :o))


Sep 12, 2009 at 9:57 PM // reply »
7,572 Comments

@Niraj, @Prashanth, @JB,

Awesome! That's great to know this is still helping people.


Sep 16, 2009 at 10:05 AM // reply »
10 Comments

I know this is an old post but saved me a ton of frustration today!


Sep 18, 2009 at 4:58 PM // reply »
7,572 Comments

@Aaron,

Ha ha, awesome.


Dec 22, 2009 at 2:39 AM // reply »
1 Comments

it helped a lot


Dec 22, 2009 at 8:11 AM // reply »
1 Comments

Thanks, man. You just got me out of trouble within seconds. :-)


Jan 11, 2010 at 2:04 PM // reply »
1 Comments

Sweet - This fixed my problem! Thanks...


Feb 1, 2010 at 2:17 PM // reply »
7 Comments

I'm having this exact problem adn really struggling...

As mentioned above:

"It can happens even if you have more than one prolog in the same xml
so remove all "<?xml ... ?>" after the first!!"

Now my returned xml does indeed have multiple instances of <?xml version="1.0" encoding="UTF-8" standalone="no"?> within the string.

How do I get round this?

Cheers,

Phil


Feb 1, 2010 at 6:22 PM // reply »
7,572 Comments

@Phil,

Sorry if this is an obvious question, but you don't have control over the generation of the, right? It's always easier to fix the output than to work around it.


Feb 2, 2010 at 4:50 AM // reply »
7 Comments

Nope, it is an XML response generated by the Nominet EPP service.

Now I've cleaned it quite a bit already removing the ascii chars. etc but what I might try is replacing the </epp> with </epp>| and then looping over it to separate the response into three separate blocks...


Feb 2, 2010 at 4:59 AM // reply »
7 Comments

At last! That little idea worked nicely and I now have xmlparse working on the three blocks. Probably not the most efficient method but considering I've spent the last week on this flipping thing I don't care! :D


Feb 4, 2010 at 10:10 PM // reply »
7,572 Comments

@Phil,

You could probably also strip out ALL the meta tags in the beginning. I think the XML will parse fine without them. Something like:

trim( reReplace( yourXML, "<\?xml[^]+>", "", "all" ) )


Feb 4, 2010 at 10:11 PM // reply »
7,572 Comments

OOps, forgot the character in my character set:

trim( reReplace( yourXML, "<\?xml[^>]+>", "", "all" ) )


Feb 5, 2010 at 3:11 AM // reply »
7 Comments

Thanks Ben but the loop method actually works quite well as there is only 3-4 XML blocks returned each time.

I'm looping over them and stuffing the response into an array to return back to my calling page which is just the job :)


Feb 6, 2010 at 6:07 PM // reply »
7,572 Comments

@Phil,

Sounds good - I'm glad you got it working.


Mar 16, 2010 at 1:19 AM // reply »
1 Comments

well,that's help me too


Mar 17, 2010 at 10:13 AM // reply »
7,572 Comments

@Panda,

Yeah, this definitely got drilled into my head. I never work with XML these days without trim()ing the value :)


Post Comment  |  Ask Ben

Recent Blog Comments
Mar 20, 2010 at 12:07 PM
Drawing On The iPhone Canvas With jQuery And ColdFusion
Simply awesome. Saved my day. ... read »
Mar 20, 2010 at 9:00 AM
Building A Fixed-Position Bottom Menu Bar (ala FaceBook)
I would like to say thx for an easy way to create a bottom bar. I do have a ?. Is it possible to center the bar if i want to resize it to ex 85%. Regards Offenbach ... read »
Mar 19, 2010 at 7:26 PM
MySQL 3/4 - com.mysql.jdbc.Driver And allowMultiQueries=true
Thank you very much for this post. Adding allowMultiQueries="true" in context.xml didn't help until I added it to url as allowMultiQueries=true Good idea is to use prepared statements and it will he ... read »
Jim
Mar 19, 2010 at 4:49 PM
Nobody Puts Baby In The Corner!
Wow. This is like suddenly finding a support group for your secret shame. I'm not alone! I always liked this movie, even though it is extremely cheesy. I just wish Jennifer Grey hadn't gotten the ... read »
Mar 19, 2010 at 4:47 PM
Application.cfc OnRequest() Method Affects OnError() Arguments
@Jason and @Ben, I've been doing some CF9 refactoring on our systems and noticed an odd occurrence with onError as well. Found a way to work around my problem, but what I saw was... Background: Our ... read »
Jim
Mar 19, 2010 at 4:44 PM
Shoot 'Em Up Starring Clive Owen And Paul Giamatti
I actually enjoyed this movie quite a lot. It was different, certainly, but I think they were going for more of a Quentin Tarentino-"wow, that was weird"-vibe than an actual spoof. Once I realize ... read »
Mar 19, 2010 at 4:34 PM
An Intensive Exploration Of jQuery With Ben Nadel (Video Presentation)
Hey I guess the video is down. Is there anyway you can upload to youtube or vimeo or some other service? Greatly appreciated. ... read »
Mar 19, 2010 at 4:24 PM
ColdFusion CFPOP - My First Look
@Ben Thanks for the follow up! The root of the problem had to do with being able to trace bounced emails to specific records in a DB table. Let's say you run an email campaign and you get 1,000 bou ... read »