Wednesday, December 26, 2007

Cold Fusion not parsing xml \ Dreamweaver adding characters

This is the primary reason I started this blog. I had dealt with this issue before but since I didn't write it down someplace I had to figure it out all over again.

If you have an xml file that you edit and upload to a server, there are cases where hidden characters will prevent the code from being parsed using the XMLParse() method. It seems that some editors will place hidden characters in the beginning of the xml -- i think its because the encoding is incorrect. The xml will look fine in Dreamweaver and even notepad but will crash and burn in some parsers. For instance I had done the xml for www.bahaullah.org and stored it on a server. I then did:

XMLContent = ToString(trim(cfhttp.filecontent));
XMLContent = XMLParse(XMLContent);


and instead of parsing the xml it threw this error:

An error occured while Parsing an XML document. Content is not allowed in prolog

To fix it I had to edit the file directly on the server using vi and removed the characters that appears just before the opening root node.

AND then it appears that the errors can also be introduced in Dreamweaver CS3 for .cfm files too!! While I was trying to modify a .cfm file and change the path to the file, it apparently added odd characters along with the "_" -- even if I tried to remove the "_" again.

I also had to fix this by editing the .cfm file using vi in unix.

This is very frustrating as I have spent hours debugging errors that I can't even see...

UPDATE-- It's a short time later but I just found the main gremlin. I had also tried opening the file in Microsoft XML Notepad 2007 and this is what added the special characters! I should have known that it would be caused by Microsoft and not Adobe Dreamweaver ;-)

Although I'm still not sure what caused the issue with the config.cfm edit too -- but i'm sure it CAN'T be adobe!

No comments: