getSearchResult

8 views
Skip to first unread message

adrianrosca

unread,
Oct 16, 2009, 7:08:42 PM10/16/09
to Fotolia API
Hello,

Anyone knows how to handle the response from "getSearchResult" with
XmlRpc.Net?

The result is some kind of array:

Example response:
<methodResponse>
<params>
<param>
<value>
<struct>

<member>
<name>nb_results</name>
<value>
<int>459</int>
</value>
</member>

<member>
<name>0</name>
<value>
<struct>
<member>
<name>id</name>
<value>
<int>1384045</int>
</value>
</member>
</struct>
</value>
</member>

<member>
<name>1</name>
<value>
<struct>
<member>
<name>id</name>
<value>
<int>1384045</int>
</value>
</member>
</struct>
</value>
</member>

</struct>
</value>
</param>
</params>
</methodResponse>

How do I define an array that can be parsed from members that are
named "0", "1", "2", etc?

/ Adrian

Robert Davies

unread,
Oct 17, 2009, 9:49:39 AM10/17/09
to Fotolia API
(emailed this last night but thought I'd post here too for anyone
else)

Primarily you use the XmlRPCStruct class (which also is used for
arrays)
The official DOCs are a bit distracting, but here's where I started:
http://www.xml-rpc.net/faq/xmlrpcnetfaq.html#2.1



Mine is implemented something like this:

CLASS/INTERFACE:

[XmlRpcUrl("http://us.fotolia.com/Xmlrpc/rpc")]
public interface IFotolia : IXmlRpcProxy
{
[XmlRpcMethod("xmlrpc.test")]
XmlRpcStruct test(string apikey);

[XmlRpcMethod("xmlrpc.getSearchResults")]
XmlRpcStruct getSearchResults(
string apikey,
XmlRpcStruct Params,
string[] result_fields);
}

CALL/HANDLE:

IFotolia FotoliaApi = (IFotolia)XmlRpcProxyGen.Create(typeof
(IFotolia));;
XMLRPCStruct searchResults = FotoliaApi.getSearchResults(apikey,
Params /* an XMLRPCStruct */, result_fields /*a regular string array
*/);
if (searchresults != null)
{
for(int i=0; i<Counter; i++)
{
XmlRpcStruct Record = (XmlRpcStruct)(searchresults[i.ToString
()]);
if(Record != null)
{
//Do something with Record["title"] //Or whatever
fieldName
}
}
}

As long as the cookcomputing dll is registered you shouldn't need to
add anything else.

Of course you may want to class that up to re-use your objects
effectively.

Hope that helps :)
Bob
Reply all
Reply to author
Forward
0 new messages