You will find several examples of the use of the SOIF API in PortalServer-base/sdk/rdm/examples directory.
This section discusses an example that is similar to (but not necessarily identical to) example1.c. It shows how to iterate through a SOIF stream and print the URL and number of attributes of each SOIF in the stream.
This example assumes that you have already created a file containing a SOIF stream which is available on stdin. For example, you could have created a SOIF stream containing one or more RDs from the search engine database, which you would do by using the routines in RDM.h.
This example uses SOIF_ParseInitFile() to create a SOIF stream from the standard input.
/* Example 1 - Simple SOIF Stream Parsing */
#include <stdio.h>
#include <stdlib.h>
#include “soif.h”
int main(int argc, char *argv[])
{
/* Define a SOIFStream and SOIF */
SOIFStream *ss;
SOIF *s;
char *titleptr;
/* Open a SOIF stream that gets its SOIF from stdin */
ss = SOIF_ParseInitFile(stdin);
/* SOIFStream_IsEOS() checks if this is the end of the stream */
while (!SOIFStream_IsEOS(ss)) {
if (!(s = SOIFStream_Parse(ss)))
/* Exit the loop if the SOIF is invalid */
break;
/* Print the URL for each SOIF (will be “-” if there is no URL)*/
printf(“URL = %s\\n”, s->url);
/* Print the title if it exists. */
titleptr = SOIF_Findval(s, “title”);
printf(“Title = %s\\n”, titleptr ? titleptr : “(none)”)
/* Print the number of attributes in the SOIF*/
printf(“# of Attributes = %d\\n”, SOIF_GetAttributeCount(s));
/* release the memory used by the SOIF */
SOIF_Free(s);
}
/* Close the SOIFStream and exit */
SOIFStream_Finish(ss);
exit(0);
}
|