1

I'm learning how to invoke web-services using coldfusion 7 (later we'll upgrade). I found some free web services to use.

<cfscript>
    stArgs = structNew(); 
    stArgs.symbol = "msft"; 
</cfscript> 

<cfinvoke webservice="http://www.webservicex.net/stockquote.asmx?WSDL" method="GetQuote" argumentcollection="#stArgs#" returnvariable="aTemp">

The result from #atemp# is

<StockQuotes><Stock><Symbol>msft</Symbol><Last>47.77</Last><Date>10/20/2015</Date><Time>4:00pm</Time><Change>+0.15</Change><Open>47.41</Open><High>47.81</High><Low>47.02</Low><Volume>30793995</Volume><MktCap>382.06B</MktCap><PreviousClose>47.62</PreviousClose><PercentageChange>+0.31%</PercentageChange><AnnRange>39.72 - 50.05</AnnRange><Earns>1.48</Earns><P-E>32.28</P-E><Name>Microsoft Corporation</Name></Stock></StockQuotes>

My question is how do I extract (for example) the PercentageChange result? Thank you!

Alverant
  • 229
  • 2
  • 5
  • 13
  • 2
    (Edit) What have you tried? :) Hint: The [web service](http://www.webservicex.net/stockquote.asmx?op=GetQuote) returns text/xml. Use [XML Functions](http://help.adobe.com/livedocs/coldfusion/7/htmldocs/00000372.htm#3468770) like to parse the result string into an object. (CFdump the object to see the structure). Then access the results with dot notation. Side note, rather than mixing cfscript and tags, it is cleaner to use all cfscript IMO. See the `createObject` docs for an alternative to `cfinvoke`. – Leigh Oct 20 '15 at 21:41
  • 1
    As Leigh said, XML Functions are useful. Try ``. This will allow you to use the response as a CF object. After that, it's a matter of getting to whatever node you're looking for: `` – Chester Oct 20 '15 at 22:26
  • I tried using aTemp.symbol and was getting an error. The responseXML code worked. Thank you!! – Alverant Oct 21 '15 at 14:14

0 Answers0