House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Cleaner way to retrieve a value from an XML node (XML-RPC)

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Cameron Johnson
06/30/2009 09:35 AM

Hi, folks. I'm retrieving an XML packet from an API that uses the XML-RPC standard (http://www.xmlrpc.com/spec). When I connect to the Login method of this API, I need to pull the session ID out of the packet. I can do that long-hand with this: <cfset local.loginResponseSID = local.requestXMLObject.XMLRoot.XMLChildren[1].XMLChildren[1].XMLChildren[1].XMLChildren[1].XMLChildren[1].XMLChildren[2].XMLChildren[1].XMLText /> But, there must be a cleaner way to do this, right? A note: the node that I am looking for is called <string>, BUT, if the login fails, there are multiple nodes called <string> in the response, so I can't do an XMLSearch for "//string[.]" and get just the one I need. FYI, the specific API that I am hitting is for iThenticate and the example is on page 16 of this PDF: https://ne.edgecastcdn.net/800404/static.ithenticate.com/static/build/media/e356a7e98a516945bba0af5293e8eb48cb_iThenticateAPIGuide.pdf) Any help to streamline this is much appreciated. Cameron

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dave Watts
07/01/2009 02:40 AM

> I'm retrieving an XML packet from an API that uses the XML-RPC standard > (http://www.xmlrpc.com/spec). First, have you looked at this? http://support.journurl.com/users/admin/index.cfm?mode=article&entry=362 ----- Excess quoted text cut - see Original Post for more ----- Almost certainly. In general, you can simply refer to XML elements as nested arrays and structures, using the names of the elements; if they're repeated within a single parent, you use array notation to get to the one you want. So, if you had a document like this in myXmlObj: <xmldoc>      <child>           <grandchild>value1</grandchild>      </child>      <child>           <grandchild>value2</grandchild>      </child> </xmldoc> you could get to "value2" using: myXmlObj.child[2].grandchild.xmlText (Actually, since it's nearly 3am, I could very well have a minor error in that, but the basic point stands.) Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Software provides the highest caliber vendor-authorized instruction at our training centers in Washington DC, Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location. Visit http://training.figleaf.com/ for more information!

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Cameron Johnson
07/01/2009 12:28 PM

Thank you, Dave. >First, have you looked at this? >http://support.journurl.com/users/admin/index.cfm?mode=article&entry=362 Great! I was searching for a component like that, and I never came across this one; just the two old ones that the author references. ----- Excess quoted text cut - see Original Post for more ----- I see. Going by the names of the nodes makes sense, and it's easier to read/manage. In that case, I've got this: <cfset local.loginResponseSID = local.requestXMLObject.methodResponse.params.param.value.struct.member.value.string.xmlText /> Is that the simplest/cleanest that this is going to get? Much appreciated. Cameron

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Casey Dougall
07/01/2009 02:06 PM

On Wed, Jul 1, 2009 at 12:23 PM, Camer ----- Excess quoted text cut - see Original Post for more ----- Do you always know how many children will be returned for a specific node? If not you want to check this out. It will loop over children and you can work specifically with those items. http://www.bennadel.com/blog/1039-Ask-Ben-Iterating-Over-A-ColdFusion-XML-Document.htm

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Cameron Johnson
07/02/2009 05:01 PM

>Do you always know how many children will be returned for a specific node? > >If not you want to check this out. It will loop over children and you can >work specifically with those items. > >http://www.bennadel.com/blog/1039-Ask-Ben-Iterating-Over-A-ColdFusion-XML-Document.htm Yes, but the number is different depending on the success or failure of the login. My instinct is to add logic to determine that success/failure first, then go find the node I need. Or, I'll see if I can use the technique in that blog to make it more compact. Thanks for pointing that out, Casey. (And thanks, Ben, for writing it). Cameron

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dave Watts
07/01/2009 05:13 PM

----- Excess quoted text cut - see Original Post for more ----- Yes, that's as good as it'll get if that's the structure of your XML document, I think. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Software provides the highest caliber vendor-authorized instruction at our training centers in Washington DC, Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location. Visit http://training.figleaf.com/ for more information!


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

March 21, 2010

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
   1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31