XML, SQL, and C
by Jim Kent

Listing One

<SHAPES>
  <POLYGON color="red" name="triangle">
    <DESCRIPTION>A 3-4-5 right triangle</DESCRIPTION>
    <PT-TWO-D x="0" y="0" />
    <PT-TWO-D x="3.0" y="0" />
    <PT-TWO-D x="0" y="4" />
  </POLYGON>
  <POLYGON color="black" name="square">
    <DESCRIPTION>Your basic black unit square</DESCRIPTION>
    <PT-TWO-D x="0" y="0" />
    <PT-TWO-D x="1" y="0" />
    <PT-TWO-D x="1" y="1" />
    <PT-TWO-D x="0" y="1" />
  </POLYGON>
</SHAPES>


Listing Two

#include "poly.h"
void shrinkShape(char *in, char *out)
{
struct polyShapes *shapes = polyShapesLoad(in);
struct polyPolygon *polygon;
FILE *f;

/* Loop through all points of all polygons, scaling by 50% */
for (polygon = shapes->polyPolygon; polygon != NULL; polygon = polygon->next)
    {
    struct polyPtTwoD *point;
    for (point = polygon->polyPoint; point != NULL; point = point->next)
        {
        point->x *= 0.5;
        point->y *= 0.5;
        }
    printf("Shrunk %s\n", polygon->description->text);
    }

/* Save result. */
f = fopen(out, "w");
polyShapesSave(shapes, 0, f);
fclose(f);
}


Listing Three

void processPolysInLimitedMemory(char *in)
{
struct xap *xap = xapOpen(in);
struct polyPolygon *polygon;

while ((polygon = polyPolygonNext(xap)) != NULL)
    {
    /* Do some processing to polygon here... */
    polyPolygonFree(&polygon);
    }
xapFree(&xap);
}





2


