Copy link to clipboard
Copied
CF seems to have problems parsing XML that starts like this:
<?xml version="1.0" encoding="UTF-8"?>
<ArrayOfRateInfo>
instead of
<ArrayOfRateInfo xmlns="http://schemas.datacontract.org/2004/07/SingletonRateService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
Can you advise why this is so?
XmlSearch never returns data when using the latter example even when usign XMLParse
<cfset xmlCCY=XMLParse("http://site.com/rateservice.svc/")>
<cfscript>
selectedElements = XmlSearch(xmlCCY, "/ArrayOfRateInfo");
for (i = 1; i LTE ArrayLen(selectedElements); i = i + 1)
writeoutput(selectedElements.XmlText & "<br>");
</cfscript>
Copy link to clipboard
Copied
Nope, CF doesn't have problems with that sort of thing, as quickly demonstrated here:
<cfset sX = '<?xml version="1.0" encoding="UTF-8"?><ArrayOfRateInfo><foo>bar</foo></ArrayOfRateInfo>'>
<cfset x = xmlParse(sX)>
<cfdump var="#x#">
<cfset a = xmlSearch(x, "/ArrayOfRateInfo/foo")>
<cfdump var="#a#">
So whatever issue you're having, it ain't that.
CF is flaky when there's anything before the <?xml?> tag though. Like whitespace or a BOM.
What error are you getting?
Also, in your second example, you need to indicate in your xpath expression that you're not using a prefix for your namespace, like this:
<cfset a = xmlSearch(x, "/:ArrayOfRateInfo/:foo")>
Why? Dunno... I have no idea about XML namespaces... I just googled that.
--
Adam