Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting XML parse error in ColdFusion. Can the packet returned be validated?

Tags:

coldfusion

xml

Getting an error on occasion on a specific CF page. Offending code listed below. Very odd because when I rebooted CF it went away. Can the XML be checked via XMLValidate to prevent this from happening?

Is this some sort of CF bug since the error disappeared after reboot of CF? I have a feeling that the error will resurface at some point.

An error occured while Parsing an XML document. The element type "meta" must be terminated by the matching end-tag "".

<cfhttp method="get" url="http://bs.mysite.com/webservice/rec/get.sbs?customerId=345S4BE8x&itemId=#product_id#&number=20&ruleId=#product.location_tab_accessories#">

<cfset result = xmlParse(cfhttp.FileContent)>
<cfset recs = xmlSearch(result, "/result/thsite/site/itemId")>
like image 892
jeff Avatar asked Apr 08 '10 01:04

jeff


1 Answers

You can use XmlValidate() to validate a xml doc against a DTD or a Schema. XmlParse() itself validates the document and throws an error if the xml is not well formed. It also supports a validator parameter as of CF7. Use cftry/cfcatch to handle the exception.

The error message you received indicates that you didn't receive the XML document you expected, but a HTML page with unclosed meta tags in it. Maybe this could be a error page or some other html page you've been redirected to.

Did something change with DNS/IP of the target URL? Cfhttp does DNS caching (the underlying JVM does) and this can lead to strange effects like you experienced here. Restarting ColdFusion clears the cache, the url is resolved again and your request will be successful.

like image 170
Andreas Schuldhaus Avatar answered Nov 15 '22 07:11

Andreas Schuldhaus