Skip to main content
Inspiring
December 26, 2011
Question

XML value not reading correctly

  • December 26, 2011
  • 1 reply
  • 1253 views

I am trying to read an XML response after passing data to a 3rd party server and receiving a reply then act appropriately upon the value of a field (response)

The problem is that when I have my CFIF statement, the logic seems to be backwards, if it equals FAIL then I cfabort, but only if I use CFIF NOT does it then cfabort, this is not right at all

As the code stands, the CFIF the value of response IS fail it should CFABORT, but it doesn't

Below is the code, and also a CFDUMP, anybody any ideas?

Thanks

Mark

xml document [short version]
XmlComment
XmlRoot
xml element
XmlNameiimobileengine
XmlNsPrefix
XmlNsURI
XmlText
XmlComment
XmlAttributes
struct [empty]
XmlChildren
xml element
XmlNamestage
XmlNsPrefix
XmlNsURI
XmlTextPRELOAD
XmlComment
XmlAttributes
struct [empty]
XmlChildren
xml element
XmlNameresponse
XmlNsPrefix
XmlNsURI
XmlTextFAIL
XmlComment
XmlAttributes
struct [empty]
XmlChildren
xml element
XmlNamelid
XmlNsPrefix
XmlNsURI
XmlText
XmlComment
XmlAttributes
struct [empty]
XmlChildren
xml element
XmlNamelsdid
XmlNsPrefix
XmlNsURI
XmlText
XmlComment
XmlAttributes
struct [empty]
XmlChildren
xml element
XmlNamereason
XmlNsPrefix
XmlNsURI
XmlTextCarrier Not Supported
XmlComment
XmlAttributes
struct [empty]
XmlChildren
xml element
XmlNametc
XmlNsPrefix
XmlNsURI
XmlText
XmlComment
XmlAttributes
struct [empty]
XmlChildren
iimobileengine
XmlText
stage
XmlTextPRELOAD
response
XmlTextFAIL
lid
XmlText
lsdid
XmlText
reason
XmlTextCarrier Not Supported
tc
XmlText

<cfset myxml=XMLParse(#cfhttp.filecontent#)>

<CFDUMP VAR="#myxml#">

        <!--- CHECK FOR FAIL RESPONSE --->

<CFIF #myxml.iimobileengine.response# IS "FAIL">

<CFOUTPUT>Stage 1: #myxml.iimobileengine.reason#</CFOUTPUT>

<CFABORT>

</CFIF>

This topic has been closed for replies.

1 reply

Community Expert
December 26, 2011

Isn't "response" an element? If so, what happens when you reference myxml.iimobileengine.response.XmlText (the text node within your response element) instead of referencing the element (which is not a string) directly?

Dave Watts, CTO, Fig Leaf Software

Dave Watts, Eidolon LLC
ACS LLCAuthor
Inspiring
December 26, 2011

Hey Dave, it works, THANKS!

I have never worked with reading XML's before so I found it a little confusing.

The thing that threw me and still does is that if I CFOUTPUT #myxml.iimobileengine.response# without the XMLText part, then it does display FAIL, yet doesnt read it in a logic CFIF statement..strange (well strange to me right now

Thanks

Mark

Community Expert
December 26, 2011

Well, working with XML in CF is kind of strange. CF generally makes it much easier, but as a result it can be difficult to figure out how something should act when you're working with XML in CF.

In this case, when you output the element, it outputs all the text nodes within the element, but that doesn't mean that the text node value is equivalent to the element. For example, let's say you had an XML fragment like this:

<tag1>some text

     <tag2>some more text</tag2>

     still more text</tag1>

When you output that with CF, I would expect you'd either get:

some text

some more text

still more text

or:

some text

still more text

(I can't be bothered to test)

But the point is that a single XML element can have all sorts of things in it, including multiple text nodes.

Dave Watts, CTO, Fig Leaf Software

Dave Watts, Eidolon LLC