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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
@node Example, Reference, Overview, top
@chapter Usage
The following C program parses an RDF file and prints out a list of
RDF descriptions, as well as the contents of the descriptions.
@example
#include <stdio.h>
#include <stdlib.h>
#include <gnurdf.h>
int
main(int argc, char **argv)
@{
RdfSchema *rdf;
RdfDescription *description;
RdfNamespace *myNamespace;
RdfElement *element;
char *about, *value;
char *filename;
if (argc < 2)
@{
fprintf(stderr, "Usage: %s <file>\n", argv[0]);
exit(1);
@}
filename = argv[1];
/* Read in the file. */
rdf = rdfReadFile(filename);
if (rdf == NULL)
@{
fprintf(stderr, "Unable to open %s.\n", filename);
exit(1);
@}
/* Locate the namespace. */
myNamespace = rdfGetNamespace(rdf, "urn:MyStuff:MyNamespace");
if (myNamespace == NULL)
@{
fprintf(stderr, "Namespace not found!\n");
exit(1);
@}
/* Loop through the descriptions. */
for (description = rdfFirstDescription(rdf);
description != NULL;
description = rdfNextDescription(description))
@{
about = rdfGetDescriptionAbout(rdf, description);
printf("\tAbout: %s\n", about);
free(about);
for (element = rdfFirstProperty(description);
element != NULL;
element = rdfNextProperty(element))
@{
value = rdfGetElementValue(element);
printf("\t\tName: %s\n",
rdfGetElementPropertyName(element));
printf("\t\tValue: %s\n", value);
printf("\t\tNamespace: %s\n\n",
rdfGetNamespaceURI(rdfGetElementNamespace(element)));
free(value);
@}
@}
/* Clean up. */
rdfDestroySchema(rdf);
return 0;
@}
@end example
|