Wednesday, July 03, 2013

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

I was doing some operation on some XML document and I got a strange error :
"The processing instruction target matching "[xX][mM][lL]" is not allowed. "
I just regenerated the error with the following code sample.



Then I searched in web I found that this is not related to any specific language, this is related to the XML declaration format.

According to the XML spec we can't have anything at all before the XML prolog. In our XML we are staring with XML declaration. So, that XML declaration should be the first character in our XML document no white space or any special characters are allowed before our XML document declaration.

So, the question is how we can avoid this in our above code?

- Use trim before parsing the XML string like below
   <cfset mydoc = XmlParse(trim(request.x))>

So, trim function will remove any extra spaces present in the document before starting the XML declaration.

- Write XML declaration as the first character of your XML text. No white space or any other characters at the starting position.

- Remove your XML declaration from the XML text.


Hope it will save your time...

No comments:

Post a Comment

Followers