SCA

SDO XSD Helper API examples

test_dfAlloc.c
Basic allocation of a data factory containing build-in XML Schema ypes
test_ftypeDefine_invalidxml.c
Handling an invalid XML Schema
test_ftypeDefine.c
Defining types from a file containing an XML Schema; TODO: FIXME: must declare schema components in default xmlns namespace (use eg. xmlns:t="..." <xsd:simpleType name="t:..."> doesn't appear to work
test_stypeDefine.c
Defining types from a string containing an XML Schema

test_dfAlloc.c

#include "SDO.h"
#include "assert.h"


// Basic allocation of a data factory containing build-in
// XML Schema ypes
void test_dfAlloc() {
	SDOFACTORY df = dfAlloc("test_dfAlloc");
	assert(df);
	assert(findType(df, "http://www.w3.org/2001/XMLSchema", "string"));
}

test_ftypeDefine_invalidxml.c

#include "SDO.h"
#include "assert.h"


// Handling an invalid XML Schema
void test_ftypeDefine_invalidxml() {
	SDOFACTORY df = dfAlloc("test_ftypeDefine_invalidxml");

	// deliberately contains </schema> rather than </xsd:schema>
	FILE *f = fopen("test_ftypeDefine_invalidxml.tmp", "w");
	fputs(
		"<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n"
                "            targetNamespace=\"http://www.example.com\" \n"
                "            xmlns:t=\"http://www.example.com\">\n"
		"  <xsd:simpleType name=\"t:myType\">\n"
		"    <xsd:restriction base=\"xsd:string\"/>\n"
		"  </xsd:simpleType>\n"
		"</schema>\n", f);
	fclose(f);
	
	f = fopen("test_ftypeDefine_invalidxml.tmp", "r");
	assert(!ftypeDefine(df, f));
	fclose(f);
}

test_ftypeDefine.c

#include "SDO.h"
#include "assert.h"


// Defining types from a file containing an XML Schema;
// TODO: FIXME: must declare schema components in default xmlns
// namespace (use eg. xmlns:t="..." <xsd:simpleType name="t:...">
// doesn't appear to work
void test_ftypeDefine() {
	SDOFACTORY df = dfAlloc("test_ftypeDefine");

	SDOTYPE t0 = findType(df, "http://www.example.com", "myType");

	FILE *f = fopen("test_ftypeDefine.tmp", "w");
	fputs(
		"<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"
                "            targetNamespace=\"http://www.example.com\"\n"
                "            xmlns=\"http://www.example.com\">\n"
		"  <xsd:simpleType name=\"myType\">\n"
		"    <xsd:restriction base=\"xsd:string\"/>\n"
		"  </xsd:simpleType>\n"
		"</xsd:schema>\n", f);
	fclose(f);
	
	f = fopen("test_ftypeDefine.tmp", "r");
	SDOLIST l = ftypeDefine(df, f);
	fclose(f);

	fprintf(stderr, "getCountList=%d\n", getCountList(l));
	fflush(stderr);

	assert(getCountList(l) == 1);
	assert(!strcmp("myType", getTypeName(getTypeList(l, 0))));
	assert(findType(df, "http://www.example.com", "myType"));
}

test_stypeDefine.c

#include "SDO.h"
#include "assert.h"


// Defining types from a string containing an XML Schema
void test_stypeDefine() {
	SDOFACTORY df = dfAlloc("test_stypeDefine");

	SDOLIST l = stypeDefine(df,
		"<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"
                "            targetNamespace=\"http://www.example.com\"\n"
                "            xmlns=\"http://www.example.com\">\n"
		"  <xsd:simpleType name=\"myType\">\n"
		"    <xsd:restriction base=\"xsd:string\"/>\n"
		"  </xsd:simpleType>\n"
		"</xsd:schema>\n");

	assert(getCountList(l) == 1);
	assert(!strcmp("myType", getTypeName(getTypeList(l, 0))));
	assert(findType(df, "http://www.example.com", "myType"));
}