Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

XMLParse problem when using XML

Enthusiast ,
Jun 16, 2010 Jun 16, 2010

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>

331
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 16, 2010 Jun 16, 2010
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources