Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * schemas.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 <veillard@redhat.com> |
| 8 | */ |
| 9 | |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 10 | /* |
| 11 | * TODO: |
| 12 | * - when types are redefined in includes, check that all |
| 13 | * types in the redef list are equal |
| 14 | * -> need a type equality operation. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15 | * - if we don't intend to use the schema for schemas, we |
| 16 | * need to validate all schema attributes (ref, type, name) |
| 17 | * against their types. |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 18 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19 | #define IN_LIBXML |
| 20 | #include "libxml.h" |
| 21 | |
| 22 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 23 | |
| 24 | #include <string.h> |
| 25 | #include <libxml/xmlmemory.h> |
| 26 | #include <libxml/parser.h> |
| 27 | #include <libxml/parserInternals.h> |
| 28 | #include <libxml/hash.h> |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 29 | #include <libxml/uri.h> |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 30 | |
| 31 | #include <libxml/xmlschemas.h> |
| 32 | #include <libxml/schemasInternals.h> |
| 33 | #include <libxml/xmlschemastypes.h> |
| 34 | #include <libxml/xmlautomata.h> |
| 35 | #include <libxml/xmlregexp.h> |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 36 | #include <libxml/dict.h> |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 37 | |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 38 | /* #define DEBUG 1 */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 39 | |
Daniel Veillard | 82bbbd4 | 2003-05-11 20:16:09 +0000 | [diff] [blame] | 40 | /* #define DEBUG_CONTENT 1 */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 41 | |
Daniel Veillard | 82bbbd4 | 2003-05-11 20:16:09 +0000 | [diff] [blame] | 42 | /* #define DEBUG_TYPE 1 */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 43 | |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 44 | /* #define DEBUG_CONTENT_REGEXP 1 */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 45 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 46 | /* #define DEBUG_AUTOMATA 1 */ |
| 47 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 48 | /* #define DEBUG_ATTR_VALIDATION 1 */ |
| 49 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 50 | /* #define DEBUG_UNION_VALIDATION 1 */ |
| 51 | |
| 52 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 53 | #define UNBOUNDED (1 << 30) |
| 54 | #define TODO \ |
| 55 | xmlGenericError(xmlGenericErrorContext, \ |
| 56 | "Unimplemented block at %s:%d\n", \ |
| 57 | __FILE__, __LINE__); |
| 58 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 59 | #define XML_SCHEMAS_NO_NAMESPACE (const xmlChar *) "##" |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 60 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 61 | /* |
| 62 | * The XML Schemas namespaces |
| 63 | */ |
| 64 | static const xmlChar *xmlSchemaNs = (const xmlChar *) |
| 65 | "http://www.w3.org/2001/XMLSchema"; |
| 66 | |
| 67 | static const xmlChar *xmlSchemaInstanceNs = (const xmlChar *) |
| 68 | "http://www.w3.org/2001/XMLSchema-instance"; |
| 69 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 70 | static const xmlChar *xmlSchemaElemDesElemDecl = (const xmlChar *) |
| 71 | "Element decl."; |
| 72 | static const xmlChar *xmlSchemaElemDesElemRef = (const xmlChar *) |
| 73 | "Element ref."; |
| 74 | static const xmlChar *xmlSchemaElemDesAttrDecl = (const xmlChar *) |
| 75 | "Attribute decl."; |
| 76 | static const xmlChar *xmlSchemaElemDesAttrRef = (const xmlChar *) |
| 77 | "Attribute ref."; |
| 78 | static const xmlChar *xmlSchemaElemDesST = (const xmlChar *) |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 79 | "simple type"; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 80 | static const xmlChar *xmlSchemaElemDesCT = (const xmlChar *) |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 81 | "complex type"; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 82 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 83 | #define IS_SCHEMA(node, type) \ |
| 84 | ((node != NULL) && (node->ns != NULL) && \ |
| 85 | (xmlStrEqual(node->name, (const xmlChar *) type)) && \ |
| 86 | (xmlStrEqual(node->ns->href, xmlSchemaNs))) |
| 87 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 88 | #define FREE_AND_NULL(str) \ |
| 89 | if (str != NULL) { \ |
| 90 | xmlFree(str); \ |
| 91 | str = NULL; \ |
| 92 | } |
| 93 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 94 | #define IS_ANYTYPE(item) \ |
| 95 | ((item->type == XML_SCHEMA_TYPE_BASIC) && \ |
| 96 | (item->builtInType == XML_SCHEMAS_ANYTYPE)) |
| 97 | |
| 98 | #define IS_COMPLEX_TYPE(item) \ |
| 99 | ((item->type == XML_SCHEMA_TYPE_COMPLEX) || \ |
| 100 | (item->builtInType == XML_SCHEMAS_ANYTYPE)) |
| 101 | |
| 102 | #define IS_SIMPLE_TYPE(item) \ |
| 103 | ((item->type == XML_SCHEMA_TYPE_SIMPLE) || \ |
| 104 | ((item->type == XML_SCHEMA_TYPE_BASIC) && \ |
| 105 | (item->builtInType != XML_SCHEMAS_ANYTYPE))) |
| 106 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 107 | #define XML_SCHEMAS_VAL_WTSP_PRESERVE 0 |
| 108 | #define XML_SCHEMAS_VAL_WTSP_REPLACE 1 |
| 109 | #define XML_SCHEMAS_VAL_WTSP_COLLAPSE 2 |
| 110 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 111 | #define XML_SCHEMAS_PARSE_ERROR 1 |
| 112 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 113 | #define SCHEMAS_PARSE_OPTIONS XML_PARSE_NOENT |
| 114 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 115 | |
| 116 | /* |
| 117 | * XML_SCHEMA_VAL_XSI_ASSEMBLE_TNS_COMPOSE |
| 118 | * allow to assemble schemata with |
| 119 | * the same target namespace from |
| 120 | * different sources; otherwise, the first |
| 121 | * encountered schema with a specific target |
| 122 | * namespace will be used only * |
| 123 | |
| 124 | * |
| 125 | * XML_SCHEMA_VAL_LOCATE_BY_NSNAME = 1<<2 |
| 126 | * locate schemata to be imported |
| 127 | * using the namespace name; otherwise |
| 128 | * the location URI will be used */ |
| 129 | |
| 130 | /* |
| 131 | * xmlSchemaParserOption: |
| 132 | * |
| 133 | * This is the set of XML Schema parser options. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 134 | * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 135 | typedef enum { |
| 136 | XML_SCHEMA_PAR_LOCATE_BY_NSNAME = 1<<0 |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 137 | * locate schemata to be imported |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 138 | * using the namespace name; otherwise |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 139 | * the location URI will be used * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 140 | } xmlSchemaParserOption; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 141 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 142 | |
| 143 | /* |
| 144 | XMLPUBFUN int XMLCALL |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 145 | xmlSchemaParserCtxtSetOptions(xmlSchemaParserCtxtPtr ctxt, |
| 146 | int options); |
| 147 | XMLPUBFUN int XMLCALL |
| 148 | xmlSchemaParserCtxtGetOptions(xmlSchemaParserCtxtPtr ctxt); |
| 149 | |
| 150 | */ |
| 151 | |
| 152 | typedef struct _xmlSchemaAssemble xmlSchemaAssemble; |
| 153 | typedef xmlSchemaAssemble *xmlSchemaAssemblePtr; |
| 154 | struct _xmlSchemaAssemble { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 155 | void **items; /* used for dynamic addition of schemata */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 156 | int nbItems; /* used for dynamic addition of schemata */ |
| 157 | int sizeItems; /* used for dynamic addition of schemata */ |
| 158 | }; |
| 159 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 160 | struct _xmlSchemaParserCtxt { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 161 | void *userData; /* user specific data block */ |
| 162 | xmlSchemaValidityErrorFunc error; /* the callback in case of errors */ |
| 163 | xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */ |
Daniel Veillard | e19fc23 | 2002-04-22 16:01:24 +0000 | [diff] [blame] | 164 | xmlSchemaValidError err; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 165 | int nberrors; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 166 | xmlStructuredErrorFunc serror; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 167 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 168 | xmlSchemaPtr topschema; /* The main schema */ |
| 169 | xmlHashTablePtr namespaces; /* Hash table of namespaces to schemas */ |
| 170 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 171 | xmlSchemaPtr schema; /* The schema in use */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 172 | const xmlChar *container; /* the current element, group, ... */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 173 | int counter; |
| 174 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 175 | const xmlChar *URL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 176 | xmlDocPtr doc; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 177 | int preserve; /* Whether the doc should be freed */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 178 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 179 | const char *buffer; |
| 180 | int size; |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 181 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 182 | /* |
| 183 | * Used to build complex element content models |
| 184 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 185 | xmlAutomataPtr am; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 186 | xmlAutomataStatePtr start; |
| 187 | xmlAutomataStatePtr end; |
| 188 | xmlAutomataStatePtr state; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 189 | |
| 190 | xmlDictPtr dict; /* dictionnary for interned string names */ |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 191 | int includes; /* the inclusion level, 0 for root or imports */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 192 | xmlSchemaTypePtr ctxtType; /* The current context simple/complex type */ |
| 193 | xmlSchemaTypePtr parentItem; /* The current parent schema item */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 194 | xmlSchemaAssemblePtr assemble; |
| 195 | int options; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 196 | xmlSchemaValidCtxtPtr vctxt; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 197 | }; |
| 198 | |
| 199 | |
| 200 | #define XML_SCHEMAS_ATTR_UNKNOWN 1 |
| 201 | #define XML_SCHEMAS_ATTR_CHECKED 2 |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 202 | #define XML_SCHEMAS_ATTR_PROHIBITED 3 |
| 203 | #define XML_SCHEMAS_ATTR_MISSING 4 |
| 204 | #define XML_SCHEMAS_ATTR_INVALID_VALUE 5 |
| 205 | #define XML_SCHEMAS_ATTR_TYPE_NOT_RESOLVED 6 |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 206 | #define XML_SCHEMAS_ATTR_INVALID_FIXED_VALUE 7 |
| 207 | #define XML_SCHEMAS_ATTR_DEFAULT 8 |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 208 | |
| 209 | typedef struct _xmlSchemaAttrState xmlSchemaAttrState; |
| 210 | typedef xmlSchemaAttrState *xmlSchemaAttrStatePtr; |
| 211 | struct _xmlSchemaAttrState { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 212 | xmlSchemaAttrStatePtr next; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 213 | xmlAttrPtr attr; |
| 214 | int state; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 215 | xmlSchemaAttributePtr decl; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 216 | const xmlChar *value; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 217 | }; |
| 218 | |
| 219 | /** |
| 220 | * xmlSchemaValidCtxt: |
| 221 | * |
| 222 | * A Schemas validation context |
| 223 | */ |
| 224 | |
| 225 | struct _xmlSchemaValidCtxt { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 226 | void *userData; /* user specific data block */ |
| 227 | xmlSchemaValidityErrorFunc error; /* the callback in case of errors */ |
| 228 | xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */ |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 229 | xmlStructuredErrorFunc serror; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 230 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 231 | xmlSchemaPtr schema; /* The schema in use */ |
| 232 | xmlDocPtr doc; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 233 | xmlParserInputBufferPtr input; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 234 | xmlCharEncoding enc; |
| 235 | xmlSAXHandlerPtr sax; |
| 236 | void *user_data; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 237 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 238 | xmlDocPtr myDoc; |
| 239 | int err; |
| 240 | int nberrors; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 241 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 242 | xmlNodePtr node; |
| 243 | xmlNodePtr cur; |
| 244 | xmlSchemaTypePtr type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 245 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 246 | xmlRegExecCtxtPtr regexp; |
| 247 | xmlSchemaValPtr value; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 248 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 249 | xmlSchemaAttrStatePtr attrTop; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 250 | xmlSchemaAttrStatePtr attr; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 251 | /* xmlNodePtr scope; not used */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 252 | int valueWS; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 253 | int options; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 254 | xmlNodePtr validationRoot; |
| 255 | xmlSchemaParserCtxtPtr pctxt; |
| 256 | int xsiAssemble; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 257 | }; |
| 258 | |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 259 | /* |
| 260 | * These are the entries in the schemas importSchemas hash table |
| 261 | */ |
| 262 | typedef struct _xmlSchemaImport xmlSchemaImport; |
| 263 | typedef xmlSchemaImport *xmlSchemaImportPtr; |
| 264 | struct _xmlSchemaImport { |
| 265 | const xmlChar *schemaLocation; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 266 | xmlSchemaPtr schema; /* not used any more */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 267 | xmlDocPtr doc; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 268 | int isMain; |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 269 | }; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 270 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 271 | /* |
| 272 | * These are the entries associated to includes in a schemas |
| 273 | */ |
| 274 | typedef struct _xmlSchemaInclude xmlSchemaInclude; |
| 275 | typedef xmlSchemaInclude *xmlSchemaIncludePtr; |
| 276 | struct _xmlSchemaInclude { |
| 277 | xmlSchemaIncludePtr next; |
| 278 | |
| 279 | const xmlChar *schemaLocation; |
| 280 | xmlDocPtr doc; |
| 281 | }; |
| 282 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 283 | typedef struct _xmlSchemaParticle xmlSchemaParticle; |
| 284 | typedef xmlSchemaParticle *xmlSchemaParticlePtr; |
| 285 | struct _xmlSchemaParticle { |
| 286 | xmlSchemaTypeType type; |
| 287 | xmlSchemaParticlePtr next; /* the next particle if in a list */ |
| 288 | int minOccurs; |
| 289 | int maxOccurs; |
| 290 | xmlSchemaTypePtr term; |
| 291 | }; |
| 292 | |
| 293 | |
| 294 | typedef struct _xmlSchemaModelGroup xmlSchemaModelGroup; |
| 295 | typedef xmlSchemaModelGroup *xmlSchemaModelGroupPtr; |
| 296 | struct _xmlSchemaModelGroup { |
| 297 | xmlSchemaTypeType type; |
| 298 | int compositor; /* one of all, choice or sequence */ |
| 299 | xmlSchemaParticlePtr particles; /* list of particles */ |
| 300 | xmlSchemaAnnotPtr annot; |
| 301 | }; |
| 302 | |
| 303 | typedef struct _xmlSchemaModelGroupDef xmlSchemaModelGroupDef; |
| 304 | typedef xmlSchemaModelGroupDef *xmlSchemaModelGroupDefPtr; |
| 305 | struct _xmlSchemaModelGroupDef { |
| 306 | xmlSchemaTypeType type; |
| 307 | const xmlChar *name; |
| 308 | const xmlChar *targetNamespace; |
| 309 | xmlSchemaModelGroupPtr modelGroup; |
| 310 | xmlSchemaAnnotPtr annot; |
| 311 | }; |
| 312 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 313 | /************************************************************************ |
| 314 | * * |
| 315 | * Some predeclarations * |
| 316 | * * |
| 317 | ************************************************************************/ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 318 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 319 | static int xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt, |
| 320 | xmlSchemaPtr schema, |
| 321 | xmlNodePtr node); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 322 | static void |
| 323 | xmlSchemaTypeFixup(xmlSchemaTypePtr typeDecl, |
| 324 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name); |
| 325 | static const char * |
| 326 | xmlSchemaFacetTypeToString(xmlSchemaTypeType type); |
| 327 | static int |
| 328 | xmlSchemaValidateSimpleTypeValue(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 329 | xmlSchemaTypePtr type, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 330 | const xmlChar *value, |
| 331 | int fireErrors, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 332 | int applyFacets, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 333 | int normalize, |
| 334 | int checkNodes); |
| 335 | static int |
| 336 | xmlSchemaValidateElementByDeclaration(xmlSchemaValidCtxtPtr ctxt, |
| 337 | xmlSchemaElementPtr elemDecl); |
| 338 | static int |
| 339 | xmlSchemaValidateElementByWildcard(xmlSchemaValidCtxtPtr ctxt, |
| 340 | xmlSchemaTypePtr type); |
| 341 | static int |
| 342 | xmlSchemaHasElemOrCharContent(xmlNodePtr node); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 343 | static int |
| 344 | xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 345 | xmlNodePtr node); |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 346 | static void |
| 347 | xmlSchemaCheckDefaults(xmlSchemaTypePtr typeDecl, |
| 348 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name); |
William M. Brack | 87640d5 | 2004-04-17 14:58:15 +0000 | [diff] [blame] | 349 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 350 | /************************************************************************ |
| 351 | * * |
| 352 | * Datatype error handlers * |
| 353 | * * |
| 354 | ************************************************************************/ |
| 355 | |
| 356 | /** |
| 357 | * xmlSchemaPErrMemory: |
| 358 | * @node: a context node |
| 359 | * @extra: extra informations |
| 360 | * |
| 361 | * Handle an out of memory condition |
| 362 | */ |
| 363 | static void |
| 364 | xmlSchemaPErrMemory(xmlSchemaParserCtxtPtr ctxt, |
| 365 | const char *extra, xmlNodePtr node) |
| 366 | { |
| 367 | if (ctxt != NULL) |
| 368 | ctxt->nberrors++; |
| 369 | __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, node, NULL, |
| 370 | extra); |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * xmlSchemaPErr: |
| 375 | * @ctxt: the parsing context |
| 376 | * @node: the context node |
| 377 | * @error: the error code |
| 378 | * @msg: the error message |
| 379 | * @str1: extra data |
| 380 | * @str2: extra data |
| 381 | * |
| 382 | * Handle a parser error |
| 383 | */ |
| 384 | static void |
| 385 | xmlSchemaPErr(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error, |
| 386 | const char *msg, const xmlChar * str1, const xmlChar * str2) |
| 387 | { |
| 388 | xmlGenericErrorFunc channel = NULL; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 389 | xmlStructuredErrorFunc schannel = NULL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 390 | void *data = NULL; |
| 391 | |
| 392 | if (ctxt != NULL) { |
| 393 | ctxt->nberrors++; |
| 394 | channel = ctxt->error; |
| 395 | data = ctxt->userData; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 396 | schannel = ctxt->serror; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 397 | } |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 398 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 399 | error, XML_ERR_ERROR, NULL, 0, |
| 400 | (const char *) str1, (const char *) str2, NULL, 0, 0, |
| 401 | msg, str1, str2); |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * xmlSchemaPErr2: |
| 406 | * @ctxt: the parsing context |
| 407 | * @node: the context node |
| 408 | * @node: the current child |
| 409 | * @error: the error code |
| 410 | * @msg: the error message |
| 411 | * @str1: extra data |
| 412 | * @str2: extra data |
| 413 | * |
| 414 | * Handle a parser error |
| 415 | */ |
| 416 | static void |
| 417 | xmlSchemaPErr2(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
| 418 | xmlNodePtr child, int error, |
| 419 | const char *msg, const xmlChar * str1, const xmlChar * str2) |
| 420 | { |
| 421 | if (child != NULL) |
| 422 | xmlSchemaPErr(ctxt, child, error, msg, str1, str2); |
| 423 | else |
| 424 | xmlSchemaPErr(ctxt, node, error, msg, str1, str2); |
| 425 | } |
| 426 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 427 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 428 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 429 | * xmlSchemaPErrExt: |
| 430 | * @ctxt: the parsing context |
| 431 | * @node: the context node |
| 432 | * @error: the error code |
| 433 | * @strData1: extra data |
| 434 | * @strData2: extra data |
| 435 | * @strData3: extra data |
| 436 | * @msg: the message |
| 437 | * @str1: extra parameter for the message display |
| 438 | * @str2: extra parameter for the message display |
| 439 | * @str3: extra parameter for the message display |
| 440 | * @str4: extra parameter for the message display |
| 441 | * @str5: extra parameter for the message display |
| 442 | * |
| 443 | * Handle a parser error |
| 444 | */ |
| 445 | static void |
| 446 | xmlSchemaPErrExt(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error, |
| 447 | const xmlChar * strData1, const xmlChar * strData2, |
| 448 | const xmlChar * strData3, const char *msg, const xmlChar * str1, |
| 449 | const xmlChar * str2, const xmlChar * str3, const xmlChar * str4, |
| 450 | const xmlChar * str5) |
| 451 | { |
| 452 | |
| 453 | xmlGenericErrorFunc channel = NULL; |
| 454 | xmlStructuredErrorFunc schannel = NULL; |
| 455 | void *data = NULL; |
| 456 | |
| 457 | if (ctxt != NULL) { |
| 458 | ctxt->nberrors++; |
| 459 | channel = ctxt->error; |
| 460 | data = ctxt->userData; |
| 461 | schannel = ctxt->serror; |
| 462 | } |
| 463 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP, |
| 464 | error, XML_ERR_ERROR, NULL, 0, |
| 465 | (const char *) strData1, (const char *) strData2, |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 466 | (const char *) strData3, 0, 0, msg, str1, str2, |
| 467 | str3, str4, str5); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 468 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 469 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 470 | |
| 471 | /** |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 472 | * xmlSchemaVTypeErrMemory: |
| 473 | * @node: a context node |
| 474 | * @extra: extra informations |
| 475 | * |
| 476 | * Handle an out of memory condition |
| 477 | */ |
| 478 | static void |
| 479 | xmlSchemaVErrMemory(xmlSchemaValidCtxtPtr ctxt, |
| 480 | const char *extra, xmlNodePtr node) |
| 481 | { |
| 482 | if (ctxt != NULL) { |
| 483 | ctxt->nberrors++; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 484 | ctxt->err = XML_SCHEMAV_INTERNAL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 485 | } |
| 486 | __xmlSimpleError(XML_FROM_SCHEMASV, XML_ERR_NO_MEMORY, node, NULL, |
| 487 | extra); |
| 488 | } |
| 489 | |
| 490 | /** |
| 491 | * xmlSchemaVErr3: |
| 492 | * @ctxt: the validation context |
| 493 | * @node: the context node |
| 494 | * @error: the error code |
| 495 | * @msg: the error message |
| 496 | * @str1: extra data |
| 497 | * @str2: extra data |
| 498 | * @str3: extra data |
| 499 | * |
| 500 | * Handle a validation error |
| 501 | */ |
| 502 | static void |
| 503 | xmlSchemaVErr3(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr node, int error, |
| 504 | const char *msg, const xmlChar *str1, const xmlChar *str2, |
| 505 | const xmlChar *str3) |
| 506 | { |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 507 | xmlStructuredErrorFunc schannel = NULL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 508 | xmlGenericErrorFunc channel = NULL; |
| 509 | void *data = NULL; |
| 510 | |
| 511 | if (ctxt != NULL) { |
| 512 | ctxt->nberrors++; |
| 513 | ctxt->err = error; |
| 514 | channel = ctxt->error; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 515 | schannel = ctxt->serror; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 516 | data = ctxt->userData; |
| 517 | } |
| 518 | /* reajust to global error numbers */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 519 | /* Removed, since the old schema error codes have been |
| 520 | * substituted for the global error codes. |
| 521 | * |
| 522 | * error += XML_SCHEMAV_NOROOT - XML_SCHEMAS_ERR_NOROOT; |
| 523 | */ |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 524 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASV, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 525 | error, XML_ERR_ERROR, NULL, 0, |
| 526 | (const char *) str1, (const char *) str2, |
| 527 | (const char *) str3, 0, 0, |
| 528 | msg, str1, str2, str3); |
| 529 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 530 | |
| 531 | /** |
| 532 | * xmlSchemaVErrExt: |
| 533 | * @ctxt: the validation context |
| 534 | * @node: the context node |
| 535 | * @error: the error code |
| 536 | * @msg: the message |
| 537 | * @str1: extra parameter for the message display |
| 538 | * @str2: extra parameter for the message display |
| 539 | * @str3: extra parameter for the message display |
| 540 | * @str4: extra parameter for the message display |
| 541 | * @str5: extra parameter for the message display |
| 542 | * |
| 543 | * Handle a validation error |
| 544 | */ |
| 545 | static void |
| 546 | xmlSchemaVErrExt(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr node, int error, |
| 547 | const char *msg, const xmlChar * str1, |
| 548 | const xmlChar * str2, const xmlChar * str3, |
| 549 | const xmlChar * str4, const xmlChar * str5) |
| 550 | { |
| 551 | xmlStructuredErrorFunc schannel = NULL; |
| 552 | xmlGenericErrorFunc channel = NULL; |
| 553 | void *data = NULL; |
| 554 | |
| 555 | if (ctxt != NULL) { |
| 556 | ctxt->nberrors++; |
| 557 | ctxt->err = error; |
| 558 | channel = ctxt->error; |
| 559 | schannel = ctxt->serror; |
| 560 | data = ctxt->userData; |
| 561 | } |
| 562 | /* reajust to global error numbers */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 563 | /* Removed, since the old schema error codes have been |
| 564 | * substituted for the global error codes. |
| 565 | * |
| 566 | * error += XML_SCHEMAV_NOROOT - XML_SCHEMAS_ERR_NOROOT; |
| 567 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 568 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP, |
| 569 | error, XML_ERR_ERROR, NULL, 0, NULL, NULL, NULL, 0, 0, |
| 570 | msg, str1, str2, str3, str4, str5); |
| 571 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 572 | /** |
| 573 | * xmlSchemaVErr: |
| 574 | * @ctxt: the validation context |
| 575 | * @node: the context node |
| 576 | * @error: the error code |
| 577 | * @msg: the error message |
| 578 | * @str1: extra data |
| 579 | * @str2: extra data |
| 580 | * |
| 581 | * Handle a validation error |
| 582 | */ |
| 583 | static void |
| 584 | xmlSchemaVErr(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr node, int error, |
| 585 | const char *msg, const xmlChar * str1, const xmlChar * str2) |
| 586 | { |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 587 | xmlStructuredErrorFunc schannel = NULL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 588 | xmlGenericErrorFunc channel = NULL; |
| 589 | void *data = NULL; |
| 590 | |
| 591 | if (ctxt != NULL) { |
| 592 | ctxt->nberrors++; |
| 593 | ctxt->err = error; |
| 594 | channel = ctxt->error; |
| 595 | data = ctxt->userData; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 596 | schannel = ctxt->serror; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 597 | } |
| 598 | /* reajust to global error numbers */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 599 | /* Removed, since the old schema error codes have been |
| 600 | * substituted for the global error codes. |
| 601 | * |
| 602 | * error += XML_SCHEMAV_NOROOT - XML_SCHEMAS_ERR_NOROOT; |
| 603 | */ |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 604 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASV, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 605 | error, XML_ERR_ERROR, NULL, 0, |
| 606 | (const char *) str1, (const char *) str2, NULL, 0, 0, |
| 607 | msg, str1, str2); |
| 608 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 609 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 610 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 611 | * xmlSchemaGetAttrName: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 612 | * @attr: the attribute declaration/use |
| 613 | * |
| 614 | * Returns the name of the attribute; if the attribute |
| 615 | * is a reference, the name of the referenced global type will be returned. |
| 616 | */ |
| 617 | static const xmlChar * |
| 618 | xmlSchemaGetAttrName(xmlSchemaAttributePtr attr) |
| 619 | { |
| 620 | if (attr->ref != NULL) |
| 621 | return(attr->ref); |
| 622 | else |
| 623 | return(attr->name); |
| 624 | } |
| 625 | |
| 626 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 627 | * xmlSchemaGetAttrTargetNsURI: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 628 | * @type: the type (element or attribute) |
| 629 | * |
| 630 | * Returns the target namespace URI of the type; if the type is a reference, |
| 631 | * the target namespace of the referenced type will be returned. |
| 632 | */ |
| 633 | static const xmlChar * |
| 634 | xmlSchemaGetAttrTargetNsURI(xmlSchemaAttributePtr attr) |
| 635 | { |
| 636 | if (attr->ref != NULL) |
| 637 | return (attr->refNs); |
| 638 | else |
| 639 | return(attr->targetNamespace); |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * xmlSchemaFormatNsUriLocal: |
| 644 | * @buf: the string buffer |
| 645 | * @uri: the namespace URI |
| 646 | * @local: the local name |
| 647 | * |
| 648 | * Returns a representation of the given URI used |
| 649 | * for error reports. |
| 650 | * |
| 651 | * Returns an empty string, if @ns is NULL, a formatted |
| 652 | * string otherwise. |
| 653 | */ |
| 654 | static const xmlChar* |
| 655 | xmlSchemaFormatNsUriLocal(xmlChar **buf, |
| 656 | const xmlChar *uri, const xmlChar *local) |
| 657 | { |
| 658 | if (*buf != NULL) |
| 659 | xmlFree(*buf); |
| 660 | if (uri == NULL) { |
| 661 | *buf = xmlStrdup(BAD_CAST "{'"); |
| 662 | *buf = xmlStrcat(*buf, local); |
| 663 | } else { |
| 664 | *buf = xmlStrdup(BAD_CAST "{'"); |
| 665 | *buf = xmlStrcat(*buf, uri); |
| 666 | *buf = xmlStrcat(*buf, BAD_CAST "', '"); |
| 667 | *buf = xmlStrcat(*buf, local); |
| 668 | } |
| 669 | *buf = xmlStrcat(*buf, BAD_CAST "'}"); |
| 670 | return ((const xmlChar *) *buf); |
| 671 | } |
| 672 | |
| 673 | /** |
| 674 | * xmlSchemaFormatNsPrefixLocal: |
| 675 | * @buf: the string buffer |
| 676 | * @ns: the namespace |
| 677 | * @local: the local name |
| 678 | * |
| 679 | * Returns a representation of the given URI used |
| 680 | * for error reports. |
| 681 | * |
| 682 | * Returns an empty string, if @ns is NULL, a formatted |
| 683 | * string otherwise. |
| 684 | */ |
| 685 | static const xmlChar* |
| 686 | xmlSchemaFormatNsPrefixLocal(xmlChar **buf, |
| 687 | xmlNsPtr ns, const xmlChar *local) |
| 688 | { |
| 689 | if (*buf != NULL) { |
| 690 | xmlFree(*buf); |
| 691 | *buf = NULL; |
| 692 | } |
| 693 | if ((ns == NULL) || (ns->prefix == NULL)) |
| 694 | return(local); |
| 695 | else { |
| 696 | *buf = xmlStrdup(ns->prefix); |
| 697 | *buf = xmlStrcat(*buf, BAD_CAST ":"); |
| 698 | *buf = xmlStrcat(*buf, local); |
| 699 | } |
| 700 | return ((const xmlChar *) *buf); |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * xmlSchemaFormatItemForReport: |
| 705 | * @buf: the string buffer |
| 706 | * @itemDes: the designation of the item |
| 707 | * @itemName: the name of the item |
| 708 | * @item: the item as an object |
| 709 | * @itemNode: the node of the item |
| 710 | * @local: the local name |
| 711 | * @parsing: if the function is used during the parse |
| 712 | * |
| 713 | * Returns a representation of the given item used |
| 714 | * for error reports. |
| 715 | * |
| 716 | * The following order is used to build the resulting |
| 717 | * designation if the arguments are not NULL: |
| 718 | * 1a. If itemDes not NULL -> itemDes |
| 719 | * 1b. If (itemDes not NULL) and (itemName not NULL) |
| 720 | * -> itemDes + itemName |
| 721 | * 2. If the preceding was NULL and (item not NULL) -> item |
| 722 | * 3. If the preceding was NULL and (itemNode not NULL) -> itemNode |
| 723 | * |
| 724 | * If the itemNode is an attribute node, the name of the attribute |
| 725 | * will be appended to the result. |
| 726 | * |
| 727 | * Returns the formatted string and sets @buf to the resulting value. |
| 728 | */ |
| 729 | static xmlChar* |
| 730 | xmlSchemaFormatItemForReport(xmlChar **buf, |
| 731 | const xmlChar *itemDes, |
| 732 | xmlSchemaTypePtr item, |
| 733 | xmlNodePtr itemNode, |
| 734 | int parsing) |
| 735 | { |
| 736 | xmlChar *str = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 737 | int named = 1; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 738 | |
| 739 | if (*buf != NULL) { |
| 740 | xmlFree(*buf); |
| 741 | *buf = NULL; |
| 742 | } |
| 743 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 744 | if (itemDes != NULL) { |
| 745 | *buf = xmlStrdup(itemDes); |
| 746 | } else if (item != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 747 | if (item->type == XML_SCHEMA_TYPE_BASIC) { |
| 748 | if (item->builtInType == XML_SCHEMAS_ANYTYPE) |
| 749 | *buf = xmlStrdup(BAD_CAST "'anyType'"); |
| 750 | else if (item->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) |
| 751 | *buf = xmlStrdup(BAD_CAST "'anySimpleType'"); |
| 752 | else { |
| 753 | /* *buf = xmlStrdup(BAD_CAST "bi "); */ |
| 754 | /* *buf = xmlStrcat(*buf, xmlSchemaElemDesST); */ |
| 755 | *buf = xmlStrdup(BAD_CAST "'"); |
| 756 | *buf = xmlStrcat(*buf, item->name); |
| 757 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 758 | } |
| 759 | } else if (item->type == XML_SCHEMA_TYPE_SIMPLE) { |
| 760 | if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) { |
| 761 | *buf = xmlStrdup(xmlSchemaElemDesST); |
| 762 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 763 | *buf = xmlStrcat(*buf, item->name); |
| 764 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 765 | } else { |
| 766 | *buf = xmlStrdup(xmlSchemaElemDesST); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 767 | /* Local types will get to name |
| 768 | *buf = xmlStrcat(*buf, BAD_CAST " "); |
| 769 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 770 | } |
| 771 | } else if (item->type == XML_SCHEMA_TYPE_COMPLEX) { |
| 772 | if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) { |
| 773 | *buf = xmlStrdup(xmlSchemaElemDesCT); |
| 774 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 775 | *buf = xmlStrcat(*buf, item->name); |
| 776 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 777 | } else { |
| 778 | *buf = xmlStrdup(xmlSchemaElemDesCT); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 779 | /* Local types will get to name |
| 780 | *buf = xmlStrcat(*buf, BAD_CAST " "); |
| 781 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 782 | } |
| 783 | } else if (item->type == XML_SCHEMA_TYPE_ATTRIBUTE) { |
| 784 | xmlSchemaAttributePtr attr; |
| 785 | |
| 786 | attr = (xmlSchemaAttributePtr) item; |
| 787 | if ((attr->flags & XML_SCHEMAS_TYPE_GLOBAL) || |
| 788 | (attr->ref == NULL)) { |
| 789 | *buf = xmlStrdup(xmlSchemaElemDesAttrDecl); |
| 790 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 791 | *buf = xmlStrcat(*buf, attr->name); |
| 792 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 793 | } else { |
| 794 | *buf = xmlStrdup(xmlSchemaElemDesAttrRef); |
| 795 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 796 | *buf = xmlStrcat(*buf, attr->refPrefix); |
| 797 | *buf = xmlStrcat(*buf, BAD_CAST ":"); |
| 798 | *buf = xmlStrcat(*buf, attr->ref); |
| 799 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 800 | } |
| 801 | } else if (item->type == XML_SCHEMA_TYPE_ELEMENT) { |
| 802 | xmlSchemaElementPtr elem; |
| 803 | |
| 804 | elem = (xmlSchemaElementPtr) item; |
| 805 | if ((elem->flags & XML_SCHEMAS_TYPE_GLOBAL) || |
| 806 | (elem->ref == NULL)) { |
| 807 | *buf = xmlStrdup(xmlSchemaElemDesElemDecl); |
| 808 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 809 | *buf = xmlStrcat(*buf, elem->name); |
| 810 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 811 | } else { |
| 812 | *buf = xmlStrdup(xmlSchemaElemDesElemRef); |
| 813 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 814 | *buf = xmlStrcat(*buf, elem->refPrefix); |
| 815 | *buf = xmlStrcat(*buf, BAD_CAST ":"); |
| 816 | *buf = xmlStrcat(*buf, elem->ref); |
| 817 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 818 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 819 | } else |
| 820 | named = 0; |
| 821 | } else |
| 822 | named = 0; |
| 823 | |
| 824 | if ((named == 0) && (itemNode != NULL)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 825 | xmlNodePtr elem; |
| 826 | |
| 827 | if (itemNode->type == XML_ATTRIBUTE_NODE) |
| 828 | elem = itemNode->parent; |
| 829 | else |
| 830 | elem = itemNode; |
| 831 | *buf = xmlStrdup(BAD_CAST "Element '"); |
| 832 | if (parsing) |
| 833 | *buf = xmlStrcat(*buf, elem->name); |
| 834 | else |
| 835 | *buf = xmlStrcat(*buf, |
| 836 | xmlSchemaFormatNsPrefixLocal(&str, elem->ns, elem->name)); |
| 837 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 838 | } |
| 839 | if ((itemNode != NULL) && (itemNode->type == XML_ATTRIBUTE_NODE)) { |
| 840 | *buf = xmlStrcat(*buf, BAD_CAST ", attribute '"); |
| 841 | *buf = xmlStrcat(*buf, xmlSchemaFormatNsPrefixLocal(&str, |
| 842 | itemNode->ns, itemNode->name)); |
| 843 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 844 | } |
| 845 | FREE_AND_NULL(str); |
| 846 | |
| 847 | return (*buf); |
| 848 | } |
| 849 | |
| 850 | /** |
| 851 | * xmlSchemaPFormatItemDes: |
| 852 | * @buf: the string buffer |
| 853 | * @item: the item as a schema object |
| 854 | * @itemNode: the item as a node |
| 855 | * |
| 856 | * If the pointer to @buf is not NULL and @but holds no value, |
| 857 | * the value is set to a item designation using |
| 858 | * xmlSchemaFormatItemForReport. This one avoids adding |
| 859 | * an attribute designation postfix. |
| 860 | * |
| 861 | * Returns a string of all enumeration elements. |
| 862 | */ |
| 863 | static void |
| 864 | xmlSchemaPRequestItemDes(xmlChar **buf, |
| 865 | xmlSchemaTypePtr item, |
| 866 | xmlNodePtr itemNode) |
| 867 | { |
| 868 | if ((buf == 0) || (*buf != NULL)) |
| 869 | return; |
| 870 | if (itemNode->type == XML_ATTRIBUTE_NODE) |
| 871 | itemNode = itemNode->parent; |
| 872 | xmlSchemaFormatItemForReport(buf, NULL, item, itemNode, 1); |
| 873 | } |
| 874 | |
| 875 | /** |
| 876 | * xmlSchemaFormatFacetEnumSet: |
| 877 | * @buf: the string buffer |
| 878 | * @type: the type holding the enumeration facets |
| 879 | * |
| 880 | * Builds a string consisting of all enumeration elements. |
| 881 | * |
| 882 | * Returns a string of all enumeration elements. |
| 883 | */ |
| 884 | static const xmlChar * |
| 885 | xmlSchemaFormatFacetEnumSet(xmlChar **buf, xmlSchemaTypePtr type) |
| 886 | { |
| 887 | xmlSchemaFacetLinkPtr link; |
| 888 | |
| 889 | if (*buf != NULL) |
| 890 | xmlFree(*buf); |
| 891 | *buf = NULL; |
| 892 | for (link = type->facetSet; link != NULL; link = link->next) { |
| 893 | if (link->facet->type == XML_SCHEMA_FACET_ENUMERATION) { |
| 894 | if (*buf == NULL) { |
| 895 | *buf = xmlStrdup(BAD_CAST "'"); |
| 896 | *buf = xmlStrcat(*buf, link->facet->value); |
| 897 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 898 | } else { |
| 899 | *buf = xmlStrcat(*buf, BAD_CAST ", '"); |
| 900 | *buf = xmlStrcat(*buf, link->facet->value); |
| 901 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 902 | } |
| 903 | } |
| 904 | } |
| 905 | return ((const xmlChar *) *buf); |
| 906 | } |
| 907 | |
| 908 | /** |
| 909 | * xmlSchemaVFacetErr: |
| 910 | * @ctxt: the schema validation context |
| 911 | * @error: the error code |
| 912 | * @node: the node to be validated |
| 913 | * @value: the value of the node |
| 914 | * @type: the type holding the facet |
| 915 | * @facet: the facet |
| 916 | * @message: the error message of NULL |
| 917 | * @str1: extra data |
| 918 | * @str2: extra data |
| 919 | * @str3: extra data |
| 920 | * |
| 921 | * Reports a facet validation error. |
| 922 | * TODO: Should this report the value of an element as well? |
| 923 | */ |
| 924 | static void |
| 925 | xmlSchemaVFacetErr(xmlSchemaValidCtxtPtr ctxt, |
| 926 | xmlParserErrors error, |
| 927 | xmlNodePtr node, |
| 928 | const xmlChar *value, |
| 929 | unsigned long length, |
| 930 | xmlSchemaTypePtr type, |
| 931 | xmlSchemaFacetPtr facet, |
| 932 | const char *message, |
| 933 | const xmlChar *str1, |
| 934 | const xmlChar *str2, |
| 935 | const xmlChar *str3) |
| 936 | { |
| 937 | xmlChar *str = NULL, *msg = NULL; |
| 938 | xmlSchemaTypeType facetType; |
| 939 | |
| 940 | xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); |
| 941 | msg = xmlStrcat(msg, BAD_CAST " ["); |
| 942 | msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); |
| 943 | msg = xmlStrcat(msg, BAD_CAST ", facet '"); |
| 944 | if (error == XML_SCHEMAV_CVC_ENUMERATION_VALID) { |
| 945 | facetType = XML_SCHEMA_FACET_ENUMERATION; |
| 946 | /* |
| 947 | * If enumerations are validated, one must not expect the |
| 948 | * facet to be given. |
| 949 | */ |
| 950 | } else |
| 951 | facetType = facet->type; |
| 952 | msg = xmlStrcat(msg, BAD_CAST xmlSchemaFacetTypeToString(facetType)); |
| 953 | msg = xmlStrcat(msg, BAD_CAST "']: "); |
| 954 | if (message == NULL) { |
| 955 | /* |
| 956 | * Use a default message. |
| 957 | */ |
| 958 | if ((facetType == XML_SCHEMA_FACET_LENGTH) || |
| 959 | (facetType == XML_SCHEMA_FACET_MINLENGTH) || |
| 960 | (facetType == XML_SCHEMA_FACET_MAXLENGTH)) { |
| 961 | |
| 962 | char len[25], actLen[25]; |
| 963 | |
| 964 | /* FIXME, TODO: What is the max expected string length of the |
| 965 | * this value? |
| 966 | */ |
| 967 | if (node->type == XML_ATTRIBUTE_NODE) |
| 968 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' has a length of '%s'; "); |
| 969 | else |
| 970 | msg = xmlStrcat(msg, BAD_CAST "The value has a length of '%s'; "); |
| 971 | |
| 972 | snprintf(len, 24, "%lu", xmlSchemaGetFacetValueAsULong(facet)); |
| 973 | snprintf(actLen, 24, "%lu", length); |
| 974 | |
| 975 | if (facetType == XML_SCHEMA_FACET_LENGTH) |
| 976 | msg = xmlStrcat(msg, |
| 977 | BAD_CAST "this differs from the allowed length of '%s'.\n"); |
| 978 | else if (facetType == XML_SCHEMA_FACET_MAXLENGTH) |
| 979 | msg = xmlStrcat(msg, |
| 980 | BAD_CAST "this exceeds the allowed maximum length of '%s'.\n"); |
| 981 | else if (facetType == XML_SCHEMA_FACET_MINLENGTH) |
| 982 | msg = xmlStrcat(msg, |
| 983 | BAD_CAST "this underruns the allowed minimum length of '%s'.\n"); |
| 984 | |
| 985 | if (node->type == XML_ATTRIBUTE_NODE) |
| 986 | xmlSchemaVErrExt(ctxt, node, error, |
| 987 | (const char *) msg, |
| 988 | value, (const xmlChar *) actLen, (const xmlChar *) len, |
| 989 | NULL, NULL); |
| 990 | else |
| 991 | xmlSchemaVErr(ctxt, node, error, |
| 992 | (const char *) msg, |
| 993 | (const xmlChar *) actLen, (const xmlChar *) len); |
| 994 | |
| 995 | } else if (facetType == XML_SCHEMA_FACET_ENUMERATION) { |
| 996 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not an element " |
| 997 | "of the set {%s}.\n"); |
| 998 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, |
| 999 | xmlSchemaFormatFacetEnumSet(&str, type)); |
| 1000 | } else if (facetType == XML_SCHEMA_FACET_PATTERN) { |
| 1001 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not accepted " |
| 1002 | "by the pattern '%s'.\n"); |
| 1003 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, |
| 1004 | facet->value); |
| 1005 | } else if (node->type == XML_ATTRIBUTE_NODE) { |
| 1006 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not facet-valid.\n"); |
| 1007 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, NULL); |
| 1008 | } else { |
| 1009 | msg = xmlStrcat(msg, BAD_CAST "The value is not facet-valid.\n"); |
| 1010 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, NULL, NULL); |
| 1011 | } |
| 1012 | } else { |
| 1013 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 1014 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1015 | xmlSchemaVErr3(ctxt, node, error, (const char *) msg, str1, str2, str3); |
| 1016 | } |
| 1017 | FREE_AND_NULL(str) |
| 1018 | xmlFree(msg); |
| 1019 | } |
| 1020 | |
| 1021 | /** |
| 1022 | * xmlSchemaVSimpleTypeErr: |
| 1023 | * @ctxt: the schema validation context |
| 1024 | * @error: the error code |
| 1025 | * @type: the type used for validation |
| 1026 | * @node: the node containing the validated value |
| 1027 | * @value: the validated value |
| 1028 | * |
| 1029 | * Reports a simple type validation error. |
| 1030 | * TODO: Should this report the value of an element as well? |
| 1031 | */ |
| 1032 | static void |
| 1033 | xmlSchemaVSimpleTypeErr(xmlSchemaValidCtxtPtr ctxt, |
| 1034 | xmlParserErrors error, |
| 1035 | xmlNodePtr node, |
| 1036 | const xmlChar *value, |
| 1037 | xmlSchemaTypePtr type) |
| 1038 | { |
| 1039 | xmlChar *str = NULL, *msg = NULL; |
| 1040 | |
| 1041 | xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); |
| 1042 | msg = xmlStrcat(msg, BAD_CAST " ["); |
| 1043 | msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); |
| 1044 | if (node->type == XML_ATTRIBUTE_NODE) { |
| 1045 | msg = xmlStrcat(msg, BAD_CAST "]: The value '%s' is not valid.\n"); |
| 1046 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, NULL); |
| 1047 | } else { |
| 1048 | msg = xmlStrcat(msg, BAD_CAST "]: The character content is not valid.\n"); |
| 1049 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, NULL, NULL); |
| 1050 | } |
| 1051 | FREE_AND_NULL(str) |
| 1052 | xmlFree(msg); |
| 1053 | } |
| 1054 | |
| 1055 | /** |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1056 | * xmlSchemaVComplexTypeErr: |
| 1057 | * @ctxt: the schema validation context |
| 1058 | * @error: the error code |
| 1059 | * @node: the node containing the validated value |
| 1060 | * @type: the complex type used for validation |
| 1061 | * @message: the error message |
| 1062 | * |
| 1063 | * Reports a complex type validation error. |
| 1064 | */ |
| 1065 | static void |
| 1066 | xmlSchemaVComplexTypeErr(xmlSchemaValidCtxtPtr ctxt, |
| 1067 | xmlParserErrors error, |
| 1068 | xmlNodePtr node, |
| 1069 | xmlSchemaTypePtr type, |
| 1070 | const char *message) |
| 1071 | { |
| 1072 | xmlChar *str = NULL, *msg = NULL; |
| 1073 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 1074 | xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 1075 | /* Specify the complex type only if it is global. */ |
| 1076 | if ((type != NULL) && (type->flags & XML_SCHEMAS_TYPE_GLOBAL)) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 1077 | msg = xmlStrcat(msg, BAD_CAST " ["); |
| 1078 | msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); |
| 1079 | msg = xmlStrcat(msg, BAD_CAST "]"); |
| 1080 | } |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1081 | msg = xmlStrcat(msg, BAD_CAST ": %s.\n"); |
| 1082 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1083 | (const xmlChar *) message, NULL); |
| 1084 | FREE_AND_NULL(str) |
| 1085 | xmlFree(msg); |
| 1086 | } |
| 1087 | |
| 1088 | /** |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1089 | * xmlSchemaVComplexTypeElemErr: |
| 1090 | * @ctxt: the schema validation context |
| 1091 | * @error: the error code |
| 1092 | * @node: the node containing the validated value |
| 1093 | * @type: the complex type used for validation |
| 1094 | * @message: the error message |
| 1095 | * |
| 1096 | * Reports a complex type validation error. |
| 1097 | */ |
| 1098 | static void |
| 1099 | xmlSchemaVComplexTypeElemErr(xmlSchemaValidCtxtPtr ctxt, |
| 1100 | xmlParserErrors error, |
| 1101 | xmlNodePtr node, |
| 1102 | xmlSchemaTypePtr type, |
| 1103 | const char *message, |
| 1104 | int nbval, |
| 1105 | int nbneg, |
| 1106 | xmlChar **values) |
| 1107 | { |
| 1108 | xmlChar *str = NULL, *msg = NULL; |
| 1109 | xmlChar *localName, *nsName; |
| 1110 | const xmlChar *cur, *end; |
| 1111 | int i; |
| 1112 | |
| 1113 | xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); |
| 1114 | /* Specify the complex type only if it is global. */ |
| 1115 | if ((type != NULL) && (type->flags & XML_SCHEMAS_TYPE_GLOBAL)) { |
| 1116 | msg = xmlStrcat(msg, BAD_CAST " ["); |
| 1117 | msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); |
| 1118 | msg = xmlStrcat(msg, BAD_CAST "]"); |
| 1119 | FREE_AND_NULL(str) |
| 1120 | } |
| 1121 | msg = xmlStrcat(msg, BAD_CAST ": "); |
| 1122 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 1123 | /* |
| 1124 | * Note that is does not make sense to report that we have a |
| 1125 | * wildcard here, since the wildcard might be unfolded into |
| 1126 | * multiple transitions. |
| 1127 | */ |
| 1128 | if (nbval + nbneg > 0) { |
| 1129 | if (nbval + nbneg > 1) { |
| 1130 | str = xmlStrdup(BAD_CAST ". Expected is one of "); |
| 1131 | } else |
| 1132 | str = xmlStrdup(BAD_CAST ". Expected is "); |
| 1133 | nsName = NULL; |
| 1134 | |
| 1135 | for (i = 0; i < nbval + nbneg; i++) { |
| 1136 | cur = values[i]; |
| 1137 | /* |
| 1138 | * Get the local name. |
| 1139 | */ |
| 1140 | localName = NULL; |
| 1141 | |
| 1142 | end = cur; |
| 1143 | if (*end == '*') { |
| 1144 | localName = xmlStrdup(BAD_CAST "*"); |
| 1145 | *end++; |
| 1146 | } else { |
| 1147 | while ((*end != 0) && (*end != '|')) |
| 1148 | end++; |
| 1149 | localName = xmlStrcat(localName, BAD_CAST "'"); |
| 1150 | localName = xmlStrncat(localName, BAD_CAST cur, end - cur); |
| 1151 | localName = xmlStrcat(localName, BAD_CAST "'"); |
| 1152 | } |
| 1153 | if (*end != 0) { |
| 1154 | *end++; |
| 1155 | /* |
| 1156 | * Skip "*|*" if they come with negated expressions, since |
| 1157 | * they represent the same negated wildcard. |
| 1158 | */ |
| 1159 | if ((nbneg == 0) || (*end != '*') || (*localName != '*')) { |
| 1160 | /* |
| 1161 | * Get the namespace name. |
| 1162 | */ |
| 1163 | cur = end; |
| 1164 | if (*end == '*') { |
| 1165 | nsName = xmlStrdup(BAD_CAST "{*}"); |
| 1166 | } else { |
| 1167 | while (*end != 0) |
| 1168 | end++; |
| 1169 | |
| 1170 | if (i >= nbval) |
| 1171 | nsName = xmlStrdup(BAD_CAST "{##other:"); |
| 1172 | else |
| 1173 | nsName = xmlStrdup(BAD_CAST "{"); |
| 1174 | |
| 1175 | nsName = xmlStrncat(nsName, BAD_CAST cur, end - cur); |
| 1176 | nsName = xmlStrcat(nsName, BAD_CAST "}"); |
| 1177 | } |
| 1178 | str = xmlStrcat(str, BAD_CAST nsName); |
| 1179 | FREE_AND_NULL(nsName) |
| 1180 | } else { |
| 1181 | FREE_AND_NULL(localName); |
| 1182 | continue; |
| 1183 | } |
| 1184 | } |
| 1185 | str = xmlStrcat(str, BAD_CAST localName); |
| 1186 | FREE_AND_NULL(localName); |
| 1187 | |
| 1188 | if (i < nbval + nbneg -1) |
| 1189 | str = xmlStrcat(str, BAD_CAST ", "); |
| 1190 | } |
| 1191 | msg = xmlStrcat(msg, BAD_CAST str); |
| 1192 | FREE_AND_NULL(str) |
| 1193 | } |
| 1194 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1195 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, NULL, NULL); |
| 1196 | xmlFree(msg); |
| 1197 | } |
| 1198 | |
| 1199 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1200 | * xmlSchemaPMissingAttrErr: |
| 1201 | * @ctxt: the schema validation context |
| 1202 | * @ownerDes: the designation of the owner |
| 1203 | * @ownerName: the name of the owner |
| 1204 | * @ownerItem: the owner as a schema object |
| 1205 | * @ownerElem: the owner as an element node |
| 1206 | * @node: the parent element node of the missing attribute node |
| 1207 | * @type: the corresponding type of the attribute node |
| 1208 | * |
| 1209 | * Reports an illegal attribute. |
| 1210 | */ |
| 1211 | static void |
| 1212 | xmlSchemaPMissingAttrErr(xmlSchemaParserCtxtPtr ctxt, |
| 1213 | xmlParserErrors error, |
| 1214 | xmlChar **ownerDes, |
| 1215 | xmlSchemaTypePtr ownerItem, |
| 1216 | xmlNodePtr ownerElem, |
| 1217 | const char *name, |
| 1218 | const char *message) |
| 1219 | { |
| 1220 | xmlChar *des = NULL; |
| 1221 | |
| 1222 | if (ownerDes == NULL) |
| 1223 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem, 1); |
| 1224 | else if (*ownerDes == NULL) { |
| 1225 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, ownerElem, 1); |
| 1226 | des = *ownerDes; |
| 1227 | } else |
| 1228 | des = *ownerDes; |
| 1229 | if (message != NULL) |
| 1230 | xmlSchemaPErr(ctxt, ownerElem, error, "%s: %s.\n", BAD_CAST des, BAD_CAST message); |
| 1231 | else |
| 1232 | xmlSchemaPErr(ctxt, ownerElem, error, |
| 1233 | "%s: The attribute '%s' is required but missing.\n", |
| 1234 | BAD_CAST des, BAD_CAST name); |
| 1235 | if (ownerDes == NULL) |
| 1236 | FREE_AND_NULL(des); |
| 1237 | } |
| 1238 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1239 | /** |
| 1240 | * xmlSchemaCompTypeToString: |
| 1241 | * @type: the type of the schema item |
| 1242 | * |
| 1243 | * Returns the component name of a schema item. |
| 1244 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1245 | static const char * |
| 1246 | xmlSchemaCompTypeToString(xmlSchemaTypeType type) |
| 1247 | { |
| 1248 | switch (type) { |
| 1249 | case XML_SCHEMA_TYPE_SIMPLE: |
| 1250 | return("simple type definition"); |
| 1251 | case XML_SCHEMA_TYPE_COMPLEX: |
| 1252 | return("complex type definition"); |
| 1253 | case XML_SCHEMA_TYPE_ELEMENT: |
| 1254 | return("element declaration"); |
| 1255 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 1256 | return("attribute declaration"); |
| 1257 | case XML_SCHEMA_TYPE_GROUP: |
| 1258 | return("model group definition"); |
| 1259 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
| 1260 | return("attribute group definition"); |
| 1261 | case XML_SCHEMA_TYPE_NOTATION: |
| 1262 | return("notation declaration"); |
| 1263 | default: |
| 1264 | return("Not a schema component"); |
| 1265 | } |
| 1266 | } |
| 1267 | /** |
| 1268 | * xmlSchemaPResCompAttrErr: |
| 1269 | * @ctxt: the schema validation context |
| 1270 | * @error: the error code |
| 1271 | * @ownerDes: the designation of the owner |
| 1272 | * @ownerItem: the owner as a schema object |
| 1273 | * @ownerElem: the owner as an element node |
| 1274 | * @name: the name of the attribute holding the QName |
| 1275 | * @refName: the referenced local name |
| 1276 | * @refURI: the referenced namespace URI |
| 1277 | * @message: optional message |
| 1278 | * |
| 1279 | * Used to report QName attribute values that failed to resolve |
| 1280 | * to schema components. |
| 1281 | */ |
| 1282 | static void |
| 1283 | xmlSchemaPResCompAttrErr(xmlSchemaParserCtxtPtr ctxt, |
| 1284 | xmlParserErrors error, |
| 1285 | xmlChar **ownerDes, |
| 1286 | xmlSchemaTypePtr ownerItem, |
| 1287 | xmlNodePtr ownerElem, |
| 1288 | const char *name, |
| 1289 | const xmlChar *refName, |
| 1290 | const xmlChar *refURI, |
| 1291 | xmlSchemaTypeType refType, |
| 1292 | const char *refTypeStr) |
| 1293 | { |
| 1294 | xmlChar *des = NULL, *strA = NULL; |
| 1295 | |
| 1296 | if (ownerDes == NULL) |
| 1297 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem, 1); |
| 1298 | else if (*ownerDes == NULL) { |
| 1299 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, ownerElem, 1); |
| 1300 | des = *ownerDes; |
| 1301 | } else |
| 1302 | des = *ownerDes; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1303 | if (refTypeStr == NULL) |
| 1304 | refTypeStr = xmlSchemaCompTypeToString(refType); |
| 1305 | xmlSchemaPErrExt(ctxt, ownerElem, error, |
| 1306 | NULL, NULL, NULL, |
| 1307 | "%s, attribute '%s': The QName value %s does not resolve to a(n) " |
| 1308 | "%s.\n", BAD_CAST des, BAD_CAST name, |
| 1309 | xmlSchemaFormatNsUriLocal(&strA, refURI, refName), |
| 1310 | BAD_CAST refTypeStr, NULL); |
| 1311 | if (ownerDes == NULL) |
| 1312 | FREE_AND_NULL(des) |
| 1313 | FREE_AND_NULL(strA) |
| 1314 | } |
| 1315 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1316 | /** |
| 1317 | * xmlSchemaPCustomAttrErr: |
| 1318 | * @ctxt: the schema parser context |
| 1319 | * @error: the error code |
| 1320 | * @ownerDes: the designation of the owner |
| 1321 | * @ownerItem: the owner as a schema object |
| 1322 | * @attr: the illegal attribute node |
| 1323 | * |
| 1324 | * Reports an illegal attribute during the parse. |
| 1325 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1326 | static void |
| 1327 | xmlSchemaPCustomAttrErr(xmlSchemaParserCtxtPtr ctxt, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1328 | xmlParserErrors error, |
| 1329 | xmlChar **ownerDes, |
| 1330 | xmlSchemaTypePtr ownerItem, |
| 1331 | xmlAttrPtr attr, |
| 1332 | const char *msg) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1333 | { |
| 1334 | xmlChar *des = NULL; |
| 1335 | |
| 1336 | if (ownerDes == NULL) |
| 1337 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent, 1); |
| 1338 | else if (*ownerDes == NULL) { |
| 1339 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent, 1); |
| 1340 | des = *ownerDes; |
| 1341 | } else |
| 1342 | des = *ownerDes; |
| 1343 | xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL, |
| 1344 | "%s, attribute '%s': %s.\n", |
| 1345 | BAD_CAST des, attr->name, (const xmlChar *) msg, NULL, NULL); |
| 1346 | if (ownerDes == NULL) |
| 1347 | FREE_AND_NULL(des); |
| 1348 | } |
| 1349 | |
| 1350 | /** |
| 1351 | * xmlSchemaPIllegalAttrErr: |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1352 | * @ctxt: the schema parser context |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1353 | * @error: the error code |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1354 | * @ownerDes: the designation of the attribute's owner |
| 1355 | * @ownerItem: the attribute's owner item |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1356 | * @attr: the illegal attribute node |
| 1357 | * |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1358 | * Reports an illegal attribute during the parse. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1359 | */ |
| 1360 | static void |
| 1361 | xmlSchemaPIllegalAttrErr(xmlSchemaParserCtxtPtr ctxt, |
| 1362 | xmlParserErrors error, |
| 1363 | xmlChar **ownerDes, |
| 1364 | xmlSchemaTypePtr ownerItem, |
| 1365 | xmlAttrPtr attr) |
| 1366 | { |
| 1367 | xmlChar *des = NULL, *strA = NULL; |
| 1368 | |
| 1369 | if (ownerDes == NULL) |
| 1370 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent, 1); |
| 1371 | else if (*ownerDes == NULL) { |
| 1372 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent, 1); |
| 1373 | des = *ownerDes; |
| 1374 | } else |
| 1375 | des = *ownerDes; |
| 1376 | xmlSchemaPErr(ctxt, (xmlNodePtr) attr, error, |
| 1377 | "%s: The attribute '%s' is not allowed.\n", BAD_CAST des, |
| 1378 | xmlSchemaFormatNsPrefixLocal(&strA, attr->ns, attr->name)); |
| 1379 | if (ownerDes == NULL) |
| 1380 | FREE_AND_NULL(des); |
| 1381 | FREE_AND_NULL(strA); |
| 1382 | } |
| 1383 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1384 | /** |
| 1385 | * xmlSchemaPAquireDes: |
| 1386 | * @des: the first designation |
| 1387 | * @itemDes: the second designation |
| 1388 | * @item: the schema item |
| 1389 | * @itemElem: the node of the schema item |
| 1390 | * |
| 1391 | * Creates a designation for an item. |
| 1392 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1393 | static void |
| 1394 | xmlSchemaPAquireDes(xmlChar **des, |
| 1395 | xmlChar **itemDes, |
| 1396 | xmlSchemaTypePtr item, |
| 1397 | xmlNodePtr itemElem) |
| 1398 | { |
| 1399 | if (itemDes == NULL) |
| 1400 | xmlSchemaFormatItemForReport(des, NULL, item, itemElem, 1); |
| 1401 | else if (*itemDes == NULL) { |
| 1402 | xmlSchemaFormatItemForReport(itemDes, NULL, item, itemElem, 1); |
| 1403 | *des = *itemDes; |
| 1404 | } else |
| 1405 | *des = *itemDes; |
| 1406 | } |
| 1407 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1408 | /** |
| 1409 | * xmlSchemaPCustomErr: |
| 1410 | * @ctxt: the schema parser context |
| 1411 | * @error: the error code |
| 1412 | * @itemDes: the designation of the schema item |
| 1413 | * @item: the schema item |
| 1414 | * @itemElem: the node of the schema item |
| 1415 | * @message: the error message |
| 1416 | * @str1: an optional param for the error message |
| 1417 | * @str2: an optional param for the error message |
| 1418 | * @str3: an optional param for the error message |
| 1419 | * |
| 1420 | * Reports an error during parsing. |
| 1421 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1422 | static void |
| 1423 | xmlSchemaPCustomErrExt(xmlSchemaParserCtxtPtr ctxt, |
| 1424 | xmlParserErrors error, |
| 1425 | xmlChar **itemDes, |
| 1426 | xmlSchemaTypePtr item, |
| 1427 | xmlNodePtr itemElem, |
| 1428 | const char *message, |
| 1429 | const xmlChar *str1, |
| 1430 | const xmlChar *str2, |
| 1431 | const xmlChar *str3) |
| 1432 | { |
| 1433 | xmlChar *des = NULL, *msg = NULL; |
| 1434 | |
| 1435 | xmlSchemaPAquireDes(&des, itemDes, item, itemElem); |
| 1436 | msg = xmlStrdup(BAD_CAST "%s: "); |
| 1437 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 1438 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1439 | if ((itemElem == NULL) && (item != NULL)) |
| 1440 | itemElem = item->node; |
| 1441 | xmlSchemaPErrExt(ctxt, itemElem, error, NULL, NULL, NULL, |
| 1442 | (const char *) msg, BAD_CAST des, str1, str2, str3, NULL); |
| 1443 | if (itemDes == NULL) |
| 1444 | FREE_AND_NULL(des); |
| 1445 | FREE_AND_NULL(msg); |
| 1446 | } |
| 1447 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1448 | /** |
| 1449 | * xmlSchemaPCustomErr: |
| 1450 | * @ctxt: the schema parser context |
| 1451 | * @error: the error code |
| 1452 | * @itemDes: the designation of the schema item |
| 1453 | * @item: the schema item |
| 1454 | * @itemElem: the node of the schema item |
| 1455 | * @message: the error message |
| 1456 | * @str1: the optional param for the error message |
| 1457 | * |
| 1458 | * Reports an error during parsing. |
| 1459 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1460 | static void |
| 1461 | xmlSchemaPCustomErr(xmlSchemaParserCtxtPtr ctxt, |
| 1462 | xmlParserErrors error, |
| 1463 | xmlChar **itemDes, |
| 1464 | xmlSchemaTypePtr item, |
| 1465 | xmlNodePtr itemElem, |
| 1466 | const char *message, |
| 1467 | const xmlChar *str1) |
| 1468 | { |
| 1469 | xmlSchemaPCustomErrExt(ctxt, error, itemDes, item, itemElem, message, |
| 1470 | str1, NULL, NULL); |
| 1471 | } |
| 1472 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1473 | /** |
| 1474 | * xmlSchemaPAttrUseErr: |
| 1475 | * @ctxt: the schema parser context |
| 1476 | * @error: the error code |
| 1477 | * @itemDes: the designation of the schema type |
| 1478 | * @item: the schema type |
| 1479 | * @itemElem: the node of the schema type |
| 1480 | * @attr: the invalid schema attribute |
| 1481 | * @message: the error message |
| 1482 | * @str1: the optional param for the error message |
| 1483 | * |
| 1484 | * Reports an attribute use error during parsing. |
| 1485 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1486 | static void |
| 1487 | xmlSchemaPAttrUseErr(xmlSchemaParserCtxtPtr ctxt, |
| 1488 | xmlParserErrors error, |
| 1489 | xmlChar **itemDes, |
| 1490 | xmlSchemaTypePtr item, |
| 1491 | xmlNodePtr itemElem, |
| 1492 | const xmlSchemaAttributePtr attr, |
| 1493 | const char *message, |
| 1494 | const xmlChar *str1) |
| 1495 | { |
| 1496 | xmlChar *des = NULL, *strA = NULL, *msg = NULL; |
| 1497 | |
| 1498 | xmlSchemaPAquireDes(&des, itemDes, item, itemElem); |
| 1499 | xmlSchemaFormatNsUriLocal(&strA, xmlSchemaGetAttrTargetNsURI(attr), |
| 1500 | xmlSchemaGetAttrName(attr)); |
| 1501 | msg = xmlStrdup(BAD_CAST "%s, attr. use %s: "); |
| 1502 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 1503 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1504 | if ((itemElem == NULL) && (item != NULL)) |
| 1505 | itemElem = item->node; |
| 1506 | xmlSchemaPErrExt(ctxt, itemElem, error, NULL, NULL, NULL, |
| 1507 | (const char *) msg, BAD_CAST des, BAD_CAST strA, str1, NULL, NULL); |
| 1508 | if (itemDes == NULL) |
| 1509 | FREE_AND_NULL(des); |
| 1510 | FREE_AND_NULL(strA); |
| 1511 | xmlFree(msg); |
| 1512 | } |
| 1513 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1514 | /** |
| 1515 | * xmlSchemaPIllegalFacetAtomicErr: |
| 1516 | * @ctxt: the schema parser context |
| 1517 | * @error: the error code |
| 1518 | * @itemDes: the designation of the type |
| 1519 | * @item: the schema type |
| 1520 | * @baseItem: the base type of type |
| 1521 | * @facet: the illegal facet |
| 1522 | * |
| 1523 | * Reports an illegal facet for atomic simple types. |
| 1524 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1525 | static void |
| 1526 | xmlSchemaPIllegalFacetAtomicErr(xmlSchemaParserCtxtPtr ctxt, |
| 1527 | xmlParserErrors error, |
| 1528 | xmlChar **itemDes, |
| 1529 | xmlSchemaTypePtr item, |
| 1530 | xmlSchemaTypePtr baseItem, |
| 1531 | xmlSchemaFacetPtr facet) |
| 1532 | { |
| 1533 | xmlChar *des = NULL, *strT = NULL; |
| 1534 | |
| 1535 | xmlSchemaPAquireDes(&des, itemDes, item, item->node); |
| 1536 | xmlSchemaPErrExt(ctxt, item->node, error, NULL, NULL, NULL, |
| 1537 | "%s: The facet '%s' is not allowed on types derived from the " |
| 1538 | "type %s.\n", |
| 1539 | BAD_CAST des, BAD_CAST xmlSchemaFacetTypeToString(facet->type), |
| 1540 | xmlSchemaFormatItemForReport(&strT, NULL, baseItem, NULL, 1), |
| 1541 | NULL, NULL); |
| 1542 | if (itemDes == NULL) |
| 1543 | FREE_AND_NULL(des); |
| 1544 | FREE_AND_NULL(strT); |
| 1545 | } |
| 1546 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1547 | /** |
| 1548 | * xmlSchemaPIllegalFacetListUnionErr: |
| 1549 | * @ctxt: the schema parser context |
| 1550 | * @error: the error code |
| 1551 | * @itemDes: the designation of the schema item involved |
| 1552 | * @item: the schema item involved |
| 1553 | * @facet: the illegal facet |
| 1554 | * |
| 1555 | * Reports an illegal facet for <list> and <union>. |
| 1556 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1557 | static void |
| 1558 | xmlSchemaPIllegalFacetListUnionErr(xmlSchemaParserCtxtPtr ctxt, |
| 1559 | xmlParserErrors error, |
| 1560 | xmlChar **itemDes, |
| 1561 | xmlSchemaTypePtr item, |
| 1562 | xmlSchemaFacetPtr facet) |
| 1563 | { |
| 1564 | xmlChar *des = NULL, *strT = NULL; |
| 1565 | |
| 1566 | xmlSchemaPAquireDes(&des, itemDes, item, item->node); |
| 1567 | xmlSchemaPErr(ctxt, item->node, error, |
| 1568 | "%s: The facet '%s' is not allowed.\n", |
| 1569 | BAD_CAST des, BAD_CAST xmlSchemaFacetTypeToString(facet->type)); |
| 1570 | if (itemDes == NULL) |
| 1571 | FREE_AND_NULL(des); |
| 1572 | FREE_AND_NULL(strT); |
| 1573 | } |
| 1574 | |
| 1575 | /** |
| 1576 | * xmlSchemaPMutualExclAttrErr: |
| 1577 | * @ctxt: the schema validation context |
| 1578 | * @error: the error code |
| 1579 | * @elemDes: the designation of the parent element node |
| 1580 | * @attr: the bad attribute node |
| 1581 | * @type: the corresponding type of the attribute node |
| 1582 | * |
| 1583 | * Reports an illegal attribute. |
| 1584 | */ |
| 1585 | static void |
| 1586 | xmlSchemaPMutualExclAttrErr(xmlSchemaParserCtxtPtr ctxt, |
| 1587 | xmlParserErrors error, |
| 1588 | xmlChar **ownerDes, |
| 1589 | xmlSchemaTypePtr ownerItem, |
| 1590 | xmlAttrPtr attr, |
| 1591 | const char *name1, |
| 1592 | const char *name2) |
| 1593 | { |
| 1594 | xmlChar *des = NULL; |
| 1595 | |
| 1596 | if (ownerDes == NULL) |
| 1597 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent, 1); |
| 1598 | else if (*ownerDes == NULL) { |
| 1599 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent, 1); |
| 1600 | des = *ownerDes; |
| 1601 | } else |
| 1602 | des = *ownerDes; |
| 1603 | xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL, |
| 1604 | "%s: The attributes '%s' and '%s' are mutually exclusive.\n", |
| 1605 | BAD_CAST des, BAD_CAST name1, BAD_CAST name2, NULL, NULL); |
| 1606 | if (ownerDes == NULL) |
| 1607 | FREE_AND_NULL(des) |
| 1608 | } |
| 1609 | |
| 1610 | /** |
| 1611 | * xmlSchemaPSimpleTypeErr: |
| 1612 | * @ctxt: the schema validation context |
| 1613 | * @error: the error code |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1614 | * @type: the type specifier |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1615 | * @ownerDes: the designation of the owner |
| 1616 | * @ownerItem: the schema object if existent |
| 1617 | * @node: the validated node |
| 1618 | * @value: the validated value |
| 1619 | * |
| 1620 | * Reports a simple type validation error. |
| 1621 | * TODO: Should this report the value of an element as well? |
| 1622 | */ |
| 1623 | static void |
| 1624 | xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt, |
| 1625 | xmlParserErrors error, |
| 1626 | xmlChar **ownerDes, |
| 1627 | xmlSchemaTypePtr ownerItem, |
| 1628 | xmlNodePtr node, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1629 | xmlSchemaTypePtr type, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1630 | const char *typeDes, |
| 1631 | const xmlChar *value, |
| 1632 | const char *message, |
| 1633 | const xmlChar *str1, |
| 1634 | const xmlChar *str2) |
| 1635 | { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1636 | xmlChar *des = NULL, *strA = NULL, *strT = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1637 | |
| 1638 | if (ownerDes == NULL) |
| 1639 | xmlSchemaPRequestItemDes(&des, ownerItem, node); |
| 1640 | else if (*ownerDes == NULL) { |
| 1641 | xmlSchemaPRequestItemDes(ownerDes, ownerItem, node); |
| 1642 | des = *ownerDes; |
| 1643 | } else |
| 1644 | des = *ownerDes; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1645 | if (type != NULL) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1646 | typeDes = (const char *) xmlSchemaFormatItemForReport(&strT, NULL, type, NULL, 1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1647 | if (message == NULL) { |
| 1648 | /* |
| 1649 | * Use default messages. |
| 1650 | */ |
| 1651 | if (node->type == XML_ATTRIBUTE_NODE) { |
| 1652 | xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL, |
| 1653 | "%s, attribute '%s' [%s]: The value '%s' is not " |
| 1654 | "valid.\n", |
| 1655 | BAD_CAST des, xmlSchemaFormatNsPrefixLocal(&strA, node->ns, |
| 1656 | node->name), BAD_CAST typeDes, value, NULL); |
| 1657 | } else { |
| 1658 | xmlSchemaPErr(ctxt, node, error, |
| 1659 | "%s [%s]: The character content is not valid.\n", |
| 1660 | BAD_CAST des, BAD_CAST typeDes); |
| 1661 | } |
| 1662 | } else { |
| 1663 | xmlChar *msg; |
| 1664 | |
| 1665 | msg = xmlStrdup(BAD_CAST "%s"); |
| 1666 | if (node->type == XML_ATTRIBUTE_NODE) |
| 1667 | msg = xmlStrcat(msg, BAD_CAST ", attribute '%s'"); |
| 1668 | msg = xmlStrcat(msg, BAD_CAST " [%s]: "); |
| 1669 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 1670 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1671 | if (node->type == XML_ATTRIBUTE_NODE) { |
| 1672 | xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL, |
| 1673 | (const char *) msg, |
| 1674 | BAD_CAST des, xmlSchemaFormatNsPrefixLocal(&strA, |
| 1675 | node->ns, node->name), BAD_CAST typeDes, str1, str2); |
| 1676 | } else { |
| 1677 | xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL, |
| 1678 | (const char *) msg, |
| 1679 | BAD_CAST des, BAD_CAST typeDes, str1, str2, NULL); |
| 1680 | } |
| 1681 | xmlFree(msg); |
| 1682 | } |
| 1683 | /* Cleanup. */ |
| 1684 | FREE_AND_NULL(strA) |
| 1685 | FREE_AND_NULL(strT) |
| 1686 | if (ownerDes == NULL) |
| 1687 | FREE_AND_NULL(des) |
| 1688 | } |
| 1689 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1690 | /** |
| 1691 | * xmlSchemaPContentErr: |
| 1692 | * @ctxt: the schema parser context |
| 1693 | * @error: the error code |
| 1694 | * @onwerDes: the designation of the holder of the content |
| 1695 | * @ownerItem: the owner item of the holder of the content |
| 1696 | * @ownerElem: the node of the holder of the content |
| 1697 | * @child: the invalid child node |
| 1698 | * @message: the optional error message |
| 1699 | * @content: the optional string describing the correct content |
| 1700 | * |
| 1701 | * Reports an error concerning the content of a schema element. |
| 1702 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1703 | static void |
| 1704 | xmlSchemaPContentErr(xmlSchemaParserCtxtPtr ctxt, |
| 1705 | xmlParserErrors error, |
| 1706 | xmlChar **ownerDes, |
| 1707 | xmlSchemaTypePtr ownerItem, |
| 1708 | xmlNodePtr ownerElem, |
| 1709 | xmlNodePtr child, |
| 1710 | const char *message, |
| 1711 | const char *content) |
| 1712 | { |
| 1713 | xmlChar *des = NULL; |
| 1714 | |
| 1715 | if (ownerDes == NULL) |
| 1716 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem, 1); |
| 1717 | else if (*ownerDes == NULL) { |
| 1718 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, ownerElem, 1); |
| 1719 | des = *ownerDes; |
| 1720 | } else |
| 1721 | des = *ownerDes; |
| 1722 | if (message != NULL) |
| 1723 | xmlSchemaPErr2(ctxt, ownerElem, child, error, |
| 1724 | "%s: %s.\n", |
| 1725 | BAD_CAST des, BAD_CAST message); |
| 1726 | else { |
| 1727 | if (content != NULL) { |
| 1728 | xmlSchemaPErr2(ctxt, ownerElem, child, error, |
| 1729 | "%s: The content is not valid. Expected is %s.\n", |
| 1730 | BAD_CAST des, BAD_CAST content); |
| 1731 | } else { |
| 1732 | xmlSchemaPErr2(ctxt, ownerElem, child, error, |
| 1733 | "%s: The content is not valid.\n", |
| 1734 | BAD_CAST des, NULL); |
| 1735 | } |
| 1736 | } |
| 1737 | if (ownerDes == NULL) |
| 1738 | FREE_AND_NULL(des) |
| 1739 | } |
| 1740 | |
| 1741 | /** |
| 1742 | * xmlSchemaVIllegalAttrErr: |
| 1743 | * @ctxt: the schema validation context |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 1744 | * @error: the error code |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1745 | * @attr: the illegal attribute node |
| 1746 | * |
| 1747 | * Reports an illegal attribute. |
| 1748 | */ |
| 1749 | static void |
| 1750 | xmlSchemaVIllegalAttrErr(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 1751 | xmlParserErrors error, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1752 | xmlAttrPtr attr) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1753 | { |
| 1754 | xmlChar *strE = NULL, *strA = NULL; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 1755 | |
| 1756 | xmlSchemaVErr(ctxt, (xmlNodePtr) attr, |
| 1757 | error, |
| 1758 | /* XML_SCHEMAS_ERR_ATTRUNKNOWN, */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1759 | "%s: The attribute '%s' is not allowed.\n", |
| 1760 | xmlSchemaFormatItemForReport(&strE, NULL, NULL, attr->parent, 0), |
| 1761 | xmlSchemaFormatNsPrefixLocal(&strA, attr->ns, attr->name)); |
| 1762 | FREE_AND_NULL(strE) |
| 1763 | FREE_AND_NULL(strA) |
| 1764 | } |
| 1765 | |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 1766 | |
| 1767 | static int |
| 1768 | xmlSchemaIsGlobalItem(xmlSchemaTypePtr item) |
| 1769 | { |
| 1770 | switch (item->type) { |
| 1771 | case XML_SCHEMA_TYPE_COMPLEX: |
| 1772 | case XML_SCHEMA_TYPE_SIMPLE: |
| 1773 | case XML_SCHEMA_TYPE_GROUP: |
| 1774 | if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) |
| 1775 | return(1); |
| 1776 | break; |
| 1777 | case XML_SCHEMA_TYPE_ELEMENT: |
| 1778 | if ( ((xmlSchemaElementPtr) item)->flags & |
| 1779 | XML_SCHEMAS_ELEM_GLOBAL) |
| 1780 | return(1); |
| 1781 | break; |
| 1782 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 1783 | if ( ((xmlSchemaAttributePtr) item)->flags & |
| 1784 | XML_SCHEMAS_ATTR_GLOBAL) |
| 1785 | return(1); |
| 1786 | break; |
| 1787 | /* Note that attribute groups are always global. */ |
| 1788 | default: |
| 1789 | return(1); |
| 1790 | } |
| 1791 | return (0); |
| 1792 | } |
| 1793 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1794 | /** |
| 1795 | * xmlSchemaVCustomErr: |
| 1796 | * @ctxt: the schema validation context |
| 1797 | * @error: the error code |
| 1798 | * @node: the validated node |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 1799 | * @type: the schema type of the validated node |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1800 | * @message: the error message |
| 1801 | * @str1: the optional param for the message |
| 1802 | * |
| 1803 | * Reports a validation error. |
| 1804 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1805 | static void |
| 1806 | xmlSchemaVCustomErr(xmlSchemaValidCtxtPtr ctxt, |
| 1807 | xmlParserErrors error, |
| 1808 | xmlNodePtr node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 1809 | xmlSchemaTypePtr type, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1810 | const char *message, |
| 1811 | const xmlChar *str1) |
| 1812 | { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 1813 | xmlChar *msg = NULL, *str = NULL; |
| 1814 | |
| 1815 | if (node == NULL) { |
| 1816 | xmlSchemaVErr(ctxt, NULL, |
| 1817 | XML_SCHEMAV_INTERNAL, |
| 1818 | "Internal error: xmlSchemaVCustomErr, no node " |
| 1819 | "given.\n", NULL, NULL); |
| 1820 | return; |
| 1821 | } |
| 1822 | /* TODO: Are the HTML and DOCB doc nodes expected here? */ |
| 1823 | if (node->type != XML_DOCUMENT_NODE) { |
| 1824 | xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 1825 | if ((type != NULL) && (xmlSchemaIsGlobalItem(type))) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 1826 | msg = xmlStrcat(msg, BAD_CAST " ["); |
| 1827 | msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); |
| 1828 | msg = xmlStrcat(msg, BAD_CAST "]"); |
| 1829 | } |
| 1830 | msg = xmlStrcat(msg, BAD_CAST ": "); |
| 1831 | } else |
| 1832 | msg = xmlStrdup((const xmlChar *) ""); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1833 | msg = xmlStrcat(msg, (const xmlChar *) message); |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 1834 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1835 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, str1, NULL); |
| 1836 | FREE_AND_NULL(msg) |
| 1837 | FREE_AND_NULL(str) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1838 | } |
| 1839 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1840 | /** |
| 1841 | * xmlSchemaWildcardPCToString: |
| 1842 | * @pc: the type of processContents |
| 1843 | * |
| 1844 | * Returns a string representation of the type of |
| 1845 | * processContents. |
| 1846 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1847 | static const char * |
| 1848 | xmlSchemaWildcardPCToString(int pc) |
| 1849 | { |
| 1850 | switch (pc) { |
| 1851 | case XML_SCHEMAS_ANY_SKIP: |
| 1852 | return ("skip"); |
| 1853 | case XML_SCHEMAS_ANY_LAX: |
| 1854 | return ("lax"); |
| 1855 | case XML_SCHEMAS_ANY_STRICT: |
| 1856 | return ("strict"); |
| 1857 | default: |
| 1858 | return ("invalid process contents"); |
| 1859 | } |
| 1860 | } |
| 1861 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1862 | /** |
| 1863 | * xmlSchemaVWildcardErr: |
| 1864 | * @ctxt: the schema validation context |
| 1865 | * @error: the error code |
| 1866 | * @node: the validated node |
| 1867 | * @wild: the wildcard used |
| 1868 | * @message: the error message |
| 1869 | * |
| 1870 | * Reports an validation-by-wildcard error. |
| 1871 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1872 | static void |
| 1873 | xmlSchemaVWildcardErr(xmlSchemaValidCtxtPtr ctxt, |
| 1874 | xmlParserErrors error, |
| 1875 | xmlNodePtr node, |
| 1876 | xmlSchemaWildcardPtr wild, |
| 1877 | const char *message) |
| 1878 | { |
| 1879 | xmlChar *des = NULL, *msg = NULL; |
| 1880 | |
| 1881 | xmlSchemaFormatItemForReport(&des, NULL, NULL, node, 0); |
| 1882 | msg = xmlStrdup(BAD_CAST "%s, ["); |
| 1883 | msg = xmlStrcat(msg, BAD_CAST xmlSchemaWildcardPCToString(wild->processContents)); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 1884 | msg = xmlStrcat(msg, BAD_CAST " wildcard]: "); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1885 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 1886 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1887 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, BAD_CAST des, NULL); |
| 1888 | FREE_AND_NULL(des); |
| 1889 | FREE_AND_NULL(msg); |
| 1890 | } |
| 1891 | |
| 1892 | /** |
| 1893 | * xmlSchemaVMissingAttrErr: |
| 1894 | * @ctxt: the schema validation context |
| 1895 | * @node: the parent element node of the missing attribute node |
| 1896 | * @type: the corresponding type of the attribute node |
| 1897 | * |
| 1898 | * Reports an illegal attribute. |
| 1899 | */ |
| 1900 | static void |
| 1901 | xmlSchemaVMissingAttrErr(xmlSchemaValidCtxtPtr ctxt, |
| 1902 | xmlNodePtr elem, |
| 1903 | xmlSchemaAttributePtr type) |
| 1904 | { |
| 1905 | const xmlChar *name, *uri; |
| 1906 | xmlChar *strE = NULL, *strA = NULL; |
| 1907 | |
| 1908 | if (type->ref != NULL) { |
| 1909 | name = type->ref; |
| 1910 | uri = type->refNs; |
| 1911 | } else { |
| 1912 | name = type->name; |
| 1913 | uri = type->targetNamespace; |
| 1914 | } |
| 1915 | xmlSchemaVErr(ctxt, elem, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 1916 | XML_SCHEMAV_CVC_COMPLEX_TYPE_4, |
| 1917 | /* XML_SCHEMAS_ERR_MISSING, */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1918 | "%s: The attribute %s is required but missing.\n", |
| 1919 | xmlSchemaFormatItemForReport(&strE, NULL, NULL, elem, 0), |
| 1920 | xmlSchemaFormatNsUriLocal(&strA, uri, name)); |
| 1921 | FREE_AND_NULL(strE) |
| 1922 | FREE_AND_NULL(strA) |
| 1923 | } |
| 1924 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 1925 | /************************************************************************ |
| 1926 | * * |
| 1927 | * Allocation functions * |
| 1928 | * * |
| 1929 | ************************************************************************/ |
| 1930 | |
| 1931 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 1932 | * xmlSchemaNewSchemaForParserCtxt: |
William M. Brack | 0817191 | 2003-12-29 02:52:11 +0000 | [diff] [blame] | 1933 | * @ctxt: a schema validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 1934 | * |
| 1935 | * Allocate a new Schema structure. |
| 1936 | * |
| 1937 | * Returns the newly allocated structure or NULL in case or error |
| 1938 | */ |
| 1939 | static xmlSchemaPtr |
| 1940 | xmlSchemaNewSchema(xmlSchemaParserCtxtPtr ctxt) |
| 1941 | { |
| 1942 | xmlSchemaPtr ret; |
| 1943 | |
| 1944 | ret = (xmlSchemaPtr) xmlMalloc(sizeof(xmlSchema)); |
| 1945 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 1946 | xmlSchemaPErrMemory(ctxt, "allocating schema", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 1947 | return (NULL); |
| 1948 | } |
| 1949 | memset(ret, 0, sizeof(xmlSchema)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 1950 | ret->dict = ctxt->dict; |
Daniel Veillard | 500a1de | 2004-03-22 15:22:58 +0000 | [diff] [blame] | 1951 | xmlDictReference(ret->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 1952 | |
| 1953 | return (ret); |
| 1954 | } |
| 1955 | |
| 1956 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 1957 | * xmlSchemaNewSchema: |
| 1958 | * @ctxt: a schema validation context |
| 1959 | * |
| 1960 | * Allocate a new Schema structure. |
| 1961 | * |
| 1962 | * Returns the newly allocated structure or NULL in case or error |
| 1963 | */ |
| 1964 | static xmlSchemaAssemblePtr |
| 1965 | xmlSchemaNewAssemble(void) |
| 1966 | { |
| 1967 | xmlSchemaAssemblePtr ret; |
| 1968 | |
| 1969 | ret = (xmlSchemaAssemblePtr) xmlMalloc(sizeof(xmlSchemaAssemble)); |
| 1970 | if (ret == NULL) { |
| 1971 | /* xmlSchemaPErrMemory(ctxt, "allocating assemble info", NULL); */ |
| 1972 | return (NULL); |
| 1973 | } |
| 1974 | memset(ret, 0, sizeof(xmlSchemaAssemble)); |
| 1975 | ret->items = NULL; |
| 1976 | return (ret); |
| 1977 | } |
| 1978 | |
| 1979 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 1980 | * xmlSchemaNewFacet: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 1981 | * |
| 1982 | * Allocate a new Facet structure. |
| 1983 | * |
| 1984 | * Returns the newly allocated structure or NULL in case or error |
| 1985 | */ |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 1986 | xmlSchemaFacetPtr |
| 1987 | xmlSchemaNewFacet(void) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 1988 | { |
| 1989 | xmlSchemaFacetPtr ret; |
| 1990 | |
| 1991 | ret = (xmlSchemaFacetPtr) xmlMalloc(sizeof(xmlSchemaFacet)); |
| 1992 | if (ret == NULL) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 1993 | return (NULL); |
| 1994 | } |
| 1995 | memset(ret, 0, sizeof(xmlSchemaFacet)); |
| 1996 | |
| 1997 | return (ret); |
| 1998 | } |
| 1999 | |
| 2000 | /** |
| 2001 | * xmlSchemaNewAnnot: |
William M. Brack | 0817191 | 2003-12-29 02:52:11 +0000 | [diff] [blame] | 2002 | * @ctxt: a schema validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2003 | * @node: a node |
| 2004 | * |
| 2005 | * Allocate a new annotation structure. |
| 2006 | * |
| 2007 | * Returns the newly allocated structure or NULL in case or error |
| 2008 | */ |
| 2009 | static xmlSchemaAnnotPtr |
| 2010 | xmlSchemaNewAnnot(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node) |
| 2011 | { |
| 2012 | xmlSchemaAnnotPtr ret; |
| 2013 | |
| 2014 | ret = (xmlSchemaAnnotPtr) xmlMalloc(sizeof(xmlSchemaAnnot)); |
| 2015 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2016 | xmlSchemaPErrMemory(ctxt, "allocating annotation", node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2017 | return (NULL); |
| 2018 | } |
| 2019 | memset(ret, 0, sizeof(xmlSchemaAnnot)); |
| 2020 | ret->content = node; |
| 2021 | return (ret); |
| 2022 | } |
| 2023 | |
| 2024 | /** |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 2025 | * xmlSchemaFreeAnnot: |
| 2026 | * @annot: a schema type structure |
| 2027 | * |
| 2028 | * Deallocate a annotation structure |
| 2029 | */ |
| 2030 | static void |
| 2031 | xmlSchemaFreeAnnot(xmlSchemaAnnotPtr annot) |
| 2032 | { |
| 2033 | if (annot == NULL) |
| 2034 | return; |
| 2035 | xmlFree(annot); |
| 2036 | } |
| 2037 | |
| 2038 | /** |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 2039 | * xmlSchemaFreeImport: |
| 2040 | * @import: a schema import structure |
| 2041 | * |
| 2042 | * Deallocate an import structure |
| 2043 | */ |
| 2044 | static void |
| 2045 | xmlSchemaFreeImport(xmlSchemaImportPtr import) |
| 2046 | { |
| 2047 | if (import == NULL) |
| 2048 | return; |
| 2049 | |
| 2050 | xmlSchemaFree(import->schema); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2051 | xmlFreeDoc(import->doc); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 2052 | xmlFree(import); |
| 2053 | } |
| 2054 | |
| 2055 | /** |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 2056 | * xmlSchemaFreeInclude: |
| 2057 | * @include: a schema include structure |
| 2058 | * |
| 2059 | * Deallocate an include structure |
| 2060 | */ |
| 2061 | static void |
| 2062 | xmlSchemaFreeInclude(xmlSchemaIncludePtr include) |
| 2063 | { |
| 2064 | if (include == NULL) |
| 2065 | return; |
| 2066 | |
| 2067 | xmlFreeDoc(include->doc); |
| 2068 | xmlFree(include); |
| 2069 | } |
| 2070 | |
| 2071 | /** |
| 2072 | * xmlSchemaFreeIncludeList: |
| 2073 | * @includes: a schema include list |
| 2074 | * |
| 2075 | * Deallocate an include structure |
| 2076 | */ |
| 2077 | static void |
| 2078 | xmlSchemaFreeIncludeList(xmlSchemaIncludePtr includes) |
| 2079 | { |
| 2080 | xmlSchemaIncludePtr next; |
| 2081 | |
| 2082 | while (includes != NULL) { |
| 2083 | next = includes->next; |
| 2084 | xmlSchemaFreeInclude(includes); |
| 2085 | includes = next; |
| 2086 | } |
| 2087 | } |
| 2088 | |
| 2089 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2090 | * xmlSchemaFreeNotation: |
| 2091 | * @schema: a schema notation structure |
| 2092 | * |
| 2093 | * Deallocate a Schema Notation structure. |
| 2094 | */ |
| 2095 | static void |
| 2096 | xmlSchemaFreeNotation(xmlSchemaNotationPtr nota) |
| 2097 | { |
| 2098 | if (nota == NULL) |
| 2099 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2100 | xmlFree(nota); |
| 2101 | } |
| 2102 | |
| 2103 | /** |
| 2104 | * xmlSchemaFreeAttribute: |
| 2105 | * @schema: a schema attribute structure |
| 2106 | * |
| 2107 | * Deallocate a Schema Attribute structure. |
| 2108 | */ |
| 2109 | static void |
| 2110 | xmlSchemaFreeAttribute(xmlSchemaAttributePtr attr) |
| 2111 | { |
| 2112 | if (attr == NULL) |
| 2113 | return; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2114 | if (attr->annot != NULL) |
| 2115 | xmlSchemaFreeAnnot(attr->annot); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 2116 | if (attr->defVal != NULL) |
| 2117 | xmlSchemaFreeValue(attr->defVal); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2118 | xmlFree(attr); |
| 2119 | } |
| 2120 | |
| 2121 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2122 | * xmlSchemaFreeWildcardNsSet: |
| 2123 | * set: a schema wildcard namespace |
| 2124 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2125 | * Deallocates a list of wildcard constraint structures. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2126 | */ |
| 2127 | static void |
| 2128 | xmlSchemaFreeWildcardNsSet(xmlSchemaWildcardNsPtr set) |
| 2129 | { |
| 2130 | xmlSchemaWildcardNsPtr next; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2131 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2132 | while (set != NULL) { |
| 2133 | next = set->next; |
| 2134 | xmlFree(set); |
| 2135 | set = next; |
| 2136 | } |
| 2137 | } |
| 2138 | |
| 2139 | /** |
| 2140 | * xmlSchemaFreeWildcard: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2141 | * @wildcard: a wildcard structure |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2142 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2143 | * Deallocates a wildcard structure. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2144 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2145 | void |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2146 | xmlSchemaFreeWildcard(xmlSchemaWildcardPtr wildcard) |
| 2147 | { |
| 2148 | if (wildcard == NULL) |
| 2149 | return; |
| 2150 | if (wildcard->annot != NULL) |
| 2151 | xmlSchemaFreeAnnot(wildcard->annot); |
| 2152 | if (wildcard->nsSet != NULL) |
| 2153 | xmlSchemaFreeWildcardNsSet(wildcard->nsSet); |
| 2154 | if (wildcard->negNsSet != NULL) |
| 2155 | xmlFree(wildcard->negNsSet); |
| 2156 | xmlFree(wildcard); |
| 2157 | } |
| 2158 | |
| 2159 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2160 | * xmlSchemaFreeAttributeGroup: |
| 2161 | * @schema: a schema attribute group structure |
| 2162 | * |
| 2163 | * Deallocate a Schema Attribute Group structure. |
| 2164 | */ |
| 2165 | static void |
| 2166 | xmlSchemaFreeAttributeGroup(xmlSchemaAttributeGroupPtr attr) |
| 2167 | { |
| 2168 | if (attr == NULL) |
| 2169 | return; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2170 | if (attr->annot != NULL) |
| 2171 | xmlSchemaFreeAnnot(attr->annot); |
| 2172 | if ((attr->flags & XML_SCHEMAS_ATTRGROUP_GLOBAL) && |
| 2173 | (attr->attributeWildcard != NULL)) |
| 2174 | xmlSchemaFreeWildcard(attr->attributeWildcard); |
| 2175 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2176 | xmlFree(attr); |
| 2177 | } |
| 2178 | |
| 2179 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2180 | * xmlSchemaFreeAttributeUseList: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2181 | * @attrUse: an attribute link |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2182 | * |
| 2183 | * Deallocate a list of schema attribute uses. |
| 2184 | */ |
| 2185 | static void |
| 2186 | xmlSchemaFreeAttributeUseList(xmlSchemaAttributeLinkPtr attrUse) |
| 2187 | { |
| 2188 | xmlSchemaAttributeLinkPtr next; |
| 2189 | |
| 2190 | while (attrUse != NULL) { |
| 2191 | next = attrUse->next; |
| 2192 | xmlFree(attrUse); |
| 2193 | attrUse = next; |
| 2194 | } |
| 2195 | } |
| 2196 | |
| 2197 | /** |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2198 | * xmlSchemaFreeTypeLinkList: |
| 2199 | * @alink: a type link |
| 2200 | * |
| 2201 | * Deallocate a list of types. |
| 2202 | */ |
| 2203 | static void |
| 2204 | xmlSchemaFreeTypeLinkList(xmlSchemaTypeLinkPtr link) |
| 2205 | { |
| 2206 | xmlSchemaTypeLinkPtr next; |
| 2207 | |
| 2208 | while (link != NULL) { |
| 2209 | next = link->next; |
| 2210 | xmlFree(link); |
| 2211 | link = next; |
| 2212 | } |
| 2213 | } |
| 2214 | |
| 2215 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2216 | * xmlSchemaFreeElement: |
| 2217 | * @schema: a schema element structure |
| 2218 | * |
| 2219 | * Deallocate a Schema Element structure. |
| 2220 | */ |
| 2221 | static void |
| 2222 | xmlSchemaFreeElement(xmlSchemaElementPtr elem) |
| 2223 | { |
| 2224 | if (elem == NULL) |
| 2225 | return; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 2226 | if (elem->annot != NULL) |
| 2227 | xmlSchemaFreeAnnot(elem->annot); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2228 | if (elem->contModel != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2229 | xmlRegFreeRegexp(elem->contModel); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 2230 | if (elem->defVal != NULL) |
| 2231 | xmlSchemaFreeValue(elem->defVal); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2232 | xmlFree(elem); |
| 2233 | } |
| 2234 | |
| 2235 | /** |
| 2236 | * xmlSchemaFreeFacet: |
| 2237 | * @facet: a schema facet structure |
| 2238 | * |
| 2239 | * Deallocate a Schema Facet structure. |
| 2240 | */ |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 2241 | void |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2242 | xmlSchemaFreeFacet(xmlSchemaFacetPtr facet) |
| 2243 | { |
| 2244 | if (facet == NULL) |
| 2245 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2246 | if (facet->val != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2247 | xmlSchemaFreeValue(facet->val); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2248 | if (facet->regexp != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2249 | xmlRegFreeRegexp(facet->regexp); |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 2250 | if (facet->annot != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2251 | xmlSchemaFreeAnnot(facet->annot); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2252 | xmlFree(facet); |
| 2253 | } |
| 2254 | |
| 2255 | /** |
| 2256 | * xmlSchemaFreeType: |
| 2257 | * @type: a schema type structure |
| 2258 | * |
| 2259 | * Deallocate a Schema Type structure. |
| 2260 | */ |
| 2261 | void |
| 2262 | xmlSchemaFreeType(xmlSchemaTypePtr type) |
| 2263 | { |
| 2264 | if (type == NULL) |
| 2265 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2266 | if (type->annot != NULL) |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 2267 | xmlSchemaFreeAnnot(type->annot); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2268 | if (type->facets != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2269 | xmlSchemaFacetPtr facet, next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2270 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2271 | facet = type->facets; |
| 2272 | while (facet != NULL) { |
| 2273 | next = facet->next; |
| 2274 | xmlSchemaFreeFacet(facet); |
| 2275 | facet = next; |
| 2276 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2277 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2278 | if (type->type != XML_SCHEMA_TYPE_BASIC) { |
| 2279 | if (type->attributeUses != NULL) |
| 2280 | xmlSchemaFreeAttributeUseList(type->attributeUses); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 2281 | if ((type->attributeWildcard != NULL) && |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2282 | ((type->type != XML_SCHEMA_TYPE_COMPLEX) || |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 2283 | (type->flags & XML_SCHEMAS_TYPE_OWNED_ATTR_WILDCARD))) { |
| 2284 | /* |
| 2285 | * NOTE: The only case where an attribute wildcard |
| 2286 | * is not owned, is if a complex type inherits it |
| 2287 | * from a base type. |
| 2288 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2289 | xmlSchemaFreeWildcard(type->attributeWildcard); |
| 2290 | } |
| 2291 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2292 | if (type->memberTypes != NULL) |
| 2293 | xmlSchemaFreeTypeLinkList(type->memberTypes); |
| 2294 | if (type->facetSet != NULL) { |
| 2295 | xmlSchemaFacetLinkPtr next, link; |
| 2296 | |
| 2297 | link = type->facetSet; |
| 2298 | do { |
| 2299 | next = link->next; |
| 2300 | xmlFree(link); |
| 2301 | link = next; |
| 2302 | } while (link != NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 2303 | } |
| 2304 | if (type->contModel != NULL) |
| 2305 | xmlRegFreeRegexp(type->contModel); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2306 | xmlFree(type); |
| 2307 | } |
| 2308 | |
| 2309 | /** |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 2310 | * xmlSchemaFreeTypeList: |
| 2311 | * @type: a schema type structure |
| 2312 | * |
| 2313 | * Deallocate a Schema Type structure. |
| 2314 | */ |
| 2315 | static void |
| 2316 | xmlSchemaFreeTypeList(xmlSchemaTypePtr type) |
| 2317 | { |
| 2318 | xmlSchemaTypePtr next; |
| 2319 | |
| 2320 | while (type != NULL) { |
| 2321 | next = type->redef; |
| 2322 | xmlSchemaFreeType(type); |
| 2323 | type = next; |
| 2324 | } |
| 2325 | } |
| 2326 | |
| 2327 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2328 | * xmlSchemaFree: |
| 2329 | * @schema: a schema structure |
| 2330 | * |
| 2331 | * Deallocate a Schema structure. |
| 2332 | */ |
| 2333 | void |
| 2334 | xmlSchemaFree(xmlSchemaPtr schema) |
| 2335 | { |
| 2336 | if (schema == NULL) |
| 2337 | return; |
| 2338 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2339 | if (schema->notaDecl != NULL) |
| 2340 | xmlHashFree(schema->notaDecl, |
| 2341 | (xmlHashDeallocator) xmlSchemaFreeNotation); |
| 2342 | if (schema->attrDecl != NULL) |
| 2343 | xmlHashFree(schema->attrDecl, |
| 2344 | (xmlHashDeallocator) xmlSchemaFreeAttribute); |
| 2345 | if (schema->attrgrpDecl != NULL) |
| 2346 | xmlHashFree(schema->attrgrpDecl, |
| 2347 | (xmlHashDeallocator) xmlSchemaFreeAttributeGroup); |
| 2348 | if (schema->elemDecl != NULL) |
| 2349 | xmlHashFree(schema->elemDecl, |
| 2350 | (xmlHashDeallocator) xmlSchemaFreeElement); |
| 2351 | if (schema->typeDecl != NULL) |
| 2352 | xmlHashFree(schema->typeDecl, |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 2353 | (xmlHashDeallocator) xmlSchemaFreeTypeList); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 2354 | if (schema->groupDecl != NULL) |
| 2355 | xmlHashFree(schema->groupDecl, |
| 2356 | (xmlHashDeallocator) xmlSchemaFreeType); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 2357 | if (schema->schemasImports != NULL) |
| 2358 | xmlHashFree(schema->schemasImports, |
| 2359 | (xmlHashDeallocator) xmlSchemaFreeImport); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 2360 | if (schema->includes != NULL) { |
| 2361 | xmlSchemaFreeIncludeList((xmlSchemaIncludePtr) schema->includes); |
| 2362 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2363 | if (schema->annot != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2364 | xmlSchemaFreeAnnot(schema->annot); |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 2365 | if (schema->doc != NULL && !schema->preserve) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2366 | xmlFreeDoc(schema->doc); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 2367 | xmlDictFree(schema->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2368 | xmlFree(schema); |
| 2369 | } |
| 2370 | |
| 2371 | /************************************************************************ |
| 2372 | * * |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2373 | * Debug functions * |
| 2374 | * * |
| 2375 | ************************************************************************/ |
| 2376 | |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2377 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2378 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2379 | /** |
| 2380 | * xmlSchemaElementDump: |
| 2381 | * @elem: an element |
| 2382 | * @output: the file output |
| 2383 | * |
| 2384 | * Dump the element |
| 2385 | */ |
| 2386 | static void |
| 2387 | xmlSchemaElementDump(xmlSchemaElementPtr elem, FILE * output, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2388 | const xmlChar * name ATTRIBUTE_UNUSED, |
| 2389 | const xmlChar * context ATTRIBUTE_UNUSED, |
| 2390 | const xmlChar * namespace ATTRIBUTE_UNUSED) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2391 | { |
| 2392 | if (elem == NULL) |
| 2393 | return; |
| 2394 | |
| 2395 | fprintf(output, "Element "); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2396 | if (elem->flags & XML_SCHEMAS_ELEM_GLOBAL) |
| 2397 | fprintf(output, "global "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2398 | fprintf(output, ": %s ", elem->name); |
| 2399 | if (namespace != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2400 | fprintf(output, "namespace '%s' ", namespace); |
| 2401 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2402 | if (elem->flags & XML_SCHEMAS_ELEM_NILLABLE) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2403 | fprintf(output, "nillable "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2404 | if (elem->flags & XML_SCHEMAS_ELEM_DEFAULT) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2405 | fprintf(output, "default "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2406 | if (elem->flags & XML_SCHEMAS_ELEM_FIXED) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2407 | fprintf(output, "fixed "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2408 | if (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2409 | fprintf(output, "abstract "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2410 | if (elem->flags & XML_SCHEMAS_ELEM_REF) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2411 | fprintf(output, "ref '%s' ", elem->ref); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2412 | if (elem->id != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2413 | fprintf(output, "id '%s' ", elem->id); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2414 | fprintf(output, "\n"); |
| 2415 | if ((elem->minOccurs != 1) || (elem->maxOccurs != 1)) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2416 | fprintf(output, " "); |
| 2417 | if (elem->minOccurs != 1) |
| 2418 | fprintf(output, "min: %d ", elem->minOccurs); |
| 2419 | if (elem->maxOccurs >= UNBOUNDED) |
| 2420 | fprintf(output, "max: unbounded\n"); |
| 2421 | else if (elem->maxOccurs != 1) |
| 2422 | fprintf(output, "max: %d\n", elem->maxOccurs); |
| 2423 | else |
| 2424 | fprintf(output, "\n"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2425 | } |
| 2426 | if (elem->namedType != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2427 | fprintf(output, " type: %s", elem->namedType); |
| 2428 | if (elem->namedTypeNs != NULL) |
| 2429 | fprintf(output, " ns %s\n", elem->namedTypeNs); |
| 2430 | else |
| 2431 | fprintf(output, "\n"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2432 | } |
| 2433 | if (elem->substGroup != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2434 | fprintf(output, " substitutionGroup: %s", elem->substGroup); |
| 2435 | if (elem->substGroupNs != NULL) |
| 2436 | fprintf(output, " ns %s\n", elem->substGroupNs); |
| 2437 | else |
| 2438 | fprintf(output, "\n"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2439 | } |
| 2440 | if (elem->value != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2441 | fprintf(output, " default: %s", elem->value); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | /** |
| 2445 | * xmlSchemaAnnotDump: |
| 2446 | * @output: the file output |
| 2447 | * @annot: a annotation |
| 2448 | * |
| 2449 | * Dump the annotation |
| 2450 | */ |
| 2451 | static void |
| 2452 | xmlSchemaAnnotDump(FILE * output, xmlSchemaAnnotPtr annot) |
| 2453 | { |
| 2454 | xmlChar *content; |
| 2455 | |
| 2456 | if (annot == NULL) |
| 2457 | return; |
| 2458 | |
| 2459 | content = xmlNodeGetContent(annot->content); |
| 2460 | if (content != NULL) { |
| 2461 | fprintf(output, " Annot: %s\n", content); |
| 2462 | xmlFree(content); |
| 2463 | } else |
| 2464 | fprintf(output, " Annot: empty\n"); |
| 2465 | } |
| 2466 | |
| 2467 | /** |
| 2468 | * xmlSchemaTypeDump: |
| 2469 | * @output: the file output |
| 2470 | * @type: a type structure |
| 2471 | * |
| 2472 | * Dump a SchemaType structure |
| 2473 | */ |
| 2474 | static void |
| 2475 | xmlSchemaTypeDump(xmlSchemaTypePtr type, FILE * output) |
| 2476 | { |
| 2477 | if (type == NULL) { |
| 2478 | fprintf(output, "Type: NULL\n"); |
| 2479 | return; |
| 2480 | } |
| 2481 | fprintf(output, "Type: "); |
| 2482 | if (type->name != NULL) |
| 2483 | fprintf(output, "%s, ", type->name); |
| 2484 | else |
| 2485 | fprintf(output, "no name"); |
| 2486 | switch (type->type) { |
| 2487 | case XML_SCHEMA_TYPE_BASIC: |
| 2488 | fprintf(output, "basic "); |
| 2489 | break; |
| 2490 | case XML_SCHEMA_TYPE_SIMPLE: |
| 2491 | fprintf(output, "simple "); |
| 2492 | break; |
| 2493 | case XML_SCHEMA_TYPE_COMPLEX: |
| 2494 | fprintf(output, "complex "); |
| 2495 | break; |
| 2496 | case XML_SCHEMA_TYPE_SEQUENCE: |
| 2497 | fprintf(output, "sequence "); |
| 2498 | break; |
| 2499 | case XML_SCHEMA_TYPE_CHOICE: |
| 2500 | fprintf(output, "choice "); |
| 2501 | break; |
| 2502 | case XML_SCHEMA_TYPE_ALL: |
| 2503 | fprintf(output, "all "); |
| 2504 | break; |
| 2505 | case XML_SCHEMA_TYPE_UR: |
| 2506 | fprintf(output, "ur "); |
| 2507 | break; |
| 2508 | case XML_SCHEMA_TYPE_RESTRICTION: |
| 2509 | fprintf(output, "restriction "); |
| 2510 | break; |
| 2511 | case XML_SCHEMA_TYPE_EXTENSION: |
| 2512 | fprintf(output, "extension "); |
| 2513 | break; |
| 2514 | default: |
| 2515 | fprintf(output, "unknowntype%d ", type->type); |
| 2516 | break; |
| 2517 | } |
| 2518 | if (type->base != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2519 | fprintf(output, "base %s, ", type->base); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2520 | } |
| 2521 | switch (type->contentType) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2522 | case XML_SCHEMA_CONTENT_UNKNOWN: |
| 2523 | fprintf(output, "unknown "); |
| 2524 | break; |
| 2525 | case XML_SCHEMA_CONTENT_EMPTY: |
| 2526 | fprintf(output, "empty "); |
| 2527 | break; |
| 2528 | case XML_SCHEMA_CONTENT_ELEMENTS: |
| 2529 | fprintf(output, "element "); |
| 2530 | break; |
| 2531 | case XML_SCHEMA_CONTENT_MIXED: |
| 2532 | fprintf(output, "mixed "); |
| 2533 | break; |
| 2534 | case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS: |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 2535 | /* not used. */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2536 | break; |
| 2537 | case XML_SCHEMA_CONTENT_BASIC: |
| 2538 | fprintf(output, "basic "); |
| 2539 | break; |
| 2540 | case XML_SCHEMA_CONTENT_SIMPLE: |
| 2541 | fprintf(output, "simple "); |
| 2542 | break; |
| 2543 | case XML_SCHEMA_CONTENT_ANY: |
| 2544 | fprintf(output, "any "); |
| 2545 | break; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2546 | } |
| 2547 | fprintf(output, "\n"); |
| 2548 | if ((type->minOccurs != 1) || (type->maxOccurs != 1)) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2549 | fprintf(output, " "); |
| 2550 | if (type->minOccurs != 1) |
| 2551 | fprintf(output, "min: %d ", type->minOccurs); |
| 2552 | if (type->maxOccurs >= UNBOUNDED) |
| 2553 | fprintf(output, "max: unbounded\n"); |
| 2554 | else if (type->maxOccurs != 1) |
| 2555 | fprintf(output, "max: %d\n", type->maxOccurs); |
| 2556 | else |
| 2557 | fprintf(output, "\n"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2558 | } |
| 2559 | if (type->annot != NULL) |
| 2560 | xmlSchemaAnnotDump(output, type->annot); |
| 2561 | if (type->subtypes != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2562 | xmlSchemaTypePtr sub = type->subtypes; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2563 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2564 | fprintf(output, " subtypes: "); |
| 2565 | while (sub != NULL) { |
| 2566 | fprintf(output, "%s ", sub->name); |
| 2567 | sub = sub->next; |
| 2568 | } |
| 2569 | fprintf(output, "\n"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | } |
| 2573 | |
| 2574 | /** |
| 2575 | * xmlSchemaDump: |
| 2576 | * @output: the file output |
| 2577 | * @schema: a schema structure |
| 2578 | * |
| 2579 | * Dump a Schema structure. |
| 2580 | */ |
| 2581 | void |
| 2582 | xmlSchemaDump(FILE * output, xmlSchemaPtr schema) |
| 2583 | { |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 2584 | if (output == NULL) |
| 2585 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2586 | if (schema == NULL) { |
| 2587 | fprintf(output, "Schemas: NULL\n"); |
| 2588 | return; |
| 2589 | } |
| 2590 | fprintf(output, "Schemas: "); |
| 2591 | if (schema->name != NULL) |
| 2592 | fprintf(output, "%s, ", schema->name); |
| 2593 | else |
| 2594 | fprintf(output, "no name, "); |
| 2595 | if (schema->targetNamespace != NULL) |
Daniel Veillard | 580ced8 | 2003-03-21 21:22:48 +0000 | [diff] [blame] | 2596 | fprintf(output, "%s", (const char *) schema->targetNamespace); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2597 | else |
| 2598 | fprintf(output, "no target namespace"); |
| 2599 | fprintf(output, "\n"); |
| 2600 | if (schema->annot != NULL) |
| 2601 | xmlSchemaAnnotDump(output, schema->annot); |
| 2602 | |
| 2603 | xmlHashScan(schema->typeDecl, (xmlHashScanner) xmlSchemaTypeDump, |
| 2604 | output); |
| 2605 | xmlHashScanFull(schema->elemDecl, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2606 | (xmlHashScannerFull) xmlSchemaElementDump, output); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2607 | } |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2608 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2609 | |
| 2610 | /************************************************************************ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2611 | * * |
| 2612 | * Utilities * |
| 2613 | * * |
| 2614 | ************************************************************************/ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2615 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2616 | /** |
| 2617 | * xmlSchemaGetPropNode: |
| 2618 | * @node: the element node |
| 2619 | * @name: the name of the attribute |
| 2620 | * |
| 2621 | * Seeks an attribute with a name of @name in |
| 2622 | * no namespace. |
| 2623 | * |
| 2624 | * Returns the attribute or NULL if not present. |
| 2625 | */ |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 2626 | static xmlAttrPtr |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2627 | xmlSchemaGetPropNode(xmlNodePtr node, const char *name) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2628 | { |
| 2629 | xmlAttrPtr prop; |
| 2630 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2631 | if ((node == NULL) || (name == NULL)) |
| 2632 | return(NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2633 | prop = node->properties; |
| 2634 | while (prop != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2635 | if ((prop->ns == NULL) && xmlStrEqual(prop->name, BAD_CAST name)) |
| 2636 | return(prop); |
| 2637 | prop = prop->next; |
| 2638 | } |
| 2639 | return (NULL); |
| 2640 | } |
| 2641 | |
| 2642 | /** |
| 2643 | * xmlSchemaGetPropNodeNs: |
| 2644 | * @node: the element node |
| 2645 | * @uri: the uri |
| 2646 | * @name: the name of the attribute |
| 2647 | * |
| 2648 | * Seeks an attribute with a local name of @name and |
| 2649 | * a namespace URI of @uri. |
| 2650 | * |
| 2651 | * Returns the attribute or NULL if not present. |
| 2652 | */ |
| 2653 | static xmlAttrPtr |
| 2654 | xmlSchemaGetPropNodeNs(xmlNodePtr node, const char *uri, const char *name) |
| 2655 | { |
| 2656 | xmlAttrPtr prop; |
| 2657 | |
| 2658 | if ((node == NULL) || (name == NULL)) |
| 2659 | return(NULL); |
| 2660 | prop = node->properties; |
| 2661 | while (prop != NULL) { |
| 2662 | if ((prop->ns != NULL) && |
| 2663 | xmlStrEqual(prop->name, BAD_CAST name) && |
| 2664 | xmlStrEqual(prop->ns->href, BAD_CAST uri)) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2665 | return(prop); |
| 2666 | prop = prop->next; |
| 2667 | } |
| 2668 | return (NULL); |
| 2669 | } |
| 2670 | |
| 2671 | static const xmlChar * |
| 2672 | xmlSchemaGetNodeContent(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node) |
| 2673 | { |
| 2674 | xmlChar *val; |
| 2675 | const xmlChar *ret; |
| 2676 | |
| 2677 | val = xmlNodeGetContent(node); |
| 2678 | if (val == NULL) |
| 2679 | return(NULL); |
| 2680 | ret = xmlDictLookup(ctxt->dict, val, -1); |
| 2681 | xmlFree(val); |
| 2682 | return(ret); |
| 2683 | } |
| 2684 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2685 | /** |
| 2686 | * xmlSchemaGetProp: |
| 2687 | * @ctxt: the parser context |
| 2688 | * @node: the node |
| 2689 | * @name: the property name |
| 2690 | * |
| 2691 | * Read a attribute value and internalize the string |
| 2692 | * |
| 2693 | * Returns the string or NULL if not present. |
| 2694 | */ |
| 2695 | static const xmlChar * |
| 2696 | xmlSchemaGetProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
| 2697 | const char *name) |
| 2698 | { |
| 2699 | xmlChar *val; |
| 2700 | const xmlChar *ret; |
| 2701 | |
| 2702 | val = xmlGetProp(node, BAD_CAST name); |
| 2703 | if (val == NULL) |
| 2704 | return(NULL); |
| 2705 | ret = xmlDictLookup(ctxt->dict, val, -1); |
| 2706 | xmlFree(val); |
| 2707 | return(ret); |
| 2708 | } |
| 2709 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2710 | /************************************************************************ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2711 | * * |
| 2712 | * Parsing functions * |
| 2713 | * * |
| 2714 | ************************************************************************/ |
| 2715 | |
| 2716 | /** |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2717 | * xmlSchemaGetElem: |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2718 | * @schema: the schema context |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2719 | * @name: the element name |
| 2720 | * @ns: the element namespace |
| 2721 | * |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2722 | * Lookup a global element declaration in the schema. |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2723 | * |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2724 | * Returns the element declaration or NULL if not found. |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2725 | */ |
| 2726 | static xmlSchemaElementPtr |
| 2727 | xmlSchemaGetElem(xmlSchemaPtr schema, const xmlChar * name, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2728 | const xmlChar * namespace) |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2729 | { |
| 2730 | xmlSchemaElementPtr ret; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2731 | |
| 2732 | if ((name == NULL) || (schema == NULL)) |
| 2733 | return (NULL); |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2734 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2735 | ret = xmlHashLookup2(schema->elemDecl, name, namespace); |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 2736 | if ((ret != NULL) && |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2737 | (ret->flags & XML_SCHEMAS_ELEM_GLOBAL)) { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2738 | return (ret); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2739 | } else |
| 2740 | ret = NULL; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 2741 | /* |
| 2742 | * This one was removed, since top level element declarations have |
| 2743 | * the target namespace specified in targetNamespace of the <schema> |
| 2744 | * information element, even if elementFormDefault is "unqualified". |
| 2745 | */ |
| 2746 | |
| 2747 | /* else if ((schema->flags & XML_SCHEMAS_QUALIF_ELEM) == 0) { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2748 | if (xmlStrEqual(namespace, schema->targetNamespace)) |
| 2749 | ret = xmlHashLookup2(schema->elemDecl, name, NULL); |
| 2750 | else |
| 2751 | ret = xmlHashLookup2(schema->elemDecl, name, namespace); |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 2752 | if ((ret != NULL) && |
| 2753 | ((level == 0) || (ret->flags & XML_SCHEMAS_ELEM_TOPLEVEL))) { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2754 | return (ret); |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 2755 | } |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 2756 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2757 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2758 | /* |
| 2759 | * Removed since imported components will be hold by the main schema only. |
| 2760 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2761 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2762 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2763 | else |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2764 | import = xmlHashLookup(schema->schemasImports, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2765 | if (import != NULL) { |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 2766 | ret = xmlSchemaGetElem(import->schema, name, namespace, level + 1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2767 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ELEM_GLOBAL)) { |
| 2768 | return (ret); |
| 2769 | } else |
| 2770 | ret = NULL; |
| 2771 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2772 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2773 | #ifdef DEBUG |
| 2774 | if (ret == NULL) { |
| 2775 | if (namespace == NULL) |
| 2776 | fprintf(stderr, "Unable to lookup type %s", name); |
| 2777 | else |
| 2778 | fprintf(stderr, "Unable to lookup type %s:%s", name, |
| 2779 | namespace); |
| 2780 | } |
| 2781 | #endif |
| 2782 | return (ret); |
| 2783 | } |
| 2784 | |
| 2785 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2786 | * xmlSchemaGetType: |
| 2787 | * @schema: the schemas context |
| 2788 | * @name: the type name |
| 2789 | * @ns: the type namespace |
| 2790 | * |
| 2791 | * Lookup a type in the schemas or the predefined types |
| 2792 | * |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 2793 | * Returns the group definition or NULL if not found. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2794 | */ |
| 2795 | static xmlSchemaTypePtr |
| 2796 | xmlSchemaGetType(xmlSchemaPtr schema, const xmlChar * name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2797 | const xmlChar * namespace) |
| 2798 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2799 | xmlSchemaTypePtr ret; |
| 2800 | |
| 2801 | if (name == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2802 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2803 | if (schema != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2804 | ret = xmlHashLookup2(schema->typeDecl, name, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2805 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_TYPE_GLOBAL)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2806 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2807 | } |
| 2808 | ret = xmlSchemaGetPredefinedType(name, namespace); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 2809 | if (ret != NULL) |
| 2810 | return (ret); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2811 | /* |
| 2812 | * Removed, since the imported components will be grafted on the |
| 2813 | * main schema only. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2814 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2815 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2816 | else |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 2817 | import = xmlHashLookup(schema->schemasImports, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2818 | if (import != NULL) { |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 2819 | ret = xmlSchemaGetType(import->schema, name, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2820 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_TYPE_GLOBAL)) { |
| 2821 | return (ret); |
| 2822 | } else |
| 2823 | ret = NULL; |
| 2824 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2825 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2826 | #ifdef DEBUG |
| 2827 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2828 | if (namespace == NULL) |
| 2829 | fprintf(stderr, "Unable to lookup type %s", name); |
| 2830 | else |
| 2831 | fprintf(stderr, "Unable to lookup type %s:%s", name, |
| 2832 | namespace); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2833 | } |
| 2834 | #endif |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2835 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2836 | } |
| 2837 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2838 | /** |
| 2839 | * xmlSchemaGetAttribute: |
| 2840 | * @schema: the context of the schema |
| 2841 | * @name: the name of the attribute |
| 2842 | * @ns: the target namespace of the attribute |
| 2843 | * |
| 2844 | * Lookup a an attribute in the schema or imported schemas |
| 2845 | * |
| 2846 | * Returns the attribute declaration or NULL if not found. |
| 2847 | */ |
| 2848 | static xmlSchemaAttributePtr |
| 2849 | xmlSchemaGetAttribute(xmlSchemaPtr schema, const xmlChar * name, |
| 2850 | const xmlChar * namespace) |
| 2851 | { |
| 2852 | xmlSchemaAttributePtr ret; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2853 | |
| 2854 | if ((name == NULL) || (schema == NULL)) |
| 2855 | return (NULL); |
| 2856 | |
| 2857 | |
| 2858 | ret = xmlHashLookup2(schema->attrDecl, name, namespace); |
| 2859 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ATTR_GLOBAL)) |
| 2860 | return (ret); |
| 2861 | else |
| 2862 | ret = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2863 | /* |
| 2864 | * Removed, since imported components will be hold by the main schema only. |
| 2865 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2866 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2867 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2868 | else |
| 2869 | import = xmlHashLookup(schema->schemasImports, namespace); |
| 2870 | if (import != NULL) { |
| 2871 | ret = xmlSchemaGetAttribute(import->schema, name, namespace); |
| 2872 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ATTR_GLOBAL)) { |
| 2873 | return (ret); |
| 2874 | } else |
| 2875 | ret = NULL; |
| 2876 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2877 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2878 | #ifdef DEBUG |
| 2879 | if (ret == NULL) { |
| 2880 | if (namespace == NULL) |
| 2881 | fprintf(stderr, "Unable to lookup attribute %s", name); |
| 2882 | else |
| 2883 | fprintf(stderr, "Unable to lookup attribute %s:%s", name, |
| 2884 | namespace); |
| 2885 | } |
| 2886 | #endif |
| 2887 | return (ret); |
| 2888 | } |
| 2889 | |
| 2890 | /** |
| 2891 | * xmlSchemaGetAttributeGroup: |
| 2892 | * @schema: the context of the schema |
| 2893 | * @name: the name of the attribute group |
| 2894 | * @ns: the target namespace of the attribute group |
| 2895 | * |
| 2896 | * Lookup a an attribute group in the schema or imported schemas |
| 2897 | * |
| 2898 | * Returns the attribute group definition or NULL if not found. |
| 2899 | */ |
| 2900 | static xmlSchemaAttributeGroupPtr |
| 2901 | xmlSchemaGetAttributeGroup(xmlSchemaPtr schema, const xmlChar * name, |
| 2902 | const xmlChar * namespace) |
| 2903 | { |
| 2904 | xmlSchemaAttributeGroupPtr ret; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2905 | |
| 2906 | if ((name == NULL) || (schema == NULL)) |
| 2907 | return (NULL); |
| 2908 | |
| 2909 | |
| 2910 | ret = xmlHashLookup2(schema->attrgrpDecl, name, namespace); |
| 2911 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ATTRGROUP_GLOBAL)) |
| 2912 | return (ret); |
| 2913 | else |
| 2914 | ret = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2915 | /* |
| 2916 | * Removed since imported components will be hold by the main schema only. |
| 2917 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2918 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2919 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2920 | else |
| 2921 | import = xmlHashLookup(schema->schemasImports, namespace); |
| 2922 | if (import != NULL) { |
| 2923 | ret = xmlSchemaGetAttributeGroup(import->schema, name, namespace); |
| 2924 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ATTRGROUP_GLOBAL)) |
| 2925 | return (ret); |
| 2926 | else |
| 2927 | ret = NULL; |
| 2928 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2929 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2930 | #ifdef DEBUG |
| 2931 | if (ret == NULL) { |
| 2932 | if (namespace == NULL) |
| 2933 | fprintf(stderr, "Unable to lookup attribute group %s", name); |
| 2934 | else |
| 2935 | fprintf(stderr, "Unable to lookup attribute group %s:%s", name, |
| 2936 | namespace); |
| 2937 | } |
| 2938 | #endif |
| 2939 | return (ret); |
| 2940 | } |
| 2941 | |
| 2942 | /** |
| 2943 | * xmlSchemaGetGroup: |
| 2944 | * @schema: the context of the schema |
| 2945 | * @name: the name of the group |
| 2946 | * @ns: the target namespace of the group |
| 2947 | * |
| 2948 | * Lookup a group in the schema or imported schemas |
| 2949 | * |
| 2950 | * Returns the group definition or NULL if not found. |
| 2951 | */ |
| 2952 | static xmlSchemaTypePtr |
| 2953 | xmlSchemaGetGroup(xmlSchemaPtr schema, const xmlChar * name, |
| 2954 | const xmlChar * namespace) |
| 2955 | { |
| 2956 | xmlSchemaTypePtr ret; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2957 | |
| 2958 | if ((name == NULL) || (schema == NULL)) |
| 2959 | return (NULL); |
| 2960 | |
| 2961 | |
| 2962 | ret = xmlHashLookup2(schema->groupDecl, name, namespace); |
| 2963 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_TYPE_GLOBAL)) |
| 2964 | return (ret); |
| 2965 | else |
| 2966 | ret = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2967 | /* |
| 2968 | * Removed since imported components will be hold by the main schema only. |
| 2969 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2970 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2971 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2972 | else |
| 2973 | import = xmlHashLookup(schema->schemasImports, namespace); |
| 2974 | if (import != NULL) { |
| 2975 | ret = xmlSchemaGetGroup(import->schema, name, namespace); |
| 2976 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_TYPE_GLOBAL)) |
| 2977 | return (ret); |
| 2978 | else |
| 2979 | ret = NULL; |
| 2980 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2981 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2982 | #ifdef DEBUG |
| 2983 | if (ret == NULL) { |
| 2984 | if (namespace == NULL) |
| 2985 | fprintf(stderr, "Unable to lookup group %s", name); |
| 2986 | else |
| 2987 | fprintf(stderr, "Unable to lookup group %s:%s", name, |
| 2988 | namespace); |
| 2989 | } |
| 2990 | #endif |
| 2991 | return (ret); |
| 2992 | } |
| 2993 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2994 | /************************************************************************ |
| 2995 | * * |
| 2996 | * Parsing functions * |
| 2997 | * * |
| 2998 | ************************************************************************/ |
| 2999 | |
| 3000 | #define IS_BLANK_NODE(n) \ |
| 3001 | (((n)->type == XML_TEXT_NODE) && (xmlSchemaIsBlank((n)->content))) |
| 3002 | |
| 3003 | /** |
| 3004 | * xmlSchemaIsBlank: |
| 3005 | * @str: a string |
| 3006 | * |
| 3007 | * Check if a string is ignorable |
| 3008 | * |
| 3009 | * Returns 1 if the string is NULL or made of blanks chars, 0 otherwise |
| 3010 | */ |
| 3011 | static int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3012 | xmlSchemaIsBlank(xmlChar * str) |
| 3013 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3014 | if (str == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3015 | return (1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3016 | while (*str != 0) { |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3017 | if (!(IS_BLANK_CH(*str))) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3018 | return (0); |
| 3019 | str++; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3020 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3021 | return (1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3022 | } |
| 3023 | |
| 3024 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3025 | * xmlSchemaAddAssembledItem: |
| 3026 | * @ctxt: a schema parser context |
| 3027 | * @schema: the schema being built |
| 3028 | * @item: the item |
| 3029 | * |
| 3030 | * Add a item to the schema's list of current items. |
| 3031 | * This is used if the schema was already constructed and |
| 3032 | * new schemata need to be added to it. |
| 3033 | * *WARNING* this interface is highly subject to change. |
| 3034 | * |
| 3035 | * Returns 0 if suceeds and -1 if an internal error occurs. |
| 3036 | */ |
| 3037 | static int |
| 3038 | xmlSchemaAddAssembledItem(xmlSchemaParserCtxtPtr ctxt, |
| 3039 | xmlSchemaTypePtr item) |
| 3040 | { |
| 3041 | static int growSize = 100; |
| 3042 | xmlSchemaAssemblePtr ass; |
| 3043 | |
| 3044 | ass = ctxt->assemble; |
| 3045 | if (ass->sizeItems < 0) { |
| 3046 | /* If disabled. */ |
| 3047 | return (0); |
| 3048 | } |
| 3049 | if (ass->sizeItems <= 0) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 3050 | ass->items = (void **) xmlMalloc(growSize * sizeof(xmlSchemaTypePtr)); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3051 | if (ass->items == NULL) { |
| 3052 | xmlSchemaPErrMemory(ctxt, |
| 3053 | "allocating new item buffer", NULL); |
| 3054 | return (-1); |
| 3055 | } |
| 3056 | ass->sizeItems = growSize; |
| 3057 | } else if (ass->sizeItems <= ass->nbItems) { |
| 3058 | ass->sizeItems *= 2; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 3059 | ass->items = (void **) xmlRealloc(ass->items, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3060 | ass->sizeItems * sizeof(xmlSchemaTypePtr)); |
| 3061 | if (ass->items == NULL) { |
| 3062 | xmlSchemaPErrMemory(ctxt, |
| 3063 | "growing item buffer", NULL); |
| 3064 | ass->sizeItems = 0; |
| 3065 | return (-1); |
| 3066 | } |
| 3067 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 3068 | /* ass->items[ass->nbItems++] = (void *) item; */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3069 | ((xmlSchemaTypePtr *) ass->items)[ass->nbItems++] = (void *) item; |
| 3070 | return (0); |
| 3071 | } |
| 3072 | |
| 3073 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3074 | * xmlSchemaAddNotation: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3075 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3076 | * @schema: the schema being built |
| 3077 | * @name: the item name |
| 3078 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3079 | * Add an XML schema annotation declaration |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3080 | * *WARNING* this interface is highly subject to change |
| 3081 | * |
| 3082 | * Returns the new struture or NULL in case of error |
| 3083 | */ |
| 3084 | static xmlSchemaNotationPtr |
| 3085 | xmlSchemaAddNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3086 | const xmlChar * name) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3087 | { |
| 3088 | xmlSchemaNotationPtr ret = NULL; |
| 3089 | int val; |
| 3090 | |
| 3091 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3092 | return (NULL); |
| 3093 | |
| 3094 | if (schema->notaDecl == NULL) |
| 3095 | schema->notaDecl = xmlHashCreate(10); |
| 3096 | if (schema->notaDecl == NULL) |
| 3097 | return (NULL); |
| 3098 | |
| 3099 | ret = (xmlSchemaNotationPtr) xmlMalloc(sizeof(xmlSchemaNotation)); |
| 3100 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3101 | xmlSchemaPErrMemory(ctxt, "add annotation", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3102 | return (NULL); |
| 3103 | } |
| 3104 | memset(ret, 0, sizeof(xmlSchemaNotation)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3105 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3106 | val = xmlHashAddEntry2(schema->notaDecl, name, schema->targetNamespace, |
| 3107 | ret); |
| 3108 | if (val != 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3109 | /* |
| 3110 | * TODO: This should never happen, since a unique name will be computed. |
| 3111 | * If it fails, then an other internal error must have occured. |
| 3112 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3113 | xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc, |
| 3114 | XML_SCHEMAP_REDEFINED_NOTATION, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3115 | "Annotation declaration '%s' is already declared.\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3116 | name, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3117 | xmlFree(ret); |
| 3118 | return (NULL); |
| 3119 | } |
| 3120 | return (ret); |
| 3121 | } |
| 3122 | |
| 3123 | |
| 3124 | /** |
| 3125 | * xmlSchemaAddAttribute: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3126 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3127 | * @schema: the schema being built |
| 3128 | * @name: the item name |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3129 | * @namespace: the namespace |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3130 | * |
| 3131 | * Add an XML schema Attrribute declaration |
| 3132 | * *WARNING* this interface is highly subject to change |
| 3133 | * |
| 3134 | * Returns the new struture or NULL in case of error |
| 3135 | */ |
| 3136 | static xmlSchemaAttributePtr |
| 3137 | xmlSchemaAddAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3138 | const xmlChar * name, const xmlChar * namespace, |
| 3139 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3140 | { |
| 3141 | xmlSchemaAttributePtr ret = NULL; |
| 3142 | int val; |
| 3143 | |
| 3144 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3145 | return (NULL); |
| 3146 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3147 | #ifdef DEBUG |
| 3148 | fprintf(stderr, "Adding attribute %s\n", name); |
| 3149 | if (namespace != NULL) |
| 3150 | fprintf(stderr, " target namespace %s\n", namespace); |
| 3151 | #endif |
| 3152 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3153 | if (schema->attrDecl == NULL) |
| 3154 | schema->attrDecl = xmlHashCreate(10); |
| 3155 | if (schema->attrDecl == NULL) |
| 3156 | return (NULL); |
| 3157 | |
| 3158 | ret = (xmlSchemaAttributePtr) xmlMalloc(sizeof(xmlSchemaAttribute)); |
| 3159 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3160 | xmlSchemaPErrMemory(ctxt, "allocating attribute", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3161 | return (NULL); |
| 3162 | } |
| 3163 | memset(ret, 0, sizeof(xmlSchemaAttribute)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3164 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
| 3165 | ret->targetNamespace = xmlDictLookup(ctxt->dict, namespace, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3166 | val = xmlHashAddEntry3(schema->attrDecl, name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3167 | schema->targetNamespace, ctxt->container, ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3168 | if (val != 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3169 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3170 | XML_SCHEMAP_REDEFINED_ATTR, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3171 | NULL, NULL, node, |
| 3172 | "A global attribute declaration with the name '%s' does already exist", name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3173 | xmlFree(ret); |
| 3174 | return (NULL); |
| 3175 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3176 | if (ctxt->assemble != NULL) |
| 3177 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3178 | return (ret); |
| 3179 | } |
| 3180 | |
| 3181 | /** |
| 3182 | * xmlSchemaAddAttributeGroup: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3183 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3184 | * @schema: the schema being built |
| 3185 | * @name: the item name |
| 3186 | * |
| 3187 | * Add an XML schema Attrribute Group declaration |
| 3188 | * |
| 3189 | * Returns the new struture or NULL in case of error |
| 3190 | */ |
| 3191 | static xmlSchemaAttributeGroupPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3192 | xmlSchemaAddAttributeGroup(xmlSchemaParserCtxtPtr ctxt, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3193 | xmlSchemaPtr schema, const xmlChar * name, |
| 3194 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3195 | { |
| 3196 | xmlSchemaAttributeGroupPtr ret = NULL; |
| 3197 | int val; |
| 3198 | |
| 3199 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3200 | return (NULL); |
| 3201 | |
| 3202 | if (schema->attrgrpDecl == NULL) |
| 3203 | schema->attrgrpDecl = xmlHashCreate(10); |
| 3204 | if (schema->attrgrpDecl == NULL) |
| 3205 | return (NULL); |
| 3206 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3207 | ret = |
| 3208 | (xmlSchemaAttributeGroupPtr) |
| 3209 | xmlMalloc(sizeof(xmlSchemaAttributeGroup)); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3210 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3211 | xmlSchemaPErrMemory(ctxt, "allocating attribute group", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3212 | return (NULL); |
| 3213 | } |
| 3214 | memset(ret, 0, sizeof(xmlSchemaAttributeGroup)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3215 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3216 | val = xmlHashAddEntry3(schema->attrgrpDecl, name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3217 | schema->targetNamespace, ctxt->container, ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3218 | if (val != 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3219 | xmlSchemaPCustomErr(ctxt, |
| 3220 | XML_SCHEMAP_REDEFINED_ATTRGROUP, |
| 3221 | NULL, NULL, node, |
| 3222 | "A global attribute group definition with the name '%s' does already exist", name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3223 | xmlFree(ret); |
| 3224 | return (NULL); |
| 3225 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3226 | if (ctxt->assemble != NULL) |
| 3227 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3228 | return (ret); |
| 3229 | } |
| 3230 | |
| 3231 | /** |
| 3232 | * xmlSchemaAddElement: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3233 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3234 | * @schema: the schema being built |
| 3235 | * @name: the type name |
| 3236 | * @namespace: the type namespace |
| 3237 | * |
| 3238 | * Add an XML schema Element declaration |
| 3239 | * *WARNING* this interface is highly subject to change |
| 3240 | * |
| 3241 | * Returns the new struture or NULL in case of error |
| 3242 | */ |
| 3243 | static xmlSchemaElementPtr |
| 3244 | xmlSchemaAddElement(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3245 | const xmlChar * name, const xmlChar * namespace, |
| 3246 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3247 | { |
| 3248 | xmlSchemaElementPtr ret = NULL; |
| 3249 | int val; |
| 3250 | |
| 3251 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3252 | return (NULL); |
| 3253 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3254 | #ifdef DEBUG |
| 3255 | fprintf(stderr, "Adding element %s\n", name); |
| 3256 | if (namespace != NULL) |
| 3257 | fprintf(stderr, " target namespace %s\n", namespace); |
| 3258 | #endif |
| 3259 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3260 | if (schema->elemDecl == NULL) |
| 3261 | schema->elemDecl = xmlHashCreate(10); |
| 3262 | if (schema->elemDecl == NULL) |
| 3263 | return (NULL); |
| 3264 | |
| 3265 | ret = (xmlSchemaElementPtr) xmlMalloc(sizeof(xmlSchemaElement)); |
| 3266 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3267 | xmlSchemaPErrMemory(ctxt, "allocating element", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3268 | return (NULL); |
| 3269 | } |
| 3270 | memset(ret, 0, sizeof(xmlSchemaElement)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3271 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
| 3272 | ret->targetNamespace = xmlDictLookup(ctxt->dict, namespace, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3273 | val = xmlHashAddEntry3(schema->elemDecl, name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3274 | namespace, ctxt->container, ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3275 | if (val != 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3276 | if (topLevel) { |
| 3277 | xmlSchemaPCustomErr(ctxt, |
| 3278 | XML_SCHEMAP_REDEFINED_ELEMENT, |
| 3279 | NULL, NULL, node, |
| 3280 | "A global element declaration with the name '%s' does " |
| 3281 | "already exist", name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3282 | xmlFree(ret); |
| 3283 | return (NULL); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3284 | } else { |
| 3285 | char buf[30]; |
| 3286 | |
| 3287 | snprintf(buf, 29, "#eCont %d", ctxt->counter++ + 1); |
| 3288 | val = xmlHashAddEntry3(schema->elemDecl, name, (xmlChar *) buf, |
| 3289 | namespace, ret); |
| 3290 | if (val != 0) { |
| 3291 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3292 | XML_SCHEMAP_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3293 | NULL, NULL, node, |
| 3294 | "Internal error: xmlSchemaAddElement, " |
| 3295 | "a dublicate element declaration with the name '%s' " |
| 3296 | "could not be added to the hash.", name); |
| 3297 | xmlFree(ret); |
| 3298 | return (NULL); |
| 3299 | } |
| 3300 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3301 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3302 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3303 | if (ctxt->assemble != NULL) |
| 3304 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3305 | return (ret); |
| 3306 | } |
| 3307 | |
| 3308 | /** |
| 3309 | * xmlSchemaAddType: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3310 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3311 | * @schema: the schema being built |
| 3312 | * @name: the item name |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3313 | * @namespace: the namespace |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3314 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3315 | * Add an XML schema item |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3316 | * *WARNING* this interface is highly subject to change |
| 3317 | * |
| 3318 | * Returns the new struture or NULL in case of error |
| 3319 | */ |
| 3320 | static xmlSchemaTypePtr |
| 3321 | xmlSchemaAddType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3322 | const xmlChar * name, const xmlChar * namespace, |
| 3323 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3324 | { |
| 3325 | xmlSchemaTypePtr ret = NULL; |
| 3326 | int val; |
| 3327 | |
| 3328 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3329 | return (NULL); |
| 3330 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3331 | #ifdef DEBUG |
| 3332 | fprintf(stderr, "Adding type %s\n", name); |
| 3333 | if (namespace != NULL) |
| 3334 | fprintf(stderr, " target namespace %s\n", namespace); |
| 3335 | #endif |
| 3336 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3337 | if (schema->typeDecl == NULL) |
| 3338 | schema->typeDecl = xmlHashCreate(10); |
| 3339 | if (schema->typeDecl == NULL) |
| 3340 | return (NULL); |
| 3341 | |
| 3342 | ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType)); |
| 3343 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3344 | xmlSchemaPErrMemory(ctxt, "allocating type", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3345 | return (NULL); |
| 3346 | } |
| 3347 | memset(ret, 0, sizeof(xmlSchemaType)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3348 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 3349 | ret->redef = NULL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3350 | val = xmlHashAddEntry2(schema->typeDecl, name, namespace, ret); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3351 | if (val != 0) { |
| 3352 | if (ctxt->includes == 0) { |
| 3353 | xmlSchemaPCustomErr(ctxt, |
| 3354 | XML_SCHEMAP_REDEFINED_TYPE, |
| 3355 | NULL, NULL, node, |
| 3356 | "A global type definition with the name '%s' does already exist", name); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 3357 | xmlFree(ret); |
| 3358 | return (NULL); |
| 3359 | } else { |
| 3360 | xmlSchemaTypePtr prev; |
| 3361 | |
| 3362 | prev = xmlHashLookup2(schema->typeDecl, name, namespace); |
| 3363 | if (prev == NULL) { |
| 3364 | xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3365 | XML_ERR_INTERNAL_ERROR, |
| 3366 | "Internal error: xmlSchemaAddType, on type " |
| 3367 | "'%s'.\n", |
| 3368 | name, NULL); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 3369 | xmlFree(ret); |
| 3370 | return (NULL); |
| 3371 | } |
| 3372 | ret->redef = prev->redef; |
| 3373 | prev->redef = ret; |
| 3374 | } |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 3375 | } |
| 3376 | ret->minOccurs = 1; |
| 3377 | ret->maxOccurs = 1; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3378 | ret->attributeUses = NULL; |
| 3379 | ret->attributeWildcard = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3380 | if (ctxt->assemble != NULL) |
| 3381 | xmlSchemaAddAssembledItem(ctxt,ret); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 3382 | return (ret); |
| 3383 | } |
| 3384 | |
| 3385 | /** |
| 3386 | * xmlSchemaAddGroup: |
| 3387 | * @ctxt: a schema validation context |
| 3388 | * @schema: the schema being built |
| 3389 | * @name: the group name |
| 3390 | * |
| 3391 | * Add an XML schema Group definition |
| 3392 | * |
| 3393 | * Returns the new struture or NULL in case of error |
| 3394 | */ |
| 3395 | static xmlSchemaTypePtr |
| 3396 | xmlSchemaAddGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3397 | const xmlChar * name, xmlNodePtr node) |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 3398 | { |
| 3399 | xmlSchemaTypePtr ret = NULL; |
| 3400 | int val; |
| 3401 | |
| 3402 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3403 | return (NULL); |
| 3404 | |
| 3405 | if (schema->groupDecl == NULL) |
| 3406 | schema->groupDecl = xmlHashCreate(10); |
| 3407 | if (schema->groupDecl == NULL) |
| 3408 | return (NULL); |
| 3409 | |
| 3410 | ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType)); |
| 3411 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3412 | xmlSchemaPErrMemory(ctxt, "adding group", NULL); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 3413 | return (NULL); |
| 3414 | } |
| 3415 | memset(ret, 0, sizeof(xmlSchemaType)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3416 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3417 | val = |
| 3418 | xmlHashAddEntry2(schema->groupDecl, name, schema->targetNamespace, |
| 3419 | ret); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 3420 | if (val != 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3421 | xmlSchemaPCustomErr(ctxt, |
| 3422 | XML_SCHEMAP_REDEFINED_GROUP, |
| 3423 | NULL, NULL, node, |
| 3424 | "A global model group definition with the name '%s' does already exist", name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3425 | xmlFree(ret); |
| 3426 | return (NULL); |
| 3427 | } |
| 3428 | ret->minOccurs = 1; |
| 3429 | ret->maxOccurs = 1; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3430 | if (ctxt->assemble != NULL) |
| 3431 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3432 | return (ret); |
| 3433 | } |
| 3434 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3435 | /** |
| 3436 | * xmlSchemaNewWildcardNs: |
| 3437 | * @ctxt: a schema validation context |
| 3438 | * |
| 3439 | * Creates a new wildcard namespace constraint. |
| 3440 | * |
| 3441 | * Returns the new struture or NULL in case of error |
| 3442 | */ |
| 3443 | static xmlSchemaWildcardNsPtr |
| 3444 | xmlSchemaNewWildcardNsConstraint(xmlSchemaParserCtxtPtr ctxt) |
| 3445 | { |
| 3446 | xmlSchemaWildcardNsPtr ret; |
| 3447 | |
| 3448 | ret = (xmlSchemaWildcardNsPtr) |
| 3449 | xmlMalloc(sizeof(xmlSchemaWildcardNs)); |
| 3450 | if (ret == NULL) { |
| 3451 | xmlSchemaPErrMemory(ctxt, "creating wildcard namespace constraint", NULL); |
| 3452 | return (NULL); |
| 3453 | } |
| 3454 | ret->value = NULL; |
| 3455 | ret->next = NULL; |
| 3456 | return (ret); |
| 3457 | } |
| 3458 | |
| 3459 | /** |
| 3460 | * xmlSchemaAddWildcard: |
| 3461 | * @ctxt: a schema validation context |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3462 | * Adds a wildcard. It corresponds to a |
| 3463 | * xsd:anyAttribute and is used as storage for namespace |
| 3464 | * constraints on a xsd:any. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3465 | * |
| 3466 | * Returns the new struture or NULL in case of error |
| 3467 | */ |
| 3468 | static xmlSchemaWildcardPtr |
| 3469 | xmlSchemaAddWildcard(xmlSchemaParserCtxtPtr ctxt) |
| 3470 | { |
| 3471 | xmlSchemaWildcardPtr ret = NULL; |
| 3472 | |
| 3473 | if (ctxt == NULL) |
| 3474 | return (NULL); |
| 3475 | |
| 3476 | ret = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard)); |
| 3477 | if (ret == NULL) { |
| 3478 | xmlSchemaPErrMemory(ctxt, "adding wildcard", NULL); |
| 3479 | return (NULL); |
| 3480 | } |
| 3481 | memset(ret, 0, sizeof(xmlSchemaWildcard)); |
| 3482 | ret->minOccurs = 1; |
| 3483 | ret->maxOccurs = 1; |
| 3484 | |
| 3485 | return (ret); |
| 3486 | } |
| 3487 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3488 | /************************************************************************ |
| 3489 | * * |
| 3490 | * Utilities for parsing * |
| 3491 | * * |
| 3492 | ************************************************************************/ |
| 3493 | |
| 3494 | /** |
| 3495 | * xmlGetQNameProp: |
| 3496 | * @ctxt: a schema validation context |
| 3497 | * @node: a subtree containing XML Schema informations |
| 3498 | * @name: the attribute name |
| 3499 | * @namespace: the result namespace if any |
| 3500 | * |
| 3501 | * Extract a QName Attribute value |
| 3502 | * |
| 3503 | * Returns the NCName or NULL if not found, and also update @namespace |
| 3504 | * with the namespace URI |
| 3505 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3506 | static const xmlChar * |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3507 | xmlGetQNameProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3508 | const char *name, const xmlChar ** namespace) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3509 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3510 | const xmlChar *val; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3511 | xmlNsPtr ns; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3512 | const xmlChar *ret, *prefix; |
| 3513 | int len; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 3514 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3515 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3516 | *namespace = NULL; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 3517 | attr = xmlSchemaGetPropNode(node, name); |
| 3518 | if (attr == NULL) |
| 3519 | return (NULL); |
| 3520 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 3521 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3522 | if (val == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3523 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3524 | |
Daniel Veillard | ba0153a | 2004-04-01 10:42:31 +0000 | [diff] [blame] | 3525 | if (!strchr((char *) val, ':')) { |
Daniel Veillard | ebcdebd | 2004-03-05 00:15:50 +0000 | [diff] [blame] | 3526 | ns = xmlSearchNs(node->doc, node, 0); |
| 3527 | if (ns) { |
| 3528 | *namespace = xmlDictLookup(ctxt->dict, ns->href, -1); |
| 3529 | return (val); |
| 3530 | } |
| 3531 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3532 | ret = xmlSplitQName3(val, &len); |
| 3533 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3534 | return (val); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3535 | } |
| 3536 | ret = xmlDictLookup(ctxt->dict, ret, -1); |
| 3537 | prefix = xmlDictLookup(ctxt->dict, val, len); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3538 | |
| 3539 | ns = xmlSearchNs(node->doc, node, prefix); |
| 3540 | if (ns == NULL) { |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 3541 | xmlSchemaPSimpleTypeErr(ctxt, XML_SCHEMAP_PREFIX_UNDEFINED, |
| 3542 | NULL, NULL, (xmlNodePtr) attr, |
| 3543 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), NULL, val, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3544 | "The QName value '%s' has no corresponding namespace " |
| 3545 | "declaration in scope", val, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3546 | } else { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3547 | *namespace = xmlDictLookup(ctxt->dict, ns->href, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3548 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3549 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3550 | } |
| 3551 | |
| 3552 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3553 | * xmlSchemaPValAttrNodeQNameValue: |
| 3554 | * @ctxt: a schema parser context |
| 3555 | * @schema: the schema context |
| 3556 | * @ownerDes: the designation of the parent element |
| 3557 | * @ownerItem: the parent as a schema object |
| 3558 | * @value: the QName value |
| 3559 | * @local: the resulting local part if found, the attribute value otherwise |
| 3560 | * @uri: the resulting namespace URI if found |
| 3561 | * |
| 3562 | * Extracts the local name and the URI of a QName value and validates it. |
| 3563 | * This one is intended to be used on attribute values that |
| 3564 | * should resolve to schema components. |
| 3565 | * |
| 3566 | * Returns 0, in case the QName is valid, a positive error code |
| 3567 | * if not valid and -1 if an internal error occurs. |
| 3568 | */ |
| 3569 | static int |
| 3570 | xmlSchemaPValAttrNodeQNameValue(xmlSchemaParserCtxtPtr ctxt, |
| 3571 | xmlSchemaPtr schema, |
| 3572 | xmlChar **ownerDes, |
| 3573 | xmlSchemaTypePtr ownerItem, |
| 3574 | xmlAttrPtr attr, |
| 3575 | const xmlChar *value, |
| 3576 | const xmlChar **uri, |
| 3577 | const xmlChar **prefix, |
| 3578 | const xmlChar **local) |
| 3579 | { |
| 3580 | const xmlChar *pref; |
| 3581 | xmlNsPtr ns; |
| 3582 | int len, ret; |
| 3583 | |
| 3584 | *uri = NULL; |
| 3585 | *local = NULL; |
| 3586 | if (prefix != 0) |
| 3587 | *prefix = NULL; |
| 3588 | ret = xmlValidateQName(value, 1); |
| 3589 | if (ret > 0) { |
| 3590 | xmlSchemaPSimpleTypeErr(ctxt, |
| 3591 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 3592 | ownerDes, ownerItem, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3593 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
| 3594 | "QName", value, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3595 | NULL, NULL, NULL); |
| 3596 | *local = value; |
| 3597 | return (ctxt->err); |
| 3598 | } else if (ret < 0) |
| 3599 | return (-1); |
| 3600 | |
| 3601 | if (!strchr((char *) value, ':')) { |
| 3602 | ns = xmlSearchNs(attr->doc, attr->parent, 0); |
| 3603 | if (ns) |
| 3604 | *uri = xmlDictLookup(ctxt->dict, ns->href, -1); |
| 3605 | else if (schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) { |
| 3606 | /* |
| 3607 | * This one takes care of included schemas with no |
| 3608 | * target namespace. |
| 3609 | */ |
| 3610 | *uri = schema->targetNamespace; |
| 3611 | } |
| 3612 | *local = value; |
| 3613 | return (0); |
| 3614 | } |
| 3615 | /* |
| 3616 | * At this point xmlSplitQName3 has to return a local name. |
| 3617 | */ |
| 3618 | *local = xmlSplitQName3(value, &len); |
| 3619 | *local = xmlDictLookup(ctxt->dict, *local, -1); |
| 3620 | pref = xmlDictLookup(ctxt->dict, value, len); |
| 3621 | if (prefix != 0) |
| 3622 | *prefix = pref; |
| 3623 | ns = xmlSearchNs(attr->doc, attr->parent, pref); |
| 3624 | if (ns == NULL) { |
| 3625 | xmlSchemaPSimpleTypeErr(ctxt, |
| 3626 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 3627 | ownerDes, ownerItem, (xmlNodePtr) attr, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3628 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), "QName", value, |
| 3629 | "The QName value '%s' has no corresponding namespace " |
| 3630 | "declaration in scope", value, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3631 | return (ctxt->err); |
| 3632 | } else { |
| 3633 | *uri = xmlDictLookup(ctxt->dict, ns->href, -1); |
| 3634 | } |
| 3635 | return (0); |
| 3636 | } |
| 3637 | |
| 3638 | /** |
| 3639 | * xmlSchemaPValAttrNodeQName: |
| 3640 | * @ctxt: a schema parser context |
| 3641 | * @schema: the schema context |
| 3642 | * @ownerDes: the designation of the owner element |
| 3643 | * @ownerItem: the owner as a schema object |
| 3644 | * @attr: the attribute node |
| 3645 | * @local: the resulting local part if found, the attribute value otherwise |
| 3646 | * @uri: the resulting namespace URI if found |
| 3647 | * |
| 3648 | * Extracts and validates the QName of an attribute value. |
| 3649 | * This one is intended to be used on attribute values that |
| 3650 | * should resolve to schema components. |
| 3651 | * |
| 3652 | * Returns 0, in case the QName is valid, a positive error code |
| 3653 | * if not valid and -1 if an internal error occurs. |
| 3654 | */ |
| 3655 | static int |
| 3656 | xmlSchemaPValAttrNodeQName(xmlSchemaParserCtxtPtr ctxt, |
| 3657 | xmlSchemaPtr schema, |
| 3658 | xmlChar **ownerDes, |
| 3659 | xmlSchemaTypePtr ownerItem, |
| 3660 | xmlAttrPtr attr, |
| 3661 | const xmlChar **uri, |
| 3662 | const xmlChar **prefix, |
| 3663 | const xmlChar **local) |
| 3664 | { |
| 3665 | const xmlChar *value; |
| 3666 | |
| 3667 | value = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 3668 | return (xmlSchemaPValAttrNodeQNameValue(ctxt, schema, |
| 3669 | ownerDes, ownerItem, attr, value, uri, prefix, local)); |
| 3670 | } |
| 3671 | |
| 3672 | /** |
| 3673 | * xmlSchemaPValAttrQName: |
| 3674 | * @ctxt: a schema parser context |
| 3675 | * @schema: the schema context |
| 3676 | * @ownerDes: the designation of the parent element |
| 3677 | * @ownerItem: the owner as a schema object |
| 3678 | * @ownerElem: the parent node of the attribute |
| 3679 | * @name: the name of the attribute |
| 3680 | * @local: the resulting local part if found, the attribute value otherwise |
| 3681 | * @uri: the resulting namespace URI if found |
| 3682 | * |
| 3683 | * Extracts and validates the QName of an attribute value. |
| 3684 | * |
| 3685 | * Returns 0, in case the QName is valid, a positive error code |
| 3686 | * if not valid and -1 if an internal error occurs. |
| 3687 | */ |
| 3688 | static int |
| 3689 | xmlSchemaPValAttrQName(xmlSchemaParserCtxtPtr ctxt, |
| 3690 | xmlSchemaPtr schema, |
| 3691 | xmlChar **ownerDes, |
| 3692 | xmlSchemaTypePtr ownerItem, |
| 3693 | xmlNodePtr ownerElem, |
| 3694 | const char *name, |
| 3695 | const xmlChar **uri, |
| 3696 | const xmlChar **prefix, |
| 3697 | const xmlChar **local) |
| 3698 | { |
| 3699 | xmlAttrPtr attr; |
| 3700 | |
| 3701 | attr = xmlSchemaGetPropNode(ownerElem, name); |
| 3702 | if (attr == NULL) { |
| 3703 | *local = NULL; |
| 3704 | *uri = NULL; |
| 3705 | return (0); |
| 3706 | } |
| 3707 | return (xmlSchemaPValAttrNodeQName(ctxt, schema, |
| 3708 | ownerDes, ownerItem, attr, uri, prefix, local)); |
| 3709 | } |
| 3710 | |
| 3711 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3712 | * xmlGetMaxOccurs: |
| 3713 | * @ctxt: a schema validation context |
| 3714 | * @node: a subtree containing XML Schema informations |
| 3715 | * |
| 3716 | * Get the maxOccurs property |
| 3717 | * |
| 3718 | * Returns the default if not found, or the value |
| 3719 | */ |
| 3720 | static int |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 3721 | xmlGetMaxOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
| 3722 | int min, int max, int def, const char *expected) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3723 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3724 | const xmlChar *val, *cur; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3725 | int ret = 0; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 3726 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3727 | |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 3728 | attr = xmlSchemaGetPropNode(node, "maxOccurs"); |
| 3729 | if (attr == NULL) |
| 3730 | return (def); |
| 3731 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3732 | |
| 3733 | if (xmlStrEqual(val, (const xmlChar *) "unbounded")) { |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 3734 | if (max != UNBOUNDED) { |
| 3735 | xmlSchemaPSimpleTypeErr(ctxt, |
| 3736 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 3737 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 3738 | NULL, NULL, (xmlNodePtr) attr, NULL, expected, |
| 3739 | val, NULL, NULL, NULL); |
| 3740 | return (def); |
| 3741 | } else |
| 3742 | return (UNBOUNDED); /* encoding it with -1 might be another option */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | cur = val; |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3746 | while (IS_BLANK_CH(*cur)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3747 | cur++; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 3748 | if (*cur == 0) { |
| 3749 | xmlSchemaPSimpleTypeErr(ctxt, |
| 3750 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 3751 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 3752 | NULL, NULL, (xmlNodePtr) attr, NULL, expected, |
| 3753 | val, NULL, NULL, NULL); |
| 3754 | return (def); |
| 3755 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3756 | while ((*cur >= '0') && (*cur <= '9')) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3757 | ret = ret * 10 + (*cur - '0'); |
| 3758 | cur++; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3759 | } |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3760 | while (IS_BLANK_CH(*cur)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3761 | cur++; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 3762 | /* |
| 3763 | * TODO: Restrict the maximal value to Integer. |
| 3764 | */ |
| 3765 | if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) { |
| 3766 | xmlSchemaPSimpleTypeErr(ctxt, |
| 3767 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 3768 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 3769 | NULL, NULL, (xmlNodePtr) attr, NULL, expected, |
| 3770 | val, NULL, NULL, NULL); |
| 3771 | return (def); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3772 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3773 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3774 | } |
| 3775 | |
| 3776 | /** |
| 3777 | * xmlGetMinOccurs: |
| 3778 | * @ctxt: a schema validation context |
| 3779 | * @node: a subtree containing XML Schema informations |
| 3780 | * |
| 3781 | * Get the minOccurs property |
| 3782 | * |
| 3783 | * Returns the default if not found, or the value |
| 3784 | */ |
| 3785 | static int |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 3786 | xmlGetMinOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
| 3787 | int min, int max, int def, const char *expected) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3788 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3789 | const xmlChar *val, *cur; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3790 | int ret = 0; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 3791 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3792 | |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 3793 | attr = xmlSchemaGetPropNode(node, "minOccurs"); |
| 3794 | if (attr == NULL) |
| 3795 | return (def); |
| 3796 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3797 | cur = val; |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3798 | while (IS_BLANK_CH(*cur)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3799 | cur++; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 3800 | if (*cur == 0) { |
| 3801 | xmlSchemaPSimpleTypeErr(ctxt, |
| 3802 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 3803 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 3804 | NULL, NULL, (xmlNodePtr) attr, NULL, expected, |
| 3805 | val, NULL, NULL, NULL); |
| 3806 | return (def); |
| 3807 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3808 | while ((*cur >= '0') && (*cur <= '9')) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3809 | ret = ret * 10 + (*cur - '0'); |
| 3810 | cur++; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3811 | } |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3812 | while (IS_BLANK_CH(*cur)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3813 | cur++; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 3814 | /* |
| 3815 | * TODO: Restrict the maximal value to Integer. |
| 3816 | */ |
| 3817 | if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) { |
| 3818 | xmlSchemaPSimpleTypeErr(ctxt, |
| 3819 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 3820 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 3821 | NULL, NULL, (xmlNodePtr) attr, NULL, expected, |
| 3822 | val, NULL, NULL, NULL); |
| 3823 | return (def); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3824 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3825 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 3829 | * xmlSchemaPGetBoolNodeValue: |
| 3830 | * @ctxt: a schema validation context |
| 3831 | * @ownerDes: owner designation |
| 3832 | * @ownerItem: the owner as a schema item |
| 3833 | * @node: the node holding the value |
| 3834 | * |
| 3835 | * Converts a boolean string value into 1 or 0. |
| 3836 | * |
| 3837 | * Returns 0 or 1. |
| 3838 | */ |
| 3839 | static int |
| 3840 | xmlSchemaPGetBoolNodeValue(xmlSchemaParserCtxtPtr ctxt, |
| 3841 | xmlChar **ownerDes, |
| 3842 | xmlSchemaTypePtr ownerItem, |
| 3843 | xmlNodePtr node) |
| 3844 | { |
| 3845 | xmlChar *value = NULL; |
| 3846 | int res = 0; |
| 3847 | |
| 3848 | value = xmlNodeGetContent(node); |
| 3849 | /* |
| 3850 | * 3.2.2.1 Lexical representation |
| 3851 | * An instance of a datatype that is defined as ·boolean· |
| 3852 | * can have the following legal literals {true, false, 1, 0}. |
| 3853 | */ |
| 3854 | if (xmlStrEqual(BAD_CAST value, BAD_CAST "true")) |
| 3855 | res = 1; |
| 3856 | else if (xmlStrEqual(BAD_CAST value, BAD_CAST "false")) |
| 3857 | res = 0; |
| 3858 | else if (xmlStrEqual(BAD_CAST value, BAD_CAST "1")) |
| 3859 | res = 1; |
| 3860 | else if (xmlStrEqual(BAD_CAST value, BAD_CAST "0")) |
| 3861 | res = 0; |
| 3862 | else { |
| 3863 | xmlSchemaPSimpleTypeErr(ctxt, |
| 3864 | XML_SCHEMAP_INVALID_BOOLEAN, |
| 3865 | ownerDes, ownerItem, node, |
| 3866 | xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN), |
| 3867 | "(1 | 0 | true | false)", BAD_CAST value, |
| 3868 | NULL, NULL, NULL); |
| 3869 | } |
| 3870 | if (value != NULL) |
| 3871 | xmlFree(value); |
| 3872 | return (res); |
| 3873 | } |
| 3874 | |
| 3875 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3876 | * xmlGetBooleanProp: |
| 3877 | * @ctxt: a schema validation context |
| 3878 | * @node: a subtree containing XML Schema informations |
| 3879 | * @name: the attribute name |
| 3880 | * @def: the default value |
| 3881 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3882 | * Evaluate if a boolean property is set |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3883 | * |
| 3884 | * Returns the default if not found, 0 if found to be false, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3885 | * 1 if found to be true |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3886 | */ |
| 3887 | static int |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3888 | xmlGetBooleanProp(xmlSchemaParserCtxtPtr ctxt, |
| 3889 | xmlChar **ownerDes, |
| 3890 | xmlSchemaTypePtr ownerItem, |
| 3891 | xmlNodePtr node, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3892 | const char *name, int def) |
| 3893 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3894 | const xmlChar *val; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3895 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3896 | val = xmlSchemaGetProp(ctxt, node, name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3897 | if (val == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3898 | return (def); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3899 | /* |
| 3900 | * 3.2.2.1 Lexical representation |
| 3901 | * An instance of a datatype that is defined as ·boolean· |
| 3902 | * can have the following legal literals {true, false, 1, 0}. |
| 3903 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3904 | if (xmlStrEqual(val, BAD_CAST "true")) |
| 3905 | def = 1; |
| 3906 | else if (xmlStrEqual(val, BAD_CAST "false")) |
| 3907 | def = 0; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3908 | else if (xmlStrEqual(val, BAD_CAST "1")) |
| 3909 | def = 1; |
| 3910 | else if (xmlStrEqual(val, BAD_CAST "0")) |
| 3911 | def = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3912 | else { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3913 | xmlSchemaPSimpleTypeErr(ctxt, |
| 3914 | XML_SCHEMAP_INVALID_BOOLEAN, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3915 | ownerDes, ownerItem, node, |
| 3916 | xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN), |
| 3917 | "(1 | 0 | true | false)", val, NULL, NULL, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3918 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3919 | return (def); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3920 | } |
| 3921 | |
| 3922 | /************************************************************************ |
| 3923 | * * |
| 3924 | * Shema extraction from an Infoset * |
| 3925 | * * |
| 3926 | ************************************************************************/ |
| 3927 | static xmlSchemaTypePtr xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr |
| 3928 | ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3929 | xmlNodePtr node, |
| 3930 | int topLevel); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3931 | static xmlSchemaTypePtr xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr |
| 3932 | ctxt, |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3933 | xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3934 | xmlNodePtr node, |
| 3935 | int topLevel); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3936 | static xmlSchemaTypePtr xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr |
| 3937 | ctxt, |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3938 | xmlSchemaPtr schema, |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 3939 | xmlNodePtr node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3940 | static xmlSchemaTypePtr xmlSchemaParseSequence(xmlSchemaParserCtxtPtr ctxt, |
| 3941 | xmlSchemaPtr schema, |
| 3942 | xmlNodePtr node); |
| 3943 | static xmlSchemaTypePtr xmlSchemaParseAll(xmlSchemaParserCtxtPtr ctxt, |
| 3944 | xmlSchemaPtr schema, |
| 3945 | xmlNodePtr node); |
| 3946 | static xmlSchemaAttributePtr xmlSchemaParseAttribute(xmlSchemaParserCtxtPtr |
| 3947 | ctxt, |
| 3948 | xmlSchemaPtr schema, |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 3949 | xmlNodePtr node, |
| 3950 | int topLevel); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3951 | static xmlSchemaAttributeGroupPtr |
| 3952 | xmlSchemaParseAttributeGroup(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3953 | xmlSchemaPtr schema, xmlNodePtr node, |
| 3954 | int topLevel); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3955 | static xmlSchemaTypePtr xmlSchemaParseChoice(xmlSchemaParserCtxtPtr ctxt, |
| 3956 | xmlSchemaPtr schema, |
| 3957 | xmlNodePtr node); |
| 3958 | static xmlSchemaTypePtr xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt, |
| 3959 | xmlSchemaPtr schema, |
| 3960 | xmlNodePtr node); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3961 | static xmlSchemaWildcardPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3962 | xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt, |
| 3963 | xmlSchemaPtr schema, xmlNodePtr node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3964 | |
| 3965 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3966 | * xmlSchemaPValAttrNodeValue: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3967 | * |
| 3968 | * @ctxt: a schema parser context |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3969 | * @ownerDes: the designation of the parent element |
| 3970 | * @ownerItem: the schema object owner if existent |
| 3971 | * @attr: the schema attribute node being validated |
| 3972 | * @value: the value |
| 3973 | * @type: the built-in type to be validated against |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3974 | * |
| 3975 | * Validates a value against the given built-in type. |
| 3976 | * This one is intended to be used internally for validation |
| 3977 | * of schema attribute values during parsing of the schema. |
| 3978 | * |
| 3979 | * Returns 0 if the value is valid, a positive error code |
| 3980 | * number otherwise and -1 in case of an internal or API error. |
| 3981 | */ |
| 3982 | static int |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3983 | xmlSchemaPValAttrNodeValue(xmlSchemaParserCtxtPtr ctxt, |
| 3984 | xmlChar **ownerDes, |
| 3985 | xmlSchemaTypePtr ownerItem, |
| 3986 | xmlAttrPtr attr, |
| 3987 | const xmlChar *value, |
| 3988 | xmlSchemaTypePtr type) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3989 | { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3990 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3991 | int ret = 0; |
| 3992 | |
| 3993 | /* |
| 3994 | * NOTE: Should we move this to xmlschematypes.c? Hmm, but this |
| 3995 | * one is really meant to be used internally, so better not. |
| 3996 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3997 | if ((ctxt == NULL) || (type == NULL) || (attr == NULL)) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3998 | return (-1); |
| 3999 | if (type->type != XML_SCHEMA_TYPE_BASIC) { |
| 4000 | xmlSchemaPErr(ctxt, (xmlNodePtr) attr, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 4001 | XML_SCHEMAP_INTERNAL, |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 4002 | "Internal error: xmlSchemaPValAttrNodeValue, the given " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4003 | "type '%s' is not a built-in type.\n", |
| 4004 | type->name, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4005 | return (-1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4006 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4007 | switch (type->builtInType) { |
| 4008 | case XML_SCHEMAS_NCNAME: |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 4009 | case XML_SCHEMAS_QNAME: |
| 4010 | case XML_SCHEMAS_ANYURI: |
| 4011 | case XML_SCHEMAS_TOKEN: |
| 4012 | case XML_SCHEMAS_LANGUAGE: |
| 4013 | ret = xmlSchemaValPredefTypeNode(type, value, NULL, (xmlNodePtr) attr); |
| 4014 | break; |
| 4015 | |
| 4016 | /* |
| 4017 | case XML_SCHEMAS_NCNAME: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4018 | ret = xmlValidateNCName(value, 1); |
| 4019 | break; |
| 4020 | case XML_SCHEMAS_QNAME: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4021 | xmlSchemaPErr(ctxt, (xmlNodePtr) attr, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 4022 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4023 | "Internal error: xmlSchemaPvalueAttrNode, use " |
| 4024 | "the function xmlSchemaExtractSchemaQNamePropvalueidated " |
| 4025 | "for extracting QName valueues instead.\n", |
| 4026 | NULL, NULL); |
| 4027 | return (-1); |
| 4028 | case XML_SCHEMAS_ANYURI: |
| 4029 | if (value != NULL) { |
| 4030 | xmlURIPtr uri = xmlParseURI((const char *) value); |
| 4031 | if (uri == NULL) |
| 4032 | ret = 1; |
| 4033 | else |
| 4034 | xmlFreeURI(uri); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4035 | } |
| 4036 | break; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4037 | case XML_SCHEMAS_TOKEN: { |
| 4038 | const xmlChar *cur = value; |
| 4039 | |
| 4040 | if (IS_BLANK_CH(*cur)) { |
| 4041 | ret = 1; |
| 4042 | } else while (*cur != 0) { |
| 4043 | if ((*cur == 0xd) || (*cur == 0xa) || (*cur == 0x9)) { |
| 4044 | ret = 1; |
| 4045 | break; |
| 4046 | } else if (*cur == ' ') { |
| 4047 | cur++; |
| 4048 | if ((*cur == 0) || (*cur == ' ')) { |
| 4049 | ret = 1; |
| 4050 | break; |
| 4051 | } |
| 4052 | } else { |
| 4053 | cur++; |
| 4054 | } |
| 4055 | } |
| 4056 | } |
| 4057 | break; |
| 4058 | case XML_SCHEMAS_LANGUAGE: |
| 4059 | if (xmlCheckLanguageID(value) != 1) |
| 4060 | ret = 1; |
| 4061 | break; |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 4062 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4063 | default: { |
| 4064 | xmlSchemaPErr(ctxt, (xmlNodePtr) attr, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 4065 | XML_SCHEMAP_INTERNAL, |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 4066 | "Internal error: xmlSchemaPValAttrNodeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4067 | "valueidation using the type '%s' is not implemented " |
| 4068 | "yet.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4069 | type->name, NULL); |
| 4070 | return (-1); |
| 4071 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4072 | } |
| 4073 | /* |
| 4074 | * TODO: Should we use the S4S error codes instead? |
| 4075 | */ |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 4076 | if (ret < 0) { |
| 4077 | xmlSchemaPErr(ctxt, (xmlNodePtr) attr, |
| 4078 | XML_SCHEMAP_INTERNAL, |
| 4079 | "Internal error: xmlSchemaPValAttrNodeValue, " |
| 4080 | "failed to validate a schema attribute value.\n", |
| 4081 | NULL, NULL); |
| 4082 | return (-1); |
| 4083 | } else if (ret > 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4084 | if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 4085 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4086 | XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2, |
| 4087 | ownerDes, ownerItem, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4088 | type, NULL, value, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4089 | NULL, NULL, NULL); |
| 4090 | return(XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2); |
| 4091 | } else { |
| 4092 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4093 | XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, |
| 4094 | ownerDes, ownerItem, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4095 | type, NULL, value, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4096 | NULL, NULL, NULL); |
| 4097 | return(XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1); |
| 4098 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4099 | } |
| 4100 | return (ret); |
| 4101 | } |
| 4102 | |
| 4103 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4104 | * xmlSchemaPValAttrNode: |
| 4105 | * |
| 4106 | * @ctxt: a schema parser context |
| 4107 | * @ownerDes: the designation of the parent element |
| 4108 | * @ownerItem: the schema object owner if existent |
| 4109 | * @attr: the schema attribute node being validated |
| 4110 | * @type: the built-in type to be validated against |
| 4111 | * @value: the resulting value if any |
| 4112 | * |
| 4113 | * Extracts and validates a value against the given built-in type. |
| 4114 | * This one is intended to be used internally for validation |
| 4115 | * of schema attribute values during parsing of the schema. |
| 4116 | * |
| 4117 | * Returns 0 if the value is valid, a positive error code |
| 4118 | * number otherwise and -1 in case of an internal or API error. |
| 4119 | */ |
| 4120 | static int |
| 4121 | xmlSchemaPValAttrNode(xmlSchemaParserCtxtPtr ctxt, |
| 4122 | xmlChar **ownerDes, |
| 4123 | xmlSchemaTypePtr ownerItem, |
| 4124 | xmlAttrPtr attr, |
| 4125 | xmlSchemaTypePtr type, |
| 4126 | const xmlChar **value) |
| 4127 | { |
| 4128 | const xmlChar *val; |
| 4129 | |
| 4130 | if ((ctxt == NULL) || (type == NULL) || (attr == NULL)) |
| 4131 | return (-1); |
| 4132 | |
| 4133 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 4134 | if (value != NULL) |
| 4135 | *value = val; |
| 4136 | |
| 4137 | return (xmlSchemaPValAttrNodeValue(ctxt, ownerDes, ownerItem, attr, |
| 4138 | val, type)); |
| 4139 | } |
| 4140 | |
| 4141 | /** |
| 4142 | * xmlSchemaPValAttr: |
| 4143 | * |
| 4144 | * @ctxt: a schema parser context |
| 4145 | * @node: the element node of the attribute |
| 4146 | * @ownerDes: the designation of the parent element |
| 4147 | * @ownerItem: the schema object owner if existent |
| 4148 | * @ownerElem: the owner element node |
| 4149 | * @name: the name of the schema attribute node |
| 4150 | * @type: the built-in type to be validated against |
| 4151 | * @value: the resulting value if any |
| 4152 | * |
| 4153 | * Extracts and validates a value against the given built-in type. |
| 4154 | * This one is intended to be used internally for validation |
| 4155 | * of schema attribute values during parsing of the schema. |
| 4156 | * |
| 4157 | * Returns 0 if the value is valid, a positive error code |
| 4158 | * number otherwise and -1 in case of an internal or API error. |
| 4159 | */ |
| 4160 | static int |
| 4161 | xmlSchemaPValAttr(xmlSchemaParserCtxtPtr ctxt, |
| 4162 | xmlChar **ownerDes, |
| 4163 | xmlSchemaTypePtr ownerItem, |
| 4164 | xmlNodePtr ownerElem, |
| 4165 | const char *name, |
| 4166 | xmlSchemaTypePtr type, |
| 4167 | const xmlChar **value) |
| 4168 | { |
| 4169 | xmlAttrPtr attr; |
| 4170 | |
| 4171 | if ((ctxt == NULL) || (type == NULL)) { |
| 4172 | if (value != NULL) |
| 4173 | *value = NULL; |
| 4174 | return (-1); |
| 4175 | } |
| 4176 | if (type->type != XML_SCHEMA_TYPE_BASIC) { |
| 4177 | if (value != NULL) |
| 4178 | *value = NULL; |
| 4179 | xmlSchemaPErr(ctxt, ownerElem, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 4180 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4181 | "Internal error: xmlSchemaPValAttr, the given " |
| 4182 | "type '%s' is not a built-in type.\n", |
| 4183 | type->name, NULL); |
| 4184 | return (-1); |
| 4185 | } |
| 4186 | attr = xmlSchemaGetPropNode(ownerElem, name); |
| 4187 | if (attr == NULL) { |
| 4188 | if (value != NULL) |
| 4189 | *value = NULL; |
| 4190 | return (0); |
| 4191 | } |
| 4192 | return (xmlSchemaPValAttrNode(ctxt, ownerDes, ownerItem, attr, |
| 4193 | type, value)); |
| 4194 | } |
| 4195 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4196 | * xmlSchemaParseAttrDecls: |
| 4197 | * @ctxt: a schema validation context |
| 4198 | * @schema: the schema being built |
| 4199 | * @node: a subtree containing XML Schema informations |
| 4200 | * @type: the hosting type |
| 4201 | * |
| 4202 | * parse a XML schema attrDecls declaration corresponding to |
| 4203 | * <!ENTITY % attrDecls |
| 4204 | * '((%attribute;| %attributeGroup;)*,(%anyAttribute;)?)'> |
| 4205 | */ |
| 4206 | static xmlNodePtr |
| 4207 | xmlSchemaParseAttrDecls(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 4208 | xmlNodePtr child, xmlSchemaTypePtr type) |
| 4209 | { |
| 4210 | xmlSchemaAttributePtr lastattr, attr; |
| 4211 | |
| 4212 | lastattr = NULL; |
| 4213 | while ((IS_SCHEMA(child, "attribute")) || |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4214 | (IS_SCHEMA(child, "attributeGroup"))) { |
| 4215 | attr = NULL; |
| 4216 | if (IS_SCHEMA(child, "attribute")) { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4217 | attr = xmlSchemaParseAttribute(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4218 | } else if (IS_SCHEMA(child, "attributeGroup")) { |
| 4219 | attr = (xmlSchemaAttributePtr) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4220 | xmlSchemaParseAttributeGroup(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4221 | } |
| 4222 | if (attr != NULL) { |
| 4223 | if (lastattr == NULL) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4224 | if (type->type == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) |
| 4225 | ((xmlSchemaAttributeGroupPtr) type)->attributes = attr; |
| 4226 | else |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4227 | type->attributes = attr; |
| 4228 | lastattr = attr; |
| 4229 | } else { |
| 4230 | lastattr->next = attr; |
| 4231 | lastattr = attr; |
| 4232 | } |
| 4233 | } |
| 4234 | child = child->next; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4235 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4236 | return (child); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4237 | } |
| 4238 | |
| 4239 | /** |
| 4240 | * xmlSchemaParseAnnotation: |
| 4241 | * @ctxt: a schema validation context |
| 4242 | * @schema: the schema being built |
| 4243 | * @node: a subtree containing XML Schema informations |
| 4244 | * |
| 4245 | * parse a XML schema Attrribute declaration |
| 4246 | * *WARNING* this interface is highly subject to change |
| 4247 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4248 | * Returns -1 in case of error, 0 if the declaration is improper and |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4249 | * 1 in case of success. |
| 4250 | */ |
| 4251 | static xmlSchemaAnnotPtr |
| 4252 | xmlSchemaParseAnnotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 4253 | xmlNodePtr node) |
| 4254 | { |
| 4255 | xmlSchemaAnnotPtr ret; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4256 | xmlNodePtr child = NULL; |
| 4257 | xmlAttrPtr attr; |
| 4258 | int barked = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4259 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4260 | /* |
| 4261 | * INFO: S4S completed. |
| 4262 | */ |
| 4263 | /* |
| 4264 | * id = ID |
| 4265 | * {any attributes with non-schema namespace . . .}> |
| 4266 | * Content: (appinfo | documentation)* |
| 4267 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4268 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 4269 | return (NULL); |
| 4270 | ret = xmlSchemaNewAnnot(ctxt, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4271 | attr = node->properties; |
| 4272 | while (attr != NULL) { |
| 4273 | if (((attr->ns == NULL) && |
| 4274 | (!xmlStrEqual(attr->name, BAD_CAST "id"))) || |
| 4275 | ((attr->ns != NULL) && |
| 4276 | xmlStrEqual(attr->ns->href, xmlSchemaNs))) { |
| 4277 | |
| 4278 | xmlSchemaPIllegalAttrErr(ctxt, |
| 4279 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 4280 | NULL, NULL, attr); |
| 4281 | } |
| 4282 | attr = attr->next; |
| 4283 | } |
| 4284 | /* TODO: Check id. */ |
| 4285 | |
| 4286 | /* |
| 4287 | * And now for the children... |
| 4288 | */ |
| 4289 | child = node->children; |
| 4290 | while (child != NULL) { |
| 4291 | if (IS_SCHEMA(child, "appinfo")) { |
| 4292 | /* TODO: make available the content of "appinfo". */ |
| 4293 | /* |
| 4294 | * source = anyURI |
| 4295 | * {any attributes with non-schema namespace . . .}> |
| 4296 | * Content: ({any})* |
| 4297 | */ |
| 4298 | attr = child->properties; |
| 4299 | while (attr != NULL) { |
| 4300 | if (((attr->ns == NULL) && |
| 4301 | (!xmlStrEqual(attr->name, BAD_CAST "source"))) || |
| 4302 | ((attr->ns != NULL) && |
| 4303 | xmlStrEqual(attr->ns->href, xmlSchemaNs))) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4304 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4305 | xmlSchemaPIllegalAttrErr(ctxt, |
| 4306 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 4307 | NULL, NULL, attr); |
| 4308 | } |
| 4309 | attr = attr->next; |
| 4310 | } |
| 4311 | xmlSchemaPValAttr(ctxt, NULL, NULL, child, "source", |
| 4312 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), NULL); |
| 4313 | child = child->next; |
| 4314 | } else if (IS_SCHEMA(child, "documentation")) { |
| 4315 | /* TODO: make available the content of "documentation". */ |
| 4316 | /* |
| 4317 | * source = anyURI |
| 4318 | * {any attributes with non-schema namespace . . .}> |
| 4319 | * Content: ({any})* |
| 4320 | */ |
| 4321 | attr = child->properties; |
| 4322 | while (attr != NULL) { |
| 4323 | if (attr->ns == NULL) { |
| 4324 | if (!xmlStrEqual(attr->name, BAD_CAST "source")) { |
| 4325 | xmlSchemaPIllegalAttrErr(ctxt, |
| 4326 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 4327 | NULL, NULL, attr); |
| 4328 | } |
| 4329 | } else { |
| 4330 | if (xmlStrEqual(attr->ns->href, xmlSchemaNs) || |
| 4331 | (xmlStrEqual(attr->name, BAD_CAST "lang") && |
| 4332 | (!xmlStrEqual(attr->ns->href, XML_XML_NAMESPACE)))) { |
| 4333 | |
| 4334 | xmlSchemaPIllegalAttrErr(ctxt, |
| 4335 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 4336 | NULL, NULL, attr); |
| 4337 | } |
| 4338 | } |
| 4339 | attr = attr->next; |
| 4340 | } |
| 4341 | /* |
| 4342 | * Attribute "xml:lang". |
| 4343 | */ |
| 4344 | attr = xmlSchemaGetPropNodeNs(child, (const char *) XML_XML_NAMESPACE, "lang"); |
| 4345 | if (attr != NULL) |
| 4346 | xmlSchemaPValAttrNode(ctxt, NULL, NULL, attr, |
| 4347 | xmlSchemaGetBuiltInType(XML_SCHEMAS_LANGUAGE), NULL); |
| 4348 | child = child->next; |
| 4349 | } else { |
| 4350 | if (!barked) |
| 4351 | xmlSchemaPContentErr(ctxt, |
| 4352 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 4353 | NULL, NULL, node, child, NULL, "(appinfo | documentation)*"); |
| 4354 | barked = 1; |
| 4355 | child = child->next; |
| 4356 | } |
| 4357 | } |
| 4358 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4359 | return (ret); |
| 4360 | } |
| 4361 | |
| 4362 | /** |
| 4363 | * xmlSchemaParseFacet: |
| 4364 | * @ctxt: a schema validation context |
| 4365 | * @schema: the schema being built |
| 4366 | * @node: a subtree containing XML Schema informations |
| 4367 | * |
| 4368 | * parse a XML schema Facet declaration |
| 4369 | * *WARNING* this interface is highly subject to change |
| 4370 | * |
| 4371 | * Returns the new type structure or NULL in case of error |
| 4372 | */ |
| 4373 | static xmlSchemaFacetPtr |
| 4374 | xmlSchemaParseFacet(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4375 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4376 | { |
| 4377 | xmlSchemaFacetPtr facet; |
| 4378 | xmlNodePtr child = NULL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4379 | const xmlChar *value; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4380 | |
| 4381 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 4382 | return (NULL); |
| 4383 | |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 4384 | facet = xmlSchemaNewFacet(); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4385 | if (facet == NULL) { |
| 4386 | xmlSchemaPErrMemory(ctxt, "allocating facet", node); |
| 4387 | return (NULL); |
| 4388 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4389 | facet->node = node; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4390 | value = xmlSchemaGetProp(ctxt, node, "value"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4391 | if (value == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4392 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_FACET_NO_VALUE, |
| 4393 | "Facet %s has no value\n", node->name, NULL); |
| 4394 | xmlSchemaFreeFacet(facet); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4395 | return (NULL); |
| 4396 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4397 | if (IS_SCHEMA(node, "minInclusive")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4398 | facet->type = XML_SCHEMA_FACET_MININCLUSIVE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4399 | } else if (IS_SCHEMA(node, "minExclusive")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4400 | facet->type = XML_SCHEMA_FACET_MINEXCLUSIVE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4401 | } else if (IS_SCHEMA(node, "maxInclusive")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4402 | facet->type = XML_SCHEMA_FACET_MAXINCLUSIVE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4403 | } else if (IS_SCHEMA(node, "maxExclusive")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4404 | facet->type = XML_SCHEMA_FACET_MAXEXCLUSIVE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4405 | } else if (IS_SCHEMA(node, "totalDigits")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4406 | facet->type = XML_SCHEMA_FACET_TOTALDIGITS; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4407 | } else if (IS_SCHEMA(node, "fractionDigits")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4408 | facet->type = XML_SCHEMA_FACET_FRACTIONDIGITS; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4409 | } else if (IS_SCHEMA(node, "pattern")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4410 | facet->type = XML_SCHEMA_FACET_PATTERN; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4411 | } else if (IS_SCHEMA(node, "enumeration")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4412 | facet->type = XML_SCHEMA_FACET_ENUMERATION; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4413 | } else if (IS_SCHEMA(node, "whiteSpace")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4414 | facet->type = XML_SCHEMA_FACET_WHITESPACE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4415 | } else if (IS_SCHEMA(node, "length")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4416 | facet->type = XML_SCHEMA_FACET_LENGTH; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4417 | } else if (IS_SCHEMA(node, "maxLength")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4418 | facet->type = XML_SCHEMA_FACET_MAXLENGTH; |
| 4419 | } else if (IS_SCHEMA(node, "minLength")) { |
| 4420 | facet->type = XML_SCHEMA_FACET_MINLENGTH; |
| 4421 | } else { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4422 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_TYPE, |
| 4423 | "Unknown facet type %s\n", node->name, NULL); |
| 4424 | xmlSchemaFreeFacet(facet); |
| 4425 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4426 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4427 | facet->id = xmlSchemaGetProp(ctxt, node, "id"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4428 | facet->value = value; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4429 | if ((facet->type != XML_SCHEMA_FACET_PATTERN) && |
| 4430 | (facet->type != XML_SCHEMA_FACET_ENUMERATION)) { |
| 4431 | const xmlChar *fixed; |
| 4432 | |
| 4433 | fixed = xmlSchemaGetProp(ctxt, node, "fixed"); |
| 4434 | if (fixed != NULL) { |
| 4435 | if (xmlStrEqual(fixed, BAD_CAST "true")) |
| 4436 | facet->fixed = 1; |
| 4437 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4438 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4439 | child = node->children; |
| 4440 | |
| 4441 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4442 | facet->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 4443 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4444 | } |
| 4445 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4446 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_CHILD, |
| 4447 | "Facet %s has unexpected child content\n", |
| 4448 | node->name, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4449 | } |
| 4450 | return (facet); |
| 4451 | } |
| 4452 | |
| 4453 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4454 | * xmlSchemaParseWildcardNs: |
| 4455 | * @ctxt: a schema parser context |
| 4456 | * @wildc: the wildcard, already created |
| 4457 | * @node: a subtree containing XML Schema informations |
| 4458 | * |
| 4459 | * Parses the attribute "processContents" and "namespace" |
| 4460 | * of a xsd:anyAttribute and xsd:any. |
| 4461 | * *WARNING* this interface is highly subject to change |
| 4462 | * |
| 4463 | * Returns 0 if everything goes fine, a positive error code |
| 4464 | * if something is not valid and -1 if an internal error occurs. |
| 4465 | */ |
| 4466 | static int |
| 4467 | xmlSchemaParseWildcardNs(xmlSchemaParserCtxtPtr ctxt, |
| 4468 | xmlSchemaPtr schema, |
| 4469 | xmlSchemaWildcardPtr wildc, |
| 4470 | xmlNodePtr node) |
| 4471 | { |
| 4472 | const xmlChar *pc, *ns, *dictnsItem; |
| 4473 | int ret = 0; |
| 4474 | xmlChar *nsItem; |
| 4475 | xmlSchemaWildcardNsPtr tmp, lastNs = NULL; |
| 4476 | xmlAttrPtr attr; |
| 4477 | |
| 4478 | pc = xmlSchemaGetProp(ctxt, node, "processContents"); |
| 4479 | if ((pc == NULL) |
| 4480 | || (xmlStrEqual(pc, (const xmlChar *) "strict"))) { |
| 4481 | wildc->processContents = XML_SCHEMAS_ANY_STRICT; |
| 4482 | } else if (xmlStrEqual(pc, (const xmlChar *) "skip")) { |
| 4483 | wildc->processContents = XML_SCHEMAS_ANY_SKIP; |
| 4484 | } else if (xmlStrEqual(pc, (const xmlChar *) "lax")) { |
| 4485 | wildc->processContents = XML_SCHEMAS_ANY_LAX; |
| 4486 | } else { |
| 4487 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4488 | XML_SCHEMAP_UNKNOWN_PROCESSCONTENT_CHILD, |
| 4489 | NULL, NULL, node, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4490 | NULL, "(strict | skip | lax)", pc, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4491 | NULL, NULL, NULL); |
| 4492 | wildc->processContents = XML_SCHEMAS_ANY_STRICT; |
| 4493 | ret = XML_SCHEMAP_UNKNOWN_PROCESSCONTENT_CHILD; |
| 4494 | } |
| 4495 | /* |
| 4496 | * Build the namespace constraints. |
| 4497 | */ |
| 4498 | attr = xmlSchemaGetPropNode(node, "namespace"); |
| 4499 | ns = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 4500 | if ((ns == NULL) || (xmlStrEqual(ns, BAD_CAST "##any"))) |
| 4501 | wildc->any = 1; |
| 4502 | else if (xmlStrEqual(ns, BAD_CAST "##other")) { |
| 4503 | wildc->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 4504 | if (wildc->negNsSet == NULL) { |
| 4505 | return (-1); |
| 4506 | } |
| 4507 | wildc->negNsSet->value = schema->targetNamespace; |
| 4508 | } else { |
| 4509 | const xmlChar *end, *cur; |
| 4510 | |
| 4511 | cur = ns; |
| 4512 | do { |
| 4513 | while (IS_BLANK_CH(*cur)) |
| 4514 | cur++; |
| 4515 | end = cur; |
| 4516 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 4517 | end++; |
| 4518 | if (end == cur) |
| 4519 | break; |
| 4520 | nsItem = xmlStrndup(cur, end - cur); |
| 4521 | if ((xmlStrEqual(nsItem, BAD_CAST "##other")) || |
| 4522 | (xmlStrEqual(nsItem, BAD_CAST "##any"))) { |
| 4523 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4524 | XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER, |
| 4525 | NULL, NULL, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4526 | NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4527 | "((##any | ##other) | List of (anyURI | " |
| 4528 | "(##targetNamespace | ##local)))", |
| 4529 | nsItem, NULL, NULL, NULL); |
| 4530 | ret = XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER; |
| 4531 | } else { |
| 4532 | if (xmlStrEqual(nsItem, BAD_CAST "##targetNamespace")) { |
| 4533 | dictnsItem = schema->targetNamespace; |
| 4534 | } else if (xmlStrEqual(nsItem, BAD_CAST "##local")) { |
| 4535 | dictnsItem = NULL; |
| 4536 | } else { |
| 4537 | /* |
| 4538 | * Validate the item (anyURI). |
| 4539 | */ |
| 4540 | xmlSchemaPValAttrNodeValue(ctxt, NULL, NULL, attr, |
| 4541 | nsItem, xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI)); |
| 4542 | dictnsItem = xmlDictLookup(ctxt->dict, nsItem, -1); |
| 4543 | } |
| 4544 | /* |
| 4545 | * Avoid dublicate namespaces. |
| 4546 | */ |
| 4547 | tmp = wildc->nsSet; |
| 4548 | while (tmp != NULL) { |
| 4549 | if (dictnsItem == tmp->value) |
| 4550 | break; |
| 4551 | tmp = tmp->next; |
| 4552 | } |
| 4553 | if (tmp == NULL) { |
| 4554 | tmp = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 4555 | if (tmp == NULL) { |
| 4556 | xmlFree(nsItem); |
| 4557 | return (-1); |
| 4558 | } |
| 4559 | tmp->value = dictnsItem; |
| 4560 | tmp->next = NULL; |
| 4561 | if (wildc->nsSet == NULL) |
| 4562 | wildc->nsSet = tmp; |
| 4563 | else |
| 4564 | lastNs->next = tmp; |
| 4565 | lastNs = tmp; |
| 4566 | } |
| 4567 | |
| 4568 | } |
| 4569 | xmlFree(nsItem); |
| 4570 | cur = end; |
| 4571 | } while (*cur != 0); |
| 4572 | } |
| 4573 | return (ret); |
| 4574 | } |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4575 | |
| 4576 | static int |
| 4577 | xmlSchemaPCheckParticleCorrect_2(xmlSchemaParserCtxtPtr ctxt, |
| 4578 | xmlSchemaTypePtr item, |
| 4579 | xmlNodePtr node, |
| 4580 | int minOccurs, |
| 4581 | int maxOccurs) { |
| 4582 | |
| 4583 | if (maxOccurs != UNBOUNDED) { |
| 4584 | /* |
| 4585 | * TODO: Maby we should better not create the particle, |
| 4586 | * if min/max is invalid, since it could confuse the build of the |
| 4587 | * content model. |
| 4588 | */ |
| 4589 | /* |
| 4590 | * 3.9.6 Schema Component Constraint: Particle Correct |
| 4591 | * |
| 4592 | */ |
| 4593 | if (maxOccurs < 1) { |
| 4594 | /* |
| 4595 | * 2.2 {max occurs} must be greater than or equal to 1. |
| 4596 | */ |
| 4597 | xmlSchemaPCustomAttrErr(ctxt, |
| 4598 | XML_SCHEMAP_P_PROPS_CORRECT_2_2, |
| 4599 | NULL, item, xmlSchemaGetPropNode(node, "maxOccurs"), |
| 4600 | "The value must be greater than or equal to 1"); |
| 4601 | return (XML_SCHEMAP_P_PROPS_CORRECT_2_2); |
| 4602 | } else if (minOccurs > maxOccurs) { |
| 4603 | /* |
| 4604 | * 2.1 {min occurs} must not be greater than {max occurs}. |
| 4605 | */ |
| 4606 | xmlSchemaPCustomAttrErr(ctxt, |
| 4607 | XML_SCHEMAP_P_PROPS_CORRECT_2_1, |
| 4608 | NULL, item, xmlSchemaGetPropNode(node, "minOccurs"), |
| 4609 | "The value must not be greater than the value of 'maxOccurs'"); |
| 4610 | return (XML_SCHEMAP_P_PROPS_CORRECT_2_1); |
| 4611 | } |
| 4612 | } |
| 4613 | return (0); |
| 4614 | } |
| 4615 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4616 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4617 | * xmlSchemaParseAny: |
| 4618 | * @ctxt: a schema validation context |
| 4619 | * @schema: the schema being built |
| 4620 | * @node: a subtree containing XML Schema informations |
| 4621 | * |
| 4622 | * parse a XML schema Any declaration |
| 4623 | * *WARNING* this interface is highly subject to change |
| 4624 | * |
| 4625 | * Returns the new type structure or NULL in case of error |
| 4626 | */ |
| 4627 | static xmlSchemaTypePtr |
| 4628 | xmlSchemaParseAny(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 4629 | xmlNodePtr node) |
| 4630 | { |
| 4631 | xmlSchemaTypePtr type; |
| 4632 | xmlNodePtr child = NULL; |
| 4633 | xmlChar name[30]; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4634 | xmlSchemaWildcardPtr wildc; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4635 | int minOccurs, maxOccurs; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4636 | |
| 4637 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 4638 | return (NULL); |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4639 | maxOccurs = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, |
| 4640 | "(nonNegativeInteger | unbounded)"); |
| 4641 | minOccurs = xmlGetMinOccurs(ctxt, node, 0, -1, 1, |
| 4642 | "nonNegativeInteger"); |
| 4643 | if ((minOccurs == 0) && (maxOccurs == 0)) |
| 4644 | return (NULL); |
| 4645 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4646 | snprintf((char *) name, 30, "any %d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4647 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4648 | if (type == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4649 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4650 | type->node = node; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4651 | type->type = XML_SCHEMA_TYPE_ANY; |
| 4652 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4653 | wildc = xmlSchemaAddWildcard(ctxt); |
| 4654 | /* |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4655 | * Check min/max sanity. |
| 4656 | */ |
| 4657 | type->maxOccurs = maxOccurs; |
| 4658 | type->minOccurs = minOccurs; |
| 4659 | xmlSchemaPCheckParticleCorrect_2(ctxt, type, |
| 4660 | node, type->minOccurs, type->maxOccurs); |
| 4661 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4662 | * This is not nice, since it is won't be used as a attribute wildcard, |
| 4663 | * but better than adding a field to the structure. |
| 4664 | */ |
| 4665 | type->attributeWildcard = wildc; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4666 | xmlSchemaParseWildcardNs(ctxt, schema, wildc, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4667 | child = node->children; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4668 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4669 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 4670 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4671 | } |
| 4672 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4673 | xmlSchemaPErr2(ctxt, node, child, |
| 4674 | XML_SCHEMAP_UNKNOWN_SEQUENCE_CHILD, |
| 4675 | "Sequence %s has unexpected content\n", type->name, |
| 4676 | NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4677 | } |
| 4678 | |
| 4679 | return (type); |
| 4680 | } |
| 4681 | |
| 4682 | /** |
| 4683 | * xmlSchemaParseNotation: |
| 4684 | * @ctxt: a schema validation context |
| 4685 | * @schema: the schema being built |
| 4686 | * @node: a subtree containing XML Schema informations |
| 4687 | * |
| 4688 | * parse a XML schema Notation declaration |
| 4689 | * |
| 4690 | * Returns the new structure or NULL in case of error |
| 4691 | */ |
| 4692 | static xmlSchemaNotationPtr |
| 4693 | xmlSchemaParseNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4694 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4695 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4696 | const xmlChar *name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4697 | xmlSchemaNotationPtr ret; |
| 4698 | xmlNodePtr child = NULL; |
| 4699 | |
| 4700 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 4701 | return (NULL); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4702 | name = xmlSchemaGetProp(ctxt, node, "name"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4703 | if (name == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4704 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_NOTATION_NO_NAME, |
| 4705 | "Notation has no name\n", NULL, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4706 | return (NULL); |
| 4707 | } |
| 4708 | ret = xmlSchemaAddNotation(ctxt, schema, name); |
| 4709 | if (ret == NULL) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4710 | return (NULL); |
| 4711 | } |
| 4712 | child = node->children; |
| 4713 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4714 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 4715 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4716 | } |
| 4717 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4718 | xmlSchemaPErr2(ctxt, node, child, |
| 4719 | XML_SCHEMAP_UNKNOWN_NOTATION_CHILD, |
| 4720 | "notation %s has unexpected content\n", name, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4721 | } |
| 4722 | |
| 4723 | return (ret); |
| 4724 | } |
| 4725 | |
| 4726 | /** |
| 4727 | * xmlSchemaParseAnyAttribute: |
| 4728 | * @ctxt: a schema validation context |
| 4729 | * @schema: the schema being built |
| 4730 | * @node: a subtree containing XML Schema informations |
| 4731 | * |
| 4732 | * parse a XML schema AnyAttrribute declaration |
| 4733 | * *WARNING* this interface is highly subject to change |
| 4734 | * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4735 | * Returns a wildcard or NULL. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4736 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4737 | static xmlSchemaWildcardPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4738 | xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt, |
| 4739 | xmlSchemaPtr schema, xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4740 | { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4741 | xmlSchemaWildcardPtr ret; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4742 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4743 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4744 | |
| 4745 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 4746 | return (NULL); |
| 4747 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4748 | ret = xmlSchemaAddWildcard(ctxt); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4749 | if (ret == NULL) { |
| 4750 | return (NULL); |
| 4751 | } |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4752 | ret->type = XML_SCHEMA_TYPE_ANY_ATTRIBUTE; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4753 | /* |
| 4754 | * Check for illegal attributes. |
| 4755 | */ |
| 4756 | attr = node->properties; |
| 4757 | while (attr != NULL) { |
| 4758 | if (attr->ns == NULL) { |
| 4759 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 4760 | (!xmlStrEqual(attr->name, BAD_CAST "namespace")) && |
| 4761 | (!xmlStrEqual(attr->name, BAD_CAST "processContents"))) { |
| 4762 | xmlSchemaPIllegalAttrErr(ctxt, |
| 4763 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 4764 | NULL, NULL, attr); |
| 4765 | } |
| 4766 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 4767 | xmlSchemaPIllegalAttrErr(ctxt, |
| 4768 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 4769 | NULL, NULL, attr); |
| 4770 | } |
| 4771 | attr = attr->next; |
| 4772 | } |
| 4773 | /* ret->id = xmlSchemaGetProp(ctxt, node, "id"); */ |
| 4774 | /* |
| 4775 | * Parse the namespace list. |
| 4776 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4777 | if (xmlSchemaParseWildcardNs(ctxt, schema, ret, node) != 0) { |
| 4778 | xmlSchemaFreeWildcard(ret); |
| 4779 | return (NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4780 | } |
| 4781 | /* |
| 4782 | * And now for the children... |
| 4783 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4784 | child = node->children; |
| 4785 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4786 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 4787 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4788 | } |
| 4789 | if (child != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4790 | xmlSchemaPContentErr(ctxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4791 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 4792 | NULL, NULL, node, child, |
| 4793 | NULL, "(annotation?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4794 | } |
| 4795 | |
| 4796 | return (ret); |
| 4797 | } |
| 4798 | |
| 4799 | |
| 4800 | /** |
| 4801 | * xmlSchemaParseAttribute: |
| 4802 | * @ctxt: a schema validation context |
| 4803 | * @schema: the schema being built |
| 4804 | * @node: a subtree containing XML Schema informations |
| 4805 | * |
| 4806 | * parse a XML schema Attrribute declaration |
| 4807 | * *WARNING* this interface is highly subject to change |
| 4808 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4809 | * Returns the attribute declaration. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4810 | */ |
| 4811 | static xmlSchemaAttributePtr |
| 4812 | xmlSchemaParseAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4813 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4814 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4815 | const xmlChar *name, *attrValue; |
| 4816 | xmlChar *repName = NULL; /* The reported designation. */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4817 | xmlSchemaAttributePtr ret; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4818 | xmlNodePtr child = NULL; |
| 4819 | xmlAttrPtr attr, nameAttr; |
| 4820 | int isRef = 0; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4821 | |
| 4822 | /* |
| 4823 | * Note that the w3c spec assumes the schema to be validated with schema |
| 4824 | * for schemas beforehand. |
| 4825 | * |
| 4826 | * 3.2.3 Constraints on XML Representations of Attribute Declarations |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4827 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4828 | |
| 4829 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 4830 | return (NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4831 | attr = xmlSchemaGetPropNode(node, "ref"); |
| 4832 | nameAttr = xmlSchemaGetPropNode(node, "name"); |
| 4833 | |
| 4834 | if ((attr == NULL) && (nameAttr == NULL)) { |
| 4835 | /* |
| 4836 | * 3.2.3 : 3.1 |
| 4837 | * One of ref or name must be present, but not both |
| 4838 | */ |
| 4839 | xmlSchemaPMissingAttrErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_3_1, |
| 4840 | (xmlChar **) &xmlSchemaElemDesAttrDecl, NULL, node, NULL, |
| 4841 | "One of the attributes 'ref' or 'name' must be present"); |
| 4842 | return (NULL); |
| 4843 | } |
| 4844 | if ((topLevel) || (attr == NULL)) { |
| 4845 | if (nameAttr == NULL) { |
| 4846 | xmlSchemaPMissingAttrErr(ctxt, XML_SCHEMAP_S4S_ATTR_MISSING, |
| 4847 | (xmlChar **) &xmlSchemaElemDesAttrDecl, NULL, node, |
| 4848 | "name", NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4849 | return (NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4850 | } |
| 4851 | } else |
| 4852 | isRef = 1; |
| 4853 | |
| 4854 | if (isRef) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 4855 | char buf[50]; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4856 | const xmlChar *refNs = NULL, *ref = NULL, *refPrefix = NULL; |
| 4857 | |
| 4858 | /* |
| 4859 | * Parse as attribute reference. |
| 4860 | */ |
| 4861 | if (xmlSchemaPValAttrNodeQName(ctxt, schema, |
| 4862 | (xmlChar **) &xmlSchemaElemDesAttrRef, NULL, attr, &refNs, |
| 4863 | &refPrefix, &ref) != 0) { |
| 4864 | return (NULL); |
| 4865 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 4866 | snprintf(buf, 49, "#aRef %d", ctxt->counter++ + 1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4867 | name = (const xmlChar *) buf; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4868 | ret = xmlSchemaAddAttribute(ctxt, schema, name, NULL, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4869 | if (ret == NULL) { |
| 4870 | if (repName != NULL) |
| 4871 | xmlFree(repName); |
| 4872 | return (NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4873 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4874 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTE; |
| 4875 | ret->node = node; |
| 4876 | ret->refNs = refNs; |
| 4877 | ret->refPrefix = refPrefix; |
| 4878 | ret->ref = ref; |
| 4879 | /* |
| 4880 | xmlSchemaFormatTypeRep(&repName, (xmlSchemaTypePtr) ret, NULL, NULL); |
| 4881 | */ |
| 4882 | if (nameAttr != NULL) |
| 4883 | xmlSchemaPMutualExclAttrErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_3_1, |
| 4884 | &repName, (xmlSchemaTypePtr) ret, nameAttr, |
| 4885 | "ref", "name"); |
| 4886 | /* |
| 4887 | * Check for illegal attributes. |
| 4888 | */ |
| 4889 | attr = node->properties; |
| 4890 | while (attr != NULL) { |
| 4891 | if (attr->ns == NULL) { |
| 4892 | if (xmlStrEqual(attr->name, BAD_CAST "type") || |
| 4893 | xmlStrEqual(attr->name, BAD_CAST "form")) { |
| 4894 | /* |
| 4895 | * 3.2.3 : 3.2 |
| 4896 | * If ref is present, then all of <simpleType>, |
| 4897 | * form and type must be absent. |
| 4898 | */ |
| 4899 | xmlSchemaPIllegalAttrErr(ctxt, |
| 4900 | XML_SCHEMAP_SRC_ATTRIBUTE_3_2, &repName, |
| 4901 | (xmlSchemaTypePtr) ret, attr); |
| 4902 | } else if ((!xmlStrEqual(attr->name, BAD_CAST "ref")) && |
| 4903 | (!xmlStrEqual(attr->name, BAD_CAST "use")) && |
| 4904 | (!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 4905 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
| 4906 | (!xmlStrEqual(attr->name, BAD_CAST "fixed")) && |
| 4907 | (!xmlStrEqual(attr->name, BAD_CAST "default"))) { |
| 4908 | xmlSchemaPIllegalAttrErr(ctxt, |
| 4909 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 4910 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 4911 | } |
| 4912 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 4913 | xmlSchemaPIllegalAttrErr(ctxt, |
| 4914 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 4915 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 4916 | } |
| 4917 | attr = attr->next; |
| 4918 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4919 | } else { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4920 | const xmlChar *ns = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4921 | |
| 4922 | /* |
| 4923 | * Parse as attribute declaration. |
| 4924 | */ |
| 4925 | if (xmlSchemaPValAttrNode(ctxt, |
| 4926 | (xmlChar **) &xmlSchemaElemDesAttrDecl, NULL, nameAttr, |
| 4927 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 4928 | return (NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4929 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4930 | /* |
| 4931 | xmlSchemaFormatTypeRep(&repName, NULL, xmlSchemaElemDesAttrDecl, name); |
| 4932 | */ |
| 4933 | /* |
| 4934 | * 3.2.6 Schema Component Constraint: xmlns Not Allowed |
| 4935 | */ |
| 4936 | if (xmlStrEqual(name, BAD_CAST "xmlns")) { |
| 4937 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4938 | XML_SCHEMAP_NO_XMLNS, |
| 4939 | &repName, NULL, (xmlNodePtr) nameAttr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4940 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), "NCName", NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4941 | "The value must not match 'xmlns'", |
| 4942 | NULL, NULL); |
| 4943 | if (repName != NULL) |
| 4944 | xmlFree(repName); |
| 4945 | return (NULL); |
| 4946 | } |
| 4947 | /* |
| 4948 | * Evaluate the target namespace |
| 4949 | */ |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4950 | if (topLevel) { |
| 4951 | ns = schema->targetNamespace; |
| 4952 | } else { |
| 4953 | attr = xmlSchemaGetPropNode(node, "form"); |
| 4954 | if (attr != NULL) { |
| 4955 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 4956 | if (xmlStrEqual(attrValue, BAD_CAST "qualified")) { |
| 4957 | ns = schema->targetNamespace; |
| 4958 | } else if (!xmlStrEqual(attrValue, BAD_CAST "unqualified")) { |
| 4959 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4960 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4961 | &repName, NULL, (xmlNodePtr) attr, |
| 4962 | NULL, "(qualified | unqualified)", |
| 4963 | attrValue, NULL, NULL, NULL); |
| 4964 | } |
| 4965 | } else if (schema->flags & XML_SCHEMAS_QUALIF_ATTR) |
| 4966 | ns = schema->targetNamespace; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4967 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4968 | ret = xmlSchemaAddAttribute(ctxt, schema, name, ns, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4969 | if (ret == NULL) { |
| 4970 | if (repName != NULL) |
| 4971 | xmlFree(repName); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4972 | return (NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4973 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4974 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTE; |
| 4975 | ret->node = node; |
| 4976 | if (topLevel) |
| 4977 | ret->flags |= XML_SCHEMAS_ATTR_GLOBAL; |
| 4978 | /* |
| 4979 | * 3.2.6 Schema Component Constraint: xsi: Not Allowed |
| 4980 | */ |
| 4981 | if (xmlStrEqual(ret->targetNamespace, xmlSchemaInstanceNs)) { |
| 4982 | xmlSchemaPCustomErr(ctxt, |
| 4983 | XML_SCHEMAP_NO_XSI, |
| 4984 | &repName, (xmlSchemaTypePtr) ret, node, |
| 4985 | "The target namespace must not match '%s'", |
| 4986 | xmlSchemaInstanceNs); |
| 4987 | } |
| 4988 | /* |
| 4989 | * Check for illegal attributes. |
| 4990 | */ |
| 4991 | attr = node->properties; |
| 4992 | while (attr != NULL) { |
| 4993 | if (attr->ns == NULL) { |
| 4994 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 4995 | (!xmlStrEqual(attr->name, BAD_CAST "default")) && |
| 4996 | (!xmlStrEqual(attr->name, BAD_CAST "fixed")) && |
| 4997 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
| 4998 | (!xmlStrEqual(attr->name, BAD_CAST "type"))) { |
| 4999 | if ((topLevel) || |
| 5000 | ((!xmlStrEqual(attr->name, BAD_CAST "form")) && |
| 5001 | (!xmlStrEqual(attr->name, BAD_CAST "use")))) { |
| 5002 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5003 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5004 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 5005 | } |
| 5006 | } |
| 5007 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 5008 | xmlSchemaPIllegalAttrErr(ctxt, XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5009 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 5010 | } |
| 5011 | attr = attr->next; |
| 5012 | } |
| 5013 | xmlSchemaPValAttrQName(ctxt, schema, &repName, (xmlSchemaTypePtr) ret, |
| 5014 | node, "type", &ret->typeNs, NULL, &ret->typeName); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5015 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5016 | /* TODO: Check ID. */ |
| 5017 | ret->id = xmlSchemaGetProp(ctxt, node, "id"); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5018 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5019 | * Attribute "fixed". |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5020 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5021 | ret->defValue = xmlSchemaGetProp(ctxt, node, "fixed"); |
| 5022 | if (ret->defValue != NULL) |
| 5023 | ret->flags |= XML_SCHEMAS_ATTR_FIXED; |
| 5024 | /* |
| 5025 | * Attribute "default". |
| 5026 | */ |
| 5027 | attr = xmlSchemaGetPropNode(node, "default"); |
| 5028 | if (attr != NULL) { |
| 5029 | /* |
| 5030 | * 3.2.3 : 1 |
| 5031 | * default and fixed must not both be present. |
| 5032 | */ |
| 5033 | if (ret->flags & XML_SCHEMAS_ATTR_FIXED) { |
| 5034 | xmlSchemaPMutualExclAttrErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_1, |
| 5035 | &repName, (xmlSchemaTypePtr) ret, attr, "default", "fixed"); |
| 5036 | } else |
| 5037 | ret->defValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 5038 | } |
| 5039 | if (topLevel == 0) { |
| 5040 | /* |
| 5041 | * Attribute "use". |
| 5042 | */ |
| 5043 | attr = xmlSchemaGetPropNode(node, "use"); |
| 5044 | if (attr != NULL) { |
| 5045 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 5046 | if (xmlStrEqual(attrValue, BAD_CAST "optional")) |
| 5047 | ret->occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL; |
| 5048 | else if (xmlStrEqual(attrValue, BAD_CAST "prohibited")) |
| 5049 | ret->occurs = XML_SCHEMAS_ATTR_USE_PROHIBITED; |
| 5050 | else if (xmlStrEqual(attrValue, BAD_CAST "required")) |
| 5051 | ret->occurs = XML_SCHEMAS_ATTR_USE_REQUIRED; |
| 5052 | else |
| 5053 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5054 | XML_SCHEMAP_INVALID_ATTR_USE, |
| 5055 | &repName, (xmlSchemaTypePtr) ret, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5056 | NULL, "(optional | prohibited | required)", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5057 | attrValue, NULL, NULL, NULL); |
| 5058 | } else |
| 5059 | ret->occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL; |
| 5060 | /* |
| 5061 | * 3.2.3 : 2 |
| 5062 | * If default and use are both present, use must have |
| 5063 | * the actual value optional. |
| 5064 | */ |
| 5065 | if ((ret->occurs != XML_SCHEMAS_ATTR_USE_OPTIONAL) && |
| 5066 | (ret->defValue != NULL) && |
| 5067 | ((ret->flags & XML_SCHEMAS_ATTR_FIXED) == 0)) { |
| 5068 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5069 | XML_SCHEMAP_SRC_ATTRIBUTE_2, |
| 5070 | &repName, (xmlSchemaTypePtr) ret, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5071 | NULL, "(optional | prohibited | required)", NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5072 | "The value must be 'optional' if the attribute " |
| 5073 | "'default' is present as well", NULL, NULL); |
| 5074 | } |
| 5075 | } |
| 5076 | /* |
| 5077 | * And now for the children... |
| 5078 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5079 | child = node->children; |
| 5080 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5081 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5082 | child = child->next; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5083 | } |
| 5084 | if (isRef) { |
| 5085 | if (child != NULL) { |
| 5086 | if (IS_SCHEMA(child, "simpleType")) |
| 5087 | /* |
| 5088 | * 3.2.3 : 3.2 |
| 5089 | * If ref is present, then all of <simpleType>, |
| 5090 | * form and type must be absent. |
| 5091 | */ |
| 5092 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_3_2, |
| 5093 | &repName, (xmlSchemaTypePtr) ret, node, child, NULL, |
| 5094 | "(annotation?)"); |
| 5095 | else |
| 5096 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 5097 | &repName, (xmlSchemaTypePtr) ret, node, child, NULL, |
| 5098 | "(annotation?)"); |
| 5099 | } |
| 5100 | } else { |
| 5101 | if (IS_SCHEMA(child, "simpleType")) { |
| 5102 | if (ret->typeName != NULL) { |
| 5103 | /* |
| 5104 | * 3.2.3 : 4 |
| 5105 | * type and <simpleType> must not both be present. |
| 5106 | */ |
| 5107 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_4, |
| 5108 | &repName, (xmlSchemaTypePtr) ret, node, child, |
| 5109 | "The attribute 'type' and the <simpleType> child " |
| 5110 | "are mutually exclusive", NULL); |
| 5111 | } else |
| 5112 | ret->subtypes = xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
| 5113 | child = child->next; |
| 5114 | } |
| 5115 | if (child != NULL) |
| 5116 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 5117 | &repName, (xmlSchemaTypePtr) ret, node, child, NULL, |
| 5118 | "(annotation?, simpleType?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5119 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5120 | /* |
| 5121 | * Cleanup. |
| 5122 | */ |
| 5123 | if (repName != NULL) |
| 5124 | xmlFree(repName); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5125 | return (ret); |
| 5126 | } |
| 5127 | |
| 5128 | /** |
| 5129 | * xmlSchemaParseAttributeGroup: |
| 5130 | * @ctxt: a schema validation context |
| 5131 | * @schema: the schema being built |
| 5132 | * @node: a subtree containing XML Schema informations |
| 5133 | * |
| 5134 | * parse a XML schema Attribute Group declaration |
| 5135 | * *WARNING* this interface is highly subject to change |
| 5136 | * |
| 5137 | * Returns the attribute group or NULL in case of error. |
| 5138 | */ |
| 5139 | static xmlSchemaAttributeGroupPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5140 | xmlSchemaParseAttributeGroup(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5141 | xmlSchemaPtr schema, xmlNodePtr node, |
| 5142 | int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5143 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5144 | const xmlChar *name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5145 | xmlSchemaAttributeGroupPtr ret; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5146 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5147 | const xmlChar *oldcontainer; |
| 5148 | xmlAttrPtr attr, nameAttr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5149 | |
| 5150 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5151 | return (NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5152 | |
| 5153 | nameAttr = xmlSchemaGetPropNode(node, "name"); |
| 5154 | attr = xmlSchemaGetPropNode(node, "ref"); |
| 5155 | if ((topLevel) || (attr == NULL)) { |
| 5156 | /* |
| 5157 | * Parse as an attribute group definition. |
| 5158 | * Note that those are allowed at top level only. |
| 5159 | */ |
| 5160 | if (nameAttr == NULL) { |
| 5161 | xmlSchemaPMissingAttrErr(ctxt, |
| 5162 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 5163 | NULL, NULL, node, "name", NULL); |
| 5164 | return (NULL); |
| 5165 | } |
| 5166 | name = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) nameAttr); |
| 5167 | /* |
| 5168 | * The name is crucial, exit if invalid. |
| 5169 | */ |
| 5170 | if (xmlSchemaPValAttrNode(ctxt, |
| 5171 | NULL, NULL, nameAttr, |
| 5172 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 5173 | return (NULL); |
| 5174 | } |
| 5175 | ret = xmlSchemaAddAttributeGroup(ctxt, schema, name, node); |
| 5176 | if (ret == NULL) |
| 5177 | return (NULL); |
| 5178 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTEGROUP; |
| 5179 | ret->flags |= XML_SCHEMAS_ATTRGROUP_GLOBAL; |
| 5180 | ret->node = node; |
| 5181 | } else { |
| 5182 | char buf[50]; |
| 5183 | const xmlChar *refNs = NULL, *ref = NULL, *refPrefix; |
| 5184 | |
| 5185 | /* |
| 5186 | * Parse as an attribute group definition reference. |
| 5187 | */ |
| 5188 | if (attr == NULL) { |
| 5189 | xmlSchemaPMissingAttrErr(ctxt, |
| 5190 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 5191 | NULL, NULL, node, "ref", NULL); |
| 5192 | } |
| 5193 | xmlSchemaPValAttrNodeQName(ctxt, schema, |
| 5194 | NULL, NULL, attr, &refNs, &refPrefix, &ref); |
| 5195 | |
| 5196 | snprintf(buf, 49, "#aGrRef %d", ctxt->counter++ + 1); |
| 5197 | name = (const xmlChar *) buf; |
| 5198 | if (name == NULL) { |
| 5199 | xmlSchemaPErrMemory(ctxt, "creating internal name for an " |
| 5200 | "attribute group definition reference", node); |
| 5201 | return (NULL); |
| 5202 | } |
| 5203 | ret = xmlSchemaAddAttributeGroup(ctxt, schema, name, node); |
| 5204 | if (ret == NULL) |
| 5205 | return (NULL); |
| 5206 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTEGROUP; |
| 5207 | ret->ref = ref; |
| 5208 | ret->refNs = refNs; |
| 5209 | /* TODO: Is @refPrefix currently used? */ |
| 5210 | ret->refPrefix = refPrefix; |
| 5211 | ret->node = node; |
| 5212 | } |
| 5213 | /* |
| 5214 | * Check for illegal attributes. |
| 5215 | */ |
| 5216 | attr = node->properties; |
| 5217 | while (attr != NULL) { |
| 5218 | if (attr->ns == NULL) { |
| 5219 | if ((((topLevel == 0) && (!xmlStrEqual(attr->name, BAD_CAST "ref"))) || |
| 5220 | (topLevel && (!xmlStrEqual(attr->name, BAD_CAST "name")))) && |
| 5221 | (!xmlStrEqual(attr->name, BAD_CAST "id"))) |
| 5222 | { |
| 5223 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5224 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5225 | NULL, NULL, attr); |
| 5226 | } |
| 5227 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 5228 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5229 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5230 | NULL, NULL, attr); |
| 5231 | } |
| 5232 | attr = attr->next; |
| 5233 | } |
| 5234 | /* TODO: Validate "id" ? */ |
| 5235 | /* |
| 5236 | * And now for the children... |
| 5237 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5238 | oldcontainer = ctxt->container; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5239 | ctxt->container = name; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5240 | child = node->children; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5241 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5242 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5243 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5244 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5245 | if (topLevel) { |
| 5246 | child = xmlSchemaParseAttrDecls(ctxt, schema, child, (xmlSchemaTypePtr) ret); |
| 5247 | if (IS_SCHEMA(child, "anyAttribute")) { |
| 5248 | ret->attributeWildcard = xmlSchemaParseAnyAttribute(ctxt, schema, child); |
| 5249 | child = child->next; |
| 5250 | } |
| 5251 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5252 | if (child != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5253 | xmlSchemaPContentErr(ctxt, |
| 5254 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 5255 | NULL, NULL, node, child, NULL, |
| 5256 | "(annotation?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5257 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5258 | ctxt->container = oldcontainer; |
| 5259 | return (ret); |
| 5260 | } |
| 5261 | |
| 5262 | /** |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5263 | * xmlSchemaPValAttrFormDefault: |
| 5264 | * @value: the value |
| 5265 | * @flags: the flags to be modified |
| 5266 | * @flagQualified: the specific flag for "qualified" |
| 5267 | * |
| 5268 | * Returns 0 if the value is valid, 1 otherwise. |
| 5269 | */ |
| 5270 | static int |
| 5271 | xmlSchemaPValAttrFormDefault(const xmlChar *value, |
| 5272 | int *flags, |
| 5273 | int flagQualified) |
| 5274 | { |
| 5275 | if (xmlStrEqual(value, BAD_CAST "qualified")) { |
| 5276 | if ((*flags & flagQualified) == 0) |
| 5277 | *flags |= flagQualified; |
| 5278 | } else if (!xmlStrEqual(value, BAD_CAST "unqualified")) |
| 5279 | return (1); |
| 5280 | |
| 5281 | return (0); |
| 5282 | } |
| 5283 | |
| 5284 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5285 | * xmlSchemaPValAttrBlockFinal: |
| 5286 | * @value: the value |
| 5287 | * @flags: the flags to be modified |
| 5288 | * @flagAll: the specific flag for "#all" |
| 5289 | * @flagExtension: the specific flag for "extension" |
| 5290 | * @flagRestriction: the specific flag for "restriction" |
| 5291 | * @flagSubstitution: the specific flag for "substitution" |
| 5292 | * @flagList: the specific flag for "list" |
| 5293 | * @flagUnion: the specific flag for "union" |
| 5294 | * |
| 5295 | * Validates the value of the attribute "final" and "block". The value |
| 5296 | * is converted into the specified flag values and returned in @flags. |
| 5297 | * |
| 5298 | * Returns 0 if the value is valid, 1 otherwise. |
| 5299 | */ |
| 5300 | |
| 5301 | static int |
| 5302 | xmlSchemaPValAttrBlockFinal(const xmlChar *value, |
| 5303 | int *flags, |
| 5304 | int flagAll, |
| 5305 | int flagExtension, |
| 5306 | int flagRestriction, |
| 5307 | int flagSubstitution, |
| 5308 | int flagList, |
| 5309 | int flagUnion) |
| 5310 | { |
| 5311 | int ret = 0; |
| 5312 | |
| 5313 | /* |
| 5314 | * TODO: This does not check for dublicate entries. |
| 5315 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5316 | if (value == NULL) |
| 5317 | return (1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5318 | if (xmlStrEqual(value, BAD_CAST "#all")) { |
| 5319 | if (flagAll != -1) |
| 5320 | *flags |= flagAll; |
| 5321 | else { |
| 5322 | if (flagExtension != -1) |
| 5323 | *flags |= flagExtension; |
| 5324 | if (flagRestriction != -1) |
| 5325 | *flags |= flagRestriction; |
| 5326 | if (flagSubstitution != -1) |
| 5327 | *flags |= flagSubstitution; |
| 5328 | if (flagList != -1) |
| 5329 | *flags |= flagList; |
| 5330 | if (flagUnion != -1) |
| 5331 | *flags |= flagUnion; |
| 5332 | } |
| 5333 | } else { |
| 5334 | const xmlChar *end, *cur = value; |
| 5335 | xmlChar *item; |
| 5336 | |
| 5337 | do { |
| 5338 | while (IS_BLANK_CH(*cur)) |
| 5339 | cur++; |
| 5340 | end = cur; |
| 5341 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 5342 | end++; |
| 5343 | if (end == cur) |
| 5344 | break; |
| 5345 | item = xmlStrndup(cur, end - cur); |
| 5346 | if (xmlStrEqual(item, BAD_CAST "extension")) { |
| 5347 | if (flagExtension != -1) { |
| 5348 | if ((*flags & flagExtension) == 0) |
| 5349 | *flags |= flagExtension; |
| 5350 | } else |
| 5351 | ret = 1; |
| 5352 | } else if (xmlStrEqual(item, BAD_CAST "restriction")) { |
| 5353 | if (flagRestriction != -1) { |
| 5354 | if ((*flags & flagRestriction) == 0) |
| 5355 | *flags |= flagRestriction; |
| 5356 | } else |
| 5357 | ret = 1; |
| 5358 | } else if (xmlStrEqual(item, BAD_CAST "substitution")) { |
| 5359 | if (flagSubstitution != -1) { |
| 5360 | if ((*flags & flagSubstitution) == 0) |
| 5361 | *flags |= flagSubstitution; |
| 5362 | } else |
| 5363 | ret = 1; |
| 5364 | } else if (xmlStrEqual(item, BAD_CAST "list")) { |
| 5365 | if (flagList != -1) { |
| 5366 | if ((*flags & flagList) == 0) |
| 5367 | *flags |= flagList; |
| 5368 | } else |
| 5369 | ret = 1; |
| 5370 | } else if (xmlStrEqual(item, BAD_CAST "union")) { |
| 5371 | if (flagUnion != -1) { |
| 5372 | if ((*flags & flagUnion) == 0) |
| 5373 | *flags |= flagUnion; |
| 5374 | } else |
| 5375 | ret = 1; |
| 5376 | } else |
| 5377 | ret = 1; |
| 5378 | if (item != NULL) |
| 5379 | xmlFree(item); |
| 5380 | cur = end; |
| 5381 | } while ((ret == 0) && (*cur != 0)); |
| 5382 | } |
| 5383 | |
| 5384 | return (ret); |
| 5385 | } |
| 5386 | |
| 5387 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5388 | * xmlSchemaParseElement: |
| 5389 | * @ctxt: a schema validation context |
| 5390 | * @schema: the schema being built |
| 5391 | * @node: a subtree containing XML Schema informations |
| 5392 | * |
| 5393 | * parse a XML schema Element declaration |
| 5394 | * *WARNING* this interface is highly subject to change |
| 5395 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5396 | * Returns the parsed element declaration. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5397 | */ |
| 5398 | static xmlSchemaElementPtr |
| 5399 | xmlSchemaParseElement(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5400 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5401 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5402 | const xmlChar *name = NULL; |
| 5403 | const xmlChar *attrValue; |
| 5404 | xmlChar *repName = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5405 | xmlSchemaElementPtr ret; |
| 5406 | xmlNodePtr child = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5407 | const xmlChar *oldcontainer; |
| 5408 | xmlAttrPtr attr, nameAttr; |
| 5409 | int minOccurs, maxOccurs; |
| 5410 | int isRef = 0; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5411 | |
| 5412 | /* 3.3.3 Constraints on XML Representations of Element Declarations */ |
| 5413 | /* TODO: Complete implementation of 3.3.6 */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5414 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5415 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5416 | return (NULL); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5417 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5418 | oldcontainer = ctxt->container; |
| 5419 | |
| 5420 | nameAttr = xmlSchemaGetPropNode(node, "name"); |
| 5421 | attr = xmlSchemaGetPropNode(node, "ref"); |
| 5422 | if ((topLevel) || (attr == NULL)) { |
| 5423 | if (nameAttr == NULL) { |
| 5424 | xmlSchemaPMissingAttrErr(ctxt, |
| 5425 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 5426 | (xmlChar **) &xmlSchemaElemDesElemDecl, NULL, node, |
| 5427 | "name", NULL); |
| 5428 | return (NULL); |
| 5429 | } |
| 5430 | name = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) nameAttr); |
| 5431 | } else { |
| 5432 | isRef = 1; |
| 5433 | |
| 5434 | } |
| 5435 | /* |
| 5436 | * ... unless minOccurs=maxOccurs=0, in which case the item corresponds |
| 5437 | * to no component at all |
| 5438 | * TODO: It might be better to validate the element, even if it won't be |
| 5439 | * used. |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5440 | */ |
| 5441 | minOccurs = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "nonNegativeInteger"); |
| 5442 | maxOccurs = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, "(nonNegativeInteger | unbounded)"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5443 | if ((minOccurs == 0) && (maxOccurs == 0)) |
| 5444 | return (NULL); |
| 5445 | /* |
| 5446 | * If we get a "ref" attribute on a local <element> we will assume it's |
| 5447 | * a reference - even if there's a "name" attribute; this seems to be more |
| 5448 | * robust. |
| 5449 | */ |
| 5450 | if (isRef) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5451 | char buf[50]; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5452 | const xmlChar *refNs = NULL, *ref = NULL, *refPrefix; |
| 5453 | |
| 5454 | /* |
| 5455 | * Parse as a particle. |
| 5456 | */ |
| 5457 | xmlSchemaPValAttrNodeQName(ctxt, schema, |
| 5458 | (xmlChar **) &xmlSchemaElemDesAttrRef, |
| 5459 | NULL, attr, &refNs, &refPrefix, &ref); |
| 5460 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5461 | snprintf(buf, 49, "#eRef %d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 5462 | ret = xmlSchemaAddElement(ctxt, schema, (const xmlChar *) buf, NULL, node, 0); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5463 | if (ret == NULL) { |
| 5464 | if (repName != NULL) |
| 5465 | xmlFree(repName); |
| 5466 | return (NULL); |
| 5467 | } |
| 5468 | ret->type = XML_SCHEMA_TYPE_ELEMENT; |
| 5469 | ret->node = node; |
| 5470 | ret->ref = ref; |
| 5471 | ret->refNs = refNs; |
| 5472 | ret->refPrefix = refPrefix; |
| 5473 | ret->flags |= XML_SCHEMAS_ELEM_REF; |
| 5474 | /* |
| 5475 | * Check for illegal attributes. |
| 5476 | */ |
| 5477 | /* |
| 5478 | * 3.3.3 : 2.1 |
| 5479 | * One of ref or name must be present, but not both |
| 5480 | */ |
| 5481 | if (nameAttr != NULL) { |
| 5482 | xmlSchemaPMutualExclAttrErr(ctxt, |
| 5483 | XML_SCHEMAP_SRC_ELEMENT_2_1, |
| 5484 | &repName, (xmlSchemaTypePtr) ret, nameAttr, |
| 5485 | "ref", "name"); |
| 5486 | } |
| 5487 | /* 3.3.3 : 2.2 */ |
| 5488 | attr = node->properties; |
| 5489 | while (attr != NULL) { |
| 5490 | if (attr->ns == NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5491 | if (xmlStrEqual(attr->name, BAD_CAST "ref") || |
| 5492 | xmlStrEqual(attr->name, BAD_CAST "name") || |
| 5493 | xmlStrEqual(attr->name, BAD_CAST "id") || |
| 5494 | xmlStrEqual(attr->name, BAD_CAST "maxOccurs") || |
| 5495 | xmlStrEqual(attr->name, BAD_CAST "minOccurs")) |
| 5496 | { |
| 5497 | attr = attr->next; |
| 5498 | continue; |
| 5499 | } else { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5500 | xmlSchemaPCustomAttrErr(ctxt, |
| 5501 | XML_SCHEMAP_SRC_ELEMENT_2_2, |
| 5502 | &repName, (xmlSchemaTypePtr) ret, attr, |
| 5503 | "Only the attributes 'minOccurs', 'maxOccurs' and " |
| 5504 | "'id' are allowed in addition to 'ref'"); |
| 5505 | break; |
| 5506 | } |
| 5507 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 5508 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5509 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5510 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 5511 | } |
| 5512 | attr = attr->next; |
| 5513 | } |
| 5514 | } else { |
| 5515 | const xmlChar *ns = NULL, *fixed; |
| 5516 | |
| 5517 | /* |
| 5518 | * Parse as an element declaration. |
| 5519 | */ |
| 5520 | if (xmlSchemaPValAttrNode(ctxt, |
| 5521 | (xmlChar **) &xmlSchemaElemDesElemDecl, NULL, nameAttr, |
| 5522 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) |
| 5523 | return (NULL); |
| 5524 | /* |
| 5525 | * Evaluate the target namespace. |
| 5526 | */ |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5527 | if (topLevel) { |
| 5528 | ns = schema->targetNamespace; |
| 5529 | } else { |
| 5530 | attr = xmlSchemaGetPropNode(node, "form"); |
| 5531 | if (attr != NULL) { |
| 5532 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 5533 | if (xmlStrEqual(attrValue, BAD_CAST "qualified")) { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5534 | ns = schema->targetNamespace; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5535 | } else if (!xmlStrEqual(attrValue, BAD_CAST "unqualified")) { |
| 5536 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5537 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 5538 | &repName, NULL, (xmlNodePtr) attr, |
| 5539 | NULL, "(qualified | unqualified)", |
| 5540 | attrValue, NULL, NULL, NULL); |
| 5541 | } |
| 5542 | } else if (schema->flags & XML_SCHEMAS_QUALIF_ELEM) |
| 5543 | ns = schema->targetNamespace; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5544 | } |
| 5545 | ret = xmlSchemaAddElement(ctxt, schema, name, ns, node, topLevel); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5546 | if (ret == NULL) { |
| 5547 | if (repName != NULL) |
| 5548 | xmlFree(repName); |
| 5549 | return (NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5550 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5551 | ret->type = XML_SCHEMA_TYPE_ELEMENT; |
| 5552 | ret->node = node; |
| 5553 | /* |
| 5554 | * Check for illegal attributes. |
| 5555 | */ |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5556 | attr = node->properties; |
| 5557 | while (attr != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5558 | if (attr->ns == NULL) { |
| 5559 | if ((!xmlStrEqual(attr->name, BAD_CAST "name")) && |
| 5560 | (!xmlStrEqual(attr->name, BAD_CAST "type")) && |
| 5561 | (!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 5562 | (!xmlStrEqual(attr->name, BAD_CAST "default")) && |
| 5563 | (!xmlStrEqual(attr->name, BAD_CAST "fixed")) && |
| 5564 | (!xmlStrEqual(attr->name, BAD_CAST "block")) && |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5565 | (!xmlStrEqual(attr->name, BAD_CAST "nillable"))) |
| 5566 | { |
| 5567 | if (topLevel == 0) { |
| 5568 | if ((!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) && |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5569 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) && |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5570 | (!xmlStrEqual(attr->name, BAD_CAST "form"))) |
| 5571 | { |
| 5572 | if (xmlStrEqual(attr->name, BAD_CAST "substitutionGroup")) { |
| 5573 | /* |
| 5574 | * 3.3.6 : 3 If there is a non-·absent· {substitution |
| 5575 | * group affiliation}, then {scope} must be global. |
| 5576 | * TODO: This one is redundant, since the S4S does |
| 5577 | * prohibit this attribute on local declarations already; |
| 5578 | * so why an explicit error code? Weird spec. |
| 5579 | * TODO: Move this to the proper constraint layer. |
| 5580 | * TODO: Or better wait for spec 1.1 to come. |
| 5581 | */ |
| 5582 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5583 | XML_SCHEMAP_E_PROPS_CORRECT_3, |
| 5584 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 5585 | } else { |
| 5586 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5587 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5588 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 5589 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5590 | } |
| 5591 | } else if ((!xmlStrEqual(attr->name, BAD_CAST "final")) && |
| 5592 | (!xmlStrEqual(attr->name, BAD_CAST "abstract")) && |
| 5593 | (!xmlStrEqual(attr->name, BAD_CAST "substitutionGroup"))) { |
| 5594 | |
| 5595 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5596 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5597 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 5598 | } |
| 5599 | } |
| 5600 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 5601 | |
| 5602 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5603 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5604 | &repName, (xmlSchemaTypePtr) ret, attr); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5605 | } |
| 5606 | attr = attr->next; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5607 | } |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5608 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5609 | * Extract/validate attributes. |
| 5610 | */ |
| 5611 | if (topLevel) { |
| 5612 | /* |
| 5613 | * Process top attributes of global element declarations here. |
| 5614 | */ |
| 5615 | ret->flags |= XML_SCHEMAS_ELEM_GLOBAL; |
| 5616 | ret->flags |= XML_SCHEMAS_ELEM_TOPLEVEL; |
| 5617 | xmlSchemaPValAttrQName(ctxt, schema, &repName, |
| 5618 | (xmlSchemaTypePtr) ret, node, "substitutionGroup", |
| 5619 | &(ret->substGroupNs), NULL, &(ret->substGroup)); |
| 5620 | if (xmlGetBooleanProp(ctxt, &repName, (xmlSchemaTypePtr) ret, |
| 5621 | node, "abstract", 0)) |
| 5622 | ret->flags |= XML_SCHEMAS_ELEM_ABSTRACT; |
| 5623 | /* |
| 5624 | * Attribute "final". |
| 5625 | */ |
| 5626 | attr = xmlSchemaGetPropNode(node, "final"); |
| 5627 | if (attr == NULL) { |
| 5628 | ret->flags |= XML_SCHEMAS_ELEM_FINAL_ABSENT; |
| 5629 | } else { |
| 5630 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 5631 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(ret->flags), |
| 5632 | -1, |
| 5633 | XML_SCHEMAS_ELEM_FINAL_EXTENSION, |
| 5634 | XML_SCHEMAS_ELEM_FINAL_RESTRICTION, -1, -1, -1) != 0) { |
| 5635 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5636 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 5637 | &repName, (xmlSchemaTypePtr) ret, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5638 | NULL, "(#all | List of (extension | restriction))", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5639 | attrValue, NULL, NULL, NULL); |
| 5640 | } |
| 5641 | } |
| 5642 | } |
| 5643 | /* |
| 5644 | * Attribute "block". |
| 5645 | */ |
| 5646 | attr = xmlSchemaGetPropNode(node, "block"); |
| 5647 | if (attr == NULL) { |
| 5648 | ret->flags |= XML_SCHEMAS_ELEM_BLOCK_ABSENT; |
| 5649 | } else { |
| 5650 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 5651 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(ret->flags), |
| 5652 | -1, |
| 5653 | XML_SCHEMAS_ELEM_BLOCK_EXTENSION, |
| 5654 | XML_SCHEMAS_ELEM_BLOCK_RESTRICTION, |
| 5655 | XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION, -1, -1) != 0) { |
| 5656 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5657 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 5658 | &repName, (xmlSchemaTypePtr) ret, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5659 | NULL, "(#all | List of (extension | " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5660 | "restriction | substitution))", attrValue, |
| 5661 | NULL, NULL, NULL); |
| 5662 | } |
| 5663 | } |
| 5664 | if (xmlGetBooleanProp(ctxt, &repName, (xmlSchemaTypePtr) ret, |
| 5665 | node, "nillable", 0)) |
| 5666 | ret->flags |= XML_SCHEMAS_ELEM_NILLABLE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5667 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5668 | xmlSchemaPValAttrQName(ctxt, schema, |
| 5669 | &repName, (xmlSchemaTypePtr) ret, node, |
| 5670 | "type", &(ret->namedTypeNs), NULL, &(ret->namedType)); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5671 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5672 | ret->value = xmlSchemaGetProp(ctxt, node, "default"); |
| 5673 | attr = xmlSchemaGetPropNode(node, "fixed"); |
| 5674 | if (attr != NULL) { |
| 5675 | fixed = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 5676 | if (ret->value != NULL) { |
| 5677 | /* |
| 5678 | * 3.3.3 : 1 |
| 5679 | * default and fixed must not both be present. |
| 5680 | */ |
| 5681 | xmlSchemaPMutualExclAttrErr(ctxt, |
| 5682 | XML_SCHEMAP_SRC_ELEMENT_1, |
| 5683 | &repName, (xmlSchemaTypePtr) ret, attr, |
| 5684 | "default", "fixed"); |
| 5685 | } else { |
| 5686 | ret->flags |= XML_SCHEMAS_ELEM_FIXED; |
| 5687 | ret->value = fixed; |
| 5688 | } |
| 5689 | } |
| 5690 | } |
| 5691 | /* |
| 5692 | * Extract/validate common attributes. |
| 5693 | */ |
| 5694 | /* TODO: Check ID: */ |
| 5695 | ret->id = xmlSchemaGetProp(ctxt, node, "id"); |
| 5696 | ret->minOccurs = minOccurs; |
| 5697 | ret->maxOccurs = maxOccurs; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5698 | if (topLevel != 1) |
| 5699 | xmlSchemaPCheckParticleCorrect_2(ctxt, (xmlSchemaTypePtr) ret, |
| 5700 | node, minOccurs, maxOccurs); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5701 | /* |
| 5702 | * And now for the children... |
| 5703 | */ |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 5704 | ctxt->container = ret->name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5705 | child = node->children; |
| 5706 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5707 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5708 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5709 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5710 | if (isRef) { |
| 5711 | if (child != NULL) { |
| 5712 | xmlSchemaPContentErr(ctxt, |
| 5713 | XML_SCHEMAP_SRC_ELEMENT_2_2, |
| 5714 | &repName, (xmlSchemaTypePtr) ret, node, child, |
| 5715 | NULL, "(annotation?)"); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5716 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5717 | } else { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5718 | if (IS_SCHEMA(child, "complexType")) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5719 | /* |
| 5720 | * 3.3.3 : 3 |
| 5721 | * "type" and either <simpleType> or <complexType> are mutually |
| 5722 | * exclusive |
| 5723 | */ |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5724 | if (ret->namedType != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5725 | xmlSchemaPContentErr(ctxt, |
| 5726 | XML_SCHEMAP_SRC_ELEMENT_3, |
| 5727 | &repName, (xmlSchemaTypePtr) ret, node, child, |
| 5728 | "The attribute 'type' and the <complexType> child are " |
| 5729 | "mutually exclusive", NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5730 | } else |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5731 | ret->subtypes = xmlSchemaParseComplexType(ctxt, schema, child, 0); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5732 | child = child->next; |
| 5733 | } else if (IS_SCHEMA(child, "simpleType")) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5734 | /* |
| 5735 | * 3.3.3 : 3 |
| 5736 | * "type" and either <simpleType> or <complexType> are |
| 5737 | * mutually exclusive |
| 5738 | */ |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5739 | if (ret->namedType != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5740 | xmlSchemaPContentErr(ctxt, |
| 5741 | XML_SCHEMAP_SRC_ELEMENT_3, |
| 5742 | &repName, (xmlSchemaTypePtr) ret, node, child, |
| 5743 | "The attribute 'type' and the <simpleType> child are " |
| 5744 | "mutually exclusive", NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5745 | } else |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5746 | ret->subtypes = xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5747 | child = child->next; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5748 | } |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5749 | while ((IS_SCHEMA(child, "unique")) || |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5750 | (IS_SCHEMA(child, "key")) || (IS_SCHEMA(child, "keyref"))) { |
Kasimier T. Buchcik | 48307f4 | 2004-11-12 15:16:25 +0000 | [diff] [blame] | 5751 | TODO child = child->next; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5752 | } |
| 5753 | if (child != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5754 | xmlSchemaPContentErr(ctxt, |
| 5755 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 5756 | &repName, (xmlSchemaTypePtr) ret, node, child, |
| 5757 | NULL, "(annotation?, ((simpleType | complexType)?, " |
| 5758 | "(unique | key | keyref)*))"); |
| 5759 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5760 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5761 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5762 | ctxt->container = oldcontainer; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5763 | /* |
| 5764 | * Cleanup. |
| 5765 | */ |
| 5766 | if (repName != NULL) |
| 5767 | xmlFree(repName); |
| 5768 | /* |
| 5769 | * NOTE: Element Declaration Representation OK 4. will be checked at a |
| 5770 | * different layer. |
| 5771 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5772 | return (ret); |
| 5773 | } |
| 5774 | |
| 5775 | /** |
| 5776 | * xmlSchemaParseUnion: |
| 5777 | * @ctxt: a schema validation context |
| 5778 | * @schema: the schema being built |
| 5779 | * @node: a subtree containing XML Schema informations |
| 5780 | * |
| 5781 | * parse a XML schema Union definition |
| 5782 | * *WARNING* this interface is highly subject to change |
| 5783 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5784 | * Returns -1 in case of error, 0 if the declaration is improper and |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5785 | * 1 in case of success. |
| 5786 | */ |
| 5787 | static xmlSchemaTypePtr |
| 5788 | xmlSchemaParseUnion(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5789 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5790 | { |
| 5791 | xmlSchemaTypePtr type, subtype, last = NULL; |
| 5792 | xmlNodePtr child = NULL; |
| 5793 | xmlChar name[30]; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5794 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5795 | |
| 5796 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5797 | return (NULL); |
| 5798 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5799 | snprintf((char *) name, 30, "#union %d", ctxt->counter++ + 1); |
| 5800 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5801 | if (type == NULL) |
| 5802 | return (NULL); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 5803 | type->type = XML_SCHEMA_TYPE_UNION; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5804 | type->node = node; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5805 | /* |
| 5806 | * Check for illegal attributes. |
| 5807 | */ |
| 5808 | attr = node->properties; |
| 5809 | while (attr != NULL) { |
| 5810 | if (attr->ns == NULL) { |
| 5811 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 5812 | (!xmlStrEqual(attr->name, BAD_CAST "memberTypes"))) { |
| 5813 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5814 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5815 | NULL, type, attr); |
| 5816 | } |
| 5817 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 5818 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5819 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5820 | NULL, type, attr); |
| 5821 | } |
| 5822 | attr = attr->next; |
| 5823 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5824 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5825 | /* |
| 5826 | * Attribute "memberTypes". This is a list of QNames. |
| 5827 | * TODO: Validate the QNames. |
| 5828 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5829 | type->base = xmlSchemaGetProp(ctxt, node, "memberTypes"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5830 | /* |
| 5831 | * And now for the children... |
| 5832 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5833 | child = node->children; |
| 5834 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5835 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5836 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5837 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5838 | while (IS_SCHEMA(child, "simpleType")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5839 | subtype = (xmlSchemaTypePtr) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5840 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5841 | if (subtype != NULL) { |
| 5842 | if (last == NULL) { |
| 5843 | type->subtypes = subtype; |
| 5844 | last = subtype; |
| 5845 | } else { |
| 5846 | last->next = subtype; |
| 5847 | last = subtype; |
| 5848 | } |
| 5849 | last->next = NULL; |
| 5850 | } |
| 5851 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5852 | } |
| 5853 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5854 | /* TODO: Think about the error code. */ |
| 5855 | xmlSchemaPContentErr(ctxt, |
| 5856 | XML_SCHEMAP_UNKNOWN_UNION_CHILD, |
| 5857 | NULL, type, node, child, NULL, "(annotation?, simpleType*)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5858 | } |
| 5859 | return (type); |
| 5860 | } |
| 5861 | |
| 5862 | /** |
| 5863 | * xmlSchemaParseList: |
| 5864 | * @ctxt: a schema validation context |
| 5865 | * @schema: the schema being built |
| 5866 | * @node: a subtree containing XML Schema informations |
| 5867 | * |
| 5868 | * parse a XML schema List definition |
| 5869 | * *WARNING* this interface is highly subject to change |
| 5870 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5871 | * Returns -1 in case of error, 0 if the declaration is improper and |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5872 | * 1 in case of success. |
| 5873 | */ |
| 5874 | static xmlSchemaTypePtr |
| 5875 | xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5876 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5877 | { |
| 5878 | xmlSchemaTypePtr type, subtype; |
| 5879 | xmlNodePtr child = NULL; |
| 5880 | xmlChar name[30]; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5881 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5882 | |
| 5883 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5884 | return (NULL); |
| 5885 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5886 | snprintf((char *) name, 30, "#list %d", ctxt->counter++ + 1); |
| 5887 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5888 | if (type == NULL) |
| 5889 | return (NULL); |
| 5890 | type->node = node; |
| 5891 | type->type = XML_SCHEMA_TYPE_LIST; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5892 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5893 | /* |
| 5894 | * Check for illegal attributes. |
| 5895 | */ |
| 5896 | attr = node->properties; |
| 5897 | while (attr != NULL) { |
| 5898 | if (attr->ns == NULL) { |
| 5899 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 5900 | (!xmlStrEqual(attr->name, BAD_CAST "itemType"))) { |
| 5901 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5902 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5903 | NULL, type, attr); |
| 5904 | } |
| 5905 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 5906 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5907 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5908 | NULL, type, attr); |
| 5909 | } |
| 5910 | attr = attr->next; |
| 5911 | } |
| 5912 | /* |
| 5913 | * Attribute "itemType". |
| 5914 | */ |
| 5915 | xmlSchemaPValAttrQName(ctxt, schema, NULL, NULL, |
| 5916 | node, "itemType", &(type->baseNs), NULL, &(type->base)); |
| 5917 | /* |
| 5918 | * And now for the children... |
| 5919 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5920 | child = node->children; |
| 5921 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5922 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5923 | child = child->next; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5924 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5925 | subtype = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5926 | if (IS_SCHEMA(child, "simpleType")) { |
| 5927 | if (type->base != NULL) { |
| 5928 | xmlSchemaPCustomErr(ctxt, |
| 5929 | XML_SCHEMAP_SRC_SIMPLE_TYPE_1, |
| 5930 | NULL, type, node, |
| 5931 | "The attribute 'itemType' and the <simpleType> child " |
| 5932 | "are mutually exclusive", NULL); |
| 5933 | } else { |
| 5934 | subtype = (xmlSchemaTypePtr) |
| 5935 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
| 5936 | type->subtypes = subtype; |
| 5937 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5938 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5939 | } |
| 5940 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5941 | /* TODO: Think about the error code. */ |
| 5942 | xmlSchemaPContentErr(ctxt, |
| 5943 | XML_SCHEMAP_UNKNOWN_LIST_CHILD, |
| 5944 | NULL, type, node, child, NULL, "(annotation?, simpleType?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5945 | } |
| 5946 | return (type); |
| 5947 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5948 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5949 | /** |
| 5950 | * xmlSchemaParseSimpleType: |
| 5951 | * @ctxt: a schema validation context |
| 5952 | * @schema: the schema being built |
| 5953 | * @node: a subtree containing XML Schema informations |
| 5954 | * |
| 5955 | * parse a XML schema Simple Type definition |
| 5956 | * *WARNING* this interface is highly subject to change |
| 5957 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5958 | * Returns -1 in case of error, 0 if the declaration is improper and |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5959 | * 1 in case of success. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5960 | */ |
| 5961 | static xmlSchemaTypePtr |
| 5962 | xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5963 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5964 | { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5965 | xmlSchemaTypePtr type, subtype, oldCtxtType, oldParentItem; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5966 | xmlNodePtr child = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5967 | const xmlChar *attrValue = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5968 | xmlChar *des = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5969 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5970 | |
| 5971 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5972 | return (NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5973 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5974 | if (topLevel) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5975 | attr = xmlSchemaGetPropNode(node, "name"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5976 | if (attr == NULL) { |
| 5977 | xmlSchemaPMissingAttrErr(ctxt, |
| 5978 | XML_SCHEMAP_S4S_ATTR_MISSING, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5979 | (xmlChar **) &xmlSchemaElemDesST, NULL, node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5980 | "name", NULL); |
| 5981 | return (NULL); |
| 5982 | } else if (xmlSchemaPValAttrNode(ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5983 | (xmlChar **) &xmlSchemaElemDesST, NULL, attr, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5984 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &attrValue) != 0) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5985 | return (NULL); |
| 5986 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5987 | } |
| 5988 | |
| 5989 | if (topLevel == 0) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5990 | char buf[40]; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5991 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5992 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5993 | * Parse as local simple type definition. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5994 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5995 | snprintf(buf, 39, "#ST %d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5996 | type = xmlSchemaAddType(ctxt, schema, (const xmlChar *)buf, NULL, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5997 | if (type == NULL) |
| 5998 | return (NULL); |
| 5999 | type->node = node; |
| 6000 | type->type = XML_SCHEMA_TYPE_SIMPLE; |
| 6001 | /* |
| 6002 | * Check for illegal attributes. |
| 6003 | */ |
| 6004 | attr = node->properties; |
| 6005 | while (attr != NULL) { |
| 6006 | if (attr->ns == NULL) { |
| 6007 | if (!xmlStrEqual(attr->name, BAD_CAST "id")) { |
| 6008 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6009 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6010 | &des, type, attr); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 6011 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6012 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 6013 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6014 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6015 | &des, type, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6016 | } |
| 6017 | attr = attr->next; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 6018 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6019 | } else { |
| 6020 | /* |
| 6021 | * Parse as global simple type definition. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6022 | * |
| 6023 | * Note that attrValue is the value of the attribute "name" here. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6024 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6025 | type = xmlSchemaAddType(ctxt, schema, attrValue, schema->targetNamespace, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6026 | if (type == NULL) |
| 6027 | return (NULL); |
| 6028 | type->node = node; |
| 6029 | type->type = XML_SCHEMA_TYPE_SIMPLE; |
| 6030 | type->flags |= XML_SCHEMAS_TYPE_GLOBAL; |
| 6031 | /* |
| 6032 | * Check for illegal attributes. |
| 6033 | */ |
| 6034 | attr = node->properties; |
| 6035 | while (attr != NULL) { |
| 6036 | if (attr->ns == NULL) { |
| 6037 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 6038 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6039 | (!xmlStrEqual(attr->name, BAD_CAST "final"))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6040 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6041 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6042 | &des, type, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6043 | } |
| 6044 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 6045 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6046 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6047 | &des, type, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6048 | } |
| 6049 | attr = attr->next; |
| 6050 | } |
| 6051 | /* |
| 6052 | * Attribute "final". |
| 6053 | */ |
| 6054 | attr = xmlSchemaGetPropNode(node, "final"); |
| 6055 | if (attr == NULL) { |
| 6056 | type->flags |= XML_SCHEMAS_TYPE_FINAL_DEFAULT; |
| 6057 | } else { |
| 6058 | attrValue = xmlSchemaGetProp(ctxt, node, "final"); |
| 6059 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(type->flags), |
| 6060 | -1, -1, XML_SCHEMAS_TYPE_FINAL_RESTRICTION, -1, |
| 6061 | XML_SCHEMAS_TYPE_FINAL_LIST, |
| 6062 | XML_SCHEMAS_TYPE_FINAL_UNION) != 0) { |
| 6063 | |
| 6064 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6065 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6066 | &des, type, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6067 | NULL, "(#all | List of (list | union | restriction)", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6068 | attrValue, NULL, NULL, NULL); |
| 6069 | } |
| 6070 | } |
| 6071 | } |
| 6072 | /* TODO: Check id. */ |
| 6073 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
| 6074 | /* |
| 6075 | * And now for the children... |
| 6076 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6077 | oldCtxtType = ctxt->ctxtType; |
| 6078 | oldParentItem = ctxt->parentItem; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6079 | ctxt->ctxtType = type; |
| 6080 | ctxt->parentItem = type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6081 | child = node->children; |
| 6082 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6083 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6084 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6085 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6086 | subtype = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6087 | if (IS_SCHEMA(child, "restriction")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6088 | subtype = (xmlSchemaTypePtr) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 6089 | xmlSchemaParseRestriction(ctxt, schema, child); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6090 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6091 | } else if (IS_SCHEMA(child, "list")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6092 | subtype = (xmlSchemaTypePtr) |
| 6093 | xmlSchemaParseList(ctxt, schema, child); |
| 6094 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6095 | } else if (IS_SCHEMA(child, "union")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6096 | subtype = (xmlSchemaTypePtr) |
| 6097 | xmlSchemaParseUnion(ctxt, schema, child); |
| 6098 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6099 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6100 | type->subtypes = subtype; |
| 6101 | if ((child != NULL) || (subtype == NULL)) { |
| 6102 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6103 | &des, type, node, child, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6104 | "(annotation?, (restriction | list | union))"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6105 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6106 | ctxt->parentItem = oldParentItem; |
| 6107 | ctxt->ctxtType = oldCtxtType; |
| 6108 | FREE_AND_NULL(des) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 6109 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6110 | return (type); |
| 6111 | } |
| 6112 | |
| 6113 | |
| 6114 | /** |
| 6115 | * xmlSchemaParseGroup: |
| 6116 | * @ctxt: a schema validation context |
| 6117 | * @schema: the schema being built |
| 6118 | * @node: a subtree containing XML Schema informations |
| 6119 | * |
| 6120 | * parse a XML schema Group definition |
| 6121 | * *WARNING* this interface is highly subject to change |
| 6122 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6123 | * Returns -1 in case of error, 0 if the declaration is improper and |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6124 | * 1 in case of success. |
| 6125 | */ |
| 6126 | static xmlSchemaTypePtr |
| 6127 | xmlSchemaParseGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6128 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6129 | { |
| 6130 | xmlSchemaTypePtr type, subtype; |
| 6131 | xmlNodePtr child = NULL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 6132 | const xmlChar *name; |
| 6133 | const xmlChar *ref = NULL, *refNs = NULL; |
| 6134 | char buf[100]; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 6135 | int minOccurs, maxOccurs; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6136 | |
| 6137 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 6138 | return (NULL); |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 6139 | /* |
| 6140 | * TODO: Validate the element even if no item is created |
| 6141 | * (i.e. min/maxOccurs == 0). |
| 6142 | */ |
| 6143 | minOccurs = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "nonNegativeInteger"); |
| 6144 | maxOccurs = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, "(nonNegativeInteger | unbounded)"); |
| 6145 | if ((minOccurs == 0) && (maxOccurs == 0)) { |
| 6146 | return (NULL); |
| 6147 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 6148 | name = xmlSchemaGetProp(ctxt, node, "name"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6149 | if (name == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6150 | ref = xmlGetQNameProp(ctxt, node, "ref", &refNs); |
| 6151 | if (ref == NULL) { |
| 6152 | xmlSchemaPErr2(ctxt, node, child, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6153 | XML_SCHEMAP_GROUP_NONAME_NOREF, |
| 6154 | "Group definition or particle: One of the attributes \"name\" " |
| 6155 | "or \"ref\" must be present.\n", NULL, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6156 | return (NULL); |
| 6157 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 6158 | if (refNs == NULL) |
| 6159 | refNs = schema->targetNamespace; |
| 6160 | snprintf(buf, 99, "anongroup %d", ctxt->counter++ + 1); |
| 6161 | name = (const xmlChar *) buf; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6162 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6163 | type = xmlSchemaAddGroup(ctxt, schema, name, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6164 | if (type == NULL) |
| 6165 | return (NULL); |
| 6166 | type->node = node; |
| 6167 | type->type = XML_SCHEMA_TYPE_GROUP; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6168 | if (topLevel) |
| 6169 | type->flags |= XML_SCHEMAS_TYPE_GLOBAL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 6170 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6171 | type->ref = ref; |
| 6172 | type->refNs = refNs; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 6173 | type->minOccurs = minOccurs; |
| 6174 | type->maxOccurs = maxOccurs; |
| 6175 | xmlSchemaPCheckParticleCorrect_2(ctxt, type, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6176 | node, type->minOccurs, type->maxOccurs); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6177 | |
| 6178 | child = node->children; |
| 6179 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6180 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6181 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6182 | } |
| 6183 | subtype = NULL; |
| 6184 | if (IS_SCHEMA(child, "all")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6185 | subtype = (xmlSchemaTypePtr) |
| 6186 | xmlSchemaParseAll(ctxt, schema, child); |
| 6187 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6188 | } else if (IS_SCHEMA(child, "choice")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6189 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 6190 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6191 | } else if (IS_SCHEMA(child, "sequence")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6192 | subtype = (xmlSchemaTypePtr) |
| 6193 | xmlSchemaParseSequence(ctxt, schema, child); |
| 6194 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6195 | } |
| 6196 | if (subtype != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6197 | type->subtypes = subtype; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6198 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6199 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_GROUP_CHILD, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6200 | "Group definition \"%s\" has unexpected content.\n", type->name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6201 | NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6202 | } |
| 6203 | |
| 6204 | return (type); |
| 6205 | } |
| 6206 | |
| 6207 | /** |
| 6208 | * xmlSchemaParseAll: |
| 6209 | * @ctxt: a schema validation context |
| 6210 | * @schema: the schema being built |
| 6211 | * @node: a subtree containing XML Schema informations |
| 6212 | * |
| 6213 | * parse a XML schema All definition |
| 6214 | * *WARNING* this interface is highly subject to change |
| 6215 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6216 | * Returns -1 in case of error, 0 if the declaration is improper and |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6217 | * 1 in case of success. |
| 6218 | */ |
| 6219 | static xmlSchemaTypePtr |
| 6220 | xmlSchemaParseAll(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6221 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6222 | { |
| 6223 | xmlSchemaTypePtr type, subtype, last = NULL; |
| 6224 | xmlNodePtr child = NULL; |
| 6225 | xmlChar name[30]; |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 6226 | const xmlChar *oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6227 | |
| 6228 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 6229 | return (NULL); |
| 6230 | |
| 6231 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6232 | snprintf((char *) name, 30, "all%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6233 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6234 | if (type == NULL) |
| 6235 | return (NULL); |
| 6236 | type->node = node; |
Daniel Veillard | 7646b18 | 2002-04-20 06:41:40 +0000 | [diff] [blame] | 6237 | type->type = XML_SCHEMA_TYPE_ALL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 6238 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6239 | |
| 6240 | type->minOccurs = xmlGetMinOccurs(ctxt, node, 0, 1, 1, "(0 | 1)"); |
| 6241 | type->maxOccurs = xmlGetMaxOccurs(ctxt, node, 1, 1, 1, "1"); |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 6242 | |
| 6243 | oldcontainer = ctxt->container; |
| 6244 | ctxt->container = (const xmlChar *) name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6245 | child = node->children; |
| 6246 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6247 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6248 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6249 | } |
| 6250 | while (IS_SCHEMA(child, "element")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6251 | subtype = (xmlSchemaTypePtr) |
| 6252 | xmlSchemaParseElement(ctxt, schema, child, 0); |
| 6253 | if (subtype != NULL) { |
William M. Brack | b15351e | 2003-12-27 04:34:42 +0000 | [diff] [blame] | 6254 | if (subtype->minOccurs > 1) |
| 6255 | xmlSchemaPErr(ctxt, child, XML_SCHEMAP_INVALID_MINOCCURS, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6256 | "invalid value for minOccurs (must be 0 or 1).\n", |
William M. Brack | b15351e | 2003-12-27 04:34:42 +0000 | [diff] [blame] | 6257 | NULL, NULL); |
| 6258 | if (subtype->maxOccurs > 1) |
| 6259 | xmlSchemaPErr(ctxt, child, XML_SCHEMAP_INVALID_MAXOCCURS, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6260 | "invalid value for maxOccurs (must be 0 or 1).\n", |
William M. Brack | b15351e | 2003-12-27 04:34:42 +0000 | [diff] [blame] | 6261 | NULL, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6262 | if (last == NULL) { |
| 6263 | type->subtypes = subtype; |
| 6264 | last = subtype; |
| 6265 | } else { |
| 6266 | last->next = subtype; |
| 6267 | last = subtype; |
| 6268 | } |
| 6269 | last->next = NULL; |
| 6270 | } |
| 6271 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6272 | } |
| 6273 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6274 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_ALL_CHILD, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6275 | "<all> has unexpected content.\n", type->name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6276 | NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6277 | } |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 6278 | ctxt->container = oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6279 | return (type); |
| 6280 | } |
| 6281 | |
| 6282 | /** |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 6283 | * xmlSchemaCleanupDoc: |
| 6284 | * @ctxt: a schema validation context |
| 6285 | * @node: the root of the document. |
| 6286 | * |
| 6287 | * removes unwanted nodes in a schemas document tree |
| 6288 | */ |
| 6289 | static void |
| 6290 | xmlSchemaCleanupDoc(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr root) |
| 6291 | { |
| 6292 | xmlNodePtr delete, cur; |
| 6293 | |
| 6294 | if ((ctxt == NULL) || (root == NULL)) return; |
| 6295 | |
| 6296 | /* |
| 6297 | * Remove all the blank text nodes |
| 6298 | */ |
| 6299 | delete = NULL; |
| 6300 | cur = root; |
| 6301 | while (cur != NULL) { |
| 6302 | if (delete != NULL) { |
| 6303 | xmlUnlinkNode(delete); |
| 6304 | xmlFreeNode(delete); |
| 6305 | delete = NULL; |
| 6306 | } |
| 6307 | if (cur->type == XML_TEXT_NODE) { |
| 6308 | if (IS_BLANK_NODE(cur)) { |
| 6309 | if (xmlNodeGetSpacePreserve(cur) != 1) { |
| 6310 | delete = cur; |
| 6311 | } |
| 6312 | } |
| 6313 | } else if ((cur->type != XML_ELEMENT_NODE) && |
| 6314 | (cur->type != XML_CDATA_SECTION_NODE)) { |
| 6315 | delete = cur; |
| 6316 | goto skip_children; |
| 6317 | } |
| 6318 | |
| 6319 | /* |
| 6320 | * Skip to next node |
| 6321 | */ |
| 6322 | if (cur->children != NULL) { |
| 6323 | if ((cur->children->type != XML_ENTITY_DECL) && |
| 6324 | (cur->children->type != XML_ENTITY_REF_NODE) && |
| 6325 | (cur->children->type != XML_ENTITY_NODE)) { |
| 6326 | cur = cur->children; |
| 6327 | continue; |
| 6328 | } |
| 6329 | } |
| 6330 | skip_children: |
| 6331 | if (cur->next != NULL) { |
| 6332 | cur = cur->next; |
| 6333 | continue; |
| 6334 | } |
| 6335 | |
| 6336 | do { |
| 6337 | cur = cur->parent; |
| 6338 | if (cur == NULL) |
| 6339 | break; |
| 6340 | if (cur == root) { |
| 6341 | cur = NULL; |
| 6342 | break; |
| 6343 | } |
| 6344 | if (cur->next != NULL) { |
| 6345 | cur = cur->next; |
| 6346 | break; |
| 6347 | } |
| 6348 | } while (cur != NULL); |
| 6349 | } |
| 6350 | if (delete != NULL) { |
| 6351 | xmlUnlinkNode(delete); |
| 6352 | xmlFreeNode(delete); |
| 6353 | delete = NULL; |
| 6354 | } |
| 6355 | } |
| 6356 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6357 | |
| 6358 | /** |
| 6359 | * xmlSchemaImportSchema |
| 6360 | * |
| 6361 | * @ctxt: a schema validation context |
| 6362 | * @schemaLocation: an URI defining where to find the imported schema |
| 6363 | * |
| 6364 | * import a XML schema |
| 6365 | * *WARNING* this interface is highly subject to change |
| 6366 | * |
| 6367 | * Returns -1 in case of error and 1 in case of success. |
| 6368 | */ |
| 6369 | #if 0 |
| 6370 | static xmlSchemaImportPtr |
| 6371 | xmlSchemaImportSchema(xmlSchemaParserCtxtPtr ctxt, |
| 6372 | const xmlChar *schemaLocation) |
| 6373 | { |
| 6374 | xmlSchemaImportPtr import; |
| 6375 | xmlSchemaParserCtxtPtr newctxt; |
| 6376 | |
| 6377 | newctxt = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 6378 | if (newctxt == NULL) { |
| 6379 | xmlSchemaPErrMemory(ctxt, "allocating schema parser context", |
| 6380 | NULL); |
| 6381 | return (NULL); |
| 6382 | } |
| 6383 | memset(newctxt, 0, sizeof(xmlSchemaParserCtxt)); |
| 6384 | /* Keep the same dictionnary for parsing, really */ |
| 6385 | xmlDictReference(ctxt->dict); |
| 6386 | newctxt->dict = ctxt->dict; |
| 6387 | newctxt->includes = 0; |
| 6388 | newctxt->URL = xmlDictLookup(newctxt->dict, schemaLocation, -1); |
| 6389 | |
| 6390 | xmlSchemaSetParserErrors(newctxt, ctxt->error, ctxt->warning, |
| 6391 | ctxt->userData); |
| 6392 | |
| 6393 | import = (xmlSchemaImport*) xmlMalloc(sizeof(xmlSchemaImport)); |
| 6394 | if (import == NULL) { |
| 6395 | xmlSchemaPErrMemory(NULL, "allocating imported schema", |
| 6396 | NULL); |
| 6397 | xmlSchemaFreeParserCtxt(newctxt); |
| 6398 | return (NULL); |
| 6399 | } |
| 6400 | |
| 6401 | memset(import, 0, sizeof(xmlSchemaImport)); |
| 6402 | import->schemaLocation = xmlDictLookup(ctxt->dict, schemaLocation, -1); |
| 6403 | import->schema = xmlSchemaParse(newctxt); |
| 6404 | |
| 6405 | if (import->schema == NULL) { |
| 6406 | /* FIXME use another error enum here ? */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 6407 | xmlSchemaPErr(ctxt, NULL, XML_SCHEMAP_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6408 | "Failed to import schema from location \"%s\".\n", |
| 6409 | schemaLocation, NULL); |
| 6410 | |
| 6411 | xmlSchemaFreeParserCtxt(newctxt); |
| 6412 | /* The schemaLocation is held by the dictionary. |
| 6413 | if (import->schemaLocation != NULL) |
| 6414 | xmlFree((xmlChar *)import->schemaLocation); |
| 6415 | */ |
| 6416 | xmlFree(import); |
| 6417 | return NULL; |
| 6418 | } |
| 6419 | |
| 6420 | xmlSchemaFreeParserCtxt(newctxt); |
| 6421 | return import; |
| 6422 | } |
| 6423 | #endif |
| 6424 | |
| 6425 | static void |
| 6426 | xmlSchemaClearSchemaDefaults(xmlSchemaPtr schema) |
| 6427 | { |
| 6428 | if (schema->flags & XML_SCHEMAS_QUALIF_ELEM) |
| 6429 | schema->flags ^= XML_SCHEMAS_QUALIF_ELEM; |
| 6430 | |
| 6431 | if (schema->flags & XML_SCHEMAS_QUALIF_ATTR) |
| 6432 | schema->flags ^= XML_SCHEMAS_QUALIF_ATTR; |
| 6433 | |
| 6434 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION) |
| 6435 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_EXTENSION; |
| 6436 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION) |
| 6437 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION; |
| 6438 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_LIST) |
| 6439 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_LIST; |
| 6440 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_UNION) |
| 6441 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_UNION; |
| 6442 | |
| 6443 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION) |
| 6444 | schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION; |
| 6445 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION) |
| 6446 | schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION; |
| 6447 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION) |
| 6448 | schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION; |
| 6449 | } |
| 6450 | |
| 6451 | static void |
| 6452 | xmlSchemaParseSchemaDefaults(xmlSchemaParserCtxtPtr ctxt, |
| 6453 | xmlSchemaPtr schema, |
| 6454 | xmlNodePtr node) |
| 6455 | { |
| 6456 | xmlAttrPtr attr; |
| 6457 | const xmlChar *val; |
| 6458 | |
| 6459 | attr = xmlSchemaGetPropNode(node, "elementFormDefault"); |
| 6460 | if (attr != NULL) { |
| 6461 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 6462 | if (xmlSchemaPValAttrFormDefault(val, &schema->flags, |
| 6463 | XML_SCHEMAS_QUALIF_ELEM) != 0) { |
| 6464 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6465 | XML_SCHEMAP_ELEMFORMDEFAULT_VALUE, |
| 6466 | NULL, NULL, (xmlNodePtr) attr, NULL, |
| 6467 | "(qualified | unqualified)", val, NULL, NULL, NULL); |
| 6468 | } |
| 6469 | } |
| 6470 | |
| 6471 | attr = xmlSchemaGetPropNode(node, "attributeFormDefault"); |
| 6472 | if (attr != NULL) { |
| 6473 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 6474 | if (xmlSchemaPValAttrFormDefault(val, &schema->flags, |
| 6475 | XML_SCHEMAS_QUALIF_ATTR) != 0) { |
| 6476 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6477 | XML_SCHEMAP_ATTRFORMDEFAULT_VALUE, |
| 6478 | NULL, NULL, (xmlNodePtr) attr, NULL, |
| 6479 | "(qualified | unqualified)", val, NULL, NULL, NULL); |
| 6480 | } |
| 6481 | } |
| 6482 | |
| 6483 | attr = xmlSchemaGetPropNode(node, "finalDefault"); |
| 6484 | if (attr != NULL) { |
| 6485 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 6486 | if (xmlSchemaPValAttrBlockFinal(val, &(schema->flags), -1, |
| 6487 | XML_SCHEMAS_FINAL_DEFAULT_EXTENSION, |
| 6488 | XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION, |
| 6489 | -1, |
| 6490 | XML_SCHEMAS_FINAL_DEFAULT_LIST, |
| 6491 | XML_SCHEMAS_FINAL_DEFAULT_UNION) != 0) { |
| 6492 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6493 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 6494 | NULL, NULL, (xmlNodePtr) attr, NULL, |
| 6495 | "(#all | List of (extension | restriction | list | union))", |
| 6496 | val, NULL, NULL, NULL); |
| 6497 | } |
| 6498 | } |
| 6499 | |
| 6500 | attr = xmlSchemaGetPropNode(node, "blockDefault"); |
| 6501 | if (attr != NULL) { |
| 6502 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 6503 | if (xmlSchemaPValAttrBlockFinal(val, &(schema->flags), -1, |
| 6504 | XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION, |
| 6505 | XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION, |
| 6506 | XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION, -1, -1) != 0) { |
| 6507 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6508 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 6509 | NULL, NULL, (xmlNodePtr) attr, NULL, |
| 6510 | "(#all | List of (extension | restriction | substitution))", |
| 6511 | val, NULL, NULL, NULL); |
| 6512 | } |
| 6513 | } |
| 6514 | } |
| 6515 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 6516 | /** |
| 6517 | * xmlSchemaParseSchemaTopLevel: |
| 6518 | * @ctxt: a schema validation context |
| 6519 | * @schema: the schemas |
| 6520 | * @nodes: the list of top level nodes |
| 6521 | * |
| 6522 | * Returns the internal XML Schema structure built from the resource or |
| 6523 | * NULL in case of error |
| 6524 | */ |
| 6525 | static void |
| 6526 | xmlSchemaParseSchemaTopLevel(xmlSchemaParserCtxtPtr ctxt, |
| 6527 | xmlSchemaPtr schema, xmlNodePtr nodes) |
| 6528 | { |
| 6529 | xmlNodePtr child; |
| 6530 | xmlSchemaAnnotPtr annot; |
| 6531 | |
| 6532 | if ((ctxt == NULL) || (schema == NULL) || (nodes == NULL)) |
| 6533 | return; |
| 6534 | |
| 6535 | child = nodes; |
| 6536 | while ((IS_SCHEMA(child, "include")) || |
| 6537 | (IS_SCHEMA(child, "import")) || |
| 6538 | (IS_SCHEMA(child, "redefine")) || |
| 6539 | (IS_SCHEMA(child, "annotation"))) { |
| 6540 | if (IS_SCHEMA(child, "annotation")) { |
| 6541 | annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6542 | if (schema->annot == NULL) |
| 6543 | schema->annot = annot; |
| 6544 | else |
| 6545 | xmlSchemaFreeAnnot(annot); |
| 6546 | } else if (IS_SCHEMA(child, "import")) { |
| 6547 | xmlSchemaParseImport(ctxt, schema, child); |
| 6548 | } else if (IS_SCHEMA(child, "include")) { |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 6549 | ctxt->includes++; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 6550 | xmlSchemaParseInclude(ctxt, schema, child); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 6551 | ctxt->includes--; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 6552 | } else if (IS_SCHEMA(child, "redefine")) { |
| 6553 | TODO |
| 6554 | } |
| 6555 | child = child->next; |
| 6556 | } |
| 6557 | while (child != NULL) { |
| 6558 | if (IS_SCHEMA(child, "complexType")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6559 | xmlSchemaParseComplexType(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 6560 | child = child->next; |
| 6561 | } else if (IS_SCHEMA(child, "simpleType")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6562 | xmlSchemaParseSimpleType(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 6563 | child = child->next; |
| 6564 | } else if (IS_SCHEMA(child, "element")) { |
| 6565 | xmlSchemaParseElement(ctxt, schema, child, 1); |
| 6566 | child = child->next; |
| 6567 | } else if (IS_SCHEMA(child, "attribute")) { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6568 | xmlSchemaParseAttribute(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 6569 | child = child->next; |
| 6570 | } else if (IS_SCHEMA(child, "attributeGroup")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6571 | xmlSchemaParseAttributeGroup(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 6572 | child = child->next; |
| 6573 | } else if (IS_SCHEMA(child, "group")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6574 | xmlSchemaParseGroup(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 6575 | child = child->next; |
| 6576 | } else if (IS_SCHEMA(child, "notation")) { |
| 6577 | xmlSchemaParseNotation(ctxt, schema, child); |
| 6578 | child = child->next; |
| 6579 | } else { |
| 6580 | xmlSchemaPErr2(ctxt, NULL, child, |
| 6581 | XML_SCHEMAP_UNKNOWN_SCHEMAS_CHILD, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6582 | "Unexpected element \"%s\" as child of <schema>.\n", |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 6583 | child->name, NULL); |
| 6584 | child = child->next; |
| 6585 | } |
| 6586 | while (IS_SCHEMA(child, "annotation")) { |
| 6587 | annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6588 | if (schema->annot == NULL) |
| 6589 | schema->annot = annot; |
| 6590 | else |
| 6591 | xmlSchemaFreeAnnot(annot); |
| 6592 | child = child->next; |
| 6593 | } |
| 6594 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 6595 | ctxt->parentItem = NULL; |
| 6596 | ctxt->ctxtType = NULL; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 6597 | } |
| 6598 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6599 | static xmlSchemaImportPtr |
| 6600 | xmlSchemaAddImport(xmlSchemaParserCtxtPtr ctxt, |
| 6601 | xmlHashTablePtr *imports, |
| 6602 | const xmlChar *nsName) |
| 6603 | { |
| 6604 | xmlSchemaImportPtr ret; |
| 6605 | |
| 6606 | if (*imports == NULL) { |
| 6607 | *imports = xmlHashCreate(10); |
| 6608 | if (*imports == NULL) { |
| 6609 | xmlSchemaPCustomErr(ctxt, |
| 6610 | XML_SCHEMAP_FAILED_BUILD_IMPORT, |
| 6611 | NULL, NULL, (xmlNodePtr) ctxt->doc, |
| 6612 | "Internal error: failed to build the import table", |
| 6613 | NULL); |
| 6614 | return (NULL); |
| 6615 | } |
| 6616 | } |
| 6617 | ret = (xmlSchemaImport*) xmlMalloc(sizeof(xmlSchemaImport)); |
| 6618 | if (ret == NULL) { |
| 6619 | xmlSchemaPErrMemory(NULL, "allocating import struct", NULL); |
| 6620 | return (NULL); |
| 6621 | } |
| 6622 | memset(ret, 0, sizeof(xmlSchemaImport)); |
| 6623 | if (nsName == NULL) |
| 6624 | nsName = XML_SCHEMAS_NO_NAMESPACE; |
| 6625 | xmlHashAddEntry(*imports, nsName, ret); |
| 6626 | |
| 6627 | return (ret); |
| 6628 | } |
| 6629 | |
| 6630 | static int |
| 6631 | xmlSchemaAcquireSchemaDoc(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6632 | xmlSchemaPtr schema, |
| 6633 | xmlNodePtr node, |
| 6634 | const xmlChar *nsName, |
| 6635 | const xmlChar *location, |
| 6636 | xmlDocPtr *doc, |
| 6637 | const xmlChar **targetNamespace, |
| 6638 | int absolute) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6639 | { |
| 6640 | xmlParserCtxtPtr parserCtxt; |
| 6641 | xmlSchemaImportPtr import; |
| 6642 | const xmlChar *ns; |
| 6643 | xmlNodePtr root; |
| 6644 | |
| 6645 | /* |
| 6646 | * NOTE: This will be used for <import>, <xsi:schemaLocation> and |
| 6647 | * <xsi:noNamespaceSchemaLocation>. |
| 6648 | */ |
| 6649 | *doc = NULL; |
| 6650 | /* |
| 6651 | * Given that the schemaLocation [attribute] is only a hint, it is open |
| 6652 | * to applications to ignore all but the first <import> for a given |
| 6653 | * namespace, regardless of the ·actual value· of schemaLocation, but |
| 6654 | * such a strategy risks missing useful information when new |
| 6655 | * schemaLocations are offered. |
| 6656 | * |
| 6657 | * XSV (ver 2.5-2) does use the first <import> which resolves to a valid schema. |
| 6658 | * Xerces-J (ver 2.5.1) ignores all but the first given <import> - regardless if |
| 6659 | * valid or not. |
| 6660 | * We will follow XSV here. |
| 6661 | */ |
| 6662 | if (location == NULL) { |
| 6663 | /* |
| 6664 | * Schema Document Location Strategy: |
| 6665 | * |
| 6666 | * 3 Based on the namespace name, identify an existing schema document, |
| 6667 | * either as a resource which is an XML document or a <schema> element |
| 6668 | * information item, in some local schema repository; |
| 6669 | * |
| 6670 | * 5 Attempt to resolve the namespace name to locate such a resource. |
| 6671 | * |
| 6672 | * NOTE: Those stategies are not supported, so we will skip. |
| 6673 | */ |
| 6674 | return (0); |
| 6675 | } |
| 6676 | if (nsName == NULL) |
| 6677 | ns = XML_SCHEMAS_NO_NAMESPACE; |
| 6678 | else |
| 6679 | ns = nsName; |
| 6680 | |
| 6681 | import = xmlHashLookup(schema->schemasImports, ns); |
| 6682 | if (import != NULL) { |
| 6683 | /* |
| 6684 | * There was a valid resource for the specified namespace already |
| 6685 | * defined, so skip. |
| 6686 | * TODO: This might be changed someday to allow import of |
| 6687 | * components from multiple documents for a single target namespace. |
| 6688 | */ |
| 6689 | return (0); |
| 6690 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6691 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6692 | /* |
| 6693 | * Schema Document Location Strategy: |
| 6694 | * |
| 6695 | * 2 Based on the location URI, identify an existing schema document, |
| 6696 | * either as a resource which is an XML document or a <schema> element |
| 6697 | * information item, in some local schema repository; |
| 6698 | * |
| 6699 | * 4 Attempt to resolve the location URI, to locate a resource on the |
| 6700 | * web which is or contains or references a <schema> element; |
| 6701 | * TODO: Hmm, I don't know if the reference stuff in 4. will work. |
| 6702 | * |
| 6703 | */ |
| 6704 | if ((absolute == 0) && (node != NULL)) { |
| 6705 | xmlChar *base, *URI; |
| 6706 | |
| 6707 | base = xmlNodeGetBase(node->doc, node); |
| 6708 | if (base == NULL) { |
| 6709 | URI = xmlBuildURI(location, node->doc->URL); |
| 6710 | } else { |
| 6711 | URI = xmlBuildURI(location, base); |
| 6712 | xmlFree(base); |
| 6713 | } |
| 6714 | if (URI != NULL) { |
| 6715 | location = xmlDictLookup(ctxt->dict, URI, -1); |
| 6716 | xmlFree(URI); |
| 6717 | } |
| 6718 | } |
| 6719 | parserCtxt = xmlNewParserCtxt(); |
| 6720 | if (parserCtxt == NULL) { |
| 6721 | xmlSchemaPErrMemory(NULL, "xmlSchemaParseImport: " |
| 6722 | "allocating a parser context", NULL); |
| 6723 | return(-1); |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 6724 | } |
| 6725 | |
| 6726 | if ((ctxt->dict != NULL) && (parserCtxt->dict != NULL)) { |
| 6727 | xmlDictFree(parserCtxt->dict); |
| 6728 | parserCtxt->dict = ctxt->dict; |
| 6729 | xmlDictReference(parserCtxt->dict); |
| 6730 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6731 | |
| 6732 | *doc = xmlCtxtReadFile(parserCtxt, (const char *) location, |
| 6733 | NULL, SCHEMAS_PARSE_OPTIONS); |
| 6734 | |
| 6735 | /* |
| 6736 | * 2.1 The referent is (a fragment of) a resource which is an |
| 6737 | * XML document (see clause 1.1), which in turn corresponds to |
| 6738 | * a <schema> element information item in a well-formed information |
| 6739 | * set, which in turn corresponds to a valid schema. |
| 6740 | * TODO: What to do with the "fragment" stuff? |
| 6741 | * |
| 6742 | * 2.2 The referent is a <schema> element information item in |
| 6743 | * a well-formed information set, which in turn corresponds |
| 6744 | * to a valid schema. |
| 6745 | * NOTE: 2.2 won't apply, since only XML documents will be processed |
| 6746 | * here. |
| 6747 | */ |
| 6748 | if (*doc == NULL) { |
| 6749 | xmlErrorPtr lerr; |
| 6750 | /* |
| 6751 | * It is *not* an error for the application schema reference |
| 6752 | * strategy to fail. |
| 6753 | * |
| 6754 | * If the doc is NULL and the parser error is an IO error we |
| 6755 | * will assume that the resource could not be located or accessed. |
| 6756 | * |
| 6757 | * TODO: Try to find specific error codes to react only on |
| 6758 | * localisation failures. |
| 6759 | * |
| 6760 | * TODO, FIXME: Check the spec: is a namespace added to the imported |
| 6761 | * namespaces, even if the schemaLocation did not provide |
| 6762 | * a resource? I guess so, since omitting the "schemaLocation" |
| 6763 | * attribute, imports a namespace as well. |
| 6764 | */ |
| 6765 | lerr = xmlGetLastError(); |
| 6766 | if ((lerr != NULL) && (lerr->domain == XML_FROM_IO)) { |
| 6767 | xmlFreeParserCtxt(parserCtxt); |
| 6768 | return(0); |
| 6769 | } |
| 6770 | |
| 6771 | xmlSchemaPCustomErr(ctxt, |
| 6772 | XML_SCHEMAP_SRC_IMPORT_2_1, |
| 6773 | NULL, NULL, node, |
| 6774 | "Failed to parse the resource '%s' for import", |
| 6775 | location); |
| 6776 | xmlFreeParserCtxt(parserCtxt); |
| 6777 | return(XML_SCHEMAP_SRC_IMPORT_2_1); |
| 6778 | } |
| 6779 | xmlFreeParserCtxt(parserCtxt); |
| 6780 | |
| 6781 | root = xmlDocGetRootElement(*doc); |
| 6782 | if (root == NULL) { |
| 6783 | xmlSchemaPCustomErr(ctxt, |
| 6784 | XML_SCHEMAP_SRC_IMPORT_2_1, |
| 6785 | NULL, NULL, node, |
| 6786 | "The XML document '%s' to be imported has no document " |
| 6787 | "element", location); |
| 6788 | xmlFreeDoc(*doc); |
| 6789 | *doc = NULL; |
| 6790 | return (XML_SCHEMAP_SRC_IMPORT_2_1); |
| 6791 | } |
| 6792 | |
| 6793 | xmlSchemaCleanupDoc(ctxt, root); |
| 6794 | |
| 6795 | if (!IS_SCHEMA(root, "schema")) { |
| 6796 | xmlSchemaPCustomErr(ctxt, |
| 6797 | XML_SCHEMAP_SRC_IMPORT_2_1, |
| 6798 | NULL, NULL, node, |
| 6799 | "The XML document '%s' to be imported is not a XML schema document", |
| 6800 | location); |
| 6801 | xmlFreeDoc(*doc); |
| 6802 | *doc = NULL; |
| 6803 | return (XML_SCHEMAP_SRC_IMPORT_2_1); |
| 6804 | } |
| 6805 | *targetNamespace = xmlSchemaGetProp(ctxt, root, "targetNamespace"); |
| 6806 | /* |
| 6807 | * Schema Representation Constraint: Import Constraints and Semantics |
| 6808 | */ |
| 6809 | if (nsName == NULL) { |
| 6810 | if (*targetNamespace != NULL) { |
| 6811 | xmlSchemaPCustomErr(ctxt, |
| 6812 | XML_SCHEMAP_SRC_IMPORT_3_2, |
| 6813 | NULL, NULL, node, |
| 6814 | "The XML schema to be imported is not expected " |
| 6815 | "to have a target namespace; this differs from " |
| 6816 | "its target namespace of '%s'", *targetNamespace); |
| 6817 | xmlFreeDoc(*doc); |
| 6818 | *doc = NULL; |
| 6819 | return (XML_SCHEMAP_SRC_IMPORT_3_2); |
| 6820 | } |
| 6821 | } else { |
| 6822 | if (*targetNamespace == NULL) { |
| 6823 | xmlSchemaPCustomErr(ctxt, |
| 6824 | XML_SCHEMAP_SRC_IMPORT_3_1, |
| 6825 | NULL, NULL, node, |
| 6826 | "The XML schema to be imported is expected to have a target " |
| 6827 | "namespace of '%s'", nsName); |
| 6828 | xmlFreeDoc(*doc); |
| 6829 | *doc = NULL; |
| 6830 | return (XML_SCHEMAP_SRC_IMPORT_3_1); |
| 6831 | } else if (!xmlStrEqual(*targetNamespace, nsName)) { |
| 6832 | xmlSchemaPCustomErrExt(ctxt, |
| 6833 | XML_SCHEMAP_SRC_IMPORT_3_1, |
| 6834 | NULL, NULL, node, |
| 6835 | "The XML schema to be imported is expected to have a " |
| 6836 | "target namespace of '%s'; this differs from " |
| 6837 | "its target namespace of '%s'", |
| 6838 | nsName, *targetNamespace, NULL); |
| 6839 | xmlFreeDoc(*doc); |
| 6840 | *doc = NULL; |
| 6841 | return (XML_SCHEMAP_SRC_IMPORT_3_1); |
| 6842 | } |
| 6843 | } |
| 6844 | |
| 6845 | import = xmlSchemaAddImport(ctxt, &(schema->schemasImports), nsName); |
| 6846 | if (import == NULL) { |
| 6847 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_FAILED_BUILD_IMPORT, |
| 6848 | NULL, NULL, NULL, |
| 6849 | "Internal error: xmlSchemaAcquireSchemaDoc, " |
| 6850 | "failed to build import table", NULL); |
| 6851 | xmlFreeDoc(*doc); |
| 6852 | *doc = NULL; |
| 6853 | return (-1); |
| 6854 | } |
| 6855 | import->schemaLocation = location; |
| 6856 | import->doc = *doc; |
| 6857 | return (0); |
| 6858 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6859 | |
| 6860 | /** |
| 6861 | * xmlSchemaParseImport: |
| 6862 | * @ctxt: a schema validation context |
| 6863 | * @schema: the schema being built |
| 6864 | * @node: a subtree containing XML Schema informations |
| 6865 | * |
| 6866 | * parse a XML schema Import definition |
| 6867 | * *WARNING* this interface is highly subject to change |
| 6868 | * |
| 6869 | * Returns 0 in case of success, a positive error code if |
| 6870 | * not valid and -1 in case of an internal error. |
| 6871 | */ |
| 6872 | static int |
| 6873 | xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 6874 | xmlNodePtr node) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6875 | { |
| 6876 | xmlNodePtr child; |
| 6877 | const xmlChar *namespace = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6878 | const xmlChar *schemaLocation = NULL; |
| 6879 | const xmlChar *targetNamespace, *oldTNS, *url; |
| 6880 | xmlAttrPtr attr; |
| 6881 | xmlDocPtr doc; |
| 6882 | xmlNodePtr root; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6883 | int flags, ret = 0; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6884 | |
| 6885 | |
| 6886 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 6887 | return (-1); |
| 6888 | |
| 6889 | /* |
| 6890 | * Check for illegal attributes. |
| 6891 | */ |
| 6892 | attr = node->properties; |
| 6893 | while (attr != NULL) { |
| 6894 | if (attr->ns == NULL) { |
| 6895 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 6896 | (!xmlStrEqual(attr->name, BAD_CAST "namespace")) && |
| 6897 | (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation"))) { |
| 6898 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6899 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6900 | NULL, NULL, attr); |
| 6901 | } |
| 6902 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 6903 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6904 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6905 | NULL, NULL, attr); |
| 6906 | } |
| 6907 | attr = attr->next; |
| 6908 | } |
| 6909 | /* |
| 6910 | * Extract and validate attributes. |
| 6911 | */ |
| 6912 | if (xmlSchemaPValAttr(ctxt, NULL, NULL, node, |
| 6913 | "namespace", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
| 6914 | &namespace) != 0) { |
| 6915 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6916 | XML_SCHEMAP_IMPORT_NAMESPACE_NOT_URI, |
| 6917 | NULL, NULL, node, |
| 6918 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
| 6919 | NULL, namespace, NULL, NULL, NULL); |
| 6920 | return (XML_SCHEMAP_IMPORT_NAMESPACE_NOT_URI); |
| 6921 | } |
| 6922 | |
| 6923 | if (xmlSchemaPValAttr(ctxt, NULL, NULL, node, |
| 6924 | "schemaLocation", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
| 6925 | &schemaLocation) != 0) { |
| 6926 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6927 | XML_SCHEMAP_IMPORT_SCHEMA_NOT_URI, |
| 6928 | NULL, NULL, node, |
| 6929 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
| 6930 | NULL, namespace, NULL, NULL, NULL); |
| 6931 | return (XML_SCHEMAP_IMPORT_SCHEMA_NOT_URI); |
| 6932 | } |
| 6933 | /* |
| 6934 | * And now for the children... |
| 6935 | */ |
| 6936 | child = node->children; |
| 6937 | if (IS_SCHEMA(child, "annotation")) { |
| 6938 | /* |
| 6939 | * the annotation here is simply discarded ... |
| 6940 | */ |
| 6941 | child = child->next; |
| 6942 | } |
| 6943 | if (child != NULL) { |
| 6944 | xmlSchemaPContentErr(ctxt, |
| 6945 | XML_SCHEMAP_UNKNOWN_IMPORT_CHILD, |
| 6946 | NULL, NULL, node, child, NULL, |
| 6947 | "(annotation?)"); |
| 6948 | } |
| 6949 | /* |
| 6950 | * Apply additional constraints. |
| 6951 | */ |
| 6952 | if (namespace != NULL) { |
| 6953 | /* |
| 6954 | * 1.1 If the namespace [attribute] is present, then its ·actual value· |
| 6955 | * must not match the ·actual value· of the enclosing <schema>'s |
| 6956 | * targetNamespace [attribute]. |
| 6957 | */ |
| 6958 | if (xmlStrEqual(schema->targetNamespace, namespace)) { |
| 6959 | xmlSchemaPCustomErr(ctxt, |
| 6960 | XML_SCHEMAP_SRC_IMPORT_1_1, |
| 6961 | NULL, NULL, node, |
| 6962 | "The value of the attribute 'namespace' must not match " |
| 6963 | "the target namespace '%s' of the importing schema", |
| 6964 | schema->targetNamespace); |
| 6965 | return (XML_SCHEMAP_SRC_IMPORT_1_1); |
| 6966 | } |
| 6967 | } else { |
| 6968 | /* |
| 6969 | * 1.2 If the namespace [attribute] is not present, then the enclosing |
| 6970 | * <schema> must have a targetNamespace [attribute]. |
| 6971 | */ |
| 6972 | if (schema->targetNamespace == NULL) { |
| 6973 | xmlSchemaPCustomErr(ctxt, |
| 6974 | XML_SCHEMAP_SRC_IMPORT_1_2, |
| 6975 | NULL, NULL, node, |
| 6976 | "The attribute 'namespace' must be existent if " |
| 6977 | "the importing schema has no target namespace", |
| 6978 | NULL); |
| 6979 | return (XML_SCHEMAP_SRC_IMPORT_1_2); |
| 6980 | } |
| 6981 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6982 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6983 | * Locate and aquire the schema document. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6984 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6985 | ret = xmlSchemaAcquireSchemaDoc(ctxt, schema, node, namespace, |
| 6986 | schemaLocation, &doc, &targetNamespace, 0); |
| 6987 | if (ret != 0) { |
| 6988 | if (doc != NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6989 | xmlFreeDoc(doc); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6990 | return (ret); |
| 6991 | } else if (doc != NULL) { |
| 6992 | /* |
| 6993 | * Save and reset the context & schema. |
| 6994 | */ |
| 6995 | url = ctxt->URL; |
| 6996 | /* TODO: Is using the doc->URL here correct? */ |
| 6997 | ctxt->URL = doc->URL; |
| 6998 | flags = schema->flags; |
| 6999 | oldTNS = schema->targetNamespace; |
| 7000 | /* |
| 7001 | * Parse the schema. |
| 7002 | */ |
| 7003 | root = xmlDocGetRootElement(doc); |
| 7004 | xmlSchemaClearSchemaDefaults(schema); |
| 7005 | xmlSchemaParseSchemaDefaults(ctxt, schema, root); |
| 7006 | schema->targetNamespace = targetNamespace; |
| 7007 | xmlSchemaParseSchemaTopLevel(ctxt, schema, root->children); |
| 7008 | /* |
| 7009 | * Restore the context & schema. |
| 7010 | */ |
| 7011 | schema->flags = flags; |
| 7012 | schema->targetNamespace = oldTNS; |
| 7013 | ctxt->URL = url; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7014 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7015 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7016 | return (0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7017 | } |
| 7018 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7019 | /** |
| 7020 | * xmlSchemaParseInclude: |
| 7021 | * @ctxt: a schema validation context |
| 7022 | * @schema: the schema being built |
| 7023 | * @node: a subtree containing XML Schema informations |
| 7024 | * |
| 7025 | * parse a XML schema Include definition |
| 7026 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7027 | * Returns -1 in case of error, 0 if the declaration is improper and |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7028 | * 1 in case of success. |
| 7029 | */ |
| 7030 | static int |
| 7031 | xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 7032 | xmlNodePtr node) |
| 7033 | { |
| 7034 | xmlNodePtr child = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7035 | const xmlChar *schemaLocation, *targetNamespace; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7036 | xmlDocPtr doc; |
| 7037 | xmlNodePtr root; |
| 7038 | xmlSchemaIncludePtr include; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7039 | int wasConvertingNs = 0; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7040 | xmlAttrPtr attr; |
| 7041 | int saveFlags; |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 7042 | xmlParserCtxtPtr parserCtxt; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7043 | |
| 7044 | |
| 7045 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 7046 | return (-1); |
| 7047 | |
| 7048 | /* |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7049 | * Check for illegal attributes. |
| 7050 | */ |
| 7051 | attr = node->properties; |
| 7052 | while (attr != NULL) { |
| 7053 | if (attr->ns == NULL) { |
| 7054 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 7055 | (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation"))) { |
| 7056 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7057 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7058 | NULL, NULL, attr); |
| 7059 | } |
| 7060 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 7061 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7062 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7063 | NULL, NULL, attr); |
| 7064 | } |
| 7065 | attr = attr->next; |
| 7066 | } |
| 7067 | /* |
| 7068 | * Extract and validate attributes. |
| 7069 | */ |
| 7070 | /* |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7071 | * Preliminary step, extract the URI-Reference for the include and |
| 7072 | * make an URI from the base. |
| 7073 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7074 | attr = xmlSchemaGetPropNode(node, "schemaLocation"); |
| 7075 | if (attr != NULL) { |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7076 | xmlChar *base = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7077 | xmlChar *uri = NULL; |
| 7078 | |
| 7079 | if (xmlSchemaPValAttrNode(ctxt, NULL, NULL, attr, |
| 7080 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), &schemaLocation) != 0) |
| 7081 | return (-1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7082 | base = xmlNodeGetBase(node->doc, node); |
| 7083 | if (base == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7084 | uri = xmlBuildURI(schemaLocation, node->doc->URL); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7085 | } else { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7086 | uri = xmlBuildURI(schemaLocation, base); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7087 | xmlFree(base); |
| 7088 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7089 | if (uri != NULL) { |
| 7090 | schemaLocation = xmlDictLookup(ctxt->dict, uri, -1); |
| 7091 | xmlFree(uri); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7092 | } |
| 7093 | } else { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7094 | xmlSchemaPMissingAttrErr(ctxt, |
| 7095 | XML_SCHEMAP_INCLUDE_SCHEMA_NO_URI, |
| 7096 | NULL, NULL, node, "schemaLocation", NULL); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7097 | return (-1); |
| 7098 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7099 | /* |
| 7100 | * And now for the children... |
| 7101 | */ |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7102 | child = node->children; |
| 7103 | while (IS_SCHEMA(child, "annotation")) { |
| 7104 | /* |
| 7105 | * the annotations here are simply discarded ... |
| 7106 | */ |
| 7107 | child = child->next; |
| 7108 | } |
| 7109 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7110 | xmlSchemaPContentErr(ctxt, |
| 7111 | XML_SCHEMAP_UNKNOWN_INCLUDE_CHILD, |
| 7112 | NULL, NULL, node, child, NULL, |
| 7113 | "(annotation?)"); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7114 | } |
| 7115 | |
| 7116 | /* |
| 7117 | * First step is to parse the input document into an DOM/Infoset |
| 7118 | */ |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 7119 | /* |
| 7120 | * TODO: Use xmlCtxtReadFile to share the dictionary. |
| 7121 | */ |
| 7122 | parserCtxt = xmlNewParserCtxt(); |
| 7123 | if (parserCtxt == NULL) { |
| 7124 | xmlSchemaPErrMemory(NULL, "xmlSchemaParseInclude: " |
| 7125 | "allocating a parser context", NULL); |
| 7126 | return(-1); |
| 7127 | } |
| 7128 | |
| 7129 | if ((ctxt->dict != NULL) && (parserCtxt->dict != NULL)) { |
| 7130 | xmlDictFree(parserCtxt->dict); |
| 7131 | parserCtxt->dict = ctxt->dict; |
| 7132 | xmlDictReference(parserCtxt->dict); |
| 7133 | } |
| 7134 | |
| 7135 | doc = xmlCtxtReadFile(parserCtxt, (const char *) schemaLocation, |
| 7136 | NULL, SCHEMAS_PARSE_OPTIONS); |
| 7137 | xmlFreeParserCtxt(parserCtxt); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7138 | if (doc == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7139 | /* |
| 7140 | * TODO: It is not an error for the ·actual value· of the |
| 7141 | * schemaLocation [attribute] to fail to resolve it all, in which |
| 7142 | * case no corresponding inclusion is performed. |
| 7143 | * So do we need a warning report here? |
| 7144 | */ |
| 7145 | xmlSchemaPCustomErr(ctxt, |
| 7146 | XML_SCHEMAP_FAILED_LOAD, |
| 7147 | NULL, NULL, node, |
| 7148 | "Failed to load the document '%s' for inclusion", schemaLocation); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7149 | return(-1); |
| 7150 | } |
| 7151 | |
| 7152 | /* |
| 7153 | * Then extract the root of the schema |
| 7154 | */ |
| 7155 | root = xmlDocGetRootElement(doc); |
| 7156 | if (root == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7157 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7158 | XML_SCHEMAP_NOROOT, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7159 | NULL, NULL, node, |
| 7160 | "The included document '%s' has no document " |
| 7161 | "element", schemaLocation); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7162 | xmlFreeDoc(doc); |
| 7163 | return (-1); |
| 7164 | } |
| 7165 | |
| 7166 | /* |
| 7167 | * Remove all the blank text nodes |
| 7168 | */ |
| 7169 | xmlSchemaCleanupDoc(ctxt, root); |
| 7170 | |
| 7171 | /* |
| 7172 | * Check the schemas top level element |
| 7173 | */ |
| 7174 | if (!IS_SCHEMA(root, "schema")) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7175 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7176 | XML_SCHEMAP_NOT_SCHEMA, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7177 | NULL, NULL, node, |
| 7178 | "The document '%s' to be included is not a schema document", |
| 7179 | schemaLocation); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7180 | xmlFreeDoc(doc); |
| 7181 | return (-1); |
| 7182 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7183 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7184 | targetNamespace = xmlSchemaGetProp(ctxt, root, "targetNamespace"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7185 | /* |
| 7186 | * 2.1 SII has a targetNamespace [attribute], and its ·actual |
| 7187 | * value· is identical to the ·actual value· of the targetNamespace |
| 7188 | * [attribute] of SIIÂ’ (which must have such an [attribute]). |
| 7189 | */ |
| 7190 | if (targetNamespace != NULL) { |
| 7191 | if (schema->targetNamespace == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7192 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7193 | XML_SCHEMAP_SRC_INCLUDE, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7194 | NULL, NULL, node, |
| 7195 | "The target namespace of the included schema " |
| 7196 | "'%s' has to be absent, since the including schema " |
| 7197 | "has no target namespace", |
| 7198 | schemaLocation); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7199 | xmlFreeDoc(doc); |
| 7200 | return (-1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7201 | } else if (!xmlStrEqual(targetNamespace, schema->targetNamespace)) { |
| 7202 | xmlSchemaPCustomErrExt(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7203 | XML_SCHEMAP_SRC_INCLUDE, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7204 | NULL, NULL, node, |
| 7205 | "The target namespace '%s' of the included schema '%s' " |
| 7206 | "differs from '%s' of the including schema", |
| 7207 | targetNamespace, schemaLocation, schema->targetNamespace); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7208 | xmlFreeDoc(doc); |
| 7209 | return (-1); |
| 7210 | } |
| 7211 | } else if (schema->targetNamespace != NULL) { |
| 7212 | if ((schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) == 0) { |
| 7213 | schema->flags |= XML_SCHEMAS_INCLUDING_CONVERT_NS; |
| 7214 | } else |
| 7215 | wasConvertingNs = 1; |
| 7216 | } |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7217 | /* |
| 7218 | * register the include |
| 7219 | */ |
| 7220 | include = (xmlSchemaIncludePtr) xmlMalloc(sizeof(xmlSchemaInclude)); |
| 7221 | if (include == NULL) { |
| 7222 | xmlSchemaPErrMemory(ctxt, "allocating included schema", NULL); |
| 7223 | xmlFreeDoc(doc); |
| 7224 | return (-1); |
| 7225 | } |
| 7226 | |
| 7227 | memset(include, 0, sizeof(xmlSchemaInclude)); |
| 7228 | include->schemaLocation = xmlDictLookup(ctxt->dict, schemaLocation, -1); |
| 7229 | include->doc = doc; |
| 7230 | include->next = schema->includes; |
| 7231 | schema->includes = include; |
| 7232 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7233 | /* |
| 7234 | * parse the declarations in the included file like if they |
| 7235 | * were in the original file. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7236 | */ |
| 7237 | /* |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7238 | * TODO: The complete validation of the <schema> element is not done. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7239 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7240 | /* |
| 7241 | * The default values ("blockDefault", "elementFormDefault", etc.) |
| 7242 | * are set to the values of the included schema and restored afterwards. |
| 7243 | */ |
| 7244 | saveFlags = schema->flags; |
| 7245 | xmlSchemaClearSchemaDefaults(schema); |
| 7246 | xmlSchemaParseSchemaDefaults(ctxt, schema, root); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7247 | xmlSchemaParseSchemaTopLevel(ctxt, schema, root->children); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7248 | schema->flags = saveFlags; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7249 | /* |
| 7250 | * Remove the converting flag. |
| 7251 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7252 | if ((wasConvertingNs == 0) && |
| 7253 | (schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS)) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7254 | schema->flags ^= XML_SCHEMAS_INCLUDING_CONVERT_NS; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7255 | return (1); |
| 7256 | } |
| 7257 | |
| 7258 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7259 | * xmlSchemaParseChoice: |
| 7260 | * @ctxt: a schema validation context |
| 7261 | * @schema: the schema being built |
| 7262 | * @node: a subtree containing XML Schema informations |
| 7263 | * |
| 7264 | * parse a XML schema Choice definition |
| 7265 | * *WARNING* this interface is highly subject to change |
| 7266 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7267 | * Returns -1 in case of error, 0 if the declaration is improper and |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7268 | * 1 in case of success. |
| 7269 | */ |
| 7270 | static xmlSchemaTypePtr |
| 7271 | xmlSchemaParseChoice(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7272 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7273 | { |
| 7274 | xmlSchemaTypePtr type, subtype, last = NULL; |
| 7275 | xmlNodePtr child = NULL; |
| 7276 | xmlChar name[30]; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7277 | xmlAttrPtr attr; |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 7278 | const xmlChar *oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7279 | |
| 7280 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 7281 | return (NULL); |
| 7282 | |
| 7283 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7284 | snprintf((char *) name, 30, "choice %d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7285 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7286 | if (type == NULL) |
| 7287 | return (NULL); |
| 7288 | type->node = node; |
| 7289 | type->type = XML_SCHEMA_TYPE_CHOICE; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7290 | /* |
| 7291 | * Check for illegal attributes. |
| 7292 | */ |
| 7293 | attr = node->properties; |
| 7294 | while (attr != NULL) { |
| 7295 | if (attr->ns == NULL) { |
| 7296 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 7297 | (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) && |
| 7298 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs"))) { |
| 7299 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7300 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7301 | NULL, type, attr); |
| 7302 | } |
| 7303 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 7304 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7305 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7306 | NULL, type, attr); |
| 7307 | } |
| 7308 | attr = attr->next; |
| 7309 | } |
| 7310 | /* |
| 7311 | * Extract and validate attributes. |
| 7312 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 7313 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 7314 | type->minOccurs = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "nonNegativeInteger"); |
| 7315 | type->maxOccurs = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, |
| 7316 | "(nonNegativeInteger | unbounded)"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7317 | /* |
| 7318 | * And now for the children... |
| 7319 | */ |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 7320 | oldcontainer = ctxt->container; |
| 7321 | ctxt->container = (const xmlChar *) name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7322 | child = node->children; |
| 7323 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7324 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7325 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7326 | } |
| 7327 | while ((IS_SCHEMA(child, "element")) || |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7328 | (IS_SCHEMA(child, "group")) || |
| 7329 | (IS_SCHEMA(child, "any")) || |
| 7330 | (IS_SCHEMA(child, "choice")) || |
| 7331 | (IS_SCHEMA(child, "sequence"))) { |
| 7332 | subtype = NULL; |
| 7333 | if (IS_SCHEMA(child, "element")) { |
| 7334 | subtype = (xmlSchemaTypePtr) |
| 7335 | xmlSchemaParseElement(ctxt, schema, child, 0); |
| 7336 | } else if (IS_SCHEMA(child, "group")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 7337 | subtype = xmlSchemaParseGroup(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7338 | } else if (IS_SCHEMA(child, "any")) { |
| 7339 | subtype = xmlSchemaParseAny(ctxt, schema, child); |
| 7340 | } else if (IS_SCHEMA(child, "sequence")) { |
| 7341 | subtype = xmlSchemaParseSequence(ctxt, schema, child); |
| 7342 | } else if (IS_SCHEMA(child, "choice")) { |
| 7343 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 7344 | } |
| 7345 | if (subtype != NULL) { |
| 7346 | if (last == NULL) { |
| 7347 | type->subtypes = subtype; |
| 7348 | last = subtype; |
| 7349 | } else { |
| 7350 | last->next = subtype; |
| 7351 | last = subtype; |
| 7352 | } |
| 7353 | last->next = NULL; |
| 7354 | } |
| 7355 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7356 | } |
| 7357 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7358 | /* TODO: error code. */ |
| 7359 | xmlSchemaPContentErr(ctxt, |
| 7360 | XML_SCHEMAP_UNKNOWN_CHOICE_CHILD, |
| 7361 | NULL, type, node, child, NULL, |
| 7362 | "(annotation?, (element | group | choice | sequence | any)*)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7363 | } |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 7364 | ctxt->container = oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7365 | return (type); |
| 7366 | } |
| 7367 | |
| 7368 | /** |
| 7369 | * xmlSchemaParseSequence: |
| 7370 | * @ctxt: a schema validation context |
| 7371 | * @schema: the schema being built |
| 7372 | * @node: a subtree containing XML Schema informations |
| 7373 | * |
| 7374 | * parse a XML schema Sequence definition |
| 7375 | * *WARNING* this interface is highly subject to change |
| 7376 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7377 | * Returns -1 in case of error, 0 if the declaration is improper and |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7378 | * 1 in case of success. |
| 7379 | */ |
| 7380 | static xmlSchemaTypePtr |
| 7381 | xmlSchemaParseSequence(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7382 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7383 | { |
| 7384 | xmlSchemaTypePtr type, subtype, last = NULL; |
| 7385 | xmlNodePtr child = NULL; |
| 7386 | xmlChar name[30]; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7387 | xmlAttrPtr attr; |
| 7388 | const xmlChar *oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7389 | |
| 7390 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 7391 | return (NULL); |
| 7392 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7393 | oldcontainer = ctxt->container; |
| 7394 | snprintf((char *) name, 30, "#seq %d", ctxt->counter++ + 1); |
| 7395 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7396 | if (type == NULL) |
| 7397 | return (NULL); |
| 7398 | type->node = node; |
| 7399 | type->type = XML_SCHEMA_TYPE_SEQUENCE; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7400 | /* |
| 7401 | * Check for illegal attributes. |
| 7402 | */ |
| 7403 | attr = node->properties; |
| 7404 | while (attr != NULL) { |
| 7405 | if (attr->ns == NULL) { |
| 7406 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 7407 | (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) && |
| 7408 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs"))) { |
| 7409 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7410 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7411 | NULL, type, attr); |
| 7412 | } |
| 7413 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 7414 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7415 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7416 | NULL, type, attr); |
| 7417 | } |
| 7418 | attr = attr->next; |
| 7419 | } |
| 7420 | /* |
| 7421 | * Extract and validate attributes. |
| 7422 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 7423 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 7424 | type->minOccurs = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "nonNegativeInteger"); |
| 7425 | type->maxOccurs = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, |
| 7426 | "(nonNegativeInteger | unbounded)"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7427 | /* |
| 7428 | * And now for the children... |
| 7429 | */ |
| 7430 | ctxt->container = (const xmlChar *) name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7431 | child = node->children; |
| 7432 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7433 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7434 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7435 | } |
| 7436 | while ((IS_SCHEMA(child, "element")) || |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7437 | (IS_SCHEMA(child, "group")) || |
| 7438 | (IS_SCHEMA(child, "any")) || |
| 7439 | (IS_SCHEMA(child, "choice")) || |
| 7440 | (IS_SCHEMA(child, "sequence"))) { |
| 7441 | subtype = NULL; |
| 7442 | if (IS_SCHEMA(child, "element")) { |
| 7443 | subtype = (xmlSchemaTypePtr) |
| 7444 | xmlSchemaParseElement(ctxt, schema, child, 0); |
| 7445 | } else if (IS_SCHEMA(child, "group")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 7446 | subtype = xmlSchemaParseGroup(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7447 | } else if (IS_SCHEMA(child, "any")) { |
| 7448 | subtype = xmlSchemaParseAny(ctxt, schema, child); |
| 7449 | } else if (IS_SCHEMA(child, "choice")) { |
| 7450 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 7451 | } else if (IS_SCHEMA(child, "sequence")) { |
| 7452 | subtype = xmlSchemaParseSequence(ctxt, schema, child); |
| 7453 | } |
| 7454 | if (subtype != NULL) { |
| 7455 | if (last == NULL) { |
| 7456 | type->subtypes = subtype; |
| 7457 | last = subtype; |
| 7458 | } else { |
| 7459 | last->next = subtype; |
| 7460 | last = subtype; |
| 7461 | } |
| 7462 | last->next = NULL; |
| 7463 | } |
| 7464 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7465 | } |
| 7466 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7467 | xmlSchemaPContentErr(ctxt, |
| 7468 | XML_SCHEMAP_UNKNOWN_SEQUENCE_CHILD, |
| 7469 | NULL, type, node, child, NULL, |
| 7470 | "(annotation?, (element | group | choice | sequence | any)*)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7471 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7472 | ctxt->container = oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7473 | |
| 7474 | return (type); |
| 7475 | } |
| 7476 | |
| 7477 | /** |
| 7478 | * xmlSchemaParseRestriction: |
| 7479 | * @ctxt: a schema validation context |
| 7480 | * @schema: the schema being built |
| 7481 | * @node: a subtree containing XML Schema informations |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7482 | * |
| 7483 | * parse a XML schema Restriction definition |
| 7484 | * *WARNING* this interface is highly subject to change |
| 7485 | * |
| 7486 | * Returns the type definition or NULL in case of error |
| 7487 | */ |
| 7488 | static xmlSchemaTypePtr |
| 7489 | xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 7490 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7491 | { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7492 | xmlSchemaTypePtr type, subtype; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7493 | xmlNodePtr child = NULL; |
| 7494 | xmlChar name[30]; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 7495 | const xmlChar *oldcontainer; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7496 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7497 | |
| 7498 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 7499 | return (NULL); |
| 7500 | |
| 7501 | oldcontainer = ctxt->container; |
| 7502 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7503 | snprintf((char *) name, 30, "#restr %d", ctxt->counter++ + 1); |
| 7504 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7505 | if (type == NULL) |
| 7506 | return (NULL); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 7507 | type->type = XML_SCHEMA_TYPE_RESTRICTION; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7508 | type->node = node; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7509 | /* |
| 7510 | * Check for illegal attributes. |
| 7511 | */ |
| 7512 | attr = node->properties; |
| 7513 | while (attr != NULL) { |
| 7514 | if (attr->ns == NULL) { |
| 7515 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 7516 | (!xmlStrEqual(attr->name, BAD_CAST "base"))) { |
| 7517 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7518 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7519 | NULL, type, attr); |
| 7520 | } |
| 7521 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 7522 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7523 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7524 | NULL, type, attr); |
| 7525 | } |
| 7526 | attr = attr->next; |
| 7527 | } |
| 7528 | /* |
| 7529 | * Extract and validate attributes. |
| 7530 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 7531 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7532 | /* |
| 7533 | * Attribute "base". |
| 7534 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7535 | type->base = xmlGetQNameProp(ctxt, node, "base", &(type->baseNs)); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7536 | if ((type->base == NULL) && |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7537 | (ctxt->ctxtType->type == XML_SCHEMA_TYPE_COMPLEX)) { |
| 7538 | /* TODO: Think about the error code. */ |
| 7539 | xmlSchemaPMissingAttrErr(ctxt, |
| 7540 | XML_SCHEMAP_RESTRICTION_NONAME_NOREF, |
| 7541 | NULL, type, node, "base", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7542 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7543 | /* |
| 7544 | * And now for the children... |
| 7545 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7546 | ctxt->container = name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7547 | child = node->children; |
| 7548 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7549 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7550 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7551 | } |
| 7552 | subtype = NULL; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7553 | if (ctxt->parentItem->type == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
| 7554 | if (IS_SCHEMA(child, "all")) { |
| 7555 | subtype = (xmlSchemaTypePtr) |
| 7556 | xmlSchemaParseAll(ctxt, schema, child); |
| 7557 | child = child->next; |
| 7558 | type->subtypes = subtype; |
| 7559 | } else if (IS_SCHEMA(child, "choice")) { |
| 7560 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 7561 | child = child->next; |
| 7562 | type->subtypes = subtype; |
| 7563 | } else if (IS_SCHEMA(child, "sequence")) { |
| 7564 | subtype = (xmlSchemaTypePtr) |
| 7565 | xmlSchemaParseSequence(ctxt, schema, child); |
| 7566 | child = child->next; |
| 7567 | type->subtypes = subtype; |
| 7568 | } else if (IS_SCHEMA(child, "group")) { |
| 7569 | subtype = (xmlSchemaTypePtr) |
| 7570 | xmlSchemaParseGroup(ctxt, schema, child, 0); |
| 7571 | child = child->next; |
| 7572 | type->subtypes = subtype; |
| 7573 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7574 | } else if (ctxt->ctxtType->type == XML_SCHEMA_TYPE_SIMPLE) { |
| 7575 | if (IS_SCHEMA(child, "simpleType")) { |
| 7576 | if (type->base != NULL) { |
| 7577 | /* |
| 7578 | * src-restriction-base-or-simpleType |
| 7579 | * Either the base [attribute] or the simpleType [child] of the |
| 7580 | * <restriction> element must be present, but not both. |
| 7581 | */ |
| 7582 | xmlSchemaPContentErr(ctxt, |
| 7583 | XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE, |
| 7584 | NULL, NULL, type->node, child, |
| 7585 | "The attribute 'base' and the <simpleType> child are " |
| 7586 | "mutually exclusive", NULL); |
| 7587 | } else { |
| 7588 | subtype = (xmlSchemaTypePtr) |
| 7589 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
| 7590 | type->baseType = subtype; |
| 7591 | } |
| 7592 | child = child->next; |
| 7593 | } |
| 7594 | } else if (ctxt->parentItem->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7595 | if (IS_SCHEMA(child, "simpleType")) { |
| 7596 | subtype = (xmlSchemaTypePtr) |
| 7597 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7598 | type->subtypes = subtype; |
| 7599 | child = child->next; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7600 | } |
| 7601 | } |
| 7602 | if ((ctxt->ctxtType->type == XML_SCHEMA_TYPE_SIMPLE) || |
| 7603 | (ctxt->parentItem->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT)) { |
| 7604 | xmlSchemaFacetPtr facet, lastfacet = NULL; |
| 7605 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7606 | /* |
| 7607 | * Add the facets to the parent simpleType/complexType. |
| 7608 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7609 | /* |
| 7610 | * TODO: Datatypes: 4.1.3 Constraints on XML Representation of |
| 7611 | * Simple Type Definition Schema Representation Constraint: |
| 7612 | * *Single Facet Value* |
| 7613 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7614 | while ((IS_SCHEMA(child, "minInclusive")) || |
| 7615 | (IS_SCHEMA(child, "minExclusive")) || |
| 7616 | (IS_SCHEMA(child, "maxInclusive")) || |
| 7617 | (IS_SCHEMA(child, "maxExclusive")) || |
| 7618 | (IS_SCHEMA(child, "totalDigits")) || |
| 7619 | (IS_SCHEMA(child, "fractionDigits")) || |
| 7620 | (IS_SCHEMA(child, "pattern")) || |
| 7621 | (IS_SCHEMA(child, "enumeration")) || |
| 7622 | (IS_SCHEMA(child, "whiteSpace")) || |
| 7623 | (IS_SCHEMA(child, "length")) || |
| 7624 | (IS_SCHEMA(child, "maxLength")) || |
| 7625 | (IS_SCHEMA(child, "minLength"))) { |
| 7626 | facet = xmlSchemaParseFacet(ctxt, schema, child); |
| 7627 | if (facet != NULL) { |
| 7628 | if (lastfacet == NULL) |
| 7629 | ctxt->ctxtType->facets = facet; |
| 7630 | else |
| 7631 | lastfacet->next = facet; |
| 7632 | lastfacet = facet; |
| 7633 | lastfacet->next = NULL; |
| 7634 | } |
| 7635 | child = child->next; |
| 7636 | } |
| 7637 | /* |
| 7638 | * Create links for derivation and validation. |
| 7639 | */ |
| 7640 | if (lastfacet != NULL) { |
| 7641 | xmlSchemaFacetLinkPtr facetLink, lastFacetLink = NULL; |
| 7642 | |
| 7643 | facet = ctxt->ctxtType->facets; |
| 7644 | do { |
| 7645 | facetLink = (xmlSchemaFacetLinkPtr) xmlMalloc(sizeof(xmlSchemaFacetLink)); |
| 7646 | if (facetLink == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7647 | xmlSchemaPErrMemory(ctxt, "allocating a facet link", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7648 | xmlFree(facetLink); |
| 7649 | return (NULL); |
| 7650 | } |
| 7651 | facetLink->facet = facet; |
| 7652 | facetLink->next = NULL; |
| 7653 | if (lastFacetLink == NULL) |
| 7654 | ctxt->ctxtType->facetSet = facetLink; |
| 7655 | else |
| 7656 | lastFacetLink->next = facetLink; |
| 7657 | lastFacetLink = facetLink; |
| 7658 | facet = facet->next; |
| 7659 | } while (facet != NULL); |
| 7660 | } |
| 7661 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7662 | if (ctxt->ctxtType->type == XML_SCHEMA_TYPE_COMPLEX) { |
| 7663 | child = xmlSchemaParseAttrDecls(ctxt, schema, child, type); |
| 7664 | if (IS_SCHEMA(child, "anyAttribute")) { |
| 7665 | ctxt->ctxtType->attributeWildcard = xmlSchemaParseAnyAttribute(ctxt, schema, child); |
| 7666 | child = child->next; |
| 7667 | } |
| 7668 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7669 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7670 | /* TODO: Think about the error code. */ |
| 7671 | if (ctxt->parentItem->type == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
| 7672 | xmlSchemaPContentErr(ctxt, |
| 7673 | XML_SCHEMAP_UNKNOWN_RESTRICTION_CHILD, |
| 7674 | NULL, type, node, child, NULL, |
| 7675 | "annotation?, (group | all | choice | sequence)?, " |
| 7676 | "((attribute | attributeGroup)*, anyAttribute?))"); |
| 7677 | } else if (ctxt->parentItem->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT) { |
| 7678 | xmlSchemaPContentErr(ctxt, |
| 7679 | XML_SCHEMAP_UNKNOWN_RESTRICTION_CHILD, |
| 7680 | NULL, type, node, child, NULL, |
| 7681 | "(annotation?, (simpleType?, (minExclusive | minInclusive | " |
| 7682 | "maxExclusive | maxInclusive | totalDigits | fractionDigits | " |
| 7683 | "length | minLength | maxLength | enumeration | whiteSpace | " |
| 7684 | "pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))"); |
| 7685 | } else { |
| 7686 | /* Simple type */ |
| 7687 | xmlSchemaPContentErr(ctxt, |
| 7688 | XML_SCHEMAP_UNKNOWN_RESTRICTION_CHILD, |
| 7689 | NULL, type, node, child, NULL, |
| 7690 | "(annotation?, (simpleType?, (minExclusive | minInclusive | " |
| 7691 | "maxExclusive | maxInclusive | totalDigits | fractionDigits | " |
| 7692 | "length | minLength | maxLength | enumeration | whiteSpace | " |
| 7693 | "pattern)*))"); |
| 7694 | } |
| 7695 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7696 | ctxt->container = oldcontainer; |
| 7697 | return (type); |
| 7698 | } |
| 7699 | |
| 7700 | /** |
| 7701 | * xmlSchemaParseExtension: |
| 7702 | * @ctxt: a schema validation context |
| 7703 | * @schema: the schema being built |
| 7704 | * @node: a subtree containing XML Schema informations |
| 7705 | * |
| 7706 | * parse a XML schema Extension definition |
| 7707 | * *WARNING* this interface is highly subject to change |
| 7708 | * |
| 7709 | * Returns the type definition or NULL in case of error |
| 7710 | */ |
| 7711 | static xmlSchemaTypePtr |
| 7712 | xmlSchemaParseExtension(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7713 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7714 | { |
| 7715 | xmlSchemaTypePtr type, subtype; |
| 7716 | xmlNodePtr child = NULL; |
| 7717 | xmlChar name[30]; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 7718 | const xmlChar *oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7719 | |
| 7720 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 7721 | return (NULL); |
| 7722 | |
| 7723 | oldcontainer = ctxt->container; |
| 7724 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7725 | snprintf((char *) name, 30, "extension %d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7726 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7727 | if (type == NULL) |
| 7728 | return (NULL); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 7729 | type->type = XML_SCHEMA_TYPE_EXTENSION; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7730 | type->node = node; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 7731 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7732 | ctxt->container = name; |
| 7733 | |
| 7734 | type->base = xmlGetQNameProp(ctxt, node, "base", &(type->baseNs)); |
| 7735 | if (type->base == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7736 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_EXTENSION_NO_BASE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7737 | "<extension>: The attribute \"base\" is missing.\n", |
| 7738 | type->name, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7739 | } |
| 7740 | child = node->children; |
| 7741 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7742 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7743 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7744 | } |
| 7745 | subtype = NULL; |
| 7746 | |
| 7747 | if (IS_SCHEMA(child, "all")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7748 | subtype = xmlSchemaParseAll(ctxt, schema, child); |
| 7749 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7750 | } else if (IS_SCHEMA(child, "choice")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7751 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 7752 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7753 | } else if (IS_SCHEMA(child, "sequence")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7754 | subtype = xmlSchemaParseSequence(ctxt, schema, child); |
| 7755 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7756 | } else if (IS_SCHEMA(child, "group")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 7757 | subtype = xmlSchemaParseGroup(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7758 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7759 | } |
| 7760 | if (subtype != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7761 | type->subtypes = subtype; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7762 | if ((ctxt->ctxtType != NULL) && |
| 7763 | (ctxt->ctxtType->type == XML_SCHEMA_TYPE_COMPLEX)) { |
| 7764 | child = xmlSchemaParseAttrDecls(ctxt, schema, child, type); |
| 7765 | if (IS_SCHEMA(child, "anyAttribute")) { |
| 7766 | ctxt->ctxtType->attributeWildcard = |
| 7767 | xmlSchemaParseAnyAttribute(ctxt, schema, child); |
| 7768 | child = child->next; |
| 7769 | } |
| 7770 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7771 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7772 | xmlSchemaPErr2(ctxt, node, child, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7773 | XML_SCHEMAP_UNKNOWN_EXTENSION_CHILD, |
| 7774 | "<extension> has unexpected content.\n", type->name, |
| 7775 | NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7776 | } |
| 7777 | ctxt->container = oldcontainer; |
| 7778 | return (type); |
| 7779 | } |
| 7780 | |
| 7781 | /** |
| 7782 | * xmlSchemaParseSimpleContent: |
| 7783 | * @ctxt: a schema validation context |
| 7784 | * @schema: the schema being built |
| 7785 | * @node: a subtree containing XML Schema informations |
| 7786 | * |
| 7787 | * parse a XML schema SimpleContent definition |
| 7788 | * *WARNING* this interface is highly subject to change |
| 7789 | * |
| 7790 | * Returns the type definition or NULL in case of error |
| 7791 | */ |
| 7792 | static xmlSchemaTypePtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7793 | xmlSchemaParseSimpleContent(xmlSchemaParserCtxtPtr ctxt, |
| 7794 | xmlSchemaPtr schema, xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7795 | { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7796 | xmlSchemaTypePtr type, subtype, oldParentItem; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7797 | xmlNodePtr child = NULL; |
| 7798 | xmlChar name[30]; |
| 7799 | |
| 7800 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 7801 | return (NULL); |
| 7802 | |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7803 | snprintf((char *) name, 30, "simpleContent %d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7804 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7805 | if (type == NULL) |
| 7806 | return (NULL); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 7807 | type->type = XML_SCHEMA_TYPE_SIMPLE_CONTENT; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7808 | type->node = node; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 7809 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7810 | |
| 7811 | child = node->children; |
| 7812 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7813 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7814 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7815 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7816 | oldParentItem = ctxt->parentItem; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7817 | ctxt->parentItem = type; |
| 7818 | subtype = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7819 | if (IS_SCHEMA(child, "restriction")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7820 | subtype = (xmlSchemaTypePtr) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 7821 | xmlSchemaParseRestriction(ctxt, schema, child); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7822 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7823 | } else if (IS_SCHEMA(child, "extension")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7824 | subtype = (xmlSchemaTypePtr) |
| 7825 | xmlSchemaParseExtension(ctxt, schema, child); |
| 7826 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7827 | } |
| 7828 | type->subtypes = subtype; |
| 7829 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7830 | xmlSchemaPErr2(ctxt, node, child, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7831 | XML_SCHEMAP_UNKNOWN_SIMPLECONTENT_CHILD, |
| 7832 | "<simpleContent> has unexpected content.\n", |
| 7833 | NULL, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7834 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7835 | ctxt->parentItem = oldParentItem; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7836 | return (type); |
| 7837 | } |
| 7838 | |
| 7839 | /** |
| 7840 | * xmlSchemaParseComplexContent: |
| 7841 | * @ctxt: a schema validation context |
| 7842 | * @schema: the schema being built |
| 7843 | * @node: a subtree containing XML Schema informations |
| 7844 | * |
| 7845 | * parse a XML schema ComplexContent definition |
| 7846 | * *WARNING* this interface is highly subject to change |
| 7847 | * |
| 7848 | * Returns the type definition or NULL in case of error |
| 7849 | */ |
| 7850 | static xmlSchemaTypePtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7851 | xmlSchemaParseComplexContent(xmlSchemaParserCtxtPtr ctxt, |
| 7852 | xmlSchemaPtr schema, xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7853 | { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7854 | xmlSchemaTypePtr type, subtype, oldParentItem; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7855 | xmlNodePtr child = NULL; |
| 7856 | xmlChar name[30]; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7857 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7858 | |
| 7859 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 7860 | return (NULL); |
| 7861 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7862 | snprintf((char *) name, 30, "#CC %d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7863 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7864 | if (type == NULL) |
| 7865 | return (NULL); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 7866 | type->type = XML_SCHEMA_TYPE_COMPLEX_CONTENT; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7867 | type->node = node; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7868 | /* |
| 7869 | * Check for illegal attributes. |
| 7870 | */ |
| 7871 | attr = node->properties; |
| 7872 | while (attr != NULL) { |
| 7873 | if (attr->ns == NULL) { |
| 7874 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 7875 | (!xmlStrEqual(attr->name, BAD_CAST "mixed"))) |
| 7876 | { |
| 7877 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7878 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7879 | NULL, NULL, attr); |
| 7880 | } |
| 7881 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 7882 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7883 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7884 | NULL, NULL, attr); |
| 7885 | } |
| 7886 | attr = attr->next; |
| 7887 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 7888 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7889 | /* |
| 7890 | * Handle attribute 'mixed'. |
| 7891 | */ |
| 7892 | if (xmlGetBooleanProp(ctxt, NULL, type, node, "mixed", 0)) { |
| 7893 | if ((ctxt->ctxtType->flags & XML_SCHEMAS_TYPE_MIXED) == 0) |
| 7894 | ctxt->ctxtType->flags |= XML_SCHEMAS_TYPE_MIXED; |
| 7895 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7896 | child = node->children; |
| 7897 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7898 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7899 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7900 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7901 | oldParentItem = ctxt->parentItem; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7902 | ctxt->parentItem = type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7903 | subtype = NULL; |
| 7904 | if (IS_SCHEMA(child, "restriction")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7905 | subtype = (xmlSchemaTypePtr) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 7906 | xmlSchemaParseRestriction(ctxt, schema, child); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7907 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7908 | } else if (IS_SCHEMA(child, "extension")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7909 | subtype = (xmlSchemaTypePtr) |
| 7910 | xmlSchemaParseExtension(ctxt, schema, child); |
| 7911 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7912 | } |
| 7913 | type->subtypes = subtype; |
| 7914 | if (child != NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7915 | xmlSchemaPContentErr(ctxt, |
| 7916 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 7917 | NULL, NULL, node, child, |
| 7918 | NULL, "(annotation?, (restriction | extension))"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7919 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7920 | ctxt->parentItem = oldParentItem; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7921 | return (type); |
| 7922 | } |
| 7923 | |
| 7924 | /** |
| 7925 | * xmlSchemaParseComplexType: |
| 7926 | * @ctxt: a schema validation context |
| 7927 | * @schema: the schema being built |
| 7928 | * @node: a subtree containing XML Schema informations |
| 7929 | * |
| 7930 | * parse a XML schema Complex Type definition |
| 7931 | * *WARNING* this interface is highly subject to change |
| 7932 | * |
| 7933 | * Returns the type definition or NULL in case of error |
| 7934 | */ |
| 7935 | static xmlSchemaTypePtr |
| 7936 | xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 7937 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7938 | { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7939 | xmlSchemaTypePtr type, subtype, ctxtType; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7940 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7941 | const xmlChar *name = NULL; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7942 | const xmlChar *oldcontainer; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7943 | xmlAttrPtr attr; |
| 7944 | const xmlChar *attrValue; |
| 7945 | xmlChar *des = NULL; /* The reported designation. */ |
Daniel Veillard | 1a380b8 | 2004-10-21 16:00:06 +0000 | [diff] [blame] | 7946 | char buf[40]; |
| 7947 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7948 | |
| 7949 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 7950 | return (NULL); |
| 7951 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7952 | ctxtType = ctxt->ctxtType; |
| 7953 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7954 | if (topLevel) { |
| 7955 | attr = xmlSchemaGetPropNode(node, "name"); |
| 7956 | if (attr == NULL) { |
| 7957 | xmlSchemaPMissingAttrErr(ctxt, |
| 7958 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 7959 | (xmlChar **) &xmlSchemaElemDesCT, NULL, node, |
| 7960 | "name", NULL); |
| 7961 | return (NULL); |
| 7962 | } else if (xmlSchemaPValAttrNode(ctxt, |
| 7963 | (xmlChar **) &xmlSchemaElemDesCT, NULL, attr, |
| 7964 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 7965 | return (NULL); |
| 7966 | } |
| 7967 | } |
| 7968 | |
| 7969 | if (topLevel == 0) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7970 | /* |
| 7971 | * Parse as local complex type definition. |
| 7972 | */ |
| 7973 | snprintf(buf, 39, "#CT %d", ctxt->counter++ + 1); |
| 7974 | type = xmlSchemaAddType(ctxt, schema, (const xmlChar *)buf, NULL, node); |
| 7975 | if (type == NULL) |
| 7976 | return (NULL); |
| 7977 | name = (const xmlChar *) buf; |
| 7978 | type->node = node; |
| 7979 | type->type = XML_SCHEMA_TYPE_COMPLEX; |
| 7980 | /* |
| 7981 | * TODO: We need the target namespace. |
| 7982 | */ |
| 7983 | } else { |
| 7984 | /* |
| 7985 | * Parse as global complex type definition. |
| 7986 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7987 | type = xmlSchemaAddType(ctxt, schema, name, schema->targetNamespace, node); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7988 | if (type == NULL) |
| 7989 | return (NULL); |
| 7990 | type->node = node; |
| 7991 | type->type = XML_SCHEMA_TYPE_COMPLEX; |
| 7992 | type->flags |= XML_SCHEMAS_TYPE_GLOBAL; |
| 7993 | /* |
| 7994 | * Set defaults. |
| 7995 | */ |
| 7996 | type->flags |= XML_SCHEMAS_TYPE_FINAL_DEFAULT; |
| 7997 | type->flags |= XML_SCHEMAS_TYPE_BLOCK_DEFAULT; |
| 7998 | } |
| 7999 | /* |
| 8000 | * Handle attributes. |
| 8001 | */ |
| 8002 | attr = node->properties; |
| 8003 | while (attr != NULL) { |
| 8004 | if (attr->ns == NULL) { |
| 8005 | if (xmlStrEqual(attr->name, BAD_CAST "id")) { |
| 8006 | /* |
| 8007 | * Attribute "id". |
| 8008 | */ |
| 8009 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
| 8010 | } else if (xmlStrEqual(attr->name, BAD_CAST "mixed")) { |
| 8011 | /* |
| 8012 | * Attribute "mixed". |
| 8013 | */ |
| 8014 | if (xmlSchemaPGetBoolNodeValue(ctxt, &des, type, |
| 8015 | (xmlNodePtr) attr)) |
| 8016 | type->flags |= XML_SCHEMAS_TYPE_MIXED; |
| 8017 | } else if (topLevel) { |
| 8018 | /* |
| 8019 | * Attributes of global complex type definitions. |
| 8020 | */ |
| 8021 | if (xmlStrEqual(attr->name, BAD_CAST "name")) { |
| 8022 | /* Pass. */ |
| 8023 | } else if (xmlStrEqual(attr->name, BAD_CAST "abstract")) { |
| 8024 | /* |
| 8025 | * Attribute "abstract". |
| 8026 | */ |
| 8027 | if (xmlSchemaPGetBoolNodeValue(ctxt, &des, type, |
| 8028 | (xmlNodePtr) attr)) |
| 8029 | type->flags |= XML_SCHEMAS_TYPE_ABSTRACT; |
| 8030 | } else if (xmlStrEqual(attr->name, BAD_CAST "final")) { |
| 8031 | /* |
| 8032 | * Attribute "final". |
| 8033 | */ |
| 8034 | attrValue = xmlSchemaGetNodeContent(ctxt, |
| 8035 | (xmlNodePtr) attr); |
| 8036 | if (xmlSchemaPValAttrBlockFinal(attrValue, |
| 8037 | &(type->flags), |
| 8038 | -1, |
| 8039 | XML_SCHEMAS_TYPE_FINAL_EXTENSION, |
| 8040 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION, |
| 8041 | -1, -1, -1) != 0) |
| 8042 | { |
| 8043 | xmlSchemaPSimpleTypeErr(ctxt, |
| 8044 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 8045 | &des, type, (xmlNodePtr) attr, |
| 8046 | NULL, |
| 8047 | "(#all | List of (extension | restriction))", |
| 8048 | attrValue, NULL, NULL, NULL); |
| 8049 | } |
| 8050 | } else if (xmlStrEqual(attr->name, BAD_CAST "block")) { |
| 8051 | /* |
| 8052 | * Attribute "block". |
| 8053 | */ |
| 8054 | attrValue = xmlSchemaGetNodeContent(ctxt, |
| 8055 | (xmlNodePtr) attr); |
| 8056 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(type->flags), |
| 8057 | -1, |
| 8058 | XML_SCHEMAS_TYPE_BLOCK_EXTENSION, |
| 8059 | XML_SCHEMAS_TYPE_BLOCK_RESTRICTION, |
| 8060 | -1, -1, -1) != 0) { |
| 8061 | xmlSchemaPSimpleTypeErr(ctxt, |
| 8062 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 8063 | &des, type, (xmlNodePtr) attr, |
| 8064 | NULL, |
| 8065 | "(#all | List of (extension | restriction)) ", |
| 8066 | attrValue, NULL, NULL, NULL); |
| 8067 | } |
| 8068 | } else { |
| 8069 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8070 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8071 | &des, type, attr); |
| 8072 | } |
| 8073 | } else { |
| 8074 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8075 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8076 | &des, type, attr); |
| 8077 | } |
| 8078 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 8079 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8080 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8081 | &des, type, attr); |
| 8082 | } |
| 8083 | attr = attr->next; |
| 8084 | } |
| 8085 | /* |
| 8086 | * Set as default for attribute wildcards. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8087 | * This will be only changed if a complex type |
| 8088 | * inherits an attribute wildcard from a base type. |
| 8089 | */ |
| 8090 | type->flags |= XML_SCHEMAS_TYPE_OWNED_ATTR_WILDCARD; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8091 | /* |
| 8092 | * And now for the children... |
| 8093 | */ |
| 8094 | oldcontainer = ctxt->container; |
| 8095 | ctxt->container = name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8096 | child = node->children; |
| 8097 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8098 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 8099 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8100 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8101 | ctxt->ctxtType = type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8102 | if (IS_SCHEMA(child, "simpleContent")) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8103 | /* |
| 8104 | * 3.4.3 : 2.2 |
| 8105 | * Specifying mixed='true' when the <simpleContent> |
| 8106 | * alternative is chosen has no effect |
| 8107 | */ |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 8108 | if (type->flags & XML_SCHEMAS_TYPE_MIXED) |
| 8109 | type->flags ^= XML_SCHEMAS_TYPE_MIXED; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8110 | type->subtypes = xmlSchemaParseSimpleContent(ctxt, schema, child); |
| 8111 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8112 | } else if (IS_SCHEMA(child, "complexContent")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8113 | type->subtypes = xmlSchemaParseComplexContent(ctxt, schema, child); |
| 8114 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8115 | } else { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8116 | subtype = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8117 | /* |
| 8118 | * Parse model groups. |
| 8119 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8120 | if (IS_SCHEMA(child, "all")) { |
| 8121 | subtype = xmlSchemaParseAll(ctxt, schema, child); |
| 8122 | child = child->next; |
| 8123 | } else if (IS_SCHEMA(child, "choice")) { |
| 8124 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 8125 | child = child->next; |
| 8126 | } else if (IS_SCHEMA(child, "sequence")) { |
| 8127 | subtype = xmlSchemaParseSequence(ctxt, schema, child); |
| 8128 | child = child->next; |
| 8129 | } else if (IS_SCHEMA(child, "group")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 8130 | subtype = xmlSchemaParseGroup(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8131 | child = child->next; |
| 8132 | } |
| 8133 | if (subtype != NULL) |
| 8134 | type->subtypes = subtype; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8135 | /* |
| 8136 | * Parse attribute decls/refs. |
| 8137 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8138 | child = xmlSchemaParseAttrDecls(ctxt, schema, child, type); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8139 | /* |
| 8140 | * Parse attribute wildcard. |
| 8141 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8142 | if (IS_SCHEMA(child, "anyAttribute")) { |
| 8143 | type->attributeWildcard = xmlSchemaParseAnyAttribute(ctxt, schema, child); |
| 8144 | child = child->next; |
| 8145 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8146 | } |
| 8147 | if (child != NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8148 | xmlSchemaPContentErr(ctxt, |
| 8149 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 8150 | &des, type, node, child, |
| 8151 | NULL, "(annotation?, (simpleContent | complexContent | " |
| 8152 | "((group | all | choice | sequence)?, ((attribute | " |
| 8153 | "attributeGroup)*, anyAttribute?))))"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8154 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8155 | FREE_AND_NULL(des); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8156 | ctxt->container = oldcontainer; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8157 | ctxt->ctxtType = ctxtType; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8158 | return (type); |
| 8159 | } |
| 8160 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8161 | /** |
| 8162 | * xmlSchemaParseSchema: |
| 8163 | * @ctxt: a schema validation context |
| 8164 | * @node: a subtree containing XML Schema informations |
| 8165 | * |
| 8166 | * parse a XML schema definition from a node set |
| 8167 | * *WARNING* this interface is highly subject to change |
| 8168 | * |
| 8169 | * Returns the internal XML Schema structure built from the resource or |
| 8170 | * NULL in case of error |
| 8171 | */ |
| 8172 | static xmlSchemaPtr |
| 8173 | xmlSchemaParseSchema(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node) |
| 8174 | { |
| 8175 | xmlSchemaPtr schema = NULL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 8176 | const xmlChar *val; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 8177 | int nberrors; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8178 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8179 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8180 | /* |
| 8181 | * This one is called by xmlSchemaParse only and is used if |
| 8182 | * the schema to be parsed was specified via the API; i.e. not |
| 8183 | * automatically by the validated instance document. |
| 8184 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8185 | if ((ctxt == NULL) || (node == NULL)) |
| 8186 | return (NULL); |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 8187 | nberrors = ctxt->nberrors; |
| 8188 | ctxt->nberrors = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8189 | if (IS_SCHEMA(node, "schema")) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8190 | xmlSchemaImportPtr import; |
| 8191 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8192 | schema = xmlSchemaNewSchema(ctxt); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8193 | if (schema == NULL) |
| 8194 | return (NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8195 | /* |
| 8196 | * Disable build of list of items. |
| 8197 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8198 | attr = xmlSchemaGetPropNode(node, "targetNamespace"); |
| 8199 | if (attr != NULL) { |
| 8200 | xmlSchemaPValAttrNode(ctxt, NULL, NULL, attr, |
| 8201 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), &val); |
| 8202 | /* |
| 8203 | * TODO: Should we proceed with an invalid target namespace? |
| 8204 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 8205 | schema->targetNamespace = xmlDictLookup(ctxt->dict, val, -1); |
| 8206 | } else { |
| 8207 | schema->targetNamespace = NULL; |
| 8208 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8209 | /* |
| 8210 | * Add the current ns name and location to the import table; |
| 8211 | * this is needed to have a consistent mechanism, regardless |
| 8212 | * if all schemata are constructed dynamically fired by the |
| 8213 | * instance or if the schema to be used was specified via |
| 8214 | * the API. |
| 8215 | */ |
| 8216 | import = xmlSchemaAddImport(ctxt, &(schema->schemasImports), |
| 8217 | schema->targetNamespace); |
| 8218 | if (import == NULL) { |
| 8219 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_FAILED_BUILD_IMPORT, |
| 8220 | NULL, NULL, (xmlNodePtr) ctxt->doc, |
| 8221 | "Internal error: xmlSchemaParseSchema, " |
| 8222 | "failed to add an import entry", NULL); |
| 8223 | xmlSchemaFree(schema); |
| 8224 | schema = NULL; |
| 8225 | return (NULL); |
| 8226 | } |
| 8227 | import->schemaLocation = ctxt->URL; |
| 8228 | /* |
| 8229 | * NOTE: We won't set the doc here, otherwise it will be freed |
| 8230 | * if the import struct is freed. |
| 8231 | * import->doc = ctxt->doc; |
| 8232 | */ |
| 8233 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8234 | /* TODO: Check id. */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 8235 | schema->id = xmlSchemaGetProp(ctxt, node, "id"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8236 | xmlSchemaPValAttr(ctxt, NULL, NULL, node, "version", |
| 8237 | xmlSchemaGetBuiltInType(XML_SCHEMAS_TOKEN), &(schema->version)); |
| 8238 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8239 | xmlSchemaParseSchemaDefaults(ctxt, schema, node); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8240 | xmlSchemaParseSchemaTopLevel(ctxt, schema, node->children); |
| 8241 | } else { |
| 8242 | xmlDocPtr doc; |
| 8243 | |
| 8244 | doc = node->doc; |
| 8245 | |
| 8246 | if ((doc != NULL) && (doc->URL != NULL)) { |
| 8247 | xmlSchemaPErr(ctxt, (xmlNodePtr) doc, |
| 8248 | XML_SCHEMAP_NOT_SCHEMA, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8249 | "The file \"%s\" is not a XML schema.\n", doc->URL, NULL); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8250 | } else { |
| 8251 | xmlSchemaPErr(ctxt, (xmlNodePtr) doc, |
| 8252 | XML_SCHEMAP_NOT_SCHEMA, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8253 | "The file is not a XML schema.\n", NULL, NULL); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8254 | } |
| 8255 | return(NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8256 | } |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 8257 | if (ctxt->nberrors != 0) { |
| 8258 | if (schema != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8259 | xmlSchemaFree(schema); |
| 8260 | schema = NULL; |
| 8261 | } |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 8262 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8263 | if (schema != NULL) |
| 8264 | schema->counter = ctxt->counter; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 8265 | ctxt->nberrors = nberrors; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8266 | #ifdef DEBUG |
| 8267 | if (schema == NULL) |
| 8268 | xmlGenericError(xmlGenericErrorContext, |
| 8269 | "xmlSchemaParse() failed\n"); |
| 8270 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8271 | return (schema); |
| 8272 | } |
| 8273 | |
| 8274 | /************************************************************************ |
| 8275 | * * |
| 8276 | * Validating using Schemas * |
| 8277 | * * |
| 8278 | ************************************************************************/ |
| 8279 | |
| 8280 | /************************************************************************ |
| 8281 | * * |
| 8282 | * Reading/Writing Schemas * |
| 8283 | * * |
| 8284 | ************************************************************************/ |
| 8285 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8286 | #if 0 /* Will be enabled if it is clear what options are needed. */ |
| 8287 | /** |
| 8288 | * xmlSchemaParserCtxtSetOptions: |
| 8289 | * @ctxt: a schema parser context |
| 8290 | * @options: a combination of xmlSchemaParserOption |
| 8291 | * |
| 8292 | * Sets the options to be used during the parse. |
| 8293 | * |
| 8294 | * Returns 0 in case of success, -1 in case of an |
| 8295 | * API error. |
| 8296 | */ |
| 8297 | static int |
| 8298 | xmlSchemaParserCtxtSetOptions(xmlSchemaParserCtxtPtr ctxt, |
| 8299 | int options) |
| 8300 | |
| 8301 | { |
| 8302 | int i; |
| 8303 | |
| 8304 | if (ctxt == NULL) |
| 8305 | return (-1); |
| 8306 | /* |
| 8307 | * WARNING: Change the start value if adding to the |
| 8308 | * xmlSchemaParseOption. |
| 8309 | */ |
| 8310 | for (i = 1; i < (int) sizeof(int) * 8; i++) { |
| 8311 | if (options & 1<<i) { |
| 8312 | return (-1); |
| 8313 | } |
| 8314 | } |
| 8315 | ctxt->options = options; |
| 8316 | return (0); |
| 8317 | } |
| 8318 | |
| 8319 | /** |
| 8320 | * xmlSchemaValidCtxtGetOptions: |
| 8321 | * @ctxt: a schema parser context |
| 8322 | * |
| 8323 | * Returns the option combination of the parser context. |
| 8324 | */ |
| 8325 | static int |
| 8326 | xmlSchemaParserCtxtGetOptions(xmlSchemaParserCtxtPtr ctxt) |
| 8327 | |
| 8328 | { |
| 8329 | if (ctxt == NULL) |
| 8330 | return (-1); |
| 8331 | else |
| 8332 | return (ctxt->options); |
| 8333 | } |
| 8334 | |
| 8335 | void *curItems; /* used for dynamic addition of schemata */ |
| 8336 | int nbCurItems; /* used for dynamic addition of schemata */ |
| 8337 | int sizeCurItems; /* used for dynamic addition of schemata */ |
| 8338 | |
| 8339 | #endif |
| 8340 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8341 | /** |
| 8342 | * xmlSchemaNewParserCtxt: |
| 8343 | * @URL: the location of the schema |
| 8344 | * |
| 8345 | * Create an XML Schemas parse context for that file/resource expected |
| 8346 | * to contain an XML Schemas file. |
| 8347 | * |
| 8348 | * Returns the parser context or NULL in case of error |
| 8349 | */ |
| 8350 | xmlSchemaParserCtxtPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8351 | xmlSchemaNewParserCtxt(const char *URL) |
| 8352 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8353 | xmlSchemaParserCtxtPtr ret; |
| 8354 | |
| 8355 | if (URL == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8356 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8357 | |
| 8358 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 8359 | if (ret == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8360 | xmlSchemaPErrMemory(NULL, "allocating schema parser context", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8361 | NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8362 | return (NULL); |
| 8363 | } |
| 8364 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 8365 | ret->dict = xmlDictCreate(); |
| 8366 | ret->URL = xmlDictLookup(ret->dict, (const xmlChar *) URL, -1); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 8367 | ret->includes = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8368 | return (ret); |
| 8369 | } |
| 8370 | |
| 8371 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8372 | * xmlSchemaNewParserCtxtUseDict: |
| 8373 | * @URL: the location of the schema |
| 8374 | * @dict: the dictionary to be used |
| 8375 | * |
| 8376 | * Create an XML Schemas parse context for that file/resource expected |
| 8377 | * to contain an XML Schemas file. |
| 8378 | * |
| 8379 | * Returns the parser context or NULL in case of error |
| 8380 | */ |
| 8381 | static xmlSchemaParserCtxtPtr |
| 8382 | xmlSchemaNewParserCtxtUseDict(const char *URL, xmlDictPtr dict) |
| 8383 | { |
| 8384 | xmlSchemaParserCtxtPtr ret; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8385 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8386 | if (URL == NULL) |
| 8387 | return (NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8388 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8389 | |
| 8390 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 8391 | if (ret == NULL) { |
| 8392 | xmlSchemaPErrMemory(NULL, "allocating schema parser context", |
| 8393 | NULL); |
| 8394 | return (NULL); |
| 8395 | } |
| 8396 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
| 8397 | ret->dict = dict; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8398 | xmlDictReference(dict); |
| 8399 | if (URL != NULL) |
| 8400 | ret->URL = xmlDictLookup(dict, (const xmlChar *) URL, -1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8401 | ret->includes = 0; |
| 8402 | return (ret); |
| 8403 | } |
| 8404 | |
| 8405 | |
| 8406 | /** |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 8407 | * xmlSchemaNewMemParserCtxt: |
| 8408 | * @buffer: a pointer to a char array containing the schemas |
| 8409 | * @size: the size of the array |
| 8410 | * |
| 8411 | * Create an XML Schemas parse context for that memory buffer expected |
| 8412 | * to contain an XML Schemas file. |
| 8413 | * |
| 8414 | * Returns the parser context or NULL in case of error |
| 8415 | */ |
| 8416 | xmlSchemaParserCtxtPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8417 | xmlSchemaNewMemParserCtxt(const char *buffer, int size) |
| 8418 | { |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 8419 | xmlSchemaParserCtxtPtr ret; |
| 8420 | |
| 8421 | if ((buffer == NULL) || (size <= 0)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8422 | return (NULL); |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 8423 | |
| 8424 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 8425 | if (ret == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8426 | xmlSchemaPErrMemory(NULL, "allocating schema parser context", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8427 | NULL); |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 8428 | return (NULL); |
| 8429 | } |
| 8430 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
| 8431 | ret->buffer = buffer; |
| 8432 | ret->size = size; |
William M. Brack | cf9eadf | 2003-12-25 13:24:05 +0000 | [diff] [blame] | 8433 | ret->dict = xmlDictCreate(); |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 8434 | return (ret); |
| 8435 | } |
| 8436 | |
| 8437 | /** |
Daniel Veillard | 9d75150 | 2003-10-29 13:21:47 +0000 | [diff] [blame] | 8438 | * xmlSchemaNewDocParserCtxt: |
| 8439 | * @doc: a preparsed document tree |
| 8440 | * |
| 8441 | * Create an XML Schemas parse context for that document. |
| 8442 | * NB. The document may be modified during the parsing process. |
| 8443 | * |
| 8444 | * Returns the parser context or NULL in case of error |
| 8445 | */ |
| 8446 | xmlSchemaParserCtxtPtr |
| 8447 | xmlSchemaNewDocParserCtxt(xmlDocPtr doc) |
| 8448 | { |
| 8449 | xmlSchemaParserCtxtPtr ret; |
| 8450 | |
| 8451 | if (doc == NULL) |
| 8452 | return (NULL); |
| 8453 | |
| 8454 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 8455 | if (ret == NULL) { |
| 8456 | xmlSchemaPErrMemory(NULL, "allocating schema parser context", |
| 8457 | NULL); |
| 8458 | return (NULL); |
| 8459 | } |
| 8460 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
| 8461 | ret->doc = doc; |
William M. Brack | cf9eadf | 2003-12-25 13:24:05 +0000 | [diff] [blame] | 8462 | ret->dict = xmlDictCreate(); |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 8463 | /* The application has responsibility for the document */ |
| 8464 | ret->preserve = 1; |
Daniel Veillard | 9d75150 | 2003-10-29 13:21:47 +0000 | [diff] [blame] | 8465 | |
| 8466 | return (ret); |
| 8467 | } |
| 8468 | |
| 8469 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8470 | * xmlSchemaFreeParserCtxt: |
| 8471 | * @ctxt: the schema parser context |
| 8472 | * |
| 8473 | * Free the resources associated to the schema parser context |
| 8474 | */ |
| 8475 | void |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8476 | xmlSchemaFreeParserCtxt(xmlSchemaParserCtxtPtr ctxt) |
| 8477 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8478 | if (ctxt == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8479 | return; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 8480 | if (ctxt->doc != NULL && !ctxt->preserve) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8481 | xmlFreeDoc(ctxt->doc); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8482 | if (ctxt->assemble != NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8483 | xmlFree((xmlSchemaTypePtr *) ctxt->assemble->items); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8484 | xmlFree(ctxt->assemble); |
| 8485 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8486 | if (ctxt->vctxt != NULL) { |
| 8487 | xmlSchemaFreeValidCtxt(ctxt->vctxt); |
| 8488 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 8489 | xmlDictFree(ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8490 | xmlFree(ctxt); |
| 8491 | } |
| 8492 | |
| 8493 | /************************************************************************ |
| 8494 | * * |
| 8495 | * Building the content models * |
| 8496 | * * |
| 8497 | ************************************************************************/ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8498 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8499 | /** |
| 8500 | * xmlSchemaBuildAContentModel: |
| 8501 | * @type: the schema type definition |
| 8502 | * @ctxt: the schema parser context |
| 8503 | * @name: the element name whose content is being built |
| 8504 | * |
| 8505 | * Generate the automata sequence needed for that type |
| 8506 | */ |
| 8507 | static void |
| 8508 | xmlSchemaBuildAContentModel(xmlSchemaTypePtr type, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8509 | xmlSchemaParserCtxtPtr ctxt, |
| 8510 | const xmlChar * name) |
| 8511 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8512 | if (type == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8513 | xmlGenericError(xmlGenericErrorContext, |
| 8514 | "Found unexpected type = NULL in %s content model\n", |
| 8515 | name); |
| 8516 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8517 | } |
| 8518 | switch (type->type) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8519 | case XML_SCHEMA_TYPE_ANY: { |
| 8520 | xmlAutomataStatePtr start, end; |
| 8521 | xmlSchemaWildcardPtr wild; |
| 8522 | xmlSchemaWildcardNsPtr ns; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 8523 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8524 | wild = type->attributeWildcard; |
| 8525 | |
| 8526 | if (wild == NULL) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 8527 | xmlSchemaPErr(ctxt, type->node, XML_SCHEMAP_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8528 | "Internal error: xmlSchemaBuildAContentModel, " |
| 8529 | "no wildcard on xsd:any.\n", NULL, NULL); |
| 8530 | return; |
| 8531 | } |
| 8532 | |
| 8533 | start = ctxt->state; |
| 8534 | end = xmlAutomataNewState(ctxt->am); |
| 8535 | |
| 8536 | if (type->maxOccurs == 1) { |
| 8537 | if (wild->any == 1) { |
| 8538 | /* |
| 8539 | * We need to add both transitions: |
| 8540 | * |
| 8541 | * 1. the {"*", "*"} for elements in a namespace. |
| 8542 | */ |
| 8543 | ctxt->state = |
| 8544 | xmlAutomataNewTransition2(ctxt->am, |
| 8545 | start, NULL, BAD_CAST "*", BAD_CAST "*", type); |
| 8546 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 8547 | /* |
| 8548 | * 2. the {"*"} for elements in no namespace. |
| 8549 | */ |
| 8550 | ctxt->state = |
| 8551 | xmlAutomataNewTransition2(ctxt->am, |
| 8552 | start, NULL, BAD_CAST "*", NULL, type); |
| 8553 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 8554 | |
| 8555 | } else if (wild->nsSet != NULL) { |
| 8556 | ns = wild->nsSet; |
| 8557 | do { |
| 8558 | ctxt->state = start; |
| 8559 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 8560 | ctxt->state, NULL, BAD_CAST "*", ns->value, type); |
| 8561 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 8562 | ns = ns->next; |
| 8563 | } while (ns != NULL); |
| 8564 | |
| 8565 | } else if (wild->negNsSet != NULL) { |
| 8566 | xmlAutomataStatePtr deadEnd; |
| 8567 | |
| 8568 | deadEnd = xmlAutomataNewState(ctxt->am); |
| 8569 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 8570 | start, deadEnd, BAD_CAST "*", wild->negNsSet->value, type); |
| 8571 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 8572 | start, NULL, BAD_CAST "*", BAD_CAST "*", type); |
| 8573 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 8574 | } |
| 8575 | } else { |
| 8576 | int counter; |
| 8577 | xmlAutomataStatePtr hop; |
| 8578 | int maxOccurs = |
| 8579 | type->maxOccurs == UNBOUNDED ? UNBOUNDED : type->maxOccurs - 1; |
| 8580 | int minOccurs = |
| 8581 | type->minOccurs < 1 ? 0 : type->minOccurs - 1; |
| 8582 | |
| 8583 | counter = xmlAutomataNewCounter(ctxt->am, minOccurs, maxOccurs); |
| 8584 | hop = xmlAutomataNewState(ctxt->am); |
| 8585 | if (wild->any == 1) { |
| 8586 | ctxt->state = |
| 8587 | xmlAutomataNewTransition2(ctxt->am, |
| 8588 | start, NULL, BAD_CAST "*", BAD_CAST "*", type); |
| 8589 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 8590 | ctxt->state = |
| 8591 | xmlAutomataNewTransition2(ctxt->am, |
| 8592 | start, NULL, BAD_CAST "*", NULL, type); |
| 8593 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 8594 | } else if (wild->nsSet != NULL) { |
| 8595 | ns = wild->nsSet; |
| 8596 | do { |
| 8597 | ctxt->state = |
| 8598 | xmlAutomataNewTransition2(ctxt->am, |
| 8599 | start, NULL, BAD_CAST "*", ns->value, type); |
| 8600 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 8601 | ns = ns->next; |
| 8602 | } while (ns != NULL); |
| 8603 | |
| 8604 | } else if (wild->negNsSet != NULL) { |
| 8605 | xmlAutomataStatePtr deadEnd; |
| 8606 | |
| 8607 | deadEnd = xmlAutomataNewState(ctxt->am); |
| 8608 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 8609 | start, deadEnd, BAD_CAST "*", wild->negNsSet->value, type); |
| 8610 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 8611 | start, NULL, BAD_CAST "*", BAD_CAST "*", type); |
| 8612 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 8613 | } |
| 8614 | xmlAutomataNewCountedTrans(ctxt->am, hop, start, counter); |
| 8615 | xmlAutomataNewCounterTrans(ctxt->am, hop, end, counter); |
| 8616 | } |
| 8617 | if (type->minOccurs == 0) { |
| 8618 | xmlAutomataNewEpsilon(ctxt->am, start, end); |
| 8619 | } |
| 8620 | ctxt->state = end; |
| 8621 | break; |
| 8622 | } |
| 8623 | case XML_SCHEMA_TYPE_ELEMENT:{ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8624 | xmlAutomataStatePtr oldstate; |
| 8625 | xmlSchemaElementPtr particle, elemDecl; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 8626 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8627 | /* |
| 8628 | * IMPORTANT: This puts element declarations |
| 8629 | * (and never element decl. references) into the |
| 8630 | * automaton. This is crucial and should not be changed, |
| 8631 | * since validating functions rely now on it. |
| 8632 | */ |
| 8633 | particle = (xmlSchemaElementPtr) type; |
| 8634 | if (particle->ref != NULL) { |
| 8635 | if (particle->refDecl == NULL) { |
| 8636 | /* |
| 8637 | * Skip content model creation if the reference |
| 8638 | * did not resolve to a declaration. |
| 8639 | */ |
| 8640 | break; |
| 8641 | } else { |
| 8642 | /* |
| 8643 | * Referenced global element declaration. |
| 8644 | */ |
| 8645 | elemDecl = particle->refDecl; |
| 8646 | } |
| 8647 | } else { |
| 8648 | /* |
| 8649 | * Anonymous element declaration. |
| 8650 | */ |
| 8651 | elemDecl = particle; |
| 8652 | } |
| 8653 | |
| 8654 | oldstate = ctxt->state; |
| 8655 | |
| 8656 | if (particle->maxOccurs >= UNBOUNDED) { |
| 8657 | if (particle->minOccurs > 1) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8658 | xmlAutomataStatePtr tmp; |
| 8659 | int counter; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 8660 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8661 | ctxt->state = xmlAutomataNewEpsilon(ctxt->am, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8662 | oldstate, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8663 | oldstate = ctxt->state; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8664 | counter = xmlAutomataNewCounter(ctxt->am, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8665 | particle->minOccurs - 1, UNBOUNDED); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 8666 | ctxt->state = |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8667 | xmlAutomataNewTransition2(ctxt->am, |
| 8668 | ctxt->state, NULL, |
| 8669 | elemDecl->name, |
| 8670 | elemDecl->targetNamespace, |
| 8671 | (xmlSchemaTypePtr) elemDecl); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8672 | tmp = ctxt->state; |
| 8673 | xmlAutomataNewCountedTrans(ctxt->am, tmp, oldstate, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8674 | counter); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8675 | ctxt->state = |
| 8676 | xmlAutomataNewCounterTrans(ctxt->am, tmp, NULL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8677 | counter); |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 8678 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8679 | } else { |
| 8680 | ctxt->state = |
| 8681 | xmlAutomataNewTransition2(ctxt->am, |
| 8682 | ctxt->state, NULL, |
| 8683 | elemDecl->name, |
| 8684 | elemDecl->targetNamespace, |
| 8685 | (xmlSchemaTypePtr) elemDecl); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8686 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, |
| 8687 | oldstate); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8688 | if (particle->minOccurs == 0) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8689 | /* basically an elem* */ |
| 8690 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
| 8691 | ctxt->state); |
| 8692 | } |
| 8693 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8694 | } else if ((particle->maxOccurs > 1) || (particle->minOccurs > 1)) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8695 | xmlAutomataStatePtr tmp; |
| 8696 | int counter; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 8697 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8698 | ctxt->state = xmlAutomataNewEpsilon(ctxt->am, |
| 8699 | oldstate, NULL); |
| 8700 | oldstate = ctxt->state; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8701 | counter = xmlAutomataNewCounter(ctxt->am, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8702 | particle->minOccurs - 1, |
| 8703 | particle->maxOccurs - 1); |
| 8704 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 8705 | ctxt->state, |
| 8706 | NULL, |
| 8707 | elemDecl->name, |
| 8708 | elemDecl->targetNamespace, |
| 8709 | (xmlSchemaTypePtr) elemDecl); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8710 | tmp = ctxt->state; |
| 8711 | xmlAutomataNewCountedTrans(ctxt->am, tmp, oldstate, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8712 | counter); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8713 | ctxt->state = xmlAutomataNewCounterTrans(ctxt->am, tmp, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8714 | NULL, counter); |
| 8715 | if (particle->minOccurs == 0) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8716 | /* basically an elem? */ |
| 8717 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8718 | ctxt->state); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8719 | } |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 8720 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8721 | } else { |
| 8722 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 8723 | ctxt->state, |
| 8724 | NULL, |
| 8725 | elemDecl->name, |
| 8726 | elemDecl->targetNamespace, |
| 8727 | (xmlSchemaTypePtr) elemDecl); |
| 8728 | if (particle->minOccurs == 0) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8729 | /* basically an elem? */ |
| 8730 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8731 | ctxt->state); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8732 | } |
| 8733 | } |
| 8734 | break; |
| 8735 | } |
| 8736 | case XML_SCHEMA_TYPE_SEQUENCE:{ |
| 8737 | xmlSchemaTypePtr subtypes; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 8738 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8739 | /* |
| 8740 | * If max and min occurances are default (1) then |
| 8741 | * simply iterate over the subtypes |
| 8742 | */ |
| 8743 | if ((type->minOccurs == 1) && (type->maxOccurs == 1)) { |
| 8744 | subtypes = type->subtypes; |
| 8745 | while (subtypes != NULL) { |
| 8746 | xmlSchemaBuildAContentModel(subtypes, ctxt, name); |
| 8747 | subtypes = subtypes->next; |
| 8748 | } |
| 8749 | } else { |
| 8750 | xmlAutomataStatePtr oldstate = ctxt->state; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 8751 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8752 | if (type->maxOccurs >= UNBOUNDED) { |
| 8753 | if (type->minOccurs > 1) { |
| 8754 | xmlAutomataStatePtr tmp; |
| 8755 | int counter; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 8756 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8757 | ctxt->state = xmlAutomataNewEpsilon(ctxt->am, |
| 8758 | oldstate, |
| 8759 | NULL); |
| 8760 | oldstate = ctxt->state; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 8761 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8762 | counter = xmlAutomataNewCounter(ctxt->am, |
| 8763 | type-> |
| 8764 | minOccurs - 1, |
| 8765 | UNBOUNDED); |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 8766 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8767 | subtypes = type->subtypes; |
| 8768 | while (subtypes != NULL) { |
| 8769 | xmlSchemaBuildAContentModel(subtypes, ctxt, |
| 8770 | name); |
| 8771 | subtypes = subtypes->next; |
| 8772 | } |
| 8773 | tmp = ctxt->state; |
| 8774 | xmlAutomataNewCountedTrans(ctxt->am, tmp, |
| 8775 | oldstate, counter); |
| 8776 | ctxt->state = |
| 8777 | xmlAutomataNewCounterTrans(ctxt->am, tmp, |
| 8778 | NULL, counter); |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 8779 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8780 | } else { |
| 8781 | subtypes = type->subtypes; |
| 8782 | while (subtypes != NULL) { |
| 8783 | xmlSchemaBuildAContentModel(subtypes, ctxt, |
| 8784 | name); |
| 8785 | subtypes = subtypes->next; |
| 8786 | } |
| 8787 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, |
| 8788 | oldstate); |
| 8789 | if (type->minOccurs == 0) { |
| 8790 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
| 8791 | ctxt->state); |
| 8792 | } |
| 8793 | } |
| 8794 | } else if ((type->maxOccurs > 1) |
| 8795 | || (type->minOccurs > 1)) { |
| 8796 | xmlAutomataStatePtr tmp; |
| 8797 | int counter; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 8798 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8799 | ctxt->state = xmlAutomataNewEpsilon(ctxt->am, |
| 8800 | oldstate, |
| 8801 | NULL); |
| 8802 | oldstate = ctxt->state; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8803 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8804 | counter = xmlAutomataNewCounter(ctxt->am, |
| 8805 | type->minOccurs - |
| 8806 | 1, |
| 8807 | type->maxOccurs - |
| 8808 | 1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8809 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8810 | subtypes = type->subtypes; |
| 8811 | while (subtypes != NULL) { |
| 8812 | xmlSchemaBuildAContentModel(subtypes, ctxt, |
| 8813 | name); |
| 8814 | subtypes = subtypes->next; |
| 8815 | } |
| 8816 | tmp = ctxt->state; |
| 8817 | xmlAutomataNewCountedTrans(ctxt->am, tmp, oldstate, |
| 8818 | counter); |
| 8819 | ctxt->state = |
| 8820 | xmlAutomataNewCounterTrans(ctxt->am, tmp, NULL, |
| 8821 | counter); |
| 8822 | if (type->minOccurs == 0) { |
| 8823 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
| 8824 | ctxt->state); |
| 8825 | } |
Daniel Veillard | b509f15 | 2002-04-17 16:28:10 +0000 | [diff] [blame] | 8826 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8827 | } else { |
| 8828 | subtypes = type->subtypes; |
| 8829 | while (subtypes != NULL) { |
| 8830 | xmlSchemaBuildAContentModel(subtypes, ctxt, |
| 8831 | name); |
| 8832 | subtypes = subtypes->next; |
| 8833 | } |
| 8834 | if (type->minOccurs == 0) { |
| 8835 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
| 8836 | ctxt->state); |
| 8837 | } |
| 8838 | } |
| 8839 | } |
| 8840 | break; |
| 8841 | } |
| 8842 | case XML_SCHEMA_TYPE_CHOICE:{ |
| 8843 | xmlSchemaTypePtr subtypes; |
| 8844 | xmlAutomataStatePtr start, end; |
Daniel Veillard | b509f15 | 2002-04-17 16:28:10 +0000 | [diff] [blame] | 8845 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8846 | start = ctxt->state; |
| 8847 | end = xmlAutomataNewState(ctxt->am); |
Daniel Veillard | 7646b18 | 2002-04-20 06:41:40 +0000 | [diff] [blame] | 8848 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8849 | /* |
| 8850 | * iterate over the subtypes and remerge the end with an |
| 8851 | * epsilon transition |
| 8852 | */ |
| 8853 | if (type->maxOccurs == 1) { |
| 8854 | subtypes = type->subtypes; |
| 8855 | while (subtypes != NULL) { |
| 8856 | ctxt->state = start; |
| 8857 | xmlSchemaBuildAContentModel(subtypes, ctxt, name); |
| 8858 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 8859 | subtypes = subtypes->next; |
| 8860 | } |
| 8861 | } else { |
| 8862 | int counter; |
| 8863 | xmlAutomataStatePtr hop; |
| 8864 | int maxOccurs = type->maxOccurs == UNBOUNDED ? |
| 8865 | UNBOUNDED : type->maxOccurs - 1; |
| 8866 | int minOccurs = |
| 8867 | type->minOccurs < 1 ? 0 : type->minOccurs - 1; |
Daniel Veillard | 7646b18 | 2002-04-20 06:41:40 +0000 | [diff] [blame] | 8868 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8869 | /* |
| 8870 | * use a counter to keep track of the number of transtions |
| 8871 | * which went through the choice. |
| 8872 | */ |
| 8873 | counter = |
| 8874 | xmlAutomataNewCounter(ctxt->am, minOccurs, |
| 8875 | maxOccurs); |
| 8876 | hop = xmlAutomataNewState(ctxt->am); |
Daniel Veillard | 6231e84 | 2002-04-18 11:54:04 +0000 | [diff] [blame] | 8877 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8878 | subtypes = type->subtypes; |
| 8879 | while (subtypes != NULL) { |
| 8880 | ctxt->state = start; |
| 8881 | xmlSchemaBuildAContentModel(subtypes, ctxt, name); |
| 8882 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 8883 | subtypes = subtypes->next; |
| 8884 | } |
| 8885 | xmlAutomataNewCountedTrans(ctxt->am, hop, start, |
| 8886 | counter); |
| 8887 | xmlAutomataNewCounterTrans(ctxt->am, hop, end, |
| 8888 | counter); |
| 8889 | } |
| 8890 | if (type->minOccurs == 0) { |
| 8891 | xmlAutomataNewEpsilon(ctxt->am, start, end); |
| 8892 | } |
| 8893 | ctxt->state = end; |
| 8894 | break; |
| 8895 | } |
| 8896 | case XML_SCHEMA_TYPE_ALL:{ |
| 8897 | xmlAutomataStatePtr start; |
| 8898 | xmlSchemaTypePtr subtypes; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8899 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 8900 | xmlSchemaElementPtr elem; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8901 | int lax; |
| 8902 | |
| 8903 | subtypes = type->subtypes; |
| 8904 | if (subtypes == NULL) |
| 8905 | break; |
| 8906 | start = ctxt->state; |
| 8907 | while (subtypes != NULL) { |
| 8908 | ctxt->state = start; |
William M. Brack | 9989c7d | 2004-05-12 14:39:38 +0000 | [diff] [blame] | 8909 | /* |
| 8910 | * the following 'if' was needed to fix bug 139897 |
| 8911 | * not quite sure why it only needs to be done for |
| 8912 | * elements with a 'ref', but it seems to work ok. |
| 8913 | */ |
| 8914 | if (subtypes->ref != NULL) |
| 8915 | xmlSchemaBuildAContentModel(subtypes, ctxt, name); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8916 | elem = (xmlSchemaElementPtr) subtypes; |
| 8917 | /* |
| 8918 | * NOTE: The {max occurs} of all the particles in the |
| 8919 | * {particles} of the group must be 0 or 1. |
| 8920 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8921 | if ((elem->minOccurs == 1) && (elem->maxOccurs == 1)) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8922 | xmlAutomataNewOnceTrans2(ctxt->am, ctxt->state, |
| 8923 | ctxt->state, |
| 8924 | elem->name, |
| 8925 | elem->targetNamespace, |
| 8926 | 1, 1, subtypes); |
| 8927 | } else if ((elem->minOccurs == 0) && |
| 8928 | (elem->maxOccurs == 1)) { |
| 8929 | |
| 8930 | xmlAutomataNewCountTrans2(ctxt->am, ctxt->state, |
| 8931 | ctxt->state, |
| 8932 | elem->name, |
| 8933 | elem->targetNamespace, |
| 8934 | 0, |
| 8935 | 1, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8936 | subtypes); |
| 8937 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8938 | /* |
| 8939 | * NOTE: if maxOccurs == 0 then no transition will be |
| 8940 | * created. |
| 8941 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8942 | subtypes = subtypes->next; |
| 8943 | } |
| 8944 | lax = type->minOccurs == 0; |
| 8945 | ctxt->state = |
| 8946 | xmlAutomataNewAllTrans(ctxt->am, ctxt->state, NULL, |
| 8947 | lax); |
| 8948 | break; |
| 8949 | } |
| 8950 | case XML_SCHEMA_TYPE_RESTRICTION: |
| 8951 | if (type->subtypes != NULL) |
| 8952 | xmlSchemaBuildAContentModel(type->subtypes, ctxt, name); |
| 8953 | break; |
| 8954 | case XML_SCHEMA_TYPE_EXTENSION: |
| 8955 | if (type->baseType != NULL) { |
| 8956 | xmlSchemaTypePtr subtypes; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8957 | |
| 8958 | /* |
| 8959 | * TODO: Circular definitions will be checked at the |
| 8960 | * constraint level. So remove this when the complex type |
| 8961 | * constraints are implemented. |
| 8962 | */ |
Daniel Veillard | f762755 | 2004-04-22 07:15:40 +0000 | [diff] [blame] | 8963 | if (type->recurse) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8964 | /* TODO: Change the error code. */ |
| 8965 | xmlSchemaPCustomErr(ctxt, |
| 8966 | XML_SCHEMAP_UNKNOWN_BASE_TYPE, |
| 8967 | NULL, type, type->node, |
| 8968 | "This item is circular", NULL); |
Daniel Veillard | f762755 | 2004-04-22 07:15:40 +0000 | [diff] [blame] | 8969 | return; |
| 8970 | } |
| 8971 | type->recurse = 1; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8972 | xmlSchemaBuildAContentModel(type->baseType, ctxt, name); |
Daniel Veillard | f762755 | 2004-04-22 07:15:40 +0000 | [diff] [blame] | 8973 | type->recurse = 0; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8974 | subtypes = type->subtypes; |
| 8975 | while (subtypes != NULL) { |
| 8976 | xmlSchemaBuildAContentModel(subtypes, ctxt, name); |
| 8977 | subtypes = subtypes->next; |
| 8978 | } |
| 8979 | } else if (type->subtypes != NULL) |
| 8980 | xmlSchemaBuildAContentModel(type->subtypes, ctxt, name); |
| 8981 | break; |
| 8982 | case XML_SCHEMA_TYPE_GROUP: |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 8983 | /* |
| 8984 | * Handle model group definition references. |
| 8985 | * NOTE: type->subtypes is the referenced model grop definition; |
| 8986 | * and type->subtypes->subtypes is the model group (i.e. <all> or |
| 8987 | * <choice> or <sequence>). |
| 8988 | */ |
| 8989 | if ((type->ref != NULL) && (type->subtypes != NULL) && |
| 8990 | (type->subtypes->subtypes != NULL)) { |
| 8991 | xmlSchemaTypePtr modelGr; |
| 8992 | xmlAutomataStatePtr start, end; |
| 8993 | |
| 8994 | modelGr = type->subtypes->subtypes; |
| 8995 | start = ctxt->state; |
| 8996 | end = xmlAutomataNewState(ctxt->am); |
| 8997 | if (type->maxOccurs == 1) { |
| 8998 | ctxt->state = start; |
| 8999 | xmlSchemaBuildAContentModel(modelGr, ctxt, name); |
| 9000 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 9001 | } else { |
| 9002 | int counter; |
| 9003 | xmlAutomataStatePtr hop; |
| 9004 | int maxOccurs = type->maxOccurs == UNBOUNDED ? |
| 9005 | UNBOUNDED : type->maxOccurs - 1; |
| 9006 | int minOccurs = |
| 9007 | type->minOccurs < 1 ? 0 : type->minOccurs - 1; |
| 9008 | |
| 9009 | counter = |
| 9010 | xmlAutomataNewCounter(ctxt->am, minOccurs, maxOccurs); |
| 9011 | hop = xmlAutomataNewState(ctxt->am); |
| 9012 | ctxt->state = start; |
| 9013 | xmlSchemaBuildAContentModel(modelGr, ctxt, name); |
| 9014 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 9015 | xmlAutomataNewCountedTrans(ctxt->am, hop, start, |
| 9016 | counter); |
| 9017 | xmlAutomataNewCounterTrans(ctxt->am, hop, end, |
| 9018 | counter); |
| 9019 | } |
| 9020 | if (type->minOccurs == 0) { |
| 9021 | xmlAutomataNewEpsilon(ctxt->am, start, end); |
| 9022 | } |
| 9023 | ctxt->state = end; |
| 9024 | break; |
| 9025 | } |
| 9026 | break; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9027 | case XML_SCHEMA_TYPE_COMPLEX: |
| 9028 | case XML_SCHEMA_TYPE_COMPLEX_CONTENT: |
| 9029 | if (type->subtypes != NULL) |
| 9030 | xmlSchemaBuildAContentModel(type->subtypes, ctxt, name); |
| 9031 | break; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9032 | case XML_SCHEMA_TYPE_SIMPLE_CONTENT: |
| 9033 | break; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9034 | default: |
| 9035 | xmlGenericError(xmlGenericErrorContext, |
| 9036 | "Found unexpected type %d in %s content model\n", |
| 9037 | type->type, name); |
| 9038 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9039 | } |
| 9040 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9041 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9042 | /** |
| 9043 | * xmlSchemaBuildContentModel: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9044 | * @type: the type definition (or reference) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9045 | * @ctxt: the schema parser context |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 9046 | * @name: the element name |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9047 | * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9048 | * Builds the content model of the complex type. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9049 | */ |
| 9050 | static void |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9051 | xmlSchemaBuildContentModel(xmlSchemaTypePtr type, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9052 | xmlSchemaParserCtxtPtr ctxt, |
| 9053 | const xmlChar * name) |
| 9054 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9055 | xmlAutomataStatePtr start; |
| 9056 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9057 | if ((type->type != XML_SCHEMA_TYPE_COMPLEX) || (type->ref != NULL) || |
| 9058 | (type->contentType == XML_SCHEMA_CONTENT_BASIC) || |
| 9059 | (type->contentType == XML_SCHEMA_CONTENT_SIMPLE) || |
| 9060 | (type->contModel != NULL)) |
| 9061 | return; |
Daniel Veillard | decd64d | 2002-04-18 14:41:51 +0000 | [diff] [blame] | 9062 | |
| 9063 | #ifdef DEBUG_CONTENT |
| 9064 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9065 | "Building content model for %s\n", name); |
Daniel Veillard | decd64d | 2002-04-18 14:41:51 +0000 | [diff] [blame] | 9066 | #endif |
| 9067 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9068 | ctxt->am = xmlNewAutomata(); |
| 9069 | if (ctxt->am == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9070 | xmlGenericError(xmlGenericErrorContext, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9071 | "Cannot create automata for complex tpye %s\n", name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9072 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9073 | } |
| 9074 | start = ctxt->state = xmlAutomataGetInitState(ctxt->am); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9075 | xmlSchemaBuildAContentModel(type, ctxt, name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9076 | xmlAutomataSetFinalState(ctxt->am, ctxt->state); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9077 | type->contModel = xmlAutomataCompile(ctxt->am); |
| 9078 | if (type->contModel == NULL) { |
| 9079 | xmlSchemaPCustomErr(ctxt, |
| 9080 | XML_SCHEMAP_INTERNAL, |
| 9081 | NULL, type, type->node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9082 | "Failed to compile the content model", NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9083 | } else if (xmlRegexpIsDeterminist(type->contModel) != 1) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 9084 | xmlSchemaPCustomErr(ctxt, |
| 9085 | XML_SCHEMAP_NOT_DETERMINISTIC, |
| 9086 | /* XML_SCHEMAS_ERR_NOTDETERMINIST, */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9087 | NULL, type, type->node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9088 | "The content model is not determinist", NULL); |
Daniel Veillard | e19fc23 | 2002-04-22 16:01:24 +0000 | [diff] [blame] | 9089 | } else { |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 9090 | #ifdef DEBUG_CONTENT_REGEXP |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9091 | xmlGenericError(xmlGenericErrorContext, |
| 9092 | "Content model of %s:\n", name); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9093 | xmlRegexpPrint(stderr, type->contModel); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9094 | #endif |
Daniel Veillard | e19fc23 | 2002-04-22 16:01:24 +0000 | [diff] [blame] | 9095 | } |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 9096 | ctxt->state = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9097 | xmlFreeAutomata(ctxt->am); |
| 9098 | ctxt->am = NULL; |
| 9099 | } |
| 9100 | |
| 9101 | /** |
| 9102 | * xmlSchemaRefFixupCallback: |
| 9103 | * @elem: the schema element context |
| 9104 | * @ctxt: the schema parser context |
| 9105 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9106 | * Resolves the references of an element declaration |
| 9107 | * or particle, which has an element declaration as it's |
| 9108 | * term. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9109 | */ |
| 9110 | static void |
| 9111 | xmlSchemaRefFixupCallback(xmlSchemaElementPtr elem, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9112 | xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9113 | const xmlChar * name ATTRIBUTE_UNUSED, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9114 | const xmlChar * context ATTRIBUTE_UNUSED, |
| 9115 | const xmlChar * namespace ATTRIBUTE_UNUSED) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9116 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9117 | if ((ctxt == NULL) || (elem == NULL) || |
| 9118 | ((elem != NULL) && (elem->flags & XML_SCHEMAS_ELEM_INTERNAL_RESOLVED))) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9119 | return; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9120 | elem->flags |= XML_SCHEMAS_ELEM_INTERNAL_RESOLVED; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9121 | if (elem->ref != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9122 | xmlSchemaElementPtr elemDecl; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9123 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9124 | /* |
| 9125 | * TODO: Evaluate, what errors could occur if the declaration is not |
| 9126 | * found. It might be possible that the "typefixup" might crash if |
| 9127 | * no ref declaration was found. |
| 9128 | */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 9129 | elemDecl = xmlSchemaGetElem(ctxt->schema, elem->ref, elem->refNs); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9130 | if (elemDecl == NULL) { |
| 9131 | xmlSchemaPResCompAttrErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9132 | XML_SCHEMAP_SRC_RESOLVE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9133 | NULL, (xmlSchemaTypePtr) elem, elem->node, |
| 9134 | "ref", elem->ref, elem->refNs, |
| 9135 | XML_SCHEMA_TYPE_ELEMENT, NULL); |
| 9136 | } else |
| 9137 | elem->refDecl = elemDecl; |
| 9138 | } else { |
| 9139 | if ((elem->subtypes == NULL) && (elem->namedType != NULL)) { |
| 9140 | xmlSchemaTypePtr type; |
| 9141 | |
| 9142 | /* (type definition) ... otherwise the type definition ·resolved· |
| 9143 | * to by the ·actual value· of the type [attribute] ... |
| 9144 | */ |
| 9145 | type = xmlSchemaGetType(ctxt->schema, elem->namedType, |
| 9146 | elem->namedTypeNs); |
| 9147 | if (type == NULL) { |
| 9148 | xmlSchemaPResCompAttrErr(ctxt, |
| 9149 | XML_SCHEMAP_SRC_RESOLVE, |
| 9150 | NULL, (xmlSchemaTypePtr) elem, elem->node, |
| 9151 | "type", elem->namedType, elem->namedTypeNs, |
| 9152 | XML_SCHEMA_TYPE_BASIC, "type definition"); |
| 9153 | } else |
| 9154 | elem->subtypes = type; |
| 9155 | } |
| 9156 | if (elem->substGroup != NULL) { |
| 9157 | xmlSchemaElementPtr substHead; |
| 9158 | |
| 9159 | /* |
| 9160 | * FIXME TODO: Do we need a new field in _xmlSchemaElement for |
| 9161 | * substitutionGroup? |
| 9162 | */ |
| 9163 | substHead = xmlSchemaGetElem(ctxt->schema, elem->substGroup, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 9164 | elem->substGroupNs); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9165 | if (substHead == NULL) { |
| 9166 | xmlSchemaPResCompAttrErr(ctxt, |
| 9167 | XML_SCHEMAP_SRC_RESOLVE, |
| 9168 | NULL, (xmlSchemaTypePtr) elem, NULL, |
| 9169 | "substitutionGroup", elem->substGroup, elem->substGroupNs, |
| 9170 | XML_SCHEMA_TYPE_ELEMENT, NULL); |
| 9171 | } else { |
| 9172 | xmlSchemaRefFixupCallback(substHead, ctxt, NULL, NULL, NULL); |
| 9173 | /* |
| 9174 | * (type definition)...otherwise the {type definition} of the |
| 9175 | * element declaration ·resolved· to by the ·actual value· of |
| 9176 | * the substitutionGroup [attribute], if present |
| 9177 | */ |
| 9178 | if (elem->subtypes == NULL) |
| 9179 | elem->subtypes = substHead->subtypes; |
| 9180 | } |
| 9181 | } |
| 9182 | if ((elem->subtypes == NULL) && (elem->namedType == NULL) && |
| 9183 | (elem->substGroup == NULL)) |
| 9184 | elem->subtypes = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 9185 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9186 | } |
| 9187 | |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 9188 | /** |
| 9189 | * xmlSchemaParseListRefFixup: |
| 9190 | * @type: the schema type definition |
| 9191 | * @ctxt: the schema parser context |
| 9192 | * |
| 9193 | * Fixup of the itemType reference of the list type. |
| 9194 | */ |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 9195 | static void |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 9196 | xmlSchemaParseListRefFixup(xmlSchemaTypePtr type, xmlSchemaParserCtxtPtr ctxt) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9197 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9198 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9199 | if (((type->base == NULL) && |
| 9200 | (type->subtypes == NULL)) || |
| 9201 | ((type->base != NULL) && |
| 9202 | (type->subtypes != NULL))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9203 | /* |
| 9204 | * src-list-itemType-or-simpleType |
| 9205 | * Either the itemType [attribute] or the <simpleType> [child] of |
| 9206 | * the <list> element must be present, but not both. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9207 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9208 | /* |
| 9209 | * TODO: Move this to the parse function. |
| 9210 | */ |
| 9211 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9212 | XML_SCHEMAP_SRC_LIST_ITEMTYPE_OR_SIMPLETYPE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9213 | NULL, type, type->node, |
| 9214 | "The attribute 'itemType' and the <simpleType> child " |
| 9215 | "are mutually exclusive", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9216 | } else if (type->base!= NULL) { |
| 9217 | type->subtypes = xmlSchemaGetType(ctxt->schema, type->base, type->baseNs); |
| 9218 | if (type->subtypes == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9219 | xmlSchemaPResCompAttrErr(ctxt, |
| 9220 | XML_SCHEMAP_SRC_RESOLVE, |
| 9221 | NULL, type, type->node, |
| 9222 | "itemType", type->base, type->baseNs, |
| 9223 | XML_SCHEMA_TYPE_SIMPLE, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9224 | } |
| 9225 | } |
| 9226 | if ((type->subtypes != NULL) && |
| 9227 | (type->subtypes->contentType == XML_SCHEMA_CONTENT_UNKNOWN)) |
| 9228 | xmlSchemaTypeFixup(type->subtypes, ctxt, NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 9229 | } |
| 9230 | |
| 9231 | /** |
| 9232 | * xmlSchemaParseUnionRefCheck: |
| 9233 | * @typeDecl: the schema type definition |
| 9234 | * @ctxt: the schema parser context |
| 9235 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9236 | * Checks and builds the memberTypes of the union type. |
| 9237 | * Returns -1 in case of an internal error, 0 otherwise. |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 9238 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9239 | static int |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 9240 | xmlSchemaParseUnionRefCheck(xmlSchemaTypePtr type, |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 9241 | xmlSchemaParserCtxtPtr ctxt) |
| 9242 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9243 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9244 | xmlSchemaTypeLinkPtr link, lastLink = NULL, prevLink, subLink, newLink; |
| 9245 | xmlSchemaTypePtr memberType, ctxtType; |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 9246 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9247 | /* 1 If the <union> alternative is chosen, then [Definition:] |
| 9248 | * define the explicit members as the type definitions ·resolved· |
| 9249 | * to by the items in the ·actual value· of the memberTypes [attribute], |
| 9250 | * if any, followed by the type definitions corresponding to the |
| 9251 | * <simpleType>s among the [children] of <union>, if any. |
| 9252 | */ |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 9253 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9254 | if (type->type != XML_SCHEMA_TYPE_UNION) |
| 9255 | return (-1); |
| 9256 | if (ctxt->ctxtType == NULL) { |
| 9257 | xmlSchemaPErr(ctxt, type->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 9258 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9259 | "Internal error: xmlSchemaParseUnionRefCheck, no parent type " |
| 9260 | "available", NULL, NULL); |
| 9261 | return (-1); |
| 9262 | } |
| 9263 | /* |
| 9264 | * src-union-memberTypes-or-simpleTypes |
| 9265 | * Either the memberTypes [attribute] of the <union> element must |
| 9266 | * be non-empty or there must be at least one simpleType [child]. |
| 9267 | */ |
| 9268 | if ((type->base == NULL) && |
| 9269 | (type->subtypes == NULL)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9270 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9271 | XML_SCHEMAP_SRC_UNION_MEMBERTYPES_OR_SIMPLETYPES, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9272 | NULL, NULL, type->node, |
| 9273 | "Either the attribute 'memberTypes' must be non-empty " |
| 9274 | "or there must be at least one <simpleType> child", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9275 | } |
| 9276 | |
| 9277 | ctxtType = ctxt->ctxtType; |
| 9278 | if (type->base != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9279 | xmlAttrPtr attr; |
| 9280 | const xmlChar *cur, *end; |
| 9281 | xmlChar *tmp; |
| 9282 | const xmlChar *localName, *uri; |
| 9283 | |
| 9284 | attr = xmlSchemaGetPropNode(type->node, "memberTypes"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9285 | cur = type->base; |
| 9286 | do { |
| 9287 | while (IS_BLANK_CH(*cur)) |
| 9288 | cur++; |
| 9289 | end = cur; |
| 9290 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 9291 | end++; |
| 9292 | if (end == cur) |
| 9293 | break; |
| 9294 | tmp = xmlStrndup(cur, end - cur); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9295 | xmlSchemaPValAttrNodeQNameValue(ctxt, ctxt->schema, NULL, |
| 9296 | NULL, attr, BAD_CAST tmp, &uri, NULL, &localName); |
| 9297 | memberType = xmlSchemaGetType(ctxt->schema, localName, uri); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9298 | if (memberType == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9299 | xmlSchemaPResCompAttrErr(ctxt, |
| 9300 | XML_SCHEMAP_UNKNOWN_MEMBER_TYPE, |
| 9301 | NULL, NULL, type->node, "memberTypes", localName, uri, |
| 9302 | XML_SCHEMA_TYPE_SIMPLE, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9303 | } else { |
| 9304 | if (memberType->contentType == XML_SCHEMA_CONTENT_UNKNOWN) |
| 9305 | xmlSchemaTypeFixup(memberType, ctxt, NULL); |
| 9306 | link = (xmlSchemaTypeLinkPtr) xmlMalloc(sizeof(xmlSchemaTypeLink)); |
| 9307 | if (link == NULL) { |
| 9308 | xmlSchemaPErrMemory(ctxt, "allocating a type link", NULL); |
| 9309 | return (-1); |
| 9310 | } |
| 9311 | link->type = memberType; |
| 9312 | link->next = NULL; |
| 9313 | if (lastLink == NULL) |
| 9314 | ctxtType->memberTypes = link; |
| 9315 | else |
| 9316 | lastLink->next = link; |
| 9317 | lastLink = link; |
| 9318 | } |
| 9319 | xmlFree(tmp); |
| 9320 | cur = end; |
| 9321 | } while (*cur != 0); |
| 9322 | } |
| 9323 | /* |
| 9324 | * Add local simple types, |
| 9325 | */ |
| 9326 | memberType = type->subtypes; |
| 9327 | while (memberType != NULL) { |
| 9328 | if (memberType->contentType == XML_SCHEMA_CONTENT_UNKNOWN) |
| 9329 | xmlSchemaTypeFixup(memberType, ctxt, NULL); |
| 9330 | link = (xmlSchemaTypeLinkPtr) xmlMalloc(sizeof(xmlSchemaTypeLink)); |
| 9331 | if (link == NULL) { |
| 9332 | xmlSchemaPErrMemory(ctxt, "allocating a type link", NULL); |
| 9333 | return (-1); |
| 9334 | } |
| 9335 | link->type = memberType; |
| 9336 | link->next = NULL; |
| 9337 | if (lastLink == NULL) |
| 9338 | ctxtType->memberTypes = link; |
| 9339 | else |
| 9340 | lastLink->next = link; |
| 9341 | lastLink = link; |
| 9342 | memberType = memberType->next; |
| 9343 | } |
| 9344 | /* |
| 9345 | * The actual value is then formed by replacing any union type |
| 9346 | * definition in the ·explicit members· with the members of their |
| 9347 | * {member type definitions}, in order. |
| 9348 | */ |
| 9349 | link = ctxtType->memberTypes; |
| 9350 | while (link != NULL) { |
| 9351 | if (link->type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
| 9352 | subLink = link->type->memberTypes; |
| 9353 | if (subLink != NULL) { |
| 9354 | link->type = subLink->type; |
| 9355 | if (subLink->next != NULL) { |
| 9356 | lastLink = link->next; |
| 9357 | subLink = subLink->next; |
| 9358 | prevLink = link; |
| 9359 | while (subLink != NULL) { |
| 9360 | newLink = (xmlSchemaTypeLinkPtr) |
| 9361 | xmlMalloc(sizeof(xmlSchemaTypeLink)); |
| 9362 | if (newLink == NULL) { |
| 9363 | xmlSchemaPErrMemory(ctxt, "allocating a type link", |
| 9364 | NULL); |
| 9365 | return (-1); |
| 9366 | } |
| 9367 | newLink->type = memberType; |
| 9368 | prevLink->next = newLink; |
| 9369 | prevLink = newLink; |
| 9370 | newLink->next = lastLink; |
| 9371 | |
| 9372 | subLink = subLink->next; |
| 9373 | } |
| 9374 | } |
| 9375 | } |
| 9376 | } |
| 9377 | link = link->next; |
| 9378 | } |
| 9379 | |
| 9380 | return (0); |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 9381 | } |
| 9382 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9383 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9384 | * xmlSchemaIsDerivedFromBuiltInType: |
| 9385 | * @ctxt: the schema parser context |
| 9386 | * @type: the type definition |
| 9387 | * @valType: the value type |
| 9388 | * |
| 9389 | * |
| 9390 | * Returns 1 if the type has the given value type, or |
| 9391 | * is derived from such a type. |
| 9392 | */ |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 9393 | static int |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9394 | xmlSchemaIsDerivedFromBuiltInType(xmlSchemaParserCtxtPtr ctxt, |
| 9395 | xmlSchemaTypePtr type, int valType) |
| 9396 | { |
| 9397 | /* TODO: Check if this works in every case. */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9398 | if ((type->type == XML_SCHEMA_TYPE_BASIC) && |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9399 | (type->contentType == XML_SCHEMA_CONTENT_BASIC)) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9400 | if (type->builtInType == valType) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9401 | return(1); |
| 9402 | } else if (type->type == XML_SCHEMA_TYPE_ATTRIBUTE) { |
| 9403 | if (((xmlSchemaAttributePtr) type)->subtypes != NULL) |
| 9404 | return(xmlSchemaIsDerivedFromBuiltInType(ctxt, |
| 9405 | ((xmlSchemaAttributePtr) type)->subtypes, valType)); |
| 9406 | } else if ((type->type == XML_SCHEMA_TYPE_RESTRICTION) || |
| 9407 | (type->type == XML_SCHEMA_TYPE_EXTENSION)) { |
| 9408 | if (type->baseType != NULL) |
| 9409 | return(xmlSchemaIsDerivedFromBuiltInType(ctxt, type->baseType, |
| 9410 | valType)); |
| 9411 | } else if ((type->subtypes != NULL) && |
| 9412 | ((type->subtypes->type == XML_SCHEMA_TYPE_COMPLEX) || |
| 9413 | (type->subtypes->type == XML_SCHEMA_TYPE_COMPLEX_CONTENT) || |
| 9414 | (type->subtypes->type == XML_SCHEMA_TYPE_SIMPLE) || |
| 9415 | (type->subtypes->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT))) { |
| 9416 | return(xmlSchemaIsDerivedFromBuiltInType(ctxt, type->subtypes, |
| 9417 | valType)); |
| 9418 | } |
| 9419 | |
| 9420 | return (0); |
| 9421 | } |
| 9422 | |
| 9423 | /** |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9424 | * xmlSchemaIsDerivedFromBuiltInType: |
| 9425 | * @type: the simpleType definition |
| 9426 | * |
| 9427 | * Returns the primitive type of the given type or |
| 9428 | * NULL in case of error. |
| 9429 | */ |
| 9430 | static xmlSchemaTypePtr |
| 9431 | xmlSchemaGetPrimitiveType(xmlSchemaTypePtr type) |
| 9432 | { |
| 9433 | while (type != NULL) { |
| 9434 | if (type->flags & XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE) |
| 9435 | return (type); |
| 9436 | type = type->baseType; |
| 9437 | } |
| 9438 | |
| 9439 | return (NULL); |
| 9440 | } |
| 9441 | |
| 9442 | |
| 9443 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9444 | * xmlSchemaBuildAttributeUsesOwned: |
| 9445 | * @ctxt: the schema parser context |
| 9446 | * @type: the complex type definition |
| 9447 | * @cur: the attribute declaration list |
| 9448 | * @lastUse: the top of the attribute use list |
| 9449 | * |
| 9450 | * Builds the attribute uses list on the given complex type. |
| 9451 | * This one is supposed to be called by |
| 9452 | * xmlSchemaBuildAttributeValidation only. |
| 9453 | */ |
| 9454 | static int |
| 9455 | xmlSchemaBuildAttributeUsesOwned(xmlSchemaParserCtxtPtr ctxt, |
| 9456 | xmlSchemaAttributePtr cur, |
| 9457 | xmlSchemaAttributeLinkPtr *uses, |
| 9458 | xmlSchemaAttributeLinkPtr *lastUse) |
| 9459 | { |
| 9460 | xmlSchemaAttributeLinkPtr tmp; |
| 9461 | while (cur != NULL) { |
| 9462 | if (cur->type == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) { |
| 9463 | /* |
| 9464 | * W3C: "2 The {attribute uses} of the attribute groups ·resolved· |
| 9465 | * to by the ·actual value·s of the ref [attribute] of the |
| 9466 | * <attributeGroup> [children], if any." |
| 9467 | */ |
| 9468 | if (xmlSchemaBuildAttributeUsesOwned(ctxt, |
| 9469 | ((xmlSchemaAttributeGroupPtr) cur)->attributes, uses, |
| 9470 | lastUse) == -1) { |
| 9471 | return (-1); |
| 9472 | } |
| 9473 | } else { |
| 9474 | /* W3C: "1 The set of attribute uses corresponding to the |
| 9475 | * <attribute> [children], if any." |
| 9476 | */ |
| 9477 | tmp = (xmlSchemaAttributeLinkPtr) |
| 9478 | xmlMalloc(sizeof(xmlSchemaAttributeLink)); |
| 9479 | if (tmp == NULL) { |
| 9480 | xmlSchemaPErrMemory(ctxt, "building attribute uses", NULL); |
| 9481 | return (-1); |
| 9482 | } |
| 9483 | tmp->attr = cur; |
| 9484 | tmp->next = NULL; |
| 9485 | if (*uses == NULL) |
| 9486 | *uses = tmp; |
| 9487 | else |
| 9488 | (*lastUse)->next = tmp; |
| 9489 | *lastUse = tmp; |
| 9490 | } |
| 9491 | cur = cur->next; |
| 9492 | } |
| 9493 | return (0); |
| 9494 | } |
| 9495 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 9496 | /** |
| 9497 | * xmlSchemaCloneWildcardNsConstraints: |
| 9498 | * @ctxt: the schema parser context |
| 9499 | * @dest: the destination wildcard |
| 9500 | * @source: the source wildcard |
| 9501 | * |
| 9502 | * Clones the namespace constraints of source |
| 9503 | * and assignes them to dest. |
| 9504 | * Returns -1 on internal error, 0 otherwise. |
| 9505 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9506 | static int |
| 9507 | xmlSchemaCloneWildcardNsConstraints(xmlSchemaParserCtxtPtr ctxt, |
| 9508 | xmlSchemaWildcardPtr *dest, |
| 9509 | xmlSchemaWildcardPtr source) |
| 9510 | { |
| 9511 | xmlSchemaWildcardNsPtr cur, tmp, last; |
| 9512 | |
| 9513 | if ((source == NULL) || (*dest == NULL)) |
| 9514 | return(-1); |
| 9515 | (*dest)->any = source->any; |
| 9516 | cur = source->nsSet; |
| 9517 | last = NULL; |
| 9518 | while (cur != NULL) { |
| 9519 | tmp = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 9520 | if (tmp == NULL) |
| 9521 | return(-1); |
| 9522 | tmp->value = cur->value; |
| 9523 | if (last == NULL) |
| 9524 | (*dest)->nsSet = tmp; |
| 9525 | else |
| 9526 | last->next = tmp; |
| 9527 | last = tmp; |
| 9528 | cur = cur->next; |
| 9529 | } |
| 9530 | if ((*dest)->negNsSet != NULL) |
| 9531 | xmlSchemaFreeWildcardNsSet((*dest)->negNsSet); |
| 9532 | if (source->negNsSet != NULL) { |
| 9533 | (*dest)->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 9534 | if ((*dest)->negNsSet == NULL) |
| 9535 | return(-1); |
| 9536 | (*dest)->negNsSet->value = source->negNsSet->value; |
| 9537 | } else |
| 9538 | (*dest)->negNsSet = NULL; |
| 9539 | return(0); |
| 9540 | } |
| 9541 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 9542 | /** |
| 9543 | * xmlSchemaUnionWildcards: |
| 9544 | * @ctxt: the schema parser context |
| 9545 | * @completeWild: the first wildcard |
| 9546 | * @curWild: the second wildcard |
| 9547 | * |
| 9548 | * Unions the namespace constraints of the given wildcards. |
| 9549 | * @completeWild will hold the resulting union. |
| 9550 | * Returns a positive error code on failure, -1 in case of an |
| 9551 | * internal error, 0 otherwise. |
| 9552 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9553 | static int |
| 9554 | xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt, |
| 9555 | xmlSchemaWildcardPtr completeWild, |
| 9556 | xmlSchemaWildcardPtr curWild) |
| 9557 | { |
| 9558 | xmlSchemaWildcardNsPtr cur, curB, tmp; |
| 9559 | |
| 9560 | /* |
| 9561 | * 1 If O1 and O2 are the same value, then that value must be the |
| 9562 | * value. |
| 9563 | */ |
| 9564 | if ((completeWild->any == curWild->any) && |
| 9565 | ((completeWild->nsSet == NULL) == (curWild->nsSet == NULL)) && |
| 9566 | ((completeWild->negNsSet == NULL) == (curWild->negNsSet == NULL))) { |
| 9567 | |
| 9568 | if ((completeWild->negNsSet == NULL) || |
| 9569 | (completeWild->negNsSet->value == curWild->negNsSet->value)) { |
| 9570 | |
| 9571 | if (completeWild->nsSet != NULL) { |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 9572 | int found = 0; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9573 | |
| 9574 | /* |
| 9575 | * Check equality of sets. |
| 9576 | */ |
| 9577 | cur = completeWild->nsSet; |
| 9578 | while (cur != NULL) { |
| 9579 | found = 0; |
| 9580 | curB = curWild->nsSet; |
| 9581 | while (curB != NULL) { |
| 9582 | if (cur->value == curB->value) { |
| 9583 | found = 1; |
| 9584 | break; |
| 9585 | } |
| 9586 | curB = curB->next; |
| 9587 | } |
| 9588 | if (!found) |
| 9589 | break; |
| 9590 | cur = cur->next; |
| 9591 | } |
| 9592 | if (found) |
| 9593 | return(0); |
| 9594 | } else |
| 9595 | return(0); |
| 9596 | } |
| 9597 | } |
| 9598 | /* |
| 9599 | * 2 If either O1 or O2 is any, then any must be the value |
| 9600 | */ |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 9601 | if (completeWild->any != curWild->any) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9602 | if (completeWild->any == 0) { |
| 9603 | completeWild->any = 1; |
| 9604 | if (completeWild->nsSet != NULL) { |
| 9605 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 9606 | completeWild->nsSet = NULL; |
| 9607 | } |
| 9608 | if (completeWild->negNsSet != NULL) { |
| 9609 | xmlFree(completeWild->negNsSet); |
| 9610 | completeWild->negNsSet = NULL; |
| 9611 | } |
| 9612 | } |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 9613 | return (0); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9614 | } |
| 9615 | /* |
| 9616 | * 3 If both O1 and O2 are sets of (namespace names or ·absent·), |
| 9617 | * then the union of those sets must be the value. |
| 9618 | */ |
| 9619 | if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) { |
| 9620 | int found; |
| 9621 | xmlSchemaWildcardNsPtr start; |
| 9622 | |
| 9623 | cur = curWild->nsSet; |
| 9624 | start = completeWild->nsSet; |
| 9625 | while (cur != NULL) { |
| 9626 | found = 0; |
| 9627 | curB = start; |
| 9628 | while (curB != NULL) { |
| 9629 | if (cur->value == curB->value) { |
| 9630 | found = 1; |
| 9631 | break; |
| 9632 | } |
| 9633 | curB = curB->next; |
| 9634 | } |
| 9635 | if (!found) { |
| 9636 | tmp = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 9637 | if (tmp == NULL) |
| 9638 | return (-1); |
| 9639 | tmp->value = cur->value; |
| 9640 | tmp->next = completeWild->nsSet; |
| 9641 | completeWild->nsSet = tmp; |
| 9642 | } |
| 9643 | cur = cur->next; |
| 9644 | } |
| 9645 | |
| 9646 | return(0); |
| 9647 | } |
| 9648 | /* |
| 9649 | * 4 If the two are negations of different values (namespace names |
| 9650 | * or ·absent·), then a pair of not and ·absent· must be the value. |
| 9651 | */ |
| 9652 | if ((completeWild->negNsSet != NULL) && |
| 9653 | (curWild->negNsSet != NULL) && |
| 9654 | (completeWild->negNsSet->value != curWild->negNsSet->value)) { |
| 9655 | completeWild->negNsSet->value = NULL; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 9656 | |
| 9657 | return(0); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9658 | } |
| 9659 | /* |
| 9660 | * 5. |
| 9661 | */ |
| 9662 | if (((completeWild->negNsSet != NULL) && |
| 9663 | (completeWild->negNsSet->value != NULL) && |
| 9664 | (curWild->nsSet != NULL)) || |
| 9665 | ((curWild->negNsSet != NULL) && |
| 9666 | (curWild->negNsSet->value != NULL) && |
| 9667 | (completeWild->nsSet != NULL))) { |
| 9668 | |
| 9669 | int nsFound, absentFound = 0; |
| 9670 | |
| 9671 | if (completeWild->nsSet != NULL) { |
| 9672 | cur = completeWild->nsSet; |
| 9673 | curB = curWild->negNsSet; |
| 9674 | } else { |
| 9675 | cur = curWild->nsSet; |
| 9676 | curB = completeWild->negNsSet; |
| 9677 | } |
| 9678 | nsFound = 0; |
| 9679 | while (cur != NULL) { |
| 9680 | if (cur->value == NULL) |
| 9681 | absentFound = 1; |
| 9682 | else if (cur->value == curB->value) |
| 9683 | nsFound = 1; |
| 9684 | if (nsFound && absentFound) |
| 9685 | break; |
| 9686 | cur = cur->next; |
| 9687 | } |
| 9688 | |
| 9689 | if (nsFound && absentFound) { |
| 9690 | /* |
| 9691 | * 5.1 If the set S includes both the negated namespace |
| 9692 | * name and ·absent·, then any must be the value. |
| 9693 | */ |
| 9694 | completeWild->any = 1; |
| 9695 | if (completeWild->nsSet != NULL) { |
| 9696 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 9697 | completeWild->nsSet = NULL; |
| 9698 | } |
| 9699 | if (completeWild->negNsSet != NULL) { |
| 9700 | xmlFree(completeWild->negNsSet); |
| 9701 | completeWild->negNsSet = NULL; |
| 9702 | } |
| 9703 | } else if (nsFound && (!absentFound)) { |
| 9704 | /* |
| 9705 | * 5.2 If the set S includes the negated namespace name |
| 9706 | * but not ·absent·, then a pair of not and ·absent· must |
| 9707 | * be the value. |
| 9708 | */ |
| 9709 | if (completeWild->nsSet != NULL) { |
| 9710 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 9711 | completeWild->nsSet = NULL; |
| 9712 | } |
| 9713 | if (completeWild->negNsSet == NULL) { |
| 9714 | completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 9715 | if (completeWild->negNsSet == NULL) |
| 9716 | return (-1); |
| 9717 | } |
| 9718 | completeWild->negNsSet->value = NULL; |
| 9719 | } else if ((!nsFound) && absentFound) { |
| 9720 | /* |
| 9721 | * 5.3 If the set S includes ·absent· but not the negated |
| 9722 | * namespace name, then the union is not expressible. |
| 9723 | */ |
| 9724 | xmlSchemaPErr(ctxt, completeWild->node, |
| 9725 | XML_SCHEMAP_UNION_NOT_EXPRESSIBLE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9726 | "The union of the wilcard is not expressible.\n", |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9727 | NULL, NULL); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 9728 | return(XML_SCHEMAP_UNION_NOT_EXPRESSIBLE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9729 | } else if ((!nsFound) && (!absentFound)) { |
| 9730 | /* |
| 9731 | * 5.4 If the set S does not include either the negated namespace |
| 9732 | * name or ·absent·, then whichever of O1 or O2 is a pair of not |
| 9733 | * and a namespace name must be the value. |
| 9734 | */ |
| 9735 | if (completeWild->negNsSet == NULL) { |
| 9736 | if (completeWild->nsSet != NULL) { |
| 9737 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 9738 | completeWild->nsSet = NULL; |
| 9739 | } |
| 9740 | completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 9741 | if (completeWild->negNsSet == NULL) |
| 9742 | return (-1); |
| 9743 | completeWild->negNsSet->value = curWild->negNsSet->value; |
| 9744 | } |
| 9745 | } |
| 9746 | return (0); |
| 9747 | } |
| 9748 | /* |
| 9749 | * 6. |
| 9750 | */ |
| 9751 | if (((completeWild->negNsSet != NULL) && |
| 9752 | (completeWild->negNsSet->value == NULL) && |
| 9753 | (curWild->nsSet != NULL)) || |
| 9754 | ((curWild->negNsSet != NULL) && |
| 9755 | (curWild->negNsSet->value == NULL) && |
| 9756 | (completeWild->nsSet != NULL))) { |
| 9757 | |
| 9758 | if (completeWild->nsSet != NULL) { |
| 9759 | cur = completeWild->nsSet; |
| 9760 | } else { |
| 9761 | cur = curWild->nsSet; |
| 9762 | } |
| 9763 | while (cur != NULL) { |
| 9764 | if (cur->value == NULL) { |
| 9765 | /* |
| 9766 | * 6.1 If the set S includes ·absent·, then any must be the |
| 9767 | * value. |
| 9768 | */ |
| 9769 | completeWild->any = 1; |
| 9770 | if (completeWild->nsSet != NULL) { |
| 9771 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 9772 | completeWild->nsSet = NULL; |
| 9773 | } |
| 9774 | if (completeWild->negNsSet != NULL) { |
| 9775 | xmlFree(completeWild->negNsSet); |
| 9776 | completeWild->negNsSet = NULL; |
| 9777 | } |
| 9778 | return (0); |
| 9779 | } |
| 9780 | cur = cur->next; |
| 9781 | } |
| 9782 | if (completeWild->negNsSet == NULL) { |
| 9783 | /* |
| 9784 | * 6.2 If the set S does not include ·absent·, then a pair of not |
| 9785 | * and ·absent· must be the value. |
| 9786 | */ |
| 9787 | if (completeWild->nsSet != NULL) { |
| 9788 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 9789 | completeWild->nsSet = NULL; |
| 9790 | } |
| 9791 | completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 9792 | if (completeWild->negNsSet == NULL) |
| 9793 | return (-1); |
| 9794 | completeWild->negNsSet->value = NULL; |
| 9795 | } |
| 9796 | return (0); |
| 9797 | } |
| 9798 | return (0); |
| 9799 | |
| 9800 | } |
| 9801 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 9802 | /** |
| 9803 | * xmlSchemaIntersectWildcards: |
| 9804 | * @ctxt: the schema parser context |
| 9805 | * @completeWild: the first wildcard |
| 9806 | * @curWild: the second wildcard |
| 9807 | * |
| 9808 | * Intersects the namespace constraints of the given wildcards. |
| 9809 | * @completeWild will hold the resulting intersection. |
| 9810 | * Returns a positive error code on failure, -1 in case of an |
| 9811 | * internal error, 0 otherwise. |
| 9812 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9813 | static int |
| 9814 | xmlSchemaIntersectWildcards(xmlSchemaParserCtxtPtr ctxt, |
| 9815 | xmlSchemaWildcardPtr completeWild, |
| 9816 | xmlSchemaWildcardPtr curWild) |
| 9817 | { |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 9818 | xmlSchemaWildcardNsPtr cur, curB, prev, tmp; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9819 | |
| 9820 | /* |
| 9821 | * 1 If O1 and O2 are the same value, then that value must be the |
| 9822 | * value. |
| 9823 | */ |
| 9824 | if ((completeWild->any == curWild->any) && |
| 9825 | ((completeWild->nsSet == NULL) == (curWild->nsSet == NULL)) && |
| 9826 | ((completeWild->negNsSet == NULL) == (curWild->negNsSet == NULL))) { |
| 9827 | |
| 9828 | if ((completeWild->negNsSet == NULL) || |
| 9829 | (completeWild->negNsSet->value == curWild->negNsSet->value)) { |
| 9830 | |
| 9831 | if (completeWild->nsSet != NULL) { |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 9832 | int found = 0; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9833 | |
| 9834 | /* |
| 9835 | * Check equality of sets. |
| 9836 | */ |
| 9837 | cur = completeWild->nsSet; |
| 9838 | while (cur != NULL) { |
| 9839 | found = 0; |
| 9840 | curB = curWild->nsSet; |
| 9841 | while (curB != NULL) { |
| 9842 | if (cur->value == curB->value) { |
| 9843 | found = 1; |
| 9844 | break; |
| 9845 | } |
| 9846 | curB = curB->next; |
| 9847 | } |
| 9848 | if (!found) |
| 9849 | break; |
| 9850 | cur = cur->next; |
| 9851 | } |
| 9852 | if (found) |
| 9853 | return(0); |
| 9854 | } else |
| 9855 | return(0); |
| 9856 | } |
| 9857 | } |
| 9858 | /* |
| 9859 | * 2 If either O1 or O2 is any, then the other must be the value. |
| 9860 | */ |
| 9861 | if ((completeWild->any != curWild->any) && (completeWild->any)) { |
| 9862 | if (xmlSchemaCloneWildcardNsConstraints(ctxt, &completeWild, curWild) == -1) |
| 9863 | return(-1); |
| 9864 | return(0); |
| 9865 | } |
| 9866 | /* |
| 9867 | * 3 If either O1 or O2 is a pair of not and a value (a namespace |
| 9868 | * name or ·absent·) and the other is a set of (namespace names or |
| 9869 | * ·absent·), then that set, minus the negated value if it was in |
| 9870 | * the set, minus ·absent· if it was in the set, must be the value. |
| 9871 | */ |
| 9872 | if (((completeWild->negNsSet != NULL) && (curWild->nsSet != NULL)) || |
| 9873 | ((curWild->negNsSet != NULL) && (completeWild->nsSet != NULL))) { |
| 9874 | const xmlChar *neg; |
| 9875 | |
| 9876 | if (completeWild->nsSet == NULL) { |
| 9877 | neg = completeWild->negNsSet->value; |
| 9878 | if (xmlSchemaCloneWildcardNsConstraints(ctxt, &completeWild, curWild) == -1) |
| 9879 | return(-1); |
| 9880 | } else |
| 9881 | neg = curWild->negNsSet->value; |
| 9882 | /* |
| 9883 | * Remove absent and negated. |
| 9884 | */ |
| 9885 | prev = NULL; |
| 9886 | cur = completeWild->nsSet; |
| 9887 | while (cur != NULL) { |
| 9888 | if (cur->value == NULL) { |
| 9889 | if (prev == NULL) |
| 9890 | completeWild->nsSet = cur->next; |
| 9891 | else |
| 9892 | prev->next = cur->next; |
| 9893 | xmlFree(cur); |
| 9894 | break; |
| 9895 | } |
| 9896 | prev = cur; |
| 9897 | cur = cur->next; |
| 9898 | } |
| 9899 | if (neg != NULL) { |
| 9900 | prev = NULL; |
| 9901 | cur = completeWild->nsSet; |
| 9902 | while (cur != NULL) { |
| 9903 | if (cur->value == neg) { |
| 9904 | if (prev == NULL) |
| 9905 | completeWild->nsSet = cur->next; |
| 9906 | else |
| 9907 | prev->next = cur->next; |
| 9908 | xmlFree(cur); |
| 9909 | break; |
| 9910 | } |
| 9911 | prev = cur; |
| 9912 | cur = cur->next; |
| 9913 | } |
| 9914 | } |
| 9915 | |
| 9916 | return(0); |
| 9917 | } |
| 9918 | /* |
| 9919 | * 4 If both O1 and O2 are sets of (namespace names or ·absent·), |
| 9920 | * then the intersection of those sets must be the value. |
| 9921 | */ |
| 9922 | if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) { |
| 9923 | int found; |
| 9924 | |
| 9925 | cur = completeWild->nsSet; |
| 9926 | prev = NULL; |
| 9927 | while (cur != NULL) { |
| 9928 | found = 0; |
| 9929 | curB = curWild->nsSet; |
| 9930 | while (curB != NULL) { |
| 9931 | if (cur->value == curB->value) { |
| 9932 | found = 1; |
| 9933 | break; |
| 9934 | } |
| 9935 | curB = curB->next; |
| 9936 | } |
| 9937 | if (!found) { |
| 9938 | if (prev == NULL) |
| 9939 | completeWild->nsSet = cur->next; |
| 9940 | else |
| 9941 | prev->next = cur->next; |
| 9942 | tmp = cur->next; |
| 9943 | xmlFree(cur); |
| 9944 | cur = tmp; |
| 9945 | continue; |
| 9946 | } |
| 9947 | prev = cur; |
| 9948 | cur = cur->next; |
| 9949 | } |
| 9950 | |
| 9951 | return(0); |
| 9952 | } |
| 9953 | /* 5 If the two are negations of different namespace names, |
| 9954 | * then the intersection is not expressible |
| 9955 | */ |
| 9956 | if ((completeWild->negNsSet != NULL) && |
| 9957 | (curWild->negNsSet != NULL) && |
| 9958 | (completeWild->negNsSet->value != curWild->negNsSet->value) && |
| 9959 | (completeWild->negNsSet->value != NULL) && |
| 9960 | (curWild->negNsSet->value != NULL)) { |
| 9961 | |
| 9962 | xmlSchemaPErr(ctxt, completeWild->node, XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9963 | "The intersection of the wilcard is not expressible.\n", |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9964 | NULL, NULL); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 9965 | return(XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9966 | } |
| 9967 | /* |
| 9968 | * 6 If the one is a negation of a namespace name and the other |
| 9969 | * is a negation of ·absent·, then the one which is the negation |
| 9970 | * of a namespace name must be the value. |
| 9971 | */ |
| 9972 | if ((completeWild->negNsSet != NULL) && (curWild->negNsSet != NULL) && |
| 9973 | (completeWild->negNsSet->value != curWild->negNsSet->value) && |
| 9974 | (completeWild->negNsSet->value == NULL)) { |
| 9975 | completeWild->negNsSet->value = curWild->negNsSet->value; |
| 9976 | } |
| 9977 | return(0); |
| 9978 | } |
| 9979 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 9980 | /** |
| 9981 | * xmlSchemaIsWildcardNsConstraintSubset: |
| 9982 | * @ctxt: the schema parser context |
| 9983 | * @wildA: the first wildcard |
| 9984 | * @wildB: the second wildcard |
| 9985 | * |
| 9986 | * Returns 1 if the namespace constraint of @wildA is an intensional |
| 9987 | * subset of @wildB, 0 otherwise. |
| 9988 | */ |
| 9989 | static int |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9990 | xmlSchemaIsWildcardNsConstraintSubset(xmlSchemaWildcardPtr wildA, |
| 9991 | xmlSchemaWildcardPtr wildB) |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 9992 | { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9993 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 9994 | /* |
| 9995 | * Schema Component Constraint: Wildcard Subset |
| 9996 | */ |
| 9997 | /* |
| 9998 | * 1 super must be any. |
| 9999 | */ |
| 10000 | if (wildB->any) |
| 10001 | return (1); |
| 10002 | /* |
| 10003 | * 2.1 sub must be a pair of not and a namespace name or ·absent·. |
| 10004 | * 2.2 super must be a pair of not and the same value. |
| 10005 | */ |
| 10006 | if ((wildA->negNsSet != NULL) && |
| 10007 | (wildB->negNsSet != NULL) && |
| 10008 | (wildA->negNsSet->value == wildA->negNsSet->value)) |
| 10009 | return (1); |
| 10010 | /* |
| 10011 | * 3.1 sub must be a set whose members are either namespace names or ·absent·. |
| 10012 | */ |
| 10013 | if (wildA->nsSet != NULL) { |
| 10014 | /* |
| 10015 | * 3.2.1 super must be the same set or a superset thereof. |
| 10016 | */ |
| 10017 | if (wildB->nsSet != NULL) { |
| 10018 | xmlSchemaWildcardNsPtr cur, curB; |
| 10019 | int found = 0; |
| 10020 | |
| 10021 | cur = wildA->nsSet; |
| 10022 | while (cur != NULL) { |
| 10023 | found = 0; |
| 10024 | curB = wildB->nsSet; |
| 10025 | while (curB != NULL) { |
| 10026 | if (cur->value == curB->value) { |
| 10027 | found = 1; |
| 10028 | break; |
| 10029 | } |
| 10030 | curB = curB->next; |
| 10031 | } |
| 10032 | if (!found) |
| 10033 | return (0); |
| 10034 | cur = cur->next; |
| 10035 | } |
| 10036 | if (found) |
| 10037 | return (1); |
| 10038 | } else if (wildB->negNsSet != NULL) { |
| 10039 | xmlSchemaWildcardNsPtr cur; |
| 10040 | /* |
| 10041 | * 3.2.2 super must be a pair of not and a namespace name or |
| 10042 | * ·absent· and that value must not be in sub's set. |
| 10043 | */ |
| 10044 | cur = wildA->nsSet; |
| 10045 | while (cur != NULL) { |
| 10046 | if (cur->value == wildB->negNsSet->value) |
| 10047 | return (0); |
| 10048 | cur = cur->next; |
| 10049 | } |
| 10050 | return (1); |
| 10051 | } |
| 10052 | } |
| 10053 | return (0); |
| 10054 | } |
| 10055 | |
| 10056 | /** |
| 10057 | * xmlSchemaBuildCompleteAttributeWildcard: |
| 10058 | * @ctxt: the schema parser context |
| 10059 | * @attrs: the attribute list |
| 10060 | * @completeWild: the resulting complete wildcard |
| 10061 | * |
| 10062 | * Returns -1 in case of an internal error, 0 otherwise. |
| 10063 | */ |
| 10064 | static int |
| 10065 | xmlSchemaBuildCompleteAttributeWildcard(xmlSchemaParserCtxtPtr ctxt, |
| 10066 | xmlSchemaAttributePtr attrs, |
| 10067 | xmlSchemaWildcardPtr *completeWild) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10068 | { |
| 10069 | while (attrs != NULL) { |
| 10070 | if (attrs->type == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) { |
| 10071 | xmlSchemaAttributeGroupPtr group; |
| 10072 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10073 | group = (xmlSchemaAttributeGroupPtr) attrs; |
| 10074 | /* |
| 10075 | * Handle attribute group references. |
| 10076 | */ |
| 10077 | if (group->ref != NULL) { |
| 10078 | if (group->refItem == NULL) { |
| 10079 | /* |
| 10080 | * TODO: Should we raise a warning here? |
| 10081 | */ |
| 10082 | /* |
| 10083 | * The referenced attribute group definition could not |
| 10084 | * be resolved beforehand, so skip. |
| 10085 | */ |
| 10086 | attrs = attrs->next; |
| 10087 | continue; |
| 10088 | } else |
| 10089 | group = group->refItem; |
| 10090 | } |
| 10091 | /* |
| 10092 | * For every attribute group definition, an intersected wildcard |
| 10093 | * will be created (assumed that a wildcard exists on the |
| 10094 | * particular attr. gr. def. or on any contained attr. gr. def |
| 10095 | * at all). |
| 10096 | * The flag XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED ensures |
| 10097 | * that the intersection will be performed only once. |
| 10098 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10099 | if ((group->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED) == 0) { |
| 10100 | if (group->attributes != NULL) { |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10101 | if (xmlSchemaBuildCompleteAttributeWildcard(ctxt, |
| 10102 | group->attributes, &group->attributeWildcard) == -1) |
| 10103 | return (-1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10104 | } |
| 10105 | group->flags |= XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED; |
| 10106 | } |
| 10107 | if (group->attributeWildcard != NULL) { |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10108 | if (*completeWild == NULL) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10109 | /* |
| 10110 | * Copy the first encountered wildcard as context, except for the annotation. |
| 10111 | */ |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10112 | *completeWild = xmlSchemaAddWildcard(ctxt); |
| 10113 | (*completeWild)->type = XML_SCHEMA_TYPE_ANY_ATTRIBUTE; |
| 10114 | if (xmlSchemaCloneWildcardNsConstraints(ctxt, |
| 10115 | completeWild, group->attributeWildcard) == -1) |
| 10116 | return (-1); |
| 10117 | (*completeWild)->processContents = group->attributeWildcard->processContents; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10118 | /* |
| 10119 | * Although the complete wildcard might not correspond to any |
| 10120 | * node in the schema, we will save this context node. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10121 | * TODO: Hmm, is this sane? |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10122 | */ |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10123 | (*completeWild)->node = group->attributeWildcard->node; |
| 10124 | |
| 10125 | } else if (xmlSchemaIntersectWildcards(ctxt, *completeWild, group->attributeWildcard) == -1) { |
| 10126 | xmlSchemaFreeWildcard(*completeWild); |
| 10127 | return (-1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10128 | } |
| 10129 | } |
| 10130 | } |
| 10131 | attrs = attrs->next; |
| 10132 | } |
| 10133 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10134 | return (0); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10135 | } |
| 10136 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10137 | static int |
| 10138 | xmlSchemaGetEffectiveValueConstraint(xmlSchemaAttributePtr item, |
| 10139 | int *fixed, |
| 10140 | const xmlChar **value, |
| 10141 | xmlSchemaValPtr *val) |
| 10142 | { |
| 10143 | *fixed = 0; |
| 10144 | *value = NULL; |
| 10145 | if (val != 0) |
| 10146 | *val = NULL; |
| 10147 | |
| 10148 | if (item->defValue == NULL) |
| 10149 | item = item->refDecl; |
| 10150 | |
| 10151 | if (item == NULL) |
| 10152 | return (0); |
| 10153 | |
| 10154 | if (item->defValue != NULL) { |
| 10155 | *value = item->defValue; |
| 10156 | if (val != 0) |
| 10157 | *val = item->defVal; |
| 10158 | if (item->flags & XML_SCHEMAS_ATTR_FIXED) |
| 10159 | *fixed = 1; |
| 10160 | return (1); |
| 10161 | } |
| 10162 | return (0); |
| 10163 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10164 | /** |
| 10165 | * xmlSchemaMatchesWildcardNs: |
| 10166 | * @wild: the wildcard |
| 10167 | * @ns: the namespace |
| 10168 | * |
| 10169 | * |
| 10170 | * Returns 1 if the given namespace matches the wildcard, |
| 10171 | * 0 otherwise. |
| 10172 | */ |
| 10173 | static int |
| 10174 | xmlSchemaMatchesWildcardNs(xmlSchemaWildcardPtr wild, const xmlChar* ns) |
| 10175 | { |
| 10176 | if (wild == NULL) |
| 10177 | return(0); |
| 10178 | |
| 10179 | if (wild->any) |
| 10180 | return(1); |
| 10181 | else if (wild->nsSet != NULL) { |
| 10182 | xmlSchemaWildcardNsPtr cur; |
| 10183 | |
| 10184 | cur = wild->nsSet; |
| 10185 | while (cur != NULL) { |
| 10186 | if (xmlStrEqual(cur->value, ns)) |
| 10187 | return(1); |
| 10188 | cur = cur->next; |
| 10189 | } |
| 10190 | } else if ((wild->negNsSet != NULL) && (ns != NULL) && |
| 10191 | (!xmlStrEqual(wild->negNsSet->value, ns))) |
| 10192 | return(1); |
| 10193 | |
| 10194 | return(0); |
| 10195 | } |
| 10196 | |
| 10197 | /** |
| 10198 | * xmlSchemaBuildAttributeValidation: |
| 10199 | * @ctxt: the schema parser context |
| 10200 | * @type: the complex type definition |
| 10201 | * |
| 10202 | * |
| 10203 | * Builds the wildcard and the attribute uses on the given complex type. |
| 10204 | * Returns -1 if an internal error occurs, 0 otherwise. |
| 10205 | */ |
| 10206 | static int |
| 10207 | xmlSchemaBuildAttributeValidation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaTypePtr type) |
| 10208 | { |
| 10209 | xmlSchemaTypePtr baseType = NULL; |
| 10210 | xmlSchemaAttributeLinkPtr cur, base, tmp, id = NULL, prev = NULL, uses = NULL, |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 10211 | lastUse = NULL, lastBaseUse = NULL; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10212 | xmlSchemaAttributePtr attrs; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10213 | xmlSchemaTypePtr anyType; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10214 | int baseIsAnyType = 0; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10215 | xmlChar *str = NULL; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 10216 | int err = 0; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10217 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10218 | anyType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10219 | /* |
| 10220 | * Complex Type Definition with complex content Schema Component. |
| 10221 | * |
| 10222 | * Attribute uses. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10223 | * TODO: Add checks for absent referenced attribute declarations and |
| 10224 | * simple types. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10225 | */ |
| 10226 | if (type->attributeUses != NULL) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 10227 | xmlSchemaPErr(ctxt, type->node, XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10228 | "Internal error: xmlSchemaBuildAttributeValidation: " |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10229 | "attribute uses already builded.\n", |
| 10230 | NULL, NULL); |
| 10231 | return (-1); |
| 10232 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10233 | if (type->baseType == NULL) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 10234 | xmlSchemaPErr(ctxt, type->node, XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10235 | "Internal error: xmlSchemaBuildAttributeValidation: " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10236 | "complex type '%s' has no base type.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10237 | type->name, NULL); |
| 10238 | return (-1); |
| 10239 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 10240 | baseType = type->baseType; |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 10241 | if (baseType == anyType) |
| 10242 | baseIsAnyType = 1; |
| 10243 | /* |
| 10244 | * Inherit the attribute uses of the base type. |
| 10245 | */ |
| 10246 | /* |
| 10247 | * NOTE: It is allowed to "extend" the anyType complex type. |
| 10248 | */ |
| 10249 | if (!baseIsAnyType) { |
| 10250 | if (baseType != NULL) { |
| 10251 | for (cur = baseType->attributeUses; cur != NULL; cur = cur->next) { |
| 10252 | tmp = (xmlSchemaAttributeLinkPtr) |
| 10253 | xmlMalloc(sizeof(xmlSchemaAttributeLink)); |
| 10254 | if (tmp == NULL) { |
| 10255 | xmlSchemaPErrMemory(ctxt, |
| 10256 | "building attribute uses of complexType", NULL); |
| 10257 | return (-1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10258 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 10259 | tmp->attr = cur->attr; |
| 10260 | tmp->next = NULL; |
| 10261 | if (type->attributeUses == NULL) { |
| 10262 | type->attributeUses = tmp; |
| 10263 | } else |
| 10264 | lastBaseUse->next = tmp; |
| 10265 | lastBaseUse = tmp; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10266 | } |
| 10267 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 10268 | } |
| 10269 | if ((type->subtypes != NULL) && |
| 10270 | ((type->subtypes->type == XML_SCHEMA_TYPE_COMPLEX_CONTENT) || |
| 10271 | (type->subtypes->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT))) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10272 | /* |
| 10273 | * type --> (<simpleContent>|<complexContent>) |
| 10274 | * --> (<restriction>|<extension>) --> attributes |
| 10275 | */ |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 10276 | attrs = type->subtypes->subtypes->attributes; |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 10277 | } else { |
| 10278 | /* Short hand form of the complexType. */ |
| 10279 | attrs = type->attributes; |
| 10280 | } |
| 10281 | /* |
| 10282 | * Handle attribute wildcards. |
| 10283 | */ |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 10284 | err = xmlSchemaBuildCompleteAttributeWildcard(ctxt, |
| 10285 | attrs, &type->attributeWildcard); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10286 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10287 | * NOTE: During the parse time, the wildcard is created on the complexType |
| 10288 | * directly, if encountered in a <restriction> or <extension> element. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10289 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10290 | if (err == -1) { |
| 10291 | xmlSchemaPErr(ctxt, type->node, XML_SCHEMAP_INTERNAL, |
| 10292 | "Internal error: xmlSchemaBuildAttributeValidation: " |
| 10293 | "failed to build an intersected attribute wildcard.\n", |
| 10294 | NULL, NULL); |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 10295 | return (-1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10296 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 10297 | |
| 10298 | if ((type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) && |
| 10299 | ((baseIsAnyType) || |
| 10300 | ((baseType != NULL) && |
| 10301 | (baseType->type == XML_SCHEMA_TYPE_COMPLEX) && |
| 10302 | (baseType->attributeWildcard != NULL)))) { |
| 10303 | if (type->attributeWildcard != NULL) { |
| 10304 | /* |
| 10305 | * Union the complete wildcard with the base wildcard. |
| 10306 | */ |
| 10307 | if (xmlSchemaUnionWildcards(ctxt, type->attributeWildcard, |
| 10308 | baseType->attributeWildcard) == -1) |
| 10309 | return (-1); |
| 10310 | } else { |
| 10311 | /* |
| 10312 | * Just inherit the wildcard. |
| 10313 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10314 | /* |
| 10315 | * NOTE: This is the only case where an attribute |
| 10316 | * wildcard is shared. |
| 10317 | */ |
| 10318 | if (type->flags & XML_SCHEMAS_TYPE_OWNED_ATTR_WILDCARD) |
| 10319 | type->flags ^= XML_SCHEMAS_TYPE_OWNED_ATTR_WILDCARD; |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 10320 | type->attributeWildcard = baseType->attributeWildcard; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10321 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 10322 | } |
| 10323 | |
| 10324 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
| 10325 | if (type->attributeWildcard != NULL) { |
| 10326 | /* |
| 10327 | * Derivation Valid (Restriction, Complex) |
| 10328 | * 4.1 The {base type definition} must also have one. |
| 10329 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10330 | if (baseType->attributeWildcard == NULL) { |
| 10331 | xmlSchemaPCustomErr(ctxt, |
| 10332 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_1, |
| 10333 | NULL, type, NULL, |
| 10334 | "The type has an attribute wildcard, " |
| 10335 | "but the base type %s does not have one", |
| 10336 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 10337 | FREE_AND_NULL(str) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 10338 | return (1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10339 | } else if (xmlSchemaIsWildcardNsConstraintSubset( |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 10340 | type->attributeWildcard, baseType->attributeWildcard) == 0) { |
| 10341 | /* 4.2 */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10342 | xmlSchemaPCustomErr(ctxt, |
| 10343 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_2, |
| 10344 | NULL, type, NULL, |
| 10345 | "The attribute wildcard is not a valid " |
| 10346 | "subset of the wildcard in the base type %s", |
| 10347 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 10348 | FREE_AND_NULL(str) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 10349 | return (1); |
| 10350 | } |
| 10351 | /* 4.3 Unless the {base type definition} is the ·ur-type |
| 10352 | * definition·, the complex type definition's {attribute |
| 10353 | * wildcard}'s {process contents} must be identical to or |
| 10354 | * stronger than the {base type definition}'s {attribute |
| 10355 | * wildcard}'s {process contents}, where strict is stronger |
| 10356 | * than lax is stronger than skip. |
| 10357 | */ |
| 10358 | if ((type->baseType != anyType) && |
| 10359 | (type->attributeWildcard->processContents < |
| 10360 | baseType->attributeWildcard->processContents)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10361 | xmlSchemaPCustomErr(ctxt, |
| 10362 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_3, |
| 10363 | NULL, type, NULL, |
| 10364 | "The 'process contents' of the attribute wildcard is weaker than " |
| 10365 | "the one in the base type %s", |
| 10366 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 10367 | FREE_AND_NULL(str) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 10368 | return (1); |
| 10369 | } |
| 10370 | } |
| 10371 | } else if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) { |
| 10372 | /* |
| 10373 | * Derivation Valid (Extension) |
| 10374 | * At this point the type and the base have both, either |
| 10375 | * no wildcard or a wildcard. |
| 10376 | */ |
| 10377 | if ((baseType->attributeWildcard != NULL) && |
| 10378 | (baseType->attributeWildcard != type->attributeWildcard)) { |
| 10379 | /* 1.3 */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10380 | if (xmlSchemaIsWildcardNsConstraintSubset( |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 10381 | baseType->attributeWildcard, type->attributeWildcard) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10382 | xmlSchemaPCustomErr(ctxt, |
| 10383 | XML_SCHEMAP_COS_CT_EXTENDS_1_3, |
| 10384 | NULL, type, NULL, |
| 10385 | "The attribute wildcard is not a valid " |
| 10386 | "superset of the one in the base type %s", |
| 10387 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 10388 | FREE_AND_NULL(str) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 10389 | return (1); |
| 10390 | } |
| 10391 | } |
| 10392 | } |
| 10393 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10394 | /* |
| 10395 | * Gather attribute uses defined by this type. |
| 10396 | */ |
| 10397 | if (attrs != NULL) { |
| 10398 | if (xmlSchemaBuildAttributeUsesOwned(ctxt, attrs, |
| 10399 | &uses, &lastUse) == -1) { |
| 10400 | return (-1); |
| 10401 | } |
| 10402 | } |
| 10403 | /* 3.4.6 -> Complex Type Definition Properties Correct 4. |
| 10404 | * "Two distinct attribute declarations in the {attribute uses} must |
| 10405 | * not have identical {name}s and {target namespace}s." |
| 10406 | * |
| 10407 | * For "extension" this is done further down. |
| 10408 | */ |
| 10409 | if ((uses != NULL) && ((type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) == 0)) { |
| 10410 | cur = uses; |
| 10411 | while (cur != NULL) { |
| 10412 | tmp = cur->next; |
| 10413 | while (tmp != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10414 | if ((xmlStrEqual(xmlSchemaGetAttrName(cur->attr), |
| 10415 | xmlSchemaGetAttrName(tmp->attr))) && |
| 10416 | (xmlStrEqual(xmlSchemaGetAttrTargetNsURI(cur->attr ), |
| 10417 | xmlSchemaGetAttrTargetNsURI(tmp->attr)))) { |
| 10418 | |
| 10419 | xmlSchemaPAttrUseErr(ctxt, |
| 10420 | XML_SCHEMAP_CT_PROPS_CORRECT_4, |
| 10421 | NULL, type, NULL, cur->attr, |
| 10422 | "Duplicate attribute use %s specified", |
| 10423 | xmlSchemaFormatNsUriLocal(&str, |
| 10424 | xmlSchemaGetAttrTargetNsURI(tmp->attr), |
| 10425 | xmlSchemaGetAttrName(tmp->attr)) |
| 10426 | ); |
| 10427 | FREE_AND_NULL(str) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10428 | break; |
| 10429 | } |
| 10430 | tmp = tmp->next; |
| 10431 | } |
| 10432 | cur = cur->next; |
| 10433 | } |
| 10434 | } |
| 10435 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
| 10436 | /* |
| 10437 | * Derive by restriction. |
| 10438 | */ |
| 10439 | if (baseIsAnyType) { |
| 10440 | type->attributeUses = uses; |
| 10441 | } else { |
| 10442 | int found; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10443 | const xmlChar *bEffValue; |
| 10444 | int effFixed; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10445 | |
| 10446 | cur = uses; |
| 10447 | while (cur != NULL) { |
| 10448 | found = 0; |
| 10449 | base = type->attributeUses; |
| 10450 | while (base != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10451 | if (xmlStrEqual(xmlSchemaGetAttrName(cur->attr), |
| 10452 | xmlSchemaGetAttrName(base->attr)) && |
| 10453 | xmlStrEqual(xmlSchemaGetAttrTargetNsURI(cur->attr), |
| 10454 | xmlSchemaGetAttrTargetNsURI(base->attr))) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10455 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10456 | found = 1; |
| 10457 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10458 | if ((cur->attr->occurs == XML_SCHEMAS_ATTR_USE_OPTIONAL) && |
| 10459 | (base->attr->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED)) { |
| 10460 | /* |
| 10461 | * derivation-ok-restriction 2.1.1 |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10462 | */ |
| 10463 | xmlSchemaPAttrUseErr(ctxt, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10464 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10465 | NULL, type, NULL, cur->attr, |
| 10466 | "The 'optional' use is inconsistent with a matching " |
| 10467 | "'required' use of the base type", NULL); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10468 | } else if ((cur->attr->occurs == XML_SCHEMAS_ATTR_USE_PROHIBITED) && |
| 10469 | (base->attr->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED)) { |
| 10470 | /* |
| 10471 | * derivation-ok-restriction 3 |
| 10472 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10473 | xmlSchemaPCustomErr(ctxt, |
| 10474 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_3, |
| 10475 | NULL, type, NULL, |
| 10476 | "A matching attribute use for the 'required' " |
| 10477 | "attribute use %s of the base type is missing", |
| 10478 | xmlSchemaFormatNsUriLocal(&str, |
| 10479 | xmlSchemaGetAttrTargetNsURI(base->attr), |
| 10480 | xmlSchemaGetAttrName(base->attr))); |
| 10481 | FREE_AND_NULL(str) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10482 | } else { |
| 10483 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10484 | * 2.1.3 [Definition:] Let the effective value |
| 10485 | * constraint of an attribute use be its {value |
| 10486 | * constraint}, if present, otherwise its {attribute |
| 10487 | * declaration}'s {value constraint} . |
| 10488 | */ |
| 10489 | xmlSchemaGetEffectiveValueConstraint(base->attr, &effFixed, |
| 10490 | &bEffValue, 0); |
| 10491 | /* |
| 10492 | * 2.1.3 ... one of the following must be true |
| 10493 | * |
| 10494 | * 2.1.3.1 B's ·effective value constraint· is |
| 10495 | * ·absent· or default. |
| 10496 | */ |
| 10497 | if ((bEffValue != NULL) && |
| 10498 | (effFixed == 1)) { |
| 10499 | const xmlChar *rEffValue = NULL; |
| 10500 | |
| 10501 | xmlSchemaGetEffectiveValueConstraint(base->attr, &effFixed, |
| 10502 | &rEffValue, 0); |
| 10503 | /* |
| 10504 | * 2.1.3.2 R's ·effective value constraint· is |
| 10505 | * fixed with the same string as B's. |
| 10506 | */ |
| 10507 | if ((effFixed == 0) || |
| 10508 | (! xmlStrEqual(rEffValue, bEffValue))) { |
| 10509 | xmlSchemaPAttrUseErr(ctxt, |
| 10510 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_3, |
| 10511 | NULL, type, NULL, cur->attr, |
| 10512 | "The effective value constraint of the " |
| 10513 | "attribute use is inconsistent with " |
| 10514 | "its correspondent of the base type", |
| 10515 | NULL); |
| 10516 | } |
| 10517 | } |
| 10518 | /* |
| 10519 | * TODO: derivation-ok-restriction 2.1.2 ({type definition} must be validly derived) |
| 10520 | */ |
| 10521 | /* |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10522 | * Override the attribute use. |
| 10523 | */ |
| 10524 | base->attr = cur->attr; |
| 10525 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 10526 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10527 | break; |
| 10528 | } |
| 10529 | base = base->next; |
| 10530 | } |
| 10531 | |
| 10532 | if (!found) { |
| 10533 | if (cur->attr->occurs != XML_SCHEMAS_ATTR_USE_PROHIBITED) { |
| 10534 | /* |
| 10535 | * derivation-ok-restriction 2.2 |
| 10536 | */ |
| 10537 | if ((type->attributeWildcard != NULL) && |
| 10538 | xmlSchemaMatchesWildcardNs(type->attributeWildcard, |
| 10539 | cur->attr->targetNamespace)) |
| 10540 | found = 1; |
| 10541 | |
| 10542 | if (!found) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10543 | xmlSchemaPAttrUseErr(ctxt, |
| 10544 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_2, |
| 10545 | NULL, type, NULL, cur->attr, |
| 10546 | "Neither a matching attribute use, " |
| 10547 | "nor a matching wildcard in the base type does exist", |
| 10548 | NULL); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10549 | } else { |
| 10550 | /* |
| 10551 | * Add the attribute use. |
| 10552 | * |
| 10553 | * Note that this may lead to funny derivation error reports, if |
| 10554 | * multiple equal attribute uses exist; but this is not |
| 10555 | * allowed anyway, and it will be reported beforehand. |
| 10556 | */ |
| 10557 | tmp = cur; |
| 10558 | if (prev != NULL) |
| 10559 | prev->next = cur->next; |
| 10560 | else |
| 10561 | uses = cur->next; |
| 10562 | cur = cur->next; |
| 10563 | if (type->attributeUses == NULL) { |
| 10564 | type->attributeUses = tmp; |
| 10565 | } else |
| 10566 | lastBaseUse->next = tmp; |
| 10567 | lastBaseUse = tmp; |
| 10568 | |
| 10569 | continue; |
| 10570 | } |
| 10571 | } |
| 10572 | } |
| 10573 | prev = cur; |
| 10574 | cur = cur->next; |
| 10575 | } |
| 10576 | if (uses != NULL) |
| 10577 | xmlSchemaFreeAttributeUseList(uses); |
| 10578 | } |
| 10579 | } else if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) { |
| 10580 | /* |
| 10581 | * The spec allows only appending, and not other kinds of extensions. |
| 10582 | * |
| 10583 | * This ensures: Schema Component Constraint: Derivation Valid (Extension) : 1.2 |
| 10584 | */ |
| 10585 | if (uses != NULL) { |
| 10586 | if (type->attributeUses == NULL) { |
| 10587 | type->attributeUses = uses; |
| 10588 | } else |
| 10589 | lastBaseUse->next = uses; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10590 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10591 | } else { |
| 10592 | /* |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10593 | * Derive implicitely from the ur-type. |
| 10594 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10595 | type->attributeUses = uses; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10596 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10597 | /* |
| 10598 | * 3.4.6 -> Complex Type Definition Properties Correct |
| 10599 | */ |
| 10600 | if (type->attributeUses != NULL) { |
| 10601 | cur = type->attributeUses; |
| 10602 | prev = NULL; |
| 10603 | while (cur != NULL) { |
| 10604 | /* |
| 10605 | * 4. Two distinct attribute declarations in the {attribute uses} must |
| 10606 | * not have identical {name}s and {target namespace}s. |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10607 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10608 | * Note that this was already done for "restriction" and types derived from |
| 10609 | * the ur-type. |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10610 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10611 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) { |
| 10612 | tmp = cur->next; |
| 10613 | while (tmp != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10614 | if ((xmlStrEqual(xmlSchemaGetAttrName(cur->attr), |
| 10615 | xmlSchemaGetAttrName(tmp->attr))) && |
| 10616 | (xmlStrEqual(xmlSchemaGetAttrTargetNsURI(cur->attr ), |
| 10617 | xmlSchemaGetAttrTargetNsURI(tmp->attr)))) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10618 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10619 | xmlSchemaPAttrUseErr(ctxt, |
| 10620 | XML_SCHEMAP_CT_PROPS_CORRECT_4, |
| 10621 | NULL, type, NULL, tmp->attr, |
| 10622 | "Duplicate attribute use specified", NULL); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10623 | break; |
| 10624 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10625 | tmp = tmp->next; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10626 | } |
| 10627 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10628 | /* |
| 10629 | * 5. Two distinct attribute declarations in the {attribute uses} must |
| 10630 | * not have {type definition}s which are or are derived from ID. |
| 10631 | */ |
| 10632 | if ((cur->attr->subtypes != NULL) && |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10633 | (xmlSchemaIsDerivedFromBuiltInType(ctxt, (xmlSchemaTypePtr) cur->attr, XML_SCHEMAS_ID))) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10634 | if (id != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10635 | xmlSchemaPAttrUseErr(ctxt, |
| 10636 | XML_SCHEMAP_CT_PROPS_CORRECT_5, |
| 10637 | NULL, type, NULL, cur->attr, |
| 10638 | "There must not exist more than one attribute use, " |
| 10639 | "declared of type 'ID' or derived from it", |
| 10640 | NULL); |
| 10641 | FREE_AND_NULL(str) |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10642 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10643 | id = cur; |
| 10644 | } |
| 10645 | /* |
| 10646 | * Remove "prohibited" attribute uses. The reason this is done at this late |
| 10647 | * stage is to be able to catch dublicate attribute uses. So we had to keep |
| 10648 | * prohibited uses in the list as well. |
| 10649 | */ |
| 10650 | if (cur->attr->occurs == XML_SCHEMAS_ATTR_USE_PROHIBITED) { |
| 10651 | tmp = cur; |
| 10652 | if (prev == NULL) |
| 10653 | type->attributeUses = cur->next; |
| 10654 | else |
| 10655 | prev->next = cur->next; |
| 10656 | cur = cur->next; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10657 | xmlFree(tmp); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10658 | } else { |
| 10659 | prev = cur; |
| 10660 | cur = cur->next; |
| 10661 | } |
| 10662 | } |
| 10663 | } |
| 10664 | /* |
| 10665 | * TODO: This check should be removed if we are 100% sure of |
| 10666 | * the base type attribute uses already being built. |
| 10667 | */ |
| 10668 | if ((baseType != NULL) && (!baseIsAnyType) && |
| 10669 | (baseType->type == XML_SCHEMA_TYPE_COMPLEX) && |
| 10670 | (baseType->contentType == XML_SCHEMA_CONTENT_UNKNOWN)) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 10671 | xmlSchemaPErr(ctxt, baseType->node, XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10672 | "Internal error: xmlSchemaBuildAttributeValidation: " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10673 | "attribute uses not builded on base type '%s'.\n", |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10674 | baseType->name, NULL); |
| 10675 | } |
| 10676 | return (0); |
| 10677 | } |
| 10678 | |
| 10679 | /** |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10680 | * xmlSchemaTypeFinalContains: |
| 10681 | * @schema: the schema |
| 10682 | * @type: the type definition |
| 10683 | * @final: the final |
| 10684 | * |
| 10685 | * Evaluates if a type definition contains the given "final". |
| 10686 | * This does take "finalDefault" into account as well. |
| 10687 | * |
| 10688 | * Returns 1 if the type does containt the given "final", |
| 10689 | * 0 otherwise. |
| 10690 | */ |
| 10691 | static int |
| 10692 | xmlSchemaTypeFinalContains(xmlSchemaPtr schema, xmlSchemaTypePtr type, int final) |
| 10693 | { |
| 10694 | int tfinal = final, tflags = type->flags; |
| 10695 | |
| 10696 | if (type == NULL) |
| 10697 | return (0); |
| 10698 | if (type->flags & XML_SCHEMAS_TYPE_FINAL_DEFAULT) { |
| 10699 | switch (final) { |
| 10700 | case XML_SCHEMAS_TYPE_FINAL_RESTRICTION: |
| 10701 | tfinal = XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION; |
| 10702 | break; |
| 10703 | case XML_SCHEMAS_TYPE_FINAL_EXTENSION: |
| 10704 | tfinal = XML_SCHEMAS_FINAL_DEFAULT_EXTENSION; |
| 10705 | break; |
| 10706 | case XML_SCHEMAS_TYPE_FINAL_LIST: |
| 10707 | tfinal = XML_SCHEMAS_FINAL_DEFAULT_LIST; |
| 10708 | break; |
| 10709 | case XML_SCHEMAS_TYPE_FINAL_UNION: |
| 10710 | tfinal = XML_SCHEMAS_FINAL_DEFAULT_UNION; |
| 10711 | break; |
| 10712 | } |
| 10713 | tflags = schema->flags; |
| 10714 | } |
| 10715 | if (tflags & tfinal) |
| 10716 | return (1); |
| 10717 | else |
| 10718 | return (0); |
| 10719 | |
| 10720 | } |
| 10721 | |
| 10722 | /** |
| 10723 | * xmlSchemaGetUnionSimpleTypeMemberTypes: |
| 10724 | * @type: the Union Simple Type |
| 10725 | * |
| 10726 | * Returns a list of member types of @type if existing, |
| 10727 | * returns NULL otherwise. |
| 10728 | */ |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 10729 | static xmlSchemaTypeLinkPtr |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10730 | xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type) |
| 10731 | { |
| 10732 | while (type != NULL) { |
| 10733 | if (type->memberTypes != NULL) |
| 10734 | return (type->memberTypes); |
| 10735 | else |
| 10736 | type = type->baseType; |
| 10737 | } |
| 10738 | return (NULL); |
| 10739 | } |
| 10740 | |
| 10741 | /** |
| 10742 | * xmlSchemaGetListSimpleTypeItemType: |
| 10743 | * @type: the simple type definition |
| 10744 | * |
| 10745 | * Returns the item type definition of the list simple type. |
| 10746 | */ |
| 10747 | static xmlSchemaTypePtr |
| 10748 | xmlSchemaGetListSimpleTypeItemType(xmlSchemaTypePtr type) |
| 10749 | { |
| 10750 | if ((type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) == 0) |
| 10751 | return (NULL); |
| 10752 | /* |
| 10753 | * Note: In libxml2, the built-in types do not reflect |
| 10754 | * the datatype hierarchy (yet?) - we have to treat them |
| 10755 | * in a special way. |
| 10756 | */ |
| 10757 | if (type->type == XML_SCHEMA_TYPE_BASIC) |
| 10758 | return (xmlSchemaGetBuiltInListSimpleTypeItemType(type)); |
| 10759 | if (type->subtypes->type == XML_SCHEMA_TYPE_LIST) |
| 10760 | /* 1 If the <list> alternative is chosen, then the type |
| 10761 | * definition ·resolved· to by the ·actual value· of the |
| 10762 | * itemType [attribute] of <list>, if present, otherwise |
| 10763 | * the type definition corresponding to the <simpleType> |
| 10764 | * among the [children] of <list>. |
| 10765 | */ |
| 10766 | return (type->subtypes->subtypes); |
| 10767 | else { |
| 10768 | /* 2 If the <restriction> option is chosen, then the |
| 10769 | * {item type definition} of the {base type definition}. |
| 10770 | */ |
| 10771 | return (xmlSchemaGetListSimpleTypeItemType(type->baseType)); |
| 10772 | } |
| 10773 | } |
| 10774 | |
| 10775 | /** |
| 10776 | * xmlSchemaCheckCOSSTDerivedOK: |
| 10777 | * @type: the derived simple type definition |
| 10778 | * @baseType: the base type definition |
| 10779 | * |
| 10780 | * Checks wheter @type can be validly |
| 10781 | * derived from @baseType. |
| 10782 | * |
| 10783 | * Returns 0 on success, an positive error code otherwise. |
| 10784 | */ |
| 10785 | static int |
| 10786 | xmlSchemaCheckCOSSTDerivedOK(xmlSchemaPtr schema, |
| 10787 | xmlSchemaTypePtr type, |
| 10788 | xmlSchemaTypePtr baseType, |
| 10789 | int subset) |
| 10790 | { |
| 10791 | /* |
| 10792 | * Schema Component Constraint: Type Derivation OK (Simple) |
| 10793 | * |
| 10794 | * |
| 10795 | * 1 They are the same type definition. |
| 10796 | * TODO: The identy check might have to be more complex than this. |
| 10797 | */ |
| 10798 | if (type == baseType) |
| 10799 | return (0); |
| 10800 | /* |
| 10801 | * 2.1 restriction is not in the subset, or in the {final} |
| 10802 | * of its own {base type definition}; |
| 10803 | */ |
| 10804 | if ((subset & XML_SCHEMAS_TYPE_FINAL_RESTRICTION) || |
| 10805 | (xmlSchemaTypeFinalContains(schema, |
| 10806 | type->baseType, XML_SCHEMAS_TYPE_FINAL_RESTRICTION))) { |
| 10807 | return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_1); |
| 10808 | } |
| 10809 | /* 2.2 */ |
| 10810 | if (type->baseType == baseType) { |
| 10811 | /* |
| 10812 | * 2.2.1 D's ·base type definition· is B. |
| 10813 | */ |
| 10814 | return (0); |
| 10815 | } |
| 10816 | /* |
| 10817 | * 2.2.2 D's ·base type definition· is not the ·ur-type definition· |
| 10818 | * and is validly derived from B given the subset, as defined by this |
| 10819 | * constraint. |
| 10820 | */ |
| 10821 | if ((type->baseType != xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE)) && |
| 10822 | (xmlSchemaCheckCOSSTDerivedOK(schema, type->baseType, baseType, subset) == 0)) { |
| 10823 | return (0); |
| 10824 | } |
| 10825 | /* |
| 10826 | * 2.2.3 D's {variety} is list or union and B is the ·simple ur-type |
| 10827 | * definition·. |
| 10828 | */ |
| 10829 | if (((type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) || |
| 10830 | (type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION)) && |
| 10831 | (baseType == xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE))) { |
| 10832 | return (0); |
| 10833 | } |
| 10834 | /* |
| 10835 | * 2.2.4 B's {variety} is union and D is validly derived from a type |
| 10836 | * definition in B's {member type definitions} given the subset, as |
| 10837 | * defined by this constraint. |
| 10838 | * |
| 10839 | * NOTE: This seems not to involve built-in types, since there is no |
| 10840 | * built-in Union Simple Type. |
| 10841 | */ |
| 10842 | if (baseType->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
| 10843 | xmlSchemaTypeLinkPtr cur; |
| 10844 | |
| 10845 | cur = baseType->memberTypes; |
| 10846 | while (cur != NULL) { |
| 10847 | if (xmlSchemaCheckCOSSTDerivedOK(schema, type, |
| 10848 | cur->type, subset) == 0) |
| 10849 | return (0); |
| 10850 | cur = cur->next; |
| 10851 | } |
| 10852 | } |
| 10853 | |
| 10854 | return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_2); |
| 10855 | } |
| 10856 | |
| 10857 | |
| 10858 | /** |
| 10859 | * xmlSchemaCheckSTPropsCorrect: |
| 10860 | * @ctxt: the schema parser context |
| 10861 | * @type: the simple type definition |
| 10862 | * |
| 10863 | * Checks st-props-correct. |
| 10864 | * |
| 10865 | * Returns 0 if the properties are correct, |
| 10866 | * if not, a positive error code and -1 on internal |
| 10867 | * errors. |
| 10868 | */ |
| 10869 | static int |
| 10870 | xmlSchemaCheckSTPropsCorrect(xmlSchemaParserCtxtPtr ctxt, |
| 10871 | xmlSchemaTypePtr type) |
| 10872 | { |
| 10873 | xmlSchemaTypePtr baseType = type->baseType, anySimpleType, |
| 10874 | anyType; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10875 | xmlChar *str = NULL; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10876 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10877 | /* STATE: error funcs converted. */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10878 | /* |
| 10879 | * Schema Component Constraint: Simple Type Definition Properties Correct |
| 10880 | * |
| 10881 | * NOTE: This is somehow redundant, since we actually built a simple type |
| 10882 | * to have all the needed information; this acts as an self test. |
| 10883 | */ |
| 10884 | anySimpleType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 10885 | anyType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 10886 | /* |
| 10887 | * TODO: 1 The values of the properties of a simple type definition must be as |
| 10888 | * described in the property tableau in Datatype definition, modulo the |
| 10889 | * impact of Missing Sub-components (§5.3). |
| 10890 | */ |
| 10891 | /* Base type: If the datatype has been ·derived· by ·restriction· |
| 10892 | * then the Simple Type Definition component from which it is ·derived·, |
| 10893 | * otherwise the Simple Type Definition for anySimpleType (§4.1.6). |
| 10894 | */ |
| 10895 | if (baseType == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10896 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10897 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10898 | NULL, type, NULL, |
| 10899 | "No base type existent", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10900 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
| 10901 | } |
| 10902 | if ((baseType->type != XML_SCHEMA_TYPE_SIMPLE) && |
| 10903 | ((baseType->type != XML_SCHEMA_TYPE_BASIC) || |
| 10904 | (baseType == anyType))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10905 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10906 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10907 | NULL, type, NULL, |
| 10908 | "The base type %s is not a simple type", |
| 10909 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 10910 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10911 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
| 10912 | } |
| 10913 | if ((baseType != anySimpleType) && |
| 10914 | (type->subtypes->type != XML_SCHEMA_TYPE_RESTRICTION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10915 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10916 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10917 | NULL, type, NULL, |
| 10918 | "A type, derived by list or union, must have" |
| 10919 | "the simple ur-type definition as base type, not %s", |
| 10920 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 10921 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10922 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
| 10923 | } |
| 10924 | /* |
| 10925 | * Variety: One of {atomic, list, union}. |
| 10926 | */ |
| 10927 | if (((type->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) == 0) && |
| 10928 | ((type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) == 0) && |
| 10929 | ((type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) == 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10930 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10931 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10932 | NULL, type, NULL, |
| 10933 | "The variety is absent", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10934 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
| 10935 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10936 | /* TODO: Finish this. Hmm, is this finished? */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10937 | |
| 10938 | /* |
| 10939 | * 2 All simple type definitions must be derived ultimately from the ·simple |
| 10940 | * ur-type definition (so· circular definitions are disallowed). That is, it |
| 10941 | * must be possible to reach a built-in primitive datatype or the ·simple |
| 10942 | * ur-type definition· by repeatedly following the {base type definition}. |
| 10943 | */ |
| 10944 | baseType = type->baseType; |
| 10945 | while ((baseType != NULL) && (baseType->type != XML_SCHEMA_TYPE_BASIC)) { |
| 10946 | if (baseType->contentType == XML_SCHEMA_CONTENT_UNKNOWN) |
| 10947 | xmlSchemaTypeFixup(baseType, ctxt, NULL); |
| 10948 | if (baseType == anySimpleType) |
| 10949 | break; |
| 10950 | else if (baseType == type) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10951 | xmlSchemaPCustomErr(ctxt, |
| 10952 | XML_SCHEMAP_ST_PROPS_CORRECT_2, |
| 10953 | NULL, type, NULL, |
| 10954 | "The definition is circular", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10955 | return (XML_SCHEMAP_ST_PROPS_CORRECT_2); |
| 10956 | } |
| 10957 | baseType = baseType->baseType; |
| 10958 | } |
| 10959 | /* |
| 10960 | * 3 The {final} of the {base type definition} must not contain restriction. |
| 10961 | */ |
| 10962 | if (xmlSchemaTypeFinalContains(ctxt->schema, baseType, |
| 10963 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10964 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10965 | XML_SCHEMAP_ST_PROPS_CORRECT_3, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10966 | NULL, type, NULL, |
| 10967 | "The 'final' of its base type %s must not contain " |
| 10968 | "'restriction'", |
| 10969 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 10970 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10971 | return (XML_SCHEMAP_ST_PROPS_CORRECT_3); |
| 10972 | } |
| 10973 | return (0); |
| 10974 | } |
| 10975 | |
| 10976 | /** |
| 10977 | * xmlSchemaCheckDerivationValidSimpleRestriction: |
| 10978 | * @ctxt: the schema parser context |
| 10979 | * @type: the simple type definition |
| 10980 | * |
| 10981 | * Checks if the given @type (simpleType) is derived |
| 10982 | * validly by restriction. |
| 10983 | * |
| 10984 | * Returns -1 on internal errors, 0 if the type is validly derived, |
| 10985 | * a positive error code otherwise. |
| 10986 | */ |
| 10987 | static int |
| 10988 | xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10989 | xmlSchemaTypePtr type) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10990 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10991 | xmlChar *str = NULL; |
| 10992 | |
| 10993 | /* STATE: error funcs converted. */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10994 | |
| 10995 | if (type->type != XML_SCHEMA_TYPE_SIMPLE) { |
| 10996 | xmlSchemaPErr(ctxt, type->node, |
| 10997 | XML_ERR_INTERNAL_ERROR, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10998 | "xmlSchemaCheckDerivationValidSimpleRestriction: The given " |
| 10999 | "type '%s' is not a user-derived simpleType.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11000 | type->name, NULL); |
| 11001 | return (-1); |
| 11002 | } |
| 11003 | |
| 11004 | if (type->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) { |
| 11005 | xmlSchemaTypePtr primitive; |
| 11006 | /* |
| 11007 | * 1.1 The {base type definition} must be an atomic simple |
| 11008 | * type definition or a built-in primitive datatype. |
| 11009 | */ |
| 11010 | if ((type->baseType->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11011 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11012 | XML_SCHEMAP_COS_ST_RESTRICTS_1_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11013 | NULL, type, NULL, |
| 11014 | "The base type %s is not an atomic simple type", |
| 11015 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 11016 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11017 | return (XML_SCHEMAP_COS_ST_RESTRICTS_1_1); |
| 11018 | } |
| 11019 | /* 1.2 The {final} of the {base type definition} must not contain |
| 11020 | * restriction. |
| 11021 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11022 | /* OPTIMIZE TODO : This is already done in xmlSchemaCheckStPropsCorrect */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11023 | if (xmlSchemaTypeFinalContains(ctxt->schema, type->baseType, |
| 11024 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11025 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11026 | XML_SCHEMAP_COS_ST_RESTRICTS_1_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11027 | NULL, type, NULL, |
| 11028 | "The final of its base type %s must not contain 'restriction'", |
| 11029 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 11030 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11031 | return (XML_SCHEMAP_COS_ST_RESTRICTS_1_2); |
| 11032 | } |
| 11033 | |
| 11034 | /* |
| 11035 | * 1.3.1 DF must be an allowed constraining facet for the {primitive |
| 11036 | * type definition}, as specified in the appropriate subsection of 3.2 |
| 11037 | * Primitive datatypes. |
| 11038 | */ |
| 11039 | if (type->facets != NULL) { |
| 11040 | xmlSchemaFacetPtr facet; |
| 11041 | int ok = 1; |
| 11042 | |
| 11043 | primitive = xmlSchemaGetPrimitiveType(type); |
| 11044 | if (primitive == NULL) { |
| 11045 | xmlSchemaPErr(ctxt, type->node, |
| 11046 | XML_ERR_INTERNAL_ERROR, |
| 11047 | "xmlSchemaCheckDerivationValidSimpleRestriction: failed " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11048 | "to get primitive type of type '%s'.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11049 | type->name, NULL); |
| 11050 | return (-1); |
| 11051 | } |
| 11052 | facet = type->facets; |
| 11053 | do { |
| 11054 | if (xmlSchemaIsBuiltInTypeFacet(primitive, facet->type) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11055 | ok = 0; |
| 11056 | xmlSchemaPIllegalFacetAtomicErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11057 | XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11058 | NULL, type, primitive, facet); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11059 | } |
| 11060 | facet = facet->next; |
| 11061 | } while (facet != NULL); |
| 11062 | if (ok == 0) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11063 | return (XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11064 | } |
| 11065 | /* |
| 11066 | * TODO: 1.3.2 (facet derivation) |
| 11067 | */ |
| 11068 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 11069 | xmlSchemaTypePtr itemType = NULL; |
| 11070 | |
| 11071 | itemType = xmlSchemaGetListSimpleTypeItemType(type); |
| 11072 | if (itemType == NULL) { |
| 11073 | xmlSchemaPErr(ctxt, type->node, |
| 11074 | XML_ERR_INTERNAL_ERROR, |
| 11075 | "Internal error: xmlSchemaCheckDerivationValidSimpleRestriction: " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11076 | "failed to evaluate the item type of type '%s'.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11077 | type->name, NULL); |
| 11078 | return (-1); |
| 11079 | } |
| 11080 | /* |
| 11081 | * 2.1 The {item type definition} must have a {variety} of atomic or |
| 11082 | * union (in which case all the {member type definitions} |
| 11083 | * must be atomic). |
| 11084 | */ |
| 11085 | if (((itemType->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) == 0) && |
| 11086 | ((itemType->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) == 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11087 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11088 | XML_SCHEMAP_COS_ST_RESTRICTS_2_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11089 | NULL, type, NULL, |
| 11090 | "The item type %s must have a variety of atomic or union", |
| 11091 | xmlSchemaFormatItemForReport(&str, NULL, itemType, NULL, 1)); |
| 11092 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11093 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1); |
| 11094 | } else if (itemType->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
| 11095 | xmlSchemaTypeLinkPtr member; |
| 11096 | |
| 11097 | member = itemType->memberTypes; |
| 11098 | while (member != NULL) { |
| 11099 | if ((member->type->flags & |
| 11100 | XML_SCHEMAS_TYPE_VARIETY_ATOMIC) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11101 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11102 | XML_SCHEMAP_COS_ST_RESTRICTS_2_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11103 | NULL, type, NULL, |
| 11104 | "The item type is a union type, but the " |
| 11105 | "member type %s of this item type is not atomic", |
| 11106 | xmlSchemaFormatItemForReport(&str, NULL, member->type, NULL, 1)); |
| 11107 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11108 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1); |
| 11109 | } |
| 11110 | member = member->next; |
| 11111 | } |
| 11112 | } |
| 11113 | |
| 11114 | if (type->baseType == xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE)) { |
| 11115 | xmlSchemaFacetPtr facet; |
| 11116 | /* |
| 11117 | * This is the case if we have: <simpleType><list .. |
| 11118 | */ |
| 11119 | /* |
| 11120 | * 2.3.1 |
| 11121 | * 2.3.1.1 The {final} of the {item type definition} must not |
| 11122 | * contain list. |
| 11123 | */ |
| 11124 | if (xmlSchemaTypeFinalContains(ctxt->schema, |
| 11125 | itemType, XML_SCHEMAS_TYPE_FINAL_LIST)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11126 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11127 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11128 | NULL, type, NULL, |
| 11129 | "The final of its item type %s must not contain 'list'", |
| 11130 | xmlSchemaFormatItemForReport(&str, NULL, itemType, NULL, 1)); |
| 11131 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11132 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1); |
| 11133 | } |
| 11134 | /* |
| 11135 | * 2.3.1.2 The {facets} must only contain the whiteSpace |
| 11136 | * facet component. |
| 11137 | */ |
| 11138 | if (type->facets != NULL) { |
| 11139 | facet = type->facets; |
| 11140 | do { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11141 | if (facet->type != XML_SCHEMA_FACET_WHITESPACE) { |
| 11142 | xmlSchemaPIllegalFacetListUnionErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11143 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11144 | NULL, type, facet); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11145 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2); |
| 11146 | } |
| 11147 | facet = facet->next; |
| 11148 | } while (facet != NULL); |
| 11149 | } |
| 11150 | /* |
| 11151 | * TODO: Datatypes states: |
| 11152 | * A ·list· datatype can be ·derived· from an ·atomic· datatype |
| 11153 | * whose ·lexical space· allows space (such as string or anyURI)or |
| 11154 | * a ·union· datatype any of whose {member type definitions}'s |
| 11155 | * ·lexical space· allows space. |
| 11156 | */ |
| 11157 | } else { |
| 11158 | /* |
| 11159 | * This is the case if we have: <simpleType><restriction ... |
| 11160 | */ |
| 11161 | /* |
| 11162 | * 2.3.2 |
| 11163 | * 2.3.2.1 The {base type definition} must have a {variety} of list. |
| 11164 | */ |
| 11165 | if ((type->baseType->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11166 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11167 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11168 | NULL, type, NULL, |
| 11169 | "The base type %s must be a list type", |
| 11170 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 11171 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11172 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1); |
| 11173 | } |
| 11174 | /* |
| 11175 | * 2.3.2.2 The {final} of the {base type definition} must not |
| 11176 | * contain restriction. |
| 11177 | */ |
| 11178 | if (xmlSchemaTypeFinalContains(ctxt->schema, type->baseType, |
| 11179 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11180 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11181 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11182 | NULL, type, NULL, |
| 11183 | "The final of the base type %s must not contain 'restriction'", |
| 11184 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 11185 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11186 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2); |
| 11187 | } |
| 11188 | /* |
| 11189 | * 2.3.2.3 The {item type definition} must be validly derived |
| 11190 | * from the {base type definition}'s {item type definition} given |
| 11191 | * the empty set, as defined in Type Derivation OK (Simple) (§3.14.6). |
| 11192 | */ |
| 11193 | { |
| 11194 | xmlSchemaTypePtr baseItemType; |
| 11195 | |
| 11196 | baseItemType = xmlSchemaGetListSimpleTypeItemType(type->baseType); |
| 11197 | if (baseItemType == NULL) { |
| 11198 | xmlSchemaPErr(ctxt, type->node, |
| 11199 | XML_ERR_INTERNAL_ERROR, |
| 11200 | "xmlSchemaCheckDerivationValidSimpleRestriction: " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11201 | "List simple type '%s': Failed to " |
| 11202 | "evaluate the item type of its base type '%s'.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11203 | type->name, type->baseType->name); |
| 11204 | return (-1); |
| 11205 | } |
| 11206 | if ((itemType != baseItemType) && |
| 11207 | (xmlSchemaCheckCOSSTDerivedOK(ctxt->schema, itemType, |
| 11208 | baseItemType, 0) != 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11209 | xmlChar *strBIT = NULL, *strBT = NULL; |
| 11210 | xmlSchemaPCustomErrExt(ctxt, |
| 11211 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3, |
| 11212 | NULL, type, NULL, |
| 11213 | "The item type %s is not validly derived from the " |
| 11214 | "item type %s of the base type %s", |
| 11215 | xmlSchemaFormatItemForReport(&str, NULL, itemType, NULL, 1), |
| 11216 | xmlSchemaFormatItemForReport(&strBIT, NULL, baseItemType, NULL, 1), |
| 11217 | xmlSchemaFormatItemForReport(&strBT, NULL, type->baseType, NULL, 1)); |
| 11218 | |
| 11219 | FREE_AND_NULL(str) |
| 11220 | FREE_AND_NULL(strBIT) |
| 11221 | FREE_AND_NULL(strBT) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11222 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3); |
| 11223 | } |
| 11224 | } |
| 11225 | |
| 11226 | if (type->facets != NULL) { |
| 11227 | xmlSchemaFacetPtr facet; |
| 11228 | int ok = 1; |
| 11229 | /* |
| 11230 | * 2.3.2.4 Only length, minLength, maxLength, whiteSpace, pattern |
| 11231 | * and enumeration facet components are allowed among the {facets}. |
| 11232 | */ |
| 11233 | facet = type->facets; |
| 11234 | do { |
| 11235 | switch (facet->type) { |
| 11236 | case XML_SCHEMA_FACET_LENGTH: |
| 11237 | case XML_SCHEMA_FACET_MINLENGTH: |
| 11238 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 11239 | case XML_SCHEMA_FACET_WHITESPACE: |
| 11240 | /* |
| 11241 | * TODO: 2.5.1.2 List datatypes |
| 11242 | * The value of ·whiteSpace· is fixed to the value collapse. |
| 11243 | */ |
| 11244 | case XML_SCHEMA_FACET_PATTERN: |
| 11245 | case XML_SCHEMA_FACET_ENUMERATION: |
| 11246 | break; |
| 11247 | default: { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11248 | xmlSchemaPIllegalFacetListUnionErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11249 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11250 | NULL, type, facet); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11251 | /* |
| 11252 | * We could return, but it's nicer to report all |
| 11253 | * invalid facets. |
| 11254 | */ |
| 11255 | ok = 0; |
| 11256 | } |
| 11257 | } |
| 11258 | facet = facet->next; |
| 11259 | } while (facet != NULL); |
| 11260 | if (ok == 0) |
| 11261 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4); |
| 11262 | /* |
| 11263 | * TODO: 2.3.2.5 For each facet in the {facets} (call this DF), if there |
| 11264 | * is a facet of the same kind in the {facets} of the {base type |
| 11265 | * definition} (call this BF),then the DF's {value} must be a valid |
| 11266 | * restriction of BF's {value} as defined in [XML Schemas: Datatypes]. |
| 11267 | */ |
| 11268 | } |
| 11269 | |
| 11270 | |
| 11271 | } |
| 11272 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
| 11273 | /* |
| 11274 | * 3.1 The {member type definitions} must all have {variety} of |
| 11275 | * atomic or list. |
| 11276 | */ |
| 11277 | xmlSchemaTypeLinkPtr member; |
| 11278 | |
| 11279 | member = type->memberTypes; |
| 11280 | while (member != NULL) { |
| 11281 | if (((member->type->flags & |
| 11282 | XML_SCHEMAS_TYPE_VARIETY_ATOMIC) == 0) && |
| 11283 | ((member->type->flags & |
| 11284 | XML_SCHEMAS_TYPE_VARIETY_LIST) == 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11285 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11286 | XML_SCHEMAP_COS_ST_RESTRICTS_3_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11287 | NULL, type, NULL, |
| 11288 | "The member type %s is neither an atomic, nor a list type", |
| 11289 | xmlSchemaFormatItemForReport(&str, NULL, member->type, NULL, 1)); |
| 11290 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11291 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_1); |
| 11292 | } |
| 11293 | member = member->next; |
| 11294 | } |
| 11295 | /* |
| 11296 | * 3.3.1 If the {base type definition} is the ·simple ur-type |
| 11297 | * definition· |
| 11298 | */ |
| 11299 | if (type->baseType == xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE)) { |
| 11300 | /* |
| 11301 | * 3.3.1.1 All of the {member type definitions} must have a |
| 11302 | * {final} which does not contain union. |
| 11303 | */ |
| 11304 | member = type->memberTypes; |
| 11305 | while (member != NULL) { |
| 11306 | if (xmlSchemaTypeFinalContains(ctxt->schema, member->type, |
| 11307 | XML_SCHEMAS_TYPE_FINAL_UNION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11308 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11309 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11310 | NULL, type, NULL, |
| 11311 | "The final of member type %s contains 'union'", |
| 11312 | xmlSchemaFormatItemForReport(&str, NULL, member->type, NULL, 1)); |
| 11313 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11314 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1); |
| 11315 | } |
| 11316 | member = member->next; |
| 11317 | } |
| 11318 | /* |
| 11319 | * 3.3.1.2 The {facets} must be empty. |
| 11320 | */ |
| 11321 | if (type->facetSet != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11322 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11323 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11324 | NULL, type, NULL, |
| 11325 | "No facets allowed", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11326 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2); |
| 11327 | } |
| 11328 | } else { |
| 11329 | /* |
| 11330 | * 3.3.2.1 The {base type definition} must have a {variety} of union. |
| 11331 | */ |
| 11332 | if ((type->baseType->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11333 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11334 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11335 | NULL, type, NULL, |
| 11336 | "The base type %s is not a union type", |
| 11337 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 11338 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11339 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1); |
| 11340 | } |
| 11341 | /* |
| 11342 | * 3.3.2.2 The {final} of the {base type definition} must not contain restriction. |
| 11343 | */ |
| 11344 | if (xmlSchemaTypeFinalContains(ctxt->schema, type->baseType, |
| 11345 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11346 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11347 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11348 | NULL, type, NULL, |
| 11349 | "The final of its base type %s must not contain 'restriction'", |
| 11350 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 11351 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11352 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2); |
| 11353 | } |
| 11354 | /* |
| 11355 | * 3.3.2.3 The {member type definitions}, in order, must be validly |
| 11356 | * derived from the corresponding type definitions in the {base |
| 11357 | * type definition}'s {member type definitions} given the empty set, |
| 11358 | * as defined in Type Derivation OK (Simple) (§3.14.6). |
| 11359 | */ |
| 11360 | { |
| 11361 | xmlSchemaTypeLinkPtr baseMember; |
| 11362 | |
| 11363 | /* |
| 11364 | * OPTIMIZE: if the type is restricting, it has no local defined |
| 11365 | * member types and inherits the member types of the base type; |
| 11366 | * thus a check for equality can be skipped. |
| 11367 | */ |
| 11368 | /* |
| 11369 | * TODO: Even worse: I cannot see a scenario where a restricting |
| 11370 | * union simple type can have other member types as the member |
| 11371 | * types of it's base type. This check seems not necessary with |
| 11372 | * respect to the derivation process in libxml2. |
| 11373 | */ |
| 11374 | if (type->memberTypes != NULL) { |
| 11375 | member = type->memberTypes; |
| 11376 | baseMember = xmlSchemaGetUnionSimpleTypeMemberTypes(type->baseType); |
| 11377 | if ((member == NULL) && (baseMember != NULL)) { |
| 11378 | xmlSchemaPErr(ctxt, type->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 11379 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11380 | "Internal error: " |
| 11381 | "xmlSchemaCheckDerivationValidSimpleRestriction " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11382 | "(3.3.2.3), union simple type '%s', unequal number " |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11383 | "of member types in the base type\n", |
| 11384 | type->name, NULL); |
| 11385 | } |
| 11386 | while (member != NULL) { |
| 11387 | if (baseMember == NULL) { |
| 11388 | xmlSchemaPErr(ctxt, type->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 11389 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11390 | "Internal error: " |
| 11391 | "xmlSchemaCheckDerivationValidSimpleRestriction " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11392 | "(3.3.2.3), union simple type '%s', unequal number " |
| 11393 | "of member types in the base type.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11394 | type->name, NULL); |
| 11395 | } |
| 11396 | if ((member->type != baseMember->type) && |
| 11397 | (xmlSchemaCheckCOSSTDerivedOK(ctxt->schema, |
| 11398 | member->type, baseMember->type, 0) != 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11399 | xmlChar *strBMT = NULL, *strBT = NULL; |
| 11400 | |
| 11401 | xmlSchemaPCustomErrExt(ctxt, |
| 11402 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3, |
| 11403 | NULL, type, NULL, |
| 11404 | "The member type %s is not validly derived from its " |
| 11405 | "corresponding member type %s of the base type %s", |
| 11406 | xmlSchemaFormatItemForReport(&str, NULL, member->type, NULL, 1), |
| 11407 | xmlSchemaFormatItemForReport(&strBMT, NULL, baseMember->type, NULL, 1), |
| 11408 | xmlSchemaFormatItemForReport(&strBT, NULL, type->baseType, NULL, 1)); |
| 11409 | FREE_AND_NULL(str) |
| 11410 | FREE_AND_NULL(strBMT) |
| 11411 | FREE_AND_NULL(strBT) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11412 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3); |
| 11413 | } |
| 11414 | member = member->next; |
| 11415 | baseMember = baseMember->next; |
| 11416 | } |
| 11417 | } |
| 11418 | } |
| 11419 | /* |
| 11420 | * 3.3.2.4 Only pattern and enumeration facet components are |
| 11421 | * allowed among the {facets}. |
| 11422 | */ |
| 11423 | if (type->facets != NULL) { |
| 11424 | xmlSchemaFacetPtr facet; |
| 11425 | int ok = 1; |
| 11426 | |
| 11427 | facet = type->facets; |
| 11428 | do { |
| 11429 | if ((facet->type != XML_SCHEMA_FACET_PATTERN) && |
| 11430 | (facet->type != XML_SCHEMA_FACET_ENUMERATION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11431 | xmlSchemaPIllegalFacetListUnionErr(ctxt, |
| 11432 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4, |
| 11433 | NULL, type, facet); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11434 | ok = 0; |
| 11435 | } |
| 11436 | facet = facet->next; |
| 11437 | } while (facet != NULL); |
| 11438 | if (ok == 0) |
| 11439 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4); |
| 11440 | |
| 11441 | } |
| 11442 | /* |
| 11443 | * TODO: 3.3.2.5 (facet derivation) |
| 11444 | */ |
| 11445 | } |
| 11446 | } |
| 11447 | |
| 11448 | return (0); |
| 11449 | } |
| 11450 | |
| 11451 | /** |
| 11452 | * xmlSchemaCheckSRCSimpleType: |
| 11453 | * @ctxt: the schema parser context |
| 11454 | * @type: the simple type definition |
| 11455 | * |
| 11456 | * Checks crc-simple-type constraints. |
| 11457 | * |
| 11458 | * Returns 0 if the constraints are satisfied, |
| 11459 | * if not a positive error code and -1 on internal |
| 11460 | * errors. |
| 11461 | */ |
| 11462 | static int |
| 11463 | xmlSchemaCheckSRCSimpleType(xmlSchemaParserCtxtPtr ctxt, |
| 11464 | xmlSchemaTypePtr type) |
| 11465 | { |
| 11466 | /* |
| 11467 | * NOTE: src-simple-type 2-4 are redundant, since the checks |
| 11468 | * were are done for the corresponding <restriction>, <list> and <union> |
| 11469 | * elements, but W3C wants a <simpleType> error as well, so it gets one. |
| 11470 | * Maby this can be skipped in the future, if we get sure it's not needed. |
| 11471 | */ |
| 11472 | if (type->subtypes == NULL) { |
| 11473 | xmlSchemaPErr(ctxt, type->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 11474 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11475 | "Internal error: xmlSchemaCheckSRCSimpleType, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11476 | "no subtype on simple type '%s'.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11477 | type->name, NULL); |
| 11478 | return (-1); |
| 11479 | } |
| 11480 | /* |
| 11481 | * src-simple-type.1 The corresponding simple type definition, if any, |
| 11482 | * must satisfy the conditions set out in Constraints on Simple Type |
| 11483 | * Definition Schema Components (§3.14.6). |
| 11484 | */ |
| 11485 | if ((xmlSchemaCheckSTPropsCorrect(ctxt, type) != 0) || |
| 11486 | (xmlSchemaCheckCOSSTRestricts(ctxt, type) != 0)) { |
| 11487 | /* |
| 11488 | * TODO: Removed this, since it got annoying to get an |
| 11489 | * extra error report, if anything failed until now. |
| 11490 | * Enable this if needed. |
| 11491 | */ |
| 11492 | /* |
| 11493 | xmlSchemaPErr(ctxt, type->node, |
| 11494 | XML_SCHEMAP_SRC_SIMPLE_TYPE_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11495 | "Simple type '%s' does not satisfy the constraints " |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11496 | "on simple type definitions.\n", |
| 11497 | type->name, NULL); |
| 11498 | */ |
| 11499 | return (XML_SCHEMAP_SRC_SIMPLE_TYPE_1); |
| 11500 | } |
| 11501 | |
| 11502 | if (type->subtypes->type == XML_SCHEMA_TYPE_RESTRICTION) { |
| 11503 | /* |
| 11504 | * src-simple-type.2 If the <restriction> alternative is chosen, |
| 11505 | * either it must have a base [attribute] or a <simpleType> among its |
| 11506 | * [children], but not both. |
| 11507 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11508 | /* |
| 11509 | * XML_SCHEMAP_SRC_SIMPLE_TYPE_2 |
| 11510 | * NOTE: This was removed, since this will be already handled |
| 11511 | * in the parse function for <restriction>. |
| 11512 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11513 | } else if (type->subtypes->type == XML_SCHEMA_TYPE_LIST) { |
| 11514 | /* src-simple-type.3 If the <list> alternative is chosen, either it must have |
| 11515 | * an itemType [attribute] or a <simpleType> among its [children], |
| 11516 | * but not both. |
| 11517 | * NOTE: baseType is set to the local simple type definiton, |
| 11518 | * if existent, at parse time. This is a hack and not nice. |
| 11519 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11520 | /* |
| 11521 | * TODO: Remove this, and add the check to the parse function of <list>. |
| 11522 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11523 | if (((type->subtypes->base == NULL) && |
| 11524 | (type->baseType == NULL)) || |
| 11525 | ((type->subtypes->base != NULL) && |
| 11526 | (type->subtypes->baseType != NULL))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11527 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11528 | XML_SCHEMAP_SRC_SIMPLE_TYPE_3, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11529 | NULL, type, NULL, |
| 11530 | "Either the attribute 'itemType' or the <simpleType> child " |
| 11531 | "must be present on the <list> child ", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11532 | return (XML_SCHEMAP_SRC_SIMPLE_TYPE_3); |
| 11533 | } |
| 11534 | |
| 11535 | |
| 11536 | } else if (type->subtypes->type == XML_SCHEMA_TYPE_UNION) { |
| 11537 | xmlSchemaTypeLinkPtr member; |
| 11538 | xmlSchemaTypePtr ancestor, anySimpleType; |
| 11539 | |
| 11540 | anySimpleType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 11541 | |
| 11542 | /* src-simple-type.4 Circular union type definition is disallowed. That is, if |
| 11543 | * the <union> alternative is chosen, there must not be any entries |
| 11544 | * in the memberTypes [attribute] at any depth which resolve to the |
| 11545 | * component corresponding to the <simpleType>. |
| 11546 | */ |
| 11547 | member = type->memberTypes; |
| 11548 | while (member != NULL) { |
| 11549 | ancestor = member->type; |
| 11550 | while ((ancestor != NULL) && (ancestor->type != XML_SCHEMA_TYPE_BASIC)) { |
| 11551 | if (ancestor->contentType == XML_SCHEMA_CONTENT_UNKNOWN) |
| 11552 | xmlSchemaTypeFixup(ancestor, ctxt, NULL); |
| 11553 | if (ancestor == anySimpleType) |
| 11554 | break; |
| 11555 | else if (ancestor == type) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11556 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11557 | XML_SCHEMAP_SRC_SIMPLE_TYPE_4, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11558 | NULL, type, NULL, |
| 11559 | "The definition is circular", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11560 | return (XML_SCHEMAP_SRC_SIMPLE_TYPE_4); |
| 11561 | } else if (ancestor->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 11562 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11563 | * TODO, FIXME: Although a list simple type must not have a union ST |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11564 | * type as item type, which in turn has a list ST as member |
| 11565 | * type, we will assume this here as well, since this check |
| 11566 | * was not yet performed. |
| 11567 | */ |
| 11568 | |
| 11569 | } |
| 11570 | ancestor = ancestor->baseType; |
| 11571 | } |
| 11572 | member = member->next; |
| 11573 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11574 | } |
| 11575 | |
| 11576 | return (0); |
| 11577 | } |
| 11578 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11579 | #if 0 /* Not yet used code for CT schema validation */ |
| 11580 | static int |
| 11581 | xmlSchemaCheckCVCSimpleType(xmlSchemaValidCtxtPtr ctxt, |
| 11582 | const xmlChar * value, |
| 11583 | xmlSchemaTypePtr type, |
| 11584 | int fireErrors) |
| 11585 | { |
| 11586 | int ret; |
| 11587 | /* |
| 11588 | * 3.14.4 Simple Type Definition Validation Rules |
| 11589 | * Validation Rule: String Valid |
| 11590 | */ |
| 11591 | /* |
| 11592 | * 1 It is schema-valid with respect to that definition as defined |
| 11593 | * by Datatype Valid in [XML Schemas: Datatypes]. |
| 11594 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11595 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, type, value, |
| 11596 | fireErrors, 1, 1, 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11597 | return (ret); |
| 11598 | /* |
| 11599 | * 2.1 If The definition is ENTITY or is validly derived from ENTITY given |
| 11600 | * the empty set, as defined in Type Derivation OK (Simple) (§3.14.6), then |
| 11601 | * the string must be a ·declared entity name·. |
| 11602 | */ |
| 11603 | /* |
| 11604 | * 2.2 If The definition is ENTITIES or is validly derived from ENTITIES |
| 11605 | * given the empty set, as defined in Type Derivation OK (Simple) (§3.14.6), |
| 11606 | * then every whitespace-delimited substring of the string must be a ·declared |
| 11607 | * entity name·. |
| 11608 | */ |
| 11609 | /* |
| 11610 | * 2.3 otherwise no further condition applies. |
| 11611 | */ |
| 11612 | |
| 11613 | return (0); |
| 11614 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11615 | #endif |
| 11616 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11617 | |
| 11618 | static int |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11619 | xmlSchemaCreatePCtxtOnVCtxt(xmlSchemaValidCtxtPtr vctxt) |
| 11620 | { |
| 11621 | if (vctxt->pctxt == NULL) { |
| 11622 | vctxt->pctxt =xmlSchemaNewParserCtxtUseDict("*", vctxt->schema->dict); |
| 11623 | /* vctxt->pctxt = xmlSchemaNewParserCtxt("*"); */ |
| 11624 | if (vctxt->pctxt == NULL) { |
| 11625 | xmlSchemaVErr(vctxt, NULL, |
| 11626 | XML_SCHEMAV_INTERNAL, |
| 11627 | "Internal error: xmlSchemaCreatePCtxtOnVCtxt, " |
| 11628 | "failed to create a temp. parser context.\n", |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11629 | NULL, NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11630 | return (-1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11631 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11632 | /* TODO: Pass user data. */ |
| 11633 | xmlSchemaSetParserErrors(vctxt->pctxt, vctxt->error, vctxt->warning, NULL); |
| 11634 | } |
| 11635 | return (0); |
| 11636 | } |
| 11637 | |
| 11638 | static int |
| 11639 | xmlSchemaCreateVCtxtOnPCtxt(xmlSchemaParserCtxtPtr ctxt) |
| 11640 | { |
| 11641 | if (ctxt->vctxt == NULL) { |
| 11642 | ctxt->vctxt = xmlSchemaNewValidCtxt(NULL); |
| 11643 | if (ctxt->vctxt == NULL) { |
| 11644 | xmlSchemaPErr(ctxt, NULL, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 11645 | XML_SCHEMAP_INTERNAL, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11646 | "Internal error: xmlSchemaCreatePCtxtOnVCtxt, " |
| 11647 | "failed to create a temp. validation context.\n", |
| 11648 | NULL, NULL); |
| 11649 | return (-1); |
| 11650 | } |
| 11651 | /* TODO: Pass user data. */ |
| 11652 | xmlSchemaSetValidErrors(ctxt->vctxt, ctxt->error, ctxt->warning, NULL); |
| 11653 | } |
| 11654 | return (0); |
| 11655 | } |
| 11656 | |
| 11657 | /** |
| 11658 | * xmlSchemaCheckCOSValidDefault: |
| 11659 | * @ctxt: the schema parser context |
| 11660 | * @type: the simple type definition |
| 11661 | * @value: the default value |
| 11662 | * @node: an optional node (the holder of the value) |
| 11663 | * |
| 11664 | * Checks the "cos-valid-default" constraints. |
| 11665 | * |
| 11666 | * Returns 0 if the constraints are satisfied, |
| 11667 | * if not, a positive error code and -1 on internal |
| 11668 | * errors. |
| 11669 | */ |
| 11670 | static int |
| 11671 | xmlSchemaCheckCOSValidDefault(xmlSchemaParserCtxtPtr pctxt, |
| 11672 | xmlSchemaValidCtxtPtr vctxt, |
| 11673 | xmlSchemaTypePtr type, |
| 11674 | const xmlChar *value, |
| 11675 | xmlNodePtr node) |
| 11676 | { |
| 11677 | int ret = 0; |
| 11678 | |
| 11679 | /* |
| 11680 | * cos-valid-default: |
| 11681 | * Schema Component Constraint: Element Default Valid (Immediate) |
| 11682 | * For a string to be a valid default with respect to a type |
| 11683 | * definition the appropriate case among the following must be true: |
| 11684 | */ |
| 11685 | /* |
| 11686 | * NOTE: This has to work without a given node (the holder of the |
| 11687 | * value), since it should work on the component, i.e. an underlying |
| 11688 | * DOM must not be mandatory. |
| 11689 | */ |
| 11690 | if ((pctxt == NULL) || (vctxt == NULL)) { |
| 11691 | xmlSchemaPErr(pctxt, node, |
| 11692 | XML_SCHEMAP_INTERNAL, |
| 11693 | "Internal error: xmlSchemaCheckCOSValidDefault, " |
| 11694 | "bad arguments: the parser and/or validation context is " |
| 11695 | "missing.\n", |
| 11696 | NULL, NULL); |
| 11697 | return (-1); |
| 11698 | } |
| 11699 | if IS_COMPLEX_TYPE(type) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11700 | /* |
| 11701 | * Complex type. |
| 11702 | * |
| 11703 | * 2.1 its {content type} must be a simple type definition or mixed. |
| 11704 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11705 | /* |
| 11706 | * TODO: Adjust this when the content type will be computed |
| 11707 | * correctly. |
| 11708 | */ |
| 11709 | if ((type->contentType != XML_SCHEMA_CONTENT_SIMPLE) && |
| 11710 | (type->contentType != XML_SCHEMA_CONTENT_BASIC) && |
| 11711 | (type->contentType != XML_SCHEMA_CONTENT_MIXED)) { |
| 11712 | xmlSchemaPSimpleTypeErr(pctxt, |
| 11713 | XML_SCHEMAP_COS_VALID_DEFAULT_2_1, |
| 11714 | NULL, NULL, node, |
| 11715 | type, NULL, NULL, |
| 11716 | "If the type of a constraint value is complex, its content " |
| 11717 | "type must be mixed or a simple type", |
| 11718 | NULL, NULL); |
| 11719 | return(XML_SCHEMAP_COS_VALID_DEFAULT_2_1); |
| 11720 | } |
| 11721 | if (type->contentType == XML_SCHEMA_CONTENT_MIXED) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11722 | /* |
| 11723 | * 2.2.2 If the {content type} is mixed, then the {content type}'s |
| 11724 | * particle must be ·emptiable· as defined by Particle Emptiable |
| 11725 | * (§3.9.6). |
| 11726 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11727 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11728 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11729 | * URGENT TODO: Implement this. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11730 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11731 | return (0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11732 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11733 | } |
| 11734 | /* |
| 11735 | * 1 If the type definition is a simple type definition, then the string |
| 11736 | * must be ·valid· with respect to that definition as defined by String |
| 11737 | * Valid (§3.14.4). |
| 11738 | * |
| 11739 | * AND |
| 11740 | * |
| 11741 | * 2.2.1 If the {content type} is a simple type definition, then the |
| 11742 | * string must be ·valid· with respect to that simple type definition |
| 11743 | * as defined by String Valid (§3.14.4). |
| 11744 | */ |
| 11745 | vctxt->node = node; |
| 11746 | vctxt->cur = NULL; |
| 11747 | ret = xmlSchemaValidateSimpleTypeValue(vctxt, type, value, 1, 1, 1, 0); |
| 11748 | /* ret = xmlSchemaCheckCVCSimpleType(vctxt, elemDecl->value, typeDef, 0); */ |
| 11749 | if (ret < 0) { |
| 11750 | xmlSchemaPErr(pctxt, node, |
| 11751 | /* NOTNICE: error code: This function will be used during |
| 11752 | * schema construction and xsi:type validation. |
| 11753 | */ |
| 11754 | XML_SCHEMAP_INTERNAL, |
| 11755 | "Internal error: xmlSchemaCheckCOSValidDefault, " |
| 11756 | "while validating a value constaint value.\n", |
| 11757 | NULL, NULL); |
| 11758 | |
| 11759 | } |
| 11760 | return (ret); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11761 | } |
| 11762 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11763 | #if 0 /* Not yet used code for CT schema validation */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11764 | /** |
| 11765 | * xmlSchemaGetSTContentOfCT: |
| 11766 | * @ctxt: the schema parser context |
| 11767 | * @type: the complex type definition |
| 11768 | * |
| 11769 | * |
| 11770 | * Returns the corresponding simple type for the content of |
| 11771 | * the complex type. |
| 11772 | */ |
| 11773 | static xmlSchemaTypePtr |
| 11774 | xmlSchemaGetSTContentOfCT(xmlSchemaParserCtxtPtr ctxt, |
| 11775 | xmlSchemaTypePtr type) |
| 11776 | { |
| 11777 | xmlSchemaTypePtr orig = type, anyType; |
| 11778 | |
| 11779 | anyType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 11780 | while ((type != NULL) && (type != anyType) && |
| 11781 | (type->type == XML_SCHEMA_TYPE_COMPLEX)) { |
| 11782 | if (type->type == XML_SCHEMA_TYPE_SIMPLE) |
| 11783 | return(type); |
| 11784 | type = type->baseType; |
| 11785 | } |
| 11786 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 11787 | XML_SCHEMAP_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11788 | NULL, orig, NULL, |
| 11789 | "Internal error: xmlSchemaGetSTContentTypeOfCT, " |
| 11790 | "no simple type for the content of complex type '%s' could be " |
| 11791 | "computed", orig->name); |
| 11792 | return (NULL); |
| 11793 | } |
| 11794 | |
| 11795 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11796 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11797 | |
| 11798 | /** |
| 11799 | * xmlSchemaCheckCOSCTExtends: |
| 11800 | * @ctxt: the schema parser context |
| 11801 | * @type: the complex type definition |
| 11802 | * |
| 11803 | * Schema Component Constraint: Derivation Valid (Extension) |
| 11804 | * |
| 11805 | * Returns 0 if the constraints are satisfied, a positive |
| 11806 | * error code if not and -1 if an internal error occured. |
| 11807 | */ |
| 11808 | static int |
| 11809 | xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt, |
| 11810 | xmlSchemaTypePtr type) |
| 11811 | { |
| 11812 | xmlSchemaTypePtr base; |
| 11813 | /* |
| 11814 | * 1 If the {base type definition} is a complex type definition, |
| 11815 | * then all of the following must be true: |
| 11816 | */ |
| 11817 | base = type->baseType; |
| 11818 | if (base == NULL) { |
| 11819 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 11820 | XML_SCHEMAP_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 11821 | NULL, type, NULL, |
| 11822 | "Internal error: xmlSchemaCheckCOSCTExtends, " |
| 11823 | "the complex type '%s' has no base type", type->name); |
| 11824 | return (-1); |
| 11825 | } |
| 11826 | if (base->type == XML_SCHEMA_TYPE_COMPLEX) { |
| 11827 | /* |
| 11828 | * 1.1 The {final} of the {base type definition} must not |
| 11829 | * contain extension. |
| 11830 | */ |
| 11831 | if (base->flags & XML_SCHEMAS_TYPE_FINAL_EXTENSION) { |
| 11832 | xmlSchemaPCustomErr(ctxt, |
| 11833 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
| 11834 | NULL, type, NULL, |
| 11835 | "The 'final' of the base type definition " |
| 11836 | "contains extension", NULL); |
| 11837 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
| 11838 | } |
| 11839 | /* |
| 11840 | * 1.2 Its {attribute uses} must be a subset of the {attribute uses} |
| 11841 | * of the complex type definition itself, that is, for every attribute |
| 11842 | * use in the {attribute uses} of the {base type definition}, there |
| 11843 | * must be an attribute use in the {attribute uses} of the complex |
| 11844 | * type definition itself whose {attribute declaration} has the same |
| 11845 | * {name}, {target namespace} and {type definition} as its attribute |
| 11846 | * declaration |
| 11847 | * |
| 11848 | * NOTE: This will be already satisfied by the way the attribute uses |
| 11849 | * are extended in xmlSchemaBuildAttributeValidation; thus this check |
| 11850 | * is not needed. |
| 11851 | */ |
| 11852 | |
| 11853 | /* |
| 11854 | * 1.3 If it has an {attribute wildcard}, the complex type definition |
| 11855 | * must also have one, and the base type definition's {attribute |
| 11856 | * wildcard}'s {namespace constraint} must be a subset of the complex |
| 11857 | * type definition's {attribute wildcard}'s {namespace constraint}, |
| 11858 | * as defined by Wildcard Subset (§3.10.6). |
| 11859 | * |
| 11860 | * This is already checked in xmlSchemaBuildAttributeValidation; thus |
| 11861 | * this check is not needed. |
| 11862 | */ |
| 11863 | |
| 11864 | /* |
| 11865 | * 1.4 One of the following must be true: |
| 11866 | * |
| 11867 | * 1.4.1 The {content type} of the {base type definition} and the |
| 11868 | * {content type} of the complex type definition itself must be the same |
| 11869 | * simple type definition |
| 11870 | */ |
| 11871 | |
| 11872 | |
| 11873 | |
| 11874 | } else { |
| 11875 | /* |
| 11876 | * 2 If the {base type definition} is a simple type definition, |
| 11877 | * then all of the following must be true: |
| 11878 | */ |
| 11879 | /* |
| 11880 | * 2.1 The {content type} must be the same simple type definition. |
| 11881 | */ |
| 11882 | /* |
| 11883 | * 2.2 The {final} of the {base type definition} must not contain |
| 11884 | * extension |
| 11885 | */ |
| 11886 | } |
| 11887 | |
| 11888 | } |
| 11889 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11890 | static int |
| 11891 | xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt, |
| 11892 | xmlSchemaTypePtr type) |
| 11893 | { |
| 11894 | xmlSchemaTypePtr base, content; |
| 11895 | int OK = 0; |
| 11896 | |
| 11897 | /* |
| 11898 | * TODO: Adjust the error codes here, as I used |
| 11899 | * XML_SCHEMAP_SRC_CT_1 only yet. |
| 11900 | */ |
| 11901 | /* |
| 11902 | * Schema Representation Constraint: |
| 11903 | * Complex Type Definition Representation OK |
| 11904 | */ |
| 11905 | base = type->baseType; |
| 11906 | if (base == NULL) { |
| 11907 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, NULL, type, NULL, |
| 11908 | "Internal error: xmlSchemaCheckSRCCT, '%s', no base type", |
| 11909 | type->name); |
| 11910 | return (-1); |
| 11911 | } |
| 11912 | |
| 11913 | if (type->subtypes != NULL) { |
| 11914 | if (type->subtypes->type == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
| 11915 | if IS_COMPLEX_TYPE(base) { |
| 11916 | /* |
| 11917 | * 1 If the <complexContent> alternative is chosen, the type definition |
| 11918 | * ·resolved· to by the ·actual value· of the base [attribute] |
| 11919 | * must be a complex type definition; |
| 11920 | */ |
| 11921 | xmlSchemaPCustomErr(ctxt, |
| 11922 | XML_SCHEMAP_SRC_CT_1, |
| 11923 | NULL, type, NULL, |
| 11924 | "The base type is not a complex type", NULL); |
| 11925 | return (XML_SCHEMAP_SRC_CT_1); |
| 11926 | } |
| 11927 | } else if (type->subtypes->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT) { |
| 11928 | |
| 11929 | if IS_SIMPLE_TYPE(base) { |
| 11930 | if (type->flags & |
| 11931 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
| 11932 | /* |
| 11933 | * 2.1.3 only if the <extension> alternative is also |
| 11934 | * chosen, a simple type definition. |
| 11935 | */ |
| 11936 | /* TODO: Change error code to ..._SRC_CT_2_1_3. */ |
| 11937 | xmlSchemaPCustomErr(ctxt, |
| 11938 | XML_SCHEMAP_SRC_CT_1, |
| 11939 | NULL, type, NULL, |
| 11940 | "A complex type (simple content) cannot restrict " |
| 11941 | "an other simple type", |
| 11942 | NULL); |
| 11943 | return (XML_SCHEMAP_SRC_CT_1); |
| 11944 | } |
| 11945 | OK = 1; |
| 11946 | |
| 11947 | } else { /* if IS_SIMPLE_TYPE(base) */ |
| 11948 | if (base->contentType = XML_SCHEMA_CONTENT_MIXED) { |
| 11949 | /* |
| 11950 | * 2.1.2 only if the <restriction> alternative is also |
| 11951 | * chosen, a complex type definition whose {content type} |
| 11952 | * is mixed and a particle emptyable. |
| 11953 | */ |
| 11954 | /* |
| 11955 | * FIXME TODO: Check for *empiable particle* is missing. |
| 11956 | */ |
| 11957 | if ((type->flags & |
| 11958 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) == 0) { |
| 11959 | xmlSchemaPCustomErr(ctxt, |
| 11960 | XML_SCHEMAP_SRC_CT_1, |
| 11961 | NULL, type, NULL, |
| 11962 | "A complex type (simple content) cannot " |
| 11963 | "extend an other complex type which has a " |
| 11964 | "content type of: 'mixed' and emptiable particle", |
| 11965 | NULL); |
| 11966 | return (XML_SCHEMAP_SRC_CT_1); |
| 11967 | } |
| 11968 | /* |
| 11969 | * NOTE: This will be fired as well, if the base type |
| 11970 | * is *'anyType'*. |
| 11971 | * NOTE: type->subtypes->subtypes will be the |
| 11972 | * <restriction> item. |
| 11973 | */ |
| 11974 | if (type->subtypes->subtypes == NULL) { |
| 11975 | /* Yes, this is paranoid programming. */ |
| 11976 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, |
| 11977 | NULL, type, NULL, |
| 11978 | "Internal error: xmlSchemaCheckSRCCT, " |
| 11979 | "'%s', <simpleContent> has no <restriction>", |
| 11980 | type->name); |
| 11981 | return (-1); |
| 11982 | } |
| 11983 | /* |
| 11984 | * 2.2 If clause 2.1.2 above is satisfied, then there |
| 11985 | * must be a <simpleType> among the [children] of |
| 11986 | * <restriction>. |
| 11987 | */ |
| 11988 | if (type->subtypes->subtypes->type != |
| 11989 | XML_SCHEMA_TYPE_SIMPLE) { |
| 11990 | /* TODO: Change error code to ..._SRC_CT_2_2. */ |
| 11991 | xmlSchemaPCustomErr(ctxt, |
| 11992 | XML_SCHEMAP_SRC_CT_1, |
| 11993 | NULL, type, NULL, |
| 11994 | "A <simpleType> is expected among the children " |
| 11995 | "of <restriction>", NULL); |
| 11996 | return (XML_SCHEMAP_SRC_CT_1); |
| 11997 | } |
| 11998 | OK = 1; |
| 11999 | } else { /* if (base->contentType = XML_SCHEMA_CONTENT_MIXED)*/ |
| 12000 | /* |
| 12001 | * 2.1.1 a complex type definition whose {content type} is a |
| 12002 | * simple type definition; |
| 12003 | */ |
| 12004 | if (base->contentType == XML_SCHEMA_CONTENT_ELEMENTS) { |
| 12005 | xmlSchemaPCustomErr(ctxt, |
| 12006 | XML_SCHEMAP_SRC_CT_1, |
| 12007 | NULL, type, NULL, |
| 12008 | "A complex type (simple content) cannot " |
| 12009 | "be derived from the complex type '%s'", |
| 12010 | base->name); |
| 12011 | return (XML_SCHEMAP_SRC_CT_1); |
| 12012 | } |
| 12013 | content = base->contentTypeDef; |
| 12014 | if (content == NULL) { |
| 12015 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, |
| 12016 | NULL, type, NULL, |
| 12017 | "Internal error: xmlSchemaCheckSRCCT, " |
| 12018 | "'%s', base type has no content type", |
| 12019 | type->name); |
| 12020 | return (-1); |
| 12021 | } |
| 12022 | if (content->type != XML_SCHEMA_TYPE_SIMPLE) { |
| 12023 | xmlSchemaPCustomErr(ctxt, |
| 12024 | XML_SCHEMAP_SRC_CT_1, |
| 12025 | NULL, type, NULL, |
| 12026 | "A complex type (simple content) cannot " |
| 12027 | "be derived from the complex type '%s'", |
| 12028 | base->name); |
| 12029 | return (XML_SCHEMAP_SRC_CT_1); |
| 12030 | } |
| 12031 | } |
| 12032 | } |
| 12033 | } |
| 12034 | } |
| 12035 | /* |
| 12036 | * TODO: 3 The corresponding complex type definition component must |
| 12037 | * satisfy the conditions set out in Constraints on Complex Type |
| 12038 | * Definition Schema Components (§3.4.6); |
| 12039 | * |
| 12040 | * TODO: 4 If clause 2.2.1 or clause 2.2.2 in the correspondence specification |
| 12041 | * above for {attribute wildcard} is satisfied, the intensional |
| 12042 | * intersection must be expressible, as defined in Attribute Wildcard |
| 12043 | * Intersection (§3.10.6). |
| 12044 | */ |
| 12045 | |
| 12046 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12047 | #endif |
| 12048 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12049 | /** |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 12050 | * xmlSchemaGroupDefFixup: |
| 12051 | * @typeDecl: the schema model group definition |
| 12052 | * @ctxt: the schema parser context |
| 12053 | * |
| 12054 | * Fixes model group definitions. |
| 12055 | */ |
| 12056 | static void |
| 12057 | xmlSchemaGroupDefFixup(xmlSchemaTypePtr group, |
| 12058 | xmlSchemaParserCtxtPtr ctxt, |
| 12059 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 12060 | { |
| 12061 | group->contentType = XML_SCHEMA_CONTENT_ELEMENTS; |
| 12062 | if ((group->ref != NULL) && (group->subtypes == NULL)) { |
| 12063 | xmlSchemaTypePtr groupDef; |
| 12064 | /* |
| 12065 | * Resolve the reference. |
| 12066 | */ |
| 12067 | groupDef = xmlSchemaGetGroup(ctxt->schema, group->ref, |
| 12068 | group->refNs); |
| 12069 | if (groupDef == NULL) { |
| 12070 | xmlSchemaPResCompAttrErr(ctxt, |
| 12071 | XML_SCHEMAP_SRC_RESOLVE, |
| 12072 | NULL, group, NULL, |
| 12073 | "ref", group->ref, group->refNs, |
| 12074 | XML_SCHEMA_TYPE_GROUP, NULL); |
| 12075 | return; |
| 12076 | } |
| 12077 | group->subtypes = groupDef; |
| 12078 | } |
| 12079 | } |
| 12080 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12081 | #if 0 /* Enable when the content type will be computed. */ |
| 12082 | static int |
| 12083 | xmlSchemaComputeContentType(xmlSchemaParserCtxtPtr ctxt, |
| 12084 | xmlSchemaTypePtr type) |
| 12085 | { |
| 12086 | xmlSchemaTypePtr base, res = NULL; |
| 12087 | |
| 12088 | base = type->baseType; |
| 12089 | if (base == NULL) { |
| 12090 | xmlSchemaPCustomErr(ctxt, |
| 12091 | XML_SCHEMAP_INTERNAL, |
| 12092 | NULL, type, NULL, |
| 12093 | "Internal error: xmlSchemaGetContentType, " |
| 12094 | "the complex type '%s' has no base type", type->name); |
| 12095 | return (-1); |
| 12096 | } |
| 12097 | if (IS_ANYTYPE(base) || (type->subtypes->type == |
| 12098 | XML_SCHEMA_TYPE_COMPLEX_CONTENT)) { |
| 12099 | xmlSchemaTypePtr start; |
| 12100 | /* |
| 12101 | * Effective 'mixed'. |
| 12102 | */ |
| 12103 | if (type->flags & XML_SCHEMAS_TYPE_MIXED) |
| 12104 | type->contentType = XML_SCHEMA_CONTENT_MIXED; |
| 12105 | /* |
| 12106 | * Effective content. |
| 12107 | */ |
| 12108 | if (IS_ANYTYPE(base)) |
| 12109 | start = type; |
| 12110 | else |
| 12111 | start = type->subtypes; |
| 12112 | |
| 12113 | } else { /* if XML_SCHEMA_TYPE_COMPLEX_CONTENT */ |
| 12114 | xmlSchemaTypePtr baseContentItem; |
| 12115 | |
| 12116 | /* |
| 12117 | * Complex type with simple content. |
| 12118 | */ |
| 12119 | if IS_COMPLEX_TYPE(base) { |
| 12120 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
| 12121 | /* |
| 12122 | * Summary: a complex type (simple content) can *restrict* |
| 12123 | * a complex type with the following content type: |
| 12124 | * 1. 'mixed' and an emptiable particle |
| 12125 | * 2. simple type |
| 12126 | */ |
| 12127 | if (base->contentType == XML_SCHEMA_CONTENT_MIXED) { |
| 12128 | /* |
| 12129 | * 2 if the {content type} of the base type is mixed and a |
| 12130 | * particle which is ·emptiable·, |
| 12131 | * [...] |
| 12132 | * then starting from the simple type definition |
| 12133 | * corresponding to the <simpleType> among the [children] |
| 12134 | * of <restriction> (**which must be present**) |
| 12135 | * |
| 12136 | * FIXME TODO: Handle "emptiable particle". |
| 12137 | */ |
| 12138 | res = type->subtypes->subtypes; |
| 12139 | if (res == NULL) { |
| 12140 | xmlSchemaPCustomErr(ctxt, |
| 12141 | XML_SCHEMAP_INTERNAL, |
| 12142 | NULL, type, NULL, |
| 12143 | "Internal error: xmlSchemaGetContentType, " |
| 12144 | "CT '%s' (restricting): <simpleContent> has no " |
| 12145 | "<restriction>", |
| 12146 | type->name); |
| 12147 | return (-1); |
| 12148 | } |
| 12149 | |
| 12150 | res->subtypes; |
| 12151 | if (res == NULL) { |
| 12152 | xmlSchemaPCustomErr(ctxt, |
| 12153 | XML_SCHEMAP_INTERNAL, |
| 12154 | NULL, type, NULL, |
| 12155 | "Internal error: xmlSchemaGetContentType, " |
| 12156 | "CT '%s' (restricting): <restriction> has no " |
| 12157 | "mandatory <simpleType>", |
| 12158 | type->name); |
| 12159 | return (-1); |
| 12160 | } |
| 12161 | } else { |
| 12162 | baseContentItem = base->contentTypeDef; |
| 12163 | if (baseContentItem == NULL) { |
| 12164 | xmlSchemaPCustomErr(ctxt, |
| 12165 | XML_SCHEMAP_INTERNAL, |
| 12166 | NULL, type, NULL, |
| 12167 | "Internal error: xmlSchemaGetContentType, " |
| 12168 | "CT '%s' (restricting), the base type has no " |
| 12169 | "content type", type->name); |
| 12170 | return (-1); |
| 12171 | } |
| 12172 | if IS_SIMPLE_TYPE(baseContentItem) { |
| 12173 | /* |
| 12174 | * 1 If the base type is a complex type whose own |
| 12175 | * {content type} is a simple type and the <restriction> |
| 12176 | * alternative is chosen |
| 12177 | */ |
| 12178 | /* type->subtypes->subtypes will be the restriction item.*/ |
| 12179 | res = type->subtypes->subtypes; |
| 12180 | if (res == NULL) { |
| 12181 | xmlSchemaPCustomErr(ctxt, |
| 12182 | XML_SCHEMAP_INTERNAL, |
| 12183 | NULL, type, NULL, |
| 12184 | "Internal error: xmlSchemaGetContentType, " |
| 12185 | "CT '%s' (restricting): <simpleType> has no " |
| 12186 | "<restriction>", type->name); |
| 12187 | return (-1); |
| 12188 | } |
| 12189 | /* |
| 12190 | * 1.1 the simple type definition corresponding to the |
| 12191 | * <simpleType> among the [children] of <restriction>if |
| 12192 | * there is one; |
| 12193 | */ |
| 12194 | res = res->subtypes; |
| 12195 | if (res == NULL) { |
| 12196 | /* |
| 12197 | * 1.2 otherwise the {content type} |
| 12198 | * of the base type . |
| 12199 | */ |
| 12200 | res = baseContentItem; |
| 12201 | } |
| 12202 | } |
| 12203 | } |
| 12204 | /* |
| 12205 | * SPECIAL TODO: If *restricting* the spec wants us to |
| 12206 | * create an *additional* simple type which restricts the |
| 12207 | * located simple type; we won't do this yet, and look how |
| 12208 | * far we get with it. |
| 12209 | */ |
| 12210 | } else { /* if XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION */ |
| 12211 | /* |
| 12212 | * Summary: a complex type (simple content) can *extend* |
| 12213 | * only a complex base with a simple type as content. |
| 12214 | */ |
| 12215 | /* |
| 12216 | * 3 If the type definition ·resolved· to by the ·actual |
| 12217 | * value· of the base [attribute] is a complex type |
| 12218 | * definition (whose own {content type} *must be* a simple |
| 12219 | * type definition, see below) and the *<extension>* |
| 12220 | * alternative is chosen, then the {content type} of that |
| 12221 | * complex type definition; |
| 12222 | */ |
| 12223 | res = base->contentTypeDef; |
| 12224 | if (res == NULL) { |
| 12225 | xmlSchemaPCustomErr(ctxt, |
| 12226 | XML_SCHEMAP_INTERNAL, |
| 12227 | NULL, type, NULL, |
| 12228 | "Internal error: xmlSchemaGetContentType, " |
| 12229 | "CT '%s' (extending), the base type has no content " |
| 12230 | "type", type->name); |
| 12231 | return (-1); |
| 12232 | } |
| 12233 | if (! IS_SIMPLE_TYPE(res)) { |
| 12234 | xmlSchemaPCustomErr(ctxt, |
| 12235 | XML_SCHEMAP_INTERNAL, |
| 12236 | NULL, type, NULL, |
| 12237 | "Internal error: xmlSchemaGetContentType, " |
| 12238 | "CT '%s' (extending), the content type of the " |
| 12239 | "base is not a simple type", type->name); |
| 12240 | return (-1); |
| 12241 | } |
| 12242 | } |
| 12243 | } else /* if IS_COMPLEX_TYPE(base) */ |
| 12244 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) { |
| 12245 | /* |
| 12246 | * 4 otherwise (the type definition ·resolved· to by the |
| 12247 | * ·actual value· of the base [attribute] is a simple type |
| 12248 | * definition and the <extension> alternative is chosen), |
| 12249 | * then that simple type definition. |
| 12250 | */ |
| 12251 | res = base; |
| 12252 | } |
| 12253 | type->contentTypeDef = res; |
| 12254 | if (res == NULL) { |
| 12255 | xmlSchemaPCustomErr(ctxt, |
| 12256 | XML_SCHEMAP_INTERNAL, |
| 12257 | NULL, type, NULL, |
| 12258 | "Internal error: xmlSchemaGetContentType, " |
| 12259 | "'%s', the content type could not be determined", |
| 12260 | type->name); |
| 12261 | return (-1); |
| 12262 | } |
| 12263 | |
| 12264 | } |
| 12265 | |
| 12266 | } |
| 12267 | #endif |
| 12268 | |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 12269 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 12270 | * xmlSchemaTypeFixup: |
| 12271 | * @typeDecl: the schema type definition |
| 12272 | * @ctxt: the schema parser context |
| 12273 | * |
| 12274 | * Fixes the content model of the type. |
| 12275 | */ |
| 12276 | static void |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12277 | xmlSchemaTypeFixup(xmlSchemaTypePtr item, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12278 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 12279 | { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12280 | xmlSchemaTypePtr ctxtType; |
| 12281 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12282 | if (item == NULL) |
Daniel Veillard | 82bbbd4 | 2003-05-11 20:16:09 +0000 | [diff] [blame] | 12283 | return; |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 12284 | /* |
| 12285 | * Do not allow the following types to be typefixed, prior to |
| 12286 | * the corresponding simple/complex types. |
| 12287 | */ |
| 12288 | if (ctxt->ctxtType == NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12289 | switch (item->type) { |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 12290 | case XML_SCHEMA_TYPE_SIMPLE_CONTENT: |
| 12291 | case XML_SCHEMA_TYPE_COMPLEX_CONTENT: |
| 12292 | case XML_SCHEMA_TYPE_UNION: |
| 12293 | case XML_SCHEMA_TYPE_RESTRICTION: |
| 12294 | case XML_SCHEMA_TYPE_EXTENSION: |
| 12295 | return; |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12296 | default: |
| 12297 | break; |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 12298 | } |
| 12299 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 12300 | if (name == NULL) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12301 | name = item->name; |
| 12302 | if (item->contentType == XML_SCHEMA_CONTENT_UNKNOWN) { |
| 12303 | switch (item->type) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12304 | case XML_SCHEMA_TYPE_SIMPLE_CONTENT:{ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12305 | if (item->subtypes != NULL) { |
| 12306 | if (item->subtypes->contentType == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12307 | XML_SCHEMA_CONTENT_UNKNOWN) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12308 | xmlSchemaTypeFixup(item->subtypes, ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12309 | NULL); |
| 12310 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12311 | item->contentType = |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12312 | XML_SCHEMA_CONTENT_SIMPLE; |
| 12313 | /* item->subtypes->contentType; */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12314 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12315 | break; |
| 12316 | } |
| 12317 | case XML_SCHEMA_TYPE_RESTRICTION:{ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12318 | xmlSchemaTypePtr base = NULL; |
| 12319 | |
| 12320 | ctxt->ctxtType->flags |= |
| 12321 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12322 | if (item->baseType != NULL) |
| 12323 | base = item->baseType; |
| 12324 | else if (item->base != NULL) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12325 | base = |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12326 | xmlSchemaGetType(ctxt->schema, item->base, |
| 12327 | item->baseNs); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12328 | if (base == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12329 | xmlSchemaPResCompAttrErr(ctxt, |
| 12330 | XML_SCHEMAP_SRC_RESOLVE, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12331 | NULL, NULL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12332 | (xmlNodePtr) xmlSchemaGetPropNode(item->node, "base"), |
| 12333 | "base", item->base, item->baseNs, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12334 | XML_SCHEMA_TYPE_BASIC, "type definition"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12335 | } else if (base->contentType == |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12336 | XML_SCHEMA_CONTENT_UNKNOWN) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12337 | xmlSchemaTypeFixup(base, ctxt, NULL); |
| 12338 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12339 | } |
| 12340 | ctxt->ctxtType->baseType = base; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12341 | if (ctxt->ctxtType->type == XML_SCHEMA_TYPE_COMPLEX) { |
| 12342 | /* |
| 12343 | * ComplexType restriction. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12344 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12345 | /* |
| 12346 | * Content type. |
| 12347 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12348 | if (item->subtypes == NULL) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12349 | /* 1.1.1 */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12350 | item->contentType = XML_SCHEMA_CONTENT_EMPTY; |
| 12351 | else if ((item->subtypes->subtypes == NULL) && |
| 12352 | ((item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12353 | XML_SCHEMA_TYPE_ALL) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12354 | || (item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12355 | XML_SCHEMA_TYPE_SEQUENCE))) |
| 12356 | /* 1.1.2 */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12357 | item->contentType = XML_SCHEMA_CONTENT_EMPTY; |
| 12358 | else if ((item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12359 | XML_SCHEMA_TYPE_CHOICE) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12360 | && (item->subtypes->subtypes == NULL)) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12361 | /* 1.1.3 */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12362 | item->contentType = XML_SCHEMA_CONTENT_EMPTY; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12363 | else { |
| 12364 | /* 1.2 and 2.X are applied at the other layer */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12365 | item->contentType = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12366 | XML_SCHEMA_CONTENT_ELEMENTS; |
| 12367 | } |
| 12368 | } else { |
| 12369 | /* |
| 12370 | * SimpleType restriction. |
| 12371 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12372 | /* TODO: Nothing? */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12373 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12374 | break; |
| 12375 | } |
| 12376 | case XML_SCHEMA_TYPE_EXTENSION:{ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12377 | xmlSchemaTypePtr base = NULL; |
| 12378 | xmlSchemaContentType explicitContentType; |
| 12379 | |
| 12380 | /* |
| 12381 | * An extension does exist on a complexType only. |
| 12382 | */ |
| 12383 | ctxt->ctxtType->flags |= |
| 12384 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12385 | if (item->recurse) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12386 | /* TODO: The word "recursive" should be changed to "circular" here. */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12387 | xmlSchemaPCustomErr(ctxt, |
| 12388 | XML_SCHEMAP_UNKNOWN_BASE_TYPE, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12389 | NULL, item, item->node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12390 | "This item is circular", NULL); |
Daniel Veillard | 2582a33 | 2004-04-18 19:49:46 +0000 | [diff] [blame] | 12391 | return; |
| 12392 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12393 | if (item->base != NULL) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12394 | base = |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12395 | xmlSchemaGetType(ctxt->schema, item->base, |
| 12396 | item->baseNs); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12397 | if (base == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12398 | xmlSchemaPResCompAttrErr(ctxt, |
| 12399 | XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12400 | NULL, item, item->node, |
| 12401 | "base", item->base, item->baseNs, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12402 | XML_SCHEMA_TYPE_BASIC, "type definition"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12403 | } else if (base->contentType == |
| 12404 | XML_SCHEMA_CONTENT_UNKNOWN) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12405 | item->recurse = 1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12406 | xmlSchemaTypeFixup(base, ctxt, NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12407 | item->recurse = 0; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12408 | } |
| 12409 | /* |
| 12410 | * The type definition ·resolved· to by the ·actual |
| 12411 | * value· of the base [attribute] |
| 12412 | */ |
| 12413 | ctxt->ctxtType->baseType = base; |
| 12414 | /* |
| 12415 | * TODO: This one is still needed for computation of |
| 12416 | * the content model by xmlSchemaBuildAContentModel. |
| 12417 | * Try to get rid of it. |
| 12418 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12419 | item->baseType = base; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12420 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12421 | if ((item->subtypes != NULL) && |
| 12422 | (item->subtypes->contentType == XML_SCHEMA_CONTENT_UNKNOWN)) |
| 12423 | xmlSchemaTypeFixup(item->subtypes, ctxt, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12424 | |
| 12425 | explicitContentType = XML_SCHEMA_CONTENT_ELEMENTS; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12426 | if (item->subtypes == NULL) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12427 | /* 1.1.1 */ |
| 12428 | explicitContentType = XML_SCHEMA_CONTENT_EMPTY; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12429 | else if ((item->subtypes->subtypes == NULL) && |
| 12430 | ((item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12431 | XML_SCHEMA_TYPE_ALL) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12432 | || (item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12433 | XML_SCHEMA_TYPE_SEQUENCE))) |
| 12434 | /* 1.1.2 */ |
| 12435 | explicitContentType = XML_SCHEMA_CONTENT_EMPTY; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12436 | else if ((item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12437 | XML_SCHEMA_TYPE_CHOICE) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12438 | && (item->subtypes->subtypes == NULL)) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12439 | /* 1.1.3 */ |
| 12440 | explicitContentType = XML_SCHEMA_CONTENT_EMPTY; |
| 12441 | if (base != NULL) { |
| 12442 | /* It will be reported later, if the base is missing. */ |
| 12443 | if (explicitContentType == XML_SCHEMA_CONTENT_EMPTY) { |
| 12444 | /* 2.1 */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12445 | item->contentType = base->contentType; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12446 | } else if (base->contentType == |
| 12447 | XML_SCHEMA_CONTENT_EMPTY) { |
| 12448 | /* 2.2 imbitable ! */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12449 | item->contentType = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12450 | XML_SCHEMA_CONTENT_ELEMENTS; |
| 12451 | } else { |
| 12452 | /* 2.3 imbitable pareil ! */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12453 | item->contentType = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12454 | XML_SCHEMA_CONTENT_ELEMENTS; |
| 12455 | } |
| 12456 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12457 | break; |
| 12458 | } |
| 12459 | case XML_SCHEMA_TYPE_COMPLEX:{ |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 12460 | ctxtType = ctxt->ctxtType; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12461 | ctxt->ctxtType = item; |
| 12462 | /* |
| 12463 | * Start with an empty content-type type. |
| 12464 | */ |
| 12465 | if (item->subtypes == NULL) |
| 12466 | item->contentType = XML_SCHEMA_CONTENT_EMPTY; |
| 12467 | |
| 12468 | if ((item->subtypes == NULL) || |
| 12469 | ((item->subtypes->type != |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12470 | XML_SCHEMA_TYPE_SIMPLE_CONTENT) && |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12471 | (item->subtypes->type != |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12472 | XML_SCHEMA_TYPE_COMPLEX_CONTENT))) { |
| 12473 | /* |
| 12474 | * This case is understood as shorthand for complex |
| 12475 | * content restricting the ur-type definition, and |
| 12476 | * the details of the mappings should be modified as |
| 12477 | * necessary. |
| 12478 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12479 | item->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 12480 | item->flags |= |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12481 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12482 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12483 | * Assume that we inherit the content-type type |
| 12484 | * from 'anyType', which is 'mixed' and a particle |
| 12485 | * emptiable. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12486 | */ |
| 12487 | item->contentType = item->baseType->contentType; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12488 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12489 | /* |
| 12490 | * Fixup the sub components. |
| 12491 | */ |
| 12492 | if ((item->subtypes != NULL) && |
| 12493 | (item->subtypes->contentType == |
| 12494 | XML_SCHEMA_CONTENT_UNKNOWN)) { |
| 12495 | xmlSchemaTypeFixup(item->subtypes, ctxt, NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12496 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12497 | if (item->flags & XML_SCHEMAS_TYPE_MIXED) { |
| 12498 | item->contentType = XML_SCHEMA_CONTENT_MIXED; |
| 12499 | } else if (item->subtypes != NULL) { |
| 12500 | /* |
| 12501 | * Use the content-type type of the model groups |
| 12502 | * defined, if 'mixed' is not set. If 'mixed' is set |
| 12503 | * it will expand the content-type by allowing character |
| 12504 | * content to appear. |
| 12505 | */ |
| 12506 | item->contentType = |
| 12507 | item->subtypes->contentType; |
| 12508 | } |
| 12509 | xmlSchemaBuildAttributeValidation(ctxt, item); |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 12510 | xmlSchemaCheckDefaults(item, ctxt, item->name); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 12511 | ctxt->ctxtType = ctxtType; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12512 | break; |
| 12513 | } |
| 12514 | case XML_SCHEMA_TYPE_COMPLEX_CONTENT:{ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12515 | if (item->subtypes == NULL) { |
| 12516 | item->contentType = XML_SCHEMA_CONTENT_EMPTY; |
| 12517 | if (item->flags & XML_SCHEMAS_TYPE_MIXED) |
| 12518 | item->contentType = |
Daniel Veillard | 1aefc86 | 2004-03-04 11:40:48 +0000 | [diff] [blame] | 12519 | XML_SCHEMA_CONTENT_MIXED; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12520 | } else { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12521 | if (item->flags & XML_SCHEMAS_TYPE_MIXED) { |
| 12522 | item->contentType = |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12523 | XML_SCHEMA_CONTENT_MIXED; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12524 | } else { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12525 | xmlSchemaTypeFixup(item->subtypes, ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12526 | NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12527 | if (item->subtypes != NULL) |
| 12528 | item->contentType = |
| 12529 | item->subtypes->contentType; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12530 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12531 | /* |
| 12532 | * Removed due to implementation of the build of attribute uses. |
| 12533 | */ |
| 12534 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12535 | if (item->attributes == NULL) |
| 12536 | item->attributes = |
| 12537 | item->subtypes->attributes; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 12538 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12539 | } |
| 12540 | break; |
| 12541 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12542 | case XML_SCHEMA_TYPE_SIMPLE: |
| 12543 | /* |
| 12544 | * Simple Type Definition Schema Component |
| 12545 | * |
| 12546 | */ |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 12547 | ctxtType = ctxt->ctxtType; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12548 | item->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
| 12549 | if (item->subtypes->contentType == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12550 | XML_SCHEMA_CONTENT_UNKNOWN) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12551 | ctxt->ctxtType = item; |
| 12552 | xmlSchemaTypeFixup(item->subtypes, ctxt, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12553 | } |
| 12554 | /* Fixup base type */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12555 | if ((item->baseType != NULL) && |
| 12556 | (item->baseType->contentType == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12557 | XML_SCHEMA_CONTENT_UNKNOWN)) { |
| 12558 | /* OPTIMIZE: Actually this one will never by hit, since |
| 12559 | * the base type is already type-fixed in <restriction>. |
| 12560 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12561 | ctxt->ctxtType = item; |
| 12562 | xmlSchemaTypeFixup(item->baseType, ctxt, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12563 | } |
| 12564 | /* Base type: |
| 12565 | * 2 If the <list> or <union> alternative is chosen, |
| 12566 | * then the ·simple ur-type definition·. |
| 12567 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12568 | if (item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12569 | XML_SCHEMA_TYPE_LIST) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12570 | item->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 12571 | item->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST; |
| 12572 | } else if (item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12573 | XML_SCHEMA_TYPE_UNION) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12574 | item->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 12575 | item->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION; |
| 12576 | } else if (item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12577 | XML_SCHEMA_TYPE_RESTRICTION) { |
| 12578 | xmlSchemaFacetLinkPtr facet, cur, last = NULL; |
| 12579 | |
| 12580 | /* |
| 12581 | * Variety |
| 12582 | * If the <restriction> alternative is chosen, then the |
| 12583 | * {variety} of the {base type definition}. |
| 12584 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12585 | if (item->baseType != NULL) { |
| 12586 | if (item->baseType->flags & |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12587 | XML_SCHEMAS_TYPE_VARIETY_ATOMIC) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12588 | item->flags |= XML_SCHEMAS_TYPE_VARIETY_ATOMIC; |
| 12589 | else if (item->baseType->flags & |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12590 | XML_SCHEMAS_TYPE_VARIETY_LIST) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12591 | item->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST; |
| 12592 | else if (item->baseType->flags & |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12593 | XML_SCHEMAS_TYPE_VARIETY_UNION) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12594 | item->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12595 | /* |
| 12596 | * Schema Component Constraint: Simple Type Restriction |
| 12597 | * (Facets) |
| 12598 | * NOTE: Satisfaction of 1 and 2 arise from the fixup |
| 12599 | * applied beforehand. |
| 12600 | * |
| 12601 | * 3 The {facets} of R are the union of S and the {facets} |
| 12602 | * of B, eliminating duplicates. To eliminate duplicates, |
| 12603 | * when a facet of the same kind occurs in both S and the |
| 12604 | * {facets} of B, the one in the {facets} of B is not |
| 12605 | * included, with the exception of enumeration and pattern |
| 12606 | * facets, for which multiple occurrences with distinct values |
| 12607 | * are allowed. |
| 12608 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12609 | if (item->baseType->facetSet != NULL) { |
| 12610 | last = item->facetSet; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12611 | if (last != NULL) |
| 12612 | while (last->next != NULL) |
| 12613 | last = last->next; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12614 | cur = item->baseType->facetSet; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12615 | for (; cur != NULL; cur = cur->next) { |
| 12616 | /* |
| 12617 | * Base patterns won't be add here: |
| 12618 | * they are ORed in a type and |
| 12619 | * ANDed in derived types. This will |
| 12620 | * happed at validation level by |
| 12621 | * walking the base axis of the type. |
| 12622 | */ |
| 12623 | if (cur->facet->type == |
| 12624 | XML_SCHEMA_FACET_PATTERN) |
| 12625 | continue; |
| 12626 | facet = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12627 | if ((item->facetSet != NULL) && |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12628 | (cur->facet->type != |
| 12629 | XML_SCHEMA_FACET_PATTERN) && |
| 12630 | (cur->facet->type != |
| 12631 | XML_SCHEMA_FACET_ENUMERATION)) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12632 | facet = item->facetSet; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12633 | do { |
| 12634 | if (cur->facet->type == |
| 12635 | facet->facet->type) |
| 12636 | break; |
| 12637 | facet = facet->next; |
| 12638 | } while (facet != NULL); |
| 12639 | } |
| 12640 | if (facet == NULL) { |
| 12641 | facet = (xmlSchemaFacetLinkPtr) |
| 12642 | xmlMalloc(sizeof(xmlSchemaFacetLink)); |
| 12643 | if (facet == NULL) { |
| 12644 | xmlSchemaPErrMemory(ctxt, |
| 12645 | "fixing simpleType", NULL); |
| 12646 | return; |
| 12647 | } |
| 12648 | facet->facet = cur->facet; |
| 12649 | facet->next = NULL; |
| 12650 | if (last == NULL) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12651 | item->facetSet = facet; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12652 | else |
| 12653 | last->next = facet; |
| 12654 | last = facet; |
| 12655 | } |
| 12656 | } |
| 12657 | } |
| 12658 | } |
| 12659 | } |
| 12660 | /* |
| 12661 | * Check constraints. |
| 12662 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12663 | xmlSchemaCheckSRCSimpleType(ctxt, item); |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 12664 | xmlSchemaCheckDefaults(item, ctxt, item->name); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 12665 | ctxt->ctxtType = ctxtType; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12666 | break; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 12667 | case XML_SCHEMA_TYPE_SEQUENCE: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12668 | case XML_SCHEMA_TYPE_ALL: |
| 12669 | case XML_SCHEMA_TYPE_CHOICE: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12670 | item->contentType = XML_SCHEMA_CONTENT_ELEMENTS; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12671 | break; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 12672 | case XML_SCHEMA_TYPE_GROUP: |
| 12673 | /* |
| 12674 | * TODO: Handling was moved to xmlSchemaGroupDefFixup. |
| 12675 | */ |
| 12676 | break; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12677 | case XML_SCHEMA_TYPE_LIST: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12678 | xmlSchemaParseListRefFixup(item, ctxt); |
| 12679 | item->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12680 | break; |
| 12681 | case XML_SCHEMA_TYPE_UNION: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12682 | xmlSchemaParseUnionRefCheck(item, ctxt); |
| 12683 | item->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12684 | break; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12685 | case XML_SCHEMA_TYPE_BASIC: |
| 12686 | case XML_SCHEMA_TYPE_ANY: |
| 12687 | case XML_SCHEMA_TYPE_FACET: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12688 | case XML_SCHEMA_TYPE_UR: |
| 12689 | case XML_SCHEMA_TYPE_ELEMENT: |
| 12690 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 12691 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
William M. Brack | 29aa772 | 2004-05-12 00:27:56 +0000 | [diff] [blame] | 12692 | case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12693 | case XML_SCHEMA_TYPE_NOTATION: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12694 | case XML_SCHEMA_FACET_MININCLUSIVE: |
| 12695 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
| 12696 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
| 12697 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
| 12698 | case XML_SCHEMA_FACET_TOTALDIGITS: |
| 12699 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
| 12700 | case XML_SCHEMA_FACET_PATTERN: |
| 12701 | case XML_SCHEMA_FACET_ENUMERATION: |
| 12702 | case XML_SCHEMA_FACET_WHITESPACE: |
| 12703 | case XML_SCHEMA_FACET_LENGTH: |
| 12704 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 12705 | case XML_SCHEMA_FACET_MINLENGTH: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12706 | item->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
| 12707 | if (item->subtypes != NULL) |
| 12708 | xmlSchemaTypeFixup(item->subtypes, ctxt, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12709 | break; |
| 12710 | } |
| 12711 | } |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 12712 | #ifdef DEBUG_TYPE |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12713 | if (item->node != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12714 | xmlGenericError(xmlGenericErrorContext, |
| 12715 | "Type of %s : %s:%d :", name, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12716 | item->node->doc->URL, |
| 12717 | xmlGetLineNo(item->node)); |
Daniel Veillard | decd64d | 2002-04-18 14:41:51 +0000 | [diff] [blame] | 12718 | } else { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12719 | xmlGenericError(xmlGenericErrorContext, "Type of %s :", name); |
Daniel Veillard | decd64d | 2002-04-18 14:41:51 +0000 | [diff] [blame] | 12720 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12721 | switch (item->contentType) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12722 | case XML_SCHEMA_CONTENT_SIMPLE: |
| 12723 | xmlGenericError(xmlGenericErrorContext, "simple\n"); |
| 12724 | break; |
| 12725 | case XML_SCHEMA_CONTENT_ELEMENTS: |
| 12726 | xmlGenericError(xmlGenericErrorContext, "elements\n"); |
| 12727 | break; |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 12728 | case XML_SCHEMA_CONTENT_UNKNOWN: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12729 | xmlGenericError(xmlGenericErrorContext, "unknown !!!\n"); |
| 12730 | break; |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 12731 | case XML_SCHEMA_CONTENT_EMPTY: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12732 | xmlGenericError(xmlGenericErrorContext, "empty\n"); |
| 12733 | break; |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 12734 | case XML_SCHEMA_CONTENT_MIXED: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12735 | xmlGenericError(xmlGenericErrorContext, "mixed\n"); |
| 12736 | break; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12737 | /* Removed, since not used. */ |
| 12738 | /* |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 12739 | case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12740 | xmlGenericError(xmlGenericErrorContext, "mixed or elems\n"); |
| 12741 | break; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12742 | */ |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 12743 | case XML_SCHEMA_CONTENT_BASIC: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12744 | xmlGenericError(xmlGenericErrorContext, "basic\n"); |
| 12745 | break; |
| 12746 | default: |
| 12747 | xmlGenericError(xmlGenericErrorContext, |
| 12748 | "not registered !!!\n"); |
| 12749 | break; |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 12750 | } |
| 12751 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 12752 | } |
| 12753 | |
| 12754 | /** |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 12755 | * xmlSchemaCheckFacet: |
| 12756 | * @facet: the facet |
| 12757 | * @typeDecl: the schema type definition |
| 12758 | * @ctxt: the schema parser context or NULL |
| 12759 | * @name: name of the type |
| 12760 | * |
| 12761 | * Checks the default values types, especially for facets |
| 12762 | * |
| 12763 | * Returns 0 if okay or -1 in cae of error |
| 12764 | */ |
| 12765 | int |
| 12766 | xmlSchemaCheckFacet(xmlSchemaFacetPtr facet, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12767 | xmlSchemaTypePtr typeDecl, |
| 12768 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name) |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 12769 | { |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 12770 | xmlSchemaTypePtr nonNegativeIntegerType = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12771 | int ret = 0, reuseValCtxt = 0; |
| 12772 | |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 12773 | if ((facet == NULL) || (typeDecl == NULL)) |
| 12774 | return(-1); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12775 | /* |
| 12776 | * TODO: will the parser context be given if used from |
| 12777 | * the relaxNG module? |
| 12778 | */ |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 12779 | |
| 12780 | if (nonNegativeIntegerType == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12781 | nonNegativeIntegerType = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12782 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NNINTEGER); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 12783 | } |
| 12784 | switch (facet->type) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12785 | case XML_SCHEMA_FACET_MININCLUSIVE: |
| 12786 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
| 12787 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 12788 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
| 12789 | case XML_SCHEMA_FACET_ENUMERATION: { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12790 | /* |
| 12791 | * Okay we need to validate the value |
| 12792 | * at that point. |
| 12793 | */ |
| 12794 | xmlSchemaValidCtxtPtr vctxt; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12795 | xmlSchemaTypePtr base; |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 12796 | |
| 12797 | /* 4.3.5.5 Constraints on enumeration Schema Components |
| 12798 | * Schema Component Constraint: enumeration valid restriction |
| 12799 | * It is an ·error· if any member of {value} is not in the |
| 12800 | * ·value space· of {base type definition}. |
| 12801 | * |
| 12802 | * minInclusive, maxInclusive, minExclusive, maxExclusive: |
| 12803 | * The value ·must· be in the |
| 12804 | * ·value space· of the ·base type·. |
| 12805 | */ |
| 12806 | /* |
| 12807 | * This function is intended to deliver a compiled value |
| 12808 | * on the facet. In XML Schemas the type holding a facet, |
| 12809 | * cannot be a built-in type. Thus to ensure that other API |
| 12810 | * calls (relaxng) do work, if the given type is a built-in |
| 12811 | * type, we will assume that the given built-in type *is |
| 12812 | * already* the base type. |
| 12813 | */ |
| 12814 | if (typeDecl->type != XML_SCHEMA_TYPE_BASIC) { |
| 12815 | base = typeDecl->baseType; |
| 12816 | if (base == NULL) { |
| 12817 | xmlSchemaPErr(ctxt, typeDecl->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 12818 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 12819 | "Internal error: xmlSchemaCheckFacet, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12820 | "the type '%s' has no base type.\n", |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 12821 | typeDecl->name, NULL); |
| 12822 | return (-1); |
| 12823 | } |
| 12824 | } else |
| 12825 | base = typeDecl; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12826 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12827 | * This avoids perseverative creation of the |
| 12828 | * validation context if a parser context is |
| 12829 | * used. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12830 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12831 | if (ctxt != NULL) { |
| 12832 | reuseValCtxt = 1; |
| 12833 | if (ctxt->vctxt == NULL) { |
| 12834 | if (xmlSchemaCreateVCtxtOnPCtxt(ctxt) == -1) |
| 12835 | return (-1); |
| 12836 | } |
| 12837 | vctxt = ctxt->vctxt; |
| 12838 | } else { |
| 12839 | vctxt = xmlSchemaNewValidCtxt(NULL); |
| 12840 | if (vctxt == NULL) { |
| 12841 | xmlSchemaPErr(ctxt, typeDecl->node, |
| 12842 | XML_SCHEMAP_INTERNAL, |
| 12843 | "Internal error: xmlSchemaCheckFacet, " |
| 12844 | "creating a new validation context.\n", |
| 12845 | NULL, NULL); |
| 12846 | return (-1); |
| 12847 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12848 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12849 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12850 | vctxt->node = facet->node; |
| 12851 | vctxt->cur = NULL; |
| 12852 | /* |
| 12853 | * NOTE: This call does not check the content nodes, |
| 12854 | * since they are not available: |
| 12855 | * facet->node is just the node holding the facet |
| 12856 | * definition, *not* the attribute holding the *value* |
| 12857 | * of the facet. |
| 12858 | */ |
| 12859 | ret = xmlSchemaValidateSimpleTypeValue(vctxt, base, |
| 12860 | facet->value, 0, 1, 1, 0); |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 12861 | facet->val = vctxt->value; |
| 12862 | vctxt->value = NULL; |
| 12863 | if (ret > 0) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12864 | /* error code */ |
| 12865 | if (ctxt != NULL) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12866 | xmlSchemaPErrExt(ctxt, facet->node, |
| 12867 | XML_SCHEMAP_INVALID_FACET, |
| 12868 | NULL, NULL, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12869 | "Type definition '%s': The value '%s' of the " |
| 12870 | "facet '%s' is not valid.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12871 | name, facet->value, |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12872 | BAD_CAST xmlSchemaFacetTypeToString(facet->type), |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12873 | NULL, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12874 | } |
| 12875 | ret = -1; |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 12876 | } else if (ret < 0) { |
| 12877 | xmlSchemaPErrExt(ctxt, facet->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 12878 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 12879 | NULL, NULL, NULL, |
| 12880 | "Internal error: xmlSchemaCheckFacet, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12881 | "failed to validate the value '%s' name of the " |
| 12882 | "facet '%s' against the base type '%s'.\n", |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 12883 | facet->value, |
| 12884 | BAD_CAST xmlSchemaFacetTypeToString(facet->type), |
| 12885 | base->name, NULL, NULL); |
| 12886 | ret = -1; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12887 | } |
| 12888 | if (reuseValCtxt == 0) |
| 12889 | xmlSchemaFreeValidCtxt(vctxt); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12890 | break; |
| 12891 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12892 | case XML_SCHEMA_FACET_PATTERN: |
| 12893 | facet->regexp = xmlRegexpCompile(facet->value); |
| 12894 | if (facet->regexp == NULL) { |
| 12895 | xmlSchemaPErr(ctxt, typeDecl->node, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12896 | XML_SCHEMAP_REGEXP_INVALID, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12897 | "Type definition '%s': The value '%s' of the " |
| 12898 | "facet 'pattern' is not valid.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12899 | name, facet->value); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12900 | ret = -1; |
| 12901 | } |
| 12902 | break; |
| 12903 | case XML_SCHEMA_FACET_TOTALDIGITS: |
| 12904 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
| 12905 | case XML_SCHEMA_FACET_LENGTH: |
| 12906 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 12907 | case XML_SCHEMA_FACET_MINLENGTH:{ |
| 12908 | int tmp; |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 12909 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12910 | tmp = |
| 12911 | xmlSchemaValidatePredefinedType(nonNegativeIntegerType, |
| 12912 | facet->value, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 12913 | &(facet->val)); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12914 | if (tmp != 0) { |
| 12915 | /* error code */ |
| 12916 | if (ctxt != NULL) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12917 | xmlSchemaPErrExt(ctxt, facet->node, |
| 12918 | XML_SCHEMAP_INVALID_FACET_VALUE, |
| 12919 | NULL, NULL, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12920 | "Type definition '%s': The value '%s' of the " |
| 12921 | "facet '%s' is not valid.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12922 | name, facet->value, |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 12923 | BAD_CAST xmlSchemaFacetTypeToString(facet->type), |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12924 | NULL, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12925 | } |
| 12926 | ret = -1; |
| 12927 | } |
| 12928 | break; |
| 12929 | } |
| 12930 | case XML_SCHEMA_FACET_WHITESPACE:{ |
| 12931 | if (xmlStrEqual(facet->value, BAD_CAST "preserve")) { |
| 12932 | facet->whitespace = XML_SCHEMAS_FACET_PRESERVE; |
| 12933 | } else if (xmlStrEqual(facet->value, BAD_CAST "replace")) { |
| 12934 | facet->whitespace = XML_SCHEMAS_FACET_REPLACE; |
| 12935 | } else if (xmlStrEqual(facet->value, BAD_CAST "collapse")) { |
| 12936 | facet->whitespace = XML_SCHEMAS_FACET_COLLAPSE; |
| 12937 | } else { |
| 12938 | if (ctxt != NULL) { |
| 12939 | xmlSchemaPErr(ctxt, facet->node, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12940 | XML_SCHEMAP_INVALID_WHITE_SPACE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12941 | "Type definition '%s': The value '%s' of the " |
| 12942 | "facet 'whiteSpace' is not valid.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12943 | name, facet->value); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12944 | } |
| 12945 | ret = -1; |
| 12946 | } |
| 12947 | } |
| 12948 | default: |
| 12949 | break; |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 12950 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12951 | return (ret); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 12952 | } |
| 12953 | |
| 12954 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 12955 | * xmlSchemaCheckDefaults: |
| 12956 | * @typeDecl: the schema type definition |
| 12957 | * @ctxt: the schema parser context |
| 12958 | * |
| 12959 | * Checks the default values types, especially for facets |
| 12960 | */ |
| 12961 | static void |
| 12962 | xmlSchemaCheckDefaults(xmlSchemaTypePtr typeDecl, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 12963 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 12964 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 12965 | if (name == NULL) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12966 | name = typeDecl->name; |
| 12967 | /* |
| 12968 | * NOTE: It is intended to use the facets list, instead |
| 12969 | * of facetSet. |
| 12970 | */ |
| 12971 | if (typeDecl->facets != NULL) { |
| 12972 | xmlSchemaFacetPtr facet = typeDecl->facets; |
| 12973 | |
| 12974 | while (facet != NULL) { |
| 12975 | xmlSchemaCheckFacet(facet, typeDecl, ctxt, name); |
| 12976 | facet = facet->next; |
| 12977 | } |
| 12978 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 12979 | } |
| 12980 | |
| 12981 | /** |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 12982 | * xmlSchemaGetCircModelGrDefRef: |
| 12983 | * @ctxtGr: the searched model group |
| 12984 | * @list: the list of model groups to be processed |
| 12985 | * |
| 12986 | * This one is intended to be used by |
| 12987 | * xmlSchemaCheckGroupDefCircular only. |
| 12988 | * |
| 12989 | * Returns the circular model group definition reference, otherwise NULL. |
| 12990 | */ |
| 12991 | static xmlSchemaTypePtr |
| 12992 | xmlSchemaGetCircModelGrDefRef(xmlSchemaTypePtr ctxtGrDef, |
| 12993 | xmlSchemaTypePtr gr) |
| 12994 | { |
| 12995 | xmlSchemaTypePtr circ = NULL; |
| 12996 | int marked; |
| 12997 | /* |
| 12998 | * We will search for an model group reference which |
| 12999 | * references the context model group definition. |
| 13000 | */ |
| 13001 | while (gr != NULL) { |
| 13002 | if (((gr->type == XML_SCHEMA_TYPE_GROUP) || |
| 13003 | (gr->type == XML_SCHEMA_TYPE_ALL) || |
| 13004 | (gr->type == XML_SCHEMA_TYPE_SEQUENCE) || |
| 13005 | (gr->type == XML_SCHEMA_TYPE_CHOICE)) && |
| 13006 | (gr->subtypes != NULL)) { |
| 13007 | marked = 0; |
| 13008 | if ((gr->type == XML_SCHEMA_TYPE_GROUP) && |
| 13009 | (gr->ref != NULL)) { |
| 13010 | if (gr->subtypes == ctxtGrDef) |
| 13011 | return (gr); |
| 13012 | else if (gr->subtypes->flags & |
| 13013 | XML_SCHEMAS_TYPE_MARKED) { |
| 13014 | gr = gr->next; |
| 13015 | continue; |
| 13016 | } else { |
| 13017 | /* |
| 13018 | * Mark to avoid infinite recursion on |
| 13019 | * circular references not yet examined. |
| 13020 | */ |
| 13021 | gr->subtypes->flags |= XML_SCHEMAS_TYPE_MARKED; |
| 13022 | marked = 1; |
| 13023 | } |
| 13024 | if (gr->subtypes->subtypes != NULL) |
| 13025 | circ = xmlSchemaGetCircModelGrDefRef(ctxtGrDef, |
| 13026 | gr->subtypes->subtypes); |
| 13027 | /* |
| 13028 | * Unmark the visited model group definition. |
| 13029 | */ |
| 13030 | if (marked) |
| 13031 | gr->subtypes->flags ^= XML_SCHEMAS_TYPE_MARKED; |
| 13032 | if (circ != NULL) |
| 13033 | return (circ); |
| 13034 | } else { |
| 13035 | circ = xmlSchemaGetCircModelGrDefRef(ctxtGrDef, |
| 13036 | (xmlSchemaTypePtr) gr->subtypes); |
| 13037 | if (circ != NULL) |
| 13038 | return (circ); |
| 13039 | } |
| 13040 | |
| 13041 | } |
| 13042 | gr = gr->next; |
| 13043 | } |
| 13044 | return (NULL); |
| 13045 | } |
| 13046 | |
| 13047 | /** |
| 13048 | * xmlSchemaCheckGroupDefCircular: |
| 13049 | * attrGr: the model group definition |
| 13050 | * @ctxt: the parser context |
| 13051 | * @name: the name |
| 13052 | * |
| 13053 | * Checks for circular references to model group definitions. |
| 13054 | */ |
| 13055 | static void |
| 13056 | xmlSchemaCheckGroupDefCircular(xmlSchemaTypePtr modelGrDef, |
| 13057 | xmlSchemaParserCtxtPtr ctxt, |
| 13058 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 13059 | { |
| 13060 | /* |
| 13061 | * Schema Component Constraint: Model Group Correct |
| 13062 | * 2 Circular groups are disallowed. That is, within the {particles} |
| 13063 | * of a group there must not be at any depth a particle whose {term} |
| 13064 | * is the group itself. |
| 13065 | */ |
| 13066 | /* |
| 13067 | * NOTE: "gr->subtypes" holds the referenced group. |
| 13068 | */ |
| 13069 | if ((modelGrDef->type != XML_SCHEMA_TYPE_GROUP) || |
| 13070 | ((modelGrDef->flags & XML_SCHEMAS_TYPE_GLOBAL) == 0) || |
| 13071 | (modelGrDef->subtypes == NULL)) |
| 13072 | return; |
| 13073 | else { |
| 13074 | xmlSchemaTypePtr circ; |
| 13075 | |
| 13076 | circ = xmlSchemaGetCircModelGrDefRef(modelGrDef, modelGrDef->subtypes); |
| 13077 | if (circ != NULL) { |
| 13078 | /* |
| 13079 | * TODO: Report the referenced attr group as QName. |
| 13080 | */ |
| 13081 | xmlSchemaPCustomErr(ctxt, |
| 13082 | XML_SCHEMAP_MG_PROPS_CORRECT_2, |
| 13083 | NULL, NULL, circ->node, |
| 13084 | "Circular reference to the model group definition '%s' " |
| 13085 | "defined", modelGrDef->name); |
| 13086 | /* |
| 13087 | * NOTE: We will cut the reference to avoid further |
| 13088 | * confusion of the processor. |
| 13089 | * TODO: SPEC: Does the spec define how to process here? |
| 13090 | */ |
| 13091 | circ->subtypes = NULL; |
| 13092 | } |
| 13093 | } |
| 13094 | } |
| 13095 | |
| 13096 | |
| 13097 | /** |
| 13098 | * xmlSchemaGetCircAttrGrRef: |
| 13099 | * @ctxtGr: the searched attribute group |
| 13100 | * @attr: the current attribute list to be processed |
| 13101 | * |
| 13102 | * This one is intended to be used by |
| 13103 | * xmlSchemaCheckSRCAttributeGroupCircular only. |
| 13104 | * |
| 13105 | * Returns the circular attribute grou reference, otherwise NULL. |
| 13106 | */ |
| 13107 | static xmlSchemaAttributeGroupPtr |
| 13108 | xmlSchemaGetCircAttrGrRef(xmlSchemaAttributeGroupPtr ctxtGr, |
| 13109 | xmlSchemaAttributePtr attr) |
| 13110 | { |
| 13111 | xmlSchemaAttributeGroupPtr circ = NULL, gr; |
| 13112 | int marked; |
| 13113 | /* |
| 13114 | * We will search for an attribute group reference which |
| 13115 | * references the context attribute group. |
| 13116 | */ |
| 13117 | while (attr != NULL) { |
| 13118 | marked = 0; |
| 13119 | if (attr->type == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) { |
| 13120 | gr = (xmlSchemaAttributeGroupPtr) attr; |
| 13121 | if (gr->refItem != NULL) { |
| 13122 | if (gr->refItem == ctxtGr) |
| 13123 | return (gr); |
| 13124 | else if (gr->refItem->flags & |
| 13125 | XML_SCHEMAS_ATTRGROUP_MARKED) { |
| 13126 | attr = attr->next; |
| 13127 | continue; |
| 13128 | } else { |
| 13129 | /* |
| 13130 | * Mark as visited to avoid infinite recursion on |
| 13131 | * circular references not yet examined. |
| 13132 | */ |
| 13133 | gr->refItem->flags |= XML_SCHEMAS_ATTRGROUP_MARKED; |
| 13134 | marked = 1; |
| 13135 | } |
| 13136 | } |
| 13137 | if (gr->attributes != NULL) |
| 13138 | circ = xmlSchemaGetCircAttrGrRef(ctxtGr, gr->attributes); |
| 13139 | /* |
| 13140 | * Unmark the visited group's attributes. |
| 13141 | */ |
| 13142 | if (marked) |
| 13143 | gr->refItem->flags ^= XML_SCHEMAS_ATTRGROUP_MARKED; |
| 13144 | if (circ != NULL) |
| 13145 | return (circ); |
| 13146 | } |
| 13147 | attr = attr->next; |
| 13148 | } |
| 13149 | return (NULL); |
| 13150 | } |
| 13151 | |
| 13152 | /** |
| 13153 | * xmlSchemaCheckSRCAttributeGroupCircular: |
| 13154 | * attrGr: the attribute group definition |
| 13155 | * @ctxt: the parser context |
| 13156 | * @name: the name |
| 13157 | * |
| 13158 | * Checks for circular references of attribute groups. |
| 13159 | */ |
| 13160 | static void |
| 13161 | xmlSchemaCheckAttributeGroupCircular(xmlSchemaAttributeGroupPtr attrGr, |
| 13162 | xmlSchemaParserCtxtPtr ctxt, |
| 13163 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 13164 | { |
| 13165 | /* |
| 13166 | * Schema Representation Constraint: |
| 13167 | * Attribute Group Definition Representation OK |
| 13168 | * 3 Circular group reference is disallowed outside <redefine>. |
| 13169 | * That is, unless this element information item's parent is |
| 13170 | * <redefine>, then among the [children], if any, there must |
| 13171 | * not be an <attributeGroup> with ref [attribute] which resolves |
| 13172 | * to the component corresponding to this <attributeGroup>. Indirect |
| 13173 | * circularity is also ruled out. That is, when QName resolution |
| 13174 | * (Schema Document) (§3.15.3) is applied to a ·QName· arising from |
| 13175 | * any <attributeGroup>s with a ref [attribute] among the [children], |
| 13176 | * it must not be the case that a ·QName· is encountered at any depth |
| 13177 | * which resolves to the component corresponding to this <attributeGroup>. |
| 13178 | */ |
| 13179 | /* |
| 13180 | * Only global components can be referenced. |
| 13181 | */ |
| 13182 | if (((attrGr->flags & XML_SCHEMAS_ATTRGROUP_GLOBAL) == 0) || |
| 13183 | (attrGr->attributes == NULL)) |
| 13184 | return; |
| 13185 | else { |
| 13186 | xmlSchemaAttributeGroupPtr circ; |
| 13187 | |
| 13188 | circ = xmlSchemaGetCircAttrGrRef(attrGr, attrGr->attributes); |
| 13189 | if (circ != NULL) { |
| 13190 | /* |
| 13191 | * TODO: Report the referenced attr group as QName. |
| 13192 | */ |
| 13193 | xmlSchemaPCustomErr(ctxt, |
| 13194 | XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_3, |
| 13195 | NULL, NULL, circ->node, |
| 13196 | "Circular reference to the attribute group '%s' " |
| 13197 | "defined", attrGr->name); |
| 13198 | /* |
| 13199 | * NOTE: We will cut the reference to avoid further |
| 13200 | * confusion of the processor. |
| 13201 | * BADSPEC: The spec should define how to process in this case. |
| 13202 | */ |
| 13203 | circ->attributes = NULL; |
| 13204 | circ->refItem = NULL; |
| 13205 | } |
| 13206 | } |
| 13207 | } |
| 13208 | |
| 13209 | /** |
Daniel Veillard | 13e04c6 | 2002-04-23 17:51:29 +0000 | [diff] [blame] | 13210 | * xmlSchemaAttrGrpFixup: |
| 13211 | * @attrgrpDecl: the schema attribute definition |
| 13212 | * @ctxt: the schema parser context |
| 13213 | * @name: the attribute name |
| 13214 | * |
| 13215 | * Fixes finish doing the computations on the attributes definitions |
| 13216 | */ |
| 13217 | static void |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 13218 | xmlSchemaAttrGrpFixup(xmlSchemaAttributeGroupPtr attrgrp, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13219 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name) |
Daniel Veillard | 13e04c6 | 2002-04-23 17:51:29 +0000 | [diff] [blame] | 13220 | { |
| 13221 | if (name == NULL) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 13222 | name = attrgrp->name; |
| 13223 | if (attrgrp->attributes != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13224 | return; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 13225 | if (attrgrp->ref != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13226 | xmlSchemaAttributeGroupPtr ref; |
Daniel Veillard | 13e04c6 | 2002-04-23 17:51:29 +0000 | [diff] [blame] | 13227 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13228 | ref = xmlSchemaGetAttributeGroup(ctxt->schema, attrgrp->ref, |
| 13229 | attrgrp->refNs); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13230 | if (ref == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13231 | xmlSchemaPResCompAttrErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13232 | XML_SCHEMAP_SRC_RESOLVE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13233 | NULL, (xmlSchemaTypePtr) attrgrp, attrgrp->node, |
| 13234 | "ref", attrgrp->ref, attrgrp->refNs, |
| 13235 | XML_SCHEMA_TYPE_ATTRIBUTEGROUP, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13236 | return; |
| 13237 | } |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 13238 | attrgrp->refItem = ref; |
| 13239 | /* |
| 13240 | * Check for self reference! |
| 13241 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13242 | xmlSchemaAttrGrpFixup(ref, ctxt, NULL); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 13243 | attrgrp->attributes = ref->attributes; |
| 13244 | attrgrp->attributeWildcard = ref->attributeWildcard; |
| 13245 | } |
Daniel Veillard | 13e04c6 | 2002-04-23 17:51:29 +0000 | [diff] [blame] | 13246 | } |
| 13247 | |
| 13248 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13249 | * xmlSchemaAttrCheckValConstr: |
| 13250 | * @item: an schema attribute declaration/use |
| 13251 | * @ctxt: a schema parser context |
| 13252 | * @name: the name of the attribute |
| 13253 | * |
| 13254 | * Validates the value constraints of an attribute declaration/use. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13255 | * |
| 13256 | * Fixes finish doing the computations on the attributes definitions |
| 13257 | */ |
| 13258 | static void |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13259 | xmlSchemaCheckAttrValConstr(xmlSchemaAttributePtr item, |
| 13260 | xmlSchemaParserCtxtPtr ctxt, |
| 13261 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 13262 | { |
| 13263 | |
| 13264 | /* |
| 13265 | * a-props-correct |
| 13266 | * Schema Component Constraint: Attribute Declaration Properties Correct |
| 13267 | * |
| 13268 | * 2 if there is a {value constraint}, the canonical lexical |
| 13269 | * representation of its value must be ·valid· with respect |
| 13270 | * to the {type definition} as defined in String Valid (§3.14.4). |
| 13271 | */ |
| 13272 | |
| 13273 | if (item->defValue != NULL) { |
| 13274 | int ret; |
| 13275 | xmlNodePtr node; |
| 13276 | xmlSchemaTypePtr type; |
| 13277 | |
| 13278 | if (item->subtypes == NULL) { |
| 13279 | xmlSchemaPErr(ctxt, item->node, |
| 13280 | XML_SCHEMAP_INTERNAL, |
| 13281 | "Internal error: xmlSchemaCheckAttrValConstr, " |
| 13282 | "type is missing... skipping validation of " |
| 13283 | "value constraint", NULL, NULL); |
| 13284 | return; |
| 13285 | } |
| 13286 | |
| 13287 | /* |
| 13288 | * TODO: Try to avoid creating a new context. |
| 13289 | * TODO: This all is not very performant. |
| 13290 | */ |
| 13291 | type = item->subtypes; |
| 13292 | /* |
| 13293 | * Ensure there's validation context. |
| 13294 | */ |
| 13295 | if (ctxt->vctxt == NULL) { |
| 13296 | if (xmlSchemaCreateVCtxtOnPCtxt(ctxt) == -1) { |
| 13297 | xmlSchemaPErr(ctxt, item->node, |
| 13298 | XML_SCHEMAP_INTERNAL, |
| 13299 | "Internal error: xmlSchemaCheckAttrValConstr, " |
| 13300 | "creating a new validation context.\n", |
| 13301 | NULL, NULL); |
| 13302 | return; |
| 13303 | } |
| 13304 | } |
| 13305 | |
| 13306 | if (item->flags & XML_SCHEMAS_ATTR_FIXED) |
| 13307 | node = (xmlNodePtr) xmlHasProp(item->node, BAD_CAST "fixed"); |
| 13308 | else |
| 13309 | node = (xmlNodePtr) xmlHasProp(item->node, BAD_CAST "default"); |
| 13310 | ctxt->vctxt->node = node; |
| 13311 | ctxt->vctxt->cur = NULL; |
| 13312 | /* |
| 13313 | * NOTE: This call does not check the content nodes, |
| 13314 | * since they are not available: |
| 13315 | * facet->node is just the node holding the facet |
| 13316 | * definition, *not* the attribute holding the *value* |
| 13317 | * of the facet. |
| 13318 | */ |
| 13319 | ret = xmlSchemaValidateSimpleTypeValue(ctxt->vctxt, type, |
| 13320 | item->defValue, 0, 1, 1, 0); |
| 13321 | if (ret == 0) { |
| 13322 | /* |
| 13323 | * Store the computed value. |
| 13324 | */ |
| 13325 | item->defVal = ctxt->vctxt->value; |
| 13326 | ctxt->vctxt->value = NULL; |
| 13327 | } else if (ret > 0) { |
| 13328 | if (ctxt != NULL) { |
| 13329 | xmlSchemaPSimpleTypeErr(ctxt, |
| 13330 | XML_SCHEMAP_A_PROPS_CORRECT_2, |
| 13331 | NULL, NULL, node, |
| 13332 | type, NULL, item->defValue, |
| 13333 | NULL, NULL, NULL); |
| 13334 | } |
| 13335 | } else if (ret < 0) { |
| 13336 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, |
| 13337 | NULL, NULL, node, |
| 13338 | "Internal error: xmlSchemaAttrCheckValConstr, " |
| 13339 | "failed to validate the value constraint of the " |
| 13340 | "attribute decl/use against the type '%s'", |
| 13341 | type->name); |
| 13342 | } |
| 13343 | } |
| 13344 | } |
| 13345 | |
| 13346 | #if 0 /* Not used yet. */ |
| 13347 | static int |
| 13348 | xmlSchemaCheckElemPropsCorrect(xmlSchemaParserCtxtPtr ctxt, |
| 13349 | xmlSchemaElementPtr edecl) |
| 13350 | { |
| 13351 | /* |
| 13352 | * TODO: 1 The values of the properties of an element declaration must be as |
| 13353 | * described in the property tableau in The Element Declaration Schema |
| 13354 | * Component (§3.3.1), modulo the impact of Missing Sub-components (§5.3). |
| 13355 | */ |
| 13356 | /* |
| 13357 | * 2 If there is a {value constraint}, the canonical lexical |
| 13358 | * representation of its value must be ·valid· with respect to the {type |
| 13359 | * definition} as defined in Element Default Valid (Immediate) (§3.3.6). |
| 13360 | * |
| 13361 | * NOTE: This is done in xmlSchemaCheckElemValConstr. |
| 13362 | */ |
| 13363 | /* |
| 13364 | * 3 If there is a non-·absent· {substitution group affiliation}, |
| 13365 | * then {scope} must be global. |
| 13366 | * |
| 13367 | * NOTE: This is done in xmlSchemaParseElement. |
| 13368 | * TODO: Move it to this layer here. |
| 13369 | */ |
| 13370 | /* |
| 13371 | * TODO: 4 If there is a {substitution group affiliation}, the {type definition} |
| 13372 | * of the element declaration must be validly derived from the {type |
| 13373 | * definition} of the {substitution group affiliation}, given the value |
| 13374 | * of the {substitution group exclusions} of the {substitution group |
| 13375 | * affiliation}, as defined in Type Derivation OK (Complex) (§3.4.6) |
| 13376 | * (if the {type definition} is complex) or as defined in |
| 13377 | * Type Derivation OK (Simple) (§3.14.6) (if the {type definition} is |
| 13378 | * simple). |
| 13379 | */ |
| 13380 | /* |
| 13381 | * TODO: 5 If the {type definition} or {type definition}'s {content type} |
| 13382 | * is or is derived from ID then there must not be a {value constraint}. |
| 13383 | * Note: The use of ID as a type definition for elements goes beyond |
| 13384 | * XML 1.0, and should be avoided if backwards compatibility is desired |
| 13385 | */ |
| 13386 | /* |
| 13387 | * TODO: 6 Circular substitution groups are disallowed. That is, it must not |
| 13388 | * be possible to return to an element declaration by repeatedly following |
| 13389 | * the {substitution group affiliation} property. |
| 13390 | */ |
| 13391 | } |
| 13392 | #endif |
| 13393 | |
| 13394 | /** |
| 13395 | * xmlSchemaCheckElemValConstr: |
| 13396 | * @item: an schema element declaration/particle |
| 13397 | * @ctxt: a schema parser context |
| 13398 | * @name: the name of the attribute |
| 13399 | * |
| 13400 | * Validates the value constraints of an element declaration. |
| 13401 | * |
| 13402 | * Fixes finish doing the computations on the element declarations. |
| 13403 | */ |
| 13404 | static void |
| 13405 | xmlSchemaCheckElemValConstr(xmlSchemaElementPtr decl, |
| 13406 | xmlSchemaParserCtxtPtr ctxt, |
| 13407 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 13408 | { |
| 13409 | if (decl->value != NULL) { |
| 13410 | int ret; |
| 13411 | xmlNodePtr node = NULL; |
| 13412 | xmlSchemaTypePtr type; |
| 13413 | |
| 13414 | /* |
| 13415 | * 2 If there is a {value constraint}, the canonical lexical |
| 13416 | * representation of its value must be ·valid· with respect to the {type |
| 13417 | * definition} as defined in Element Default Valid (Immediate) (§3.3.6). |
| 13418 | */ |
| 13419 | if (decl->subtypes == NULL) { |
| 13420 | xmlSchemaPErr(ctxt, decl->node, |
| 13421 | XML_SCHEMAP_INTERNAL, |
| 13422 | "Internal error: xmlSchemaCheckElemValConstr, " |
| 13423 | "type is missing... skipping validation of " |
| 13424 | "the value constraint", NULL, NULL); |
| 13425 | return; |
| 13426 | } |
| 13427 | /* |
| 13428 | * Ensure there's a validation context. |
| 13429 | */ |
| 13430 | if (xmlSchemaCreateVCtxtOnPCtxt(ctxt) == -1) |
| 13431 | return; |
| 13432 | |
| 13433 | type = decl->subtypes; |
| 13434 | |
| 13435 | if (decl->node != NULL) { |
| 13436 | if (decl->flags & XML_SCHEMAS_ELEM_FIXED) |
| 13437 | node = (xmlNodePtr) xmlHasProp(decl->node, BAD_CAST "fixed"); |
| 13438 | else |
| 13439 | node = (xmlNodePtr) xmlHasProp(decl->node, BAD_CAST "default"); |
| 13440 | } |
| 13441 | ctxt->vctxt->node = node; |
| 13442 | ctxt->vctxt->cur = NULL; |
| 13443 | ret = xmlSchemaCheckCOSValidDefault(ctxt, ctxt->vctxt, type, decl->value, |
| 13444 | node); |
| 13445 | if (ret == 0) { |
| 13446 | /* |
| 13447 | * Consume the computed value. |
| 13448 | */ |
| 13449 | decl->defVal = ctxt->vctxt->value; |
| 13450 | ctxt->vctxt->value = NULL; |
| 13451 | } else if (ret < 0) { |
| 13452 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, |
| 13453 | NULL, NULL, node, |
| 13454 | "Internal error: xmlSchemaElemCheckValConstr, " |
| 13455 | "failed to validate the value constraint of the " |
| 13456 | "element declaration '%s'", |
| 13457 | decl->name); |
| 13458 | } |
| 13459 | } |
| 13460 | } |
| 13461 | |
| 13462 | /** |
| 13463 | * xmlSchemaAttrFixup: |
| 13464 | * @item: an schema attribute declaration/use. |
| 13465 | * @ctxt: a schema parser context |
| 13466 | * @name: the name of the attribute |
| 13467 | * |
| 13468 | * Fixes finish doing the computations on attribute declarations/uses. |
| 13469 | */ |
| 13470 | static void |
| 13471 | xmlSchemaAttrFixup(xmlSchemaAttributePtr item, |
| 13472 | xmlSchemaParserCtxtPtr ctxt, |
| 13473 | const xmlChar * name ATTRIBUTE_UNUSED) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13474 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13475 | /* |
| 13476 | * TODO: If including this is done twice (!) for every attribute. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13477 | * -> Hmm, check if this is still done. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13478 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13479 | /* |
| 13480 | * The simple type definition corresponding to the <simpleType> element |
| 13481 | * information item in the [children], if present, otherwise the simple |
| 13482 | * type definition ·resolved· to by the ·actual value· of the type |
| 13483 | * [attribute], if present, otherwise the ·simple ur-type definition·. |
| 13484 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13485 | if (item->flags & XML_SCHEMAS_ATTR_INTERNAL_RESOLVED) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13486 | return; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13487 | item->flags |= XML_SCHEMAS_ATTR_INTERNAL_RESOLVED; |
| 13488 | if (item->subtypes != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13489 | return; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13490 | if (item->typeName != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13491 | xmlSchemaTypePtr type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13492 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13493 | type = xmlSchemaGetType(ctxt->schema, item->typeName, |
| 13494 | item->typeNs); |
| 13495 | if ((type == NULL) || (! IS_SIMPLE_TYPE(type))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13496 | xmlSchemaPResCompAttrErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13497 | XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13498 | NULL, (xmlSchemaTypePtr) item, item->node, |
| 13499 | "type", item->typeName, item->typeNs, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13500 | XML_SCHEMA_TYPE_SIMPLE, NULL); |
| 13501 | } else |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13502 | item->subtypes = type; |
| 13503 | |
| 13504 | } else if (item->ref != NULL) { |
| 13505 | xmlSchemaAttributePtr decl; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13506 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13507 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13508 | * We have an attribute use here; assign the referenced |
| 13509 | * attribute declaration. |
| 13510 | */ |
| 13511 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13512 | * TODO: Evaluate, what errors could occur if the declaration is not |
| 13513 | * found. It might be possible that the "typefixup" might crash if |
| 13514 | * no ref declaration was found. |
| 13515 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13516 | decl = xmlSchemaGetAttribute(ctxt->schema, item->ref, item->refNs); |
| 13517 | if (decl == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13518 | xmlSchemaPResCompAttrErr(ctxt, |
| 13519 | XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13520 | NULL, (xmlSchemaTypePtr) item, item->node, |
| 13521 | "ref", item->ref, item->refNs, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13522 | XML_SCHEMA_TYPE_ATTRIBUTE, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13523 | return; |
| 13524 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13525 | item->refDecl = decl; |
| 13526 | xmlSchemaAttrFixup(decl, ctxt, NULL); |
| 13527 | |
| 13528 | item->subtypes = decl->subtypes; |
| 13529 | /* |
| 13530 | * Attribute Use Correct |
| 13531 | * au-props-correct.2: If the {attribute declaration} has a fixed |
| 13532 | * {value constraint}, then if the attribute use itself has a |
| 13533 | * {value constraint}, it must also be fixed and its value must match |
| 13534 | * that of the {attribute declaration}'s {value constraint}. |
| 13535 | */ |
| 13536 | if ((decl->flags & XML_SCHEMAS_ATTR_FIXED) && |
| 13537 | (item->defValue != NULL)) { |
| 13538 | if (((item->flags & XML_SCHEMAS_ATTR_FIXED) == 0) || |
| 13539 | (!xmlStrEqual(item->defValue, decl->defValue))) { |
| 13540 | xmlSchemaPCustomErr(ctxt, |
| 13541 | XML_SCHEMAP_AU_PROPS_CORRECT_2, |
| 13542 | NULL, NULL, item->node, |
| 13543 | "The value constraint must be fixed " |
| 13544 | "and match the referenced attribute " |
| 13545 | "declarations's value constraint '%s'", |
| 13546 | decl->defValue); |
| 13547 | } |
| 13548 | /* |
| 13549 | * FUTURE: One should change the values of the attr. use |
| 13550 | * if ever validation should be attempted even if the |
| 13551 | * schema itself was not fully valid. |
| 13552 | */ |
| 13553 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 13554 | } else { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13555 | item->subtypes = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 13556 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13557 | } |
| 13558 | |
| 13559 | /** |
| 13560 | * xmlSchemaParse: |
| 13561 | * @ctxt: a schema validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13562 | * |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 13563 | * parse a schema definition resource and build an internal |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13564 | * XML Shema struture which can be used to validate instances. |
| 13565 | * *WARNING* this interface is highly subject to change |
| 13566 | * |
| 13567 | * Returns the internal XML Schema structure built from the resource or |
| 13568 | * NULL in case of error |
| 13569 | */ |
| 13570 | xmlSchemaPtr |
| 13571 | xmlSchemaParse(xmlSchemaParserCtxtPtr ctxt) |
| 13572 | { |
| 13573 | xmlSchemaPtr ret = NULL; |
| 13574 | xmlDocPtr doc; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 13575 | xmlNodePtr root; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 13576 | int preserve = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13577 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13578 | /* |
| 13579 | * This one is used if the schema to be parsed was specified via |
| 13580 | * the API; i.e. not automatically by the validated instance document. |
| 13581 | */ |
| 13582 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13583 | xmlSchemaInitTypes(); |
| 13584 | |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 13585 | if (ctxt == NULL) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13586 | return (NULL); |
| 13587 | |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 13588 | ctxt->nberrors = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13589 | ctxt->counter = 0; |
| 13590 | ctxt->container = NULL; |
| 13591 | |
| 13592 | /* |
| 13593 | * First step is to parse the input document into an DOM/Infoset |
| 13594 | */ |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 13595 | if (ctxt->URL != NULL) { |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 13596 | doc = xmlReadFile((const char *) ctxt->URL, NULL, |
| 13597 | SCHEMAS_PARSE_OPTIONS); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13598 | if (doc == NULL) { |
| 13599 | xmlSchemaPErr(ctxt, NULL, |
| 13600 | XML_SCHEMAP_FAILED_LOAD, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13601 | "xmlSchemaParse: could not load '%s'.\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13602 | ctxt->URL, NULL); |
| 13603 | return (NULL); |
| 13604 | } |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 13605 | } else if (ctxt->buffer != NULL) { |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 13606 | doc = xmlReadMemory(ctxt->buffer, ctxt->size, NULL, NULL, |
| 13607 | SCHEMAS_PARSE_OPTIONS); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13608 | if (doc == NULL) { |
| 13609 | xmlSchemaPErr(ctxt, NULL, |
| 13610 | XML_SCHEMAP_FAILED_PARSE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13611 | "xmlSchemaParse: could not parse.\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13612 | NULL, NULL); |
| 13613 | return (NULL); |
| 13614 | } |
| 13615 | doc->URL = xmlStrdup(BAD_CAST "in_memory_buffer"); |
Daniel Veillard | 6576528 | 2004-01-08 16:59:30 +0000 | [diff] [blame] | 13616 | ctxt->URL = xmlDictLookup(ctxt->dict, BAD_CAST "in_memory_buffer", -1); |
Daniel Veillard | 9d75150 | 2003-10-29 13:21:47 +0000 | [diff] [blame] | 13617 | } else if (ctxt->doc != NULL) { |
| 13618 | doc = ctxt->doc; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 13619 | preserve = 1; |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 13620 | } else { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13621 | xmlSchemaPErr(ctxt, NULL, |
| 13622 | XML_SCHEMAP_NOTHING_TO_PARSE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13623 | "xmlSchemaParse: could not parse.\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13624 | NULL, NULL); |
| 13625 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13626 | } |
| 13627 | |
| 13628 | /* |
| 13629 | * Then extract the root and Schema parse it |
| 13630 | */ |
| 13631 | root = xmlDocGetRootElement(doc); |
| 13632 | if (root == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13633 | xmlSchemaPErr(ctxt, (xmlNodePtr) doc, |
| 13634 | XML_SCHEMAP_NOROOT, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13635 | "The schema has no document element.\n", NULL, NULL); |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 13636 | if (!preserve) { |
| 13637 | xmlFreeDoc(doc); |
| 13638 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13639 | return (NULL); |
| 13640 | } |
| 13641 | |
| 13642 | /* |
| 13643 | * Remove all the blank text nodes |
| 13644 | */ |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 13645 | xmlSchemaCleanupDoc(ctxt, root); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13646 | |
| 13647 | /* |
| 13648 | * Then do the parsing for good |
| 13649 | */ |
| 13650 | ret = xmlSchemaParseSchema(ctxt, root); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 13651 | if (ret == NULL) { |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 13652 | if (!preserve) { |
| 13653 | xmlFreeDoc(doc); |
| 13654 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13655 | return (NULL); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 13656 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13657 | ret->doc = doc; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 13658 | ret->preserve = preserve; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13659 | ctxt->schema = ret; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13660 | ctxt->ctxtType = NULL; |
| 13661 | ctxt->parentItem = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13662 | /* |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 13663 | * Then fixup all attributes declarations |
| 13664 | */ |
| 13665 | xmlHashScan(ret->attrDecl, (xmlHashScanner) xmlSchemaAttrFixup, ctxt); |
| 13666 | |
| 13667 | /* |
| 13668 | * Then fixup all attributes group declarations |
| 13669 | */ |
| 13670 | xmlHashScan(ret->attrgrpDecl, (xmlHashScanner) xmlSchemaAttrGrpFixup, |
| 13671 | ctxt); |
| 13672 | |
| 13673 | /* |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 13674 | * Check attribute groups for circular references. |
| 13675 | */ |
| 13676 | xmlHashScan(ret->attrgrpDecl, (xmlHashScanner) |
| 13677 | xmlSchemaCheckAttributeGroupCircular, ctxt); |
| 13678 | |
| 13679 | /* |
| 13680 | * Then fixup all model group definitions. |
| 13681 | */ |
| 13682 | xmlHashScan(ret->groupDecl, (xmlHashScanner) xmlSchemaGroupDefFixup, ctxt); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13683 | |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 13684 | /* |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13685 | * Then fixup all types properties |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13686 | */ |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 13687 | xmlHashScan(ret->typeDecl, (xmlHashScanner) xmlSchemaTypeFixup, ctxt); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13688 | |
| 13689 | /* |
| 13690 | * Then fix references of element declaration; apply constraints. |
| 13691 | */ |
| 13692 | xmlHashScanFull(ret->elemDecl, |
| 13693 | (xmlHashScannerFull) xmlSchemaRefFixupCallback, ctxt); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13694 | |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 13695 | /* |
| 13696 | * Check model groups defnitions for circular references. |
| 13697 | */ |
| 13698 | xmlHashScan(ret->groupDecl, (xmlHashScanner) |
| 13699 | xmlSchemaCheckGroupDefCircular, ctxt); |
| 13700 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13701 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13702 | * Then build the content model for all complex types |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13703 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13704 | xmlHashScan(ret->typeDecl, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13705 | (xmlHashScanner) xmlSchemaBuildContentModel, ctxt); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13706 | |
| 13707 | /* |
| 13708 | * Then check the defaults part of the type like facets values |
| 13709 | */ |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 13710 | /* OLD: xmlHashScan(ret->typeDecl, (xmlHashScanner) xmlSchemaCheckDefaults, ctxt); */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13711 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13712 | /* |
| 13713 | * Validate the value constraint of attribute declarations/uses. |
| 13714 | */ |
| 13715 | xmlHashScan(ret->attrDecl, (xmlHashScanner) xmlSchemaCheckAttrValConstr, ctxt); |
| 13716 | |
| 13717 | /* |
| 13718 | * Validate the value constraint of element declarations. |
| 13719 | */ |
| 13720 | xmlHashScan(ret->elemDecl, (xmlHashScanner) xmlSchemaCheckElemValConstr, ctxt); |
| 13721 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13722 | |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 13723 | if (ctxt->nberrors != 0) { |
| 13724 | xmlSchemaFree(ret); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13725 | ret = NULL; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 13726 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13727 | return (ret); |
| 13728 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13729 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13730 | /** |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 13731 | * xmlSchemaSetParserErrors: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13732 | * @ctxt: a schema validation context |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 13733 | * @err: the error callback |
| 13734 | * @warn: the warning callback |
| 13735 | * @ctx: contextual data for the callbacks |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13736 | * |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 13737 | * Set the callback functions used to handle errors for a validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13738 | */ |
| 13739 | void |
| 13740 | xmlSchemaSetParserErrors(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13741 | xmlSchemaValidityErrorFunc err, |
| 13742 | xmlSchemaValidityWarningFunc warn, void *ctx) |
| 13743 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13744 | if (ctxt == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13745 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13746 | ctxt->error = err; |
| 13747 | ctxt->warning = warn; |
| 13748 | ctxt->userData = ctx; |
| 13749 | } |
| 13750 | |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 13751 | /** |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 13752 | * xmlSchemaGetParserErrors: |
| 13753 | * @ctxt: a XMl-Schema parser context |
| 13754 | * @err: the error callback result |
| 13755 | * @warn: the warning callback result |
| 13756 | * @ctx: contextual data for the callbacks result |
| 13757 | * |
| 13758 | * Get the callback information used to handle errors for a parser context |
| 13759 | * |
| 13760 | * Returns -1 in case of failure, 0 otherwise |
| 13761 | */ |
| 13762 | int |
| 13763 | xmlSchemaGetParserErrors(xmlSchemaParserCtxtPtr ctxt, |
| 13764 | xmlSchemaValidityErrorFunc * err, |
| 13765 | xmlSchemaValidityWarningFunc * warn, void **ctx) |
| 13766 | { |
| 13767 | if (ctxt == NULL) |
| 13768 | return(-1); |
| 13769 | if (err != NULL) |
| 13770 | *err = ctxt->error; |
| 13771 | if (warn != NULL) |
| 13772 | *warn = ctxt->warning; |
| 13773 | if (ctx != NULL) |
| 13774 | *ctx = ctxt->userData; |
| 13775 | return(0); |
| 13776 | } |
| 13777 | |
| 13778 | /** |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 13779 | * xmlSchemaFacetTypeToString: |
| 13780 | * @type: the facet type |
| 13781 | * |
| 13782 | * Convert the xmlSchemaTypeType to a char string. |
| 13783 | * |
| 13784 | * Returns the char string representation of the facet type if the |
| 13785 | * type is a facet and an "Internal Error" string otherwise. |
| 13786 | */ |
| 13787 | static const char * |
| 13788 | xmlSchemaFacetTypeToString(xmlSchemaTypeType type) |
| 13789 | { |
| 13790 | switch (type) { |
| 13791 | case XML_SCHEMA_FACET_PATTERN: |
| 13792 | return ("pattern"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13793 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 13794 | return ("maxExclusive"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13795 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 13796 | return ("maxInclusive"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13797 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 13798 | return ("minExclusive"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13799 | case XML_SCHEMA_FACET_MININCLUSIVE: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 13800 | return ("minInclusive"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13801 | case XML_SCHEMA_FACET_WHITESPACE: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 13802 | return ("whiteSpace"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13803 | case XML_SCHEMA_FACET_ENUMERATION: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 13804 | return ("enumeration"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13805 | case XML_SCHEMA_FACET_LENGTH: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 13806 | return ("length"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13807 | case XML_SCHEMA_FACET_MAXLENGTH: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 13808 | return ("maxLength"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13809 | case XML_SCHEMA_FACET_MINLENGTH: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 13810 | return ("minLength"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13811 | case XML_SCHEMA_FACET_TOTALDIGITS: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 13812 | return ("totalDigits"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13813 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 13814 | return ("fractionDigits"); |
| 13815 | default: |
| 13816 | break; |
| 13817 | } |
| 13818 | return ("Internal Error"); |
| 13819 | } |
| 13820 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13821 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13822 | |
| 13823 | static int |
| 13824 | xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type) |
| 13825 | { |
| 13826 | xmlSchemaTypePtr anc; |
| 13827 | |
| 13828 | /* |
| 13829 | * The normalization type can be changed only for types which are derived |
| 13830 | * from xsd:string. |
| 13831 | */ |
| 13832 | if (type->type == XML_SCHEMA_TYPE_BASIC) { |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 13833 | if (type->builtInType == XML_SCHEMAS_STRING) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13834 | return(XML_SCHEMAS_VAL_WTSP_PRESERVE); |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 13835 | else if (type->builtInType == XML_SCHEMAS_NORMSTRING) |
| 13836 | return(XML_SCHEMAS_VAL_WTSP_REPLACE); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13837 | else { |
| 13838 | /* |
| 13839 | * For all ·atomic· datatypes other than string (and types ·derived· |
| 13840 | * by ·restriction· from it) the value of whiteSpace is fixed to |
| 13841 | * collapse |
| 13842 | */ |
| 13843 | return(XML_SCHEMAS_VAL_WTSP_COLLAPSE); |
| 13844 | } |
| 13845 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 13846 | /* |
| 13847 | * For list types the facet "whiteSpace" is fixed to "collapse". |
| 13848 | */ |
| 13849 | return (XML_SCHEMAS_VAL_WTSP_COLLAPSE); |
| 13850 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
| 13851 | return (-1); |
| 13852 | } else if (type->facetSet != NULL) { |
| 13853 | xmlSchemaTypePtr anyST; |
| 13854 | xmlSchemaFacetLinkPtr lin; |
| 13855 | |
| 13856 | /* |
| 13857 | * Atomic types. |
| 13858 | */ |
| 13859 | anyST = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 13860 | anc = type->baseType; |
| 13861 | do { |
| 13862 | /* |
| 13863 | * For all ·atomic· datatypes other than string (and types ·derived· |
| 13864 | * by ·restriction· from it) the value of whiteSpace is fixed to |
| 13865 | * collapse |
| 13866 | */ |
| 13867 | if ((anc->type == XML_SCHEMA_TYPE_BASIC) && |
| 13868 | (anc->builtInType == XML_SCHEMAS_STRING)) { |
| 13869 | |
| 13870 | lin = type->facetSet; |
| 13871 | do { |
| 13872 | if (lin->facet->type == XML_SCHEMA_FACET_WHITESPACE) { |
| 13873 | if (lin->facet->whitespace == |
| 13874 | XML_SCHEMAS_FACET_COLLAPSE) { |
| 13875 | return(XML_SCHEMAS_VAL_WTSP_COLLAPSE); |
| 13876 | } else if (lin->facet->whitespace == |
| 13877 | XML_SCHEMAS_FACET_REPLACE) { |
| 13878 | return(XML_SCHEMAS_VAL_WTSP_REPLACE); |
| 13879 | } else |
| 13880 | return(XML_SCHEMAS_VAL_WTSP_PRESERVE); |
| 13881 | break; |
| 13882 | } |
| 13883 | lin = lin->next; |
| 13884 | } while (lin != NULL); |
| 13885 | break; |
| 13886 | } |
| 13887 | anc = anc->baseType; |
| 13888 | } while (anc != anyST); |
| 13889 | return (XML_SCHEMAS_VAL_WTSP_COLLAPSE); |
| 13890 | } |
| 13891 | return (-1); |
| 13892 | } |
| 13893 | |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 13894 | /** |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 13895 | * xmlSchemaValidateFacetsInternal: |
| 13896 | * @ctxt: a schema validation context |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13897 | * @type: the type holding the facets |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 13898 | * @facets: the list of facets to check |
| 13899 | * @value: the lexical repr of the value to validate |
| 13900 | * @val: the precomputed value |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 13901 | * @fireErrors: if 0, only internal errors will be fired; |
| 13902 | * otherwise all errors will be fired. |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 13903 | * |
| 13904 | * Check a value against all facet conditions |
| 13905 | * |
| 13906 | * Returns 0 if the element is schemas valid, a positive error code |
| 13907 | * number otherwise and -1 in case of internal or API error. |
| 13908 | */ |
| 13909 | static int |
| 13910 | xmlSchemaValidateFacetsInternal(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13911 | xmlSchemaTypePtr type, |
| 13912 | const xmlChar * value, |
| 13913 | unsigned long length, |
| 13914 | int fireErrors) |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 13915 | { |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 13916 | int ret = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13917 | xmlNodePtr node; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13918 | xmlSchemaTypePtr biType; /* The build-in type. */ |
| 13919 | xmlSchemaTypePtr tmpType; |
| 13920 | xmlSchemaFacetLinkPtr facetLink; |
Daniel Veillard | c7e3cc4 | 2004-09-28 12:33:52 +0000 | [diff] [blame] | 13921 | int retFacet; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13922 | xmlSchemaFacetPtr facet; |
| 13923 | unsigned long len = 0; |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 13924 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13925 | #ifdef DEBUG_UNION_VALIDATION |
| 13926 | printf("Facets of type: '%s'\n", (const char *) type->name); |
| 13927 | printf(" fireErrors: %d\n", fireErrors); |
| 13928 | #endif |
| 13929 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13930 | node = ctxt->node; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13931 | /* |
| 13932 | * NOTE: Do not jump away, if the facetSet of the given type is |
| 13933 | * empty: until now, "pattern" facets of the *base types* need to |
| 13934 | * be checked as well. |
| 13935 | */ |
| 13936 | biType = type->baseType; |
| 13937 | while ((biType != NULL) && (biType->type != XML_SCHEMA_TYPE_BASIC)) |
| 13938 | biType = biType->baseType; |
| 13939 | if (biType == NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13940 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13941 | "Internal error: xmlSchemaValidateFacetsInternal, " |
| 13942 | "the base type axis of the given type '%s' does not resolve to " |
| 13943 | "a built-in type.\n", |
| 13944 | type->name, NULL); |
| 13945 | return (-1); |
| 13946 | } |
| 13947 | |
| 13948 | if (type->facetSet != NULL) { |
| 13949 | facetLink = type->facetSet; |
| 13950 | while (facetLink != NULL) { |
| 13951 | facet = facetLink->facet; |
| 13952 | /* |
| 13953 | * Skip the pattern "whiteSpace": it is used to |
| 13954 | * format the character content beforehand. |
| 13955 | */ |
| 13956 | switch (facet->type) { |
| 13957 | case XML_SCHEMA_FACET_WHITESPACE: |
| 13958 | case XML_SCHEMA_FACET_PATTERN: |
| 13959 | case XML_SCHEMA_FACET_ENUMERATION: |
| 13960 | break; |
| 13961 | case XML_SCHEMA_FACET_LENGTH: |
| 13962 | case XML_SCHEMA_FACET_MINLENGTH: |
| 13963 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 13964 | if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 13965 | ret = xmlSchemaValidateListSimpleTypeFacet(facet, |
| 13966 | value, length, 0); |
| 13967 | len = length; |
| 13968 | } else |
| 13969 | ret = xmlSchemaValidateLengthFacet(biType, facet, |
| 13970 | value, ctxt->value, &len); |
| 13971 | break; |
| 13972 | default: |
| 13973 | ret = xmlSchemaValidateFacet(biType, facet, value, |
| 13974 | ctxt->value); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13975 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13976 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13977 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13978 | "Internal error: xmlSchemaValidateFacetsInternal, " |
| 13979 | "validating facet of type '%s'.\n", |
| 13980 | type->name, NULL); |
| 13981 | break; |
| 13982 | } else if ((ret > 0) && (fireErrors)) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13983 | xmlSchemaVFacetErr(ctxt, ret, node, value, len, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13984 | type, facet, NULL, NULL, NULL, NULL); |
| 13985 | } |
| 13986 | |
| 13987 | facetLink = facetLink->next; |
| 13988 | } |
| 13989 | if (ret >= 0) { |
| 13990 | /* |
| 13991 | * Process enumerations. |
| 13992 | */ |
| 13993 | retFacet = 0; |
| 13994 | facetLink = type->facetSet; |
| 13995 | while (facetLink != NULL) { |
| 13996 | if (facetLink->facet->type == XML_SCHEMA_FACET_ENUMERATION) { |
| 13997 | retFacet = xmlSchemaValidateFacet(biType, facetLink->facet, |
| 13998 | value, ctxt->value); |
| 13999 | if (retFacet <= 0) |
| 14000 | break; |
| 14001 | } |
| 14002 | facetLink = facetLink->next; |
| 14003 | } |
| 14004 | if (retFacet > 0) { |
| 14005 | ret = XML_SCHEMAV_CVC_ENUMERATION_VALID; |
| 14006 | if (fireErrors) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14007 | xmlSchemaVFacetErr(ctxt, ret, node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14008 | value, 0, type, NULL, NULL, NULL, NULL, NULL); |
| 14009 | } else if (retFacet < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14010 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14011 | "Internal error: xmlSchemaValidateFacetsInternal, " |
| 14012 | "validating facet of type '%s'.\n", |
| 14013 | BAD_CAST "enumeration", NULL); |
| 14014 | ret = -1; |
| 14015 | } |
| 14016 | } |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14017 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14018 | if (ret >= 0) { |
| 14019 | /* |
| 14020 | * Process patters. Pattern facets are ORed at type level |
| 14021 | * and ANDed if derived. Walk the base type axis. |
| 14022 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14023 | tmpType = type; |
| 14024 | facet = NULL; |
| 14025 | do { |
| 14026 | retFacet = 0; |
| 14027 | for (facetLink = tmpType->facetSet; facetLink != NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14028 | facetLink = facetLink->next) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14029 | if (facetLink->facet->type != XML_SCHEMA_FACET_PATTERN) |
| 14030 | continue; |
| 14031 | retFacet = xmlSchemaValidateFacet(biType, facetLink->facet, |
| 14032 | value, ctxt->value); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14033 | if (retFacet == 0) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14034 | break; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14035 | else if (retFacet < 0) { |
| 14036 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
| 14037 | "Internal error: xmlSchemaValidateFacetsInternal, " |
| 14038 | "validating 'pattern' facet '%s' of type '%s'.\n", |
| 14039 | facetLink->facet->value, tmpType->name); |
| 14040 | ret = -1; |
| 14041 | break; |
| 14042 | } else |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14043 | /* Save the last non-validating facet. */ |
| 14044 | facet = facetLink->facet; |
| 14045 | } |
| 14046 | if (retFacet != 0) |
| 14047 | break; |
| 14048 | tmpType = tmpType->baseType; |
| 14049 | } while ((tmpType != NULL) && (tmpType->type != XML_SCHEMA_TYPE_BASIC)); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14050 | if (retFacet > 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14051 | ret = XML_SCHEMAV_CVC_PATTERN_VALID; |
| 14052 | if (fireErrors) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14053 | xmlSchemaVFacetErr(ctxt, ret, node, value, 0, type, facet, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14054 | NULL, NULL, NULL, NULL); |
| 14055 | } |
| 14056 | } |
| 14057 | } |
| 14058 | |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14059 | return (ret); |
| 14060 | } |
| 14061 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14062 | /************************************************************************ |
| 14063 | * * |
| 14064 | * Simple type validation * |
| 14065 | * * |
| 14066 | ************************************************************************/ |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 14067 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14068 | |
| 14069 | /************************************************************************ |
| 14070 | * * |
| 14071 | * DOM Validation code * |
| 14072 | * * |
| 14073 | ************************************************************************/ |
| 14074 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14075 | static int xmlSchemaValidateAttributes(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14076 | xmlNodePtr elem, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14077 | xmlSchemaTypePtr type); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14078 | static int xmlSchemaValidateElementByType(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14079 | xmlSchemaTypePtr type, |
| 14080 | int valSimpleContent); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14081 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14082 | |
| 14083 | /** |
| 14084 | * xmlSchemaFreeAttrStates: |
| 14085 | * @state: a list of attribute states |
| 14086 | * |
| 14087 | * Free the given list of attribute states |
| 14088 | * |
| 14089 | */ |
| 14090 | static void |
| 14091 | xmlSchemaFreeAttributeStates(xmlSchemaAttrStatePtr state) |
| 14092 | { |
| 14093 | xmlSchemaAttrStatePtr tmp; |
| 14094 | while (state != NULL) { |
| 14095 | tmp = state; |
| 14096 | state = state->next; |
| 14097 | xmlFree(tmp); |
| 14098 | } |
| 14099 | } |
| 14100 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14101 | /** |
| 14102 | * xmlSchemaRegisterAttributes: |
| 14103 | * @ctxt: a schema validation context |
| 14104 | * @attrs: a list of attributes |
| 14105 | * |
| 14106 | * Register the list of attributes as the set to be validated on that element |
| 14107 | * |
| 14108 | * Returns -1 in case of error, 0 otherwise |
| 14109 | */ |
| 14110 | static int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14111 | xmlSchemaRegisterAttributes(xmlSchemaValidCtxtPtr ctxt, xmlAttrPtr attrs) |
| 14112 | { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14113 | xmlSchemaAttrStatePtr tmp; |
| 14114 | |
| 14115 | ctxt->attr = NULL; |
| 14116 | ctxt->attrTop = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14117 | while (attrs != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14118 | if ((attrs->ns != NULL) && |
| 14119 | (xmlStrEqual(attrs->ns->href, xmlSchemaInstanceNs))) { |
| 14120 | attrs = attrs->next; |
| 14121 | continue; |
| 14122 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14123 | tmp = (xmlSchemaAttrStatePtr) |
| 14124 | xmlMalloc(sizeof(xmlSchemaAttrState)); |
| 14125 | if (tmp == NULL) { |
| 14126 | xmlSchemaVErrMemory(ctxt, "registering attributes", NULL); |
| 14127 | return (-1); |
| 14128 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14129 | tmp->attr = attrs; |
| 14130 | tmp->state = XML_SCHEMAS_ATTR_UNKNOWN; |
| 14131 | tmp->next = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14132 | tmp->decl = NULL; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14133 | if (ctxt->attr == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14134 | ctxt->attr = tmp; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14135 | else |
| 14136 | ctxt->attrTop->next = tmp; |
| 14137 | ctxt->attrTop = tmp; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14138 | attrs = attrs->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14139 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14140 | return (0); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14141 | } |
| 14142 | |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 14143 | #if 0 /* Currently not used */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14144 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14145 | * xmlSchemaValidateCheckNodeList |
| 14146 | * @nodelist: the list of nodes |
| 14147 | * |
| 14148 | * Check the node list is only made of text nodes and entities pointing |
| 14149 | * to text nodes |
| 14150 | * |
| 14151 | * Returns 1 if true, 0 if false and -1 in case of error |
| 14152 | */ |
| 14153 | static int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14154 | xmlSchemaValidateCheckNodeList(xmlNodePtr nodelist) |
| 14155 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14156 | while (nodelist != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14157 | if (nodelist->type == XML_ENTITY_REF_NODE) { |
| 14158 | TODO /* implement recursion in the entity content */ |
| 14159 | } |
| 14160 | if ((nodelist->type != XML_TEXT_NODE) && |
| 14161 | (nodelist->type != XML_COMMENT_NODE) && |
| 14162 | (nodelist->type != XML_PI_NODE) && |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 14163 | (nodelist->type != XML_CDATA_SECTION_NODE)) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14164 | return (0); |
| 14165 | } |
| 14166 | nodelist = nodelist->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14167 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14168 | return (1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14169 | } |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 14170 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14171 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14172 | static void |
| 14173 | xmlSchemaPostSchemaAssembleFixup(xmlSchemaParserCtxtPtr ctxt) |
| 14174 | { |
| 14175 | int i, nbItems; |
| 14176 | xmlSchemaTypePtr item, *items; |
| 14177 | |
| 14178 | |
| 14179 | /* |
| 14180 | * During the Assemble of the schema ctxt->curItems has |
| 14181 | * been filled with the relevant new items. Fix those up. |
| 14182 | */ |
| 14183 | nbItems = ctxt->assemble->nbItems; |
| 14184 | items = (xmlSchemaTypePtr *) ctxt->assemble->items; |
| 14185 | |
| 14186 | for (i = 0; i < nbItems; i++) { |
| 14187 | item = items[i]; |
| 14188 | switch (item->type) { |
| 14189 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 14190 | xmlSchemaAttrFixup((xmlSchemaAttributePtr) item, ctxt, NULL); |
| 14191 | break; |
| 14192 | case XML_SCHEMA_TYPE_ELEMENT: |
| 14193 | xmlSchemaRefFixupCallback((xmlSchemaElementPtr) item, ctxt, |
| 14194 | NULL, NULL, NULL); |
| 14195 | break; |
| 14196 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
| 14197 | xmlSchemaAttrGrpFixup((xmlSchemaAttributeGroupPtr) item, |
| 14198 | ctxt, NULL); |
| 14199 | break; |
| 14200 | case XML_SCHEMA_TYPE_GROUP: |
| 14201 | xmlSchemaGroupDefFixup(item, ctxt, NULL); |
| 14202 | default: |
| 14203 | break; |
| 14204 | } |
| 14205 | } |
| 14206 | /* |
| 14207 | * Circularity checks. |
| 14208 | */ |
| 14209 | for (i = 0; i < nbItems; i++) { |
| 14210 | item = items[i]; |
| 14211 | switch (item->type) { |
| 14212 | case XML_SCHEMA_TYPE_GROUP: |
| 14213 | xmlSchemaCheckGroupDefCircular(item, ctxt, NULL); |
| 14214 | break; |
| 14215 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
| 14216 | xmlSchemaCheckAttributeGroupCircular( |
| 14217 | (xmlSchemaAttributeGroupPtr) item, ctxt, NULL); |
| 14218 | break; |
| 14219 | default: |
| 14220 | break; |
| 14221 | } |
| 14222 | } |
| 14223 | /* |
| 14224 | * Fixup for all other item. |
| 14225 | * TODO: Hmm, not sure if starting from complex/simple types, |
| 14226 | * all subsequent items will be reached. |
| 14227 | */ |
| 14228 | for (i = 0; i < nbItems; i++) { |
| 14229 | item = items[i]; |
| 14230 | switch (item->type) { |
| 14231 | case XML_SCHEMA_TYPE_SIMPLE: |
| 14232 | case XML_SCHEMA_TYPE_COMPLEX: |
| 14233 | xmlSchemaTypeFixup(item, ctxt, NULL); |
| 14234 | break; |
| 14235 | default: |
| 14236 | break; |
| 14237 | } |
| 14238 | } |
| 14239 | /* |
| 14240 | * Check facet values. Note that facets are |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 14241 | * hold by simple type components only (and |
| 14242 | * by complex types in the current implementation). |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14243 | */ |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 14244 | /* OLD: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14245 | for (i = 0; i < nbItems; i++) { |
| 14246 | item = items[i]; |
| 14247 | switch (item->type) { |
| 14248 | case XML_SCHEMA_TYPE_SIMPLE: |
| 14249 | case XML_SCHEMA_TYPE_COMPLEX: |
| 14250 | xmlSchemaCheckDefaults(item, ctxt, NULL); |
| 14251 | break; |
| 14252 | default: |
| 14253 | break; |
| 14254 | } |
| 14255 | } |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 14256 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14257 | /* |
| 14258 | * Build the content model for complex types. |
| 14259 | */ |
| 14260 | for (i = 0; i < nbItems; i++) { |
| 14261 | item = items[i]; |
| 14262 | switch (item->type) { |
| 14263 | case XML_SCHEMA_TYPE_COMPLEX: |
| 14264 | xmlSchemaBuildContentModel(item, ctxt, NULL); |
| 14265 | break; |
| 14266 | default: |
| 14267 | break; |
| 14268 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14269 | } |
| 14270 | /* |
| 14271 | * Validate value contraint values. |
| 14272 | */ |
| 14273 | for (i = 0; i < nbItems; i++) { |
| 14274 | item = items[i]; |
| 14275 | switch (item->type) { |
| 14276 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 14277 | xmlSchemaCheckAttrValConstr((xmlSchemaAttributePtr) item, ctxt, NULL); |
| 14278 | break; |
| 14279 | case XML_SCHEMA_TYPE_ELEMENT: |
| 14280 | xmlSchemaCheckElemValConstr((xmlSchemaElementPtr) item, ctxt, NULL); |
| 14281 | break; |
| 14282 | default: |
| 14283 | break; |
| 14284 | } |
| 14285 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14286 | } |
| 14287 | |
| 14288 | /** |
| 14289 | * xmlSchemaAssembleByLocation: |
| 14290 | * @pctxt: a schema parser context |
| 14291 | * @vctxt: a schema validation context |
| 14292 | * @schema: the existing schema |
| 14293 | * @node: the node that fired the assembling |
| 14294 | * @nsName: the namespace name of the new schema |
| 14295 | * @location: the location of the schema |
| 14296 | * |
| 14297 | * Expands an existing schema by an additional schema. |
| 14298 | * |
| 14299 | * Returns 0 if the new schema is correct, a positive error code |
| 14300 | * number otherwise and -1 in case of an internal or API error. |
| 14301 | */ |
| 14302 | static int |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14303 | xmlSchemaAssembleByLocation(xmlSchemaValidCtxtPtr vctxt, |
| 14304 | xmlSchemaPtr schema, |
| 14305 | xmlNodePtr node, |
| 14306 | const xmlChar *nsName, |
| 14307 | const xmlChar *location) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14308 | { |
| 14309 | const xmlChar *targetNs, *oldtns; |
| 14310 | xmlDocPtr doc, olddoc; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14311 | int oldflags, ret = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14312 | xmlNodePtr docElem; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14313 | xmlSchemaParserCtxtPtr pctxt; |
| 14314 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14315 | /* |
| 14316 | * This should be used: |
| 14317 | * 1. on <import>(s) |
| 14318 | * 2. if requested by the validated instance |
| 14319 | * 3. if requested via the API |
| 14320 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14321 | if ((vctxt == NULL) || (schema == NULL)) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14322 | return (-1); |
| 14323 | /* |
| 14324 | * Create a temporary parser context. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14325 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14326 | if ((vctxt->pctxt == NULL) && |
| 14327 | (xmlSchemaCreatePCtxtOnVCtxt(vctxt) == -1)) { |
| 14328 | xmlSchemaVErr(vctxt, node, |
| 14329 | XML_SCHEMAV_INTERNAL, |
| 14330 | "Internal error: xmlSchemaAssembleByLocation, " |
| 14331 | "failed to create a temp. parser context.\n", |
| 14332 | NULL, NULL); |
| 14333 | return (-1); |
| 14334 | } |
| 14335 | pctxt = vctxt->pctxt; |
| 14336 | /* |
| 14337 | * Set the counter to produce unique names for anonymous items. |
| 14338 | */ |
| 14339 | pctxt->counter = schema->counter; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14340 | /* |
| 14341 | * Acquire the schema document. |
| 14342 | */ |
| 14343 | ret = xmlSchemaAcquireSchemaDoc(pctxt, schema, node, |
| 14344 | nsName, location, &doc, &targetNs, 0); |
| 14345 | if (ret != 0) { |
| 14346 | if (doc != NULL) |
| 14347 | xmlFreeDoc(doc); |
| 14348 | } else if (doc != NULL) { |
| 14349 | docElem = xmlDocGetRootElement(doc); |
| 14350 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14351 | * Create new assemble info. |
| 14352 | */ |
| 14353 | if (pctxt->assemble == NULL) { |
| 14354 | pctxt->assemble = xmlSchemaNewAssemble(); |
| 14355 | if (pctxt->assemble == NULL) { |
| 14356 | xmlSchemaVErrMemory(vctxt, |
| 14357 | "Memory error: xmlSchemaAssembleByLocation, " |
| 14358 | "allocating assemble info", NULL); |
| 14359 | xmlFreeDoc(doc); |
| 14360 | return (-1); |
| 14361 | } |
| 14362 | } |
| 14363 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14364 | * Save and reset the context & schema. |
| 14365 | */ |
| 14366 | oldflags = schema->flags; |
| 14367 | oldtns = schema->targetNamespace; |
| 14368 | olddoc = schema->doc; |
| 14369 | |
| 14370 | xmlSchemaClearSchemaDefaults(schema); |
| 14371 | schema->targetNamespace = targetNs; |
| 14372 | /* schema->nbCurItems = 0; */ |
| 14373 | pctxt->schema = schema; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14374 | pctxt->ctxtType = NULL; |
| 14375 | pctxt->parentItem = NULL; |
| 14376 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14377 | xmlSchemaParseSchemaDefaults(pctxt, schema, docElem); |
| 14378 | xmlSchemaParseSchemaTopLevel(pctxt, schema, docElem->children); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14379 | xmlSchemaPostSchemaAssembleFixup(pctxt); |
| 14380 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14381 | * Set the counter of items. |
| 14382 | */ |
| 14383 | schema->counter = pctxt->counter; |
| 14384 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14385 | * Free the list of assembled components. |
| 14386 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14387 | pctxt->assemble->nbItems = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14388 | /* |
| 14389 | * Restore the context & schema. |
| 14390 | */ |
| 14391 | schema->flags = oldflags; |
| 14392 | schema->targetNamespace = oldtns; |
| 14393 | schema->doc = olddoc; |
| 14394 | ret = pctxt->err; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14395 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14396 | return (ret); |
| 14397 | } |
| 14398 | |
| 14399 | /** |
| 14400 | * xmlSchemaAssembleByXSIAttr: |
| 14401 | * @vctxt: a schema validation context |
| 14402 | * @xsiAttr: an xsi attribute |
| 14403 | * @noNamespace: whether a schema with no target namespace is exptected |
| 14404 | * |
| 14405 | * Expands an existing schema by an additional schema using |
| 14406 | * the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attribute |
| 14407 | * of an instance. If xsi:noNamespaceSchemaLocation is used, @noNamespace |
| 14408 | * must be set to 1. |
| 14409 | * |
| 14410 | * Returns 0 if the new schema is correct, a positive error code |
| 14411 | * number otherwise and -1 in case of an internal or API error. |
| 14412 | */ |
| 14413 | static int |
| 14414 | xmlSchemaAssembleByXSIAttr(xmlSchemaValidCtxtPtr vctxt, |
| 14415 | xmlAttrPtr xsiAttr, |
| 14416 | int noNamespace) |
| 14417 | { |
| 14418 | xmlChar *value; |
| 14419 | const xmlChar *cur, *end; |
| 14420 | const xmlChar *nsname = NULL, *location; |
| 14421 | int count = 0; |
| 14422 | int ret = 0; |
| 14423 | |
| 14424 | if (xsiAttr == NULL) { |
| 14425 | xmlSchemaVCustomErr(vctxt, XML_SCHEMAV_INTERNAL, |
| 14426 | NULL, NULL, |
| 14427 | "Internal error: xmlSchemaAssembleByXSIAttr, " |
| 14428 | "bad arguments", NULL); |
| 14429 | return (-1); |
| 14430 | } |
| 14431 | /* |
| 14432 | * Parse the value; we will assume an even number of values |
| 14433 | * to be given (this is how Xerces and XSV work). |
| 14434 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14435 | value = xmlNodeGetContent((xmlNodePtr) xsiAttr); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14436 | cur = value; |
| 14437 | do { |
| 14438 | if (noNamespace != 1) { |
| 14439 | /* |
| 14440 | * Get the namespace name. |
| 14441 | */ |
| 14442 | while (IS_BLANK_CH(*cur)) |
| 14443 | cur++; |
| 14444 | end = cur; |
| 14445 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 14446 | end++; |
| 14447 | if (end == cur) |
| 14448 | break; |
| 14449 | count++; |
| 14450 | nsname = xmlDictLookup(vctxt->schema->dict, cur, end - cur); |
| 14451 | cur = end; |
| 14452 | } |
| 14453 | /* |
| 14454 | * Get the URI. |
| 14455 | */ |
| 14456 | while (IS_BLANK_CH(*cur)) |
| 14457 | cur++; |
| 14458 | end = cur; |
| 14459 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 14460 | end++; |
| 14461 | if (end == cur) |
| 14462 | break; |
| 14463 | count++; |
| 14464 | location = xmlDictLookup(vctxt->schema->dict, cur, end - cur); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14465 | cur = end; |
| 14466 | ret = xmlSchemaAssembleByLocation(vctxt, vctxt->schema, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14467 | xsiAttr->parent, nsname, location); |
| 14468 | if (ret == -1) { |
| 14469 | xmlSchemaVCustomErr(vctxt, |
| 14470 | XML_SCHEMAV_INTERNAL, |
| 14471 | (xmlNodePtr) xsiAttr, NULL, |
| 14472 | "Internal error: xmlSchemaAssembleByXSIAttr, " |
| 14473 | "assembling schemata", NULL); |
| 14474 | if (value != NULL) |
| 14475 | xmlFree(value); |
| 14476 | return (-1); |
| 14477 | } |
| 14478 | } while (*cur != 0); |
| 14479 | if (value != NULL) |
| 14480 | xmlFree(value); |
| 14481 | return (ret); |
| 14482 | } |
| 14483 | |
| 14484 | /** |
| 14485 | * xmlSchemaAssembleByXSIElem: |
| 14486 | * @vctxt: a schema validation context |
| 14487 | * @elem: an element node possibly holding xsi attributes |
| 14488 | * @noNamespace: whether a schema with no target namespace is exptected |
| 14489 | * |
| 14490 | * Assembles an existing schema by an additional schema using |
| 14491 | * the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attributes |
| 14492 | * of the given @elem. |
| 14493 | * |
| 14494 | * Returns 0 if the new schema is correct, a positive error code |
| 14495 | * number otherwise and -1 in case of an internal or API error. |
| 14496 | */ |
| 14497 | static int |
| 14498 | xmlSchemaAssembleByXSIElem(xmlSchemaValidCtxtPtr vctxt, |
| 14499 | xmlNodePtr elem) |
| 14500 | { |
| 14501 | int ret = 0, retNs = 0; |
| 14502 | xmlAttrPtr attr; |
| 14503 | |
| 14504 | attr = xmlHasNsProp(elem, BAD_CAST "schemaLocation", xmlSchemaInstanceNs); |
| 14505 | if (attr != NULL) { |
| 14506 | retNs = xmlSchemaAssembleByXSIAttr(vctxt, attr, 0); |
| 14507 | if (retNs == -1) |
| 14508 | return (-1); |
| 14509 | } |
| 14510 | attr = xmlHasNsProp(elem, BAD_CAST "noNamespaceSchemaLocation", xmlSchemaInstanceNs); |
| 14511 | if (attr != NULL) { |
| 14512 | ret = xmlSchemaAssembleByXSIAttr(vctxt, attr, 1); |
| 14513 | if (ret == -1) |
| 14514 | return (-1); |
| 14515 | } |
| 14516 | if (retNs != 0) |
| 14517 | return (retNs); |
| 14518 | else |
| 14519 | return (ret); |
| 14520 | } |
| 14521 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14522 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14523 | * xmlSchemaValidateCallback: |
| 14524 | * @ctxt: a schema validation context |
| 14525 | * @name: the name of the element detected (might be NULL) |
| 14526 | * @type: the type |
| 14527 | * |
| 14528 | * A transition has been made in the automata associated to an element |
| 14529 | * content model |
| 14530 | */ |
| 14531 | static void |
| 14532 | xmlSchemaValidateCallback(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14533 | const xmlChar * name ATTRIBUTE_UNUSED, |
| 14534 | xmlSchemaTypePtr type, xmlNodePtr node) |
| 14535 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14536 | xmlSchemaTypePtr oldtype = ctxt->type; |
| 14537 | xmlNodePtr oldnode = ctxt->node; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14538 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14539 | #ifdef DEBUG_CONTENT |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 14540 | xmlGenericError(xmlGenericErrorContext, |
| 14541 | "xmlSchemaValidateCallback: %s, %s, %s\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14542 | name, type->name, node->name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14543 | #endif |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14544 | /* |
| 14545 | * @type->type will be XML_SCHEMA_TYPE_ANY or XML_SCHEMA_TYPE_ELEMENT. |
| 14546 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14547 | ctxt->type = type; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14548 | ctxt->node = node; |
| 14549 | ctxt->cur = node->children; |
| 14550 | /* |
| 14551 | * Assemble new schemata using xsi. |
| 14552 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14553 | if (ctxt->xsiAssemble) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14554 | int ret; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14555 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14556 | ret = xmlSchemaAssembleByXSIElem(ctxt, ctxt->node); |
| 14557 | if (ret == -1) { |
| 14558 | xmlSchemaVCustomErr(ctxt, |
| 14559 | XML_SCHEMAV_INTERNAL, |
| 14560 | ctxt->node, NULL, |
| 14561 | "Internal error: xmlSchemaValidateElement, " |
| 14562 | "assembling schema by xsi", NULL); |
| 14563 | return; |
| 14564 | } |
| 14565 | /* |
| 14566 | * NOTE: We won't react on schema parser errors here. |
| 14567 | * TODO: But a warning would be nice. |
| 14568 | */ |
| 14569 | } |
| 14570 | switch (type->type) { |
| 14571 | case XML_SCHEMA_TYPE_ELEMENT: { |
| 14572 | /* |
| 14573 | * NOTE: The build of the content model |
| 14574 | * (xmlSchemaBuildAContentModel) ensures that the element |
| 14575 | * declaration (and not a reference to it) will be given. |
| 14576 | */ |
| 14577 | if (((xmlSchemaElementPtr) ctxt->type)->ref != NULL) { |
| 14578 | /* |
| 14579 | * This is paranoid coding ;-)... it should not |
| 14580 | * happen here any more. |
| 14581 | */ |
| 14582 | xmlSchemaVCustomErr(ctxt, |
| 14583 | XML_SCHEMAV_INTERNAL, |
| 14584 | node, NULL, |
| 14585 | "Internal error: xmlSchemaValidateCallback, " |
| 14586 | "element declaration 'reference' encountered, " |
| 14587 | "but an element declaration was expected", |
| 14588 | NULL); |
| 14589 | return; |
| 14590 | } |
| 14591 | xmlSchemaValidateElementByDeclaration(ctxt, |
| 14592 | (xmlSchemaElementPtr) type); |
| 14593 | break; |
| 14594 | } |
| 14595 | case XML_SCHEMA_TYPE_ANY: |
| 14596 | xmlSchemaValidateElementByWildcard(ctxt, type); |
| 14597 | break; |
| 14598 | default: |
| 14599 | break; |
| 14600 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14601 | ctxt->type = oldtype; |
| 14602 | ctxt->node = oldnode; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14603 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14604 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14605 | /** |
| 14606 | * xmlSchemaValidateSimpleTypeValue: |
| 14607 | * @ctxt: a schema validation context |
| 14608 | * @value: the value to be validated |
| 14609 | * @fireErrors: shall errors be reported? |
| 14610 | * @applyFacets: shall facets be applied? |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14611 | * @normalize: shall the value be normalized? |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14612 | * @checkNodes: shall the content nodes be checked? |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14613 | * |
| 14614 | * Validates a value by the given type (user derived or built-in). |
| 14615 | * |
| 14616 | * Returns 0 if the value is valid, a positive error code |
| 14617 | * number otherwise and -1 in case of an internal or API error. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14618 | */ |
| 14619 | static int |
| 14620 | xmlSchemaValidateSimpleTypeValue(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14621 | xmlSchemaTypePtr type, |
| 14622 | const xmlChar *value, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14623 | int fireErrors, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14624 | int applyFacets, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14625 | int normalize, |
| 14626 | int checkNodes) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14627 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14628 | xmlNodePtr node; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14629 | int ret = 0; |
| 14630 | xmlChar *normValue = NULL; |
| 14631 | int wtsp; |
| 14632 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14633 | node = ctxt->node; |
| 14634 | /* Save the current whitespace normalization type. */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14635 | wtsp = ctxt->valueWS; |
| 14636 | /* |
| 14637 | * Normalize the value. |
| 14638 | */ |
| 14639 | if (normalize && |
| 14640 | (ctxt->valueWS != XML_SCHEMAS_VAL_WTSP_COLLAPSE)) { |
| 14641 | int norm = xmlSchemaGetWhiteSpaceFacetValue(type); |
| 14642 | |
| 14643 | if ((norm != -1) && (norm > ctxt->valueWS)) { |
| 14644 | if (norm == XML_SCHEMAS_VAL_WTSP_COLLAPSE) |
| 14645 | normValue = xmlSchemaCollapseString(value); |
| 14646 | else |
| 14647 | normValue = xmlSchemaWhiteSpaceReplace(value); |
| 14648 | ctxt->valueWS = norm; |
| 14649 | if (normValue != NULL) |
| 14650 | value = (const xmlChar *) normValue; |
| 14651 | } |
| 14652 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14653 | /* |
| 14654 | * The nodes of a content must be checked only once, |
| 14655 | * this is not working since list types will fire this |
| 14656 | * multiple times. |
| 14657 | */ |
| 14658 | if ((checkNodes == 1) && (ctxt->cur != NULL)) { |
| 14659 | xmlNodePtr cur = ctxt->cur; |
| 14660 | |
| 14661 | do { |
| 14662 | switch (cur->type) { |
| 14663 | case XML_TEXT_NODE: |
| 14664 | case XML_CDATA_SECTION_NODE: |
| 14665 | case XML_PI_NODE: |
| 14666 | case XML_COMMENT_NODE: |
| 14667 | case XML_XINCLUDE_START: |
| 14668 | case XML_XINCLUDE_END: |
| 14669 | break; |
| 14670 | case XML_ENTITY_REF_NODE: |
| 14671 | case XML_ENTITY_NODE: |
| 14672 | /* TODO: Scour the entities for illegal nodes. */ |
| 14673 | TODO break; |
| 14674 | case XML_ELEMENT_NODE: { |
| 14675 | /* NOTE: Changed to an internal error, since the |
| 14676 | * existence of an element node will be already checked in |
| 14677 | * xmlSchemaValidateElementBySimpleType and in |
| 14678 | * xmlSchemaValidateElementByComplexType. |
| 14679 | */ |
| 14680 | xmlSchemaVCustomErr(ctxt, |
| 14681 | XML_SCHEMAV_INTERNAL, |
| 14682 | /* XML_SCHEMAS_ERR_INVALIDELEM, */ |
| 14683 | node, type, |
| 14684 | "Element '%s' found in simple type content", |
| 14685 | cur->name); |
| 14686 | return (XML_SCHEMAV_INTERNAL); |
| 14687 | } |
| 14688 | case XML_ATTRIBUTE_NODE: |
| 14689 | case XML_DOCUMENT_NODE: |
| 14690 | case XML_DOCUMENT_TYPE_NODE: |
| 14691 | case XML_DOCUMENT_FRAG_NODE: |
| 14692 | case XML_NOTATION_NODE: |
| 14693 | case XML_HTML_DOCUMENT_NODE: |
| 14694 | case XML_DTD_NODE: |
| 14695 | case XML_ELEMENT_DECL: |
| 14696 | case XML_ATTRIBUTE_DECL: |
| 14697 | case XML_ENTITY_DECL: |
| 14698 | case XML_NAMESPACE_DECL: |
| 14699 | #ifdef LIBXML_DOCB_ENABLED |
| 14700 | case XML_DOCB_DOCUMENT_NODE: |
| 14701 | #endif |
| 14702 | xmlSchemaVCustomErr(ctxt, |
| 14703 | XML_SCHEMAV_INTERNAL, |
| 14704 | /* XML_SCHEMAS_ERR_INVALIDELEM, */ |
| 14705 | node, NULL, |
| 14706 | "Node of unexpected type found in simple type content", |
| 14707 | NULL); |
| 14708 | return (XML_SCHEMAV_INTERNAL); |
| 14709 | } |
| 14710 | cur = cur->next; |
| 14711 | } while (cur != NULL); |
| 14712 | } |
| 14713 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14714 | if (type->type == XML_SCHEMA_TYPE_COMPLEX) { |
| 14715 | xmlSchemaTypePtr base, anyType; |
| 14716 | |
| 14717 | anyType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 14718 | |
| 14719 | base = type->baseType; |
| 14720 | while ((base != NULL) && |
| 14721 | (base->type != XML_SCHEMA_TYPE_SIMPLE) && |
| 14722 | (base->type != XML_SCHEMA_TYPE_BASIC) && |
| 14723 | (base != anyType)) { |
| 14724 | base = base->baseType; |
| 14725 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14726 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, base, value, 1, 0, 1, 0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14727 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14728 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14729 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 14730 | "validating complex type '%s'\n", |
| 14731 | type->name, NULL); |
| 14732 | } else if ((ret == 0) && (applyFacets) && (type->facetSet != NULL)) { |
| 14733 | /* |
| 14734 | * Check facets. |
| 14735 | */ |
| 14736 | /* |
| 14737 | * This is somehow not nice, since if an error occurs |
| 14738 | * the reported type will be the complex type; the spec |
| 14739 | * wants a simple type to be created on the complex type |
| 14740 | * if it has a simple content. For now we have to live with |
| 14741 | * it. |
| 14742 | */ |
| 14743 | ret = xmlSchemaValidateFacetsInternal(ctxt, type, |
| 14744 | value, 0, fireErrors); |
| 14745 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14746 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14747 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 14748 | "validating facets of complex type '%s'\n", |
| 14749 | type->name, NULL); |
| 14750 | } else if (ret > 0) { |
| 14751 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14752 | if (fireErrors) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14753 | xmlSchemaVSimpleTypeErr(ctxt, ret, node, value, type); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 14754 | } |
| 14755 | } |
| 14756 | } else if (type->type == XML_SCHEMA_TYPE_BASIC) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14757 | |
| 14758 | if (ctxt->value != NULL) { |
| 14759 | xmlSchemaFreeValue(ctxt->value); |
| 14760 | ctxt->value = NULL; |
| 14761 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14762 | /* |
| 14763 | * STREAM-READ-CHILDREN. |
| 14764 | */ |
| 14765 | ret = xmlSchemaValPredefTypeNodeNoNorm(type, value, &(ctxt->value), node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14766 | if (ret > 0) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14767 | if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) |
| 14768 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
| 14769 | else |
| 14770 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14771 | if (fireErrors) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14772 | xmlSchemaVSimpleTypeErr(ctxt, ret, node, value, type); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14773 | } else if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14774 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14775 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14776 | "validating built-in type '%s'\n", type->name, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14777 | } |
| 14778 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) { |
| 14779 | /* 1.2.1 if {variety} is ·atomic· then the string must ·match· |
| 14780 | * a literal in the ·lexical space· of {base type definition} |
| 14781 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14782 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, type->baseType, value, 0, 0, 0, 0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14783 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14784 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14785 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14786 | "validating atomic simple type '%s'\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14787 | type->name, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14788 | } else if (ret > 0) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14789 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14790 | if (fireErrors) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14791 | xmlSchemaVSimpleTypeErr(ctxt, ret, node, value, type); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14792 | } else if ((applyFacets) && (type->facetSet != NULL)) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14793 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14794 | * Check facets. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14795 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14796 | ret = xmlSchemaValidateFacetsInternal(ctxt, type, |
| 14797 | value, 0, fireErrors); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14798 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14799 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14800 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14801 | "validating facets of atomic simple type '%s'\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14802 | type->name, NULL); |
| 14803 | } else if (ret > 0) { |
| 14804 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14805 | /* |
| 14806 | Disabled, since the facet validation already reports errors. |
| 14807 | if (fireErrors) |
| 14808 | xmlSchemaVSimpleTypeErr(ctxt, ret, ctxt->cur, value, type); |
| 14809 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14810 | } |
| 14811 | } |
| 14812 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 14813 | |
| 14814 | xmlSchemaTypePtr tmpType; |
| 14815 | const xmlChar *cur, *end; |
| 14816 | xmlChar *tmp; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14817 | unsigned long len = 0; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14818 | |
| 14819 | /* 1.2.2 if {variety} is ·list· then the string must be a sequence |
| 14820 | * of white space separated tokens, each of which ·match·es a literal |
| 14821 | * in the ·lexical space· of {item type definition} |
| 14822 | */ |
Kasimier T. Buchcik | de938cd | 2005-01-13 12:25:57 +0000 | [diff] [blame^] | 14823 | |
| 14824 | if (value == NULL) |
| 14825 | value = BAD_CAST ""; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14826 | tmpType = xmlSchemaGetListSimpleTypeItemType(type); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14827 | cur = value; |
| 14828 | do { |
| 14829 | while (IS_BLANK_CH(*cur)) |
| 14830 | cur++; |
| 14831 | end = cur; |
| 14832 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 14833 | end++; |
| 14834 | if (end == cur) |
| 14835 | break; |
| 14836 | tmp = xmlStrndup(cur, end - cur); |
| 14837 | len++; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14838 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, tmpType, tmp, 0, 1, 0, 0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14839 | xmlFree(tmp); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14840 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14841 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14842 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 14843 | "validating an item of list simple type '%s'\n", |
| 14844 | type->name, NULL); |
| 14845 | break; |
| 14846 | } else if (ret > 0) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14847 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14848 | if (fireErrors) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14849 | xmlSchemaVSimpleTypeErr(ctxt, ret, node, value, type); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14850 | break; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14851 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14852 | cur = end; |
| 14853 | } while (*cur != 0); |
| 14854 | /* |
| 14855 | * Check facets. |
| 14856 | */ |
| 14857 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14858 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14859 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14860 | "validating list simple type '%s'\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14861 | type->name, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14862 | } else if ((ret == 0) && (applyFacets)) { |
| 14863 | ret = xmlSchemaValidateFacetsInternal(ctxt, type, |
| 14864 | value, len, fireErrors); |
| 14865 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14866 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14867 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 14868 | "validating facets of list simple type '%s'\n", |
| 14869 | type->name, NULL); |
| 14870 | } else if (ret > 0) { |
| 14871 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14872 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14873 | Disabled, since the facet validation already reports errors. |
| 14874 | if (fireErrors) |
| 14875 | xmlSchemaVSimpleTypeErr(ctxt, ret, ctxt->cur, value, type); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14876 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14877 | } |
| 14878 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14879 | } |
| 14880 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
| 14881 | xmlSchemaTypeLinkPtr memberLink; |
| 14882 | |
| 14883 | /* |
| 14884 | * TODO: For all datatypes ·derived· by ·union· whiteSpace does |
| 14885 | * not apply directly; however, the normalization behavior of ·union· |
| 14886 | * types is controlled by the value of whiteSpace on that one of the |
| 14887 | * ·memberTypes· against which the ·union· is successfully validated. |
| 14888 | * |
| 14889 | * This means that the value is normalized by the first validating |
| 14890 | * member type, then the facets of the union type are applied. This |
| 14891 | * needs changing of the value! |
| 14892 | */ |
| 14893 | |
| 14894 | /* |
| 14895 | * 1.2.3 if {variety} is ·union· then the string must ·match· a |
| 14896 | * literal in the ·lexical space· of at least one member of |
| 14897 | * {member type definitions} |
| 14898 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14899 | #ifdef DEBUG_UNION_VALIDATION |
| 14900 | printf("Union ST : '%s'\n", (const char *) type->name); |
| 14901 | printf(" fireErrors : %d\n", fireErrors); |
| 14902 | printf(" applyFacets: %d\n", applyFacets); |
| 14903 | #endif |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14904 | memberLink = xmlSchemaGetUnionSimpleTypeMemberTypes(type); |
| 14905 | if (memberLink == NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14906 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14907 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14908 | "union simple type '%s' has no member types\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14909 | type->name, NULL); |
| 14910 | ret = -1; |
| 14911 | } |
| 14912 | if (ret == 0) { |
| 14913 | while (memberLink != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14914 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, memberLink->type, |
| 14915 | value, 0, 1, 1, 0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14916 | if ((ret <= 0) || (ret == 0)) |
| 14917 | break; |
| 14918 | memberLink = memberLink->next; |
| 14919 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14920 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14921 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14922 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14923 | "validating members of union simple type '%s'\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14924 | type->name, NULL); |
| 14925 | } else if (ret > 0) { |
| 14926 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14927 | if (fireErrors) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14928 | xmlSchemaVSimpleTypeErr(ctxt, ret, node, value, type); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14929 | } |
| 14930 | } |
| 14931 | /* |
| 14932 | * Apply facets (pattern, enumeration). |
| 14933 | */ |
| 14934 | if ((ret == 0) && (applyFacets) && (type->facetSet != NULL)) { |
| 14935 | int mws; |
| 14936 | /* |
| 14937 | * The normalization behavior of ·union· types is controlled by |
| 14938 | * the value of whiteSpace on that one of the ·memberTypes· |
| 14939 | * against which the ·union· is successfully validated. |
| 14940 | */ |
| 14941 | if (normValue != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14942 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14943 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 14944 | "the value was already normalized for the union simple " |
| 14945 | "type '%s'.\n", type->name, NULL); |
| 14946 | } |
| 14947 | mws = xmlSchemaGetWhiteSpaceFacetValue(memberLink->type); |
| 14948 | if (mws > ctxt->valueWS) { |
| 14949 | if (mws == XML_SCHEMAS_VAL_WTSP_COLLAPSE) |
| 14950 | normValue = xmlSchemaCollapseString(value); |
| 14951 | else |
| 14952 | normValue = xmlSchemaWhiteSpaceReplace(value); |
| 14953 | if (normValue != NULL) |
| 14954 | value = (const xmlChar *) normValue; |
| 14955 | } |
| 14956 | |
| 14957 | ret = xmlSchemaValidateFacetsInternal(ctxt, type, |
| 14958 | value, 0, fireErrors); |
| 14959 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14960 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14961 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 14962 | "validating facets of union simple type '%s'\n", |
| 14963 | type->name, NULL); |
| 14964 | } else if (ret > 0) { |
| 14965 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3; |
| 14966 | /* |
| 14967 | if (fireErrors) |
| 14968 | xmlSchemaVSimpleTypeErr(ctxt, ret, ctxt->cur, value, type); |
| 14969 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14970 | } |
| 14971 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14972 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14973 | ctxt->valueWS = wtsp; |
| 14974 | if (normValue != NULL) |
| 14975 | xmlFree(normValue); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14976 | return (ret); |
| 14977 | } |
| 14978 | |
| 14979 | /** |
| 14980 | * xmlSchemaValidateSimpleTypeElement: |
| 14981 | * @ctxt: a schema validation context |
| 14982 | * @node: the element node to be validated. |
| 14983 | * |
| 14984 | * Validate the element against a simple type. |
| 14985 | * |
| 14986 | * Returns 0 if the element is valid, a positive error code |
| 14987 | * number otherwise and -1 in case of an internal or API error. |
| 14988 | */ |
| 14989 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14990 | xmlSchemaValidateElementBySimpleType(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14991 | xmlSchemaTypePtr type, |
| 14992 | int valSimpleContent) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14993 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14994 | xmlSchemaTypePtr oldtype; |
| 14995 | xmlNodePtr node; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14996 | xmlAttrPtr attr; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 14997 | xmlNodePtr cur; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14998 | int ret = 0, retval = 0; |
| 14999 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15000 | if ((ctxt == NULL) || (type == NULL)) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15001 | xmlSchemaVCustomErr(ctxt, XML_SCHEMAV_INTERNAL, NULL, NULL, |
| 15002 | "Internal error: xmlSchemaValidateElementBySimpleType, " |
| 15003 | "bad arguments", NULL); |
| 15004 | return (-1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15005 | } |
| 15006 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15007 | oldtype = ctxt->type; |
| 15008 | node = ctxt->node; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15009 | /* |
| 15010 | * cvc-type: 3.1.2 The element information item must have no element |
| 15011 | * information item [children]. |
| 15012 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15013 | /* |
| 15014 | * STREAM: Child nodes are processed. |
| 15015 | */ |
| 15016 | cur = node->children; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15017 | while (cur != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15018 | /* |
| 15019 | * TODO: Entities, will they produce elements as well? |
| 15020 | */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15021 | if (cur->type == XML_ELEMENT_NODE) { |
| 15022 | xmlSchemaVCustomErr(ctxt, |
| 15023 | XML_SCHEMAV_CVC_TYPE_3_1_2, |
| 15024 | node, type, |
| 15025 | "No element content allowed", NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15026 | ret = XML_SCHEMAV_CVC_TYPE_3_1_2; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15027 | } |
| 15028 | cur = cur->next; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15029 | } |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15030 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15031 | /* |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15032 | * cvc-type 3.1.1: |
| 15033 | * |
| 15034 | * The attributes of must be empty, excepting those whose namespace name |
| 15035 | * is identical to http://www.w3.org/2001/XMLSchema-instance and whose local |
| 15036 | * name is one of type, nil, schemaLocation or noNamespaceSchemaLocation. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15037 | */ |
| 15038 | /* |
| 15039 | * STREAM: Attribute nodes are processed. |
| 15040 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15041 | attr = node->properties; |
| 15042 | while (attr != NULL) { |
| 15043 | if ((attr->ns == NULL) || |
| 15044 | (!xmlStrEqual(attr->ns->href, xmlSchemaInstanceNs)) || |
| 15045 | ((!xmlStrEqual(attr->name, BAD_CAST "type")) && |
| 15046 | (!xmlStrEqual(attr->name, BAD_CAST "nil")) && |
| 15047 | (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation")) && |
| 15048 | (!xmlStrEqual |
| 15049 | (attr->name, BAD_CAST "noNamespaceSchemaLocation")))) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15050 | xmlSchemaVIllegalAttrErr(ctxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15051 | XML_SCHEMAV_CVC_TYPE_3_1_1, attr); |
| 15052 | ret = XML_SCHEMAV_CVC_TYPE_3_1_1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15053 | } |
| 15054 | attr = attr->next; |
| 15055 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15056 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15057 | * This will skip validation if the type is 'anySimpleType' and |
| 15058 | * if the value was already validated (e.g. default values). |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15059 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15060 | if ((valSimpleContent == 1) && |
| 15061 | ((type->type != XML_SCHEMA_TYPE_BASIC) || |
| 15062 | (type->builtInType != XML_SCHEMAS_ANYSIMPLETYPE))) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15063 | xmlChar *value; |
| 15064 | |
| 15065 | value = xmlNodeGetContent(node); |
| 15066 | /* |
| 15067 | * NOTE: This call will not check the content nodes, since |
| 15068 | * this should be checked here already. |
| 15069 | */ |
| 15070 | retval = xmlSchemaValidateSimpleTypeValue(ctxt, type, value, |
| 15071 | 1, 1, 1, 0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15072 | if (value != NULL) |
| 15073 | xmlFree(value); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15074 | if (retval != 0) |
| 15075 | ret = retval; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15076 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15077 | ctxt->type = oldtype; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15078 | return (ret); |
| 15079 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15080 | |
| 15081 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15082 | * xmlSchemaValQNameAcquire: |
| 15083 | * @value: the lexical represantation of the QName value |
| 15084 | * @node: the node to search for the corresponding namespace declaration |
| 15085 | * @nsName: the resulting namespace name if found |
| 15086 | * |
| 15087 | * Checks that a value conforms to the lexical space of the type QName; |
| 15088 | * if valid, the corresponding namespace name is searched and retured |
| 15089 | * as a copy in @nsName. The local name is returned in @localName as |
| 15090 | * a copy. |
| 15091 | * |
| 15092 | * Returns 0 if valid, 1 if not valid by type, 2 if no corresponding |
| 15093 | * namespace declaration was found in scope; -1 in case of an internal or |
| 15094 | * API error. |
| 15095 | */ |
| 15096 | static int |
| 15097 | xmlSchemaValQNameAcquire(const xmlChar *value, xmlNodePtr node, |
| 15098 | xmlChar **nsName, xmlChar **localName) |
| 15099 | { |
| 15100 | int ret; |
| 15101 | xmlChar *local = NULL; |
| 15102 | |
| 15103 | if ((nsName == NULL) || (localName == NULL) || (node == NULL)) |
| 15104 | return (-1); |
| 15105 | *nsName = NULL; |
| 15106 | *localName = NULL; |
| 15107 | ret = xmlValidateQName(value, 1); |
| 15108 | if (ret == 0) { |
| 15109 | xmlChar *prefix; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15110 | xmlNsPtr ns; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15111 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15112 | /* |
| 15113 | * NOTE: xmlSplitQName2 will return a duplicated |
| 15114 | * string. |
| 15115 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15116 | local = xmlSplitQName2(value, &prefix); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15117 | if (local == NULL) |
| 15118 | local = xmlStrdup(value); |
| 15119 | ns = xmlSearchNs(node->doc, node, prefix); |
| 15120 | /* |
| 15121 | * A namespace need not to be found if the prefix is NULL. |
| 15122 | */ |
| 15123 | if (ns != NULL) { |
| 15124 | /* |
| 15125 | * TODO: Is it necessary to duplicate the URI here? |
| 15126 | */ |
| 15127 | *nsName = xmlStrdup(ns->href); |
| 15128 | } else if (prefix != NULL) { |
| 15129 | xmlFree(prefix); |
| 15130 | if (local != NULL) |
| 15131 | xmlFree(local); |
| 15132 | return (2); |
| 15133 | } |
| 15134 | *localName = local; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15135 | if (prefix != NULL) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15136 | xmlFree(prefix); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15137 | } else |
| 15138 | return (1); |
| 15139 | return (ret); |
| 15140 | } |
| 15141 | |
| 15142 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15143 | * xmlSchemaHasElemContent: |
| 15144 | * @node: the node |
| 15145 | * |
| 15146 | * Scours the content of the given node for element |
| 15147 | * nodes. |
| 15148 | * |
| 15149 | * Returns 1 if an element node is found, |
| 15150 | * 0 otherwise. |
| 15151 | */ |
| 15152 | static int |
| 15153 | xmlSchemaHasElemContent(xmlNodePtr node) |
| 15154 | { |
| 15155 | if (node == NULL) |
| 15156 | return (0); |
| 15157 | node = node->children; |
| 15158 | while (node != NULL) { |
| 15159 | if (node->type == XML_ELEMENT_NODE) |
| 15160 | return (1); |
| 15161 | node = node->next; |
| 15162 | } |
| 15163 | return (0); |
| 15164 | } |
| 15165 | /** |
| 15166 | * xmlSchemaHasElemOrCharContent: |
| 15167 | * @node: the node |
| 15168 | * |
| 15169 | * Scours the content of the given node for element |
| 15170 | * and character nodes. |
| 15171 | * |
| 15172 | * Returns 1 if an element or character node is found, |
| 15173 | * 0 otherwise. |
| 15174 | */ |
| 15175 | static int |
| 15176 | xmlSchemaHasElemOrCharContent(xmlNodePtr node) |
| 15177 | { |
| 15178 | if (node == NULL) |
| 15179 | return (0); |
| 15180 | node = node->children; |
| 15181 | while (node != NULL) { |
| 15182 | switch (node->type) { |
| 15183 | case XML_ELEMENT_NODE: |
| 15184 | /* |
| 15185 | * TODO: Ask Daniel if these are all character nodes. |
| 15186 | */ |
| 15187 | case XML_TEXT_NODE: |
| 15188 | case XML_CDATA_SECTION_NODE: |
| 15189 | /* |
| 15190 | * TODO: How XML_ENTITY_NODEs evaluated? |
| 15191 | */ |
| 15192 | case XML_ENTITY_REF_NODE: |
| 15193 | case XML_ENTITY_NODE: |
| 15194 | return (1); |
| 15195 | break; |
| 15196 | default: |
| 15197 | break; |
| 15198 | } |
| 15199 | node = node->next; |
| 15200 | } |
| 15201 | return (0); |
| 15202 | } |
| 15203 | |
| 15204 | |
| 15205 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15206 | * xmlSchemaValidateElementByDeclaration: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15207 | * @ctxt: a schema validation context |
| 15208 | * @node: the top node. |
| 15209 | * |
| 15210 | * Validate the content of an element type. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15211 | * Validation Rule: Element Locally Valid (Element) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15212 | * |
| 15213 | * Returns 0 if the element is schemas valid, a positive error code |
| 15214 | * number otherwise and -1 in case of internal or API error. |
| 15215 | */ |
| 15216 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15217 | xmlSchemaValidateElementByDeclaration(xmlSchemaValidCtxtPtr ctxt, |
| 15218 | xmlSchemaElementPtr elemDecl) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15219 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15220 | xmlNodePtr elem; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15221 | int ret = 0; |
| 15222 | xmlSchemaTypePtr actualType = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15223 | xmlAttrPtr attr; |
| 15224 | xmlChar *attrValue; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15225 | int nilled = 0, elemHasContent = -1; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15226 | |
| 15227 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15228 | * This one is called by xmlSchemaValidateElementByWildcardInternal, |
| 15229 | * xmlSchemaValidateElementByAnyType and xmlSchemaValidateElement. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15230 | * Note that @elemDecl will be the declaration and never the |
| 15231 | * reference to a declaration. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15232 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15233 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15234 | if (ctxt == NULL) { |
| 15235 | xmlSchemaVErr(ctxt, NULL, XML_SCHEMAV_INTERNAL, |
| 15236 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 15237 | "bad arguments.\n", |
| 15238 | NULL, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15239 | return (-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15240 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15241 | |
| 15242 | elem = ctxt->node; |
| 15243 | |
| 15244 | /* |
| 15245 | * cvc-elt (3.3.4) : 1 |
| 15246 | */ |
| 15247 | if (elemDecl == NULL) { |
| 15248 | xmlSchemaVCustomErr(ctxt, |
| 15249 | XML_SCHEMAV_CVC_ELT_1, |
| 15250 | elem, NULL, |
| 15251 | "No matching declaration available", NULL); |
| 15252 | return (ctxt->err); |
| 15253 | } |
| 15254 | /* |
| 15255 | * cvc-elt (3.3.4) : 2 |
| 15256 | */ |
| 15257 | if (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT) { |
| 15258 | xmlSchemaVCustomErr(ctxt, |
| 15259 | XML_SCHEMAV_CVC_ELT_2, |
| 15260 | elem, NULL, |
| 15261 | "The element declaration is abstract", NULL); |
| 15262 | return (ctxt->err); |
| 15263 | } |
| 15264 | |
| 15265 | /* |
| 15266 | * cvc-elt (3.3.4) : 3 |
| 15267 | * Handle 'xsi:nil'. |
| 15268 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15269 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15270 | attr = xmlHasNsProp(elem, BAD_CAST "nil", xmlSchemaInstanceNs); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15271 | if (attr != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15272 | attrValue = xmlNodeGetContent((xmlNodePtr) attr); |
| 15273 | ctxt->node = (xmlNodePtr) attr; |
| 15274 | ctxt->cur = attr->children; |
| 15275 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, |
| 15276 | xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN), |
| 15277 | BAD_CAST attrValue, 1, 1, 1, 1); |
| 15278 | ctxt->node = elem; |
| 15279 | ctxt->type = (xmlSchemaTypePtr) elemDecl; |
| 15280 | if (ret < 0) { |
| 15281 | xmlSchemaVCustomErr(ctxt, |
| 15282 | XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15283 | (xmlNodePtr) attr, (xmlSchemaTypePtr) elemDecl, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15284 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 15285 | "validating the attribute 'xsi:nil'", NULL); |
| 15286 | if (attrValue != NULL) |
| 15287 | xmlFree(attrValue); |
| 15288 | return (-1); |
| 15289 | } |
| 15290 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_NILLABLE) == 0) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15291 | /* |
| 15292 | * cvc-elt (3.3.4) : 3.1 |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15293 | */ |
| 15294 | xmlSchemaVCustomErr(ctxt, |
| 15295 | XML_SCHEMAV_CVC_ELT_3_1, |
| 15296 | elem, NULL, |
| 15297 | "The element is not 'nillable'", NULL); |
| 15298 | } else { |
| 15299 | if (xmlStrEqual(BAD_CAST attrValue, BAD_CAST "true") || |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15300 | xmlStrEqual(BAD_CAST attrValue, BAD_CAST "1")) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15301 | ret = 0; |
| 15302 | /* |
| 15303 | * cvc-elt (3.3.4) : 3.2.1 |
| 15304 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15305 | elemHasContent = xmlSchemaHasElemOrCharContent(elem); |
| 15306 | if (elemHasContent == 1) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15307 | xmlSchemaVCustomErr(ctxt, |
| 15308 | XML_SCHEMAV_CVC_ELT_3_2_1, |
| 15309 | /* XML_SCHEMAS_ERR_NOTEMPTY, */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15310 | elem, (xmlSchemaTypePtr) elemDecl, |
| 15311 | "The 'nilled' element must have no character or " |
| 15312 | "element content", NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15313 | ret = XML_SCHEMAV_CVC_ELT_3_2_1; |
| 15314 | } |
| 15315 | /* |
| 15316 | * cvc-elt (3.3.4) : 3.2.2 |
| 15317 | */ |
| 15318 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_FIXED) && |
| 15319 | (elemDecl->value != NULL)) { |
| 15320 | xmlSchemaVCustomErr(ctxt, XML_SCHEMAV_CVC_ELT_3_2_2, |
| 15321 | /* XML_SCHEMAS_ERR_HAVEDEFAULT, */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15322 | elem, (xmlSchemaTypePtr) elemDecl, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15323 | "There is a fixed value constraint defined for " |
| 15324 | "the 'nilled' element", NULL); |
| 15325 | ret = XML_SCHEMAV_CVC_ELT_3_2_2; |
| 15326 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15327 | if (ret == 0) |
| 15328 | nilled = 1; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15329 | } |
| 15330 | } |
| 15331 | if (attrValue != NULL) |
| 15332 | xmlFree(attrValue); |
| 15333 | } |
| 15334 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15335 | |
| 15336 | actualType = elemDecl->subtypes; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15337 | /* |
| 15338 | * cvc-elt (3.3.4) : 4 |
| 15339 | * Handle 'xsi:type'. |
| 15340 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15341 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15342 | attr = xmlHasNsProp(elem, BAD_CAST "type", xmlSchemaInstanceNs); |
| 15343 | if (attr != NULL) { |
| 15344 | xmlChar *nsName = NULL, *local = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15345 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15346 | /* |
| 15347 | * TODO: We should report a *warning* that the type was overriden |
| 15348 | * by the instance. |
| 15349 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15350 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15351 | /* |
| 15352 | * cvc-elt (3.3.4) : 4.1 |
| 15353 | */ |
| 15354 | attrValue = xmlNodeGetContent((xmlNodePtr) attr); |
| 15355 | ret = xmlSchemaValQNameAcquire(attrValue, attr->parent, |
| 15356 | &nsName, &local); |
| 15357 | if (ret < 0) { |
| 15358 | xmlSchemaVCustomErr(ctxt, |
| 15359 | XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15360 | (xmlNodePtr) attr, (xmlSchemaTypePtr) elemDecl, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15361 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 15362 | "validating the attribute 'xsi:type'", NULL);; |
| 15363 | FREE_AND_NULL(attrValue) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15364 | FREE_AND_NULL(nsName) |
| 15365 | FREE_AND_NULL(local) |
| 15366 | return (-1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15367 | } else if (ret == 1) { |
| 15368 | xmlSchemaVSimpleTypeErr(ctxt, |
| 15369 | XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, |
| 15370 | (xmlNodePtr) attr, attrValue, |
| 15371 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME)); |
| 15372 | } else if (ret == 2) { |
| 15373 | xmlSchemaVCustomErr(ctxt, |
| 15374 | XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, |
| 15375 | (xmlNodePtr) attr, |
| 15376 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
| 15377 | "The QName value '%s' has no " |
| 15378 | "corresponding namespace declaration in scope", |
| 15379 | attrValue); |
| 15380 | } else { |
| 15381 | /* |
| 15382 | * cvc-elt (3.3.4) : 4.2 |
| 15383 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15384 | actualType = xmlSchemaGetType(ctxt->schema, local, nsName); |
| 15385 | if (actualType == NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15386 | xmlChar *strA = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15387 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15388 | xmlSchemaVCustomErr(ctxt, |
| 15389 | XML_SCHEMAV_CVC_ELT_4_2, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15390 | (xmlNodePtr) attr, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15391 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
| 15392 | "The value %s does not resolve to a type " |
| 15393 | "definition", |
| 15394 | xmlSchemaFormatNsUriLocal(&strA, nsName, local)); |
| 15395 | FREE_AND_NULL(strA); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15396 | } else { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15397 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15398 | * URGENT TODO: cvc-elt (3.3.4) : 4.3 (Type Derivation OK) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15399 | */ |
| 15400 | } |
| 15401 | } |
| 15402 | FREE_AND_NULL(attrValue) |
| 15403 | FREE_AND_NULL(nsName) |
| 15404 | FREE_AND_NULL(local) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15405 | } |
| 15406 | /* TODO: Change the handling of missing types according to |
| 15407 | * the spec. |
| 15408 | */ |
| 15409 | if (actualType == NULL) { |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 15410 | xmlSchemaVCustomErr(ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15411 | XML_SCHEMAV_CVC_TYPE_1, |
| 15412 | elem, (xmlSchemaTypePtr) elemDecl, |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 15413 | "The type definition is absent", NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15414 | return (XML_SCHEMAV_CVC_TYPE_1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15415 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15416 | |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15417 | /* |
| 15418 | * TODO: Since this should be already checked by the content model automaton, |
| 15419 | * and we want to get rid of the XML_SCHEMAS_ERR... types, the error code |
| 15420 | * has been changed to XML_SCHEMAV_INTERNAL. |
| 15421 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15422 | /* |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15423 | if (child == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15424 | if (decl->minOccurs > 0) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15425 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15426 | XML_SCHEMAS_ERR_MISSING, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15427 | "Element %s: missing child %s\n", |
| 15428 | node->name, decl->name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15429 | } |
| 15430 | return (ctxt->err); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15431 | } |
| 15432 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15433 | /* |
| 15434 | * Verify the element matches |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15435 | * TODO, FIXME: Can this still happen here? Isn't this already checked |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15436 | * by the content model automaton? |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15437 | if (!xmlStrEqual(child->name, decl->name)) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15438 | xmlSchemaVErr3(ctxt, node, XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15439 | XML_SCHEMAS_ERR_WRONGELEM, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15440 | "Element %s: missing child %s found %s\n", |
| 15441 | node->name, decl->name, child->name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15442 | return (ctxt->err); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15443 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15444 | */ |
| 15445 | if (elemHasContent == -1) |
| 15446 | elemHasContent = xmlSchemaHasElemOrCharContent(elem); |
| 15447 | /* |
| 15448 | * cvc-elt (3.3.4) : 5 |
| 15449 | * The appropriate case among the following must be true: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15450 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15451 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15452 | * cvc-elt (3.3.4) : 5.1 |
| 15453 | * If the declaration has a {value constraint}, |
| 15454 | * the item has neither element nor character [children] and |
| 15455 | * clause 3.2 has not applied, then all of the following must be true: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15456 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15457 | if ((elemHasContent == 0) && (nilled == 0) && (elemDecl->value != NULL)) { |
| 15458 | /* |
| 15459 | * cvc-elt (3.3.4) : 5.1.1 |
| 15460 | * If the ·actual type definition· is a ·local type definition· |
| 15461 | * then the canonical lexical representation of the {value constraint} |
| 15462 | * value must be a valid default for the ·actual type definition· as |
| 15463 | * defined in Element Default Valid (Immediate) (§3.3.6). |
| 15464 | */ |
| 15465 | /* |
| 15466 | * NOTE: 'local' above means types aquired by xsi:type. |
| 15467 | */ |
| 15468 | ret = 0; |
| 15469 | if (actualType != elemDecl->subtypes) { |
| 15470 | xmlSchemaCreatePCtxtOnVCtxt(ctxt); |
| 15471 | ret = xmlSchemaCheckCOSValidDefault(ctxt->pctxt, ctxt, actualType, |
| 15472 | elemDecl->value, NULL); |
| 15473 | if (ret < 0) { |
| 15474 | xmlSchemaVCustomErr(ctxt, |
| 15475 | XML_SCHEMAV_INTERNAL, |
| 15476 | elem, actualType, |
| 15477 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 15478 | "validating a default value", NULL); |
| 15479 | return (-1); |
| 15480 | } |
| 15481 | } |
| 15482 | /* |
| 15483 | * cvc-elt (3.3.4) : 5.1.2 |
| 15484 | * The element information item with the canonical lexical |
| 15485 | * representation of the {value constraint} value used as its |
| 15486 | * ·normalized value· must be ·valid· with respect to the |
| 15487 | * ·actual type definition· as defined by Element Locally Valid (Type) |
| 15488 | * (§3.3.4). |
| 15489 | */ |
| 15490 | /* |
| 15491 | * Disable validation of the simple content, since it was already |
| 15492 | * done above. |
| 15493 | */ |
| 15494 | if (ret == 0) { |
| 15495 | if (actualType != elemDecl->subtypes) |
| 15496 | ret = xmlSchemaValidateElementByType(ctxt, actualType, 0); |
| 15497 | else |
| 15498 | ret = xmlSchemaValidateElementByType(ctxt, actualType, 0); |
| 15499 | ctxt->node = elem; |
| 15500 | if (ret < 0) { |
| 15501 | xmlSchemaVCustomErr(ctxt, |
| 15502 | XML_SCHEMAV_INTERNAL, |
| 15503 | elem, actualType, |
| 15504 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 15505 | "validating against the type", NULL); |
| 15506 | return (-1); |
| 15507 | } |
| 15508 | /* |
| 15509 | * PSVI: Create a text node on the instance element. |
| 15510 | */ |
| 15511 | if (ctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) { |
| 15512 | xmlNodePtr textChild; |
| 15513 | |
| 15514 | textChild = xmlNewText(elemDecl->value); |
| 15515 | if (textChild == NULL) { |
| 15516 | xmlSchemaVCustomErr(ctxt, |
| 15517 | XML_SCHEMAV_INTERNAL, |
| 15518 | elem, actualType, |
| 15519 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 15520 | "could not create a default text node for the instance", |
| 15521 | NULL); |
| 15522 | } else |
| 15523 | xmlAddChild(elem, textChild); |
| 15524 | } |
| 15525 | } |
| 15526 | |
| 15527 | } else { |
| 15528 | /* |
| 15529 | * 5.2.1 The element information item must be ·valid· with respect |
| 15530 | * to the ·actual type definition· as defined by Element Locally |
| 15531 | * Valid (Type) (§3.3.4). |
| 15532 | */ |
| 15533 | ret = xmlSchemaValidateElementByType(ctxt, actualType, 1); |
| 15534 | ctxt->node = elem; |
| 15535 | if (ret < 0) { |
| 15536 | xmlSchemaVCustomErr(ctxt, |
| 15537 | XML_SCHEMAV_INTERNAL, |
| 15538 | elem, actualType, |
| 15539 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 15540 | "validating a default value", NULL); |
| 15541 | return (-1); |
| 15542 | } |
| 15543 | /* |
| 15544 | * 5.2.2 If there is a fixed {value constraint} and clause 3.2 has |
| 15545 | * not applied, all of the following must be true: |
| 15546 | */ |
| 15547 | |
| 15548 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_FIXED) && (nilled == 0)) { |
| 15549 | /* |
| 15550 | * 5.2.2.1 The element information item must have no element |
| 15551 | * information item [children]. |
| 15552 | * |
| 15553 | * TODO REDUNDANT: If the actual type exists, the above call to |
| 15554 | * xmlSchemaValidateElementByType will already check for element |
| 15555 | * nodes. |
| 15556 | */ |
| 15557 | if (xmlSchemaHasElemContent(elem)) { |
| 15558 | xmlSchemaVCustomErr(ctxt, |
| 15559 | XML_SCHEMAV_CVC_ELT_5_2_2_1, |
| 15560 | elem, (xmlSchemaTypePtr) elemDecl, |
| 15561 | "Elements in the content are not allowed if it is " |
| 15562 | "constrained by a fixed value", NULL); |
| 15563 | } else { |
| 15564 | /* |
| 15565 | * 5.2.2.2 The appropriate case among the following must |
| 15566 | * be true: |
| 15567 | */ |
| 15568 | |
| 15569 | if (actualType->contentType == XML_SCHEMA_CONTENT_MIXED) { |
| 15570 | xmlChar *value; |
| 15571 | /* |
| 15572 | * 5.2.2.2.1 If the {content type} of the ·actual type |
| 15573 | * definition· is mixed, then the *initial value* of the |
| 15574 | * item must match the canonical lexical representation |
| 15575 | * of the {value constraint} value. |
| 15576 | * |
| 15577 | * ... the *initial value* of an element information |
| 15578 | * item is the string composed of, in order, the |
| 15579 | * [character code] of each character information item in |
| 15580 | * the [children] of that element information item. |
| 15581 | */ |
| 15582 | value = xmlNodeListGetString(elem->doc, elem->children, 1); |
| 15583 | if (! xmlStrEqual(BAD_CAST value, elemDecl->value)) { |
| 15584 | /* |
| 15585 | * TODO: Report invalid & expected values as well. |
| 15586 | * TODO: Implement the cononical stuff. |
| 15587 | */ |
| 15588 | xmlSchemaVCustomErr(ctxt, |
| 15589 | XML_SCHEMAV_CVC_ELT_5_2_2_2_1, |
| 15590 | elem, (xmlSchemaTypePtr) elemDecl, |
| 15591 | "The value does not match the cononical " |
| 15592 | "lexical representation of the fixed constraint", |
| 15593 | NULL); |
| 15594 | } |
| 15595 | if (value != NULL) |
| 15596 | xmlFree(value); |
| 15597 | } else if ((actualType->contentType == |
| 15598 | XML_SCHEMA_CONTENT_SIMPLE) || |
| 15599 | (actualType->contentType == XML_SCHEMA_CONTENT_BASIC)) { |
| 15600 | xmlChar *value; |
| 15601 | |
| 15602 | /* |
| 15603 | * 5.2.2.2.2 If the {content type} of the ·actual type |
| 15604 | * definition· is a simple type definition, then the |
| 15605 | * *actual value* of the item must match the canonical |
| 15606 | * lexical representation of the {value constraint} value. |
| 15607 | */ |
| 15608 | /* |
| 15609 | * TODO: *actual value* is the normalized value, impl. this. |
| 15610 | * TODO: Report invalid & expected values as well. |
| 15611 | * TODO: Implement the cononical stuff. |
| 15612 | * |
| 15613 | */ |
| 15614 | value = xmlNodeListGetString(elem->doc, elem->children, 1); |
| 15615 | if (! xmlStrEqual(BAD_CAST value, elemDecl->value)) { |
| 15616 | xmlSchemaVCustomErr(ctxt, |
| 15617 | XML_SCHEMAV_CVC_ELT_5_2_2_2_2, |
| 15618 | elem, (xmlSchemaTypePtr) elemDecl, |
| 15619 | "The normalized value does not match the cononical " |
| 15620 | "lexical representation of the fixed constraint", |
| 15621 | NULL); |
| 15622 | } |
| 15623 | if (value != NULL) |
| 15624 | xmlFree(value); |
| 15625 | |
| 15626 | } |
| 15627 | /* |
| 15628 | * TODO: What if the content type is not 'mixed' or simple? |
| 15629 | */ |
| 15630 | |
| 15631 | } |
| 15632 | |
| 15633 | } |
| 15634 | } |
| 15635 | |
| 15636 | /* |
| 15637 | * TODO: 6 The element information item must be ·valid· with respect to each of |
| 15638 | * the {identity-constraint definitions} as per Identity-constraint |
| 15639 | * Satisfied (§3.11.4). |
| 15640 | */ |
| 15641 | |
| 15642 | /* |
| 15643 | * TODO: 7 If the element information item is the ·validation root·, it must be |
| 15644 | * ·valid· per Validation Root Valid (ID/IDREF) (§3.3.4). |
| 15645 | */ |
| 15646 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15647 | return (ctxt->err); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15648 | } |
| 15649 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15650 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15651 | * xmlSchemaValidateElementByWildcardInternal: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15652 | * @ctxt: a schema validation context |
| 15653 | * @node: the top node. |
| 15654 | * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15655 | * Represents the recursive portion of xmlSchemaValidateElementByWildcard. |
| 15656 | * Not intended to be used by other functions. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15657 | * |
| 15658 | * Returns 0 if the element is valid, a positive error code |
| 15659 | * number otherwise and -1 in case of an internal error. |
| 15660 | */ |
| 15661 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15662 | xmlSchemaValidateElementByWildcardInternal(xmlSchemaValidCtxtPtr ctxt, |
| 15663 | xmlSchemaWildcardPtr wild, |
| 15664 | xmlNodePtr node) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15665 | { |
| 15666 | const xmlChar *uri; |
| 15667 | int ret = 0; |
| 15668 | xmlNodePtr child; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15669 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15670 | if (ctxt->xsiAssemble) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15671 | ret = xmlSchemaAssembleByXSIElem(ctxt, ctxt->node); |
| 15672 | if (ret == -1) { |
| 15673 | xmlSchemaVCustomErr(ctxt, |
| 15674 | XML_SCHEMAV_INTERNAL, |
| 15675 | ctxt->node, NULL, |
| 15676 | "Internal error: xmlSchemaValidateElement, " |
| 15677 | "assembling schema by xsi", NULL); |
| 15678 | return (-1); |
| 15679 | } |
| 15680 | /* |
| 15681 | * NOTE: We won't react on schema parser errors here. |
| 15682 | * TODO: But a warning would be nice. |
| 15683 | */ |
| 15684 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15685 | if (wild->processContents != XML_SCHEMAS_ANY_SKIP) { |
| 15686 | xmlSchemaElementPtr decl = NULL; |
| 15687 | |
| 15688 | if (node->ns != NULL) |
| 15689 | decl = xmlHashLookup3(ctxt->schema->elemDecl, |
| 15690 | node->name, node->ns->href, NULL); |
| 15691 | else |
| 15692 | decl = xmlHashLookup3(ctxt->schema->elemDecl, node->name, NULL, NULL); |
| 15693 | if (decl != NULL) { |
| 15694 | ctxt->node = node; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15695 | ret = xmlSchemaValidateElementByDeclaration(ctxt, decl); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15696 | if (ret < 0) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15697 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15698 | "Internal error: xmlSchemaValidateAnyInternal, " |
| 15699 | "validating an element in the context of a wildcard.", |
| 15700 | NULL, NULL); |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 15701 | } |
| 15702 | return (ret); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15703 | } else if (wild->processContents == XML_SCHEMAS_ANY_STRICT) { |
| 15704 | /* TODO: Change to proper error code. */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15705 | xmlSchemaVWildcardErr(ctxt, XML_SCHEMAV_CVC_ELT_1, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15706 | node, wild, "No matching global declaration available"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15707 | return (ctxt->err); |
| 15708 | } |
| 15709 | } |
| 15710 | if (node->children != NULL) { |
| 15711 | child = node->children; |
| 15712 | do { |
| 15713 | if (child->type == XML_ELEMENT_NODE) { |
| 15714 | if (child->ns != NULL) |
| 15715 | uri = child->ns->href; |
| 15716 | else |
| 15717 | uri = NULL; |
| 15718 | if (xmlSchemaMatchesWildcardNs(wild, uri) == 0) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15719 | /* TODO: error code. */ |
| 15720 | xmlSchemaVWildcardErr(ctxt, XML_SCHEMAV_ELEMENT_CONTENT, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15721 | child, wild, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15722 | "The namespace of the element is not allowed"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15723 | return (ctxt->err); |
| 15724 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15725 | ret = xmlSchemaValidateElementByWildcardInternal(ctxt, |
| 15726 | wild, child); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15727 | if (ret != 0) |
| 15728 | return (ret); |
| 15729 | } |
| 15730 | child = child->next; |
| 15731 | } while (child != NULL); |
| 15732 | } |
| 15733 | return (0); |
| 15734 | } |
| 15735 | |
| 15736 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15737 | * xmlSchemaValidateElementContByWildcard: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15738 | * @ctxt: a schema validation context |
| 15739 | * |
| 15740 | * Returns 0 if the element is valid, a positive error code |
| 15741 | * number otherwise and -1 in case of an internal or API error. |
| 15742 | */ |
| 15743 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15744 | xmlSchemaValidateElementByWildcard(xmlSchemaValidCtxtPtr ctxt, |
| 15745 | xmlSchemaTypePtr type) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15746 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15747 | if ((type == NULL) || (type->type != XML_SCHEMA_TYPE_ANY) || |
| 15748 | (ctxt->node == NULL)) { |
| 15749 | xmlSchemaVCustomErr(ctxt, |
| 15750 | XML_SCHEMAV_INTERNAL, ctxt->node, NULL, |
| 15751 | "Internal error: xmlSchemaValidateElementByWildcard, " |
| 15752 | "bad arguments", NULL); |
| 15753 | return (-1); |
| 15754 | } |
| 15755 | return(xmlSchemaValidateElementByWildcardInternal(ctxt, |
| 15756 | type->attributeWildcard, ctxt->node)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15757 | } |
| 15758 | |
| 15759 | /** |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15760 | * xmlSchemaValidateAnyTypeContent: |
| 15761 | * @ctxt: a schema validation context |
| 15762 | * @node: the current element |
| 15763 | * |
| 15764 | * This one validates the content of an element of the type |
| 15765 | * 'anyType'. The process contents of the wildcard of 'anyType' is "lax", |
| 15766 | * thus elements in the subtree will be validated, if a corresponding |
| 15767 | * declaration in the schema exists. |
| 15768 | * |
| 15769 | * Returns 0 if the element and its subtree is valid, a positive error code |
| 15770 | * otherwise and -1 in case of an internal or API error. |
| 15771 | */ |
| 15772 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15773 | xmlSchemaValidateElementByAnyType(xmlSchemaValidCtxtPtr ctxt, |
| 15774 | xmlSchemaTypePtr type) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15775 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15776 | xmlSchemaTypePtr oldtype; |
| 15777 | xmlNodePtr top, cur; |
| 15778 | xmlSchemaElementPtr decl; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15779 | int skipContent, ret; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15780 | |
| 15781 | if ((type == NULL) || (ctxt->node == NULL)) |
| 15782 | return (-1); |
| 15783 | |
| 15784 | if (ctxt->node->children == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15785 | return (0); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15786 | |
| 15787 | oldtype = ctxt->type; |
| 15788 | top = ctxt->node; |
| 15789 | /* |
| 15790 | * STREAM: Child nodes are processed. |
| 15791 | */ |
| 15792 | cur = ctxt->node->children; |
| 15793 | while (cur != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15794 | skipContent = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15795 | if (cur->type == XML_ELEMENT_NODE) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15796 | /* |
| 15797 | * The process contents of the wildcard is "lax", thus |
| 15798 | * we need to validate the element if a declaration |
| 15799 | * exists. |
| 15800 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15801 | if (cur->ns != NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15802 | decl = xmlHashLookup3(ctxt->schema->elemDecl, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15803 | cur->name, cur->ns->href, NULL); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15804 | else |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15805 | decl = xmlHashLookup3(ctxt->schema->elemDecl, cur->name, NULL, NULL); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15806 | if (decl != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15807 | ctxt->node = cur; |
| 15808 | ret = xmlSchemaValidateElementByDeclaration(ctxt, decl); |
| 15809 | ctxt->node = top; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15810 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15811 | xmlSchemaVErr(ctxt, cur, XML_SCHEMAV_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15812 | "Internal error: xmlSchemaValidateAnyTypeContent, " |
| 15813 | "validating an element in the context of a wildcard.", |
| 15814 | NULL, NULL); |
| 15815 | return (ret); |
| 15816 | } else if (ret > 0) |
| 15817 | return (ret); |
| 15818 | skipContent = 1; |
| 15819 | } |
| 15820 | } |
| 15821 | /* |
| 15822 | * Browse the full subtree, deep first. |
| 15823 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15824 | if ((skipContent == 0) && (cur->children != NULL)) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15825 | /* deep first */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15826 | cur = cur->children; |
| 15827 | } else if ((cur != top) && (cur->next != NULL)) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15828 | /* then siblings */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15829 | cur = cur->next; |
| 15830 | } else if (cur != top) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15831 | /* go up to parents->next if needed */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15832 | while (cur != top) { |
| 15833 | if (cur->parent != NULL) |
| 15834 | cur = cur->parent; |
| 15835 | if ((cur != top) && (cur->next != NULL)) { |
| 15836 | cur = cur->next; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15837 | break; |
| 15838 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15839 | if (cur->parent == NULL) { |
| 15840 | cur = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15841 | break; |
| 15842 | } |
| 15843 | } |
| 15844 | /* exit condition */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15845 | if (cur == top) |
| 15846 | cur = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15847 | } else |
| 15848 | break; |
| 15849 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15850 | ctxt->type = oldtype; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15851 | return (0); |
| 15852 | } |
| 15853 | |
| 15854 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15855 | * xmlSchemaValidateElementByComplexType: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15856 | * @ctxt: a schema validation context |
| 15857 | * @node: the top node. |
| 15858 | * |
| 15859 | * Validate the content of an element expected to be a complex type type |
| 15860 | * xmlschema-1.html#cvc-complex-type |
| 15861 | * Validation Rule: Element Locally Valid (Complex Type) |
| 15862 | * |
| 15863 | * Returns 0 if the element is schemas valid, a positive error code |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15864 | * number otherwise and -1 in case of internal or API error. |
| 15865 | * Note on reported errors: Although it might be nice to report |
| 15866 | * the name of the simple/complex type, used to validate the content |
| 15867 | * of a node, it is quite unnecessary: for global defined types |
| 15868 | * the local name of the element is equal to the NCName of the type, |
| 15869 | * for local defined types it makes no sense to output the internal |
| 15870 | * computed name of the type. TODO: Instead, one should attach the |
| 15871 | * struct of the type involved to the error handler - this allows |
| 15872 | * the report of any additional information by the user. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15873 | */ |
| 15874 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15875 | xmlSchemaValidateElementByComplexType(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15876 | xmlSchemaTypePtr type, |
| 15877 | int valSimpleContent) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15878 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15879 | xmlSchemaTypePtr oldtype; |
| 15880 | xmlNodePtr elem, child; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15881 | int ret = 0; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15882 | const xmlChar *nsUri; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15883 | xmlSchemaAttrStatePtr attrs = NULL, attrTop = NULL; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15884 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15885 | if ((ctxt == NULL) || (type->type != XML_SCHEMA_TYPE_COMPLEX)) |
| 15886 | return (-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15887 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15888 | oldtype = ctxt->type; |
| 15889 | ctxt->type = type; |
| 15890 | elem = ctxt->node; |
| 15891 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15892 | /* |
| 15893 | * Verify the attributes |
| 15894 | */ |
| 15895 | /* |
| 15896 | * TODO: This "attrTop" thing is not needed any more. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15897 | */ |
| 15898 | /* NOTE: removed, since a check for abstract is |
| 15899 | * done in the cvc-type constraint. |
| 15900 | * |
| 15901 | * |
| 15902 | * if (type->flags & XML_SCHEMAS_TYPE_ABSTRACT) { |
| 15903 | * xmlSchemaVComplexTypeErr(ctxt, |
| 15904 | * XML_SCHEMAV_CVC_COMPLEX_TYPE_1, |
| 15905 | * elem, type, |
| 15906 | * "The type definition is abstract"); |
| 15907 | * return (XML_SCHEMAV_CVC_COMPLEX_TYPE_1); |
| 15908 | *} |
| 15909 | */ |
| 15910 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15911 | attrs = ctxt->attr; |
| 15912 | attrTop = ctxt->attrTop; |
| 15913 | /* |
| 15914 | * STREAM: Attribute nodes are processed. |
| 15915 | */ |
| 15916 | xmlSchemaRegisterAttributes(ctxt, elem->properties); |
| 15917 | xmlSchemaValidateAttributes(ctxt, elem, type); |
| 15918 | if (ctxt->attr != NULL) |
| 15919 | xmlSchemaFreeAttributeStates(ctxt->attr); |
| 15920 | ctxt->attr = attrs; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15921 | ctxt->attrTop = attrTop; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15922 | |
| 15923 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15924 | * TODO: This one creates a regexp even if no content |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15925 | * model was defined. Somehow ->contModel is always not NULL |
| 15926 | * for complex types, even if they are empty. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15927 | * TODO: Check if the obove still occurs. |
| 15928 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15929 | switch (type->contentType) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15930 | case XML_SCHEMA_CONTENT_EMPTY: { |
| 15931 | /* |
| 15932 | * 1 If the {content type} is empty, then the element information |
| 15933 | * item has no character or element information item [children]. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15934 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15935 | /* |
| 15936 | * TODO: Is the entity stuff correct? |
| 15937 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15938 | if (xmlSchemaHasElemOrCharContent(elem) == 1) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15939 | xmlSchemaVComplexTypeErr(ctxt, |
| 15940 | XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15941 | elem, type, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15942 | "Character or element content is not allowed, " |
| 15943 | "because the content type is empty"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15944 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15945 | break; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15946 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15947 | case XML_SCHEMA_CONTENT_MIXED: |
| 15948 | if ((type->subtypes == NULL) && |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15949 | (type->baseType->builtInType == XML_SCHEMAS_ANYTYPE)) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15950 | /* |
| 15951 | * The type has 'anyType' as its base and no content model |
| 15952 | * is defined -> use 'anyType' as the type to validate |
| 15953 | * against. |
| 15954 | */ |
| 15955 | ret = xmlSchemaValidateElementByAnyType(ctxt, type->baseType); |
| 15956 | /* TODO: Handle -1. */ |
| 15957 | break; |
| 15958 | } |
| 15959 | /* No break on purpose. */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15960 | case XML_SCHEMA_CONTENT_ELEMENTS: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15961 | { |
| 15962 | xmlRegExecCtxtPtr oldregexp = NULL; |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 15963 | xmlChar *values[10]; |
| 15964 | int terminal, nbval = 10, nbneg; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15965 | |
| 15966 | /* |
| 15967 | * Content model check initialization. |
| 15968 | */ |
| 15969 | if (type->contModel != NULL) { |
| 15970 | oldregexp = ctxt->regexp; |
| 15971 | ctxt->regexp = xmlRegNewExecCtxt(type->contModel, |
| 15972 | (xmlRegExecCallbacks) |
| 15973 | xmlSchemaValidateCallback, ctxt); |
| 15974 | #ifdef DEBUG_AUTOMATA |
| 15975 | xmlGenericError(xmlGenericErrorContext, "====> %s\n", elem->name); |
| 15976 | #endif |
| 15977 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15978 | /* |
| 15979 | * STREAM: Children are processed. |
| 15980 | */ |
| 15981 | child = elem->children; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15982 | while (child != NULL) { |
| 15983 | if (child->type == XML_ELEMENT_NODE) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15984 | if (child->ns != NULL) |
| 15985 | nsUri = child->ns->href; |
| 15986 | else |
| 15987 | nsUri = NULL; |
| 15988 | ret = xmlRegExecPushString2(ctxt->regexp, |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 15989 | child->name, nsUri, child); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15990 | /* |
| 15991 | * URGENT TODO: Could we anchor an error report |
| 15992 | * here to notify of invalid elements? |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 15993 | * TODO: Perhaps it would be better to report |
| 15994 | * only the first erroneous element and then break. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15995 | */ |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 15996 | #ifdef DEBUG_AUTOMATA |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15997 | if (ret < 0) |
| 15998 | xmlGenericError(xmlGenericErrorContext, |
| 15999 | " --> %s Error\n", child->name); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 16000 | else |
| 16001 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16002 | " --> %s\n", child->name); |
| 16003 | #endif |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 16004 | if (ret < 0) { |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 16005 | xmlRegExecErrInfo(ctxt->regexp, NULL, &nbval, &nbneg, |
| 16006 | &values[0], &terminal); |
| 16007 | xmlSchemaVComplexTypeElemErr(ctxt, |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 16008 | XML_SCHEMAV_ELEMENT_CONTENT, |
| 16009 | child, NULL/* type */, |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 16010 | "This element is not expected", |
| 16011 | nbval, nbneg, values); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 16012 | ret = 1; |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 16013 | /* |
| 16014 | * Note that this will skip further validation of the |
| 16015 | * content. |
| 16016 | */ |
| 16017 | break; |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 16018 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16019 | } else if ((type->contentType == XML_SCHEMA_CONTENT_ELEMENTS) && |
| 16020 | /* |
| 16021 | * TODO: Ask Daniel if this are all character nodes. |
| 16022 | */ |
| 16023 | (((child->type == XML_TEXT_NODE) && (!IS_BLANK_NODE(child))) || |
| 16024 | (child->type == XML_ENTITY_NODE) || |
| 16025 | (child->type == XML_ENTITY_REF_NODE) || |
| 16026 | (child->type == XML_CDATA_SECTION_NODE))) { |
| 16027 | /* |
| 16028 | * 2.3 If the {content type} is element-only, then the |
| 16029 | * element information item has no character information |
| 16030 | * item [children] other than those whose [character |
| 16031 | * code] is defined as a white space in [XML 1.0 (Second |
| 16032 | * Edition)]. |
| 16033 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16034 | xmlSchemaVComplexTypeErr(ctxt, |
| 16035 | XML_SCHEMAV_CVC_COMPLEX_TYPE_2_3, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16036 | elem, type, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16037 | "Character content is not allowed, " |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 16038 | "because the content type is element-only"); |
| 16039 | ret = 1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16040 | break; |
| 16041 | } |
| 16042 | child = child->next; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16043 | } |
| 16044 | /* |
| 16045 | * Content model check finalization. |
| 16046 | */ |
| 16047 | if (type->contModel != NULL) { |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 16048 | if (ret == 0) { |
| 16049 | xmlRegExecNextValues(ctxt->regexp, &nbval, &nbneg, |
| 16050 | &values[0], &terminal); |
| 16051 | if (nbval + nbneg != 0) { |
| 16052 | /* |
| 16053 | * If a next value still exists, I does not have to |
| 16054 | * mean that there's an element missing, since it |
| 16055 | * might be an optional element. So double check it. |
| 16056 | */ |
| 16057 | ret = xmlRegExecPushString(ctxt->regexp, |
| 16058 | NULL, NULL); |
| 16059 | if (ret <= 0) { |
| 16060 | ret = 1; |
| 16061 | xmlSchemaVComplexTypeElemErr(ctxt, |
| 16062 | XML_SCHEMAV_ELEMENT_CONTENT, |
| 16063 | elem, type, "Missing child element(s)", |
| 16064 | nbval, nbneg, values); |
| 16065 | } else |
| 16066 | ret = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16067 | #ifdef DEBUG_AUTOMATA |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 16068 | xmlGenericError(xmlGenericErrorContext, |
| 16069 | "====> %s : %d\n", elem->name, ret); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16070 | #endif |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 16071 | } |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 16072 | #ifdef DEBUG_CONTENT |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 16073 | if (ret == 0) |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 16074 | xmlGenericError(xmlGenericErrorContext, |
| 16075 | "Element %s content check succeeded\n", |
| 16076 | elem->name); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 16077 | #endif |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16078 | } |
| 16079 | xmlRegFreeExecCtxt(ctxt->regexp); |
| 16080 | ctxt->regexp = oldregexp; |
| 16081 | } |
| 16082 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16083 | break; |
| 16084 | case XML_SCHEMA_CONTENT_SIMPLE: |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16085 | case XML_SCHEMA_CONTENT_BASIC: |
| 16086 | /* |
| 16087 | * If the simple content was already validated |
| 16088 | * (e.g. a default value), the content need not |
| 16089 | * to be validated again. |
| 16090 | */ |
| 16091 | if (valSimpleContent == 1) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16092 | xmlChar *value = NULL; |
| 16093 | /* |
| 16094 | * We hit a complexType with a simpleContent resolving |
| 16095 | * to a user derived or built-in simple type. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16096 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16097 | /* |
| 16098 | * 2.2 If the {content type} is a simple type definition, |
| 16099 | * then the element information item has no element |
| 16100 | * information item [children], and the ·normalized value· |
| 16101 | * of the element information item is ·valid· with respect |
| 16102 | * to that simple type definition as defined by String |
| 16103 | * Valid (§3.14.4). |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16104 | */ |
| 16105 | /* |
| 16106 | * STREAM: Children are processed. |
| 16107 | */ |
| 16108 | child = elem->children; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16109 | while (child != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16110 | /* |
| 16111 | * TODO: Could the entity stuff produce elements |
| 16112 | * as well? |
| 16113 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16114 | if (child->type == XML_ELEMENT_NODE) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16115 | xmlSchemaVComplexTypeErr(ctxt, |
| 16116 | XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16117 | elem, type, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16118 | "Element content is not allowed, because " |
| 16119 | "the content type is a simple type"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16120 | ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2; |
| 16121 | break; |
| 16122 | } |
| 16123 | child = child->next; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16124 | } |
| 16125 | ctxt->node = elem; |
| 16126 | ctxt->cur = elem->children; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16127 | if (ret == 0) { |
| 16128 | /* |
| 16129 | * Validate the character content against a simple type. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16130 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16131 | /* |
| 16132 | * STREAM: Children are processed. |
| 16133 | */ |
| 16134 | if (elem->children == NULL) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16135 | value = NULL; |
| 16136 | else |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16137 | value = xmlNodeGetContent(elem); |
| 16138 | /* |
| 16139 | * URGENT TODO: Should facets for the simple type validation be |
| 16140 | * disabled, if the derivation of facets for complex types |
| 16141 | * is implemented? |
| 16142 | */ |
| 16143 | /* |
| 16144 | * NOTE: This call won't check the correct types of the |
| 16145 | * content nodes, since this should be done here. |
| 16146 | */ |
| 16147 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, type, value, 1, 1, 1, 0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16148 | if (ret > 0) { |
| 16149 | /* |
| 16150 | * NOTE: Although an error will be reported by |
| 16151 | * xmlSchemaValidateSimpleTypeValue, the spec wants |
| 16152 | * a specific complex type error to be reported |
| 16153 | * additionally. |
| 16154 | */ |
| 16155 | xmlSchemaVComplexTypeErr(ctxt, |
| 16156 | XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16157 | elem, type, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16158 | "The character content is not valid"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16159 | ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2; |
| 16160 | } else if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16161 | xmlSchemaVErr(ctxt, elem, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16162 | "Internal error: xmlSchemaValidateComplexType, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16163 | "Element '%s': Error while validating character " |
| 16164 | "content against complex type '%s'.\n", |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16165 | elem->name, type->name); |
| 16166 | if (value != NULL) |
| 16167 | xmlFree(value); |
| 16168 | ctxt->type = oldtype; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16169 | return (-1); |
| 16170 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16171 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16172 | if (ret == 0) { |
| 16173 | /* |
| 16174 | * Apply facets of the complexType. Be sure to pass the |
| 16175 | * built-in type to xmlSchemaValidateFacetsInternal. |
| 16176 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16177 | /* URGENT TODO: I don't know yet if the facets of the simple type |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16178 | * are used, or if the facets, defined by this complex type, |
| 16179 | * are to be used only. This here applies both facet sets. |
| 16180 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16181 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16182 | ret = xmlSchemaValidateFacetsInternal(ctxt, |
| 16183 | type, value, 0, 1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16184 | if (ret > 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16185 | xmlSchemaVComplexTypeErr(ctxt, |
| 16186 | XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16187 | elem, type, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16188 | "The character content is not valid"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16189 | ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2; |
| 16190 | } else if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16191 | xmlSchemaVErr(ctxt, elem, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16192 | "Internal error: xmlSchemaValidateComplexType, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16193 | "Element '%s': Error while validating character " |
| 16194 | "content against complex type '%s'; failed to " |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16195 | "apply facets.\n", |
| 16196 | type->name, NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16197 | if (value != NULL) |
| 16198 | xmlFree(value); |
| 16199 | ctxt->type = oldtype; |
| 16200 | return (-1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16201 | } |
| 16202 | } |
| 16203 | if (value != NULL) |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 16204 | xmlFree(value); |
| 16205 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16206 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16207 | break; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16208 | default: |
| 16209 | TODO xmlGenericError(xmlGenericErrorContext, |
| 16210 | "unimplemented content type %d\n", |
| 16211 | type->contentType); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16212 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16213 | ctxt->type = oldtype; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16214 | return (ctxt->err); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16215 | } |
| 16216 | |
| 16217 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16218 | * xmlSchemaValidateElementByType: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16219 | * @ctxt: a schema validation context |
| 16220 | * @elem: an element |
| 16221 | * @type: the list of type declarations |
| 16222 | * |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16223 | * Validation Rule: Element Locally Valid (Type). |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16224 | * |
| 16225 | * Returns 0 if the element is schemas valid, a positive error code |
| 16226 | * number otherwise and -1 in case of internal or API error. |
| 16227 | */ |
| 16228 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16229 | xmlSchemaValidateElementByType(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16230 | xmlSchemaTypePtr type, |
| 16231 | int valSimpleContent) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16232 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16233 | int ret; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16234 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16235 | |
| 16236 | if ((ctxt == NULL) || (type == NULL)) { |
| 16237 | xmlSchemaVCustomErr(ctxt, XML_SCHEMAV_INTERNAL, NULL, NULL, |
| 16238 | "Internal error: xmlSchemaValidateElementByType, " |
| 16239 | "bad arguments", NULL); |
| 16240 | return (-1); |
| 16241 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16242 | /* |
| 16243 | * This one is called by "xmlSchemaValidateElementByDeclaration". |
| 16244 | * It will forward to the proper validation |
| 16245 | * procedures for the given type. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16246 | */ |
| 16247 | if (type == NULL) { |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 16248 | xmlSchemaVCustomErr(ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16249 | XML_SCHEMAV_CVC_TYPE_1, |
| 16250 | ctxt->node, NULL, |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 16251 | "The type definition is absent", NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16252 | return (XML_SCHEMAV_CVC_TYPE_1); |
| 16253 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16254 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16255 | if (type->flags & XML_SCHEMAS_TYPE_ABSTRACT) { |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 16256 | xmlSchemaVCustomErr(ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16257 | XML_SCHEMAV_CVC_TYPE_2, |
| 16258 | ctxt->node, type, |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 16259 | "The type definition is abstract", NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16260 | return (XML_SCHEMAV_CVC_TYPE_2); |
| 16261 | } |
| 16262 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16263 | switch (type->type) { |
| 16264 | case XML_SCHEMA_TYPE_COMPLEX: |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16265 | ret = xmlSchemaValidateElementByComplexType(ctxt, type, |
| 16266 | valSimpleContent); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16267 | break; |
| 16268 | case XML_SCHEMA_TYPE_SIMPLE: |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16269 | ret = xmlSchemaValidateElementBySimpleType(ctxt, type, |
| 16270 | valSimpleContent); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16271 | break; |
| 16272 | case XML_SCHEMA_TYPE_BASIC: |
| 16273 | if (type->builtInType == XML_SCHEMAS_ANYTYPE) |
| 16274 | ret = xmlSchemaValidateElementByAnyType(ctxt, type); |
| 16275 | else |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16276 | ret = xmlSchemaValidateElementBySimpleType(ctxt, type, |
| 16277 | valSimpleContent); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16278 | break; |
| 16279 | default: |
| 16280 | ret = -1; |
| 16281 | break; |
| 16282 | } |
| 16283 | if (ret == -1) |
| 16284 | return (-1); |
| 16285 | else |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16286 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16287 | } |
| 16288 | |
| 16289 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16290 | static int |
| 16291 | xmlSchemaCheckAttrLocallyValid(xmlSchemaValidCtxtPtr ctxt, |
| 16292 | xmlSchemaAttributePtr decl, |
| 16293 | xmlSchemaAttrStatePtr state, |
| 16294 | xmlAttrPtr attr) |
| 16295 | { |
| 16296 | xmlChar *value; |
| 16297 | const xmlChar *defValue; |
| 16298 | xmlSchemaValPtr defVal; |
| 16299 | int fixed; |
| 16300 | int ret; |
| 16301 | |
| 16302 | if (decl->subtypes == NULL) { |
| 16303 | state->state = XML_SCHEMAS_ATTR_TYPE_NOT_RESOLVED; |
| 16304 | return (XML_SCHEMAS_ATTR_TYPE_NOT_RESOLVED); |
| 16305 | } |
| 16306 | value = xmlNodeListGetString(attr->doc, attr->children, 1); |
| 16307 | ctxt->node = (xmlNodePtr) attr; |
| 16308 | ctxt->cur = attr->children; |
| 16309 | /* |
| 16310 | * NOTE: This call also checks the content nodes for correct type. |
| 16311 | */ |
| 16312 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, decl->subtypes, |
| 16313 | value, 1, 1, 1, 1); |
| 16314 | |
| 16315 | /* |
| 16316 | * Handle 'fixed' attributes. |
| 16317 | */ |
| 16318 | if (ret > 0) { |
| 16319 | state->state = XML_SCHEMAS_ATTR_INVALID_VALUE; |
| 16320 | /* |
| 16321 | * NOTE: Fixed value constraints will be not |
| 16322 | * applied if the value was invalid, because: |
| 16323 | * 1. The validation process does not return a precomputed |
| 16324 | * value. |
| 16325 | * 2. An invalid value implies a violation of a fixed |
| 16326 | * value constraint. |
| 16327 | */ |
| 16328 | } else if (ret == 0) { |
| 16329 | state->state = XML_SCHEMAS_ATTR_CHECKED; |
| 16330 | if (xmlSchemaGetEffectiveValueConstraint(decl, |
| 16331 | &fixed, &defValue, &defVal) && (fixed == 1)) { |
| 16332 | /* |
| 16333 | * cvc-au : Attribute Locally Valid (Use) |
| 16334 | * For an attribute information item to be·valid· |
| 16335 | * with respect to an attribute use its ·normalized |
| 16336 | * value· must match the canonical lexical representation |
| 16337 | * of the attribute use's {value constraint} value, if it |
| 16338 | * is present and fixed. |
| 16339 | */ |
| 16340 | /* |
| 16341 | * NOTE: the validation context holds in ctxt->value the |
| 16342 | * precomputed value of the attribute; well for some types, |
| 16343 | * fallback to string comparison if no computed value |
| 16344 | * exists. |
| 16345 | */ |
| 16346 | if (((ctxt->value != NULL) && |
| 16347 | (xmlSchemaCompareValues(ctxt->value, defVal) != 0)) || |
| 16348 | ((ctxt->value == NULL) && |
| 16349 | (! xmlStrEqual(defValue, BAD_CAST value)))) { |
| 16350 | state->state = |
| 16351 | XML_SCHEMAS_ATTR_INVALID_FIXED_VALUE; |
| 16352 | } |
| 16353 | } |
| 16354 | } |
| 16355 | if (value != NULL) { |
| 16356 | xmlFree(value); |
| 16357 | } |
| 16358 | return (ret); |
| 16359 | } |
| 16360 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16361 | /** |
| 16362 | * xmlSchemaValidateAttributes: |
| 16363 | * @ctxt: a schema validation context |
| 16364 | * @elem: an element |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16365 | * @type: the complexType holding the attribute uses |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16366 | * |
| 16367 | * Validate the attributes of an element. |
| 16368 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16369 | * 1. Existent, invalid attributes are reported in the form |
| 16370 | * "prefix:localName". |
| 16371 | * Reason: readability - it is easier to find the actual XML |
| 16372 | * representation of the attributes QName. |
| 16373 | * 2. Missing attributes are reported in the form |
| 16374 | * {"URI", "localName"}. |
| 16375 | * This is necessary, since the the prefix need not to be declared |
| 16376 | * at all, and thus is not computable. |
| 16377 | * |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16378 | * Returns 0 if the element is schemas valid, a positive error code |
| 16379 | * number otherwise and -1 in case of internal or API error. |
| 16380 | */ |
| 16381 | static int |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16382 | xmlSchemaValidateAttributes(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem, xmlSchemaTypePtr type) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16383 | { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16384 | const xmlChar *nsURI; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16385 | int ret; |
| 16386 | xmlAttrPtr attr; /* An attribute on the element. */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16387 | const xmlChar *defValue; |
| 16388 | xmlSchemaValPtr defVal; |
| 16389 | int fixed; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16390 | xmlSchemaAttributeLinkPtr attrUse = NULL; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16391 | xmlSchemaAttributePtr attrDecl; |
Daniel Veillard | c85d0fe | 2004-04-16 16:46:51 +0000 | [diff] [blame] | 16392 | int found; |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 16393 | xmlSchemaAttrStatePtr curState, reqAttrStates = NULL, reqAttrStatesTop = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16394 | xmlSchemaAttrStatePtr defAttrStates = NULL, defAttrStatesTop = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16395 | xmlNodePtr oldnode; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16396 | #ifdef DEBUG_ATTR_VALIDATION |
| 16397 | int redundant = 0; |
| 16398 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16399 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16400 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16401 | /* |
| 16402 | * Allow all attributes if the type is anyType. |
| 16403 | */ |
| 16404 | if (type == xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE)) |
| 16405 | return (0); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16406 | |
| 16407 | oldnode = ctxt->node; |
| 16408 | if (type != NULL) |
| 16409 | attrUse = type->attributeUses; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16410 | while (attrUse != NULL) { |
Daniel Veillard | c85d0fe | 2004-04-16 16:46:51 +0000 | [diff] [blame] | 16411 | found = 0; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16412 | attrDecl = attrUse->attr; |
| 16413 | #ifdef DEBUG_ATTR_VALIDATION |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16414 | printf("attr use - name: %s\n", xmlSchemaGetAttrName(attrDecl)); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16415 | printf("attr use - use: %d\n", attrDecl->occurs); |
| 16416 | #endif |
| 16417 | for (curState = ctxt->attr; curState != NULL; curState = curState->next) { |
| 16418 | |
| 16419 | if (curState->decl == attrUse->attr) { |
| 16420 | #ifdef DEBUG_ATTR_VALIDATION |
| 16421 | redundant = 1; |
| 16422 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16423 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16424 | attr = curState->attr; |
| 16425 | #ifdef DEBUG_ATTR_VALIDATION |
| 16426 | printf("attr - name: %s\n", attr->name); |
| 16427 | if (attr->ns != NULL) |
| 16428 | printf("attr - ns: %s\n", attr->ns->href); |
| 16429 | else |
| 16430 | printf("attr - ns: none\n"); |
| 16431 | #endif |
| 16432 | /* TODO: Can this ever happen? */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16433 | if (attr == NULL) |
| 16434 | continue; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16435 | if (attrDecl->ref != NULL) { |
| 16436 | if (!xmlStrEqual(attr->name, attrDecl->ref)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16437 | continue; |
| 16438 | if (attr->ns != NULL) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16439 | if ((attrDecl->refNs == NULL) || |
| 16440 | (!xmlStrEqual(attr->ns->href, attrDecl->refNs))) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16441 | continue; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16442 | } else if (attrDecl->refNs != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16443 | continue; |
| 16444 | } |
| 16445 | } else { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16446 | if (!xmlStrEqual(attr->name, attrDecl->name)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16447 | continue; |
| 16448 | /* |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 16449 | * handle the namespaces checks here |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16450 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 16451 | if (attr->ns == NULL) { |
| 16452 | /* |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 16453 | * accept an unqualified attribute only if the target |
| 16454 | * namespace of the declaration is absent. |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 16455 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16456 | if (attrDecl->targetNamespace != NULL) |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 16457 | /* |
| 16458 | * This check was removed, since the target namespace |
| 16459 | * was evaluated during parsing and already took |
| 16460 | * "attributeFormDefault" into account. |
| 16461 | */ |
| 16462 | /* ((attributes->flags & XML_SCHEMAS_ATTR_NSDEFAULT) == 0)) */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 16463 | continue; |
| 16464 | } else { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16465 | if (attrDecl->targetNamespace == NULL) |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 16466 | continue; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16467 | if (!xmlStrEqual(attrDecl->targetNamespace, |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 16468 | attr->ns->href)) |
| 16469 | continue; |
| 16470 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16471 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16472 | #ifdef DEBUG_ATTR_VALIDATION |
| 16473 | printf("found\n"); |
| 16474 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16475 | found = 1; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16476 | curState->decl = attrDecl; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16477 | ret = xmlSchemaCheckAttrLocallyValid(ctxt, attrDecl, curState, attr); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16478 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16479 | if (!found) { |
| 16480 | if (attrDecl->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED) { |
| 16481 | xmlSchemaAttrStatePtr tmp; |
| 16482 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16483 | #ifdef DEBUG_ATTR_VALIDATION |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16484 | printf("required attr not found\n"); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16485 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16486 | /* |
| 16487 | * Add a new dummy attribute state. |
| 16488 | */ |
| 16489 | tmp = (xmlSchemaAttrStatePtr) xmlMalloc(sizeof(xmlSchemaAttrState)); |
| 16490 | if (tmp == NULL) { |
| 16491 | xmlSchemaVErrMemory(ctxt, "registering required attributes", NULL); |
| 16492 | ctxt->node = oldnode; |
| 16493 | return (-1); |
| 16494 | } |
| 16495 | tmp->attr = NULL; |
| 16496 | tmp->state = XML_SCHEMAS_ATTR_MISSING; |
| 16497 | tmp->decl = attrDecl; |
| 16498 | tmp->next = NULL; |
| 16499 | |
| 16500 | if (reqAttrStates == NULL) { |
| 16501 | reqAttrStates = tmp; |
| 16502 | reqAttrStatesTop = tmp; |
| 16503 | } else { |
| 16504 | reqAttrStatesTop->next = tmp; |
| 16505 | reqAttrStatesTop = tmp; |
| 16506 | } |
| 16507 | } else if ((attrDecl->occurs == XML_SCHEMAS_ATTR_USE_OPTIONAL) && |
| 16508 | (xmlSchemaGetEffectiveValueConstraint(attrDecl, |
| 16509 | &fixed, &defValue, &defVal))) { |
| 16510 | xmlSchemaAttrStatePtr tmp; |
| 16511 | /* |
| 16512 | * Handle non existent default/fixed attributes. |
| 16513 | */ |
| 16514 | tmp = (xmlSchemaAttrStatePtr) |
| 16515 | xmlMalloc(sizeof(xmlSchemaAttrState)); |
| 16516 | if (tmp == NULL) { |
| 16517 | xmlSchemaVErrMemory(ctxt, |
| 16518 | "registering schema specified attributes", NULL); |
| 16519 | ctxt->node = oldnode; |
| 16520 | return (-1); |
| 16521 | } |
| 16522 | tmp->attr = NULL; |
| 16523 | tmp->state = XML_SCHEMAS_ATTR_DEFAULT; |
| 16524 | tmp->decl = attrDecl; |
| 16525 | tmp->value = defValue; |
| 16526 | tmp->next = NULL; |
| 16527 | |
| 16528 | if (defAttrStates == NULL) { |
| 16529 | defAttrStates = tmp; |
| 16530 | defAttrStates = tmp; |
| 16531 | } else { |
| 16532 | defAttrStates->next = tmp; |
| 16533 | defAttrStatesTop = tmp; |
| 16534 | } |
| 16535 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16536 | } |
| 16537 | attrUse = attrUse->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16538 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16539 | /* |
| 16540 | * Add required attributes to the attribute states of the context. |
| 16541 | */ |
| 16542 | if (reqAttrStates != NULL) { |
| 16543 | if (ctxt->attr == NULL) { |
| 16544 | ctxt->attr = reqAttrStates; |
| 16545 | } else { |
| 16546 | ctxt->attrTop->next = reqAttrStates; |
| 16547 | } |
| 16548 | ctxt->attrTop = reqAttrStatesTop; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16549 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16550 | /* |
| 16551 | * Process wildcards. |
| 16552 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16553 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16554 | if ((type != NULL) && (type->attributeWildcard != NULL)) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16555 | #ifdef DEBUG_ATTR_VALIDATION |
| 16556 | xmlSchemaWildcardNsPtr ns; |
| 16557 | printf("matching wildcard: [%d] of complexType: %s\n", type->attributeWildcard, type->name); |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 16558 | if (type->attributeWildcard->processContents == |
| 16559 | XML_SCHEMAS_ANY_LAX) |
| 16560 | printf("processContents: lax\n"); |
| 16561 | else if (type->attributeWildcard->processContents == |
| 16562 | XML_SCHEMAS_ANY_STRICT) |
| 16563 | printf("processContents: strict\n"); |
| 16564 | else |
| 16565 | printf("processContents: skip\n"); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16566 | if (type->attributeWildcard->any) |
| 16567 | printf("type: any\n"); |
| 16568 | else if (type->attributeWildcard->negNsSet != NULL) { |
| 16569 | printf("type: negated\n"); |
| 16570 | if (type->attributeWildcard->negNsSet->value == NULL) |
| 16571 | printf("ns: (absent)\n"); |
| 16572 | else |
| 16573 | printf("ns: %s\n", type->attributeWildcard->negNsSet->value); |
| 16574 | } else if (type->attributeWildcard->nsSet != NULL) { |
| 16575 | printf("type: set\n"); |
| 16576 | ns = type->attributeWildcard->nsSet; |
| 16577 | while (ns != NULL) { |
| 16578 | if (ns->value == NULL) |
| 16579 | printf("ns: (absent)\n"); |
| 16580 | else |
| 16581 | printf("ns: %s\n", ns->value); |
| 16582 | ns = ns->next; |
| 16583 | } |
| 16584 | } else |
| 16585 | printf("empty\n"); |
| 16586 | |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 16587 | |
| 16588 | #endif |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16589 | curState = ctxt->attr; |
| 16590 | while (curState != NULL) { |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 16591 | if (curState->state == XML_SCHEMAS_ATTR_UNKNOWN) { |
| 16592 | if (curState->attr->ns != NULL) |
| 16593 | nsURI = curState->attr->ns->href; |
| 16594 | else |
| 16595 | nsURI = NULL; |
| 16596 | if (xmlSchemaMatchesWildcardNs(type->attributeWildcard, |
| 16597 | nsURI)) { |
| 16598 | /* |
| 16599 | * Handle processContents. |
| 16600 | */ |
| 16601 | if ((type->attributeWildcard->processContents == |
| 16602 | XML_SCHEMAS_ANY_LAX) || |
| 16603 | (type->attributeWildcard->processContents == |
| 16604 | XML_SCHEMAS_ANY_STRICT)) { |
| 16605 | |
| 16606 | attr = curState->attr; |
| 16607 | attrDecl = xmlSchemaGetAttribute(ctxt->schema, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16608 | attr->name, nsURI); |
| 16609 | curState->decl = attrDecl; |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 16610 | if (attrDecl != NULL) { |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 16611 | curState->decl = attrDecl; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16612 | ret = xmlSchemaCheckAttrLocallyValid(ctxt, attrDecl, curState, attr); |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 16613 | } else if (type->attributeWildcard->processContents == |
| 16614 | XML_SCHEMAS_ANY_LAX) { |
| 16615 | curState->state = XML_SCHEMAS_ATTR_CHECKED; |
| 16616 | } |
| 16617 | } else |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16618 | curState->state = XML_SCHEMAS_ATTR_CHECKED; |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 16619 | } |
| 16620 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16621 | curState = curState->next; |
| 16622 | } |
| 16623 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16624 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16625 | /* |
| 16626 | * Report missing and illegal attributes. |
| 16627 | */ |
| 16628 | if (ctxt->attr != NULL) { |
| 16629 | curState = ctxt->attr; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16630 | while ((curState != NULL) && (curState != ctxt->attrTop->next)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16631 | if (curState->state != XML_SCHEMAS_ATTR_CHECKED) { |
| 16632 | attr = curState->attr; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16633 | if (curState->decl != NULL) { |
| 16634 | if (curState->decl->ref != NULL) |
| 16635 | attrDecl = curState->decl->refDecl; |
| 16636 | else |
| 16637 | attrDecl = curState->decl; |
| 16638 | } else |
| 16639 | attrDecl = NULL; |
| 16640 | if (curState->state == XML_SCHEMAS_ATTR_MISSING) { |
| 16641 | xmlSchemaVMissingAttrErr(ctxt, elem, attrDecl); |
| 16642 | } else if (curState->state == |
| 16643 | XML_SCHEMAS_ATTR_TYPE_NOT_RESOLVED) { |
| 16644 | xmlSchemaVCustomErr(ctxt, |
| 16645 | XML_SCHEMAV_CVC_ATTRIBUTE_2, |
| 16646 | (xmlNodePtr) attr, |
| 16647 | (xmlSchemaTypePtr) attrDecl, |
| 16648 | "The type definition is absent", |
| 16649 | NULL); |
| 16650 | } else if (curState->state == |
| 16651 | XML_SCHEMAS_ATTR_INVALID_FIXED_VALUE) { |
| 16652 | xmlSchemaVCustomErr(ctxt, |
| 16653 | XML_SCHEMAV_CVC_AU, |
| 16654 | (xmlNodePtr) attr, (xmlSchemaTypePtr) attrDecl, |
| 16655 | "The value does not match the fixed value " |
| 16656 | "constraint", NULL); |
| 16657 | } else if (curState->state == XML_SCHEMAS_ATTR_UNKNOWN) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16658 | /* TODO: "prohibited" won't ever be touched here!. |
| 16659 | (curState->state == XML_SCHEMAS_ATTR_PROHIBITED)) |
| 16660 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16661 | /* |
| 16662 | * TODO: One might report different error messages |
| 16663 | * for the following errors. |
| 16664 | */ |
| 16665 | if ((type == NULL) || (type->attributeWildcard == NULL)) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16666 | xmlSchemaVIllegalAttrErr(ctxt, |
| 16667 | XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_1, attr); |
| 16668 | } else { |
| 16669 | xmlSchemaVIllegalAttrErr(ctxt, |
| 16670 | XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_2, attr); |
| 16671 | } |
| 16672 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16673 | } |
| 16674 | curState = curState->next; |
| 16675 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16676 | } |
| 16677 | |
| 16678 | /* |
| 16679 | * Add missing default/fixed attributes. |
| 16680 | */ |
| 16681 | if (ctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) { |
| 16682 | curState = defAttrStates; |
| 16683 | while (curState != NULL) { |
| 16684 | attrDecl = curState->decl; |
| 16685 | if (attrDecl->ref != NULL) |
| 16686 | attrDecl = attrDecl->refDecl; |
| 16687 | /* |
| 16688 | * PSVI: Add a new attribute node to the current element. |
| 16689 | */ |
| 16690 | if (attrDecl->targetNamespace == NULL) { |
| 16691 | xmlNewProp(elem, attrDecl->name, curState->value); |
| 16692 | } else { |
| 16693 | xmlNsPtr ns; |
| 16694 | |
| 16695 | ns = xmlSearchNsByHref(elem->doc, elem, |
| 16696 | attrDecl->targetNamespace); |
| 16697 | if (ns == NULL) { |
| 16698 | xmlChar prefix[12]; |
| 16699 | int counter = 1; |
| 16700 | |
| 16701 | attr = curState->attr; |
| 16702 | /* |
| 16703 | * Create a namespace declaration on the validation |
| 16704 | * root node if no namespace declaration is in scope. |
| 16705 | */ |
| 16706 | snprintf((char *) prefix, sizeof(prefix), "p"); |
| 16707 | /* |
| 16708 | * This is somehow not performant, since the ancestor |
| 16709 | * axis beyond @elem will be searched as well. |
| 16710 | */ |
| 16711 | ns = xmlSearchNs(elem->doc, elem, BAD_CAST prefix); |
| 16712 | while (ns != NULL) { |
| 16713 | if (counter > 1000) { |
| 16714 | xmlSchemaVErr(ctxt, (xmlNodePtr) attr, |
| 16715 | XML_SCHEMAV_INTERNAL, |
| 16716 | "Internal error: xmlSchemaValidateAttributes, " |
| 16717 | "could not compute a ns prefix for " |
| 16718 | "default/fixed attribute '%s'.\n", |
| 16719 | attrDecl->name, NULL); |
| 16720 | |
| 16721 | break; |
| 16722 | } |
| 16723 | snprintf((char *) prefix, |
| 16724 | sizeof(prefix), "p%d", counter++); |
| 16725 | ns = xmlSearchNs(elem->doc, elem, |
| 16726 | BAD_CAST prefix); |
| 16727 | } |
| 16728 | if (ns == NULL) { |
| 16729 | ns = xmlNewNs(ctxt->validationRoot, |
| 16730 | attrDecl->targetNamespace, BAD_CAST prefix); |
| 16731 | xmlNewNsProp(elem, ns, attrDecl->name, |
| 16732 | curState->value); |
| 16733 | } |
| 16734 | } else { |
| 16735 | xmlNewNsProp(elem, ns, attrDecl->name, |
| 16736 | curState->value); |
| 16737 | } |
| 16738 | } |
| 16739 | curState = curState->next; |
| 16740 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16741 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16742 | if (defAttrStates != NULL) |
| 16743 | xmlSchemaFreeAttributeStates(defAttrStates); |
| 16744 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16745 | #ifdef DEBUG_ATTR_VALIDATION |
| 16746 | if (redundant) |
| 16747 | xmlGenericError(xmlGenericErrorContext, |
| 16748 | "xmlSchemaValidateAttributes: redundant call by type: %s\n", |
| 16749 | type->name); |
| 16750 | #endif |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16751 | ctxt->node = oldnode; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16752 | return (ctxt->err); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16753 | } |
| 16754 | |
| 16755 | /** |
| 16756 | * xmlSchemaValidateElement: |
| 16757 | * @ctxt: a schema validation context |
| 16758 | * @elem: an element |
| 16759 | * |
| 16760 | * Validate an element in a tree |
| 16761 | * |
| 16762 | * Returns 0 if the element is schemas valid, a positive error code |
| 16763 | * number otherwise and -1 in case of internal or API error. |
| 16764 | */ |
| 16765 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16766 | xmlSchemaValidateElement(xmlSchemaValidCtxtPtr ctxt) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16767 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16768 | xmlSchemaElementPtr elemDecl; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16769 | int ret = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16770 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16771 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16772 | * This one is called by xmlSchemaValidateDocument and |
| 16773 | * xmlSchemaValidateOneElement. |
| 16774 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16775 | if (ctxt->schema == NULL) { |
| 16776 | /* |
| 16777 | * No schema was specified at time of creation of the validation |
| 16778 | * context. Use xsi:schemaLocation and xsi:noNamespaceSchemaLocation |
| 16779 | * of the instance to build a schema. |
| 16780 | */ |
| 16781 | if (ctxt->pctxt == NULL) |
| 16782 | ctxt->pctxt = xmlSchemaNewParserCtxt("*"); |
| 16783 | if (ctxt->pctxt == NULL) |
| 16784 | return (-1); |
| 16785 | ctxt->schema = xmlSchemaNewSchema(ctxt->pctxt); |
| 16786 | if (ctxt->schema == NULL) |
| 16787 | return (-1); |
| 16788 | /* TODO: assign user data. */ |
| 16789 | ctxt->pctxt->error = ctxt->error; |
| 16790 | ctxt->pctxt->warning = ctxt->warning; |
| 16791 | ctxt->xsiAssemble = 1; |
| 16792 | } else |
| 16793 | ctxt->xsiAssemble = 0; |
| 16794 | /* ctxt->options |= XML_SCHEMA_VAL_VC_I_CREATE; |
| 16795 | * ctxt->xsiAssemble = 1; |
| 16796 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16797 | /* |
| 16798 | * Assemble new schemata using xsi. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16799 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16800 | if (ctxt->xsiAssemble) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16801 | ret = xmlSchemaAssembleByXSIElem(ctxt, ctxt->node); |
| 16802 | if (ret == -1) { |
| 16803 | xmlSchemaVCustomErr(ctxt, |
| 16804 | XML_SCHEMAV_INTERNAL, |
| 16805 | ctxt->node, NULL, |
| 16806 | "Internal error: xmlSchemaValidateElement, " |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16807 | "assembling schema by xsi", NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16808 | } |
| 16809 | /* |
| 16810 | * NOTE: We won't react on schema parser errors here. |
| 16811 | * TODO: But a warning would be nice. |
| 16812 | */ |
| 16813 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16814 | if (ret != -1) { |
| 16815 | if (ctxt->node->ns != NULL) |
| 16816 | elemDecl = xmlSchemaGetElem(ctxt->schema, ctxt->node->name, |
| 16817 | ctxt->node->ns->href); |
| 16818 | else |
| 16819 | elemDecl = xmlSchemaGetElem(ctxt->schema, ctxt->node->name, NULL); |
| 16820 | |
| 16821 | if (elemDecl == NULL) { |
| 16822 | xmlSchemaVCustomErr(ctxt, |
| 16823 | XML_SCHEMAV_CVC_ELT_1, |
| 16824 | ctxt->node, NULL, |
| 16825 | "No matching global declaration available", NULL); |
| 16826 | ret = XML_SCHEMAV_CVC_ELT_1; |
| 16827 | } else { |
| 16828 | ret = xmlSchemaValidateElementByDeclaration(ctxt, elemDecl); |
| 16829 | if (ret < 0) { |
| 16830 | xmlSchemaVCustomErr(ctxt, |
| 16831 | XML_SCHEMAV_INTERNAL, ctxt->node, NULL, |
| 16832 | "Internal error: xmlSchemaValidateElement, " |
| 16833 | "calling validation by declaration", NULL); |
| 16834 | } |
| 16835 | } |
| 16836 | } |
| 16837 | /* ctxt->xsiAssemble = 0; */ |
| 16838 | if (ctxt->xsiAssemble) { |
| 16839 | if (ctxt->schema != NULL) { |
| 16840 | xmlSchemaFree(ctxt->schema); |
| 16841 | ctxt->schema = NULL; |
| 16842 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16843 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16844 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16845 | } |
| 16846 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16847 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16848 | /** |
Kasimier T. Buchcik | 5eba91f | 2004-09-08 09:17:27 +0000 | [diff] [blame] | 16849 | * xmlSchemaValidateOneElement: |
| 16850 | * @ctxt: a schema validation context |
| 16851 | * @elem: an element node |
| 16852 | * |
| 16853 | * Validate a branch of a tree, starting with the given @elem. |
| 16854 | * |
| 16855 | * Returns 0 if the element and its subtree is valid, a positive error |
| 16856 | * code number otherwise and -1 in case of an internal or API error. |
| 16857 | */ |
| 16858 | int |
| 16859 | xmlSchemaValidateOneElement(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem) |
| 16860 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16861 | if ((ctxt == NULL) || (elem == NULL) || (elem->type != XML_ELEMENT_NODE)) |
Kasimier T. Buchcik | 5eba91f | 2004-09-08 09:17:27 +0000 | [diff] [blame] | 16862 | return (-1); |
| 16863 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16864 | if (ctxt->schema == NULL) { |
| 16865 | xmlSchemaVErr(ctxt, NULL, |
| 16866 | XML_SCHEMAV_INTERNAL, |
| 16867 | "API error: xmlSchemaValidateOneElement, " |
| 16868 | "no schema specified.\n", NULL, NULL); |
| 16869 | return (-1); |
| 16870 | } |
| 16871 | |
Kasimier T. Buchcik | 5eba91f | 2004-09-08 09:17:27 +0000 | [diff] [blame] | 16872 | ctxt->doc = elem->doc; |
| 16873 | ctxt->err = 0; |
| 16874 | ctxt->nberrors = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16875 | ctxt->node = elem; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16876 | ctxt->validationRoot = elem; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16877 | return (xmlSchemaValidateElement(ctxt)); |
Kasimier T. Buchcik | 5eba91f | 2004-09-08 09:17:27 +0000 | [diff] [blame] | 16878 | } |
| 16879 | |
| 16880 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16881 | * xmlSchemaValidateDocument: |
| 16882 | * @ctxt: a schema validation context |
| 16883 | * @doc: a parsed document tree |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16884 | * @xsiAssemble: should schemata be added if requested by the instance? |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16885 | * |
| 16886 | * Validate a document tree in memory. |
| 16887 | * |
| 16888 | * Returns 0 if the document is schemas valid, a positive error code |
| 16889 | * number otherwise and -1 in case of internal or API error. |
| 16890 | */ |
| 16891 | static int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16892 | xmlSchemaValidateDocument(xmlSchemaValidCtxtPtr ctxt, xmlDocPtr doc) |
| 16893 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16894 | xmlNodePtr root; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16895 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16896 | root = xmlDocGetRootElement(doc); |
| 16897 | if (root == NULL) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16898 | xmlSchemaVCustomErr(ctxt, |
| 16899 | XML_SCHEMAV_DOCUMENT_ELEMENT_MISSING, |
| 16900 | (xmlNodePtr) doc, NULL, |
| 16901 | "The document has no document element", NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16902 | return (ctxt->err); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16903 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16904 | /* ctxt->options |= XML_SCHEMA_VAL_XSI_ASSEMBLE; */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16905 | /* |
| 16906 | * Okay, start the recursive validation |
| 16907 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16908 | ctxt->node = root; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16909 | ctxt->validationRoot = root; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16910 | xmlSchemaValidateElement(ctxt); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16911 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16912 | return (ctxt->err); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16913 | } |
| 16914 | |
| 16915 | /************************************************************************ |
| 16916 | * * |
| 16917 | * SAX Validation code * |
| 16918 | * * |
| 16919 | ************************************************************************/ |
| 16920 | |
| 16921 | /************************************************************************ |
| 16922 | * * |
| 16923 | * Validation interfaces * |
| 16924 | * * |
| 16925 | ************************************************************************/ |
| 16926 | |
| 16927 | /** |
| 16928 | * xmlSchemaNewValidCtxt: |
| 16929 | * @schema: a precompiled XML Schemas |
| 16930 | * |
| 16931 | * Create an XML Schemas validation context based on the given schema |
| 16932 | * |
| 16933 | * Returns the validation context or NULL in case of error |
| 16934 | */ |
| 16935 | xmlSchemaValidCtxtPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16936 | xmlSchemaNewValidCtxt(xmlSchemaPtr schema) |
| 16937 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16938 | xmlSchemaValidCtxtPtr ret; |
| 16939 | |
| 16940 | ret = (xmlSchemaValidCtxtPtr) xmlMalloc(sizeof(xmlSchemaValidCtxt)); |
| 16941 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16942 | xmlSchemaVErrMemory(NULL, "allocating validation context", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16943 | return (NULL); |
| 16944 | } |
| 16945 | memset(ret, 0, sizeof(xmlSchemaValidCtxt)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16946 | ret->schema = schema; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16947 | ret->attrTop = NULL; |
| 16948 | ret->attr = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16949 | return (ret); |
| 16950 | } |
| 16951 | |
| 16952 | /** |
| 16953 | * xmlSchemaFreeValidCtxt: |
| 16954 | * @ctxt: the schema validation context |
| 16955 | * |
| 16956 | * Free the resources associated to the schema validation context |
| 16957 | */ |
| 16958 | void |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16959 | xmlSchemaFreeValidCtxt(xmlSchemaValidCtxtPtr ctxt) |
| 16960 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16961 | if (ctxt == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16962 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16963 | if (ctxt->attr != NULL) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 16964 | xmlSchemaFreeAttributeStates(ctxt->attr); |
Daniel Veillard | 88c5891 | 2002-04-23 07:12:20 +0000 | [diff] [blame] | 16965 | if (ctxt->value != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16966 | xmlSchemaFreeValue(ctxt->value); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16967 | if (ctxt->pctxt != NULL) { |
| 16968 | xmlSchemaFreeParserCtxt(ctxt->pctxt); |
| 16969 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16970 | xmlFree(ctxt); |
| 16971 | } |
| 16972 | |
| 16973 | /** |
| 16974 | * xmlSchemaSetValidErrors: |
| 16975 | * @ctxt: a schema validation context |
| 16976 | * @err: the error function |
| 16977 | * @warn: the warning function |
Daniel Veillard | a9b66d0 | 2002-12-11 14:23:49 +0000 | [diff] [blame] | 16978 | * @ctx: the functions context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16979 | * |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16980 | * Set the error and warning callback informations |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16981 | */ |
| 16982 | void |
| 16983 | xmlSchemaSetValidErrors(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16984 | xmlSchemaValidityErrorFunc err, |
| 16985 | xmlSchemaValidityWarningFunc warn, void *ctx) |
| 16986 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16987 | if (ctxt == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 16988 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16989 | ctxt->error = err; |
| 16990 | ctxt->warning = warn; |
| 16991 | ctxt->userData = ctx; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16992 | if (ctxt->pctxt != NULL) |
| 16993 | xmlSchemaSetParserErrors(ctxt->pctxt, err, warn, ctx); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16994 | } |
| 16995 | |
| 16996 | /** |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 16997 | * xmlSchemaGetValidErrors: |
| 16998 | * @ctxt: a XML-Schema validation context |
| 16999 | * @err: the error function result |
| 17000 | * @warn: the warning function result |
| 17001 | * @ctx: the functions context result |
| 17002 | * |
| 17003 | * Get the error and warning callback informations |
| 17004 | * |
| 17005 | * Returns -1 in case of error and 0 otherwise |
| 17006 | */ |
| 17007 | int |
| 17008 | xmlSchemaGetValidErrors(xmlSchemaValidCtxtPtr ctxt, |
| 17009 | xmlSchemaValidityErrorFunc * err, |
| 17010 | xmlSchemaValidityWarningFunc * warn, void **ctx) |
| 17011 | { |
| 17012 | if (ctxt == NULL) |
| 17013 | return (-1); |
| 17014 | if (err != NULL) |
| 17015 | *err = ctxt->error; |
| 17016 | if (warn != NULL) |
| 17017 | *warn = ctxt->warning; |
| 17018 | if (ctx != NULL) |
| 17019 | *ctx = ctxt->userData; |
| 17020 | return (0); |
| 17021 | } |
| 17022 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17023 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17024 | /** |
Daniel Veillard | 6927b10 | 2004-10-27 17:29:04 +0000 | [diff] [blame] | 17025 | * xmlSchemaSetValidOptions: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17026 | * @ctxt: a schema validation context |
| 17027 | * @options: a combination of xmlSchemaValidOption |
| 17028 | * |
| 17029 | * Sets the options to be used during the validation. |
| 17030 | * |
| 17031 | * Returns 0 in case of success, -1 in case of an |
| 17032 | * API error. |
| 17033 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17034 | int |
| 17035 | xmlSchemaSetValidOptions(xmlSchemaValidCtxtPtr ctxt, |
| 17036 | int options) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17037 | |
| 17038 | { |
| 17039 | int i; |
| 17040 | |
| 17041 | if (ctxt == NULL) |
| 17042 | return (-1); |
| 17043 | /* |
| 17044 | * WARNING: Change the start value if adding to the |
| 17045 | * xmlSchemaValidOption. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17046 | * TODO: Is there an other, more easy to maintain, |
| 17047 | * way? |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17048 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17049 | for (i = 1; i < (int) sizeof(int) * 8; i++) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17050 | if (options & 1<<i) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17051 | xmlSchemaVErr(ctxt, NULL, |
| 17052 | XML_SCHEMAV_INTERNAL, |
| 17053 | "Internal error: xmlSchemaSetValidOptions, " |
| 17054 | "invalid option argument.\n", NULL, NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17055 | return (-1); |
| 17056 | } |
| 17057 | } |
| 17058 | ctxt->options = options; |
| 17059 | return (0); |
| 17060 | } |
| 17061 | |
| 17062 | /** |
Daniel Veillard | 6927b10 | 2004-10-27 17:29:04 +0000 | [diff] [blame] | 17063 | * xmlSchemaValidCtxtGetOptions: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17064 | * @ctxt: a schema validation context |
| 17065 | * |
William M. Brack | 21e4ef2 | 2005-01-02 09:53:13 +0000 | [diff] [blame] | 17066 | * Get the validation context options. |
| 17067 | * |
| 17068 | * Returns the option combination or -1 on error. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17069 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17070 | int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17071 | xmlSchemaValidCtxtGetOptions(xmlSchemaValidCtxtPtr ctxt) |
| 17072 | |
| 17073 | { |
| 17074 | if (ctxt == NULL) |
| 17075 | return (-1); |
| 17076 | else |
| 17077 | return (ctxt->options); |
| 17078 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17079 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17080 | |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 17081 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17082 | * xmlSchemaValidateDoc: |
| 17083 | * @ctxt: a schema validation context |
| 17084 | * @doc: a parsed document tree |
| 17085 | * |
| 17086 | * Validate a document tree in memory. |
| 17087 | * |
| 17088 | * Returns 0 if the document is schemas valid, a positive error code |
| 17089 | * number otherwise and -1 in case of internal or API error. |
| 17090 | */ |
| 17091 | int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17092 | xmlSchemaValidateDoc(xmlSchemaValidCtxtPtr ctxt, xmlDocPtr doc) |
| 17093 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17094 | int ret; |
| 17095 | |
| 17096 | if ((ctxt == NULL) || (doc == NULL)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17097 | return (-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17098 | |
| 17099 | ctxt->doc = doc; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 17100 | ctxt->err = 0; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17101 | ctxt->nberrors = 0; |
| 17102 | |
| 17103 | /* |
| 17104 | if (ctxt->schema == NULL) { |
| 17105 | xmlSchemaVErr(ctxt, NULL, |
| 17106 | XML_SCHEMAV_INTERNAL, |
| 17107 | "API error: xmlSchemaValidateDoc, " |
| 17108 | "no schema specified and assembling of schemata " |
| 17109 | "using xsi:schemaLocation and xsi:noNamespaceSchemaLocation " |
| 17110 | "is not enabled.\n", NULL, NULL); |
| 17111 | return (-1); |
| 17112 | } |
| 17113 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17114 | ret = xmlSchemaValidateDocument(ctxt, doc); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17115 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17116 | } |
| 17117 | |
| 17118 | /** |
| 17119 | * xmlSchemaValidateStream: |
| 17120 | * @ctxt: a schema validation context |
| 17121 | * @input: the input to use for reading the data |
| 17122 | * @enc: an optional encoding information |
| 17123 | * @sax: a SAX handler for the resulting events |
| 17124 | * @user_data: the context to provide to the SAX handler. |
| 17125 | * |
| 17126 | * Validate a document tree in memory. |
| 17127 | * |
| 17128 | * Returns 0 if the document is schemas valid, a positive error code |
| 17129 | * number otherwise and -1 in case of internal or API error. |
| 17130 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17131 | int |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17132 | xmlSchemaValidateStream(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17133 | xmlParserInputBufferPtr input, xmlCharEncoding enc, |
| 17134 | xmlSAXHandlerPtr sax, void *user_data) |
| 17135 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17136 | if ((ctxt == NULL) || (input == NULL)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17137 | return (-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17138 | ctxt->input = input; |
| 17139 | ctxt->enc = enc; |
| 17140 | ctxt->sax = sax; |
| 17141 | ctxt->user_data = user_data; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17142 | TODO return (0); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17143 | } |
| 17144 | |
| 17145 | #endif /* LIBXML_SCHEMAS_ENABLED */ |