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

Colon in XML response

New Here ,
Nov 04, 2011 Nov 04, 2011

Copy link to clipboard

Copied

Hi,

I'm having a devil of a time with this.  I'm using cfhttp to perform a REST transaction, the returned XML being parsed with xmlparse and saved to a variable called "xmlfile".

The resulting xml has a colon in.  When I try reference part of it, my variable would look like:

#xmlfile.ns3:LookupMyAccountInfoResponse.ns3:numberOfCheckouts.xmlText#

Of course this fails due to the colons..

I understand there's some sort of bracket notation that should allow this to work. No matter where I put the brackets, it still fails.

Help?

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

correct answers 1 Correct answer

Guide , Nov 04, 2011 Nov 04, 2011

Should be

#xmlfile["ns3:LookupMyAccountInfoResponse"]["ns3:numberOfCheckouts"].xmlText #

Votes

Translate

Translate
Guide ,
Nov 04, 2011 Nov 04, 2011

Copy link to clipboard

Copied

Should be

#xmlfile["ns3:LookupMyAccountInfoResponse"]["ns3:numberOfCheckouts"].xmlText #

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
New Here ,
Nov 04, 2011 Nov 04, 2011

Copy link to clipboard

Copied

Thank you, thank you!  Seems so easy, but I just couldn't get it -- makes total sense now.  Much appreciated,

Peter

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
Guide ,
Nov 04, 2011 Nov 04, 2011

Copy link to clipboard

Copied

No worries, it's a Friday afternoon and I had lots of more boring work to get out of.

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
New Here ,
Nov 04, 2011 Nov 04, 2011

Copy link to clipboard

Copied

Well, I may have spoken too soon....or actually a slightly different question.  Now I want to access an element.  I'm looping over the result after counting the number of responses, but when I try and access the element using the loop index, it can't find it -- is this because I bracketed it?

<cfloop from="1" to="#numtitles#" index="a">

 

#xmlfile["ns3:LookupMyAccountInfoResponse"]["ns3:patronCheckoutInfo"]["ns3:title"].xmlText#<br>

  

</cfloop>

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
Guide ,
Nov 04, 2011 Nov 04, 2011

Copy link to clipboard

Copied

Break it down slowly, use single quotes if needed inside doubles and and reference the XmlChildren attribute to get child elements. Something like this:

<cfloop from="1" to="#arraylen(xmlfile['ns3:LookupMyAccountInfoResponse'].xmlChildren)#" index="i">

     <cfset thisElement = xmlfile['ns3:LookupMyAccountInfoResponse'].xmlChildren />

     <cfdump var="#thisElement#">

     <cfloop from="1" to="#arrayLen(thisElement.xmlChildren#" index="j">

          <cfset thisInnerElement = thisElement.xmlChildren />

          <cfdump var="#thisInnerElement#" />

     </cfloop>

</cfloop>

Until you have everything you're after. The important thing to remember is that child elements are represented by an ARRAY by the name XmlChildren.

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
New Here ,
Nov 04, 2011 Nov 04, 2011

Copy link to clipboard

Copied

Thanks again.  I'm still learning how to work with XML, so your response is most helpful.

Peter

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
Guide ,
Nov 04, 2011 Nov 04, 2011

Copy link to clipboard

Copied

LATEST

No worries, it's a bit odd as with CF you never *really* deal with XML when reading - you tend to deal with XML that's been converted into CF structs and arrays. You basically need to completely forget that you're dealing with XML, and just deal with it as you would any CF structure.

Don't try and do too much in one go, frequently dump out your variables to check you have what you *think* you have, and you'll get the hang in no time

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