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.