Annotation of XML/schema.c, revision 1.1

1.1     ! veillard    1: /*
        !             2:  * schema.c : implementation of the XML Schema handling and
        !             3:  *            schema validity checking
        !             4:  *
        !             5:  * See Copyright for the status of this software.
        !             6:  *
        !             7:  * Daniel.Veillard@w3.org
        !             8:  */
        !             9: 
        !            10: 
        !            11: #ifdef WIN32
        !            12: #include "win32config.h"
        !            13: #else
        !            14: #include "config.h"
        !            15: #endif
        !            16: 
        !            17: #include <libxml/schema.h>
        !            18: #include <libxml/xmlmemory.h>
        !            19: #include <libxml/parser.h>
        !            20: 
        !            21: #define DEBUG 1 /* very verobose output */
        !            22: 
        !            23: /*
        !            24:  * The XML Schemas namespaces
        !            25:  */
        !            26: static const xmlChar *xmlSchemaNs = (const xmlChar *)
        !            27:          "http://www.w3.org/1999/XMLSchema";
        !            28: 
        !            29: #define IS_SCHEMA(node, type)                                          \
        !            30:    ((node != NULL) && (node->ns != NULL) &&                            \
        !            31:     (!xmlStrcmp(node->name, (const xmlChar *) type)) &&                        \
        !            32:     (!xmlStrcmp(node->ns->href, xmlSchemaNs)))
        !            33: 
        !            34:     /******
        !            35: static const xmlChar *xmlSchemaInstanceNs =  (const xmlChar *)
        !            36:          "http://www.w3.org/1999/XMLSchema-instance";
        !            37: 
        !            38: #define IS_SCHEMA_INSTANCE(node, type)                                 \
        !            39:    ((node != NULL) && (node->ns != NULL) &&                            \
        !            40:     (!xmlStrcmp(node->name, (const xmlChar *) type)) &&                        \
        !            41:     (!xmlStrcmp(node->ns->href, xmlSchemaInstanceNs)))
        !            42:      ******/
        !            43: 
        !            44: /*
        !            45:  * XML Schemas defines multiple type of types.
        !            46:  */
        !            47: typedef enum {
        !            48:     XML_SCHEMA_TYPE_BASIC = 1,
        !            49:     XML_SCHEMA_TYPE_SIMPLE,
        !            50:     XML_SCHEMA_TYPE_COMPLEX,
        !            51:     XML_SCHEMA_TYPE_UR,
        !            52:     XML_SCHEMA_TYPE_RESTRICTION,
        !            53:     XML_SCHEMA_TYPE_EXTENTION
        !            54: } xmlSchemaTypeType;
        !            55: 
        !            56: /**
        !            57:  * A facet definition
        !            58: typedef struct _xmlSchemaFacet xmlSchemaFacet;
        !            59: typedef xmlSchemaFacet *xmlSchemaFacetPtr;
        !            60: struct _xmlSchemaFacet {
        !            61: };
        !            62:  */
        !            63: 
        !            64: /**
        !            65:  * A content type definition
        !            66: typedef struct _xmlSchemaContentType xmlSchemaContentType;
        !            67: typedef xmlSchemaContentType *xmlSchemaContentTypePtr;
        !            68: struct _xmlSchemaContentType {
        !            69: };
        !            70:  */
        !            71: 
        !            72: 
        !            73: /**
        !            74:  * Simple type definition.
        !            75:  */
        !            76: typedef struct _xmlSchemaType xmlSchemaType;
        !            77: typedef xmlSchemaType *xmlSchemaTypePtr;
        !            78: struct _xmlSchemaType {
        !            79:     const xmlChar         *name;  /* The type name */
        !            80:     const xmlChar        *annot;  /* the annotation */
        !            81:     struct _xmlSchemaType *next;  /* Next in the list */
        !            82:     xmlSchemaTypeType      type;  /* The kind of schema type */
        !            83: };
        !            84: 
        !            85: /**
        !            86:  * Derived type definition.
        !            87:  */
        !            88: typedef struct _xmlSchemaDerivedType xmlSchemaDerivedType;
        !            89: typedef xmlSchemaDerivedType *xmlSchemaDerivedTypePtr;
        !            90: struct _xmlSchemaDerivedType {
        !            91:     const xmlChar *name;
        !            92:     const xmlChar *annot;             /* the annotation */
        !            93: };
        !            94: 
        !            95: /**
        !            96:  * A notation definition.
        !            97:  */
        !            98: typedef struct _xmlSchemaNotation xmlSchemaNotation;
        !            99: typedef xmlSchemaNotation *xmlSchemaNotationPtr;
        !           100: struct _xmlSchemaNotation {
        !           101:     const xmlChar *name;
        !           102:     const xmlChar *annot;             /* the annotation */
        !           103:     struct _xmlSchemaNotation *next;  /* Next in the list */
        !           104:     const xmlChar *identifier;
        !           105: };
        !           106: 
        !           107: /**
        !           108:  * An attribute definition.
        !           109:  */
        !           110: typedef struct _xmlSchemaAttribute xmlSchemaAttribute;
        !           111: typedef xmlSchemaAttribute *xmlSchemaAttributePtr;
        !           112: struct _xmlSchemaAttribute {
        !           113:     const xmlChar *name;
        !           114:     const xmlChar *annot;             /* the annotation */
        !           115:     struct _xmlSchemaAttribute *next; /* Next in the list */
        !           116:     xmlSchemaTypePtr base;
        !           117:     int occurs;
        !           118:     const xmlChar *defValue;
        !           119: };
        !           120: 
        !           121: /**
        !           122:  * An element definition.
        !           123:  */
        !           124: typedef struct _xmlSchemaElement xmlSchemaElement;
        !           125: typedef xmlSchemaElement *xmlSchemaElementPtr;
        !           126: struct _xmlSchemaElement {
        !           127:     const xmlChar *name;
        !           128:     const xmlChar *annot;             /* the annotation */
        !           129:     struct _xmlSchemaElement *next;   /* Next in the list */
        !           130: };
        !           131: 
        !           132: /**
        !           133:  * A Schemas definition
        !           134:  */
        !           135: struct _xmlSchema {
        !           136:     const xmlChar     *name;            /* schema name */
        !           137:     const xmlChar *annot;             /* the annotation */
        !           138:     const xmlChar     *targetNameSpace; /* the target namespace */
        !           139: 
        !           140:     xmlSchemaTypePtr   typeDefs;        /* the list of types definitions */
        !           141: 
        !           142:     xmlSchemaAttributePtr   attrDecl;   /* attributes declarations */
        !           143:     xmlSchemaElementPtr     elemDecl;   /* elements declarations */
        !           144: };
        !           145: 
        !           146: /************************************************************************
        !           147:  *                                                                     *
        !           148:  *                     Allocation functions                            *
        !           149:  *                                                                     *
        !           150:  ************************************************************************/
        !           151: 
        !           152: /**
        !           153:  * xmlSchemaNewSchema:
        !           154:  * @ctxt:  a schema validation context (optional)
        !           155:  *
        !           156:  * Allocate a new Schema structure.
        !           157:  *
        !           158:  * Returns the newly allocated structure or NULL in case or error
        !           159:  */
        !           160: xmlSchemaPtr
        !           161: xmlSchemaNewSchema(xmlSchemaValidCtxtPtr ctxt) {
        !           162:     xmlSchemaPtr ret;
        !           163: 
        !           164:     ret = (xmlSchemaPtr) xmlMalloc(sizeof(xmlSchema));
        !           165:     if (ret == NULL) {
        !           166:        if ((ctxt != NULL) && (ctxt->error != NULL))
        !           167:            ctxt->error(ctxt->userData, "Out of memory\n");
        !           168:        return(NULL);
        !           169:     }
        !           170:     memset(ret, 0, sizeof(xmlSchema));
        !           171: 
        !           172:     return(ret);
        !           173: }
        !           174: 
        !           175: /**
        !           176:  * xmlSchemaFreeAttribute:
        !           177:  * @schema:  a schema attribute structure
        !           178:  *
        !           179:  * Deallocate a Schema Attribute structure.
        !           180:  */
        !           181: void
        !           182: xmlSchemaFreeAttribute(xmlSchemaAttributePtr attr) {
        !           183:     if (attr == NULL)
        !           184:        return;
        !           185:     if (attr->name != NULL)
        !           186:        xmlFree((xmlChar *) attr->name);
        !           187:     memset(attr, -1, sizeof(xmlSchemaAttribute));
        !           188:     xmlFree(attr);
        !           189: }
        !           190: 
        !           191: /**
        !           192:  * xmlSchemaFreeAttributeList:
        !           193:  * @cur:  a schema attribute list structure
        !           194:  *
        !           195:  * Deallocate a Schema Attribute structure.
        !           196:  */
        !           197: void
        !           198: xmlSchemaFreeAttributeList(xmlSchemaAttributePtr cur) {
        !           199:     xmlSchemaAttributePtr next;
        !           200: 
        !           201:     if (cur == NULL)
        !           202:        return;
        !           203:     while (cur != NULL) {
        !           204:         next = cur->next;
        !           205:         xmlSchemaFreeAttribute(cur);
        !           206:        cur = next;
        !           207:     }
        !           208: }
        !           209: 
        !           210: /**
        !           211:  * xmlSchemaFreeElement:
        !           212:  * @schema:  a schema element structure
        !           213:  *
        !           214:  * Deallocate a Schema Element structure.
        !           215:  */
        !           216: void
        !           217: xmlSchemaFreeElement(xmlSchemaElementPtr elem) {
        !           218:     if (elem == NULL)
        !           219:        return;
        !           220:     if (elem->name != NULL)
        !           221:        xmlFree((xmlChar *) elem->name);
        !           222:     memset(elem, -1, sizeof(xmlSchemaElement));
        !           223:     xmlFree(elem);
        !           224: }
        !           225: 
        !           226: /**
        !           227:  * xmlSchemaFreeElementList:
        !           228:  * @cur:  a schema element list structure
        !           229:  *
        !           230:  * Deallocate a Schema Element structure.
        !           231:  */
        !           232: void
        !           233: xmlSchemaFreeElementList(xmlSchemaElementPtr cur) {
        !           234:     xmlSchemaElementPtr next;
        !           235: 
        !           236:     if (cur == NULL)
        !           237:        return;
        !           238:     while (cur != NULL) {
        !           239:         next = cur->next;
        !           240:         xmlSchemaFreeElement(cur);
        !           241:        cur = next;
        !           242:     }
        !           243: }
        !           244: 
        !           245: /**
        !           246:  * xmlSchemaFree:
        !           247:  * @schema:  a schema structure
        !           248:  *
        !           249:  * Deallocate a Schema structure.
        !           250:  */
        !           251: void
        !           252: xmlSchemaFree(xmlSchemaPtr schema) {
        !           253:     if (schema == NULL)
        !           254:        return;
        !           255:     if (schema->name != NULL)
        !           256:        xmlFree((xmlChar *) schema->name);
        !           257:     if (schema->attrDecl != NULL)
        !           258:        xmlSchemaFreeAttributeList(schema->attrDecl);
        !           259:     if (schema->elemDecl != NULL)
        !           260:        xmlSchemaFreeElementList(schema->elemDecl);
        !           261:     memset(schema, -1, sizeof(xmlSchema));
        !           262:     xmlFree(schema);
        !           263: }
        !           264: 
        !           265: 
        !           266: /**
        !           267:  * xmlSchemaAddAttribute:
        !           268:  * @ctxt:  a schema validation context
        !           269:  * @schema:  the schema being built
        !           270:  * @name:  the item name
        !           271:  *
        !           272:  * Add an XML schema Attrribute declaration
        !           273:  * *WARNING* this interface is highly subject to change
        !           274:  *
        !           275:  * Returns the new struture or NULL in case of error
        !           276:  */
        !           277: xmlSchemaAttributePtr
        !           278: xmlSchemaAddAttribute(xmlSchemaValidCtxtPtr ctxt, xmlSchemaPtr schema,
        !           279:                        const xmlChar *name) {
        !           280:     xmlSchemaAttributePtr ret = NULL;
        !           281: 
        !           282: #ifdef DEBUG
        !           283:     fprintf(stderr, "xmlSchemaAddAttribute()\n");
        !           284: #endif
        !           285: 
        !           286:     if ((ctxt ==  NULL) || (schema == NULL) || (name == NULL))
        !           287:        return(NULL);
        !           288: 
        !           289:     ret = (xmlSchemaAttributePtr) xmlMalloc(sizeof(xmlSchemaAttribute));
        !           290:     if (ret == NULL) {
        !           291:        if ((ctxt != NULL) && (ctxt->error != NULL))
        !           292:            ctxt->error(ctxt->userData, "Out of memory\n");
        !           293:        return(NULL);
        !           294:     }
        !           295:     memset(ret, 0, sizeof(xmlSchemaAttribute));
        !           296:     ret->name = name;
        !           297:     ret->next = schema->attrDecl;
        !           298:     schema->attrDecl = ret;
        !           299: 
        !           300: #ifdef DEBUG
        !           301:     fprintf(stderr, "xmlSchemaAddAttribute() finished\n");
        !           302: #endif
        !           303: 
        !           304:     return(ret);
        !           305: }
        !           306: 
        !           307: /**
        !           308:  * xmlSchemaAddElement:
        !           309:  * @ctxt:  a schema validation context
        !           310:  * @schema:  the schema being built
        !           311:  * @name:  the item name
        !           312:  *
        !           313:  * Add an XML schema Element declaration
        !           314:  * *WARNING* this interface is highly subject to change
        !           315:  *
        !           316:  * Returns the new struture or NULL in case of error
        !           317:  */
        !           318: xmlSchemaElementPtr
        !           319: xmlSchemaAddElement(xmlSchemaValidCtxtPtr ctxt, xmlSchemaPtr schema,
        !           320:                        const xmlChar *name) {
        !           321:     xmlSchemaElementPtr ret = NULL;
        !           322: 
        !           323: #ifdef DEBUG
        !           324:     fprintf(stderr, "xmlSchemaAddElement()\n");
        !           325: #endif
        !           326: 
        !           327:     if ((ctxt ==  NULL) || (schema == NULL) || (name == NULL))
        !           328:        return(NULL);
        !           329:     ret = (xmlSchemaElementPtr) xmlMalloc(sizeof(xmlSchemaElement));
        !           330:     if (ret == NULL) {
        !           331:        if ((ctxt != NULL) && (ctxt->error != NULL))
        !           332:            ctxt->error(ctxt->userData, "Out of memory\n");
        !           333:        return(NULL);
        !           334:     }
        !           335:     memset(ret, 0, sizeof(xmlSchemaElement));
        !           336:     ret->name = name;
        !           337:     ret->next = schema->elemDecl;
        !           338:     schema->elemDecl = ret;
        !           339: 
        !           340: 
        !           341: #ifdef DEBUG
        !           342:     fprintf(stderr, "xmlSchemaAddElement() finished\n");
        !           343: #endif
        !           344: 
        !           345:     return(ret);
        !           346: }
        !           347: 
        !           348: /**
        !           349:  * xmlSchemaAddSimpleType:
        !           350:  * @ctxt:  a schema validation context
        !           351:  * @schema:  the schema being built
        !           352:  * @name:  the item name
        !           353:  *
        !           354:  * Add an XML schema Simple Type definition
        !           355:  * *WARNING* this interface is highly subject to change
        !           356:  *
        !           357:  * Returns the new struture or NULL in case of error
        !           358:  */
        !           359: xmlSchemaTypePtr
        !           360: xmlSchemaAddSimpleType(xmlSchemaValidCtxtPtr ctxt, xmlSchemaPtr schema,
        !           361:                        const xmlChar *name) {
        !           362:     xmlSchemaTypePtr ret = NULL;
        !           363: 
        !           364: #ifdef DEBUG
        !           365:     fprintf(stderr, "xmlSchemaAddSimpleType()\n");
        !           366: #endif
        !           367: 
        !           368: 
        !           369:     if ((ctxt ==  NULL) || (schema == NULL) || (name == NULL))
        !           370:        return(NULL);
        !           371:     ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType));
        !           372:     if (ret == NULL) {
        !           373:        if ((ctxt != NULL) && (ctxt->error != NULL))
        !           374:            ctxt->error(ctxt->userData, "Out of memory\n");
        !           375:        return(NULL);
        !           376:     }
        !           377:     memset(ret, 0, sizeof(xmlSchemaType));
        !           378:     ret->name = name;
        !           379:     ret->type = XML_SCHEMA_TYPE_SIMPLE;
        !           380:     ret->next = schema->typeDefs;
        !           381:     schema->typeDefs = ret;
        !           382: 
        !           383: #ifdef DEBUG
        !           384:     fprintf(stderr, "xmlSchemaAddSimpleType() finished\n");
        !           385: #endif
        !           386: 
        !           387:     return(ret);
        !           388: }
        !           389: 
        !           390: /**
        !           391:  * xmlSchemaAddComplexType:
        !           392:  * @ctxt:  a schema validation context
        !           393:  * @schema:  the schema being built
        !           394:  * @name:  the item name
        !           395:  *
        !           396:  * Add an XML schema Complex Type definition
        !           397:  * *WARNING* this interface is highly subject to change
        !           398:  *
        !           399:  * Returns the new struture or NULL in case of error
        !           400:  */
        !           401: xmlSchemaTypePtr
        !           402: xmlSchemaAddComplexType(xmlSchemaValidCtxtPtr ctxt, xmlSchemaPtr schema,
        !           403:                        const xmlChar *name) {
        !           404:     xmlSchemaTypePtr ret = NULL;
        !           405: 
        !           406: #ifdef DEBUG
        !           407:     fprintf(stderr, "xmlSchemaAddComplexType()\n");
        !           408: #endif
        !           409: 
        !           410:     if ((ctxt ==  NULL) || (schema == NULL) || (name == NULL))
        !           411:        return(NULL);
        !           412:     ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType));
        !           413:     if (ret == NULL) {
        !           414:        if ((ctxt != NULL) && (ctxt->error != NULL))
        !           415:            ctxt->error(ctxt->userData, "Out of memory\n");
        !           416:        return(NULL);
        !           417:     }
        !           418:     memset(ret, 0, sizeof(xmlSchemaType));
        !           419:     ret->name = name;
        !           420:     ret->type = XML_SCHEMA_TYPE_COMPLEX;
        !           421:     ret->next = schema->typeDefs;
        !           422:     schema->typeDefs = ret;
        !           423: 
        !           424: #ifdef DEBUG
        !           425:     fprintf(stderr, "xmlSchemaAddComplexType() finished\n");
        !           426: #endif
        !           427: 
        !           428:     return(ret);
        !           429: }
        !           430: 
        !           431: /************************************************************************
        !           432:  *                                                                     *
        !           433:  *             Shema extraction from an Infoset                        *
        !           434:  *                                                                     *
        !           435:  ************************************************************************/
        !           436: /**
        !           437:  * xmlSchemaParseAnnotation:
        !           438:  * @ctxt:  a schema validation context
        !           439:  * @schema:  the schema being built
        !           440:  * @node:  a subtree containing XML Schema informations
        !           441:  *
        !           442:  * parse a XML schema Attrribute declaration
        !           443:  * *WARNING* this interface is highly subject to change
        !           444:  *
        !           445:  * Returns -1 in case of error, 0 if the declaration is inproper and
        !           446:  *         1 in case of success.
        !           447:  */
        !           448: int
        !           449: xmlSchemaParseAnnotation(xmlSchemaValidCtxtPtr ctxt, xmlSchemaPtr schema,
        !           450:                        xmlNodePtr node) {
        !           451:     int ret = 0;
        !           452: 
        !           453: #ifdef DEBUG
        !           454:     fprintf(stderr, "xmlSchemaParseAnnotation()\n");
        !           455: #endif
        !           456: 
        !           457: 
        !           458:     if ((ctxt ==  NULL) || (schema == NULL) || (node == NULL))
        !           459:        return(-1);
        !           460: 
        !           461: #ifdef DEBUG
        !           462:     fprintf(stderr, "xmlSchemaParseAnnotation() finished\n");
        !           463: #endif
        !           464: 
        !           465:     return(ret);
        !           466: }
        !           467: 
        !           468: 
        !           469: /**
        !           470:  * xmlSchemaParseAttribute:
        !           471:  * @ctxt:  a schema validation context
        !           472:  * @schema:  the schema being built
        !           473:  * @node:  a subtree containing XML Schema informations
        !           474:  *
        !           475:  * parse a XML schema Attrribute declaration
        !           476:  * *WARNING* this interface is highly subject to change
        !           477:  *
        !           478:  * Returns -1 in case of error, 0 if the declaration is inproper and
        !           479:  *         1 in case of success.
        !           480:  */
        !           481: xmlSchemaAttributePtr
        !           482: xmlSchemaParseAttribute(xmlSchemaValidCtxtPtr ctxt, xmlSchemaPtr schema,
        !           483:                        xmlNodePtr node) {
        !           484:     xmlChar *name;
        !           485:     xmlSchemaAttributePtr ret;
        !           486: 
        !           487: #ifdef DEBUG
        !           488:     fprintf(stderr, "xmlSchemaParseAttribute()\n");
        !           489: #endif
        !           490: 
        !           491: 
        !           492:     if ((ctxt ==  NULL) || (schema == NULL) || (node == NULL))
        !           493:        return(NULL);
        !           494:     name = xmlGetProp(node, (const xmlChar *) "name");
        !           495:     if (name == NULL) {
        !           496:        if ((ctxt != NULL) && (ctxt->error != NULL))
        !           497:            ctxt->error(ctxt->userData, "Attribute has no name\n");
        !           498:        return(NULL);
        !           499:     }
        !           500:     ret = xmlSchemaAddAttribute(ctxt, schema, name);
        !           501:     if (ret == NULL) {
        !           502:        xmlFree(name);
        !           503:        return(NULL);
        !           504:     }
        !           505: 
        !           506: #ifdef DEBUG
        !           507:     fprintf(stderr, "xmlSchemaParseAttribute() finished\n");
        !           508: #endif
        !           509: 
        !           510:     return(ret);
        !           511: }
        !           512: 
        !           513: /**
        !           514:  * xmlSchemaParseElement:
        !           515:  * @ctxt:  a schema validation context
        !           516:  * @schema:  the schema being built
        !           517:  * @node:  a subtree containing XML Schema informations
        !           518:  *
        !           519:  * parse a XML schema Element declaration
        !           520:  * *WARNING* this interface is highly subject to change
        !           521:  *
        !           522:  * Returns -1 in case of error, 0 if the declaration is inproper and
        !           523:  *         1 in case of success.
        !           524:  */
        !           525: xmlSchemaElementPtr
        !           526: xmlSchemaParseElement(xmlSchemaValidCtxtPtr ctxt, xmlSchemaPtr schema,
        !           527:                        xmlNodePtr node) {
        !           528:     xmlChar *name;
        !           529:     xmlSchemaElementPtr ret;
        !           530: 
        !           531: #ifdef DEBUG
        !           532:     fprintf(stderr, "xmlSchemaParseElement()\n");
        !           533: #endif
        !           534: 
        !           535:     if ((ctxt ==  NULL) || (schema == NULL) || (node == NULL))
        !           536:        return(NULL);
        !           537:     name = xmlGetProp(node, (const xmlChar *) "name");
        !           538:     if (name == NULL) {
        !           539:        if ((ctxt != NULL) && (ctxt->error != NULL))
        !           540:            ctxt->error(ctxt->userData, "Element has no name\n");
        !           541:        return(NULL);
        !           542:     }
        !           543:     ret = xmlSchemaAddElement(ctxt, schema, name);
        !           544:     if (ret == NULL) {
        !           545:        xmlFree(name);
        !           546:        return(NULL);
        !           547:     }
        !           548: 
        !           549: 
        !           550: #ifdef DEBUG
        !           551:     fprintf(stderr, "xmlSchemaParseElement() finished\n");
        !           552: #endif
        !           553: 
        !           554:     return(ret);
        !           555: }
        !           556: 
        !           557: /**
        !           558:  * xmlSchemaParseSimpleType:
        !           559:  * @ctxt:  a schema validation context
        !           560:  * @schema:  the schema being built
        !           561:  * @node:  a subtree containing XML Schema informations
        !           562:  *
        !           563:  * parse a XML schema Simple Type definition
        !           564:  * *WARNING* this interface is highly subject to change
        !           565:  *
        !           566:  * Returns -1 in case of error, 0 if the declaration is inproper and
        !           567:  *         1 in case of success.
        !           568:  */
        !           569: int
        !           570: xmlSchemaParseSimpleType(xmlSchemaValidCtxtPtr ctxt, xmlSchemaPtr schema,
        !           571:                        xmlNodePtr node) {
        !           572:     int ret = 0;
        !           573: 
        !           574: #ifdef DEBUG
        !           575:     fprintf(stderr, "xmlSchemaParseSimpleType()\n");
        !           576: #endif
        !           577: 
        !           578: 
        !           579:     if ((ctxt ==  NULL) || (schema == NULL) || (node == NULL))
        !           580:        return(-1);
        !           581: 
        !           582: #ifdef DEBUG
        !           583:     fprintf(stderr, "xmlSchemaParseSimpleType() finished\n");
        !           584: #endif
        !           585: 
        !           586:     return(ret);
        !           587: }
        !           588: 
        !           589: /**
        !           590:  * xmlSchemaParseComplexType:
        !           591:  * @ctxt:  a schema validation context
        !           592:  * @schema:  the schema being built
        !           593:  * @node:  a subtree containing XML Schema informations
        !           594:  *
        !           595:  * parse a XML schema Complex Type definition
        !           596:  * *WARNING* this interface is highly subject to change
        !           597:  *
        !           598:  * Returns -1 in case of error, 0 if the declaration is inproper and
        !           599:  *         1 in case of success.
        !           600:  */
        !           601: int
        !           602: xmlSchemaParseComplexType(xmlSchemaValidCtxtPtr ctxt, xmlSchemaPtr schema,
        !           603:                        xmlNodePtr node) {
        !           604:     int ret = 0;
        !           605: 
        !           606: #ifdef DEBUG
        !           607:     fprintf(stderr, "xmlSchemaParseComplexType()\n");
        !           608: #endif
        !           609: 
        !           610:     if ((ctxt ==  NULL) || (schema == NULL) || (node == NULL))
        !           611:        return(-1);
        !           612: 
        !           613: #ifdef DEBUG
        !           614:     fprintf(stderr, "xmlSchemaParseComplexType() finished\n");
        !           615: #endif
        !           616: 
        !           617:     return(ret);
        !           618: }
        !           619: 
        !           620: 
        !           621: /**
        !           622:  * xmlSchemaParse:
        !           623:  * @ctxt:  a schema validation context
        !           624:  * @node:  a subtree containing XML Schema informations
        !           625:  *
        !           626:  * parse a XML schema definition from a node set
        !           627:  * *WARNING* this interface is highly subject to change
        !           628:  *
        !           629:  * Returns the internal XML Schema structure built from the resource or
        !           630:  *         NULL in case of error
        !           631:  */
        !           632: xmlSchemaPtr
        !           633: xmlSchemaParse(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr node) {
        !           634:     xmlSchemaPtr schema = NULL;
        !           635:     xmlNodePtr child;
        !           636: 
        !           637: #ifdef DEBUG
        !           638:     fprintf(stderr, "xmlSchemaParse()\n");
        !           639: #endif
        !           640: 
        !           641:     if ((ctxt ==  NULL) || (node == NULL))
        !           642:        return(NULL);
        !           643: 
        !           644:     if (IS_SCHEMA(node, "schema")) {
        !           645:        schema = xmlSchemaNewSchema(ctxt);
        !           646:        child = node->children;
        !           647:        while (child != NULL) {
        !           648:            if (IS_SCHEMA(child, "element"))
        !           649:                xmlSchemaParseElement(ctxt, schema, child);
        !           650:            else if (IS_SCHEMA(child, "attribute"))
        !           651:                xmlSchemaParseAttribute(ctxt, schema, child);
        !           652:            else if (IS_SCHEMA(child, "annotation"))
        !           653:                xmlSchemaParseAnnotation(ctxt, schema, child);
        !           654:            else if (IS_SCHEMA(child, "complexType"))
        !           655:                xmlSchemaParseComplexType(ctxt, schema, child);
        !           656:            else if (IS_SCHEMA(child, "simpleType"))
        !           657:                xmlSchemaParseSimpleType(ctxt, schema, child);
        !           658: 
        !           659:            child = child->next;
        !           660:        }
        !           661:     }
        !           662: 
        !           663: #ifdef DEBUG
        !           664:     if (schema == NULL)
        !           665:        fprintf(stderr, "xmlSchemaParse() failed\n");
        !           666:     else
        !           667:        fprintf(stderr, "xmlSchemaParse() finished\n");
        !           668: #endif
        !           669: 
        !           670:     return(schema);
        !           671: }
        !           672: 
        !           673: /************************************************************************
        !           674:  *                                                                     *
        !           675:  *                     Reading/Writing Schemas                         *
        !           676:  *                                                                     *
        !           677:  ************************************************************************/
        !           678: 
        !           679: /**
        !           680:  * xmlSchemaLoad:
        !           681:  * @ctxt:  a schema validation context
        !           682:  * @URL:  the location of the schema
        !           683:  *
        !           684:  * Load, XML parse a schema definition resource and build an internal
        !           685:  * XML Shema struture which can be used to validate instances.
        !           686:  * *WARNING* this interface is highly subject to change
        !           687:  *
        !           688:  * Returns the internal XML Schema structure built from the resource or
        !           689:  *         NULL in case of error
        !           690:  */
        !           691: xmlSchemaPtr
        !           692: xmlSchemaLoad(xmlSchemaValidCtxtPtr ctxt, const char *URL) {
        !           693:     xmlSchemaPtr ret;
        !           694:     xmlDocPtr doc;
        !           695:     xmlNodePtr root;
        !           696: 
        !           697:     if ((URL == NULL) || (ctxt == NULL))
        !           698:        return(NULL);
        !           699:     
        !           700: #ifdef DEBUG
        !           701:     fprintf(stderr, "xmlSchemaLoad(%s)\n", URL);
        !           702: #endif
        !           703: 
        !           704:     /*
        !           705:      * First step is to parse the input document into an DOM/Infoset
        !           706:      * TODO: do error redirections
        !           707:      */
        !           708:     doc = xmlParseFile(URL);
        !           709:     if (doc == NULL) {
        !           710:        if (ctxt->error != NULL)
        !           711:            ctxt->error(ctxt->userData, "xmlSchemaLoad: %s is not WellFormed\n",
        !           712:                        URL);
        !           713:        return(NULL);
        !           714:     }
        !           715: 
        !           716:     /*
        !           717:      * Then extract the root and Schema parse it
        !           718:      */
        !           719:     root = xmlDocGetRootElement(doc);
        !           720:     if (root == NULL) {
        !           721:        if (ctxt->error != NULL)
        !           722:            ctxt->error(ctxt->userData, "xmlSchemaLoad: %s is empty\n",
        !           723:                        URL);
        !           724:        return(NULL);
        !           725:     }
        !           726:     ret = xmlSchemaParse(ctxt, root);
        !           727: 
        !           728:     /*
        !           729:      * Cleanup
        !           730:      */
        !           731:     xmlFreeDoc(doc);
        !           732: 
        !           733: #ifdef DEBUG
        !           734:     fprintf(stderr, "xmlSchemaLoad(%s) finished\n", URL);
        !           735: #endif
        !           736: 
        !           737:     return(ret);
        !           738: }
        !           739: 
        !           740: /**
        !           741:  * xmlSchemaValidate:
        !           742:  * @ctxt:  a schema validation context
        !           743:  * @instance:  the subtree (infoset) instance to validate.
        !           744:  * @schema:  the internal XML Schema structure
        !           745:  *
        !           746:  * Attempts to schema validate an instance against an XML Schema
        !           747:  *
        !           748:  * Returns -1 in case of general error, 0 if the instance does not validate
        !           749:  *         and 1 if it validates
        !           750:  */
        !           751: int    
        !           752: xmlSchemaValidate(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr instance,
        !           753:                   xmlSchemaPtr schema) {
        !           754:     int ret = 0;
        !           755: 
        !           756: #ifdef DEBUG
        !           757:     fprintf(stderr, "xmlSchemaValidate()\n");
        !           758: #endif
        !           759: 
        !           760: #ifdef DEBUG
        !           761:     fprintf(stderr, "xmlSchemaValidate() finished : %d\n", ret);
        !           762: #endif
        !           763: 
        !           764:     return(ret);
        !           765: }

Webmaster