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

XML value not reading correctly

Enthusiast ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

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>

TOPICS
Advanced techniques

Views

1.1K

Translate

Translate

Report

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
Community Expert ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Community Expert ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

I am going to try avoid this as much as possible! Too confusing!

Looks like in this case I can/should add XMLText to the end of all of my statements including output of results

Votes

Translate

Translate

Report

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
Community Expert ,
Dec 29, 2011 Dec 29, 2011

Copy link to clipboard

Copied

LATEST

ACS LLC wrote:

I am going to try avoid this as much as possible! Too confusing!

Looks like in this case I can/should add XMLText to the end of all of my statements including output of results

The fact that it can work without XmlText is down to luck. That, I suppose, is also what Dave means. ColdFusion is forgiving you. In fact, your coming here with the problem is warning enough.

Your code should, strictly speaking, be something like:

<CFIF myxml.iimobileengine.response.XmlText IS "FAIL">
<CFOUTPUT>Stage 1: #myxml.iimobileengine.reason.XmlText#</CFOUTPUT>
<CFABORT>
</CFIF>

To see why adding XmlText is a good habit, run the following test:

isXml(myxml.iimobileengine.response): <cfoutput>#isXml(myxml.iimobileengine.response)#</cfoutput><br>

<cfdump var="#myxml.iimobileengine.response#">

It should convince you that myxml.iimobileengine.response isn't just simple text.

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

I just went back and double checked and sure enough they both OUTPUT the same but only one of them actually works within a logic statement, so that can be rather confusing and open to potential coding errors

This code, gives

FAIL

FAIL

<CFOUTPUT>

#myxml.iimobileengine.response#

<br>

#myxml.iimobileengine.response.XmlText#

</CFOUTPUT>

Votes

Translate

Translate

Report

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
Documentation