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 | |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 10 | /* |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 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> |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 37 | #ifdef LIBXML_PATTERN_ENABLED |
| 38 | #include <libxml/pattern.h> |
| 39 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 40 | |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 41 | /* #define DEBUG 1 */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 42 | |
Daniel Veillard | 82bbbd4 | 2003-05-11 20:16:09 +0000 | [diff] [blame] | 43 | /* #define DEBUG_CONTENT 1 */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 44 | |
Daniel Veillard | 82bbbd4 | 2003-05-11 20:16:09 +0000 | [diff] [blame] | 45 | /* #define DEBUG_TYPE 1 */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 46 | |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 47 | /* #define DEBUG_CONTENT_REGEXP 1 */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 48 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 49 | /* #define DEBUG_AUTOMATA 1 */ |
| 50 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 51 | /* #define DEBUG_ATTR_VALIDATION 1 */ |
| 52 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 53 | /* #define DEBUG_UNION_VALIDATION 1 */ |
| 54 | |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 55 | #define ELEM_INFO_ENABLED 1 |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 56 | |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 57 | /* #define IDC_ENABLED 1 */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 58 | |
| 59 | /* #define IDC_VALUE_SUPPORT 1 */ |
| 60 | |
| 61 | /* #define IDC_XPATH_SUPPORT 1 */ |
| 62 | |
| 63 | /* #define DEBUG_IDC 1 */ |
| 64 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 65 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 66 | #define UNBOUNDED (1 << 30) |
| 67 | #define TODO \ |
| 68 | xmlGenericError(xmlGenericErrorContext, \ |
| 69 | "Unimplemented block at %s:%d\n", \ |
| 70 | __FILE__, __LINE__); |
| 71 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 72 | #define XML_SCHEMAS_NO_NAMESPACE (const xmlChar *) "##" |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 73 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 74 | /* |
| 75 | * The XML Schemas namespaces |
| 76 | */ |
| 77 | static const xmlChar *xmlSchemaNs = (const xmlChar *) |
| 78 | "http://www.w3.org/2001/XMLSchema"; |
| 79 | |
| 80 | static const xmlChar *xmlSchemaInstanceNs = (const xmlChar *) |
| 81 | "http://www.w3.org/2001/XMLSchema-instance"; |
| 82 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 83 | static const xmlChar *xmlSchemaElemDesElemDecl = (const xmlChar *) |
| 84 | "Element decl."; |
| 85 | static const xmlChar *xmlSchemaElemDesElemRef = (const xmlChar *) |
| 86 | "Element ref."; |
| 87 | static const xmlChar *xmlSchemaElemDesAttrDecl = (const xmlChar *) |
| 88 | "Attribute decl."; |
| 89 | static const xmlChar *xmlSchemaElemDesAttrRef = (const xmlChar *) |
| 90 | "Attribute ref."; |
| 91 | static const xmlChar *xmlSchemaElemDesST = (const xmlChar *) |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 92 | "simple type"; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 93 | static const xmlChar *xmlSchemaElemDesCT = (const xmlChar *) |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 94 | "complex type"; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 95 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 96 | #define IS_SCHEMA(node, type) \ |
| 97 | ((node != NULL) && (node->ns != NULL) && \ |
| 98 | (xmlStrEqual(node->name, (const xmlChar *) type)) && \ |
| 99 | (xmlStrEqual(node->ns->href, xmlSchemaNs))) |
| 100 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 101 | #define FREE_AND_NULL(str) \ |
| 102 | if (str != NULL) { \ |
| 103 | xmlFree(str); \ |
| 104 | str = NULL; \ |
| 105 | } |
| 106 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 107 | #define IS_ANYTYPE(item) \ |
| 108 | ((item->type == XML_SCHEMA_TYPE_BASIC) && \ |
| 109 | (item->builtInType == XML_SCHEMAS_ANYTYPE)) |
| 110 | |
| 111 | #define IS_COMPLEX_TYPE(item) \ |
| 112 | ((item->type == XML_SCHEMA_TYPE_COMPLEX) || \ |
| 113 | (item->builtInType == XML_SCHEMAS_ANYTYPE)) |
| 114 | |
| 115 | #define IS_SIMPLE_TYPE(item) \ |
| 116 | ((item->type == XML_SCHEMA_TYPE_SIMPLE) || \ |
| 117 | ((item->type == XML_SCHEMA_TYPE_BASIC) && \ |
| 118 | (item->builtInType != XML_SCHEMAS_ANYTYPE))) |
| 119 | |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 120 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 121 | #define XML_SCHEMAS_VAL_WTSP_PRESERVE 0 |
| 122 | #define XML_SCHEMAS_VAL_WTSP_REPLACE 1 |
| 123 | #define XML_SCHEMAS_VAL_WTSP_COLLAPSE 2 |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 124 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 125 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 126 | #define XML_SCHEMAS_PARSE_ERROR 1 |
| 127 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 128 | #define SCHEMAS_PARSE_OPTIONS XML_PARSE_NOENT |
| 129 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 130 | |
| 131 | /* |
| 132 | * XML_SCHEMA_VAL_XSI_ASSEMBLE_TNS_COMPOSE |
| 133 | * allow to assemble schemata with |
| 134 | * the same target namespace from |
| 135 | * different sources; otherwise, the first |
| 136 | * encountered schema with a specific target |
| 137 | * namespace will be used only * |
| 138 | |
| 139 | * |
| 140 | * XML_SCHEMA_VAL_LOCATE_BY_NSNAME = 1<<2 |
| 141 | * locate schemata to be imported |
| 142 | * using the namespace name; otherwise |
| 143 | * the location URI will be used */ |
| 144 | |
| 145 | /* |
| 146 | * xmlSchemaParserOption: |
| 147 | * |
| 148 | * This is the set of XML Schema parser options. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 149 | * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 150 | typedef enum { |
| 151 | XML_SCHEMA_PAR_LOCATE_BY_NSNAME = 1<<0 |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 152 | * locate schemata to be imported |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 153 | * using the namespace name; otherwise |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 154 | * the location URI will be used * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 155 | } xmlSchemaParserOption; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 156 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 157 | |
| 158 | /* |
| 159 | XMLPUBFUN int XMLCALL |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 160 | xmlSchemaParserCtxtSetOptions(xmlSchemaParserCtxtPtr ctxt, |
| 161 | int options); |
| 162 | XMLPUBFUN int XMLCALL |
| 163 | xmlSchemaParserCtxtGetOptions(xmlSchemaParserCtxtPtr ctxt); |
| 164 | |
| 165 | */ |
| 166 | |
| 167 | typedef struct _xmlSchemaAssemble xmlSchemaAssemble; |
| 168 | typedef xmlSchemaAssemble *xmlSchemaAssemblePtr; |
| 169 | struct _xmlSchemaAssemble { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 170 | void **items; /* used for dynamic addition of schemata */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 171 | int nbItems; /* used for dynamic addition of schemata */ |
| 172 | int sizeItems; /* used for dynamic addition of schemata */ |
| 173 | }; |
| 174 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 175 | struct _xmlSchemaParserCtxt { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 176 | void *userData; /* user specific data block */ |
| 177 | xmlSchemaValidityErrorFunc error; /* the callback in case of errors */ |
| 178 | xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */ |
Daniel Veillard | e19fc23 | 2002-04-22 16:01:24 +0000 | [diff] [blame] | 179 | xmlSchemaValidError err; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 180 | int nberrors; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 181 | xmlStructuredErrorFunc serror; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 182 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 183 | xmlSchemaPtr topschema; /* The main schema */ |
| 184 | xmlHashTablePtr namespaces; /* Hash table of namespaces to schemas */ |
| 185 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 186 | xmlSchemaPtr schema; /* The schema in use */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 187 | const xmlChar *container; /* the current element, group, ... */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 188 | int counter; |
| 189 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 190 | const xmlChar *URL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 191 | xmlDocPtr doc; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 192 | int preserve; /* Whether the doc should be freed */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 193 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 194 | const char *buffer; |
| 195 | int size; |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 196 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 197 | /* |
| 198 | * Used to build complex element content models |
| 199 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 200 | xmlAutomataPtr am; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 201 | xmlAutomataStatePtr start; |
| 202 | xmlAutomataStatePtr end; |
| 203 | xmlAutomataStatePtr state; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 204 | |
| 205 | xmlDictPtr dict; /* dictionnary for interned string names */ |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 206 | int includes; /* the inclusion level, 0 for root or imports */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 207 | xmlSchemaTypePtr ctxtType; /* The current context simple/complex type */ |
| 208 | xmlSchemaTypePtr parentItem; /* The current parent schema item */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 209 | xmlSchemaAssemblePtr assemble; |
| 210 | int options; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 211 | xmlSchemaValidCtxtPtr vctxt; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | |
| 215 | #define XML_SCHEMAS_ATTR_UNKNOWN 1 |
| 216 | #define XML_SCHEMAS_ATTR_CHECKED 2 |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 217 | #define XML_SCHEMAS_ATTR_PROHIBITED 3 |
| 218 | #define XML_SCHEMAS_ATTR_MISSING 4 |
| 219 | #define XML_SCHEMAS_ATTR_INVALID_VALUE 5 |
| 220 | #define XML_SCHEMAS_ATTR_TYPE_NOT_RESOLVED 6 |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 221 | #define XML_SCHEMAS_ATTR_INVALID_FIXED_VALUE 7 |
| 222 | #define XML_SCHEMAS_ATTR_DEFAULT 8 |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 223 | #define XML_SCHEMAS_ATTR_VALIDATE_VALUE 9 |
| 224 | #define XML_SCHEMAS_ATTR_WILD_NO_DECL 10 |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 225 | |
| 226 | typedef struct _xmlSchemaAttrState xmlSchemaAttrState; |
| 227 | typedef xmlSchemaAttrState *xmlSchemaAttrStatePtr; |
| 228 | struct _xmlSchemaAttrState { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 229 | xmlSchemaAttrStatePtr next; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 230 | xmlAttrPtr attr; |
| 231 | int state; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 232 | xmlSchemaAttributePtr decl; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 233 | const xmlChar *value; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 234 | }; |
| 235 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 236 | typedef struct _xmlSchemaBasicItem xmlSchemaBasicItem; |
| 237 | typedef xmlSchemaBasicItem *xmlSchemaBasicItemPtr; |
| 238 | struct _xmlSchemaBasicItem { |
| 239 | xmlSchemaTypeType type; |
| 240 | xmlSchemaAnnotPtr annot; |
| 241 | }; |
| 242 | |
| 243 | typedef struct _xmlSchemaItemQNRef xmlSchemaItemQNRef; |
| 244 | typedef xmlSchemaItemQNRef *xmlSchemaItemQNRefPtr; |
| 245 | struct _xmlSchemaItemQNRef { |
| 246 | xmlSchemaBasicItemPtr item; |
| 247 | const xmlChar *name; |
| 248 | const xmlChar *targetNamespace; |
| 249 | }; |
| 250 | |
| 251 | typedef struct _xmlSchemaIDC xmlSchemaIDC; |
| 252 | typedef xmlSchemaIDC *xmlSchemaIDCPtr; |
| 253 | |
| 254 | /** |
| 255 | * xmlSchemaIDCSelect: |
| 256 | * |
| 257 | * The identity-constraint "field" and "selector" item, holding the |
| 258 | * XPath expression. |
| 259 | */ |
| 260 | typedef struct _xmlSchemaIDCSelect xmlSchemaIDCSelect; |
| 261 | typedef xmlSchemaIDCSelect *xmlSchemaIDCSelectPtr; |
| 262 | struct _xmlSchemaIDCSelect { |
| 263 | xmlSchemaIDCSelectPtr next; |
| 264 | xmlSchemaIDCPtr idc; |
| 265 | int index; /* an index position if significant for IDC key-sequences */ |
| 266 | const xmlChar *xpath; /* the XPath expression */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 267 | void *xpathComp; /* the compiled XPath expression */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 268 | }; |
| 269 | |
| 270 | /** |
| 271 | * xmlSchemaIDC: |
| 272 | * |
| 273 | * The identity-constraint definition component. |
| 274 | */ |
| 275 | |
| 276 | struct _xmlSchemaIDC { |
| 277 | xmlSchemaTypeType type; |
| 278 | xmlSchemaAnnotPtr annot; |
| 279 | xmlSchemaIDCPtr next; |
| 280 | xmlNodePtr node; |
| 281 | const xmlChar *name; |
| 282 | const xmlChar *targetNamespace; |
| 283 | xmlSchemaIDCSelectPtr selector; |
| 284 | xmlSchemaIDCSelectPtr fields; |
| 285 | int nbFields; |
| 286 | xmlSchemaItemQNRefPtr ref; |
| 287 | }; |
| 288 | |
| 289 | /** |
| 290 | * xmlSchemaIDCAug: |
| 291 | * |
| 292 | * The augmented IDC information used for validation. |
| 293 | */ |
| 294 | typedef struct _xmlSchemaIDCAug xmlSchemaIDCAug; |
| 295 | typedef xmlSchemaIDCAug *xmlSchemaIDCAugPtr; |
| 296 | struct _xmlSchemaIDCAug { |
| 297 | xmlSchemaIDCAugPtr next; /* next in a list */ |
| 298 | xmlSchemaIDCPtr def; /* the IDC definition */ |
| 299 | int bubbleDepth; /* the lowest level to which IDC |
| 300 | tables need to be bubbled upwards */ |
| 301 | }; |
| 302 | |
| 303 | /** |
| 304 | * xmlSchemaPSVIIDCKeySequence: |
| 305 | * |
| 306 | * The key sequence of a node table item. |
| 307 | */ |
| 308 | typedef struct _xmlSchemaPSVIIDCKey xmlSchemaPSVIIDCKey; |
| 309 | typedef xmlSchemaPSVIIDCKey *xmlSchemaPSVIIDCKeyPtr; |
| 310 | struct _xmlSchemaPSVIIDCKey { |
| 311 | xmlSchemaTypePtr type; |
| 312 | xmlSchemaValPtr compValue; |
| 313 | }; |
| 314 | |
| 315 | /** |
| 316 | * xmlSchemaPSVIIDCNode: |
| 317 | * |
| 318 | * The node table item of a node table. |
| 319 | */ |
| 320 | typedef struct _xmlSchemaPSVIIDCNode xmlSchemaPSVIIDCNode; |
| 321 | typedef xmlSchemaPSVIIDCNode *xmlSchemaPSVIIDCNodePtr; |
| 322 | struct _xmlSchemaPSVIIDCNode { |
| 323 | xmlNodePtr node; |
| 324 | xmlSchemaPSVIIDCKeyPtr *keys; |
| 325 | }; |
| 326 | |
| 327 | /** |
| 328 | * xmlSchemaPSVIIDCBinding: |
| 329 | * |
| 330 | * The identity-constraint binding item of the [identity-constraint table]. |
| 331 | */ |
| 332 | typedef struct _xmlSchemaPSVIIDCBinding xmlSchemaPSVIIDCBinding; |
| 333 | typedef xmlSchemaPSVIIDCBinding *xmlSchemaPSVIIDCBindingPtr; |
| 334 | struct _xmlSchemaPSVIIDCBinding { |
| 335 | xmlSchemaPSVIIDCBindingPtr next; /* next binding of a specific node */ |
| 336 | xmlSchemaIDCPtr definition; /* the IDC definition */ |
| 337 | xmlSchemaPSVIIDCNodePtr *nodeTable; /* array of key-sequences */ |
| 338 | int nbNodes; /* number of entries in the node table */ |
| 339 | int sizeNodes; /* size of the node table */ |
| 340 | int nbDupls; /* number of already identified duplicates in the node |
| 341 | table */ |
| 342 | /* int nbKeys; number of keys in each key-sequence */ |
| 343 | }; |
| 344 | |
| 345 | #define XPATH_STATE_OBJ_TYPE_IDC_SELECTOR 1 |
| 346 | #define XPATH_STATE_OBJ_TYPE_IDC_FIELD 2 |
| 347 | |
| 348 | #define XPATH_STATE_OBJ_MATCHES -2 |
| 349 | #define XPATH_STATE_OBJ_BLOCKED -3 |
| 350 | |
| 351 | typedef struct _xmlSchemaIDCMatcher xmlSchemaIDCMatcher; |
| 352 | typedef xmlSchemaIDCMatcher *xmlSchemaIDCMatcherPtr; |
| 353 | |
| 354 | /** |
| 355 | * xmlSchemaIDCStateObj: |
| 356 | * |
| 357 | * The state object used to evaluate XPath expressions. |
| 358 | */ |
| 359 | typedef struct _xmlSchemaIDCStateObj xmlSchemaIDCStateObj; |
| 360 | typedef xmlSchemaIDCStateObj *xmlSchemaIDCStateObjPtr; |
| 361 | struct _xmlSchemaIDCStateObj { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 362 | int type; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 363 | xmlSchemaIDCStateObjPtr next; /* next if in a list */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 364 | int depth; /* depth of creation */ |
| 365 | int *history; /* list of (depth, state-id) tuples */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 366 | int nbHistory; |
| 367 | int sizeHistory; |
| 368 | xmlSchemaIDCMatcherPtr matcher; /* the correspondent field/selector |
| 369 | matcher */ |
| 370 | xmlSchemaIDCSelectPtr sel; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 371 | void *xpathCtxt; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 372 | }; |
| 373 | |
| 374 | #define IDC_MATCHER 0 |
| 375 | |
| 376 | /** |
| 377 | * xmlSchemaIDCMatcher: |
| 378 | * |
| 379 | * Used to IDC selectors (and fields) successively. |
| 380 | */ |
| 381 | struct _xmlSchemaIDCMatcher { |
| 382 | int type; |
| 383 | int depth; /* the tree depth at creation time */ |
| 384 | xmlSchemaIDCMatcherPtr next; /* next in the list */ |
| 385 | xmlSchemaIDCAugPtr aidc; /* the augmented IDC item */ |
| 386 | xmlSchemaPSVIIDCKeyPtr **keySeqs; /* the key-sequences of the target |
| 387 | elements */ |
| 388 | int sizeKeySeqs; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 389 | int targetDepth; |
| 390 | }; |
| 391 | |
| 392 | /* |
| 393 | * Element info flags. |
| 394 | */ |
| 395 | #define XML_SCHEMA_ELEM_INFO_VALUE_NEEDED 1<<0 |
| 396 | |
| 397 | /** |
| 398 | * xmlSchemaElemInfo: |
| 399 | * |
| 400 | * Holds information of an element node. |
| 401 | */ |
| 402 | typedef struct _xmlSchemaElemInfo xmlSchemaElemInfo; |
| 403 | typedef xmlSchemaElemInfo *xmlSchemaElemInfoPtr; |
| 404 | struct _xmlSchemaElemInfo { |
| 405 | int depth; |
| 406 | int flags; /* combination of element info flags */ |
| 407 | xmlNodePtr node; |
| 408 | const xmlChar *localName; |
| 409 | const xmlChar *namespaceName; |
| 410 | xmlSchemaTypePtr typeDef; /* the complex/simple type definition if any */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 411 | xmlSchemaTypePtr decl; /* the element/attribute declaration */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 412 | xmlSchemaValPtr value; /* the pre-computed value if any */ |
| 413 | xmlSchemaPSVIIDCBindingPtr idcTable; /* the table of PSVI IDC bindings |
| 414 | for the scope element*/ |
| 415 | xmlSchemaIDCMatcherPtr idcMatchers; /* the IDC matchers for the scope |
| 416 | element */ |
| 417 | }; |
| 418 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 419 | /** |
| 420 | * xmlSchemaValidCtxt: |
| 421 | * |
| 422 | * A Schemas validation context |
| 423 | */ |
| 424 | |
| 425 | struct _xmlSchemaValidCtxt { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 426 | void *userData; /* user specific data block */ |
| 427 | xmlSchemaValidityErrorFunc error; /* the callback in case of errors */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 428 | xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */ |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 429 | xmlStructuredErrorFunc serror; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 430 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 431 | xmlSchemaPtr schema; /* The schema in use */ |
| 432 | xmlDocPtr doc; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 433 | xmlParserInputBufferPtr input; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 434 | xmlCharEncoding enc; |
| 435 | xmlSAXHandlerPtr sax; |
| 436 | void *user_data; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 437 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 438 | xmlDocPtr myDoc; |
| 439 | int err; |
| 440 | int nberrors; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 441 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 442 | xmlNodePtr node; |
| 443 | xmlNodePtr cur; |
| 444 | xmlSchemaTypePtr type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 445 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 446 | xmlRegExecCtxtPtr regexp; |
| 447 | xmlSchemaValPtr value; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 448 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 449 | xmlSchemaAttrStatePtr attrTop; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 450 | xmlSchemaAttrStatePtr attr; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 451 | /* xmlNodePtr scope; not used */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 452 | int valueWS; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 453 | int options; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 454 | xmlNodePtr validationRoot; |
| 455 | xmlSchemaParserCtxtPtr pctxt; |
| 456 | int xsiAssemble; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 457 | #ifdef ELEM_INFO_ENABLED |
| 458 | int depth; |
| 459 | xmlSchemaElemInfoPtr *elemInfos; /* array of element informations */ |
| 460 | int sizeElemInfos; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 461 | xmlSchemaElemInfoPtr nodeInfo; /* the current element information */ |
| 462 | xmlSchemaElemInfoPtr attrInfo; /* node infor for the current attribute */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 463 | #endif |
| 464 | #ifdef IDC_ENABLED |
| 465 | xmlSchemaIDCAugPtr aidcs; /* a list of augmented IDC informations */ |
| 466 | |
| 467 | xmlSchemaIDCStateObjPtr xpathStates; /* first active state object. */ |
| 468 | xmlSchemaIDCStateObjPtr xpathStatePool; /* first stored state object. */ |
| 469 | |
| 470 | xmlSchemaPSVIIDCNodePtr *idcNodes; /* list of all IDC node-table entries*/ |
| 471 | int nbIdcNodes; |
| 472 | int sizeIdcNodes; |
| 473 | |
| 474 | xmlSchemaPSVIIDCKeyPtr *idcKeys; /* list of all IDC node-table entries */ |
| 475 | int nbIdcKeys; |
| 476 | int sizeIdcKeys; |
| 477 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 478 | }; |
| 479 | |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 480 | /* |
| 481 | * These are the entries in the schemas importSchemas hash table |
| 482 | */ |
| 483 | typedef struct _xmlSchemaImport xmlSchemaImport; |
| 484 | typedef xmlSchemaImport *xmlSchemaImportPtr; |
| 485 | struct _xmlSchemaImport { |
| 486 | const xmlChar *schemaLocation; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 487 | xmlSchemaPtr schema; /* not used any more */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 488 | xmlDocPtr doc; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 489 | int isMain; |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 490 | }; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 491 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 492 | /* |
| 493 | * These are the entries associated to includes in a schemas |
| 494 | */ |
| 495 | typedef struct _xmlSchemaInclude xmlSchemaInclude; |
| 496 | typedef xmlSchemaInclude *xmlSchemaIncludePtr; |
| 497 | struct _xmlSchemaInclude { |
| 498 | xmlSchemaIncludePtr next; |
| 499 | |
| 500 | const xmlChar *schemaLocation; |
| 501 | xmlDocPtr doc; |
| 502 | }; |
| 503 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 504 | typedef struct _xmlSchemaParticle xmlSchemaParticle; |
| 505 | typedef xmlSchemaParticle *xmlSchemaParticlePtr; |
| 506 | struct _xmlSchemaParticle { |
| 507 | xmlSchemaTypeType type; |
| 508 | xmlSchemaParticlePtr next; /* the next particle if in a list */ |
| 509 | int minOccurs; |
| 510 | int maxOccurs; |
| 511 | xmlSchemaTypePtr term; |
| 512 | }; |
| 513 | |
| 514 | |
| 515 | typedef struct _xmlSchemaModelGroup xmlSchemaModelGroup; |
| 516 | typedef xmlSchemaModelGroup *xmlSchemaModelGroupPtr; |
| 517 | struct _xmlSchemaModelGroup { |
| 518 | xmlSchemaTypeType type; |
| 519 | int compositor; /* one of all, choice or sequence */ |
| 520 | xmlSchemaParticlePtr particles; /* list of particles */ |
| 521 | xmlSchemaAnnotPtr annot; |
| 522 | }; |
| 523 | |
| 524 | typedef struct _xmlSchemaModelGroupDef xmlSchemaModelGroupDef; |
| 525 | typedef xmlSchemaModelGroupDef *xmlSchemaModelGroupDefPtr; |
| 526 | struct _xmlSchemaModelGroupDef { |
| 527 | xmlSchemaTypeType type; |
| 528 | const xmlChar *name; |
| 529 | const xmlChar *targetNamespace; |
| 530 | xmlSchemaModelGroupPtr modelGroup; |
| 531 | xmlSchemaAnnotPtr annot; |
| 532 | }; |
| 533 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 534 | /************************************************************************ |
| 535 | * * |
| 536 | * Some predeclarations * |
| 537 | * * |
| 538 | ************************************************************************/ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 539 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 540 | static int xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt, |
| 541 | xmlSchemaPtr schema, |
| 542 | xmlNodePtr node); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 543 | static void |
| 544 | xmlSchemaTypeFixup(xmlSchemaTypePtr typeDecl, |
| 545 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name); |
| 546 | static const char * |
| 547 | xmlSchemaFacetTypeToString(xmlSchemaTypeType type); |
| 548 | static int |
| 549 | xmlSchemaValidateSimpleTypeValue(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 550 | xmlSchemaTypePtr type, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 551 | const xmlChar *value, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 552 | int fireErrors, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 553 | int applyFacets, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 554 | int normalize, |
| 555 | int checkNodes); |
| 556 | static int |
| 557 | xmlSchemaValidateElementByDeclaration(xmlSchemaValidCtxtPtr ctxt, |
| 558 | xmlSchemaElementPtr elemDecl); |
| 559 | static int |
| 560 | xmlSchemaValidateElementByWildcard(xmlSchemaValidCtxtPtr ctxt, |
| 561 | xmlSchemaTypePtr type); |
| 562 | static int |
| 563 | xmlSchemaHasElemOrCharContent(xmlNodePtr node); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 564 | static int |
| 565 | xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 566 | xmlNodePtr node); |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 567 | static void |
| 568 | xmlSchemaCheckDefaults(xmlSchemaTypePtr typeDecl, |
| 569 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name); |
William M. Brack | 87640d5 | 2004-04-17 14:58:15 +0000 | [diff] [blame] | 570 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 571 | /************************************************************************ |
| 572 | * * |
| 573 | * Datatype error handlers * |
| 574 | * * |
| 575 | ************************************************************************/ |
| 576 | |
| 577 | /** |
| 578 | * xmlSchemaPErrMemory: |
| 579 | * @node: a context node |
| 580 | * @extra: extra informations |
| 581 | * |
| 582 | * Handle an out of memory condition |
| 583 | */ |
| 584 | static void |
| 585 | xmlSchemaPErrMemory(xmlSchemaParserCtxtPtr ctxt, |
| 586 | const char *extra, xmlNodePtr node) |
| 587 | { |
| 588 | if (ctxt != NULL) |
| 589 | ctxt->nberrors++; |
| 590 | __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, node, NULL, |
| 591 | extra); |
| 592 | } |
| 593 | |
| 594 | /** |
| 595 | * xmlSchemaPErr: |
| 596 | * @ctxt: the parsing context |
| 597 | * @node: the context node |
| 598 | * @error: the error code |
| 599 | * @msg: the error message |
| 600 | * @str1: extra data |
| 601 | * @str2: extra data |
| 602 | * |
| 603 | * Handle a parser error |
| 604 | */ |
| 605 | static void |
| 606 | xmlSchemaPErr(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error, |
| 607 | const char *msg, const xmlChar * str1, const xmlChar * str2) |
| 608 | { |
| 609 | xmlGenericErrorFunc channel = NULL; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 610 | xmlStructuredErrorFunc schannel = NULL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 611 | void *data = NULL; |
| 612 | |
| 613 | if (ctxt != NULL) { |
| 614 | ctxt->nberrors++; |
| 615 | channel = ctxt->error; |
| 616 | data = ctxt->userData; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 617 | schannel = ctxt->serror; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 618 | } |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 619 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 620 | error, XML_ERR_ERROR, NULL, 0, |
| 621 | (const char *) str1, (const char *) str2, NULL, 0, 0, |
| 622 | msg, str1, str2); |
| 623 | } |
| 624 | |
| 625 | /** |
| 626 | * xmlSchemaPErr2: |
| 627 | * @ctxt: the parsing context |
| 628 | * @node: the context node |
| 629 | * @node: the current child |
| 630 | * @error: the error code |
| 631 | * @msg: the error message |
| 632 | * @str1: extra data |
| 633 | * @str2: extra data |
| 634 | * |
| 635 | * Handle a parser error |
| 636 | */ |
| 637 | static void |
| 638 | xmlSchemaPErr2(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
| 639 | xmlNodePtr child, int error, |
| 640 | const char *msg, const xmlChar * str1, const xmlChar * str2) |
| 641 | { |
| 642 | if (child != NULL) |
| 643 | xmlSchemaPErr(ctxt, child, error, msg, str1, str2); |
| 644 | else |
| 645 | xmlSchemaPErr(ctxt, node, error, msg, str1, str2); |
| 646 | } |
| 647 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 648 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 649 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 650 | * xmlSchemaPErrExt: |
| 651 | * @ctxt: the parsing context |
| 652 | * @node: the context node |
| 653 | * @error: the error code |
| 654 | * @strData1: extra data |
| 655 | * @strData2: extra data |
| 656 | * @strData3: extra data |
| 657 | * @msg: the message |
| 658 | * @str1: extra parameter for the message display |
| 659 | * @str2: extra parameter for the message display |
| 660 | * @str3: extra parameter for the message display |
| 661 | * @str4: extra parameter for the message display |
| 662 | * @str5: extra parameter for the message display |
| 663 | * |
| 664 | * Handle a parser error |
| 665 | */ |
| 666 | static void |
| 667 | xmlSchemaPErrExt(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error, |
| 668 | const xmlChar * strData1, const xmlChar * strData2, |
| 669 | const xmlChar * strData3, const char *msg, const xmlChar * str1, |
| 670 | const xmlChar * str2, const xmlChar * str3, const xmlChar * str4, |
| 671 | const xmlChar * str5) |
| 672 | { |
| 673 | |
| 674 | xmlGenericErrorFunc channel = NULL; |
| 675 | xmlStructuredErrorFunc schannel = NULL; |
| 676 | void *data = NULL; |
| 677 | |
| 678 | if (ctxt != NULL) { |
| 679 | ctxt->nberrors++; |
| 680 | channel = ctxt->error; |
| 681 | data = ctxt->userData; |
| 682 | schannel = ctxt->serror; |
| 683 | } |
| 684 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP, |
| 685 | error, XML_ERR_ERROR, NULL, 0, |
| 686 | (const char *) strData1, (const char *) strData2, |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 687 | (const char *) strData3, 0, 0, msg, str1, str2, |
| 688 | str3, str4, str5); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 689 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 690 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 691 | |
| 692 | /** |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 693 | * xmlSchemaVTypeErrMemory: |
| 694 | * @node: a context node |
| 695 | * @extra: extra informations |
| 696 | * |
| 697 | * Handle an out of memory condition |
| 698 | */ |
| 699 | static void |
| 700 | xmlSchemaVErrMemory(xmlSchemaValidCtxtPtr ctxt, |
| 701 | const char *extra, xmlNodePtr node) |
| 702 | { |
| 703 | if (ctxt != NULL) { |
| 704 | ctxt->nberrors++; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 705 | ctxt->err = XML_SCHEMAV_INTERNAL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 706 | } |
| 707 | __xmlSimpleError(XML_FROM_SCHEMASV, XML_ERR_NO_MEMORY, node, NULL, |
| 708 | extra); |
| 709 | } |
| 710 | |
| 711 | /** |
| 712 | * xmlSchemaVErr3: |
| 713 | * @ctxt: the validation context |
| 714 | * @node: the context node |
| 715 | * @error: the error code |
| 716 | * @msg: the error message |
| 717 | * @str1: extra data |
| 718 | * @str2: extra data |
| 719 | * @str3: extra data |
| 720 | * |
| 721 | * Handle a validation error |
| 722 | */ |
| 723 | static void |
| 724 | xmlSchemaVErr3(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr node, int error, |
| 725 | const char *msg, const xmlChar *str1, const xmlChar *str2, |
| 726 | const xmlChar *str3) |
| 727 | { |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 728 | xmlStructuredErrorFunc schannel = NULL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 729 | xmlGenericErrorFunc channel = NULL; |
| 730 | void *data = NULL; |
| 731 | |
| 732 | if (ctxt != NULL) { |
| 733 | ctxt->nberrors++; |
| 734 | ctxt->err = error; |
| 735 | channel = ctxt->error; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 736 | schannel = ctxt->serror; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 737 | data = ctxt->userData; |
| 738 | } |
| 739 | /* reajust to global error numbers */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 740 | /* Removed, since the old schema error codes have been |
| 741 | * substituted for the global error codes. |
| 742 | * |
| 743 | * error += XML_SCHEMAV_NOROOT - XML_SCHEMAS_ERR_NOROOT; |
| 744 | */ |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 745 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASV, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 746 | error, XML_ERR_ERROR, NULL, 0, |
| 747 | (const char *) str1, (const char *) str2, |
| 748 | (const char *) str3, 0, 0, |
| 749 | msg, str1, str2, str3); |
| 750 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 751 | |
| 752 | /** |
| 753 | * xmlSchemaVErrExt: |
| 754 | * @ctxt: the validation context |
| 755 | * @node: the context node |
| 756 | * @error: the error code |
| 757 | * @msg: the message |
| 758 | * @str1: extra parameter for the message display |
| 759 | * @str2: extra parameter for the message display |
| 760 | * @str3: extra parameter for the message display |
| 761 | * @str4: extra parameter for the message display |
| 762 | * @str5: extra parameter for the message display |
| 763 | * |
| 764 | * Handle a validation error |
| 765 | */ |
| 766 | static void |
| 767 | xmlSchemaVErrExt(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr node, int error, |
| 768 | const char *msg, const xmlChar * str1, |
| 769 | const xmlChar * str2, const xmlChar * str3, |
| 770 | const xmlChar * str4, const xmlChar * str5) |
| 771 | { |
| 772 | xmlStructuredErrorFunc schannel = NULL; |
| 773 | xmlGenericErrorFunc channel = NULL; |
| 774 | void *data = NULL; |
| 775 | |
| 776 | if (ctxt != NULL) { |
| 777 | ctxt->nberrors++; |
| 778 | ctxt->err = error; |
| 779 | channel = ctxt->error; |
| 780 | schannel = ctxt->serror; |
| 781 | data = ctxt->userData; |
| 782 | } |
| 783 | /* reajust to global error numbers */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 784 | /* Removed, since the old schema error codes have been |
| 785 | * substituted for the global error codes. |
| 786 | * |
| 787 | * error += XML_SCHEMAV_NOROOT - XML_SCHEMAS_ERR_NOROOT; |
| 788 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 789 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP, |
| 790 | error, XML_ERR_ERROR, NULL, 0, NULL, NULL, NULL, 0, 0, |
| 791 | msg, str1, str2, str3, str4, str5); |
| 792 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 793 | /** |
| 794 | * xmlSchemaVErr: |
| 795 | * @ctxt: the validation context |
| 796 | * @node: the context node |
| 797 | * @error: the error code |
| 798 | * @msg: the error message |
| 799 | * @str1: extra data |
| 800 | * @str2: extra data |
| 801 | * |
| 802 | * Handle a validation error |
| 803 | */ |
| 804 | static void |
| 805 | xmlSchemaVErr(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr node, int error, |
| 806 | const char *msg, const xmlChar * str1, const xmlChar * str2) |
| 807 | { |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 808 | xmlStructuredErrorFunc schannel = NULL; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 809 | xmlGenericErrorFunc channel = NULL; |
| 810 | void *data = NULL; |
| 811 | |
| 812 | if (ctxt != NULL) { |
| 813 | ctxt->nberrors++; |
| 814 | ctxt->err = error; |
| 815 | channel = ctxt->error; |
| 816 | data = ctxt->userData; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 817 | schannel = ctxt->serror; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 818 | } |
| 819 | /* reajust to global error numbers */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 820 | /* Removed, since the old schema error codes have been |
| 821 | * substituted for the global error codes. |
| 822 | * |
| 823 | * error += XML_SCHEMAV_NOROOT - XML_SCHEMAS_ERR_NOROOT; |
| 824 | */ |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 825 | __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASV, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 826 | error, XML_ERR_ERROR, NULL, 0, |
| 827 | (const char *) str1, (const char *) str2, NULL, 0, 0, |
| 828 | msg, str1, str2); |
| 829 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 830 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 831 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 832 | * xmlSchemaGetAttrName: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 833 | * @attr: the attribute declaration/use |
| 834 | * |
| 835 | * Returns the name of the attribute; if the attribute |
| 836 | * is a reference, the name of the referenced global type will be returned. |
| 837 | */ |
| 838 | static const xmlChar * |
| 839 | xmlSchemaGetAttrName(xmlSchemaAttributePtr attr) |
| 840 | { |
| 841 | if (attr->ref != NULL) |
| 842 | return(attr->ref); |
| 843 | else |
| 844 | return(attr->name); |
| 845 | } |
| 846 | |
| 847 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 848 | * xmlSchemaGetAttrTargetNsURI: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 849 | * @type: the type (element or attribute) |
| 850 | * |
| 851 | * Returns the target namespace URI of the type; if the type is a reference, |
| 852 | * the target namespace of the referenced type will be returned. |
| 853 | */ |
| 854 | static const xmlChar * |
| 855 | xmlSchemaGetAttrTargetNsURI(xmlSchemaAttributePtr attr) |
| 856 | { |
| 857 | if (attr->ref != NULL) |
| 858 | return (attr->refNs); |
| 859 | else |
| 860 | return(attr->targetNamespace); |
| 861 | } |
| 862 | |
| 863 | /** |
| 864 | * xmlSchemaFormatNsUriLocal: |
| 865 | * @buf: the string buffer |
| 866 | * @uri: the namespace URI |
| 867 | * @local: the local name |
| 868 | * |
| 869 | * Returns a representation of the given URI used |
| 870 | * for error reports. |
| 871 | * |
| 872 | * Returns an empty string, if @ns is NULL, a formatted |
| 873 | * string otherwise. |
| 874 | */ |
| 875 | static const xmlChar* |
| 876 | xmlSchemaFormatNsUriLocal(xmlChar **buf, |
| 877 | const xmlChar *uri, const xmlChar *local) |
| 878 | { |
| 879 | if (*buf != NULL) |
| 880 | xmlFree(*buf); |
| 881 | if (uri == NULL) { |
| 882 | *buf = xmlStrdup(BAD_CAST "{'"); |
| 883 | *buf = xmlStrcat(*buf, local); |
| 884 | } else { |
| 885 | *buf = xmlStrdup(BAD_CAST "{'"); |
| 886 | *buf = xmlStrcat(*buf, uri); |
| 887 | *buf = xmlStrcat(*buf, BAD_CAST "', '"); |
| 888 | *buf = xmlStrcat(*buf, local); |
| 889 | } |
| 890 | *buf = xmlStrcat(*buf, BAD_CAST "'}"); |
| 891 | return ((const xmlChar *) *buf); |
| 892 | } |
| 893 | |
| 894 | /** |
| 895 | * xmlSchemaFormatNsPrefixLocal: |
| 896 | * @buf: the string buffer |
| 897 | * @ns: the namespace |
| 898 | * @local: the local name |
| 899 | * |
| 900 | * Returns a representation of the given URI used |
| 901 | * for error reports. |
| 902 | * |
| 903 | * Returns an empty string, if @ns is NULL, a formatted |
| 904 | * string otherwise. |
| 905 | */ |
| 906 | static const xmlChar* |
| 907 | xmlSchemaFormatNsPrefixLocal(xmlChar **buf, |
| 908 | xmlNsPtr ns, const xmlChar *local) |
| 909 | { |
| 910 | if (*buf != NULL) { |
| 911 | xmlFree(*buf); |
| 912 | *buf = NULL; |
| 913 | } |
| 914 | if ((ns == NULL) || (ns->prefix == NULL)) |
| 915 | return(local); |
| 916 | else { |
| 917 | *buf = xmlStrdup(ns->prefix); |
| 918 | *buf = xmlStrcat(*buf, BAD_CAST ":"); |
| 919 | *buf = xmlStrcat(*buf, local); |
| 920 | } |
| 921 | return ((const xmlChar *) *buf); |
| 922 | } |
| 923 | |
| 924 | /** |
| 925 | * xmlSchemaFormatItemForReport: |
| 926 | * @buf: the string buffer |
| 927 | * @itemDes: the designation of the item |
| 928 | * @itemName: the name of the item |
| 929 | * @item: the item as an object |
| 930 | * @itemNode: the node of the item |
| 931 | * @local: the local name |
| 932 | * @parsing: if the function is used during the parse |
| 933 | * |
| 934 | * Returns a representation of the given item used |
| 935 | * for error reports. |
| 936 | * |
| 937 | * The following order is used to build the resulting |
| 938 | * designation if the arguments are not NULL: |
| 939 | * 1a. If itemDes not NULL -> itemDes |
| 940 | * 1b. If (itemDes not NULL) and (itemName not NULL) |
| 941 | * -> itemDes + itemName |
| 942 | * 2. If the preceding was NULL and (item not NULL) -> item |
| 943 | * 3. If the preceding was NULL and (itemNode not NULL) -> itemNode |
| 944 | * |
| 945 | * If the itemNode is an attribute node, the name of the attribute |
| 946 | * will be appended to the result. |
| 947 | * |
| 948 | * Returns the formatted string and sets @buf to the resulting value. |
| 949 | */ |
| 950 | static xmlChar* |
| 951 | xmlSchemaFormatItemForReport(xmlChar **buf, |
| 952 | const xmlChar *itemDes, |
| 953 | xmlSchemaTypePtr item, |
| 954 | xmlNodePtr itemNode, |
| 955 | int parsing) |
| 956 | { |
| 957 | xmlChar *str = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 958 | int named = 1; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 959 | |
| 960 | if (*buf != NULL) { |
| 961 | xmlFree(*buf); |
| 962 | *buf = NULL; |
| 963 | } |
| 964 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 965 | if (itemDes != NULL) { |
| 966 | *buf = xmlStrdup(itemDes); |
| 967 | } else if (item != NULL) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 968 | switch (item->type) { |
| 969 | case XML_SCHEMA_TYPE_BASIC: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 970 | if (item->builtInType == XML_SCHEMAS_ANYTYPE) |
| 971 | *buf = xmlStrdup(BAD_CAST "'anyType'"); |
| 972 | else if (item->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) |
| 973 | *buf = xmlStrdup(BAD_CAST "'anySimpleType'"); |
| 974 | else { |
| 975 | /* *buf = xmlStrdup(BAD_CAST "bi "); */ |
| 976 | /* *buf = xmlStrcat(*buf, xmlSchemaElemDesST); */ |
| 977 | *buf = xmlStrdup(BAD_CAST "'"); |
| 978 | *buf = xmlStrcat(*buf, item->name); |
| 979 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 980 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 981 | break; |
| 982 | case XML_SCHEMA_TYPE_SIMPLE: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 983 | if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) { |
| 984 | *buf = xmlStrdup(xmlSchemaElemDesST); |
| 985 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 986 | *buf = xmlStrcat(*buf, item->name); |
| 987 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 988 | } else { |
| 989 | *buf = xmlStrdup(xmlSchemaElemDesST); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 990 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 991 | break; |
| 992 | case XML_SCHEMA_TYPE_COMPLEX: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 993 | if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) { |
| 994 | *buf = xmlStrdup(xmlSchemaElemDesCT); |
| 995 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 996 | *buf = xmlStrcat(*buf, item->name); |
| 997 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 998 | } else { |
| 999 | *buf = xmlStrdup(xmlSchemaElemDesCT); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1000 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 1001 | break; |
| 1002 | case XML_SCHEMA_TYPE_ATTRIBUTE: { |
| 1003 | xmlSchemaAttributePtr attr; |
| 1004 | |
| 1005 | attr = (xmlSchemaAttributePtr) item; |
| 1006 | if ((attr->flags & XML_SCHEMAS_TYPE_GLOBAL) || |
| 1007 | (attr->ref == NULL)) { |
| 1008 | *buf = xmlStrdup(xmlSchemaElemDesAttrDecl); |
| 1009 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1010 | *buf = xmlStrcat(*buf, attr->name); |
| 1011 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1012 | } else { |
| 1013 | *buf = xmlStrdup(xmlSchemaElemDesAttrRef); |
| 1014 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1015 | *buf = xmlStrcat(*buf, attr->refPrefix); |
| 1016 | *buf = xmlStrcat(*buf, BAD_CAST ":"); |
| 1017 | *buf = xmlStrcat(*buf, attr->ref); |
| 1018 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1019 | } |
| 1020 | } |
| 1021 | break; |
| 1022 | case XML_SCHEMA_TYPE_ELEMENT: { |
| 1023 | xmlSchemaElementPtr elem; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1024 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 1025 | elem = (xmlSchemaElementPtr) item; |
| 1026 | if ((elem->flags & XML_SCHEMAS_TYPE_GLOBAL) || |
| 1027 | (elem->ref == NULL)) { |
| 1028 | *buf = xmlStrdup(xmlSchemaElemDesElemDecl); |
| 1029 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1030 | *buf = xmlStrcat(*buf, elem->name); |
| 1031 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1032 | } else { |
| 1033 | *buf = xmlStrdup(xmlSchemaElemDesElemRef); |
| 1034 | *buf = xmlStrcat(*buf, BAD_CAST " '"); |
| 1035 | *buf = xmlStrcat(*buf, elem->refPrefix); |
| 1036 | *buf = xmlStrcat(*buf, BAD_CAST ":"); |
| 1037 | *buf = xmlStrcat(*buf, elem->ref); |
| 1038 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1039 | } |
| 1040 | } |
| 1041 | break; |
| 1042 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
| 1043 | case XML_SCHEMA_TYPE_IDC_KEY: |
| 1044 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
| 1045 | if (item->type == XML_SCHEMA_TYPE_IDC_UNIQUE) |
| 1046 | *buf = xmlStrdup(BAD_CAST "unique '"); |
| 1047 | else if (item->type == XML_SCHEMA_TYPE_IDC_KEY) |
| 1048 | *buf = xmlStrdup(BAD_CAST "key '"); |
| 1049 | else |
| 1050 | *buf = xmlStrdup(BAD_CAST "keyRef '"); |
| 1051 | *buf = xmlStrcat(*buf, ((xmlSchemaIDCPtr) item)->name); |
| 1052 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1053 | break; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 1054 | case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: |
| 1055 | TODO |
| 1056 | break; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 1057 | default: |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1058 | named = 0; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 1059 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1060 | } else |
| 1061 | named = 0; |
| 1062 | |
| 1063 | if ((named == 0) && (itemNode != NULL)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1064 | xmlNodePtr elem; |
| 1065 | |
| 1066 | if (itemNode->type == XML_ATTRIBUTE_NODE) |
| 1067 | elem = itemNode->parent; |
| 1068 | else |
| 1069 | elem = itemNode; |
| 1070 | *buf = xmlStrdup(BAD_CAST "Element '"); |
| 1071 | if (parsing) |
| 1072 | *buf = xmlStrcat(*buf, elem->name); |
| 1073 | else |
| 1074 | *buf = xmlStrcat(*buf, |
| 1075 | xmlSchemaFormatNsPrefixLocal(&str, elem->ns, elem->name)); |
| 1076 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1077 | } |
| 1078 | if ((itemNode != NULL) && (itemNode->type == XML_ATTRIBUTE_NODE)) { |
| 1079 | *buf = xmlStrcat(*buf, BAD_CAST ", attribute '"); |
| 1080 | *buf = xmlStrcat(*buf, xmlSchemaFormatNsPrefixLocal(&str, |
| 1081 | itemNode->ns, itemNode->name)); |
| 1082 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1083 | } |
| 1084 | FREE_AND_NULL(str); |
| 1085 | |
| 1086 | return (*buf); |
| 1087 | } |
| 1088 | |
| 1089 | /** |
| 1090 | * xmlSchemaPFormatItemDes: |
| 1091 | * @buf: the string buffer |
| 1092 | * @item: the item as a schema object |
| 1093 | * @itemNode: the item as a node |
| 1094 | * |
| 1095 | * If the pointer to @buf is not NULL and @but holds no value, |
| 1096 | * the value is set to a item designation using |
| 1097 | * xmlSchemaFormatItemForReport. This one avoids adding |
| 1098 | * an attribute designation postfix. |
| 1099 | * |
| 1100 | * Returns a string of all enumeration elements. |
| 1101 | */ |
| 1102 | static void |
| 1103 | xmlSchemaPRequestItemDes(xmlChar **buf, |
| 1104 | xmlSchemaTypePtr item, |
| 1105 | xmlNodePtr itemNode) |
| 1106 | { |
| 1107 | if ((buf == 0) || (*buf != NULL)) |
| 1108 | return; |
| 1109 | if (itemNode->type == XML_ATTRIBUTE_NODE) |
| 1110 | itemNode = itemNode->parent; |
| 1111 | xmlSchemaFormatItemForReport(buf, NULL, item, itemNode, 1); |
| 1112 | } |
| 1113 | |
| 1114 | /** |
| 1115 | * xmlSchemaFormatFacetEnumSet: |
| 1116 | * @buf: the string buffer |
| 1117 | * @type: the type holding the enumeration facets |
| 1118 | * |
| 1119 | * Builds a string consisting of all enumeration elements. |
| 1120 | * |
| 1121 | * Returns a string of all enumeration elements. |
| 1122 | */ |
| 1123 | static const xmlChar * |
| 1124 | xmlSchemaFormatFacetEnumSet(xmlChar **buf, xmlSchemaTypePtr type) |
| 1125 | { |
| 1126 | xmlSchemaFacetLinkPtr link; |
| 1127 | |
| 1128 | if (*buf != NULL) |
| 1129 | xmlFree(*buf); |
| 1130 | *buf = NULL; |
| 1131 | for (link = type->facetSet; link != NULL; link = link->next) { |
| 1132 | if (link->facet->type == XML_SCHEMA_FACET_ENUMERATION) { |
| 1133 | if (*buf == NULL) { |
| 1134 | *buf = xmlStrdup(BAD_CAST "'"); |
| 1135 | *buf = xmlStrcat(*buf, link->facet->value); |
| 1136 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1137 | } else { |
| 1138 | *buf = xmlStrcat(*buf, BAD_CAST ", '"); |
| 1139 | *buf = xmlStrcat(*buf, link->facet->value); |
| 1140 | *buf = xmlStrcat(*buf, BAD_CAST "'"); |
| 1141 | } |
| 1142 | } |
| 1143 | } |
| 1144 | return ((const xmlChar *) *buf); |
| 1145 | } |
| 1146 | |
| 1147 | /** |
| 1148 | * xmlSchemaVFacetErr: |
| 1149 | * @ctxt: the schema validation context |
| 1150 | * @error: the error code |
| 1151 | * @node: the node to be validated |
| 1152 | * @value: the value of the node |
| 1153 | * @type: the type holding the facet |
| 1154 | * @facet: the facet |
| 1155 | * @message: the error message of NULL |
| 1156 | * @str1: extra data |
| 1157 | * @str2: extra data |
| 1158 | * @str3: extra data |
| 1159 | * |
| 1160 | * Reports a facet validation error. |
| 1161 | * TODO: Should this report the value of an element as well? |
| 1162 | */ |
| 1163 | static void |
| 1164 | xmlSchemaVFacetErr(xmlSchemaValidCtxtPtr ctxt, |
| 1165 | xmlParserErrors error, |
| 1166 | xmlNodePtr node, |
| 1167 | const xmlChar *value, |
| 1168 | unsigned long length, |
| 1169 | xmlSchemaTypePtr type, |
| 1170 | xmlSchemaFacetPtr facet, |
| 1171 | const char *message, |
| 1172 | const xmlChar *str1, |
| 1173 | const xmlChar *str2, |
| 1174 | const xmlChar *str3) |
| 1175 | { |
| 1176 | xmlChar *str = NULL, *msg = NULL; |
| 1177 | xmlSchemaTypeType facetType; |
| 1178 | |
| 1179 | xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); |
| 1180 | msg = xmlStrcat(msg, BAD_CAST " ["); |
| 1181 | msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); |
| 1182 | msg = xmlStrcat(msg, BAD_CAST ", facet '"); |
| 1183 | if (error == XML_SCHEMAV_CVC_ENUMERATION_VALID) { |
| 1184 | facetType = XML_SCHEMA_FACET_ENUMERATION; |
| 1185 | /* |
| 1186 | * If enumerations are validated, one must not expect the |
| 1187 | * facet to be given. |
| 1188 | */ |
| 1189 | } else |
| 1190 | facetType = facet->type; |
| 1191 | msg = xmlStrcat(msg, BAD_CAST xmlSchemaFacetTypeToString(facetType)); |
| 1192 | msg = xmlStrcat(msg, BAD_CAST "']: "); |
| 1193 | if (message == NULL) { |
| 1194 | /* |
| 1195 | * Use a default message. |
| 1196 | */ |
| 1197 | if ((facetType == XML_SCHEMA_FACET_LENGTH) || |
| 1198 | (facetType == XML_SCHEMA_FACET_MINLENGTH) || |
| 1199 | (facetType == XML_SCHEMA_FACET_MAXLENGTH)) { |
| 1200 | |
| 1201 | char len[25], actLen[25]; |
| 1202 | |
| 1203 | /* FIXME, TODO: What is the max expected string length of the |
| 1204 | * this value? |
| 1205 | */ |
| 1206 | if (node->type == XML_ATTRIBUTE_NODE) |
| 1207 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' has a length of '%s'; "); |
| 1208 | else |
| 1209 | msg = xmlStrcat(msg, BAD_CAST "The value has a length of '%s'; "); |
| 1210 | |
| 1211 | snprintf(len, 24, "%lu", xmlSchemaGetFacetValueAsULong(facet)); |
| 1212 | snprintf(actLen, 24, "%lu", length); |
| 1213 | |
| 1214 | if (facetType == XML_SCHEMA_FACET_LENGTH) |
| 1215 | msg = xmlStrcat(msg, |
| 1216 | BAD_CAST "this differs from the allowed length of '%s'.\n"); |
| 1217 | else if (facetType == XML_SCHEMA_FACET_MAXLENGTH) |
| 1218 | msg = xmlStrcat(msg, |
| 1219 | BAD_CAST "this exceeds the allowed maximum length of '%s'.\n"); |
| 1220 | else if (facetType == XML_SCHEMA_FACET_MINLENGTH) |
| 1221 | msg = xmlStrcat(msg, |
| 1222 | BAD_CAST "this underruns the allowed minimum length of '%s'.\n"); |
| 1223 | |
| 1224 | if (node->type == XML_ATTRIBUTE_NODE) |
| 1225 | xmlSchemaVErrExt(ctxt, node, error, |
| 1226 | (const char *) msg, |
| 1227 | value, (const xmlChar *) actLen, (const xmlChar *) len, |
| 1228 | NULL, NULL); |
| 1229 | else |
| 1230 | xmlSchemaVErr(ctxt, node, error, |
| 1231 | (const char *) msg, |
| 1232 | (const xmlChar *) actLen, (const xmlChar *) len); |
| 1233 | |
| 1234 | } else if (facetType == XML_SCHEMA_FACET_ENUMERATION) { |
| 1235 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not an element " |
| 1236 | "of the set {%s}.\n"); |
| 1237 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, |
| 1238 | xmlSchemaFormatFacetEnumSet(&str, type)); |
| 1239 | } else if (facetType == XML_SCHEMA_FACET_PATTERN) { |
| 1240 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not accepted " |
| 1241 | "by the pattern '%s'.\n"); |
| 1242 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, |
| 1243 | facet->value); |
| 1244 | } else if (node->type == XML_ATTRIBUTE_NODE) { |
| 1245 | msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not facet-valid.\n"); |
| 1246 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, NULL); |
| 1247 | } else { |
| 1248 | msg = xmlStrcat(msg, BAD_CAST "The value is not facet-valid.\n"); |
| 1249 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, NULL, NULL); |
| 1250 | } |
| 1251 | } else { |
| 1252 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 1253 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1254 | xmlSchemaVErr3(ctxt, node, error, (const char *) msg, str1, str2, str3); |
| 1255 | } |
| 1256 | FREE_AND_NULL(str) |
| 1257 | xmlFree(msg); |
| 1258 | } |
| 1259 | |
| 1260 | /** |
| 1261 | * xmlSchemaVSimpleTypeErr: |
| 1262 | * @ctxt: the schema validation context |
| 1263 | * @error: the error code |
| 1264 | * @type: the type used for validation |
| 1265 | * @node: the node containing the validated value |
| 1266 | * @value: the validated value |
| 1267 | * |
| 1268 | * Reports a simple type validation error. |
| 1269 | * TODO: Should this report the value of an element as well? |
| 1270 | */ |
| 1271 | static void |
| 1272 | xmlSchemaVSimpleTypeErr(xmlSchemaValidCtxtPtr ctxt, |
| 1273 | xmlParserErrors error, |
| 1274 | xmlNodePtr node, |
| 1275 | const xmlChar *value, |
| 1276 | xmlSchemaTypePtr type) |
| 1277 | { |
| 1278 | xmlChar *str = NULL, *msg = NULL; |
| 1279 | |
| 1280 | xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); |
| 1281 | msg = xmlStrcat(msg, BAD_CAST " ["); |
| 1282 | msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); |
| 1283 | if (node->type == XML_ATTRIBUTE_NODE) { |
| 1284 | msg = xmlStrcat(msg, BAD_CAST "]: The value '%s' is not valid.\n"); |
| 1285 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, value, NULL); |
| 1286 | } else { |
| 1287 | msg = xmlStrcat(msg, BAD_CAST "]: The character content is not valid.\n"); |
| 1288 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, NULL, NULL); |
| 1289 | } |
| 1290 | FREE_AND_NULL(str) |
| 1291 | xmlFree(msg); |
| 1292 | } |
| 1293 | |
| 1294 | /** |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1295 | * xmlSchemaVComplexTypeErr: |
| 1296 | * @ctxt: the schema validation context |
| 1297 | * @error: the error code |
| 1298 | * @node: the node containing the validated value |
| 1299 | * @type: the complex type used for validation |
| 1300 | * @message: the error message |
| 1301 | * |
| 1302 | * Reports a complex type validation error. |
| 1303 | */ |
| 1304 | static void |
| 1305 | xmlSchemaVComplexTypeErr(xmlSchemaValidCtxtPtr ctxt, |
| 1306 | xmlParserErrors error, |
| 1307 | xmlNodePtr node, |
| 1308 | xmlSchemaTypePtr type, |
| 1309 | const char *message) |
| 1310 | { |
| 1311 | xmlChar *str = NULL, *msg = NULL; |
| 1312 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 1313 | xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 1314 | /* Specify the complex type only if it is global. */ |
| 1315 | if ((type != NULL) && (type->flags & XML_SCHEMAS_TYPE_GLOBAL)) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 1316 | msg = xmlStrcat(msg, BAD_CAST " ["); |
| 1317 | msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); |
| 1318 | msg = xmlStrcat(msg, BAD_CAST "]"); |
| 1319 | } |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1320 | msg = xmlStrcat(msg, BAD_CAST ": %s.\n"); |
| 1321 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1322 | (const xmlChar *) message, NULL); |
| 1323 | FREE_AND_NULL(str) |
| 1324 | xmlFree(msg); |
| 1325 | } |
| 1326 | |
| 1327 | /** |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1328 | * xmlSchemaVComplexTypeElemErr: |
| 1329 | * @ctxt: the schema validation context |
| 1330 | * @error: the error code |
| 1331 | * @node: the node containing the validated value |
| 1332 | * @type: the complex type used for validation |
| 1333 | * @message: the error message |
| 1334 | * |
| 1335 | * Reports a complex type validation error. |
| 1336 | */ |
| 1337 | static void |
| 1338 | xmlSchemaVComplexTypeElemErr(xmlSchemaValidCtxtPtr ctxt, |
| 1339 | xmlParserErrors error, |
| 1340 | xmlNodePtr node, |
| 1341 | xmlSchemaTypePtr type, |
| 1342 | const char *message, |
| 1343 | int nbval, |
| 1344 | int nbneg, |
| 1345 | xmlChar **values) |
| 1346 | { |
| 1347 | xmlChar *str = NULL, *msg = NULL; |
| 1348 | xmlChar *localName, *nsName; |
| 1349 | const xmlChar *cur, *end; |
| 1350 | int i; |
| 1351 | |
| 1352 | xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); |
| 1353 | /* Specify the complex type only if it is global. */ |
| 1354 | if ((type != NULL) && (type->flags & XML_SCHEMAS_TYPE_GLOBAL)) { |
| 1355 | msg = xmlStrcat(msg, BAD_CAST " ["); |
| 1356 | msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); |
| 1357 | msg = xmlStrcat(msg, BAD_CAST "]"); |
| 1358 | FREE_AND_NULL(str) |
| 1359 | } |
| 1360 | msg = xmlStrcat(msg, BAD_CAST ": "); |
| 1361 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 1362 | /* |
| 1363 | * Note that is does not make sense to report that we have a |
| 1364 | * wildcard here, since the wildcard might be unfolded into |
| 1365 | * multiple transitions. |
| 1366 | */ |
| 1367 | if (nbval + nbneg > 0) { |
| 1368 | if (nbval + nbneg > 1) { |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 1369 | str = xmlStrdup(BAD_CAST ". Expected is one of ( "); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1370 | } else |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 1371 | str = xmlStrdup(BAD_CAST ". Expected is ( "); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1372 | nsName = NULL; |
| 1373 | |
| 1374 | for (i = 0; i < nbval + nbneg; i++) { |
| 1375 | cur = values[i]; |
| 1376 | /* |
| 1377 | * Get the local name. |
| 1378 | */ |
| 1379 | localName = NULL; |
| 1380 | |
| 1381 | end = cur; |
| 1382 | if (*end == '*') { |
| 1383 | localName = xmlStrdup(BAD_CAST "*"); |
| 1384 | *end++; |
| 1385 | } else { |
| 1386 | while ((*end != 0) && (*end != '|')) |
| 1387 | end++; |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1388 | localName = xmlStrncat(localName, BAD_CAST cur, end - cur); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1389 | } |
| 1390 | if (*end != 0) { |
| 1391 | *end++; |
| 1392 | /* |
| 1393 | * Skip "*|*" if they come with negated expressions, since |
| 1394 | * they represent the same negated wildcard. |
| 1395 | */ |
| 1396 | if ((nbneg == 0) || (*end != '*') || (*localName != '*')) { |
| 1397 | /* |
| 1398 | * Get the namespace name. |
| 1399 | */ |
| 1400 | cur = end; |
| 1401 | if (*end == '*') { |
| 1402 | nsName = xmlStrdup(BAD_CAST "{*}"); |
| 1403 | } else { |
| 1404 | while (*end != 0) |
| 1405 | end++; |
| 1406 | |
| 1407 | if (i >= nbval) |
| 1408 | nsName = xmlStrdup(BAD_CAST "{##other:"); |
| 1409 | else |
| 1410 | nsName = xmlStrdup(BAD_CAST "{"); |
| 1411 | |
| 1412 | nsName = xmlStrncat(nsName, BAD_CAST cur, end - cur); |
| 1413 | nsName = xmlStrcat(nsName, BAD_CAST "}"); |
| 1414 | } |
| 1415 | str = xmlStrcat(str, BAD_CAST nsName); |
| 1416 | FREE_AND_NULL(nsName) |
| 1417 | } else { |
| 1418 | FREE_AND_NULL(localName); |
| 1419 | continue; |
| 1420 | } |
| 1421 | } |
| 1422 | str = xmlStrcat(str, BAD_CAST localName); |
| 1423 | FREE_AND_NULL(localName); |
| 1424 | |
| 1425 | if (i < nbval + nbneg -1) |
| 1426 | str = xmlStrcat(str, BAD_CAST ", "); |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 1427 | } |
| 1428 | str = xmlStrcat(str, BAD_CAST " )"); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 1429 | msg = xmlStrcat(msg, BAD_CAST str); |
| 1430 | FREE_AND_NULL(str) |
| 1431 | } |
| 1432 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1433 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, NULL, NULL); |
| 1434 | xmlFree(msg); |
| 1435 | } |
| 1436 | |
| 1437 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1438 | * xmlSchemaPMissingAttrErr: |
| 1439 | * @ctxt: the schema validation context |
| 1440 | * @ownerDes: the designation of the owner |
| 1441 | * @ownerName: the name of the owner |
| 1442 | * @ownerItem: the owner as a schema object |
| 1443 | * @ownerElem: the owner as an element node |
| 1444 | * @node: the parent element node of the missing attribute node |
| 1445 | * @type: the corresponding type of the attribute node |
| 1446 | * |
| 1447 | * Reports an illegal attribute. |
| 1448 | */ |
| 1449 | static void |
| 1450 | xmlSchemaPMissingAttrErr(xmlSchemaParserCtxtPtr ctxt, |
| 1451 | xmlParserErrors error, |
| 1452 | xmlChar **ownerDes, |
| 1453 | xmlSchemaTypePtr ownerItem, |
| 1454 | xmlNodePtr ownerElem, |
| 1455 | const char *name, |
| 1456 | const char *message) |
| 1457 | { |
| 1458 | xmlChar *des = NULL; |
| 1459 | |
| 1460 | if (ownerDes == NULL) |
| 1461 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem, 1); |
| 1462 | else if (*ownerDes == NULL) { |
| 1463 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, ownerElem, 1); |
| 1464 | des = *ownerDes; |
| 1465 | } else |
| 1466 | des = *ownerDes; |
| 1467 | if (message != NULL) |
| 1468 | xmlSchemaPErr(ctxt, ownerElem, error, "%s: %s.\n", BAD_CAST des, BAD_CAST message); |
| 1469 | else |
| 1470 | xmlSchemaPErr(ctxt, ownerElem, error, |
| 1471 | "%s: The attribute '%s' is required but missing.\n", |
| 1472 | BAD_CAST des, BAD_CAST name); |
| 1473 | if (ownerDes == NULL) |
| 1474 | FREE_AND_NULL(des); |
| 1475 | } |
| 1476 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1477 | /** |
| 1478 | * xmlSchemaCompTypeToString: |
| 1479 | * @type: the type of the schema item |
| 1480 | * |
| 1481 | * Returns the component name of a schema item. |
| 1482 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1483 | static const char * |
| 1484 | xmlSchemaCompTypeToString(xmlSchemaTypeType type) |
| 1485 | { |
| 1486 | switch (type) { |
| 1487 | case XML_SCHEMA_TYPE_SIMPLE: |
| 1488 | return("simple type definition"); |
| 1489 | case XML_SCHEMA_TYPE_COMPLEX: |
| 1490 | return("complex type definition"); |
| 1491 | case XML_SCHEMA_TYPE_ELEMENT: |
| 1492 | return("element declaration"); |
| 1493 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 1494 | return("attribute declaration"); |
| 1495 | case XML_SCHEMA_TYPE_GROUP: |
| 1496 | return("model group definition"); |
| 1497 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
| 1498 | return("attribute group definition"); |
| 1499 | case XML_SCHEMA_TYPE_NOTATION: |
| 1500 | return("notation declaration"); |
| 1501 | default: |
| 1502 | return("Not a schema component"); |
| 1503 | } |
| 1504 | } |
| 1505 | /** |
| 1506 | * xmlSchemaPResCompAttrErr: |
| 1507 | * @ctxt: the schema validation context |
| 1508 | * @error: the error code |
| 1509 | * @ownerDes: the designation of the owner |
| 1510 | * @ownerItem: the owner as a schema object |
| 1511 | * @ownerElem: the owner as an element node |
| 1512 | * @name: the name of the attribute holding the QName |
| 1513 | * @refName: the referenced local name |
| 1514 | * @refURI: the referenced namespace URI |
| 1515 | * @message: optional message |
| 1516 | * |
| 1517 | * Used to report QName attribute values that failed to resolve |
| 1518 | * to schema components. |
| 1519 | */ |
| 1520 | static void |
| 1521 | xmlSchemaPResCompAttrErr(xmlSchemaParserCtxtPtr ctxt, |
| 1522 | xmlParserErrors error, |
| 1523 | xmlChar **ownerDes, |
| 1524 | xmlSchemaTypePtr ownerItem, |
| 1525 | xmlNodePtr ownerElem, |
| 1526 | const char *name, |
| 1527 | const xmlChar *refName, |
| 1528 | const xmlChar *refURI, |
| 1529 | xmlSchemaTypeType refType, |
| 1530 | const char *refTypeStr) |
| 1531 | { |
| 1532 | xmlChar *des = NULL, *strA = NULL; |
| 1533 | |
| 1534 | if (ownerDes == NULL) |
| 1535 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem, 1); |
| 1536 | else if (*ownerDes == NULL) { |
| 1537 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, ownerElem, 1); |
| 1538 | des = *ownerDes; |
| 1539 | } else |
| 1540 | des = *ownerDes; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1541 | if (refTypeStr == NULL) |
| 1542 | refTypeStr = xmlSchemaCompTypeToString(refType); |
| 1543 | xmlSchemaPErrExt(ctxt, ownerElem, error, |
| 1544 | NULL, NULL, NULL, |
| 1545 | "%s, attribute '%s': The QName value %s does not resolve to a(n) " |
| 1546 | "%s.\n", BAD_CAST des, BAD_CAST name, |
| 1547 | xmlSchemaFormatNsUriLocal(&strA, refURI, refName), |
| 1548 | BAD_CAST refTypeStr, NULL); |
| 1549 | if (ownerDes == NULL) |
| 1550 | FREE_AND_NULL(des) |
| 1551 | FREE_AND_NULL(strA) |
| 1552 | } |
| 1553 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1554 | /** |
| 1555 | * xmlSchemaPCustomAttrErr: |
| 1556 | * @ctxt: the schema parser context |
| 1557 | * @error: the error code |
| 1558 | * @ownerDes: the designation of the owner |
| 1559 | * @ownerItem: the owner as a schema object |
| 1560 | * @attr: the illegal attribute node |
| 1561 | * |
| 1562 | * Reports an illegal attribute during the parse. |
| 1563 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1564 | static void |
| 1565 | xmlSchemaPCustomAttrErr(xmlSchemaParserCtxtPtr ctxt, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1566 | xmlParserErrors error, |
| 1567 | xmlChar **ownerDes, |
| 1568 | xmlSchemaTypePtr ownerItem, |
| 1569 | xmlAttrPtr attr, |
| 1570 | const char *msg) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1571 | { |
| 1572 | xmlChar *des = NULL; |
| 1573 | |
| 1574 | if (ownerDes == NULL) |
| 1575 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent, 1); |
| 1576 | else if (*ownerDes == NULL) { |
| 1577 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent, 1); |
| 1578 | des = *ownerDes; |
| 1579 | } else |
| 1580 | des = *ownerDes; |
| 1581 | xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL, |
| 1582 | "%s, attribute '%s': %s.\n", |
| 1583 | BAD_CAST des, attr->name, (const xmlChar *) msg, NULL, NULL); |
| 1584 | if (ownerDes == NULL) |
| 1585 | FREE_AND_NULL(des); |
| 1586 | } |
| 1587 | |
| 1588 | /** |
| 1589 | * xmlSchemaPIllegalAttrErr: |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1590 | * @ctxt: the schema parser context |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1591 | * @error: the error code |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1592 | * @ownerDes: the designation of the attribute's owner |
| 1593 | * @ownerItem: the attribute's owner item |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1594 | * @attr: the illegal attribute node |
| 1595 | * |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1596 | * Reports an illegal attribute during the parse. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1597 | */ |
| 1598 | static void |
| 1599 | xmlSchemaPIllegalAttrErr(xmlSchemaParserCtxtPtr ctxt, |
| 1600 | xmlParserErrors error, |
| 1601 | xmlChar **ownerDes, |
| 1602 | xmlSchemaTypePtr ownerItem, |
| 1603 | xmlAttrPtr attr) |
| 1604 | { |
| 1605 | xmlChar *des = NULL, *strA = NULL; |
| 1606 | |
| 1607 | if (ownerDes == NULL) |
| 1608 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent, 1); |
| 1609 | else if (*ownerDes == NULL) { |
| 1610 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent, 1); |
| 1611 | des = *ownerDes; |
| 1612 | } else |
| 1613 | des = *ownerDes; |
| 1614 | xmlSchemaPErr(ctxt, (xmlNodePtr) attr, error, |
| 1615 | "%s: The attribute '%s' is not allowed.\n", BAD_CAST des, |
| 1616 | xmlSchemaFormatNsPrefixLocal(&strA, attr->ns, attr->name)); |
| 1617 | if (ownerDes == NULL) |
| 1618 | FREE_AND_NULL(des); |
| 1619 | FREE_AND_NULL(strA); |
| 1620 | } |
| 1621 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1622 | /** |
| 1623 | * xmlSchemaPAquireDes: |
| 1624 | * @des: the first designation |
| 1625 | * @itemDes: the second designation |
| 1626 | * @item: the schema item |
| 1627 | * @itemElem: the node of the schema item |
| 1628 | * |
| 1629 | * Creates a designation for an item. |
| 1630 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1631 | static void |
| 1632 | xmlSchemaPAquireDes(xmlChar **des, |
| 1633 | xmlChar **itemDes, |
| 1634 | xmlSchemaTypePtr item, |
| 1635 | xmlNodePtr itemElem) |
| 1636 | { |
| 1637 | if (itemDes == NULL) |
| 1638 | xmlSchemaFormatItemForReport(des, NULL, item, itemElem, 1); |
| 1639 | else if (*itemDes == NULL) { |
| 1640 | xmlSchemaFormatItemForReport(itemDes, NULL, item, itemElem, 1); |
| 1641 | *des = *itemDes; |
| 1642 | } else |
| 1643 | *des = *itemDes; |
| 1644 | } |
| 1645 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1646 | /** |
| 1647 | * xmlSchemaPCustomErr: |
| 1648 | * @ctxt: the schema parser context |
| 1649 | * @error: the error code |
| 1650 | * @itemDes: the designation of the schema item |
| 1651 | * @item: the schema item |
| 1652 | * @itemElem: the node of the schema item |
| 1653 | * @message: the error message |
| 1654 | * @str1: an optional param for the error message |
| 1655 | * @str2: an optional param for the error message |
| 1656 | * @str3: an optional param for the error message |
| 1657 | * |
| 1658 | * Reports an error during parsing. |
| 1659 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1660 | static void |
| 1661 | xmlSchemaPCustomErrExt(xmlSchemaParserCtxtPtr ctxt, |
| 1662 | xmlParserErrors error, |
| 1663 | xmlChar **itemDes, |
| 1664 | xmlSchemaTypePtr item, |
| 1665 | xmlNodePtr itemElem, |
| 1666 | const char *message, |
| 1667 | const xmlChar *str1, |
| 1668 | const xmlChar *str2, |
| 1669 | const xmlChar *str3) |
| 1670 | { |
| 1671 | xmlChar *des = NULL, *msg = NULL; |
| 1672 | |
| 1673 | xmlSchemaPAquireDes(&des, itemDes, item, itemElem); |
| 1674 | msg = xmlStrdup(BAD_CAST "%s: "); |
| 1675 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 1676 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1677 | if ((itemElem == NULL) && (item != NULL)) |
| 1678 | itemElem = item->node; |
| 1679 | xmlSchemaPErrExt(ctxt, itemElem, error, NULL, NULL, NULL, |
| 1680 | (const char *) msg, BAD_CAST des, str1, str2, str3, NULL); |
| 1681 | if (itemDes == NULL) |
| 1682 | FREE_AND_NULL(des); |
| 1683 | FREE_AND_NULL(msg); |
| 1684 | } |
| 1685 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1686 | /** |
| 1687 | * xmlSchemaPCustomErr: |
| 1688 | * @ctxt: the schema parser context |
| 1689 | * @error: the error code |
| 1690 | * @itemDes: the designation of the schema item |
| 1691 | * @item: the schema item |
| 1692 | * @itemElem: the node of the schema item |
| 1693 | * @message: the error message |
| 1694 | * @str1: the optional param for the error message |
| 1695 | * |
| 1696 | * Reports an error during parsing. |
| 1697 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1698 | static void |
| 1699 | xmlSchemaPCustomErr(xmlSchemaParserCtxtPtr ctxt, |
| 1700 | xmlParserErrors error, |
| 1701 | xmlChar **itemDes, |
| 1702 | xmlSchemaTypePtr item, |
| 1703 | xmlNodePtr itemElem, |
| 1704 | const char *message, |
| 1705 | const xmlChar *str1) |
| 1706 | { |
| 1707 | xmlSchemaPCustomErrExt(ctxt, error, itemDes, item, itemElem, message, |
| 1708 | str1, NULL, NULL); |
| 1709 | } |
| 1710 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1711 | /** |
| 1712 | * xmlSchemaPAttrUseErr: |
| 1713 | * @ctxt: the schema parser context |
| 1714 | * @error: the error code |
| 1715 | * @itemDes: the designation of the schema type |
| 1716 | * @item: the schema type |
| 1717 | * @itemElem: the node of the schema type |
| 1718 | * @attr: the invalid schema attribute |
| 1719 | * @message: the error message |
| 1720 | * @str1: the optional param for the error message |
| 1721 | * |
| 1722 | * Reports an attribute use error during parsing. |
| 1723 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1724 | static void |
| 1725 | xmlSchemaPAttrUseErr(xmlSchemaParserCtxtPtr ctxt, |
| 1726 | xmlParserErrors error, |
| 1727 | xmlChar **itemDes, |
| 1728 | xmlSchemaTypePtr item, |
| 1729 | xmlNodePtr itemElem, |
| 1730 | const xmlSchemaAttributePtr attr, |
| 1731 | const char *message, |
| 1732 | const xmlChar *str1) |
| 1733 | { |
| 1734 | xmlChar *des = NULL, *strA = NULL, *msg = NULL; |
| 1735 | |
| 1736 | xmlSchemaPAquireDes(&des, itemDes, item, itemElem); |
| 1737 | xmlSchemaFormatNsUriLocal(&strA, xmlSchemaGetAttrTargetNsURI(attr), |
| 1738 | xmlSchemaGetAttrName(attr)); |
| 1739 | msg = xmlStrdup(BAD_CAST "%s, attr. use %s: "); |
| 1740 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 1741 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1742 | if ((itemElem == NULL) && (item != NULL)) |
| 1743 | itemElem = item->node; |
| 1744 | xmlSchemaPErrExt(ctxt, itemElem, error, NULL, NULL, NULL, |
| 1745 | (const char *) msg, BAD_CAST des, BAD_CAST strA, str1, NULL, NULL); |
| 1746 | if (itemDes == NULL) |
| 1747 | FREE_AND_NULL(des); |
| 1748 | FREE_AND_NULL(strA); |
| 1749 | xmlFree(msg); |
| 1750 | } |
| 1751 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1752 | /** |
| 1753 | * xmlSchemaPIllegalFacetAtomicErr: |
| 1754 | * @ctxt: the schema parser context |
| 1755 | * @error: the error code |
| 1756 | * @itemDes: the designation of the type |
| 1757 | * @item: the schema type |
| 1758 | * @baseItem: the base type of type |
| 1759 | * @facet: the illegal facet |
| 1760 | * |
| 1761 | * Reports an illegal facet for atomic simple types. |
| 1762 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1763 | static void |
| 1764 | xmlSchemaPIllegalFacetAtomicErr(xmlSchemaParserCtxtPtr ctxt, |
| 1765 | xmlParserErrors error, |
| 1766 | xmlChar **itemDes, |
| 1767 | xmlSchemaTypePtr item, |
| 1768 | xmlSchemaTypePtr baseItem, |
| 1769 | xmlSchemaFacetPtr facet) |
| 1770 | { |
| 1771 | xmlChar *des = NULL, *strT = NULL; |
| 1772 | |
| 1773 | xmlSchemaPAquireDes(&des, itemDes, item, item->node); |
| 1774 | xmlSchemaPErrExt(ctxt, item->node, error, NULL, NULL, NULL, |
| 1775 | "%s: The facet '%s' is not allowed on types derived from the " |
| 1776 | "type %s.\n", |
| 1777 | BAD_CAST des, BAD_CAST xmlSchemaFacetTypeToString(facet->type), |
| 1778 | xmlSchemaFormatItemForReport(&strT, NULL, baseItem, NULL, 1), |
| 1779 | NULL, NULL); |
| 1780 | if (itemDes == NULL) |
| 1781 | FREE_AND_NULL(des); |
| 1782 | FREE_AND_NULL(strT); |
| 1783 | } |
| 1784 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1785 | /** |
| 1786 | * xmlSchemaPIllegalFacetListUnionErr: |
| 1787 | * @ctxt: the schema parser context |
| 1788 | * @error: the error code |
| 1789 | * @itemDes: the designation of the schema item involved |
| 1790 | * @item: the schema item involved |
| 1791 | * @facet: the illegal facet |
| 1792 | * |
| 1793 | * Reports an illegal facet for <list> and <union>. |
| 1794 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1795 | static void |
| 1796 | xmlSchemaPIllegalFacetListUnionErr(xmlSchemaParserCtxtPtr ctxt, |
| 1797 | xmlParserErrors error, |
| 1798 | xmlChar **itemDes, |
| 1799 | xmlSchemaTypePtr item, |
| 1800 | xmlSchemaFacetPtr facet) |
| 1801 | { |
| 1802 | xmlChar *des = NULL, *strT = NULL; |
| 1803 | |
| 1804 | xmlSchemaPAquireDes(&des, itemDes, item, item->node); |
| 1805 | xmlSchemaPErr(ctxt, item->node, error, |
| 1806 | "%s: The facet '%s' is not allowed.\n", |
| 1807 | BAD_CAST des, BAD_CAST xmlSchemaFacetTypeToString(facet->type)); |
| 1808 | if (itemDes == NULL) |
| 1809 | FREE_AND_NULL(des); |
| 1810 | FREE_AND_NULL(strT); |
| 1811 | } |
| 1812 | |
| 1813 | /** |
| 1814 | * xmlSchemaPMutualExclAttrErr: |
| 1815 | * @ctxt: the schema validation context |
| 1816 | * @error: the error code |
| 1817 | * @elemDes: the designation of the parent element node |
| 1818 | * @attr: the bad attribute node |
| 1819 | * @type: the corresponding type of the attribute node |
| 1820 | * |
| 1821 | * Reports an illegal attribute. |
| 1822 | */ |
| 1823 | static void |
| 1824 | xmlSchemaPMutualExclAttrErr(xmlSchemaParserCtxtPtr ctxt, |
| 1825 | xmlParserErrors error, |
| 1826 | xmlChar **ownerDes, |
| 1827 | xmlSchemaTypePtr ownerItem, |
| 1828 | xmlAttrPtr attr, |
| 1829 | const char *name1, |
| 1830 | const char *name2) |
| 1831 | { |
| 1832 | xmlChar *des = NULL; |
| 1833 | |
| 1834 | if (ownerDes == NULL) |
| 1835 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent, 1); |
| 1836 | else if (*ownerDes == NULL) { |
| 1837 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent, 1); |
| 1838 | des = *ownerDes; |
| 1839 | } else |
| 1840 | des = *ownerDes; |
| 1841 | xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL, |
| 1842 | "%s: The attributes '%s' and '%s' are mutually exclusive.\n", |
| 1843 | BAD_CAST des, BAD_CAST name1, BAD_CAST name2, NULL, NULL); |
| 1844 | if (ownerDes == NULL) |
| 1845 | FREE_AND_NULL(des) |
| 1846 | } |
| 1847 | |
| 1848 | /** |
| 1849 | * xmlSchemaPSimpleTypeErr: |
| 1850 | * @ctxt: the schema validation context |
| 1851 | * @error: the error code |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1852 | * @type: the type specifier |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1853 | * @ownerDes: the designation of the owner |
| 1854 | * @ownerItem: the schema object if existent |
| 1855 | * @node: the validated node |
| 1856 | * @value: the validated value |
| 1857 | * |
| 1858 | * Reports a simple type validation error. |
| 1859 | * TODO: Should this report the value of an element as well? |
| 1860 | */ |
| 1861 | static void |
| 1862 | xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt, |
| 1863 | xmlParserErrors error, |
| 1864 | xmlChar **ownerDes, |
| 1865 | xmlSchemaTypePtr ownerItem, |
| 1866 | xmlNodePtr node, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1867 | xmlSchemaTypePtr type, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1868 | const char *typeDes, |
| 1869 | const xmlChar *value, |
| 1870 | const char *message, |
| 1871 | const xmlChar *str1, |
| 1872 | const xmlChar *str2) |
| 1873 | { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1874 | xmlChar *des = NULL, *strA = NULL, *strT = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1875 | |
| 1876 | if (ownerDes == NULL) |
| 1877 | xmlSchemaPRequestItemDes(&des, ownerItem, node); |
| 1878 | else if (*ownerDes == NULL) { |
| 1879 | xmlSchemaPRequestItemDes(ownerDes, ownerItem, node); |
| 1880 | des = *ownerDes; |
| 1881 | } else |
| 1882 | des = *ownerDes; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1883 | if (type != NULL) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1884 | typeDes = (const char *) xmlSchemaFormatItemForReport(&strT, NULL, type, NULL, 1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1885 | if (message == NULL) { |
| 1886 | /* |
| 1887 | * Use default messages. |
| 1888 | */ |
| 1889 | if (node->type == XML_ATTRIBUTE_NODE) { |
| 1890 | xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL, |
| 1891 | "%s, attribute '%s' [%s]: The value '%s' is not " |
| 1892 | "valid.\n", |
| 1893 | BAD_CAST des, xmlSchemaFormatNsPrefixLocal(&strA, node->ns, |
| 1894 | node->name), BAD_CAST typeDes, value, NULL); |
| 1895 | } else { |
| 1896 | xmlSchemaPErr(ctxt, node, error, |
| 1897 | "%s [%s]: The character content is not valid.\n", |
| 1898 | BAD_CAST des, BAD_CAST typeDes); |
| 1899 | } |
| 1900 | } else { |
| 1901 | xmlChar *msg; |
| 1902 | |
| 1903 | msg = xmlStrdup(BAD_CAST "%s"); |
| 1904 | if (node->type == XML_ATTRIBUTE_NODE) |
| 1905 | msg = xmlStrcat(msg, BAD_CAST ", attribute '%s'"); |
| 1906 | msg = xmlStrcat(msg, BAD_CAST " [%s]: "); |
| 1907 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 1908 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 1909 | if (node->type == XML_ATTRIBUTE_NODE) { |
| 1910 | xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL, |
| 1911 | (const char *) msg, |
| 1912 | BAD_CAST des, xmlSchemaFormatNsPrefixLocal(&strA, |
| 1913 | node->ns, node->name), BAD_CAST typeDes, str1, str2); |
| 1914 | } else { |
| 1915 | xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL, |
| 1916 | (const char *) msg, |
| 1917 | BAD_CAST des, BAD_CAST typeDes, str1, str2, NULL); |
| 1918 | } |
| 1919 | xmlFree(msg); |
| 1920 | } |
| 1921 | /* Cleanup. */ |
| 1922 | FREE_AND_NULL(strA) |
| 1923 | FREE_AND_NULL(strT) |
| 1924 | if (ownerDes == NULL) |
| 1925 | FREE_AND_NULL(des) |
| 1926 | } |
| 1927 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1928 | /** |
| 1929 | * xmlSchemaPContentErr: |
| 1930 | * @ctxt: the schema parser context |
| 1931 | * @error: the error code |
| 1932 | * @onwerDes: the designation of the holder of the content |
| 1933 | * @ownerItem: the owner item of the holder of the content |
| 1934 | * @ownerElem: the node of the holder of the content |
| 1935 | * @child: the invalid child node |
| 1936 | * @message: the optional error message |
| 1937 | * @content: the optional string describing the correct content |
| 1938 | * |
| 1939 | * Reports an error concerning the content of a schema element. |
| 1940 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1941 | static void |
| 1942 | xmlSchemaPContentErr(xmlSchemaParserCtxtPtr ctxt, |
| 1943 | xmlParserErrors error, |
| 1944 | xmlChar **ownerDes, |
| 1945 | xmlSchemaTypePtr ownerItem, |
| 1946 | xmlNodePtr ownerElem, |
| 1947 | xmlNodePtr child, |
| 1948 | const char *message, |
| 1949 | const char *content) |
| 1950 | { |
| 1951 | xmlChar *des = NULL; |
| 1952 | |
| 1953 | if (ownerDes == NULL) |
| 1954 | xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem, 1); |
| 1955 | else if (*ownerDes == NULL) { |
| 1956 | xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, ownerElem, 1); |
| 1957 | des = *ownerDes; |
| 1958 | } else |
| 1959 | des = *ownerDes; |
| 1960 | if (message != NULL) |
| 1961 | xmlSchemaPErr2(ctxt, ownerElem, child, error, |
| 1962 | "%s: %s.\n", |
| 1963 | BAD_CAST des, BAD_CAST message); |
| 1964 | else { |
| 1965 | if (content != NULL) { |
| 1966 | xmlSchemaPErr2(ctxt, ownerElem, child, error, |
| 1967 | "%s: The content is not valid. Expected is %s.\n", |
| 1968 | BAD_CAST des, BAD_CAST content); |
| 1969 | } else { |
| 1970 | xmlSchemaPErr2(ctxt, ownerElem, child, error, |
| 1971 | "%s: The content is not valid.\n", |
| 1972 | BAD_CAST des, NULL); |
| 1973 | } |
| 1974 | } |
| 1975 | if (ownerDes == NULL) |
| 1976 | FREE_AND_NULL(des) |
| 1977 | } |
| 1978 | |
| 1979 | /** |
| 1980 | * xmlSchemaVIllegalAttrErr: |
| 1981 | * @ctxt: the schema validation context |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 1982 | * @error: the error code |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1983 | * @attr: the illegal attribute node |
| 1984 | * |
| 1985 | * Reports an illegal attribute. |
| 1986 | */ |
| 1987 | static void |
| 1988 | xmlSchemaVIllegalAttrErr(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 1989 | xmlParserErrors error, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 1990 | xmlAttrPtr attr) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1991 | { |
| 1992 | xmlChar *strE = NULL, *strA = NULL; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 1993 | |
| 1994 | xmlSchemaVErr(ctxt, (xmlNodePtr) attr, |
| 1995 | error, |
| 1996 | /* XML_SCHEMAS_ERR_ATTRUNKNOWN, */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 1997 | "%s: The attribute '%s' is not allowed.\n", |
| 1998 | xmlSchemaFormatItemForReport(&strE, NULL, NULL, attr->parent, 0), |
| 1999 | xmlSchemaFormatNsPrefixLocal(&strA, attr->ns, attr->name)); |
| 2000 | FREE_AND_NULL(strE) |
| 2001 | FREE_AND_NULL(strA) |
| 2002 | } |
| 2003 | |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 2004 | |
| 2005 | static int |
| 2006 | xmlSchemaIsGlobalItem(xmlSchemaTypePtr item) |
| 2007 | { |
| 2008 | switch (item->type) { |
| 2009 | case XML_SCHEMA_TYPE_COMPLEX: |
| 2010 | case XML_SCHEMA_TYPE_SIMPLE: |
| 2011 | case XML_SCHEMA_TYPE_GROUP: |
| 2012 | if (item->flags & XML_SCHEMAS_TYPE_GLOBAL) |
| 2013 | return(1); |
| 2014 | break; |
| 2015 | case XML_SCHEMA_TYPE_ELEMENT: |
| 2016 | if ( ((xmlSchemaElementPtr) item)->flags & |
| 2017 | XML_SCHEMAS_ELEM_GLOBAL) |
| 2018 | return(1); |
| 2019 | break; |
| 2020 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 2021 | if ( ((xmlSchemaAttributePtr) item)->flags & |
| 2022 | XML_SCHEMAS_ATTR_GLOBAL) |
| 2023 | return(1); |
| 2024 | break; |
| 2025 | /* Note that attribute groups are always global. */ |
| 2026 | default: |
| 2027 | return(1); |
| 2028 | } |
| 2029 | return (0); |
| 2030 | } |
| 2031 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2032 | /** |
| 2033 | * xmlSchemaVCustomErr: |
| 2034 | * @ctxt: the schema validation context |
| 2035 | * @error: the error code |
| 2036 | * @node: the validated node |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2037 | * @type: the schema type of the validated node |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2038 | * @message: the error message |
| 2039 | * @str1: the optional param for the message |
| 2040 | * |
| 2041 | * Reports a validation error. |
| 2042 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2043 | static void |
| 2044 | xmlSchemaVCustomErr(xmlSchemaValidCtxtPtr ctxt, |
| 2045 | xmlParserErrors error, |
| 2046 | xmlNodePtr node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2047 | xmlSchemaTypePtr type, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2048 | const char *message, |
| 2049 | const xmlChar *str1) |
| 2050 | { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2051 | xmlChar *msg = NULL, *str = NULL; |
| 2052 | |
| 2053 | if (node == NULL) { |
| 2054 | xmlSchemaVErr(ctxt, NULL, |
| 2055 | XML_SCHEMAV_INTERNAL, |
| 2056 | "Internal error: xmlSchemaVCustomErr, no node " |
| 2057 | "given.\n", NULL, NULL); |
| 2058 | return; |
| 2059 | } |
| 2060 | /* TODO: Are the HTML and DOCB doc nodes expected here? */ |
| 2061 | if (node->type != XML_DOCUMENT_NODE) { |
| 2062 | xmlSchemaFormatItemForReport(&msg, NULL, NULL, node, 0); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 2063 | if ((type != NULL) && (xmlSchemaIsGlobalItem(type))) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2064 | msg = xmlStrcat(msg, BAD_CAST " ["); |
| 2065 | msg = xmlStrcat(msg, xmlSchemaFormatItemForReport(&str, NULL, type, NULL, 0)); |
| 2066 | msg = xmlStrcat(msg, BAD_CAST "]"); |
| 2067 | } |
| 2068 | msg = xmlStrcat(msg, BAD_CAST ": "); |
| 2069 | } else |
| 2070 | msg = xmlStrdup((const xmlChar *) ""); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2071 | msg = xmlStrcat(msg, (const xmlChar *) message); |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2072 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 2073 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, str1, NULL); |
| 2074 | FREE_AND_NULL(msg) |
| 2075 | FREE_AND_NULL(str) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2076 | } |
| 2077 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2078 | /** |
| 2079 | * xmlSchemaWildcardPCToString: |
| 2080 | * @pc: the type of processContents |
| 2081 | * |
| 2082 | * Returns a string representation of the type of |
| 2083 | * processContents. |
| 2084 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2085 | static const char * |
| 2086 | xmlSchemaWildcardPCToString(int pc) |
| 2087 | { |
| 2088 | switch (pc) { |
| 2089 | case XML_SCHEMAS_ANY_SKIP: |
| 2090 | return ("skip"); |
| 2091 | case XML_SCHEMAS_ANY_LAX: |
| 2092 | return ("lax"); |
| 2093 | case XML_SCHEMAS_ANY_STRICT: |
| 2094 | return ("strict"); |
| 2095 | default: |
| 2096 | return ("invalid process contents"); |
| 2097 | } |
| 2098 | } |
| 2099 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2100 | /** |
| 2101 | * xmlSchemaVWildcardErr: |
| 2102 | * @ctxt: the schema validation context |
| 2103 | * @error: the error code |
| 2104 | * @node: the validated node |
| 2105 | * @wild: the wildcard used |
| 2106 | * @message: the error message |
| 2107 | * |
| 2108 | * Reports an validation-by-wildcard error. |
| 2109 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2110 | static void |
| 2111 | xmlSchemaVWildcardErr(xmlSchemaValidCtxtPtr ctxt, |
| 2112 | xmlParserErrors error, |
| 2113 | xmlNodePtr node, |
| 2114 | xmlSchemaWildcardPtr wild, |
| 2115 | const char *message) |
| 2116 | { |
| 2117 | xmlChar *des = NULL, *msg = NULL; |
| 2118 | |
| 2119 | xmlSchemaFormatItemForReport(&des, NULL, NULL, node, 0); |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 2120 | msg = xmlStrdup(BAD_CAST "%s ["); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2121 | msg = xmlStrcat(msg, BAD_CAST xmlSchemaWildcardPCToString(wild->processContents)); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 2122 | msg = xmlStrcat(msg, BAD_CAST " wildcard]: "); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2123 | msg = xmlStrcat(msg, (const xmlChar *) message); |
| 2124 | msg = xmlStrcat(msg, BAD_CAST ".\n"); |
| 2125 | xmlSchemaVErr(ctxt, node, error, (const char *) msg, BAD_CAST des, NULL); |
| 2126 | FREE_AND_NULL(des); |
| 2127 | FREE_AND_NULL(msg); |
| 2128 | } |
| 2129 | |
| 2130 | /** |
| 2131 | * xmlSchemaVMissingAttrErr: |
| 2132 | * @ctxt: the schema validation context |
| 2133 | * @node: the parent element node of the missing attribute node |
| 2134 | * @type: the corresponding type of the attribute node |
| 2135 | * |
| 2136 | * Reports an illegal attribute. |
| 2137 | */ |
| 2138 | static void |
| 2139 | xmlSchemaVMissingAttrErr(xmlSchemaValidCtxtPtr ctxt, |
| 2140 | xmlNodePtr elem, |
| 2141 | xmlSchemaAttributePtr type) |
| 2142 | { |
| 2143 | const xmlChar *name, *uri; |
| 2144 | xmlChar *strE = NULL, *strA = NULL; |
| 2145 | |
| 2146 | if (type->ref != NULL) { |
| 2147 | name = type->ref; |
| 2148 | uri = type->refNs; |
| 2149 | } else { |
| 2150 | name = type->name; |
| 2151 | uri = type->targetNamespace; |
| 2152 | } |
| 2153 | xmlSchemaVErr(ctxt, elem, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 2154 | XML_SCHEMAV_CVC_COMPLEX_TYPE_4, |
| 2155 | /* XML_SCHEMAS_ERR_MISSING, */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2156 | "%s: The attribute %s is required but missing.\n", |
| 2157 | xmlSchemaFormatItemForReport(&strE, NULL, NULL, elem, 0), |
| 2158 | xmlSchemaFormatNsUriLocal(&strA, uri, name)); |
| 2159 | FREE_AND_NULL(strE) |
| 2160 | FREE_AND_NULL(strA) |
| 2161 | } |
| 2162 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2163 | /************************************************************************ |
| 2164 | * * |
| 2165 | * Allocation functions * |
| 2166 | * * |
| 2167 | ************************************************************************/ |
| 2168 | |
| 2169 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 2170 | * xmlSchemaNewSchemaForParserCtxt: |
William M. Brack | 0817191 | 2003-12-29 02:52:11 +0000 | [diff] [blame] | 2171 | * @ctxt: a schema validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2172 | * |
| 2173 | * Allocate a new Schema structure. |
| 2174 | * |
| 2175 | * Returns the newly allocated structure or NULL in case or error |
| 2176 | */ |
| 2177 | static xmlSchemaPtr |
| 2178 | xmlSchemaNewSchema(xmlSchemaParserCtxtPtr ctxt) |
| 2179 | { |
| 2180 | xmlSchemaPtr ret; |
| 2181 | |
| 2182 | ret = (xmlSchemaPtr) xmlMalloc(sizeof(xmlSchema)); |
| 2183 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2184 | xmlSchemaPErrMemory(ctxt, "allocating schema", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2185 | return (NULL); |
| 2186 | } |
| 2187 | memset(ret, 0, sizeof(xmlSchema)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2188 | ret->dict = ctxt->dict; |
Daniel Veillard | 500a1de | 2004-03-22 15:22:58 +0000 | [diff] [blame] | 2189 | xmlDictReference(ret->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2190 | |
| 2191 | return (ret); |
| 2192 | } |
| 2193 | |
| 2194 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 2195 | * xmlSchemaNewSchema: |
| 2196 | * @ctxt: a schema validation context |
| 2197 | * |
| 2198 | * Allocate a new Schema structure. |
| 2199 | * |
| 2200 | * Returns the newly allocated structure or NULL in case or error |
| 2201 | */ |
| 2202 | static xmlSchemaAssemblePtr |
| 2203 | xmlSchemaNewAssemble(void) |
| 2204 | { |
| 2205 | xmlSchemaAssemblePtr ret; |
| 2206 | |
| 2207 | ret = (xmlSchemaAssemblePtr) xmlMalloc(sizeof(xmlSchemaAssemble)); |
| 2208 | if (ret == NULL) { |
| 2209 | /* xmlSchemaPErrMemory(ctxt, "allocating assemble info", NULL); */ |
| 2210 | return (NULL); |
| 2211 | } |
| 2212 | memset(ret, 0, sizeof(xmlSchemaAssemble)); |
| 2213 | ret->items = NULL; |
| 2214 | return (ret); |
| 2215 | } |
| 2216 | |
| 2217 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2218 | * xmlSchemaNewFacet: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2219 | * |
| 2220 | * Allocate a new Facet structure. |
| 2221 | * |
| 2222 | * Returns the newly allocated structure or NULL in case or error |
| 2223 | */ |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 2224 | xmlSchemaFacetPtr |
| 2225 | xmlSchemaNewFacet(void) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2226 | { |
| 2227 | xmlSchemaFacetPtr ret; |
| 2228 | |
| 2229 | ret = (xmlSchemaFacetPtr) xmlMalloc(sizeof(xmlSchemaFacet)); |
| 2230 | if (ret == NULL) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2231 | return (NULL); |
| 2232 | } |
| 2233 | memset(ret, 0, sizeof(xmlSchemaFacet)); |
| 2234 | |
| 2235 | return (ret); |
| 2236 | } |
| 2237 | |
| 2238 | /** |
| 2239 | * xmlSchemaNewAnnot: |
William M. Brack | 0817191 | 2003-12-29 02:52:11 +0000 | [diff] [blame] | 2240 | * @ctxt: a schema validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2241 | * @node: a node |
| 2242 | * |
| 2243 | * Allocate a new annotation structure. |
| 2244 | * |
| 2245 | * Returns the newly allocated structure or NULL in case or error |
| 2246 | */ |
| 2247 | static xmlSchemaAnnotPtr |
| 2248 | xmlSchemaNewAnnot(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node) |
| 2249 | { |
| 2250 | xmlSchemaAnnotPtr ret; |
| 2251 | |
| 2252 | ret = (xmlSchemaAnnotPtr) xmlMalloc(sizeof(xmlSchemaAnnot)); |
| 2253 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2254 | xmlSchemaPErrMemory(ctxt, "allocating annotation", node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2255 | return (NULL); |
| 2256 | } |
| 2257 | memset(ret, 0, sizeof(xmlSchemaAnnot)); |
| 2258 | ret->content = node; |
| 2259 | return (ret); |
| 2260 | } |
| 2261 | |
| 2262 | /** |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 2263 | * xmlSchemaFreeAnnot: |
| 2264 | * @annot: a schema type structure |
| 2265 | * |
| 2266 | * Deallocate a annotation structure |
| 2267 | */ |
| 2268 | static void |
| 2269 | xmlSchemaFreeAnnot(xmlSchemaAnnotPtr annot) |
| 2270 | { |
| 2271 | if (annot == NULL) |
| 2272 | return; |
| 2273 | xmlFree(annot); |
| 2274 | } |
| 2275 | |
| 2276 | /** |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 2277 | * xmlSchemaFreeImport: |
| 2278 | * @import: a schema import structure |
| 2279 | * |
| 2280 | * Deallocate an import structure |
| 2281 | */ |
| 2282 | static void |
| 2283 | xmlSchemaFreeImport(xmlSchemaImportPtr import) |
| 2284 | { |
| 2285 | if (import == NULL) |
| 2286 | return; |
| 2287 | |
| 2288 | xmlSchemaFree(import->schema); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2289 | xmlFreeDoc(import->doc); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 2290 | xmlFree(import); |
| 2291 | } |
| 2292 | |
| 2293 | /** |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 2294 | * xmlSchemaFreeInclude: |
| 2295 | * @include: a schema include structure |
| 2296 | * |
| 2297 | * Deallocate an include structure |
| 2298 | */ |
| 2299 | static void |
| 2300 | xmlSchemaFreeInclude(xmlSchemaIncludePtr include) |
| 2301 | { |
| 2302 | if (include == NULL) |
| 2303 | return; |
| 2304 | |
| 2305 | xmlFreeDoc(include->doc); |
| 2306 | xmlFree(include); |
| 2307 | } |
| 2308 | |
| 2309 | /** |
| 2310 | * xmlSchemaFreeIncludeList: |
| 2311 | * @includes: a schema include list |
| 2312 | * |
| 2313 | * Deallocate an include structure |
| 2314 | */ |
| 2315 | static void |
| 2316 | xmlSchemaFreeIncludeList(xmlSchemaIncludePtr includes) |
| 2317 | { |
| 2318 | xmlSchemaIncludePtr next; |
| 2319 | |
| 2320 | while (includes != NULL) { |
| 2321 | next = includes->next; |
| 2322 | xmlSchemaFreeInclude(includes); |
| 2323 | includes = next; |
| 2324 | } |
| 2325 | } |
| 2326 | |
| 2327 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2328 | * xmlSchemaFreeNotation: |
| 2329 | * @schema: a schema notation structure |
| 2330 | * |
| 2331 | * Deallocate a Schema Notation structure. |
| 2332 | */ |
| 2333 | static void |
| 2334 | xmlSchemaFreeNotation(xmlSchemaNotationPtr nota) |
| 2335 | { |
| 2336 | if (nota == NULL) |
| 2337 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2338 | xmlFree(nota); |
| 2339 | } |
| 2340 | |
| 2341 | /** |
| 2342 | * xmlSchemaFreeAttribute: |
| 2343 | * @schema: a schema attribute structure |
| 2344 | * |
| 2345 | * Deallocate a Schema Attribute structure. |
| 2346 | */ |
| 2347 | static void |
| 2348 | xmlSchemaFreeAttribute(xmlSchemaAttributePtr attr) |
| 2349 | { |
| 2350 | if (attr == NULL) |
| 2351 | return; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2352 | if (attr->annot != NULL) |
| 2353 | xmlSchemaFreeAnnot(attr->annot); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 2354 | if (attr->defVal != NULL) |
| 2355 | xmlSchemaFreeValue(attr->defVal); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2356 | xmlFree(attr); |
| 2357 | } |
| 2358 | |
| 2359 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2360 | * xmlSchemaFreeWildcardNsSet: |
| 2361 | * set: a schema wildcard namespace |
| 2362 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2363 | * Deallocates a list of wildcard constraint structures. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2364 | */ |
| 2365 | static void |
| 2366 | xmlSchemaFreeWildcardNsSet(xmlSchemaWildcardNsPtr set) |
| 2367 | { |
| 2368 | xmlSchemaWildcardNsPtr next; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 2369 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2370 | while (set != NULL) { |
| 2371 | next = set->next; |
| 2372 | xmlFree(set); |
| 2373 | set = next; |
| 2374 | } |
| 2375 | } |
| 2376 | |
| 2377 | /** |
| 2378 | * xmlSchemaFreeWildcard: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2379 | * @wildcard: a wildcard structure |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2380 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2381 | * Deallocates a wildcard structure. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2382 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2383 | void |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2384 | xmlSchemaFreeWildcard(xmlSchemaWildcardPtr wildcard) |
| 2385 | { |
| 2386 | if (wildcard == NULL) |
| 2387 | return; |
| 2388 | if (wildcard->annot != NULL) |
| 2389 | xmlSchemaFreeAnnot(wildcard->annot); |
| 2390 | if (wildcard->nsSet != NULL) |
| 2391 | xmlSchemaFreeWildcardNsSet(wildcard->nsSet); |
| 2392 | if (wildcard->negNsSet != NULL) |
| 2393 | xmlFree(wildcard->negNsSet); |
| 2394 | xmlFree(wildcard); |
| 2395 | } |
| 2396 | |
| 2397 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2398 | * xmlSchemaFreeAttributeGroup: |
| 2399 | * @schema: a schema attribute group structure |
| 2400 | * |
| 2401 | * Deallocate a Schema Attribute Group structure. |
| 2402 | */ |
| 2403 | static void |
| 2404 | xmlSchemaFreeAttributeGroup(xmlSchemaAttributeGroupPtr attr) |
| 2405 | { |
| 2406 | if (attr == NULL) |
| 2407 | return; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2408 | if (attr->annot != NULL) |
| 2409 | xmlSchemaFreeAnnot(attr->annot); |
| 2410 | if ((attr->flags & XML_SCHEMAS_ATTRGROUP_GLOBAL) && |
| 2411 | (attr->attributeWildcard != NULL)) |
| 2412 | xmlSchemaFreeWildcard(attr->attributeWildcard); |
| 2413 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2414 | xmlFree(attr); |
| 2415 | } |
| 2416 | |
| 2417 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2418 | * xmlSchemaFreeAttributeUseList: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2419 | * @attrUse: an attribute link |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2420 | * |
| 2421 | * Deallocate a list of schema attribute uses. |
| 2422 | */ |
| 2423 | static void |
| 2424 | xmlSchemaFreeAttributeUseList(xmlSchemaAttributeLinkPtr attrUse) |
| 2425 | { |
| 2426 | xmlSchemaAttributeLinkPtr next; |
| 2427 | |
| 2428 | while (attrUse != NULL) { |
| 2429 | next = attrUse->next; |
| 2430 | xmlFree(attrUse); |
| 2431 | attrUse = next; |
| 2432 | } |
| 2433 | } |
| 2434 | |
| 2435 | /** |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2436 | * xmlSchemaFreeTypeLinkList: |
| 2437 | * @alink: a type link |
| 2438 | * |
| 2439 | * Deallocate a list of types. |
| 2440 | */ |
| 2441 | static void |
| 2442 | xmlSchemaFreeTypeLinkList(xmlSchemaTypeLinkPtr link) |
| 2443 | { |
| 2444 | xmlSchemaTypeLinkPtr next; |
| 2445 | |
| 2446 | while (link != NULL) { |
| 2447 | next = link->next; |
| 2448 | xmlFree(link); |
| 2449 | link = next; |
| 2450 | } |
| 2451 | } |
| 2452 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 2453 | #ifdef IDC_ENABLED |
| 2454 | static void |
| 2455 | xmlSchemaFreeIDCStateObjList(xmlSchemaIDCStateObjPtr sto) |
| 2456 | { |
| 2457 | xmlSchemaIDCStateObjPtr next; |
| 2458 | while (sto != NULL) { |
| 2459 | next = sto->next; |
| 2460 | if (sto->history != NULL) |
| 2461 | xmlFree(sto->history); |
| 2462 | if (sto->xpathCtxt != NULL) |
| 2463 | xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt); |
| 2464 | xmlFree(sto); |
| 2465 | sto = next; |
| 2466 | } |
| 2467 | } |
| 2468 | |
| 2469 | /** |
| 2470 | * xmlSchemaFreeIDC: |
| 2471 | * @idc: a identity-constraint definition |
| 2472 | * |
| 2473 | * Deallocates an identity-constraint definition. |
| 2474 | */ |
| 2475 | static void |
| 2476 | xmlSchemaFreeIDC(xmlSchemaIDCPtr idcDef) |
| 2477 | { |
| 2478 | xmlSchemaIDCSelectPtr cur, prev; |
| 2479 | |
| 2480 | if (idcDef == NULL) |
| 2481 | return; |
| 2482 | if (idcDef->annot != NULL) |
| 2483 | xmlSchemaFreeAnnot(idcDef->annot); |
| 2484 | if (idcDef->ref != NULL) |
| 2485 | xmlFree(idcDef->ref); |
| 2486 | /* Selector */ |
| 2487 | if (idcDef->selector != NULL) { |
| 2488 | if (idcDef->selector->xpathComp != NULL) |
| 2489 | xmlFreePattern((xmlPatternPtr) idcDef->selector->xpathComp); |
| 2490 | xmlFree(idcDef->selector); |
| 2491 | } |
| 2492 | /* Fields */ |
| 2493 | if (idcDef->fields != NULL) { |
| 2494 | cur = idcDef->fields; |
| 2495 | do { |
| 2496 | prev = cur; |
| 2497 | cur = cur->next; |
| 2498 | if (prev->xpathComp != NULL) |
| 2499 | xmlFreePattern((xmlPatternPtr) prev->xpathComp); |
| 2500 | xmlFree(prev); |
| 2501 | } while (cur != NULL); |
| 2502 | } |
| 2503 | xmlFree(idcDef); |
| 2504 | } |
| 2505 | #endif /* IDC_ENABLED */ |
| 2506 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2507 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2508 | * xmlSchemaFreeElement: |
| 2509 | * @schema: a schema element structure |
| 2510 | * |
| 2511 | * Deallocate a Schema Element structure. |
| 2512 | */ |
| 2513 | static void |
| 2514 | xmlSchemaFreeElement(xmlSchemaElementPtr elem) |
| 2515 | { |
| 2516 | if (elem == NULL) |
| 2517 | return; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 2518 | if (elem->annot != NULL) |
| 2519 | xmlSchemaFreeAnnot(elem->annot); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2520 | if (elem->contModel != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2521 | xmlRegFreeRegexp(elem->contModel); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 2522 | if (elem->defVal != NULL) |
| 2523 | xmlSchemaFreeValue(elem->defVal); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2524 | xmlFree(elem); |
| 2525 | } |
| 2526 | |
| 2527 | /** |
| 2528 | * xmlSchemaFreeFacet: |
| 2529 | * @facet: a schema facet structure |
| 2530 | * |
| 2531 | * Deallocate a Schema Facet structure. |
| 2532 | */ |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 2533 | void |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2534 | xmlSchemaFreeFacet(xmlSchemaFacetPtr facet) |
| 2535 | { |
| 2536 | if (facet == NULL) |
| 2537 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2538 | if (facet->val != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2539 | xmlSchemaFreeValue(facet->val); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2540 | if (facet->regexp != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2541 | xmlRegFreeRegexp(facet->regexp); |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 2542 | if (facet->annot != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2543 | xmlSchemaFreeAnnot(facet->annot); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2544 | xmlFree(facet); |
| 2545 | } |
| 2546 | |
| 2547 | /** |
| 2548 | * xmlSchemaFreeType: |
| 2549 | * @type: a schema type structure |
| 2550 | * |
| 2551 | * Deallocate a Schema Type structure. |
| 2552 | */ |
| 2553 | void |
| 2554 | xmlSchemaFreeType(xmlSchemaTypePtr type) |
| 2555 | { |
| 2556 | if (type == NULL) |
| 2557 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2558 | if (type->annot != NULL) |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 2559 | xmlSchemaFreeAnnot(type->annot); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2560 | if (type->facets != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2561 | xmlSchemaFacetPtr facet, next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2562 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2563 | facet = type->facets; |
| 2564 | while (facet != NULL) { |
| 2565 | next = facet->next; |
| 2566 | xmlSchemaFreeFacet(facet); |
| 2567 | facet = next; |
| 2568 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2569 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2570 | if (type->type != XML_SCHEMA_TYPE_BASIC) { |
| 2571 | if (type->attributeUses != NULL) |
| 2572 | xmlSchemaFreeAttributeUseList(type->attributeUses); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 2573 | if ((type->attributeWildcard != NULL) && |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2574 | ((type->type != XML_SCHEMA_TYPE_COMPLEX) || |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 2575 | (type->flags & XML_SCHEMAS_TYPE_OWNED_ATTR_WILDCARD))) { |
| 2576 | /* |
| 2577 | * NOTE: The only case where an attribute wildcard |
| 2578 | * is not owned, is if a complex type inherits it |
| 2579 | * from a base type. |
| 2580 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 2581 | xmlSchemaFreeWildcard(type->attributeWildcard); |
| 2582 | } |
| 2583 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2584 | if (type->memberTypes != NULL) |
| 2585 | xmlSchemaFreeTypeLinkList(type->memberTypes); |
| 2586 | if (type->facetSet != NULL) { |
| 2587 | xmlSchemaFacetLinkPtr next, link; |
| 2588 | |
| 2589 | link = type->facetSet; |
| 2590 | do { |
| 2591 | next = link->next; |
| 2592 | xmlFree(link); |
| 2593 | link = next; |
| 2594 | } while (link != NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 2595 | } |
| 2596 | if (type->contModel != NULL) |
| 2597 | xmlRegFreeRegexp(type->contModel); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2598 | xmlFree(type); |
| 2599 | } |
| 2600 | |
| 2601 | /** |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 2602 | * xmlSchemaFreeTypeList: |
| 2603 | * @type: a schema type structure |
| 2604 | * |
| 2605 | * Deallocate a Schema Type structure. |
| 2606 | */ |
| 2607 | static void |
| 2608 | xmlSchemaFreeTypeList(xmlSchemaTypePtr type) |
| 2609 | { |
| 2610 | xmlSchemaTypePtr next; |
| 2611 | |
| 2612 | while (type != NULL) { |
| 2613 | next = type->redef; |
| 2614 | xmlSchemaFreeType(type); |
| 2615 | type = next; |
| 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2620 | * xmlSchemaFree: |
| 2621 | * @schema: a schema structure |
| 2622 | * |
| 2623 | * Deallocate a Schema structure. |
| 2624 | */ |
| 2625 | void |
| 2626 | xmlSchemaFree(xmlSchemaPtr schema) |
| 2627 | { |
| 2628 | if (schema == NULL) |
| 2629 | return; |
| 2630 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2631 | if (schema->notaDecl != NULL) |
| 2632 | xmlHashFree(schema->notaDecl, |
| 2633 | (xmlHashDeallocator) xmlSchemaFreeNotation); |
| 2634 | if (schema->attrDecl != NULL) |
| 2635 | xmlHashFree(schema->attrDecl, |
| 2636 | (xmlHashDeallocator) xmlSchemaFreeAttribute); |
| 2637 | if (schema->attrgrpDecl != NULL) |
| 2638 | xmlHashFree(schema->attrgrpDecl, |
| 2639 | (xmlHashDeallocator) xmlSchemaFreeAttributeGroup); |
| 2640 | if (schema->elemDecl != NULL) |
| 2641 | xmlHashFree(schema->elemDecl, |
| 2642 | (xmlHashDeallocator) xmlSchemaFreeElement); |
| 2643 | if (schema->typeDecl != NULL) |
| 2644 | xmlHashFree(schema->typeDecl, |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 2645 | (xmlHashDeallocator) xmlSchemaFreeTypeList); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 2646 | if (schema->groupDecl != NULL) |
| 2647 | xmlHashFree(schema->groupDecl, |
| 2648 | (xmlHashDeallocator) xmlSchemaFreeType); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 2649 | #ifdef IDC_ENABLED |
| 2650 | if (schema->idcDef != NULL) |
| 2651 | xmlHashFree(schema->idcDef, |
| 2652 | (xmlHashDeallocator) xmlSchemaFreeIDC); |
| 2653 | #endif |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 2654 | if (schema->schemasImports != NULL) |
| 2655 | xmlHashFree(schema->schemasImports, |
| 2656 | (xmlHashDeallocator) xmlSchemaFreeImport); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 2657 | if (schema->includes != NULL) { |
| 2658 | xmlSchemaFreeIncludeList((xmlSchemaIncludePtr) schema->includes); |
| 2659 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2660 | if (schema->annot != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2661 | xmlSchemaFreeAnnot(schema->annot); |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 2662 | if (schema->doc != NULL && !schema->preserve) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2663 | xmlFreeDoc(schema->doc); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 2664 | xmlDictFree(schema->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2665 | xmlFree(schema); |
| 2666 | } |
| 2667 | |
| 2668 | /************************************************************************ |
| 2669 | * * |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2670 | * Debug functions * |
| 2671 | * * |
| 2672 | ************************************************************************/ |
| 2673 | |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2674 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2675 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2676 | /** |
| 2677 | * xmlSchemaElementDump: |
| 2678 | * @elem: an element |
| 2679 | * @output: the file output |
| 2680 | * |
| 2681 | * Dump the element |
| 2682 | */ |
| 2683 | static void |
| 2684 | xmlSchemaElementDump(xmlSchemaElementPtr elem, FILE * output, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2685 | const xmlChar * name ATTRIBUTE_UNUSED, |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2686 | const xmlChar * namespace ATTRIBUTE_UNUSED, |
| 2687 | const xmlChar * context ATTRIBUTE_UNUSED) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2688 | { |
| 2689 | if (elem == NULL) |
| 2690 | return; |
| 2691 | |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2692 | if (elem->flags & XML_SCHEMAS_ELEM_REF) { |
| 2693 | fprintf(output, "Particle: %s", name); |
| 2694 | fprintf(output, ", term element: %s", elem->ref); |
| 2695 | if (elem->refNs != NULL) |
| 2696 | fprintf(output, " ns %s", elem->refNs); |
| 2697 | } else { |
| 2698 | fprintf(output, "Element"); |
| 2699 | if (elem->flags & XML_SCHEMAS_ELEM_GLOBAL) |
| 2700 | fprintf(output, " (global)"); |
| 2701 | fprintf(output, ": %s ", elem->name); |
| 2702 | if (namespace != NULL) |
| 2703 | fprintf(output, "ns %s", namespace); |
| 2704 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2705 | fprintf(output, "\n"); |
| 2706 | if ((elem->minOccurs != 1) || (elem->maxOccurs != 1)) { |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2707 | fprintf(output, " min %d ", elem->minOccurs); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2708 | if (elem->maxOccurs >= UNBOUNDED) |
| 2709 | fprintf(output, "max: unbounded\n"); |
| 2710 | else if (elem->maxOccurs != 1) |
| 2711 | fprintf(output, "max: %d\n", elem->maxOccurs); |
| 2712 | else |
| 2713 | fprintf(output, "\n"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2714 | } |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2715 | /* |
| 2716 | * Misc other properties. |
| 2717 | */ |
| 2718 | if ((elem->flags & XML_SCHEMAS_ELEM_NILLABLE) || |
| 2719 | (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT) || |
| 2720 | (elem->flags & XML_SCHEMAS_ELEM_FIXED) || |
| 2721 | (elem->flags & XML_SCHEMAS_ELEM_DEFAULT) || |
| 2722 | (elem->id != NULL)) { |
| 2723 | fprintf(output, " props: "); |
| 2724 | if (elem->flags & XML_SCHEMAS_ELEM_FIXED) |
| 2725 | fprintf(output, "[fixed] "); |
| 2726 | if (elem->flags & XML_SCHEMAS_ELEM_DEFAULT) |
| 2727 | fprintf(output, "[default] "); |
| 2728 | if (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT) |
| 2729 | fprintf(output, "[abstract] "); |
| 2730 | if (elem->flags & XML_SCHEMAS_ELEM_NILLABLE) |
| 2731 | fprintf(output, "[nillable] "); |
| 2732 | if (elem->id != NULL) |
| 2733 | fprintf(output, "[id: '%s'] ", elem->id); |
| 2734 | fprintf(output, "\n"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2735 | } |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2736 | /* |
| 2737 | * Default/fixed value. |
| 2738 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2739 | if (elem->value != NULL) |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2740 | fprintf(output, " value: '%s'\n", elem->value); |
| 2741 | /* |
| 2742 | * Type. |
| 2743 | */ |
| 2744 | if (elem->namedType != NULL) { |
| 2745 | fprintf(output, " type: %s ", elem->namedType); |
| 2746 | if (elem->namedTypeNs != NULL) |
| 2747 | fprintf(output, "ns %s\n", elem->namedTypeNs); |
| 2748 | else |
| 2749 | fprintf(output, "\n"); |
| 2750 | } |
| 2751 | /* |
| 2752 | * Substitution group. |
| 2753 | */ |
| 2754 | if (elem->substGroup != NULL) { |
| 2755 | fprintf(output, " substitutionGroup: %s ", elem->substGroup); |
| 2756 | if (elem->substGroupNs != NULL) |
| 2757 | fprintf(output, "ns %s\n", elem->substGroupNs); |
| 2758 | else |
| 2759 | fprintf(output, "\n"); |
| 2760 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2761 | } |
| 2762 | |
| 2763 | /** |
| 2764 | * xmlSchemaAnnotDump: |
| 2765 | * @output: the file output |
| 2766 | * @annot: a annotation |
| 2767 | * |
| 2768 | * Dump the annotation |
| 2769 | */ |
| 2770 | static void |
| 2771 | xmlSchemaAnnotDump(FILE * output, xmlSchemaAnnotPtr annot) |
| 2772 | { |
| 2773 | xmlChar *content; |
| 2774 | |
| 2775 | if (annot == NULL) |
| 2776 | return; |
| 2777 | |
| 2778 | content = xmlNodeGetContent(annot->content); |
| 2779 | if (content != NULL) { |
| 2780 | fprintf(output, " Annot: %s\n", content); |
| 2781 | xmlFree(content); |
| 2782 | } else |
| 2783 | fprintf(output, " Annot: empty\n"); |
| 2784 | } |
| 2785 | |
| 2786 | /** |
| 2787 | * xmlSchemaTypeDump: |
| 2788 | * @output: the file output |
| 2789 | * @type: a type structure |
| 2790 | * |
| 2791 | * Dump a SchemaType structure |
| 2792 | */ |
| 2793 | static void |
| 2794 | xmlSchemaTypeDump(xmlSchemaTypePtr type, FILE * output) |
| 2795 | { |
| 2796 | if (type == NULL) { |
| 2797 | fprintf(output, "Type: NULL\n"); |
| 2798 | return; |
| 2799 | } |
| 2800 | fprintf(output, "Type: "); |
| 2801 | if (type->name != NULL) |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2802 | fprintf(output, "%s ", type->name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2803 | else |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2804 | fprintf(output, "no name "); |
| 2805 | if (type->targetNamespace != NULL) |
| 2806 | fprintf(output, "ns %s ", type->targetNamespace); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2807 | switch (type->type) { |
| 2808 | case XML_SCHEMA_TYPE_BASIC: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2809 | fprintf(output, "[basic] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2810 | break; |
| 2811 | case XML_SCHEMA_TYPE_SIMPLE: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2812 | fprintf(output, "[simple] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2813 | break; |
| 2814 | case XML_SCHEMA_TYPE_COMPLEX: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2815 | fprintf(output, "[complex] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2816 | break; |
| 2817 | case XML_SCHEMA_TYPE_SEQUENCE: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2818 | fprintf(output, "[sequence] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2819 | break; |
| 2820 | case XML_SCHEMA_TYPE_CHOICE: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2821 | fprintf(output, "[choice] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2822 | break; |
| 2823 | case XML_SCHEMA_TYPE_ALL: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2824 | fprintf(output, "[all] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2825 | break; |
| 2826 | case XML_SCHEMA_TYPE_UR: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2827 | fprintf(output, "[ur] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2828 | break; |
| 2829 | case XML_SCHEMA_TYPE_RESTRICTION: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2830 | fprintf(output, "[restriction] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2831 | break; |
| 2832 | case XML_SCHEMA_TYPE_EXTENSION: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2833 | fprintf(output, "[extension] "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2834 | break; |
| 2835 | default: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2836 | fprintf(output, "[unknown type %d] ", type->type); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2837 | break; |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2838 | } |
| 2839 | fprintf(output, "content: "); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2840 | switch (type->contentType) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2841 | case XML_SCHEMA_CONTENT_UNKNOWN: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2842 | fprintf(output, "[unknown] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2843 | break; |
| 2844 | case XML_SCHEMA_CONTENT_EMPTY: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2845 | fprintf(output, "[empty] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2846 | break; |
| 2847 | case XML_SCHEMA_CONTENT_ELEMENTS: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2848 | fprintf(output, "[element] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2849 | break; |
| 2850 | case XML_SCHEMA_CONTENT_MIXED: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2851 | fprintf(output, "[mixed] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2852 | break; |
| 2853 | case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS: |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 2854 | /* not used. */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2855 | break; |
| 2856 | case XML_SCHEMA_CONTENT_BASIC: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2857 | fprintf(output, "[basic] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2858 | break; |
| 2859 | case XML_SCHEMA_CONTENT_SIMPLE: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2860 | fprintf(output, "[simple] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2861 | break; |
| 2862 | case XML_SCHEMA_CONTENT_ANY: |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2863 | fprintf(output, "[any] "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2864 | break; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2865 | } |
| 2866 | fprintf(output, "\n"); |
| 2867 | if ((type->minOccurs != 1) || (type->maxOccurs != 1)) { |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2868 | fprintf(output, " min: %d ", type->minOccurs); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2869 | if (type->maxOccurs >= UNBOUNDED) |
| 2870 | fprintf(output, "max: unbounded\n"); |
| 2871 | else if (type->maxOccurs != 1) |
| 2872 | fprintf(output, "max: %d\n", type->maxOccurs); |
| 2873 | else |
| 2874 | fprintf(output, "\n"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2875 | } |
Kasimier T. Buchcik | f500aec | 2005-01-19 16:30:24 +0000 | [diff] [blame] | 2876 | if (type->base != NULL) { |
| 2877 | fprintf(output, " base type: %s", type->base); |
| 2878 | if (type->baseNs != NULL) |
| 2879 | fprintf(output, " ns %s\n", type->baseNs); |
| 2880 | else |
| 2881 | fprintf(output, "\n"); |
| 2882 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2883 | if (type->annot != NULL) |
| 2884 | xmlSchemaAnnotDump(output, type->annot); |
| 2885 | if (type->subtypes != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2886 | xmlSchemaTypePtr sub = type->subtypes; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2887 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2888 | fprintf(output, " subtypes: "); |
| 2889 | while (sub != NULL) { |
| 2890 | fprintf(output, "%s ", sub->name); |
| 2891 | sub = sub->next; |
| 2892 | } |
| 2893 | fprintf(output, "\n"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | } |
| 2897 | |
| 2898 | /** |
| 2899 | * xmlSchemaDump: |
| 2900 | * @output: the file output |
| 2901 | * @schema: a schema structure |
| 2902 | * |
| 2903 | * Dump a Schema structure. |
| 2904 | */ |
| 2905 | void |
| 2906 | xmlSchemaDump(FILE * output, xmlSchemaPtr schema) |
| 2907 | { |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 2908 | if (output == NULL) |
| 2909 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2910 | if (schema == NULL) { |
| 2911 | fprintf(output, "Schemas: NULL\n"); |
| 2912 | return; |
| 2913 | } |
| 2914 | fprintf(output, "Schemas: "); |
| 2915 | if (schema->name != NULL) |
| 2916 | fprintf(output, "%s, ", schema->name); |
| 2917 | else |
| 2918 | fprintf(output, "no name, "); |
| 2919 | if (schema->targetNamespace != NULL) |
Daniel Veillard | 580ced8 | 2003-03-21 21:22:48 +0000 | [diff] [blame] | 2920 | fprintf(output, "%s", (const char *) schema->targetNamespace); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2921 | else |
| 2922 | fprintf(output, "no target namespace"); |
| 2923 | fprintf(output, "\n"); |
| 2924 | if (schema->annot != NULL) |
| 2925 | xmlSchemaAnnotDump(output, schema->annot); |
| 2926 | |
| 2927 | xmlHashScan(schema->typeDecl, (xmlHashScanner) xmlSchemaTypeDump, |
| 2928 | output); |
| 2929 | xmlHashScanFull(schema->elemDecl, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2930 | (xmlHashScannerFull) xmlSchemaElementDump, output); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2931 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 2932 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 2933 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 2934 | #ifdef DEBUG_IDC |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 2935 | /** |
| 2936 | * xmlSchemaDebugDumpIDCTable: |
| 2937 | * @vctxt: the WXS validation context |
| 2938 | * |
| 2939 | * Displays the current IDC table for debug purposes. |
| 2940 | */ |
| 2941 | static void |
| 2942 | xmlSchemaDebugDumpIDCTable(FILE * output, |
| 2943 | const xmlChar *namespaceName, |
| 2944 | const xmlChar *localName, |
| 2945 | xmlSchemaPSVIIDCBindingPtr bind) |
| 2946 | { |
| 2947 | xmlChar *str = NULL, *value; |
| 2948 | xmlSchemaPSVIIDCNodePtr tab; |
| 2949 | xmlSchemaPSVIIDCKeyPtr key; |
| 2950 | int i, j, res; |
| 2951 | |
| 2952 | fprintf(output, "IDC: TABLES on %s\n", |
| 2953 | xmlSchemaFormatNsUriLocal(&str, namespaceName, localName)); |
| 2954 | FREE_AND_NULL(str) |
| 2955 | |
| 2956 | if (bind == NULL) |
| 2957 | return; |
| 2958 | do { |
| 2959 | fprintf(output, "IDC: BINDING %s\n", |
| 2960 | xmlSchemaFormatNsUriLocal(&str, bind->definition->targetNamespace, |
| 2961 | bind->definition->name)); |
| 2962 | FREE_AND_NULL(str) |
| 2963 | for (i = 0; i < bind->nbNodes; i++) { |
| 2964 | tab = bind->nodeTable[i]; |
| 2965 | fprintf(output, " ( "); |
| 2966 | for (j = 0; j < bind->definition->nbFields; j++) { |
| 2967 | key = tab->keys[j]; |
| 2968 | if ((key != NULL) && (key->compValue != NULL)) { |
| 2969 | #ifdef IDC_VALUE_SUPPORT |
| 2970 | res = xmlSchemaGetCanonValue(key->compValue, &value); |
| 2971 | #else |
| 2972 | value = xmlStrdup(BAD_CAST "dummy-value"); |
| 2973 | res = 0; |
| 2974 | #endif |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 2975 | if (res >= 0) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 2976 | fprintf(output, "\"%s\" ", value); |
| 2977 | else |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 2978 | fprintf(output, "CANON-VALUE-FAILED "); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 2979 | if (res == 0) |
| 2980 | FREE_AND_NULL(value) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 2981 | } else if (key != NULL) |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 2982 | fprintf(output, "(no val), "); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 2983 | else |
| 2984 | fprintf(output, "(key missing), "); |
| 2985 | } |
| 2986 | fprintf(output, ")\n"); |
| 2987 | } |
| 2988 | bind = bind->next; |
| 2989 | } while (bind != NULL); |
| 2990 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 2991 | #endif /* DEBUG_IDC */ |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 2992 | #endif /* IDC_ENABLED */ |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2993 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 2994 | |
| 2995 | /************************************************************************ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 2996 | * * |
| 2997 | * Utilities * |
| 2998 | * * |
| 2999 | ************************************************************************/ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3000 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3001 | /** |
| 3002 | * xmlSchemaGetPropNode: |
| 3003 | * @node: the element node |
| 3004 | * @name: the name of the attribute |
| 3005 | * |
| 3006 | * Seeks an attribute with a name of @name in |
| 3007 | * no namespace. |
| 3008 | * |
| 3009 | * Returns the attribute or NULL if not present. |
| 3010 | */ |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 3011 | static xmlAttrPtr |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3012 | xmlSchemaGetPropNode(xmlNodePtr node, const char *name) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3013 | { |
| 3014 | xmlAttrPtr prop; |
| 3015 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3016 | if ((node == NULL) || (name == NULL)) |
| 3017 | return(NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3018 | prop = node->properties; |
| 3019 | while (prop != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3020 | if ((prop->ns == NULL) && xmlStrEqual(prop->name, BAD_CAST name)) |
| 3021 | return(prop); |
| 3022 | prop = prop->next; |
| 3023 | } |
| 3024 | return (NULL); |
| 3025 | } |
| 3026 | |
| 3027 | /** |
| 3028 | * xmlSchemaGetPropNodeNs: |
| 3029 | * @node: the element node |
| 3030 | * @uri: the uri |
| 3031 | * @name: the name of the attribute |
| 3032 | * |
| 3033 | * Seeks an attribute with a local name of @name and |
| 3034 | * a namespace URI of @uri. |
| 3035 | * |
| 3036 | * Returns the attribute or NULL if not present. |
| 3037 | */ |
| 3038 | static xmlAttrPtr |
| 3039 | xmlSchemaGetPropNodeNs(xmlNodePtr node, const char *uri, const char *name) |
| 3040 | { |
| 3041 | xmlAttrPtr prop; |
| 3042 | |
| 3043 | if ((node == NULL) || (name == NULL)) |
| 3044 | return(NULL); |
| 3045 | prop = node->properties; |
| 3046 | while (prop != NULL) { |
| 3047 | if ((prop->ns != NULL) && |
| 3048 | xmlStrEqual(prop->name, BAD_CAST name) && |
| 3049 | xmlStrEqual(prop->ns->href, BAD_CAST uri)) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3050 | return(prop); |
| 3051 | prop = prop->next; |
| 3052 | } |
| 3053 | return (NULL); |
| 3054 | } |
| 3055 | |
| 3056 | static const xmlChar * |
| 3057 | xmlSchemaGetNodeContent(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node) |
| 3058 | { |
| 3059 | xmlChar *val; |
| 3060 | const xmlChar *ret; |
| 3061 | |
| 3062 | val = xmlNodeGetContent(node); |
| 3063 | if (val == NULL) |
| 3064 | return(NULL); |
| 3065 | ret = xmlDictLookup(ctxt->dict, val, -1); |
| 3066 | xmlFree(val); |
| 3067 | return(ret); |
| 3068 | } |
| 3069 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3070 | /** |
| 3071 | * xmlSchemaGetProp: |
| 3072 | * @ctxt: the parser context |
| 3073 | * @node: the node |
| 3074 | * @name: the property name |
| 3075 | * |
| 3076 | * Read a attribute value and internalize the string |
| 3077 | * |
| 3078 | * Returns the string or NULL if not present. |
| 3079 | */ |
| 3080 | static const xmlChar * |
| 3081 | xmlSchemaGetProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
| 3082 | const char *name) |
| 3083 | { |
| 3084 | xmlChar *val; |
| 3085 | const xmlChar *ret; |
| 3086 | |
| 3087 | val = xmlGetProp(node, BAD_CAST name); |
| 3088 | if (val == NULL) |
| 3089 | return(NULL); |
| 3090 | ret = xmlDictLookup(ctxt->dict, val, -1); |
| 3091 | xmlFree(val); |
| 3092 | return(ret); |
| 3093 | } |
| 3094 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3095 | /************************************************************************ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3096 | * * |
| 3097 | * Parsing functions * |
| 3098 | * * |
| 3099 | ************************************************************************/ |
| 3100 | |
| 3101 | /** |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3102 | * xmlSchemaGetElem: |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3103 | * @schema: the schema context |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3104 | * @name: the element name |
| 3105 | * @ns: the element namespace |
| 3106 | * |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3107 | * Lookup a global element declaration in the schema. |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3108 | * |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3109 | * Returns the element declaration or NULL if not found. |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3110 | */ |
| 3111 | static xmlSchemaElementPtr |
| 3112 | xmlSchemaGetElem(xmlSchemaPtr schema, const xmlChar * name, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3113 | const xmlChar * namespace) |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3114 | { |
| 3115 | xmlSchemaElementPtr ret; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3116 | |
| 3117 | if ((name == NULL) || (schema == NULL)) |
| 3118 | return (NULL); |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3119 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3120 | ret = xmlHashLookup2(schema->elemDecl, name, namespace); |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 3121 | if ((ret != NULL) && |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3122 | (ret->flags & XML_SCHEMAS_ELEM_GLOBAL)) { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3123 | return (ret); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3124 | } else |
| 3125 | ret = NULL; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 3126 | /* |
| 3127 | * This one was removed, since top level element declarations have |
| 3128 | * the target namespace specified in targetNamespace of the <schema> |
| 3129 | * information element, even if elementFormDefault is "unqualified". |
| 3130 | */ |
| 3131 | |
| 3132 | /* else if ((schema->flags & XML_SCHEMAS_QUALIF_ELEM) == 0) { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3133 | if (xmlStrEqual(namespace, schema->targetNamespace)) |
| 3134 | ret = xmlHashLookup2(schema->elemDecl, name, NULL); |
| 3135 | else |
| 3136 | ret = xmlHashLookup2(schema->elemDecl, name, namespace); |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 3137 | if ((ret != NULL) && |
| 3138 | ((level == 0) || (ret->flags & XML_SCHEMAS_ELEM_TOPLEVEL))) { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3139 | return (ret); |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 3140 | } |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 3141 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3142 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3143 | /* |
| 3144 | * Removed since imported components will be hold by the main schema only. |
| 3145 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3146 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3147 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3148 | else |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3149 | import = xmlHashLookup(schema->schemasImports, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3150 | if (import != NULL) { |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 3151 | ret = xmlSchemaGetElem(import->schema, name, namespace, level + 1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3152 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ELEM_GLOBAL)) { |
| 3153 | return (ret); |
| 3154 | } else |
| 3155 | ret = NULL; |
| 3156 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3157 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3158 | #ifdef DEBUG |
| 3159 | if (ret == NULL) { |
| 3160 | if (namespace == NULL) |
| 3161 | fprintf(stderr, "Unable to lookup type %s", name); |
| 3162 | else |
| 3163 | fprintf(stderr, "Unable to lookup type %s:%s", name, |
| 3164 | namespace); |
| 3165 | } |
| 3166 | #endif |
| 3167 | return (ret); |
| 3168 | } |
| 3169 | |
| 3170 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3171 | * xmlSchemaGetType: |
| 3172 | * @schema: the schemas context |
| 3173 | * @name: the type name |
| 3174 | * @ns: the type namespace |
| 3175 | * |
| 3176 | * Lookup a type in the schemas or the predefined types |
| 3177 | * |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 3178 | * Returns the group definition or NULL if not found. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3179 | */ |
| 3180 | static xmlSchemaTypePtr |
| 3181 | xmlSchemaGetType(xmlSchemaPtr schema, const xmlChar * name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3182 | const xmlChar * namespace) |
| 3183 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3184 | xmlSchemaTypePtr ret; |
| 3185 | |
| 3186 | if (name == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3187 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3188 | if (schema != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3189 | ret = xmlHashLookup2(schema->typeDecl, name, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3190 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_TYPE_GLOBAL)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3191 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3192 | } |
| 3193 | ret = xmlSchemaGetPredefinedType(name, namespace); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 3194 | if (ret != NULL) |
| 3195 | return (ret); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3196 | /* |
| 3197 | * Removed, since the imported components will be grafted on the |
| 3198 | * main schema only. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3199 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3200 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3201 | else |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 3202 | import = xmlHashLookup(schema->schemasImports, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3203 | if (import != NULL) { |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 3204 | ret = xmlSchemaGetType(import->schema, name, namespace); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3205 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_TYPE_GLOBAL)) { |
| 3206 | return (ret); |
| 3207 | } else |
| 3208 | ret = NULL; |
| 3209 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3210 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3211 | #ifdef DEBUG |
| 3212 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3213 | if (namespace == NULL) |
| 3214 | fprintf(stderr, "Unable to lookup type %s", name); |
| 3215 | else |
| 3216 | fprintf(stderr, "Unable to lookup type %s:%s", name, |
| 3217 | namespace); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3218 | } |
| 3219 | #endif |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3220 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3221 | } |
| 3222 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3223 | /** |
| 3224 | * xmlSchemaGetAttribute: |
| 3225 | * @schema: the context of the schema |
| 3226 | * @name: the name of the attribute |
| 3227 | * @ns: the target namespace of the attribute |
| 3228 | * |
| 3229 | * Lookup a an attribute in the schema or imported schemas |
| 3230 | * |
| 3231 | * Returns the attribute declaration or NULL if not found. |
| 3232 | */ |
| 3233 | static xmlSchemaAttributePtr |
| 3234 | xmlSchemaGetAttribute(xmlSchemaPtr schema, const xmlChar * name, |
| 3235 | const xmlChar * namespace) |
| 3236 | { |
| 3237 | xmlSchemaAttributePtr ret; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3238 | |
| 3239 | if ((name == NULL) || (schema == NULL)) |
| 3240 | return (NULL); |
| 3241 | |
| 3242 | |
| 3243 | ret = xmlHashLookup2(schema->attrDecl, name, namespace); |
| 3244 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ATTR_GLOBAL)) |
| 3245 | return (ret); |
| 3246 | else |
| 3247 | ret = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3248 | /* |
| 3249 | * Removed, since imported components will be hold by the main schema only. |
| 3250 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3251 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3252 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3253 | else |
| 3254 | import = xmlHashLookup(schema->schemasImports, namespace); |
| 3255 | if (import != NULL) { |
| 3256 | ret = xmlSchemaGetAttribute(import->schema, name, namespace); |
| 3257 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ATTR_GLOBAL)) { |
| 3258 | return (ret); |
| 3259 | } else |
| 3260 | ret = NULL; |
| 3261 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3262 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3263 | #ifdef DEBUG |
| 3264 | if (ret == NULL) { |
| 3265 | if (namespace == NULL) |
| 3266 | fprintf(stderr, "Unable to lookup attribute %s", name); |
| 3267 | else |
| 3268 | fprintf(stderr, "Unable to lookup attribute %s:%s", name, |
| 3269 | namespace); |
| 3270 | } |
| 3271 | #endif |
| 3272 | return (ret); |
| 3273 | } |
| 3274 | |
| 3275 | /** |
| 3276 | * xmlSchemaGetAttributeGroup: |
| 3277 | * @schema: the context of the schema |
| 3278 | * @name: the name of the attribute group |
| 3279 | * @ns: the target namespace of the attribute group |
| 3280 | * |
| 3281 | * Lookup a an attribute group in the schema or imported schemas |
| 3282 | * |
| 3283 | * Returns the attribute group definition or NULL if not found. |
| 3284 | */ |
| 3285 | static xmlSchemaAttributeGroupPtr |
| 3286 | xmlSchemaGetAttributeGroup(xmlSchemaPtr schema, const xmlChar * name, |
| 3287 | const xmlChar * namespace) |
| 3288 | { |
| 3289 | xmlSchemaAttributeGroupPtr ret; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3290 | |
| 3291 | if ((name == NULL) || (schema == NULL)) |
| 3292 | return (NULL); |
| 3293 | |
| 3294 | |
| 3295 | ret = xmlHashLookup2(schema->attrgrpDecl, name, namespace); |
| 3296 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ATTRGROUP_GLOBAL)) |
| 3297 | return (ret); |
| 3298 | else |
| 3299 | ret = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3300 | /* |
| 3301 | * Removed since imported components will be hold by the main schema only. |
| 3302 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3303 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3304 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3305 | else |
| 3306 | import = xmlHashLookup(schema->schemasImports, namespace); |
| 3307 | if (import != NULL) { |
| 3308 | ret = xmlSchemaGetAttributeGroup(import->schema, name, namespace); |
| 3309 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_ATTRGROUP_GLOBAL)) |
| 3310 | return (ret); |
| 3311 | else |
| 3312 | ret = NULL; |
| 3313 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3314 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3315 | #ifdef DEBUG |
| 3316 | if (ret == NULL) { |
| 3317 | if (namespace == NULL) |
| 3318 | fprintf(stderr, "Unable to lookup attribute group %s", name); |
| 3319 | else |
| 3320 | fprintf(stderr, "Unable to lookup attribute group %s:%s", name, |
| 3321 | namespace); |
| 3322 | } |
| 3323 | #endif |
| 3324 | return (ret); |
| 3325 | } |
| 3326 | |
| 3327 | /** |
| 3328 | * xmlSchemaGetGroup: |
| 3329 | * @schema: the context of the schema |
| 3330 | * @name: the name of the group |
| 3331 | * @ns: the target namespace of the group |
| 3332 | * |
| 3333 | * Lookup a group in the schema or imported schemas |
| 3334 | * |
| 3335 | * Returns the group definition or NULL if not found. |
| 3336 | */ |
| 3337 | static xmlSchemaTypePtr |
| 3338 | xmlSchemaGetGroup(xmlSchemaPtr schema, const xmlChar * name, |
| 3339 | const xmlChar * namespace) |
| 3340 | { |
| 3341 | xmlSchemaTypePtr ret; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3342 | |
| 3343 | if ((name == NULL) || (schema == NULL)) |
| 3344 | return (NULL); |
| 3345 | |
| 3346 | |
| 3347 | ret = xmlHashLookup2(schema->groupDecl, name, namespace); |
| 3348 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_TYPE_GLOBAL)) |
| 3349 | return (ret); |
| 3350 | else |
| 3351 | ret = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3352 | /* |
| 3353 | * Removed since imported components will be hold by the main schema only. |
| 3354 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3355 | if (namespace == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3356 | import = xmlHashLookup(schema->schemasImports, XML_SCHEMAS_NO_NAMESPACE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3357 | else |
| 3358 | import = xmlHashLookup(schema->schemasImports, namespace); |
| 3359 | if (import != NULL) { |
| 3360 | ret = xmlSchemaGetGroup(import->schema, name, namespace); |
| 3361 | if ((ret != NULL) && (ret->flags & XML_SCHEMAS_TYPE_GLOBAL)) |
| 3362 | return (ret); |
| 3363 | else |
| 3364 | ret = NULL; |
| 3365 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3366 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3367 | #ifdef DEBUG |
| 3368 | if (ret == NULL) { |
| 3369 | if (namespace == NULL) |
| 3370 | fprintf(stderr, "Unable to lookup group %s", name); |
| 3371 | else |
| 3372 | fprintf(stderr, "Unable to lookup group %s:%s", name, |
| 3373 | namespace); |
| 3374 | } |
| 3375 | #endif |
| 3376 | return (ret); |
| 3377 | } |
| 3378 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3379 | /************************************************************************ |
| 3380 | * * |
| 3381 | * Parsing functions * |
| 3382 | * * |
| 3383 | ************************************************************************/ |
| 3384 | |
| 3385 | #define IS_BLANK_NODE(n) \ |
| 3386 | (((n)->type == XML_TEXT_NODE) && (xmlSchemaIsBlank((n)->content))) |
| 3387 | |
| 3388 | /** |
| 3389 | * xmlSchemaIsBlank: |
| 3390 | * @str: a string |
| 3391 | * |
| 3392 | * Check if a string is ignorable |
| 3393 | * |
| 3394 | * Returns 1 if the string is NULL or made of blanks chars, 0 otherwise |
| 3395 | */ |
| 3396 | static int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3397 | xmlSchemaIsBlank(xmlChar * str) |
| 3398 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3399 | if (str == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3400 | return (1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3401 | while (*str != 0) { |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 3402 | if (!(IS_BLANK_CH(*str))) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3403 | return (0); |
| 3404 | str++; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3405 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3406 | return (1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3410 | * xmlSchemaAddAssembledItem: |
| 3411 | * @ctxt: a schema parser context |
| 3412 | * @schema: the schema being built |
| 3413 | * @item: the item |
| 3414 | * |
| 3415 | * Add a item to the schema's list of current items. |
| 3416 | * This is used if the schema was already constructed and |
| 3417 | * new schemata need to be added to it. |
| 3418 | * *WARNING* this interface is highly subject to change. |
| 3419 | * |
| 3420 | * Returns 0 if suceeds and -1 if an internal error occurs. |
| 3421 | */ |
| 3422 | static int |
| 3423 | xmlSchemaAddAssembledItem(xmlSchemaParserCtxtPtr ctxt, |
| 3424 | xmlSchemaTypePtr item) |
| 3425 | { |
| 3426 | static int growSize = 100; |
| 3427 | xmlSchemaAssemblePtr ass; |
| 3428 | |
| 3429 | ass = ctxt->assemble; |
| 3430 | if (ass->sizeItems < 0) { |
| 3431 | /* If disabled. */ |
| 3432 | return (0); |
| 3433 | } |
| 3434 | if (ass->sizeItems <= 0) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 3435 | ass->items = (void **) xmlMalloc(growSize * sizeof(xmlSchemaTypePtr)); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3436 | if (ass->items == NULL) { |
| 3437 | xmlSchemaPErrMemory(ctxt, |
| 3438 | "allocating new item buffer", NULL); |
| 3439 | return (-1); |
| 3440 | } |
| 3441 | ass->sizeItems = growSize; |
| 3442 | } else if (ass->sizeItems <= ass->nbItems) { |
| 3443 | ass->sizeItems *= 2; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 3444 | ass->items = (void **) xmlRealloc(ass->items, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3445 | ass->sizeItems * sizeof(xmlSchemaTypePtr)); |
| 3446 | if (ass->items == NULL) { |
| 3447 | xmlSchemaPErrMemory(ctxt, |
| 3448 | "growing item buffer", NULL); |
| 3449 | ass->sizeItems = 0; |
| 3450 | return (-1); |
| 3451 | } |
| 3452 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 3453 | /* ass->items[ass->nbItems++] = (void *) item; */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3454 | ((xmlSchemaTypePtr *) ass->items)[ass->nbItems++] = (void *) item; |
| 3455 | return (0); |
| 3456 | } |
| 3457 | |
| 3458 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3459 | * xmlSchemaAddNotation: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3460 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3461 | * @schema: the schema being built |
| 3462 | * @name: the item name |
| 3463 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3464 | * Add an XML schema annotation declaration |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3465 | * *WARNING* this interface is highly subject to change |
| 3466 | * |
| 3467 | * Returns the new struture or NULL in case of error |
| 3468 | */ |
| 3469 | static xmlSchemaNotationPtr |
| 3470 | xmlSchemaAddNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3471 | const xmlChar * name) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3472 | { |
| 3473 | xmlSchemaNotationPtr ret = NULL; |
| 3474 | int val; |
| 3475 | |
| 3476 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3477 | return (NULL); |
| 3478 | |
| 3479 | if (schema->notaDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 3480 | schema->notaDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3481 | if (schema->notaDecl == NULL) |
| 3482 | return (NULL); |
| 3483 | |
| 3484 | ret = (xmlSchemaNotationPtr) xmlMalloc(sizeof(xmlSchemaNotation)); |
| 3485 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3486 | xmlSchemaPErrMemory(ctxt, "add annotation", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3487 | return (NULL); |
| 3488 | } |
| 3489 | memset(ret, 0, sizeof(xmlSchemaNotation)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3490 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3491 | val = xmlHashAddEntry2(schema->notaDecl, name, schema->targetNamespace, |
| 3492 | ret); |
| 3493 | if (val != 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3494 | /* |
| 3495 | * TODO: This should never happen, since a unique name will be computed. |
| 3496 | * If it fails, then an other internal error must have occured. |
| 3497 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3498 | xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc, |
| 3499 | XML_SCHEMAP_REDEFINED_NOTATION, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3500 | "Annotation declaration '%s' is already declared.\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3501 | name, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3502 | xmlFree(ret); |
| 3503 | return (NULL); |
| 3504 | } |
| 3505 | return (ret); |
| 3506 | } |
| 3507 | |
| 3508 | |
| 3509 | /** |
| 3510 | * xmlSchemaAddAttribute: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3511 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3512 | * @schema: the schema being built |
| 3513 | * @name: the item name |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3514 | * @namespace: the namespace |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3515 | * |
| 3516 | * Add an XML schema Attrribute declaration |
| 3517 | * *WARNING* this interface is highly subject to change |
| 3518 | * |
| 3519 | * Returns the new struture or NULL in case of error |
| 3520 | */ |
| 3521 | static xmlSchemaAttributePtr |
| 3522 | xmlSchemaAddAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3523 | const xmlChar * name, const xmlChar * namespace, |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3524 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3525 | { |
| 3526 | xmlSchemaAttributePtr ret = NULL; |
| 3527 | int val; |
| 3528 | |
| 3529 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3530 | return (NULL); |
| 3531 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3532 | #ifdef DEBUG |
| 3533 | fprintf(stderr, "Adding attribute %s\n", name); |
| 3534 | if (namespace != NULL) |
| 3535 | fprintf(stderr, " target namespace %s\n", namespace); |
| 3536 | #endif |
| 3537 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3538 | if (schema->attrDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 3539 | schema->attrDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3540 | if (schema->attrDecl == NULL) |
| 3541 | return (NULL); |
| 3542 | |
| 3543 | ret = (xmlSchemaAttributePtr) xmlMalloc(sizeof(xmlSchemaAttribute)); |
| 3544 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3545 | xmlSchemaPErrMemory(ctxt, "allocating attribute", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3546 | return (NULL); |
| 3547 | } |
| 3548 | memset(ret, 0, sizeof(xmlSchemaAttribute)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3549 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 3550 | ret->targetNamespace = namespace; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3551 | val = xmlHashAddEntry3(schema->attrDecl, name, |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 3552 | namespace, ctxt->container, ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3553 | if (val != 0) { |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3554 | if (topLevel) { |
| 3555 | xmlSchemaPCustomErr(ctxt, |
| 3556 | XML_SCHEMAP_REDEFINED_ATTR, |
| 3557 | NULL, NULL, node, |
| 3558 | "A global attribute declaration with the name '%s' does " |
| 3559 | "already exist", name); |
| 3560 | xmlFree(ret); |
| 3561 | return (NULL); |
| 3562 | } else { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3563 | char buf[30]; |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3564 | /* |
| 3565 | * Using the ctxt->container for xmlHashAddEntry3 is ambigious |
| 3566 | * in the scenario: |
| 3567 | * 1. multiple top-level complex types have different target |
| 3568 | * namespaces but have the SAME NAME; this can happen if |
| 3569 | * schemata are imported |
| 3570 | * 2. those complex types contain attributes with an equal name |
| 3571 | * 3. those attributes are in no namespace |
| 3572 | * We will compute a new context string. |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3573 | */ |
| 3574 | snprintf(buf, 29, "#aCont%d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3575 | val = xmlHashAddEntry3(schema->attrDecl, name, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 3576 | namespace, xmlDictLookup(ctxt->dict, BAD_CAST buf, -1), ret); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3577 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3578 | if (val != 0) { |
| 3579 | xmlSchemaPCustomErr(ctxt, |
| 3580 | XML_SCHEMAP_INTERNAL, |
| 3581 | NULL, NULL, node, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3582 | "Internal error: xmlSchemaAddAttribute, " |
| 3583 | "a dublicate attribute declaration with the name '%s' " |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3584 | "could not be added to the hash.", name); |
| 3585 | xmlFree(ret); |
| 3586 | return (NULL); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3587 | } |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3588 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3589 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3590 | if (ctxt->assemble != NULL) |
| 3591 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3592 | return (ret); |
| 3593 | } |
| 3594 | |
| 3595 | /** |
| 3596 | * xmlSchemaAddAttributeGroup: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3597 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3598 | * @schema: the schema being built |
| 3599 | * @name: the item name |
| 3600 | * |
| 3601 | * Add an XML schema Attrribute Group declaration |
| 3602 | * |
| 3603 | * Returns the new struture or NULL in case of error |
| 3604 | */ |
| 3605 | static xmlSchemaAttributeGroupPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3606 | xmlSchemaAddAttributeGroup(xmlSchemaParserCtxtPtr ctxt, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3607 | xmlSchemaPtr schema, const xmlChar * name, |
| 3608 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3609 | { |
| 3610 | xmlSchemaAttributeGroupPtr ret = NULL; |
| 3611 | int val; |
| 3612 | |
| 3613 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3614 | return (NULL); |
| 3615 | |
| 3616 | if (schema->attrgrpDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 3617 | schema->attrgrpDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3618 | if (schema->attrgrpDecl == NULL) |
| 3619 | return (NULL); |
| 3620 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3621 | ret = |
| 3622 | (xmlSchemaAttributeGroupPtr) |
| 3623 | xmlMalloc(sizeof(xmlSchemaAttributeGroup)); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3624 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3625 | xmlSchemaPErrMemory(ctxt, "allocating attribute group", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3626 | return (NULL); |
| 3627 | } |
| 3628 | memset(ret, 0, sizeof(xmlSchemaAttributeGroup)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3629 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3630 | val = xmlHashAddEntry3(schema->attrgrpDecl, name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3631 | schema->targetNamespace, ctxt->container, ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3632 | if (val != 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3633 | xmlSchemaPCustomErr(ctxt, |
| 3634 | XML_SCHEMAP_REDEFINED_ATTRGROUP, |
| 3635 | NULL, NULL, node, |
| 3636 | "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] | 3637 | xmlFree(ret); |
| 3638 | return (NULL); |
| 3639 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3640 | if (ctxt->assemble != NULL) |
| 3641 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3642 | return (ret); |
| 3643 | } |
| 3644 | |
| 3645 | /** |
| 3646 | * xmlSchemaAddElement: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3647 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3648 | * @schema: the schema being built |
| 3649 | * @name: the type name |
| 3650 | * @namespace: the type namespace |
| 3651 | * |
| 3652 | * Add an XML schema Element declaration |
| 3653 | * *WARNING* this interface is highly subject to change |
| 3654 | * |
| 3655 | * Returns the new struture or NULL in case of error |
| 3656 | */ |
| 3657 | static xmlSchemaElementPtr |
| 3658 | xmlSchemaAddElement(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3659 | const xmlChar * name, const xmlChar * namespace, |
| 3660 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3661 | { |
| 3662 | xmlSchemaElementPtr ret = NULL; |
| 3663 | int val; |
| 3664 | |
| 3665 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3666 | return (NULL); |
| 3667 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3668 | #ifdef DEBUG |
| 3669 | fprintf(stderr, "Adding element %s\n", name); |
| 3670 | if (namespace != NULL) |
| 3671 | fprintf(stderr, " target namespace %s\n", namespace); |
| 3672 | #endif |
| 3673 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3674 | if (schema->elemDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 3675 | schema->elemDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3676 | if (schema->elemDecl == NULL) |
| 3677 | return (NULL); |
| 3678 | |
| 3679 | ret = (xmlSchemaElementPtr) xmlMalloc(sizeof(xmlSchemaElement)); |
| 3680 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3681 | xmlSchemaPErrMemory(ctxt, "allocating element", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3682 | return (NULL); |
| 3683 | } |
| 3684 | memset(ret, 0, sizeof(xmlSchemaElement)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3685 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3686 | val = xmlHashAddEntry3(schema->elemDecl, name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3687 | namespace, ctxt->container, ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3688 | if (val != 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3689 | if (topLevel) { |
| 3690 | xmlSchemaPCustomErr(ctxt, |
| 3691 | XML_SCHEMAP_REDEFINED_ELEMENT, |
| 3692 | NULL, NULL, node, |
| 3693 | "A global element declaration with the name '%s' does " |
| 3694 | "already exist", name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3695 | xmlFree(ret); |
| 3696 | return (NULL); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3697 | } else { |
| 3698 | char buf[30]; |
| 3699 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 3700 | snprintf(buf, 29, "#eCont%d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 3701 | val = xmlHashAddEntry3(schema->elemDecl, name, |
| 3702 | namespace, (xmlChar *) buf, ret); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3703 | if (val != 0) { |
| 3704 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 3705 | XML_SCHEMAP_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3706 | NULL, NULL, node, |
| 3707 | "Internal error: xmlSchemaAddElement, " |
| 3708 | "a dublicate element declaration with the name '%s' " |
| 3709 | "could not be added to the hash.", name); |
| 3710 | xmlFree(ret); |
| 3711 | return (NULL); |
| 3712 | } |
| 3713 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3714 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3715 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3716 | if (ctxt->assemble != NULL) |
| 3717 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3718 | return (ret); |
| 3719 | } |
| 3720 | |
| 3721 | /** |
| 3722 | * xmlSchemaAddType: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3723 | * @ctxt: a schema parser context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3724 | * @schema: the schema being built |
| 3725 | * @name: the item name |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3726 | * @namespace: the namespace |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3727 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3728 | * Add an XML schema item |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3729 | * *WARNING* this interface is highly subject to change |
| 3730 | * |
| 3731 | * Returns the new struture or NULL in case of error |
| 3732 | */ |
| 3733 | static xmlSchemaTypePtr |
| 3734 | xmlSchemaAddType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3735 | const xmlChar * name, const xmlChar * namespace, |
| 3736 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3737 | { |
| 3738 | xmlSchemaTypePtr ret = NULL; |
| 3739 | int val; |
| 3740 | |
| 3741 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3742 | return (NULL); |
| 3743 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3744 | #ifdef DEBUG |
| 3745 | fprintf(stderr, "Adding type %s\n", name); |
| 3746 | if (namespace != NULL) |
| 3747 | fprintf(stderr, " target namespace %s\n", namespace); |
| 3748 | #endif |
| 3749 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3750 | if (schema->typeDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 3751 | schema->typeDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3752 | if (schema->typeDecl == NULL) |
| 3753 | return (NULL); |
| 3754 | |
| 3755 | ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType)); |
| 3756 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3757 | xmlSchemaPErrMemory(ctxt, "allocating type", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3758 | return (NULL); |
| 3759 | } |
| 3760 | memset(ret, 0, sizeof(xmlSchemaType)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3761 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 3762 | ret->redef = NULL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3763 | val = xmlHashAddEntry2(schema->typeDecl, name, namespace, ret); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3764 | if (val != 0) { |
| 3765 | if (ctxt->includes == 0) { |
| 3766 | xmlSchemaPCustomErr(ctxt, |
| 3767 | XML_SCHEMAP_REDEFINED_TYPE, |
| 3768 | NULL, NULL, node, |
| 3769 | "A global type definition with the name '%s' does already exist", name); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 3770 | xmlFree(ret); |
| 3771 | return (NULL); |
| 3772 | } else { |
| 3773 | xmlSchemaTypePtr prev; |
| 3774 | |
| 3775 | prev = xmlHashLookup2(schema->typeDecl, name, namespace); |
| 3776 | if (prev == NULL) { |
| 3777 | xmlSchemaPErr(ctxt, (xmlNodePtr) ctxt->doc, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3778 | XML_ERR_INTERNAL_ERROR, |
| 3779 | "Internal error: xmlSchemaAddType, on type " |
| 3780 | "'%s'.\n", |
| 3781 | name, NULL); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 3782 | xmlFree(ret); |
| 3783 | return (NULL); |
| 3784 | } |
| 3785 | ret->redef = prev->redef; |
| 3786 | prev->redef = ret; |
| 3787 | } |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 3788 | } |
| 3789 | ret->minOccurs = 1; |
| 3790 | ret->maxOccurs = 1; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3791 | ret->attributeUses = NULL; |
| 3792 | ret->attributeWildcard = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3793 | if (ctxt->assemble != NULL) |
| 3794 | xmlSchemaAddAssembledItem(ctxt,ret); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 3795 | return (ret); |
| 3796 | } |
| 3797 | |
| 3798 | /** |
| 3799 | * xmlSchemaAddGroup: |
| 3800 | * @ctxt: a schema validation context |
| 3801 | * @schema: the schema being built |
| 3802 | * @name: the group name |
| 3803 | * |
| 3804 | * Add an XML schema Group definition |
| 3805 | * |
| 3806 | * Returns the new struture or NULL in case of error |
| 3807 | */ |
| 3808 | static xmlSchemaTypePtr |
| 3809 | xmlSchemaAddGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 3810 | const xmlChar *name, const xmlChar *namespaceName, |
| 3811 | xmlNodePtr node) |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 3812 | { |
| 3813 | xmlSchemaTypePtr ret = NULL; |
| 3814 | int val; |
| 3815 | |
| 3816 | if ((ctxt == NULL) || (schema == NULL) || (name == NULL)) |
| 3817 | return (NULL); |
| 3818 | |
| 3819 | if (schema->groupDecl == NULL) |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 3820 | schema->groupDecl = xmlHashCreateDict(10, ctxt->dict); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 3821 | if (schema->groupDecl == NULL) |
| 3822 | return (NULL); |
| 3823 | |
| 3824 | ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType)); |
| 3825 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3826 | xmlSchemaPErrMemory(ctxt, "adding group", NULL); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 3827 | return (NULL); |
| 3828 | } |
| 3829 | memset(ret, 0, sizeof(xmlSchemaType)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3830 | ret->name = xmlDictLookup(ctxt->dict, name, -1); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3831 | val = |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 3832 | xmlHashAddEntry2(schema->groupDecl, name, namespaceName, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3833 | ret); |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 3834 | if (val != 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 3835 | xmlSchemaPCustomErr(ctxt, |
| 3836 | XML_SCHEMAP_REDEFINED_GROUP, |
| 3837 | NULL, NULL, node, |
| 3838 | "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] | 3839 | xmlFree(ret); |
| 3840 | return (NULL); |
| 3841 | } |
| 3842 | ret->minOccurs = 1; |
| 3843 | ret->maxOccurs = 1; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3844 | if (ctxt->assemble != NULL) |
| 3845 | xmlSchemaAddAssembledItem(ctxt, (xmlSchemaTypePtr) ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3846 | return (ret); |
| 3847 | } |
| 3848 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3849 | /** |
| 3850 | * xmlSchemaNewWildcardNs: |
| 3851 | * @ctxt: a schema validation context |
| 3852 | * |
| 3853 | * Creates a new wildcard namespace constraint. |
| 3854 | * |
| 3855 | * Returns the new struture or NULL in case of error |
| 3856 | */ |
| 3857 | static xmlSchemaWildcardNsPtr |
| 3858 | xmlSchemaNewWildcardNsConstraint(xmlSchemaParserCtxtPtr ctxt) |
| 3859 | { |
| 3860 | xmlSchemaWildcardNsPtr ret; |
| 3861 | |
| 3862 | ret = (xmlSchemaWildcardNsPtr) |
| 3863 | xmlMalloc(sizeof(xmlSchemaWildcardNs)); |
| 3864 | if (ret == NULL) { |
| 3865 | xmlSchemaPErrMemory(ctxt, "creating wildcard namespace constraint", NULL); |
| 3866 | return (NULL); |
| 3867 | } |
| 3868 | ret->value = NULL; |
| 3869 | ret->next = NULL; |
| 3870 | return (ret); |
| 3871 | } |
| 3872 | |
| 3873 | /** |
| 3874 | * xmlSchemaAddWildcard: |
| 3875 | * @ctxt: a schema validation context |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3876 | * Adds a wildcard. It corresponds to a |
| 3877 | * xsd:anyAttribute and is used as storage for namespace |
| 3878 | * constraints on a xsd:any. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 3879 | * |
| 3880 | * Returns the new struture or NULL in case of error |
| 3881 | */ |
| 3882 | static xmlSchemaWildcardPtr |
| 3883 | xmlSchemaAddWildcard(xmlSchemaParserCtxtPtr ctxt) |
| 3884 | { |
| 3885 | xmlSchemaWildcardPtr ret = NULL; |
| 3886 | |
| 3887 | if (ctxt == NULL) |
| 3888 | return (NULL); |
| 3889 | |
| 3890 | ret = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard)); |
| 3891 | if (ret == NULL) { |
| 3892 | xmlSchemaPErrMemory(ctxt, "adding wildcard", NULL); |
| 3893 | return (NULL); |
| 3894 | } |
| 3895 | memset(ret, 0, sizeof(xmlSchemaWildcard)); |
| 3896 | ret->minOccurs = 1; |
| 3897 | ret->maxOccurs = 1; |
| 3898 | |
| 3899 | return (ret); |
| 3900 | } |
| 3901 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3902 | /************************************************************************ |
| 3903 | * * |
| 3904 | * Utilities for parsing * |
| 3905 | * * |
| 3906 | ************************************************************************/ |
| 3907 | |
| 3908 | /** |
| 3909 | * xmlGetQNameProp: |
| 3910 | * @ctxt: a schema validation context |
| 3911 | * @node: a subtree containing XML Schema informations |
| 3912 | * @name: the attribute name |
| 3913 | * @namespace: the result namespace if any |
| 3914 | * |
| 3915 | * Extract a QName Attribute value |
| 3916 | * |
| 3917 | * Returns the NCName or NULL if not found, and also update @namespace |
| 3918 | * with the namespace URI |
| 3919 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3920 | static const xmlChar * |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3921 | xmlGetQNameProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3922 | const char *name, const xmlChar ** namespace) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3923 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3924 | const xmlChar *val; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3925 | xmlNsPtr ns; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3926 | const xmlChar *ret, *prefix; |
| 3927 | int len; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 3928 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3929 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3930 | *namespace = NULL; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 3931 | attr = xmlSchemaGetPropNode(node, name); |
| 3932 | if (attr == NULL) |
| 3933 | return (NULL); |
| 3934 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 3935 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3936 | if (val == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3937 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3938 | |
Daniel Veillard | ba0153a | 2004-04-01 10:42:31 +0000 | [diff] [blame] | 3939 | if (!strchr((char *) val, ':')) { |
Daniel Veillard | ebcdebd | 2004-03-05 00:15:50 +0000 | [diff] [blame] | 3940 | ns = xmlSearchNs(node->doc, node, 0); |
| 3941 | if (ns) { |
| 3942 | *namespace = xmlDictLookup(ctxt->dict, ns->href, -1); |
| 3943 | return (val); |
| 3944 | } |
| 3945 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3946 | ret = xmlSplitQName3(val, &len); |
| 3947 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3948 | return (val); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3949 | } |
| 3950 | ret = xmlDictLookup(ctxt->dict, ret, -1); |
| 3951 | prefix = xmlDictLookup(ctxt->dict, val, len); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3952 | |
| 3953 | ns = xmlSearchNs(node->doc, node, prefix); |
| 3954 | if (ns == NULL) { |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 3955 | xmlSchemaPSimpleTypeErr(ctxt, XML_SCHEMAP_PREFIX_UNDEFINED, |
| 3956 | NULL, NULL, (xmlNodePtr) attr, |
| 3957 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), NULL, val, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 3958 | "The QName value '%s' has no corresponding namespace " |
| 3959 | "declaration in scope", val, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3960 | } else { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 3961 | *namespace = xmlDictLookup(ctxt->dict, ns->href, -1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3962 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 3963 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3964 | } |
| 3965 | |
| 3966 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3967 | * xmlSchemaPValAttrNodeQNameValue: |
| 3968 | * @ctxt: a schema parser context |
| 3969 | * @schema: the schema context |
| 3970 | * @ownerDes: the designation of the parent element |
| 3971 | * @ownerItem: the parent as a schema object |
| 3972 | * @value: the QName value |
| 3973 | * @local: the resulting local part if found, the attribute value otherwise |
| 3974 | * @uri: the resulting namespace URI if found |
| 3975 | * |
| 3976 | * Extracts the local name and the URI of a QName value and validates it. |
| 3977 | * This one is intended to be used on attribute values that |
| 3978 | * should resolve to schema components. |
| 3979 | * |
| 3980 | * Returns 0, in case the QName is valid, a positive error code |
| 3981 | * if not valid and -1 if an internal error occurs. |
| 3982 | */ |
| 3983 | static int |
| 3984 | xmlSchemaPValAttrNodeQNameValue(xmlSchemaParserCtxtPtr ctxt, |
| 3985 | xmlSchemaPtr schema, |
| 3986 | xmlChar **ownerDes, |
| 3987 | xmlSchemaTypePtr ownerItem, |
| 3988 | xmlAttrPtr attr, |
| 3989 | const xmlChar *value, |
| 3990 | const xmlChar **uri, |
| 3991 | const xmlChar **prefix, |
| 3992 | const xmlChar **local) |
| 3993 | { |
| 3994 | const xmlChar *pref; |
| 3995 | xmlNsPtr ns; |
| 3996 | int len, ret; |
| 3997 | |
| 3998 | *uri = NULL; |
| 3999 | *local = NULL; |
| 4000 | if (prefix != 0) |
| 4001 | *prefix = NULL; |
| 4002 | ret = xmlValidateQName(value, 1); |
| 4003 | if (ret > 0) { |
| 4004 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4005 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4006 | ownerDes, ownerItem, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4007 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
| 4008 | "QName", value, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4009 | NULL, NULL, NULL); |
| 4010 | *local = value; |
| 4011 | return (ctxt->err); |
| 4012 | } else if (ret < 0) |
| 4013 | return (-1); |
| 4014 | |
| 4015 | if (!strchr((char *) value, ':')) { |
| 4016 | ns = xmlSearchNs(attr->doc, attr->parent, 0); |
| 4017 | if (ns) |
| 4018 | *uri = xmlDictLookup(ctxt->dict, ns->href, -1); |
| 4019 | else if (schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) { |
| 4020 | /* |
| 4021 | * This one takes care of included schemas with no |
| 4022 | * target namespace. |
| 4023 | */ |
| 4024 | *uri = schema->targetNamespace; |
| 4025 | } |
| 4026 | *local = value; |
| 4027 | return (0); |
| 4028 | } |
| 4029 | /* |
| 4030 | * At this point xmlSplitQName3 has to return a local name. |
| 4031 | */ |
| 4032 | *local = xmlSplitQName3(value, &len); |
| 4033 | *local = xmlDictLookup(ctxt->dict, *local, -1); |
| 4034 | pref = xmlDictLookup(ctxt->dict, value, len); |
| 4035 | if (prefix != 0) |
| 4036 | *prefix = pref; |
| 4037 | ns = xmlSearchNs(attr->doc, attr->parent, pref); |
| 4038 | if (ns == NULL) { |
| 4039 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4040 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4041 | ownerDes, ownerItem, (xmlNodePtr) attr, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4042 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), "QName", value, |
| 4043 | "The QName value '%s' has no corresponding namespace " |
| 4044 | "declaration in scope", value, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4045 | return (ctxt->err); |
| 4046 | } else { |
| 4047 | *uri = xmlDictLookup(ctxt->dict, ns->href, -1); |
| 4048 | } |
| 4049 | return (0); |
| 4050 | } |
| 4051 | |
| 4052 | /** |
| 4053 | * xmlSchemaPValAttrNodeQName: |
| 4054 | * @ctxt: a schema parser context |
| 4055 | * @schema: the schema context |
| 4056 | * @ownerDes: the designation of the owner element |
| 4057 | * @ownerItem: the owner as a schema object |
| 4058 | * @attr: the attribute node |
| 4059 | * @local: the resulting local part if found, the attribute value otherwise |
| 4060 | * @uri: the resulting namespace URI if found |
| 4061 | * |
| 4062 | * Extracts and validates the QName of an attribute value. |
| 4063 | * This one is intended to be used on attribute values that |
| 4064 | * should resolve to schema components. |
| 4065 | * |
| 4066 | * Returns 0, in case the QName is valid, a positive error code |
| 4067 | * if not valid and -1 if an internal error occurs. |
| 4068 | */ |
| 4069 | static int |
| 4070 | xmlSchemaPValAttrNodeQName(xmlSchemaParserCtxtPtr ctxt, |
| 4071 | xmlSchemaPtr schema, |
| 4072 | xmlChar **ownerDes, |
| 4073 | xmlSchemaTypePtr ownerItem, |
| 4074 | xmlAttrPtr attr, |
| 4075 | const xmlChar **uri, |
| 4076 | const xmlChar **prefix, |
| 4077 | const xmlChar **local) |
| 4078 | { |
| 4079 | const xmlChar *value; |
| 4080 | |
| 4081 | value = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 4082 | return (xmlSchemaPValAttrNodeQNameValue(ctxt, schema, |
| 4083 | ownerDes, ownerItem, attr, value, uri, prefix, local)); |
| 4084 | } |
| 4085 | |
| 4086 | /** |
| 4087 | * xmlSchemaPValAttrQName: |
| 4088 | * @ctxt: a schema parser context |
| 4089 | * @schema: the schema context |
| 4090 | * @ownerDes: the designation of the parent element |
| 4091 | * @ownerItem: the owner as a schema object |
| 4092 | * @ownerElem: the parent node of the attribute |
| 4093 | * @name: the name of the attribute |
| 4094 | * @local: the resulting local part if found, the attribute value otherwise |
| 4095 | * @uri: the resulting namespace URI if found |
| 4096 | * |
| 4097 | * Extracts and validates the QName of an attribute value. |
| 4098 | * |
| 4099 | * Returns 0, in case the QName is valid, a positive error code |
| 4100 | * if not valid and -1 if an internal error occurs. |
| 4101 | */ |
| 4102 | static int |
| 4103 | xmlSchemaPValAttrQName(xmlSchemaParserCtxtPtr ctxt, |
| 4104 | xmlSchemaPtr schema, |
| 4105 | xmlChar **ownerDes, |
| 4106 | xmlSchemaTypePtr ownerItem, |
| 4107 | xmlNodePtr ownerElem, |
| 4108 | const char *name, |
| 4109 | const xmlChar **uri, |
| 4110 | const xmlChar **prefix, |
| 4111 | const xmlChar **local) |
| 4112 | { |
| 4113 | xmlAttrPtr attr; |
| 4114 | |
| 4115 | attr = xmlSchemaGetPropNode(ownerElem, name); |
| 4116 | if (attr == NULL) { |
| 4117 | *local = NULL; |
| 4118 | *uri = NULL; |
| 4119 | return (0); |
| 4120 | } |
| 4121 | return (xmlSchemaPValAttrNodeQName(ctxt, schema, |
| 4122 | ownerDes, ownerItem, attr, uri, prefix, local)); |
| 4123 | } |
| 4124 | |
| 4125 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4126 | * xmlGetMaxOccurs: |
| 4127 | * @ctxt: a schema validation context |
| 4128 | * @node: a subtree containing XML Schema informations |
| 4129 | * |
| 4130 | * Get the maxOccurs property |
| 4131 | * |
| 4132 | * Returns the default if not found, or the value |
| 4133 | */ |
| 4134 | static int |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4135 | xmlGetMaxOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
| 4136 | int min, int max, int def, const char *expected) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4137 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4138 | const xmlChar *val, *cur; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4139 | int ret = 0; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4140 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4141 | |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4142 | attr = xmlSchemaGetPropNode(node, "maxOccurs"); |
| 4143 | if (attr == NULL) |
| 4144 | return (def); |
| 4145 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4146 | |
| 4147 | if (xmlStrEqual(val, (const xmlChar *) "unbounded")) { |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4148 | if (max != UNBOUNDED) { |
| 4149 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4150 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4151 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 4152 | NULL, NULL, (xmlNodePtr) attr, NULL, expected, |
| 4153 | val, NULL, NULL, NULL); |
| 4154 | return (def); |
| 4155 | } else |
| 4156 | return (UNBOUNDED); /* encoding it with -1 might be another option */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4157 | } |
| 4158 | |
| 4159 | cur = val; |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4160 | while (IS_BLANK_CH(*cur)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4161 | cur++; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4162 | if (*cur == 0) { |
| 4163 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4164 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4165 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 4166 | NULL, NULL, (xmlNodePtr) attr, NULL, expected, |
| 4167 | val, NULL, NULL, NULL); |
| 4168 | return (def); |
| 4169 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4170 | while ((*cur >= '0') && (*cur <= '9')) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4171 | ret = ret * 10 + (*cur - '0'); |
| 4172 | cur++; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4173 | } |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4174 | while (IS_BLANK_CH(*cur)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4175 | cur++; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4176 | /* |
| 4177 | * TODO: Restrict the maximal value to Integer. |
| 4178 | */ |
| 4179 | if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) { |
| 4180 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4181 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4182 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 4183 | NULL, NULL, (xmlNodePtr) attr, NULL, expected, |
| 4184 | val, NULL, NULL, NULL); |
| 4185 | return (def); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4186 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4187 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4188 | } |
| 4189 | |
| 4190 | /** |
| 4191 | * xmlGetMinOccurs: |
| 4192 | * @ctxt: a schema validation context |
| 4193 | * @node: a subtree containing XML Schema informations |
| 4194 | * |
| 4195 | * Get the minOccurs property |
| 4196 | * |
| 4197 | * Returns the default if not found, or the value |
| 4198 | */ |
| 4199 | static int |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4200 | xmlGetMinOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, |
| 4201 | int min, int max, int def, const char *expected) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4202 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4203 | const xmlChar *val, *cur; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4204 | int ret = 0; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4205 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4206 | |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4207 | attr = xmlSchemaGetPropNode(node, "minOccurs"); |
| 4208 | if (attr == NULL) |
| 4209 | return (def); |
| 4210 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4211 | cur = val; |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4212 | while (IS_BLANK_CH(*cur)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4213 | cur++; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4214 | if (*cur == 0) { |
| 4215 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4216 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4217 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 4218 | NULL, NULL, (xmlNodePtr) attr, NULL, expected, |
| 4219 | val, NULL, NULL, NULL); |
| 4220 | return (def); |
| 4221 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4222 | while ((*cur >= '0') && (*cur <= '9')) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4223 | ret = ret * 10 + (*cur - '0'); |
| 4224 | cur++; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4225 | } |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4226 | while (IS_BLANK_CH(*cur)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4227 | cur++; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4228 | /* |
| 4229 | * TODO: Restrict the maximal value to Integer. |
| 4230 | */ |
| 4231 | if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) { |
| 4232 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4233 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 4234 | /* XML_SCHEMAP_INVALID_MINOCCURS, */ |
| 4235 | NULL, NULL, (xmlNodePtr) attr, NULL, expected, |
| 4236 | val, NULL, NULL, NULL); |
| 4237 | return (def); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4238 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4239 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4240 | } |
| 4241 | |
| 4242 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 4243 | * xmlSchemaPGetBoolNodeValue: |
| 4244 | * @ctxt: a schema validation context |
| 4245 | * @ownerDes: owner designation |
| 4246 | * @ownerItem: the owner as a schema item |
| 4247 | * @node: the node holding the value |
| 4248 | * |
| 4249 | * Converts a boolean string value into 1 or 0. |
| 4250 | * |
| 4251 | * Returns 0 or 1. |
| 4252 | */ |
| 4253 | static int |
| 4254 | xmlSchemaPGetBoolNodeValue(xmlSchemaParserCtxtPtr ctxt, |
| 4255 | xmlChar **ownerDes, |
| 4256 | xmlSchemaTypePtr ownerItem, |
| 4257 | xmlNodePtr node) |
| 4258 | { |
| 4259 | xmlChar *value = NULL; |
| 4260 | int res = 0; |
| 4261 | |
| 4262 | value = xmlNodeGetContent(node); |
| 4263 | /* |
| 4264 | * 3.2.2.1 Lexical representation |
| 4265 | * An instance of a datatype that is defined as ·boolean· |
| 4266 | * can have the following legal literals {true, false, 1, 0}. |
| 4267 | */ |
| 4268 | if (xmlStrEqual(BAD_CAST value, BAD_CAST "true")) |
| 4269 | res = 1; |
| 4270 | else if (xmlStrEqual(BAD_CAST value, BAD_CAST "false")) |
| 4271 | res = 0; |
| 4272 | else if (xmlStrEqual(BAD_CAST value, BAD_CAST "1")) |
| 4273 | res = 1; |
| 4274 | else if (xmlStrEqual(BAD_CAST value, BAD_CAST "0")) |
| 4275 | res = 0; |
| 4276 | else { |
| 4277 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4278 | XML_SCHEMAP_INVALID_BOOLEAN, |
| 4279 | ownerDes, ownerItem, node, |
| 4280 | xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN), |
| 4281 | "(1 | 0 | true | false)", BAD_CAST value, |
| 4282 | NULL, NULL, NULL); |
| 4283 | } |
| 4284 | if (value != NULL) |
| 4285 | xmlFree(value); |
| 4286 | return (res); |
| 4287 | } |
| 4288 | |
| 4289 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4290 | * xmlGetBooleanProp: |
| 4291 | * @ctxt: a schema validation context |
| 4292 | * @node: a subtree containing XML Schema informations |
| 4293 | * @name: the attribute name |
| 4294 | * @def: the default value |
| 4295 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4296 | * Evaluate if a boolean property is set |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4297 | * |
| 4298 | * Returns the default if not found, 0 if found to be false, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4299 | * 1 if found to be true |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4300 | */ |
| 4301 | static int |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4302 | xmlGetBooleanProp(xmlSchemaParserCtxtPtr ctxt, |
| 4303 | xmlChar **ownerDes, |
| 4304 | xmlSchemaTypePtr ownerItem, |
| 4305 | xmlNodePtr node, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4306 | const char *name, int def) |
| 4307 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4308 | const xmlChar *val; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4309 | |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4310 | val = xmlSchemaGetProp(ctxt, node, name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4311 | if (val == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4312 | return (def); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4313 | /* |
| 4314 | * 3.2.2.1 Lexical representation |
| 4315 | * An instance of a datatype that is defined as ·boolean· |
| 4316 | * can have the following legal literals {true, false, 1, 0}. |
| 4317 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4318 | if (xmlStrEqual(val, BAD_CAST "true")) |
| 4319 | def = 1; |
| 4320 | else if (xmlStrEqual(val, BAD_CAST "false")) |
| 4321 | def = 0; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4322 | else if (xmlStrEqual(val, BAD_CAST "1")) |
| 4323 | def = 1; |
| 4324 | else if (xmlStrEqual(val, BAD_CAST "0")) |
| 4325 | def = 0; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 4326 | else { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4327 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4328 | XML_SCHEMAP_INVALID_BOOLEAN, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 4329 | ownerDes, ownerItem, |
| 4330 | (xmlNodePtr) xmlSchemaGetPropNode(node, name), |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4331 | xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN), |
| 4332 | "(1 | 0 | true | false)", val, NULL, NULL, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4333 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4334 | return (def); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4335 | } |
| 4336 | |
| 4337 | /************************************************************************ |
| 4338 | * * |
| 4339 | * Shema extraction from an Infoset * |
| 4340 | * * |
| 4341 | ************************************************************************/ |
| 4342 | static xmlSchemaTypePtr xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr |
| 4343 | ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4344 | xmlNodePtr node, |
| 4345 | int topLevel); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4346 | static xmlSchemaTypePtr xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr |
| 4347 | ctxt, |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4348 | xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4349 | xmlNodePtr node, |
| 4350 | int topLevel); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4351 | static xmlSchemaTypePtr xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr |
| 4352 | ctxt, |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4353 | xmlSchemaPtr schema, |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 4354 | xmlNodePtr node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4355 | static xmlSchemaTypePtr xmlSchemaParseSequence(xmlSchemaParserCtxtPtr ctxt, |
| 4356 | xmlSchemaPtr schema, |
| 4357 | xmlNodePtr node); |
| 4358 | static xmlSchemaTypePtr xmlSchemaParseAll(xmlSchemaParserCtxtPtr ctxt, |
| 4359 | xmlSchemaPtr schema, |
| 4360 | xmlNodePtr node); |
| 4361 | static xmlSchemaAttributePtr xmlSchemaParseAttribute(xmlSchemaParserCtxtPtr |
| 4362 | ctxt, |
| 4363 | xmlSchemaPtr schema, |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4364 | xmlNodePtr node, |
| 4365 | int topLevel); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4366 | static xmlSchemaAttributeGroupPtr |
| 4367 | xmlSchemaParseAttributeGroup(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4368 | xmlSchemaPtr schema, xmlNodePtr node, |
| 4369 | int topLevel); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4370 | static xmlSchemaTypePtr xmlSchemaParseChoice(xmlSchemaParserCtxtPtr ctxt, |
| 4371 | xmlSchemaPtr schema, |
| 4372 | xmlNodePtr node); |
| 4373 | static xmlSchemaTypePtr xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt, |
| 4374 | xmlSchemaPtr schema, |
| 4375 | xmlNodePtr node); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4376 | static xmlSchemaWildcardPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4377 | xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt, |
| 4378 | xmlSchemaPtr schema, xmlNodePtr node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4379 | |
| 4380 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4381 | * xmlSchemaPValAttrNodeValue: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4382 | * |
| 4383 | * @ctxt: a schema parser context |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4384 | * @ownerDes: the designation of the parent element |
| 4385 | * @ownerItem: the schema object owner if existent |
| 4386 | * @attr: the schema attribute node being validated |
| 4387 | * @value: the value |
| 4388 | * @type: the built-in type to be validated against |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4389 | * |
| 4390 | * Validates a value against the given built-in type. |
| 4391 | * This one is intended to be used internally for validation |
| 4392 | * of schema attribute values during parsing of the schema. |
| 4393 | * |
| 4394 | * Returns 0 if the value is valid, a positive error code |
| 4395 | * number otherwise and -1 in case of an internal or API error. |
| 4396 | */ |
| 4397 | static int |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4398 | xmlSchemaPValAttrNodeValue(xmlSchemaParserCtxtPtr ctxt, |
| 4399 | xmlChar **ownerDes, |
| 4400 | xmlSchemaTypePtr ownerItem, |
| 4401 | xmlAttrPtr attr, |
| 4402 | const xmlChar *value, |
| 4403 | xmlSchemaTypePtr type) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4404 | { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4405 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4406 | int ret = 0; |
| 4407 | |
| 4408 | /* |
| 4409 | * NOTE: Should we move this to xmlschematypes.c? Hmm, but this |
| 4410 | * one is really meant to be used internally, so better not. |
| 4411 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4412 | if ((ctxt == NULL) || (type == NULL) || (attr == NULL)) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4413 | return (-1); |
| 4414 | if (type->type != XML_SCHEMA_TYPE_BASIC) { |
| 4415 | xmlSchemaPErr(ctxt, (xmlNodePtr) attr, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 4416 | XML_SCHEMAP_INTERNAL, |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 4417 | "Internal error: xmlSchemaPValAttrNodeValue, the given " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4418 | "type '%s' is not a built-in type.\n", |
| 4419 | type->name, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4420 | return (-1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4421 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4422 | switch (type->builtInType) { |
| 4423 | case XML_SCHEMAS_NCNAME: |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 4424 | case XML_SCHEMAS_QNAME: |
| 4425 | case XML_SCHEMAS_ANYURI: |
| 4426 | case XML_SCHEMAS_TOKEN: |
| 4427 | case XML_SCHEMAS_LANGUAGE: |
| 4428 | ret = xmlSchemaValPredefTypeNode(type, value, NULL, (xmlNodePtr) attr); |
| 4429 | break; |
| 4430 | |
| 4431 | /* |
| 4432 | case XML_SCHEMAS_NCNAME: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4433 | ret = xmlValidateNCName(value, 1); |
| 4434 | break; |
| 4435 | case XML_SCHEMAS_QNAME: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4436 | xmlSchemaPErr(ctxt, (xmlNodePtr) attr, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 4437 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4438 | "Internal error: xmlSchemaPvalueAttrNode, use " |
| 4439 | "the function xmlSchemaExtractSchemaQNamePropvalueidated " |
| 4440 | "for extracting QName valueues instead.\n", |
| 4441 | NULL, NULL); |
| 4442 | return (-1); |
| 4443 | case XML_SCHEMAS_ANYURI: |
| 4444 | if (value != NULL) { |
| 4445 | xmlURIPtr uri = xmlParseURI((const char *) value); |
| 4446 | if (uri == NULL) |
| 4447 | ret = 1; |
| 4448 | else |
| 4449 | xmlFreeURI(uri); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4450 | } |
| 4451 | break; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4452 | case XML_SCHEMAS_TOKEN: { |
| 4453 | const xmlChar *cur = value; |
| 4454 | |
| 4455 | if (IS_BLANK_CH(*cur)) { |
| 4456 | ret = 1; |
| 4457 | } else while (*cur != 0) { |
| 4458 | if ((*cur == 0xd) || (*cur == 0xa) || (*cur == 0x9)) { |
| 4459 | ret = 1; |
| 4460 | break; |
| 4461 | } else if (*cur == ' ') { |
| 4462 | cur++; |
| 4463 | if ((*cur == 0) || (*cur == ' ')) { |
| 4464 | ret = 1; |
| 4465 | break; |
| 4466 | } |
| 4467 | } else { |
| 4468 | cur++; |
| 4469 | } |
| 4470 | } |
| 4471 | } |
| 4472 | break; |
| 4473 | case XML_SCHEMAS_LANGUAGE: |
| 4474 | if (xmlCheckLanguageID(value) != 1) |
| 4475 | ret = 1; |
| 4476 | break; |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 4477 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4478 | default: { |
| 4479 | xmlSchemaPErr(ctxt, (xmlNodePtr) attr, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 4480 | XML_SCHEMAP_INTERNAL, |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 4481 | "Internal error: xmlSchemaPValAttrNodeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4482 | "valueidation using the type '%s' is not implemented " |
| 4483 | "yet.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4484 | type->name, NULL); |
| 4485 | return (-1); |
| 4486 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4487 | } |
| 4488 | /* |
| 4489 | * TODO: Should we use the S4S error codes instead? |
| 4490 | */ |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 4491 | if (ret < 0) { |
| 4492 | xmlSchemaPErr(ctxt, (xmlNodePtr) attr, |
| 4493 | XML_SCHEMAP_INTERNAL, |
| 4494 | "Internal error: xmlSchemaPValAttrNodeValue, " |
| 4495 | "failed to validate a schema attribute value.\n", |
| 4496 | NULL, NULL); |
| 4497 | return (-1); |
| 4498 | } else if (ret > 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4499 | if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 4500 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4501 | XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2, |
| 4502 | ownerDes, ownerItem, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4503 | type, NULL, value, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4504 | NULL, NULL, NULL); |
| 4505 | return(XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2); |
| 4506 | } else { |
| 4507 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4508 | XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, |
| 4509 | ownerDes, ownerItem, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4510 | type, NULL, value, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4511 | NULL, NULL, NULL); |
| 4512 | return(XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1); |
| 4513 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4514 | } |
| 4515 | return (ret); |
| 4516 | } |
| 4517 | |
| 4518 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4519 | * xmlSchemaPValAttrNode: |
| 4520 | * |
| 4521 | * @ctxt: a schema parser context |
| 4522 | * @ownerDes: the designation of the parent element |
| 4523 | * @ownerItem: the schema object owner if existent |
| 4524 | * @attr: the schema attribute node being validated |
| 4525 | * @type: the built-in type to be validated against |
| 4526 | * @value: the resulting value if any |
| 4527 | * |
| 4528 | * Extracts and validates a value against the given built-in type. |
| 4529 | * This one is intended to be used internally for validation |
| 4530 | * of schema attribute values during parsing of the schema. |
| 4531 | * |
| 4532 | * Returns 0 if the value is valid, a positive error code |
| 4533 | * number otherwise and -1 in case of an internal or API error. |
| 4534 | */ |
| 4535 | static int |
| 4536 | xmlSchemaPValAttrNode(xmlSchemaParserCtxtPtr ctxt, |
| 4537 | xmlChar **ownerDes, |
| 4538 | xmlSchemaTypePtr ownerItem, |
| 4539 | xmlAttrPtr attr, |
| 4540 | xmlSchemaTypePtr type, |
| 4541 | const xmlChar **value) |
| 4542 | { |
| 4543 | const xmlChar *val; |
| 4544 | |
| 4545 | if ((ctxt == NULL) || (type == NULL) || (attr == NULL)) |
| 4546 | return (-1); |
| 4547 | |
| 4548 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 4549 | if (value != NULL) |
| 4550 | *value = val; |
| 4551 | |
| 4552 | return (xmlSchemaPValAttrNodeValue(ctxt, ownerDes, ownerItem, attr, |
| 4553 | val, type)); |
| 4554 | } |
| 4555 | |
| 4556 | /** |
| 4557 | * xmlSchemaPValAttr: |
| 4558 | * |
| 4559 | * @ctxt: a schema parser context |
| 4560 | * @node: the element node of the attribute |
| 4561 | * @ownerDes: the designation of the parent element |
| 4562 | * @ownerItem: the schema object owner if existent |
| 4563 | * @ownerElem: the owner element node |
| 4564 | * @name: the name of the schema attribute node |
| 4565 | * @type: the built-in type to be validated against |
| 4566 | * @value: the resulting value if any |
| 4567 | * |
| 4568 | * Extracts and validates a value against the given built-in type. |
| 4569 | * This one is intended to be used internally for validation |
| 4570 | * of schema attribute values during parsing of the schema. |
| 4571 | * |
| 4572 | * Returns 0 if the value is valid, a positive error code |
| 4573 | * number otherwise and -1 in case of an internal or API error. |
| 4574 | */ |
| 4575 | static int |
| 4576 | xmlSchemaPValAttr(xmlSchemaParserCtxtPtr ctxt, |
| 4577 | xmlChar **ownerDes, |
| 4578 | xmlSchemaTypePtr ownerItem, |
| 4579 | xmlNodePtr ownerElem, |
| 4580 | const char *name, |
| 4581 | xmlSchemaTypePtr type, |
| 4582 | const xmlChar **value) |
| 4583 | { |
| 4584 | xmlAttrPtr attr; |
| 4585 | |
| 4586 | if ((ctxt == NULL) || (type == NULL)) { |
| 4587 | if (value != NULL) |
| 4588 | *value = NULL; |
| 4589 | return (-1); |
| 4590 | } |
| 4591 | if (type->type != XML_SCHEMA_TYPE_BASIC) { |
| 4592 | if (value != NULL) |
| 4593 | *value = NULL; |
| 4594 | xmlSchemaPErr(ctxt, ownerElem, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 4595 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4596 | "Internal error: xmlSchemaPValAttr, the given " |
| 4597 | "type '%s' is not a built-in type.\n", |
| 4598 | type->name, NULL); |
| 4599 | return (-1); |
| 4600 | } |
| 4601 | attr = xmlSchemaGetPropNode(ownerElem, name); |
| 4602 | if (attr == NULL) { |
| 4603 | if (value != NULL) |
| 4604 | *value = NULL; |
| 4605 | return (0); |
| 4606 | } |
| 4607 | return (xmlSchemaPValAttrNode(ctxt, ownerDes, ownerItem, attr, |
| 4608 | type, value)); |
| 4609 | } |
| 4610 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4611 | * xmlSchemaParseAttrDecls: |
| 4612 | * @ctxt: a schema validation context |
| 4613 | * @schema: the schema being built |
| 4614 | * @node: a subtree containing XML Schema informations |
| 4615 | * @type: the hosting type |
| 4616 | * |
| 4617 | * parse a XML schema attrDecls declaration corresponding to |
| 4618 | * <!ENTITY % attrDecls |
| 4619 | * '((%attribute;| %attributeGroup;)*,(%anyAttribute;)?)'> |
| 4620 | */ |
| 4621 | static xmlNodePtr |
| 4622 | xmlSchemaParseAttrDecls(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 4623 | xmlNodePtr child, xmlSchemaTypePtr type) |
| 4624 | { |
| 4625 | xmlSchemaAttributePtr lastattr, attr; |
| 4626 | |
| 4627 | lastattr = NULL; |
| 4628 | while ((IS_SCHEMA(child, "attribute")) || |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4629 | (IS_SCHEMA(child, "attributeGroup"))) { |
| 4630 | attr = NULL; |
| 4631 | if (IS_SCHEMA(child, "attribute")) { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4632 | attr = xmlSchemaParseAttribute(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4633 | } else if (IS_SCHEMA(child, "attributeGroup")) { |
| 4634 | attr = (xmlSchemaAttributePtr) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4635 | xmlSchemaParseAttributeGroup(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4636 | } |
| 4637 | if (attr != NULL) { |
| 4638 | if (lastattr == NULL) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 4639 | if (type->type == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) |
| 4640 | ((xmlSchemaAttributeGroupPtr) type)->attributes = attr; |
| 4641 | else |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4642 | type->attributes = attr; |
| 4643 | lastattr = attr; |
| 4644 | } else { |
| 4645 | lastattr->next = attr; |
| 4646 | lastattr = attr; |
| 4647 | } |
| 4648 | } |
| 4649 | child = child->next; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4650 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4651 | return (child); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4652 | } |
| 4653 | |
| 4654 | /** |
| 4655 | * xmlSchemaParseAnnotation: |
| 4656 | * @ctxt: a schema validation context |
| 4657 | * @schema: the schema being built |
| 4658 | * @node: a subtree containing XML Schema informations |
| 4659 | * |
| 4660 | * parse a XML schema Attrribute declaration |
| 4661 | * *WARNING* this interface is highly subject to change |
| 4662 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 4663 | * 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] | 4664 | * 1 in case of success. |
| 4665 | */ |
| 4666 | static xmlSchemaAnnotPtr |
| 4667 | xmlSchemaParseAnnotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 4668 | xmlNodePtr node) |
| 4669 | { |
| 4670 | xmlSchemaAnnotPtr ret; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4671 | xmlNodePtr child = NULL; |
| 4672 | xmlAttrPtr attr; |
| 4673 | int barked = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4674 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4675 | /* |
| 4676 | * INFO: S4S completed. |
| 4677 | */ |
| 4678 | /* |
| 4679 | * id = ID |
| 4680 | * {any attributes with non-schema namespace . . .}> |
| 4681 | * Content: (appinfo | documentation)* |
| 4682 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4683 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 4684 | return (NULL); |
| 4685 | ret = xmlSchemaNewAnnot(ctxt, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4686 | attr = node->properties; |
| 4687 | while (attr != NULL) { |
| 4688 | if (((attr->ns == NULL) && |
| 4689 | (!xmlStrEqual(attr->name, BAD_CAST "id"))) || |
| 4690 | ((attr->ns != NULL) && |
| 4691 | xmlStrEqual(attr->ns->href, xmlSchemaNs))) { |
| 4692 | |
| 4693 | xmlSchemaPIllegalAttrErr(ctxt, |
| 4694 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 4695 | NULL, NULL, attr); |
| 4696 | } |
| 4697 | attr = attr->next; |
| 4698 | } |
| 4699 | /* TODO: Check id. */ |
| 4700 | |
| 4701 | /* |
| 4702 | * And now for the children... |
| 4703 | */ |
| 4704 | child = node->children; |
| 4705 | while (child != NULL) { |
| 4706 | if (IS_SCHEMA(child, "appinfo")) { |
| 4707 | /* TODO: make available the content of "appinfo". */ |
| 4708 | /* |
| 4709 | * source = anyURI |
| 4710 | * {any attributes with non-schema namespace . . .}> |
| 4711 | * Content: ({any})* |
| 4712 | */ |
| 4713 | attr = child->properties; |
| 4714 | while (attr != NULL) { |
| 4715 | if (((attr->ns == NULL) && |
| 4716 | (!xmlStrEqual(attr->name, BAD_CAST "source"))) || |
| 4717 | ((attr->ns != NULL) && |
| 4718 | xmlStrEqual(attr->ns->href, xmlSchemaNs))) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4719 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4720 | xmlSchemaPIllegalAttrErr(ctxt, |
| 4721 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 4722 | NULL, NULL, attr); |
| 4723 | } |
| 4724 | attr = attr->next; |
| 4725 | } |
| 4726 | xmlSchemaPValAttr(ctxt, NULL, NULL, child, "source", |
| 4727 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), NULL); |
| 4728 | child = child->next; |
| 4729 | } else if (IS_SCHEMA(child, "documentation")) { |
| 4730 | /* TODO: make available the content of "documentation". */ |
| 4731 | /* |
| 4732 | * source = anyURI |
| 4733 | * {any attributes with non-schema namespace . . .}> |
| 4734 | * Content: ({any})* |
| 4735 | */ |
| 4736 | attr = child->properties; |
| 4737 | while (attr != NULL) { |
| 4738 | if (attr->ns == NULL) { |
| 4739 | if (!xmlStrEqual(attr->name, BAD_CAST "source")) { |
| 4740 | xmlSchemaPIllegalAttrErr(ctxt, |
| 4741 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 4742 | NULL, NULL, attr); |
| 4743 | } |
| 4744 | } else { |
| 4745 | if (xmlStrEqual(attr->ns->href, xmlSchemaNs) || |
| 4746 | (xmlStrEqual(attr->name, BAD_CAST "lang") && |
| 4747 | (!xmlStrEqual(attr->ns->href, XML_XML_NAMESPACE)))) { |
| 4748 | |
| 4749 | xmlSchemaPIllegalAttrErr(ctxt, |
| 4750 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 4751 | NULL, NULL, attr); |
| 4752 | } |
| 4753 | } |
| 4754 | attr = attr->next; |
| 4755 | } |
| 4756 | /* |
| 4757 | * Attribute "xml:lang". |
| 4758 | */ |
| 4759 | attr = xmlSchemaGetPropNodeNs(child, (const char *) XML_XML_NAMESPACE, "lang"); |
| 4760 | if (attr != NULL) |
| 4761 | xmlSchemaPValAttrNode(ctxt, NULL, NULL, attr, |
| 4762 | xmlSchemaGetBuiltInType(XML_SCHEMAS_LANGUAGE), NULL); |
| 4763 | child = child->next; |
| 4764 | } else { |
| 4765 | if (!barked) |
| 4766 | xmlSchemaPContentErr(ctxt, |
| 4767 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 4768 | NULL, NULL, node, child, NULL, "(appinfo | documentation)*"); |
| 4769 | barked = 1; |
| 4770 | child = child->next; |
| 4771 | } |
| 4772 | } |
| 4773 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4774 | return (ret); |
| 4775 | } |
| 4776 | |
| 4777 | /** |
| 4778 | * xmlSchemaParseFacet: |
| 4779 | * @ctxt: a schema validation context |
| 4780 | * @schema: the schema being built |
| 4781 | * @node: a subtree containing XML Schema informations |
| 4782 | * |
| 4783 | * parse a XML schema Facet declaration |
| 4784 | * *WARNING* this interface is highly subject to change |
| 4785 | * |
| 4786 | * Returns the new type structure or NULL in case of error |
| 4787 | */ |
| 4788 | static xmlSchemaFacetPtr |
| 4789 | xmlSchemaParseFacet(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4790 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4791 | { |
| 4792 | xmlSchemaFacetPtr facet; |
| 4793 | xmlNodePtr child = NULL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4794 | const xmlChar *value; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4795 | |
| 4796 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 4797 | return (NULL); |
| 4798 | |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 4799 | facet = xmlSchemaNewFacet(); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4800 | if (facet == NULL) { |
| 4801 | xmlSchemaPErrMemory(ctxt, "allocating facet", node); |
| 4802 | return (NULL); |
| 4803 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4804 | facet->node = node; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4805 | value = xmlSchemaGetProp(ctxt, node, "value"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4806 | if (value == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4807 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_FACET_NO_VALUE, |
| 4808 | "Facet %s has no value\n", node->name, NULL); |
| 4809 | xmlSchemaFreeFacet(facet); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4810 | return (NULL); |
| 4811 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4812 | if (IS_SCHEMA(node, "minInclusive")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4813 | facet->type = XML_SCHEMA_FACET_MININCLUSIVE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4814 | } else if (IS_SCHEMA(node, "minExclusive")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4815 | facet->type = XML_SCHEMA_FACET_MINEXCLUSIVE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4816 | } else if (IS_SCHEMA(node, "maxInclusive")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4817 | facet->type = XML_SCHEMA_FACET_MAXINCLUSIVE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4818 | } else if (IS_SCHEMA(node, "maxExclusive")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4819 | facet->type = XML_SCHEMA_FACET_MAXEXCLUSIVE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4820 | } else if (IS_SCHEMA(node, "totalDigits")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4821 | facet->type = XML_SCHEMA_FACET_TOTALDIGITS; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4822 | } else if (IS_SCHEMA(node, "fractionDigits")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4823 | facet->type = XML_SCHEMA_FACET_FRACTIONDIGITS; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4824 | } else if (IS_SCHEMA(node, "pattern")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4825 | facet->type = XML_SCHEMA_FACET_PATTERN; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4826 | } else if (IS_SCHEMA(node, "enumeration")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4827 | facet->type = XML_SCHEMA_FACET_ENUMERATION; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4828 | } else if (IS_SCHEMA(node, "whiteSpace")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4829 | facet->type = XML_SCHEMA_FACET_WHITESPACE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4830 | } else if (IS_SCHEMA(node, "length")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4831 | facet->type = XML_SCHEMA_FACET_LENGTH; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4832 | } else if (IS_SCHEMA(node, "maxLength")) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4833 | facet->type = XML_SCHEMA_FACET_MAXLENGTH; |
| 4834 | } else if (IS_SCHEMA(node, "minLength")) { |
| 4835 | facet->type = XML_SCHEMA_FACET_MINLENGTH; |
| 4836 | } else { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4837 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_TYPE, |
| 4838 | "Unknown facet type %s\n", node->name, NULL); |
| 4839 | xmlSchemaFreeFacet(facet); |
| 4840 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4841 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 4842 | facet->id = xmlSchemaGetProp(ctxt, node, "id"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4843 | facet->value = value; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4844 | if ((facet->type != XML_SCHEMA_FACET_PATTERN) && |
| 4845 | (facet->type != XML_SCHEMA_FACET_ENUMERATION)) { |
| 4846 | const xmlChar *fixed; |
| 4847 | |
| 4848 | fixed = xmlSchemaGetProp(ctxt, node, "fixed"); |
| 4849 | if (fixed != NULL) { |
| 4850 | if (xmlStrEqual(fixed, BAD_CAST "true")) |
| 4851 | facet->fixed = 1; |
| 4852 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 4853 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4854 | child = node->children; |
| 4855 | |
| 4856 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4857 | facet->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 4858 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4859 | } |
| 4860 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 4861 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_CHILD, |
| 4862 | "Facet %s has unexpected child content\n", |
| 4863 | node->name, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4864 | } |
| 4865 | return (facet); |
| 4866 | } |
| 4867 | |
| 4868 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4869 | * xmlSchemaParseWildcardNs: |
| 4870 | * @ctxt: a schema parser context |
| 4871 | * @wildc: the wildcard, already created |
| 4872 | * @node: a subtree containing XML Schema informations |
| 4873 | * |
| 4874 | * Parses the attribute "processContents" and "namespace" |
| 4875 | * of a xsd:anyAttribute and xsd:any. |
| 4876 | * *WARNING* this interface is highly subject to change |
| 4877 | * |
| 4878 | * Returns 0 if everything goes fine, a positive error code |
| 4879 | * if something is not valid and -1 if an internal error occurs. |
| 4880 | */ |
| 4881 | static int |
| 4882 | xmlSchemaParseWildcardNs(xmlSchemaParserCtxtPtr ctxt, |
| 4883 | xmlSchemaPtr schema, |
| 4884 | xmlSchemaWildcardPtr wildc, |
| 4885 | xmlNodePtr node) |
| 4886 | { |
| 4887 | const xmlChar *pc, *ns, *dictnsItem; |
| 4888 | int ret = 0; |
| 4889 | xmlChar *nsItem; |
| 4890 | xmlSchemaWildcardNsPtr tmp, lastNs = NULL; |
| 4891 | xmlAttrPtr attr; |
| 4892 | |
| 4893 | pc = xmlSchemaGetProp(ctxt, node, "processContents"); |
| 4894 | if ((pc == NULL) |
| 4895 | || (xmlStrEqual(pc, (const xmlChar *) "strict"))) { |
| 4896 | wildc->processContents = XML_SCHEMAS_ANY_STRICT; |
| 4897 | } else if (xmlStrEqual(pc, (const xmlChar *) "skip")) { |
| 4898 | wildc->processContents = XML_SCHEMAS_ANY_SKIP; |
| 4899 | } else if (xmlStrEqual(pc, (const xmlChar *) "lax")) { |
| 4900 | wildc->processContents = XML_SCHEMAS_ANY_LAX; |
| 4901 | } else { |
| 4902 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4903 | XML_SCHEMAP_UNKNOWN_PROCESSCONTENT_CHILD, |
| 4904 | NULL, NULL, node, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4905 | NULL, "(strict | skip | lax)", pc, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4906 | NULL, NULL, NULL); |
| 4907 | wildc->processContents = XML_SCHEMAS_ANY_STRICT; |
| 4908 | ret = XML_SCHEMAP_UNKNOWN_PROCESSCONTENT_CHILD; |
| 4909 | } |
| 4910 | /* |
| 4911 | * Build the namespace constraints. |
| 4912 | */ |
| 4913 | attr = xmlSchemaGetPropNode(node, "namespace"); |
| 4914 | ns = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 4915 | if ((ns == NULL) || (xmlStrEqual(ns, BAD_CAST "##any"))) |
| 4916 | wildc->any = 1; |
| 4917 | else if (xmlStrEqual(ns, BAD_CAST "##other")) { |
| 4918 | wildc->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 4919 | if (wildc->negNsSet == NULL) { |
| 4920 | return (-1); |
| 4921 | } |
| 4922 | wildc->negNsSet->value = schema->targetNamespace; |
| 4923 | } else { |
| 4924 | const xmlChar *end, *cur; |
| 4925 | |
| 4926 | cur = ns; |
| 4927 | do { |
| 4928 | while (IS_BLANK_CH(*cur)) |
| 4929 | cur++; |
| 4930 | end = cur; |
| 4931 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 4932 | end++; |
| 4933 | if (end == cur) |
| 4934 | break; |
| 4935 | nsItem = xmlStrndup(cur, end - cur); |
| 4936 | if ((xmlStrEqual(nsItem, BAD_CAST "##other")) || |
| 4937 | (xmlStrEqual(nsItem, BAD_CAST "##any"))) { |
| 4938 | xmlSchemaPSimpleTypeErr(ctxt, |
| 4939 | XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER, |
| 4940 | NULL, NULL, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4941 | NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4942 | "((##any | ##other) | List of (anyURI | " |
| 4943 | "(##targetNamespace | ##local)))", |
| 4944 | nsItem, NULL, NULL, NULL); |
| 4945 | ret = XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER; |
| 4946 | } else { |
| 4947 | if (xmlStrEqual(nsItem, BAD_CAST "##targetNamespace")) { |
| 4948 | dictnsItem = schema->targetNamespace; |
| 4949 | } else if (xmlStrEqual(nsItem, BAD_CAST "##local")) { |
| 4950 | dictnsItem = NULL; |
| 4951 | } else { |
| 4952 | /* |
| 4953 | * Validate the item (anyURI). |
| 4954 | */ |
| 4955 | xmlSchemaPValAttrNodeValue(ctxt, NULL, NULL, attr, |
| 4956 | nsItem, xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI)); |
| 4957 | dictnsItem = xmlDictLookup(ctxt->dict, nsItem, -1); |
| 4958 | } |
| 4959 | /* |
| 4960 | * Avoid dublicate namespaces. |
| 4961 | */ |
| 4962 | tmp = wildc->nsSet; |
| 4963 | while (tmp != NULL) { |
| 4964 | if (dictnsItem == tmp->value) |
| 4965 | break; |
| 4966 | tmp = tmp->next; |
| 4967 | } |
| 4968 | if (tmp == NULL) { |
| 4969 | tmp = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 4970 | if (tmp == NULL) { |
| 4971 | xmlFree(nsItem); |
| 4972 | return (-1); |
| 4973 | } |
| 4974 | tmp->value = dictnsItem; |
| 4975 | tmp->next = NULL; |
| 4976 | if (wildc->nsSet == NULL) |
| 4977 | wildc->nsSet = tmp; |
| 4978 | else |
| 4979 | lastNs->next = tmp; |
| 4980 | lastNs = tmp; |
| 4981 | } |
| 4982 | |
| 4983 | } |
| 4984 | xmlFree(nsItem); |
| 4985 | cur = end; |
| 4986 | } while (*cur != 0); |
| 4987 | } |
| 4988 | return (ret); |
| 4989 | } |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 4990 | |
| 4991 | static int |
| 4992 | xmlSchemaPCheckParticleCorrect_2(xmlSchemaParserCtxtPtr ctxt, |
| 4993 | xmlSchemaTypePtr item, |
| 4994 | xmlNodePtr node, |
| 4995 | int minOccurs, |
| 4996 | int maxOccurs) { |
| 4997 | |
| 4998 | if (maxOccurs != UNBOUNDED) { |
| 4999 | /* |
| 5000 | * TODO: Maby we should better not create the particle, |
| 5001 | * if min/max is invalid, since it could confuse the build of the |
| 5002 | * content model. |
| 5003 | */ |
| 5004 | /* |
| 5005 | * 3.9.6 Schema Component Constraint: Particle Correct |
| 5006 | * |
| 5007 | */ |
| 5008 | if (maxOccurs < 1) { |
| 5009 | /* |
| 5010 | * 2.2 {max occurs} must be greater than or equal to 1. |
| 5011 | */ |
| 5012 | xmlSchemaPCustomAttrErr(ctxt, |
| 5013 | XML_SCHEMAP_P_PROPS_CORRECT_2_2, |
| 5014 | NULL, item, xmlSchemaGetPropNode(node, "maxOccurs"), |
| 5015 | "The value must be greater than or equal to 1"); |
| 5016 | return (XML_SCHEMAP_P_PROPS_CORRECT_2_2); |
| 5017 | } else if (minOccurs > maxOccurs) { |
| 5018 | /* |
| 5019 | * 2.1 {min occurs} must not be greater than {max occurs}. |
| 5020 | */ |
| 5021 | xmlSchemaPCustomAttrErr(ctxt, |
| 5022 | XML_SCHEMAP_P_PROPS_CORRECT_2_1, |
| 5023 | NULL, item, xmlSchemaGetPropNode(node, "minOccurs"), |
| 5024 | "The value must not be greater than the value of 'maxOccurs'"); |
| 5025 | return (XML_SCHEMAP_P_PROPS_CORRECT_2_1); |
| 5026 | } |
| 5027 | } |
| 5028 | return (0); |
| 5029 | } |
| 5030 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5031 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5032 | * xmlSchemaParseAny: |
| 5033 | * @ctxt: a schema validation context |
| 5034 | * @schema: the schema being built |
| 5035 | * @node: a subtree containing XML Schema informations |
| 5036 | * |
| 5037 | * parse a XML schema Any declaration |
| 5038 | * *WARNING* this interface is highly subject to change |
| 5039 | * |
| 5040 | * Returns the new type structure or NULL in case of error |
| 5041 | */ |
| 5042 | static xmlSchemaTypePtr |
| 5043 | xmlSchemaParseAny(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 5044 | xmlNodePtr node) |
| 5045 | { |
| 5046 | xmlSchemaTypePtr type; |
| 5047 | xmlNodePtr child = NULL; |
| 5048 | xmlChar name[30]; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5049 | xmlSchemaWildcardPtr wildc; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5050 | int minOccurs, maxOccurs; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5051 | |
| 5052 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5053 | return (NULL); |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5054 | maxOccurs = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, |
| 5055 | "(nonNegativeInteger | unbounded)"); |
| 5056 | minOccurs = xmlGetMinOccurs(ctxt, node, 0, -1, 1, |
| 5057 | "nonNegativeInteger"); |
| 5058 | if ((minOccurs == 0) && (maxOccurs == 0)) |
| 5059 | return (NULL); |
| 5060 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 5061 | snprintf((char *) name, 30, "#any%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5062 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5063 | if (type == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5064 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5065 | type->node = node; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5066 | type->type = XML_SCHEMA_TYPE_ANY; |
| 5067 | |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 5068 | /* |
| 5069 | * TODO: Use a particle component here. |
| 5070 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5071 | wildc = xmlSchemaAddWildcard(ctxt); |
| 5072 | /* |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5073 | * Check min/max sanity. |
| 5074 | */ |
| 5075 | type->maxOccurs = maxOccurs; |
| 5076 | type->minOccurs = minOccurs; |
| 5077 | xmlSchemaPCheckParticleCorrect_2(ctxt, type, |
| 5078 | node, type->minOccurs, type->maxOccurs); |
| 5079 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5080 | * This is not nice, since it is won't be used as a attribute wildcard, |
| 5081 | * but better than adding a field to the structure. |
| 5082 | */ |
| 5083 | type->attributeWildcard = wildc; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5084 | xmlSchemaParseWildcardNs(ctxt, schema, wildc, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5085 | child = node->children; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5086 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5087 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5088 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5089 | } |
| 5090 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5091 | xmlSchemaPErr2(ctxt, node, child, |
| 5092 | XML_SCHEMAP_UNKNOWN_SEQUENCE_CHILD, |
| 5093 | "Sequence %s has unexpected content\n", type->name, |
| 5094 | NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5095 | } |
| 5096 | |
| 5097 | return (type); |
| 5098 | } |
| 5099 | |
| 5100 | /** |
| 5101 | * xmlSchemaParseNotation: |
| 5102 | * @ctxt: a schema validation context |
| 5103 | * @schema: the schema being built |
| 5104 | * @node: a subtree containing XML Schema informations |
| 5105 | * |
| 5106 | * parse a XML schema Notation declaration |
| 5107 | * |
| 5108 | * Returns the new structure or NULL in case of error |
| 5109 | */ |
| 5110 | static xmlSchemaNotationPtr |
| 5111 | xmlSchemaParseNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5112 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5113 | { |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5114 | const xmlChar *name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5115 | xmlSchemaNotationPtr ret; |
| 5116 | xmlNodePtr child = NULL; |
| 5117 | |
| 5118 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5119 | return (NULL); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5120 | name = xmlSchemaGetProp(ctxt, node, "name"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5121 | if (name == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5122 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_NOTATION_NO_NAME, |
| 5123 | "Notation has no name\n", NULL, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5124 | return (NULL); |
| 5125 | } |
| 5126 | ret = xmlSchemaAddNotation(ctxt, schema, name); |
| 5127 | if (ret == NULL) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5128 | return (NULL); |
| 5129 | } |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 5130 | ret->targetNamespace = schema->targetNamespace; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5131 | child = node->children; |
| 5132 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5133 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5134 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5135 | } |
| 5136 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5137 | xmlSchemaPErr2(ctxt, node, child, |
| 5138 | XML_SCHEMAP_UNKNOWN_NOTATION_CHILD, |
| 5139 | "notation %s has unexpected content\n", name, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5140 | } |
| 5141 | |
| 5142 | return (ret); |
| 5143 | } |
| 5144 | |
| 5145 | /** |
| 5146 | * xmlSchemaParseAnyAttribute: |
| 5147 | * @ctxt: a schema validation context |
| 5148 | * @schema: the schema being built |
| 5149 | * @node: a subtree containing XML Schema informations |
| 5150 | * |
| 5151 | * parse a XML schema AnyAttrribute declaration |
| 5152 | * *WARNING* this interface is highly subject to change |
| 5153 | * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5154 | * Returns a wildcard or NULL. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5155 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5156 | static xmlSchemaWildcardPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5157 | xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt, |
| 5158 | xmlSchemaPtr schema, xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5159 | { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5160 | xmlSchemaWildcardPtr ret; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5161 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5162 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5163 | |
| 5164 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5165 | return (NULL); |
| 5166 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5167 | ret = xmlSchemaAddWildcard(ctxt); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5168 | if (ret == NULL) { |
| 5169 | return (NULL); |
| 5170 | } |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5171 | ret->type = XML_SCHEMA_TYPE_ANY_ATTRIBUTE; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5172 | /* |
| 5173 | * Check for illegal attributes. |
| 5174 | */ |
| 5175 | attr = node->properties; |
| 5176 | while (attr != NULL) { |
| 5177 | if (attr->ns == NULL) { |
| 5178 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 5179 | (!xmlStrEqual(attr->name, BAD_CAST "namespace")) && |
| 5180 | (!xmlStrEqual(attr->name, BAD_CAST "processContents"))) { |
| 5181 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5182 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5183 | NULL, NULL, attr); |
| 5184 | } |
| 5185 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 5186 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5187 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5188 | NULL, NULL, attr); |
| 5189 | } |
| 5190 | attr = attr->next; |
| 5191 | } |
| 5192 | /* ret->id = xmlSchemaGetProp(ctxt, node, "id"); */ |
| 5193 | /* |
| 5194 | * Parse the namespace list. |
| 5195 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5196 | if (xmlSchemaParseWildcardNs(ctxt, schema, ret, node) != 0) { |
| 5197 | xmlSchemaFreeWildcard(ret); |
| 5198 | return (NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5199 | } |
| 5200 | /* |
| 5201 | * And now for the children... |
| 5202 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5203 | child = node->children; |
| 5204 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5205 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5206 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5207 | } |
| 5208 | if (child != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5209 | xmlSchemaPContentErr(ctxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5210 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 5211 | NULL, NULL, node, child, |
| 5212 | NULL, "(annotation?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5213 | } |
| 5214 | |
| 5215 | return (ret); |
| 5216 | } |
| 5217 | |
| 5218 | |
| 5219 | /** |
| 5220 | * xmlSchemaParseAttribute: |
| 5221 | * @ctxt: a schema validation context |
| 5222 | * @schema: the schema being built |
| 5223 | * @node: a subtree containing XML Schema informations |
| 5224 | * |
| 5225 | * parse a XML schema Attrribute declaration |
| 5226 | * *WARNING* this interface is highly subject to change |
| 5227 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5228 | * Returns the attribute declaration. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5229 | */ |
| 5230 | static xmlSchemaAttributePtr |
| 5231 | xmlSchemaParseAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5232 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5233 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5234 | const xmlChar *name, *attrValue; |
| 5235 | xmlChar *repName = NULL; /* The reported designation. */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5236 | xmlSchemaAttributePtr ret; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5237 | xmlNodePtr child = NULL; |
| 5238 | xmlAttrPtr attr, nameAttr; |
| 5239 | int isRef = 0; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5240 | |
| 5241 | /* |
| 5242 | * Note that the w3c spec assumes the schema to be validated with schema |
| 5243 | * for schemas beforehand. |
| 5244 | * |
| 5245 | * 3.2.3 Constraints on XML Representations of Attribute Declarations |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5246 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5247 | |
| 5248 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5249 | return (NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5250 | attr = xmlSchemaGetPropNode(node, "ref"); |
| 5251 | nameAttr = xmlSchemaGetPropNode(node, "name"); |
| 5252 | |
| 5253 | if ((attr == NULL) && (nameAttr == NULL)) { |
| 5254 | /* |
| 5255 | * 3.2.3 : 3.1 |
| 5256 | * One of ref or name must be present, but not both |
| 5257 | */ |
| 5258 | xmlSchemaPMissingAttrErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_3_1, |
| 5259 | (xmlChar **) &xmlSchemaElemDesAttrDecl, NULL, node, NULL, |
| 5260 | "One of the attributes 'ref' or 'name' must be present"); |
| 5261 | return (NULL); |
| 5262 | } |
| 5263 | if ((topLevel) || (attr == NULL)) { |
| 5264 | if (nameAttr == NULL) { |
| 5265 | xmlSchemaPMissingAttrErr(ctxt, XML_SCHEMAP_S4S_ATTR_MISSING, |
| 5266 | (xmlChar **) &xmlSchemaElemDesAttrDecl, NULL, node, |
| 5267 | "name", NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5268 | return (NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5269 | } |
| 5270 | } else |
| 5271 | isRef = 1; |
| 5272 | |
| 5273 | if (isRef) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 5274 | char buf[50]; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5275 | const xmlChar *refNs = NULL, *ref = NULL, *refPrefix = NULL; |
| 5276 | |
| 5277 | /* |
| 5278 | * Parse as attribute reference. |
| 5279 | */ |
| 5280 | if (xmlSchemaPValAttrNodeQName(ctxt, schema, |
| 5281 | (xmlChar **) &xmlSchemaElemDesAttrRef, NULL, attr, &refNs, |
| 5282 | &refPrefix, &ref) != 0) { |
| 5283 | return (NULL); |
| 5284 | } |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 5285 | snprintf(buf, 49, "#aRef%d", ctxt->counter++ + 1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5286 | name = (const xmlChar *) buf; |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 5287 | ret = xmlSchemaAddAttribute(ctxt, schema, name, NULL, node, 0); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5288 | if (ret == NULL) { |
| 5289 | if (repName != NULL) |
| 5290 | xmlFree(repName); |
| 5291 | return (NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5292 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5293 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTE; |
| 5294 | ret->node = node; |
| 5295 | ret->refNs = refNs; |
| 5296 | ret->refPrefix = refPrefix; |
| 5297 | ret->ref = ref; |
| 5298 | /* |
| 5299 | xmlSchemaFormatTypeRep(&repName, (xmlSchemaTypePtr) ret, NULL, NULL); |
| 5300 | */ |
| 5301 | if (nameAttr != NULL) |
| 5302 | xmlSchemaPMutualExclAttrErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_3_1, |
| 5303 | &repName, (xmlSchemaTypePtr) ret, nameAttr, |
| 5304 | "ref", "name"); |
| 5305 | /* |
| 5306 | * Check for illegal attributes. |
| 5307 | */ |
| 5308 | attr = node->properties; |
| 5309 | while (attr != NULL) { |
| 5310 | if (attr->ns == NULL) { |
| 5311 | if (xmlStrEqual(attr->name, BAD_CAST "type") || |
| 5312 | xmlStrEqual(attr->name, BAD_CAST "form")) { |
| 5313 | /* |
| 5314 | * 3.2.3 : 3.2 |
| 5315 | * If ref is present, then all of <simpleType>, |
| 5316 | * form and type must be absent. |
| 5317 | */ |
| 5318 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5319 | XML_SCHEMAP_SRC_ATTRIBUTE_3_2, &repName, |
| 5320 | (xmlSchemaTypePtr) ret, attr); |
| 5321 | } else if ((!xmlStrEqual(attr->name, BAD_CAST "ref")) && |
| 5322 | (!xmlStrEqual(attr->name, BAD_CAST "use")) && |
| 5323 | (!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 5324 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
| 5325 | (!xmlStrEqual(attr->name, BAD_CAST "fixed")) && |
| 5326 | (!xmlStrEqual(attr->name, BAD_CAST "default"))) { |
| 5327 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5328 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5329 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 5330 | } |
| 5331 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 5332 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5333 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5334 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 5335 | } |
| 5336 | attr = attr->next; |
| 5337 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 5338 | } else { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5339 | const xmlChar *ns = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5340 | |
| 5341 | /* |
| 5342 | * Parse as attribute declaration. |
| 5343 | */ |
| 5344 | if (xmlSchemaPValAttrNode(ctxt, |
| 5345 | (xmlChar **) &xmlSchemaElemDesAttrDecl, NULL, nameAttr, |
| 5346 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 5347 | return (NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5348 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5349 | /* |
| 5350 | xmlSchemaFormatTypeRep(&repName, NULL, xmlSchemaElemDesAttrDecl, name); |
| 5351 | */ |
| 5352 | /* |
| 5353 | * 3.2.6 Schema Component Constraint: xmlns Not Allowed |
| 5354 | */ |
| 5355 | if (xmlStrEqual(name, BAD_CAST "xmlns")) { |
| 5356 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5357 | XML_SCHEMAP_NO_XMLNS, |
| 5358 | &repName, NULL, (xmlNodePtr) nameAttr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5359 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), "NCName", NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5360 | "The value must not match 'xmlns'", |
| 5361 | NULL, NULL); |
| 5362 | if (repName != NULL) |
| 5363 | xmlFree(repName); |
| 5364 | return (NULL); |
| 5365 | } |
| 5366 | /* |
| 5367 | * Evaluate the target namespace |
| 5368 | */ |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 5369 | if (topLevel) { |
| 5370 | ns = schema->targetNamespace; |
| 5371 | } else { |
| 5372 | attr = xmlSchemaGetPropNode(node, "form"); |
| 5373 | if (attr != NULL) { |
| 5374 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 5375 | if (xmlStrEqual(attrValue, BAD_CAST "qualified")) { |
| 5376 | ns = schema->targetNamespace; |
| 5377 | } else if (!xmlStrEqual(attrValue, BAD_CAST "unqualified")) { |
| 5378 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5379 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 5380 | &repName, NULL, (xmlNodePtr) attr, |
| 5381 | NULL, "(qualified | unqualified)", |
| 5382 | attrValue, NULL, NULL, NULL); |
| 5383 | } |
| 5384 | } else if (schema->flags & XML_SCHEMAS_QUALIF_ATTR) |
| 5385 | ns = schema->targetNamespace; |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 5386 | } |
| 5387 | ret = xmlSchemaAddAttribute(ctxt, schema, name, ns, node, topLevel); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5388 | if (ret == NULL) { |
| 5389 | if (repName != NULL) |
| 5390 | xmlFree(repName); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5391 | return (NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5392 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5393 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTE; |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 5394 | ret->node = node; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5395 | if (topLevel) |
| 5396 | ret->flags |= XML_SCHEMAS_ATTR_GLOBAL; |
| 5397 | /* |
| 5398 | * 3.2.6 Schema Component Constraint: xsi: Not Allowed |
| 5399 | */ |
| 5400 | if (xmlStrEqual(ret->targetNamespace, xmlSchemaInstanceNs)) { |
| 5401 | xmlSchemaPCustomErr(ctxt, |
| 5402 | XML_SCHEMAP_NO_XSI, |
| 5403 | &repName, (xmlSchemaTypePtr) ret, node, |
| 5404 | "The target namespace must not match '%s'", |
| 5405 | xmlSchemaInstanceNs); |
| 5406 | } |
| 5407 | /* |
| 5408 | * Check for illegal attributes. |
| 5409 | */ |
| 5410 | attr = node->properties; |
| 5411 | while (attr != NULL) { |
| 5412 | if (attr->ns == NULL) { |
| 5413 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 5414 | (!xmlStrEqual(attr->name, BAD_CAST "default")) && |
| 5415 | (!xmlStrEqual(attr->name, BAD_CAST "fixed")) && |
| 5416 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
| 5417 | (!xmlStrEqual(attr->name, BAD_CAST "type"))) { |
| 5418 | if ((topLevel) || |
| 5419 | ((!xmlStrEqual(attr->name, BAD_CAST "form")) && |
| 5420 | (!xmlStrEqual(attr->name, BAD_CAST "use")))) { |
| 5421 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5422 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5423 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 5424 | } |
| 5425 | } |
| 5426 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 5427 | xmlSchemaPIllegalAttrErr(ctxt, XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5428 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 5429 | } |
| 5430 | attr = attr->next; |
| 5431 | } |
| 5432 | xmlSchemaPValAttrQName(ctxt, schema, &repName, (xmlSchemaTypePtr) ret, |
| 5433 | node, "type", &ret->typeNs, NULL, &ret->typeName); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5434 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5435 | /* TODO: Check ID. */ |
| 5436 | ret->id = xmlSchemaGetProp(ctxt, node, "id"); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5437 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5438 | * Attribute "fixed". |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 5439 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5440 | ret->defValue = xmlSchemaGetProp(ctxt, node, "fixed"); |
| 5441 | if (ret->defValue != NULL) |
| 5442 | ret->flags |= XML_SCHEMAS_ATTR_FIXED; |
| 5443 | /* |
| 5444 | * Attribute "default". |
| 5445 | */ |
| 5446 | attr = xmlSchemaGetPropNode(node, "default"); |
| 5447 | if (attr != NULL) { |
| 5448 | /* |
| 5449 | * 3.2.3 : 1 |
| 5450 | * default and fixed must not both be present. |
| 5451 | */ |
| 5452 | if (ret->flags & XML_SCHEMAS_ATTR_FIXED) { |
| 5453 | xmlSchemaPMutualExclAttrErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_1, |
| 5454 | &repName, (xmlSchemaTypePtr) ret, attr, "default", "fixed"); |
| 5455 | } else |
| 5456 | ret->defValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 5457 | } |
| 5458 | if (topLevel == 0) { |
| 5459 | /* |
| 5460 | * Attribute "use". |
| 5461 | */ |
| 5462 | attr = xmlSchemaGetPropNode(node, "use"); |
| 5463 | if (attr != NULL) { |
| 5464 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 5465 | if (xmlStrEqual(attrValue, BAD_CAST "optional")) |
| 5466 | ret->occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL; |
| 5467 | else if (xmlStrEqual(attrValue, BAD_CAST "prohibited")) |
| 5468 | ret->occurs = XML_SCHEMAS_ATTR_USE_PROHIBITED; |
| 5469 | else if (xmlStrEqual(attrValue, BAD_CAST "required")) |
| 5470 | ret->occurs = XML_SCHEMAS_ATTR_USE_REQUIRED; |
| 5471 | else |
| 5472 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5473 | XML_SCHEMAP_INVALID_ATTR_USE, |
| 5474 | &repName, (xmlSchemaTypePtr) ret, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5475 | NULL, "(optional | prohibited | required)", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5476 | attrValue, NULL, NULL, NULL); |
| 5477 | } else |
| 5478 | ret->occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL; |
| 5479 | /* |
| 5480 | * 3.2.3 : 2 |
| 5481 | * If default and use are both present, use must have |
| 5482 | * the actual value optional. |
| 5483 | */ |
| 5484 | if ((ret->occurs != XML_SCHEMAS_ATTR_USE_OPTIONAL) && |
| 5485 | (ret->defValue != NULL) && |
| 5486 | ((ret->flags & XML_SCHEMAS_ATTR_FIXED) == 0)) { |
| 5487 | xmlSchemaPSimpleTypeErr(ctxt, |
| 5488 | XML_SCHEMAP_SRC_ATTRIBUTE_2, |
| 5489 | &repName, (xmlSchemaTypePtr) ret, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5490 | NULL, "(optional | prohibited | required)", NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5491 | "The value must be 'optional' if the attribute " |
| 5492 | "'default' is present as well", NULL, NULL); |
| 5493 | } |
| 5494 | } |
| 5495 | /* |
| 5496 | * And now for the children... |
| 5497 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5498 | child = node->children; |
| 5499 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5500 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5501 | child = child->next; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5502 | } |
| 5503 | if (isRef) { |
| 5504 | if (child != NULL) { |
| 5505 | if (IS_SCHEMA(child, "simpleType")) |
| 5506 | /* |
| 5507 | * 3.2.3 : 3.2 |
| 5508 | * If ref is present, then all of <simpleType>, |
| 5509 | * form and type must be absent. |
| 5510 | */ |
| 5511 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_3_2, |
| 5512 | &repName, (xmlSchemaTypePtr) ret, node, child, NULL, |
| 5513 | "(annotation?)"); |
| 5514 | else |
| 5515 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 5516 | &repName, (xmlSchemaTypePtr) ret, node, child, NULL, |
| 5517 | "(annotation?)"); |
| 5518 | } |
| 5519 | } else { |
| 5520 | if (IS_SCHEMA(child, "simpleType")) { |
| 5521 | if (ret->typeName != NULL) { |
| 5522 | /* |
| 5523 | * 3.2.3 : 4 |
| 5524 | * type and <simpleType> must not both be present. |
| 5525 | */ |
| 5526 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_SRC_ATTRIBUTE_4, |
| 5527 | &repName, (xmlSchemaTypePtr) ret, node, child, |
| 5528 | "The attribute 'type' and the <simpleType> child " |
| 5529 | "are mutually exclusive", NULL); |
| 5530 | } else |
| 5531 | ret->subtypes = xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
| 5532 | child = child->next; |
| 5533 | } |
| 5534 | if (child != NULL) |
| 5535 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 5536 | &repName, (xmlSchemaTypePtr) ret, node, child, NULL, |
| 5537 | "(annotation?, simpleType?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5538 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5539 | /* |
| 5540 | * Cleanup. |
| 5541 | */ |
| 5542 | if (repName != NULL) |
| 5543 | xmlFree(repName); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5544 | return (ret); |
| 5545 | } |
| 5546 | |
| 5547 | /** |
| 5548 | * xmlSchemaParseAttributeGroup: |
| 5549 | * @ctxt: a schema validation context |
| 5550 | * @schema: the schema being built |
| 5551 | * @node: a subtree containing XML Schema informations |
| 5552 | * |
| 5553 | * parse a XML schema Attribute Group declaration |
| 5554 | * *WARNING* this interface is highly subject to change |
| 5555 | * |
| 5556 | * Returns the attribute group or NULL in case of error. |
| 5557 | */ |
| 5558 | static xmlSchemaAttributeGroupPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5559 | xmlSchemaParseAttributeGroup(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 5560 | xmlSchemaPtr schema, xmlNodePtr node, |
| 5561 | int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5562 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5563 | const xmlChar *name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5564 | xmlSchemaAttributeGroupPtr ret; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5565 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5566 | const xmlChar *oldcontainer; |
| 5567 | xmlAttrPtr attr, nameAttr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5568 | |
| 5569 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 5570 | return (NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5571 | |
| 5572 | nameAttr = xmlSchemaGetPropNode(node, "name"); |
| 5573 | attr = xmlSchemaGetPropNode(node, "ref"); |
| 5574 | if ((topLevel) || (attr == NULL)) { |
| 5575 | /* |
| 5576 | * Parse as an attribute group definition. |
| 5577 | * Note that those are allowed at top level only. |
| 5578 | */ |
| 5579 | if (nameAttr == NULL) { |
| 5580 | xmlSchemaPMissingAttrErr(ctxt, |
| 5581 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 5582 | NULL, NULL, node, "name", NULL); |
| 5583 | return (NULL); |
| 5584 | } |
| 5585 | name = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) nameAttr); |
| 5586 | /* |
| 5587 | * The name is crucial, exit if invalid. |
| 5588 | */ |
| 5589 | if (xmlSchemaPValAttrNode(ctxt, |
| 5590 | NULL, NULL, nameAttr, |
| 5591 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 5592 | return (NULL); |
| 5593 | } |
| 5594 | ret = xmlSchemaAddAttributeGroup(ctxt, schema, name, node); |
| 5595 | if (ret == NULL) |
| 5596 | return (NULL); |
| 5597 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTEGROUP; |
| 5598 | ret->flags |= XML_SCHEMAS_ATTRGROUP_GLOBAL; |
| 5599 | ret->node = node; |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 5600 | ret->targetNamespace = schema->targetNamespace; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5601 | } else { |
| 5602 | char buf[50]; |
| 5603 | const xmlChar *refNs = NULL, *ref = NULL, *refPrefix; |
| 5604 | |
| 5605 | /* |
| 5606 | * Parse as an attribute group definition reference. |
| 5607 | */ |
| 5608 | if (attr == NULL) { |
| 5609 | xmlSchemaPMissingAttrErr(ctxt, |
| 5610 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 5611 | NULL, NULL, node, "ref", NULL); |
| 5612 | } |
| 5613 | xmlSchemaPValAttrNodeQName(ctxt, schema, |
| 5614 | NULL, NULL, attr, &refNs, &refPrefix, &ref); |
| 5615 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 5616 | snprintf(buf, 49, "#agRef%d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5617 | name = (const xmlChar *) buf; |
| 5618 | if (name == NULL) { |
| 5619 | xmlSchemaPErrMemory(ctxt, "creating internal name for an " |
| 5620 | "attribute group definition reference", node); |
| 5621 | return (NULL); |
| 5622 | } |
| 5623 | ret = xmlSchemaAddAttributeGroup(ctxt, schema, name, node); |
| 5624 | if (ret == NULL) |
| 5625 | return (NULL); |
| 5626 | ret->type = XML_SCHEMA_TYPE_ATTRIBUTEGROUP; |
| 5627 | ret->ref = ref; |
| 5628 | ret->refNs = refNs; |
| 5629 | /* TODO: Is @refPrefix currently used? */ |
| 5630 | ret->refPrefix = refPrefix; |
| 5631 | ret->node = node; |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 5632 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5633 | /* |
| 5634 | * Check for illegal attributes. |
| 5635 | */ |
| 5636 | attr = node->properties; |
| 5637 | while (attr != NULL) { |
| 5638 | if (attr->ns == NULL) { |
| 5639 | if ((((topLevel == 0) && (!xmlStrEqual(attr->name, BAD_CAST "ref"))) || |
| 5640 | (topLevel && (!xmlStrEqual(attr->name, BAD_CAST "name")))) && |
| 5641 | (!xmlStrEqual(attr->name, BAD_CAST "id"))) |
| 5642 | { |
| 5643 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5644 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5645 | NULL, NULL, attr); |
| 5646 | } |
| 5647 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 5648 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5649 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5650 | NULL, NULL, attr); |
| 5651 | } |
| 5652 | attr = attr->next; |
| 5653 | } |
| 5654 | /* TODO: Validate "id" ? */ |
| 5655 | /* |
| 5656 | * And now for the children... |
| 5657 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5658 | oldcontainer = ctxt->container; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5659 | ctxt->container = name; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5660 | child = node->children; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5661 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 5662 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 5663 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5664 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5665 | if (topLevel) { |
| 5666 | child = xmlSchemaParseAttrDecls(ctxt, schema, child, (xmlSchemaTypePtr) ret); |
| 5667 | if (IS_SCHEMA(child, "anyAttribute")) { |
| 5668 | ret->attributeWildcard = xmlSchemaParseAnyAttribute(ctxt, schema, child); |
| 5669 | child = child->next; |
| 5670 | } |
| 5671 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5672 | if (child != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 5673 | xmlSchemaPContentErr(ctxt, |
| 5674 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 5675 | NULL, NULL, node, child, NULL, |
| 5676 | "(annotation?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5677 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5678 | ctxt->container = oldcontainer; |
| 5679 | return (ret); |
| 5680 | } |
| 5681 | |
| 5682 | /** |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5683 | * xmlSchemaPValAttrFormDefault: |
| 5684 | * @value: the value |
| 5685 | * @flags: the flags to be modified |
| 5686 | * @flagQualified: the specific flag for "qualified" |
| 5687 | * |
| 5688 | * Returns 0 if the value is valid, 1 otherwise. |
| 5689 | */ |
| 5690 | static int |
| 5691 | xmlSchemaPValAttrFormDefault(const xmlChar *value, |
| 5692 | int *flags, |
| 5693 | int flagQualified) |
| 5694 | { |
| 5695 | if (xmlStrEqual(value, BAD_CAST "qualified")) { |
| 5696 | if ((*flags & flagQualified) == 0) |
| 5697 | *flags |= flagQualified; |
| 5698 | } else if (!xmlStrEqual(value, BAD_CAST "unqualified")) |
| 5699 | return (1); |
| 5700 | |
| 5701 | return (0); |
| 5702 | } |
| 5703 | |
| 5704 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5705 | * xmlSchemaPValAttrBlockFinal: |
| 5706 | * @value: the value |
| 5707 | * @flags: the flags to be modified |
| 5708 | * @flagAll: the specific flag for "#all" |
| 5709 | * @flagExtension: the specific flag for "extension" |
| 5710 | * @flagRestriction: the specific flag for "restriction" |
| 5711 | * @flagSubstitution: the specific flag for "substitution" |
| 5712 | * @flagList: the specific flag for "list" |
| 5713 | * @flagUnion: the specific flag for "union" |
| 5714 | * |
| 5715 | * Validates the value of the attribute "final" and "block". The value |
| 5716 | * is converted into the specified flag values and returned in @flags. |
| 5717 | * |
| 5718 | * Returns 0 if the value is valid, 1 otherwise. |
| 5719 | */ |
| 5720 | |
| 5721 | static int |
| 5722 | xmlSchemaPValAttrBlockFinal(const xmlChar *value, |
| 5723 | int *flags, |
| 5724 | int flagAll, |
| 5725 | int flagExtension, |
| 5726 | int flagRestriction, |
| 5727 | int flagSubstitution, |
| 5728 | int flagList, |
| 5729 | int flagUnion) |
| 5730 | { |
| 5731 | int ret = 0; |
| 5732 | |
| 5733 | /* |
| 5734 | * TODO: This does not check for dublicate entries. |
| 5735 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 5736 | if (value == NULL) |
| 5737 | return (1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5738 | if (xmlStrEqual(value, BAD_CAST "#all")) { |
| 5739 | if (flagAll != -1) |
| 5740 | *flags |= flagAll; |
| 5741 | else { |
| 5742 | if (flagExtension != -1) |
| 5743 | *flags |= flagExtension; |
| 5744 | if (flagRestriction != -1) |
| 5745 | *flags |= flagRestriction; |
| 5746 | if (flagSubstitution != -1) |
| 5747 | *flags |= flagSubstitution; |
| 5748 | if (flagList != -1) |
| 5749 | *flags |= flagList; |
| 5750 | if (flagUnion != -1) |
| 5751 | *flags |= flagUnion; |
| 5752 | } |
| 5753 | } else { |
| 5754 | const xmlChar *end, *cur = value; |
| 5755 | xmlChar *item; |
| 5756 | |
| 5757 | do { |
| 5758 | while (IS_BLANK_CH(*cur)) |
| 5759 | cur++; |
| 5760 | end = cur; |
| 5761 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 5762 | end++; |
| 5763 | if (end == cur) |
| 5764 | break; |
| 5765 | item = xmlStrndup(cur, end - cur); |
| 5766 | if (xmlStrEqual(item, BAD_CAST "extension")) { |
| 5767 | if (flagExtension != -1) { |
| 5768 | if ((*flags & flagExtension) == 0) |
| 5769 | *flags |= flagExtension; |
| 5770 | } else |
| 5771 | ret = 1; |
| 5772 | } else if (xmlStrEqual(item, BAD_CAST "restriction")) { |
| 5773 | if (flagRestriction != -1) { |
| 5774 | if ((*flags & flagRestriction) == 0) |
| 5775 | *flags |= flagRestriction; |
| 5776 | } else |
| 5777 | ret = 1; |
| 5778 | } else if (xmlStrEqual(item, BAD_CAST "substitution")) { |
| 5779 | if (flagSubstitution != -1) { |
| 5780 | if ((*flags & flagSubstitution) == 0) |
| 5781 | *flags |= flagSubstitution; |
| 5782 | } else |
| 5783 | ret = 1; |
| 5784 | } else if (xmlStrEqual(item, BAD_CAST "list")) { |
| 5785 | if (flagList != -1) { |
| 5786 | if ((*flags & flagList) == 0) |
| 5787 | *flags |= flagList; |
| 5788 | } else |
| 5789 | ret = 1; |
| 5790 | } else if (xmlStrEqual(item, BAD_CAST "union")) { |
| 5791 | if (flagUnion != -1) { |
| 5792 | if ((*flags & flagUnion) == 0) |
| 5793 | *flags |= flagUnion; |
| 5794 | } else |
| 5795 | ret = 1; |
| 5796 | } else |
| 5797 | ret = 1; |
| 5798 | if (item != NULL) |
| 5799 | xmlFree(item); |
| 5800 | cur = end; |
| 5801 | } while ((ret == 0) && (*cur != 0)); |
| 5802 | } |
| 5803 | |
| 5804 | return (ret); |
| 5805 | } |
| 5806 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 5807 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 5808 | static int |
| 5809 | xmlSchemaCheckCSelectorXPath(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 5810 | xmlSchemaIDCPtr idc, |
| 5811 | xmlSchemaIDCSelectPtr selector, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 5812 | xmlAttrPtr attr, |
| 5813 | int isField) |
| 5814 | { |
| 5815 | xmlNodePtr node; |
| 5816 | |
| 5817 | /* |
| 5818 | * c-selector-xpath: |
| 5819 | * Schema Component Constraint: Selector Value OK |
| 5820 | * |
| 5821 | * TODO: 1 The {selector} must be a valid XPath expression, as defined |
| 5822 | * in [XPath]. |
| 5823 | */ |
| 5824 | if (selector == NULL) { |
| 5825 | xmlSchemaPErr(ctxt, idc->node, |
| 5826 | XML_SCHEMAP_INTERNAL, |
| 5827 | "Internal error: xmlSchemaCheckCSelectorXPath, " |
| 5828 | "the selector is not specified.\n", NULL, NULL); |
| 5829 | return (-1); |
| 5830 | } |
| 5831 | if (attr == NULL) |
| 5832 | node = idc->node; |
| 5833 | else |
| 5834 | node = (xmlNodePtr) attr; |
| 5835 | if (selector->xpath == NULL) { |
| 5836 | xmlSchemaPCustomErr(ctxt, |
| 5837 | /* TODO: Adjust error code. */ |
| 5838 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 5839 | NULL, NULL, node, |
| 5840 | "The XPath expression of the selector is not valid", NULL); |
| 5841 | return (XML_SCHEMAP_S4S_ATTR_INVALID_VALUE); |
| 5842 | } else { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 5843 | const xmlChar **nsArray = NULL; |
| 5844 | xmlNsPtr *nsList = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 5845 | /* |
| 5846 | * Compile the XPath expression. |
| 5847 | */ |
| 5848 | /* |
| 5849 | * TODO: We need the array of in-scope namespaces for compilation. |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 5850 | * TODO: Call xmlPatterncompile with different options for selector/ |
| 5851 | * field. |
| 5852 | */ |
| 5853 | nsList = xmlGetNsList(attr->doc, attr->parent); |
| 5854 | /* |
| 5855 | * Build an array of prefixes and namespaces. |
| 5856 | */ |
| 5857 | if (nsList != NULL) { |
| 5858 | int i, count = 0; |
| 5859 | xmlNsPtr ns; |
| 5860 | |
| 5861 | for (i = 0; nsList[i] != NULL; i++) |
| 5862 | count++; |
| 5863 | |
| 5864 | nsArray = (const xmlChar **) xmlMalloc( |
| 5865 | (count * 2 + 1) * sizeof(const xmlChar *)); |
| 5866 | if (nsArray == NULL) { |
| 5867 | xmlSchemaPErrMemory(ctxt, "allocating a namespace array", |
| 5868 | NULL); |
| 5869 | return (-1); |
| 5870 | } |
| 5871 | for (i = 0; i < count; i++) { |
| 5872 | ns = nsList[i]; |
| 5873 | nsArray[2 * i] = nsList[i]->href; |
| 5874 | nsArray[2 * i + 1] = nsList[i]->prefix; |
| 5875 | } |
| 5876 | nsArray[count * 2] = NULL; |
| 5877 | xmlFree(nsList); |
| 5878 | } |
| 5879 | if (isField) |
| 5880 | selector->xpathComp = (void *) xmlPatterncompile(selector->xpath, |
| 5881 | NULL, 0, nsArray); |
| 5882 | else |
| 5883 | selector->xpathComp = (void *) xmlPatterncompile(selector->xpath, |
| 5884 | NULL, 0, nsArray); |
| 5885 | if (nsArray != NULL) |
| 5886 | xmlFree((xmlChar **) nsArray); |
| 5887 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 5888 | #ifdef IDC_XPATH_SUPPORT |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 5889 | if (selector->xpathComp == NULL) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 5890 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 5891 | /* TODO: Adjust error code? */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 5892 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 5893 | NULL, NULL, node, |
| 5894 | "The XPath expression '%s' could not be " |
| 5895 | "compiled", selector->xpath); |
| 5896 | return (XML_SCHEMAP_S4S_ATTR_INVALID_VALUE); |
| 5897 | } |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 5898 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 5899 | } |
| 5900 | return (0); |
| 5901 | } |
| 5902 | |
| 5903 | /** |
| 5904 | * xmlSchemaAssignAnnotation: |
| 5905 | * @item: the schema component |
| 5906 | * @annot: the annotation |
| 5907 | * |
| 5908 | * Adds the annotation to the given schema component. |
| 5909 | * |
| 5910 | * Returns the given annotaion. |
| 5911 | */ |
| 5912 | static xmlSchemaAnnotPtr |
| 5913 | xmlSchemaAssignAnnotation(xmlSchemaBasicItemPtr item, |
| 5914 | xmlSchemaAnnotPtr annot) |
| 5915 | { |
| 5916 | xmlSchemaAnnotPtr cur = item->annot; |
| 5917 | |
| 5918 | if (item->annot == NULL) { |
| 5919 | item->annot = annot; |
| 5920 | return (annot); |
| 5921 | } |
| 5922 | cur = item->annot; |
| 5923 | if (cur->next != NULL) { |
| 5924 | cur = cur->next; |
| 5925 | } |
| 5926 | cur->next = annot; |
| 5927 | return (annot); |
| 5928 | } |
| 5929 | |
| 5930 | /** |
| 5931 | * xmlSchemaParseIDCSelectorAndField: |
| 5932 | * @ctxt: a schema validation context |
| 5933 | * @schema: the schema being built |
| 5934 | * @node: a subtree containing XML Schema informations |
| 5935 | * |
| 5936 | * Parses a XML Schema identity-contraint definition's |
| 5937 | * <selector> and <field> elements. |
| 5938 | * |
| 5939 | * Returns the parsed identity-constraint definition. |
| 5940 | */ |
| 5941 | static xmlSchemaIDCSelectPtr |
| 5942 | xmlSchemaParseIDCSelectorAndField(xmlSchemaParserCtxtPtr ctxt, |
| 5943 | xmlSchemaPtr schema, |
| 5944 | xmlSchemaIDCPtr idc, |
| 5945 | xmlNodePtr node, |
| 5946 | int isField) |
| 5947 | { |
| 5948 | xmlSchemaIDCSelectPtr item; |
| 5949 | xmlNodePtr child = NULL; |
| 5950 | xmlAttrPtr attr; |
| 5951 | |
| 5952 | /* |
| 5953 | * Check for illegal attributes. |
| 5954 | */ |
| 5955 | attr = node->properties; |
| 5956 | while (attr != NULL) { |
| 5957 | if (attr->ns == NULL) { |
| 5958 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 5959 | (!xmlStrEqual(attr->name, BAD_CAST "xpath"))) { |
| 5960 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5961 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5962 | NULL, NULL, attr); |
| 5963 | } |
| 5964 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 5965 | xmlSchemaPIllegalAttrErr(ctxt, |
| 5966 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 5967 | NULL, NULL, attr); |
| 5968 | } |
| 5969 | attr = attr->next; |
| 5970 | } |
| 5971 | /* |
| 5972 | * Create the item. |
| 5973 | */ |
| 5974 | item = (xmlSchemaIDCSelectPtr) xmlMalloc(sizeof(xmlSchemaIDCSelect)); |
| 5975 | if (item == NULL) { |
| 5976 | xmlSchemaPErrMemory(ctxt, |
| 5977 | "allocating a 'selector' of an identity-constraint definition", |
| 5978 | NULL); |
| 5979 | return (NULL); |
| 5980 | } |
| 5981 | memset(item, 0, sizeof(xmlSchemaIDCSelect)); |
| 5982 | /* |
| 5983 | * Attribute "xpath" (mandatory). |
| 5984 | */ |
| 5985 | attr = xmlSchemaGetPropNode(node, "xpath"); |
| 5986 | if (attr == NULL) { |
| 5987 | xmlSchemaPMissingAttrErr(ctxt, |
| 5988 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 5989 | NULL, NULL, node, |
| 5990 | "name", NULL); |
| 5991 | } else { |
| 5992 | item->xpath = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 5993 | /* |
| 5994 | * URGENT TODO: "field"s have an other syntax than "selector"s. |
| 5995 | */ |
| 5996 | |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 5997 | if (xmlSchemaCheckCSelectorXPath(ctxt, idc, item, attr, |
| 5998 | isField) == -1) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 5999 | xmlSchemaPErr(ctxt, |
| 6000 | (xmlNodePtr) attr, |
| 6001 | XML_SCHEMAP_INTERNAL, |
| 6002 | "Internal error: xmlSchemaParseIDCSelectorAndField, " |
| 6003 | "validating the XPath expression of a IDC selector.\n", |
| 6004 | NULL, NULL); |
| 6005 | } |
| 6006 | |
| 6007 | } |
| 6008 | /* |
| 6009 | * And now for the children... |
| 6010 | */ |
| 6011 | child = node->children; |
| 6012 | if (IS_SCHEMA(child, "annotation")) { |
| 6013 | /* |
| 6014 | * Add the annotation to the parent IDC. |
| 6015 | */ |
| 6016 | xmlSchemaAssignAnnotation((xmlSchemaBasicItemPtr) idc, |
| 6017 | xmlSchemaParseAnnotation(ctxt, schema, child)); |
| 6018 | child = child->next; |
| 6019 | } |
| 6020 | if (child != NULL) { |
| 6021 | xmlSchemaPContentErr(ctxt, |
| 6022 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 6023 | NULL, NULL, node, child, |
| 6024 | NULL, "(annotation?)"); |
| 6025 | } |
| 6026 | |
| 6027 | return (item); |
| 6028 | } |
| 6029 | |
| 6030 | /** |
| 6031 | * xmlSchemaParseIDC: |
| 6032 | * @ctxt: a schema validation context |
| 6033 | * @schema: the schema being built |
| 6034 | * @node: a subtree containing XML Schema informations |
| 6035 | * |
| 6036 | * Parses a XML Schema identity-contraint definition. |
| 6037 | * |
| 6038 | * Returns the parsed identity-constraint definition. |
| 6039 | */ |
| 6040 | static xmlSchemaIDCPtr |
| 6041 | xmlSchemaParseIDC(xmlSchemaParserCtxtPtr ctxt, |
| 6042 | xmlSchemaPtr schema, |
| 6043 | xmlNodePtr node, |
| 6044 | xmlSchemaTypeType idcCategory, |
| 6045 | const xmlChar *targetNamespace) |
| 6046 | { |
| 6047 | xmlSchemaIDCPtr item = NULL; |
| 6048 | xmlNodePtr child = NULL; |
| 6049 | xmlAttrPtr attr; |
| 6050 | const xmlChar *name = NULL; |
| 6051 | xmlSchemaIDCSelectPtr field = NULL, lastField = NULL; |
| 6052 | int resAdd; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 6053 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6054 | /* |
| 6055 | * Check for illegal attributes. |
| 6056 | */ |
| 6057 | attr = node->properties; |
| 6058 | while (attr != NULL) { |
| 6059 | if (attr->ns == NULL) { |
| 6060 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 6061 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
| 6062 | ((idcCategory != XML_SCHEMA_TYPE_IDC_KEYREF) || |
| 6063 | (!xmlStrEqual(attr->name, BAD_CAST "refer")))) { |
| 6064 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6065 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6066 | NULL, NULL, attr); |
| 6067 | } |
| 6068 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 6069 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6070 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6071 | NULL, NULL, attr); |
| 6072 | } |
| 6073 | attr = attr->next; |
| 6074 | } |
| 6075 | /* |
| 6076 | * Attribute "name" (mandatory). |
| 6077 | */ |
| 6078 | attr = xmlSchemaGetPropNode(node, "name"); |
| 6079 | if (attr == NULL) { |
| 6080 | xmlSchemaPMissingAttrErr(ctxt, |
| 6081 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 6082 | NULL, NULL, node, |
| 6083 | "name", NULL); |
| 6084 | return (NULL); |
| 6085 | } else if (xmlSchemaPValAttrNode(ctxt, |
| 6086 | NULL, NULL, attr, |
| 6087 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 6088 | return (NULL); |
| 6089 | } |
| 6090 | /* |
| 6091 | * Create the component. |
| 6092 | */ |
| 6093 | if (schema->idcDef == NULL) |
| 6094 | schema->idcDef = xmlHashCreateDict(10, ctxt->dict); |
| 6095 | if (schema->idcDef == NULL) |
| 6096 | return (NULL); |
| 6097 | |
| 6098 | item = (xmlSchemaIDCPtr) xmlMalloc(sizeof(xmlSchemaIDC)); |
| 6099 | if (item == NULL) { |
| 6100 | xmlSchemaPErrMemory(ctxt, |
| 6101 | "allocating an identity-constraint definition", NULL); |
| 6102 | return (NULL); |
| 6103 | } |
| 6104 | /* |
| 6105 | * Add the IDC to the list of IDCs on the schema component. |
| 6106 | */ |
| 6107 | resAdd = xmlHashAddEntry2(schema->idcDef, name, targetNamespace, item); |
| 6108 | if (resAdd != 0) { |
| 6109 | xmlSchemaPCustomErrExt(ctxt, |
| 6110 | XML_SCHEMAP_REDEFINED_TYPE, |
| 6111 | NULL, NULL, node, |
| 6112 | "An identity-constraint definition with the name '%s' " |
| 6113 | "and targetNamespace '%s' does already exist", |
| 6114 | name, targetNamespace, NULL); |
| 6115 | xmlFree(item); |
| 6116 | return (NULL); |
| 6117 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6118 | memset(item, 0, sizeof(xmlSchemaIDC)); |
| 6119 | item->name = name; |
| 6120 | item->type = idcCategory; |
| 6121 | item->node = node; |
| 6122 | /* |
| 6123 | * The target namespace of the parent element declaration. |
| 6124 | */ |
| 6125 | item->targetNamespace = targetNamespace; |
| 6126 | /* TODO: Handle attribute "id". */ |
| 6127 | if (idcCategory == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 6128 | /* |
| 6129 | * Attribute "refer" (mandatory). |
| 6130 | */ |
| 6131 | attr = xmlSchemaGetPropNode(node, "refer"); |
| 6132 | if (attr == NULL) { |
| 6133 | xmlSchemaPMissingAttrErr(ctxt, |
| 6134 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 6135 | NULL, NULL, node, |
| 6136 | "refer", NULL); |
| 6137 | } else { |
| 6138 | /* |
| 6139 | * Create a reference item. |
| 6140 | */ |
| 6141 | item->ref = (xmlSchemaItemQNRefPtr) xmlMalloc( |
| 6142 | sizeof(xmlSchemaItemQNRef)); |
| 6143 | if (item->ref == NULL) { |
| 6144 | xmlSchemaPErrMemory(ctxt, |
| 6145 | "allocating a QName reference item", NULL); |
| 6146 | return (NULL); |
| 6147 | } |
| 6148 | memset(item->ref, 0, sizeof(xmlSchemaItemQNRef)); |
| 6149 | xmlSchemaPValAttrNodeQName(ctxt, schema, |
| 6150 | NULL, NULL, attr, |
| 6151 | &(item->ref->targetNamespace), 0, |
| 6152 | &(item->ref->name)); |
| 6153 | } |
| 6154 | } |
| 6155 | /* |
| 6156 | * And now for the children... |
| 6157 | */ |
| 6158 | child = node->children; |
| 6159 | if (IS_SCHEMA(child, "annotation")) { |
| 6160 | item->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6161 | child = child->next; |
| 6162 | } |
| 6163 | /* |
| 6164 | * Child element <selector>. |
| 6165 | */ |
| 6166 | if (IS_SCHEMA(child, "selector")) { |
| 6167 | item->selector = xmlSchemaParseIDCSelectorAndField(ctxt, schema, |
| 6168 | item, child, 0); |
| 6169 | child = child->next; |
| 6170 | /* |
| 6171 | * Child elements <field>. |
| 6172 | */ |
| 6173 | if (IS_SCHEMA(child, "field")) { |
| 6174 | do { |
| 6175 | field = xmlSchemaParseIDCSelectorAndField(ctxt, schema, |
| 6176 | item, child, 1); |
| 6177 | if (field != NULL) { |
| 6178 | field->index = item->nbFields; |
| 6179 | item->nbFields++; |
| 6180 | if (lastField != NULL) |
| 6181 | lastField->next = field; |
| 6182 | else |
| 6183 | item->fields = field; |
| 6184 | lastField = field; |
| 6185 | } |
| 6186 | child = child->next; |
| 6187 | } while (IS_SCHEMA(child, "field")); |
| 6188 | } else { |
| 6189 | xmlSchemaPContentErr(ctxt, |
| 6190 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 6191 | NULL, NULL, node, child, |
| 6192 | NULL, "(annotation?, (selector, field+))"); |
| 6193 | } |
| 6194 | } |
| 6195 | if (child != NULL) { |
| 6196 | xmlSchemaPContentErr(ctxt, |
| 6197 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 6198 | NULL, NULL, node, child, |
| 6199 | NULL, "(annotation?, (selector, field+))"); |
| 6200 | } |
| 6201 | |
| 6202 | return (item); |
| 6203 | } |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 6204 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6205 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6206 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6207 | * xmlSchemaParseElement: |
| 6208 | * @ctxt: a schema validation context |
| 6209 | * @schema: the schema being built |
| 6210 | * @node: a subtree containing XML Schema informations |
| 6211 | * |
| 6212 | * parse a XML schema Element declaration |
| 6213 | * *WARNING* this interface is highly subject to change |
| 6214 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6215 | * Returns the parsed element declaration. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6216 | */ |
| 6217 | static xmlSchemaElementPtr |
| 6218 | xmlSchemaParseElement(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6219 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6220 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6221 | const xmlChar *name = NULL; |
| 6222 | const xmlChar *attrValue; |
| 6223 | xmlChar *repName = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6224 | xmlSchemaElementPtr ret; |
| 6225 | xmlNodePtr child = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6226 | const xmlChar *oldcontainer; |
| 6227 | xmlAttrPtr attr, nameAttr; |
| 6228 | int minOccurs, maxOccurs; |
| 6229 | int isRef = 0; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6230 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 6231 | xmlSchemaIDCPtr curIDC = NULL, lastIDC = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6232 | #endif |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6233 | |
| 6234 | /* 3.3.3 Constraints on XML Representations of Element Declarations */ |
| 6235 | /* TODO: Complete implementation of 3.3.6 */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6236 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6237 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 6238 | return (NULL); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 6239 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6240 | oldcontainer = ctxt->container; |
| 6241 | |
| 6242 | nameAttr = xmlSchemaGetPropNode(node, "name"); |
| 6243 | attr = xmlSchemaGetPropNode(node, "ref"); |
| 6244 | if ((topLevel) || (attr == NULL)) { |
| 6245 | if (nameAttr == NULL) { |
| 6246 | xmlSchemaPMissingAttrErr(ctxt, |
| 6247 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 6248 | (xmlChar **) &xmlSchemaElemDesElemDecl, NULL, node, |
| 6249 | "name", NULL); |
| 6250 | return (NULL); |
| 6251 | } |
| 6252 | name = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) nameAttr); |
| 6253 | } else { |
| 6254 | isRef = 1; |
| 6255 | |
| 6256 | } |
| 6257 | /* |
| 6258 | * ... unless minOccurs=maxOccurs=0, in which case the item corresponds |
| 6259 | * to no component at all |
| 6260 | * TODO: It might be better to validate the element, even if it won't be |
| 6261 | * used. |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6262 | */ |
| 6263 | minOccurs = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "nonNegativeInteger"); |
| 6264 | maxOccurs = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, "(nonNegativeInteger | unbounded)"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6265 | if ((minOccurs == 0) && (maxOccurs == 0)) |
| 6266 | return (NULL); |
| 6267 | /* |
| 6268 | * If we get a "ref" attribute on a local <element> we will assume it's |
| 6269 | * a reference - even if there's a "name" attribute; this seems to be more |
| 6270 | * robust. |
| 6271 | */ |
| 6272 | if (isRef) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 6273 | char buf[50]; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6274 | const xmlChar *refNs = NULL, *ref = NULL, *refPrefix; |
| 6275 | |
| 6276 | /* |
| 6277 | * Parse as a particle. |
| 6278 | */ |
| 6279 | xmlSchemaPValAttrNodeQName(ctxt, schema, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6280 | (xmlChar **) &xmlSchemaElemDesElemRef, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6281 | NULL, attr, &refNs, &refPrefix, &ref); |
| 6282 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 6283 | snprintf(buf, 49, "#eRef%d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 6284 | ret = xmlSchemaAddElement(ctxt, schema, (const xmlChar *) buf, NULL, node, 0); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6285 | if (ret == NULL) { |
| 6286 | if (repName != NULL) |
| 6287 | xmlFree(repName); |
| 6288 | return (NULL); |
| 6289 | } |
| 6290 | ret->type = XML_SCHEMA_TYPE_ELEMENT; |
| 6291 | ret->node = node; |
| 6292 | ret->ref = ref; |
| 6293 | ret->refNs = refNs; |
| 6294 | ret->refPrefix = refPrefix; |
| 6295 | ret->flags |= XML_SCHEMAS_ELEM_REF; |
| 6296 | /* |
| 6297 | * Check for illegal attributes. |
| 6298 | */ |
| 6299 | /* |
| 6300 | * 3.3.3 : 2.1 |
| 6301 | * One of ref or name must be present, but not both |
| 6302 | */ |
| 6303 | if (nameAttr != NULL) { |
| 6304 | xmlSchemaPMutualExclAttrErr(ctxt, |
| 6305 | XML_SCHEMAP_SRC_ELEMENT_2_1, |
| 6306 | &repName, (xmlSchemaTypePtr) ret, nameAttr, |
| 6307 | "ref", "name"); |
| 6308 | } |
| 6309 | /* 3.3.3 : 2.2 */ |
| 6310 | attr = node->properties; |
| 6311 | while (attr != NULL) { |
| 6312 | if (attr->ns == NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6313 | if (xmlStrEqual(attr->name, BAD_CAST "ref") || |
| 6314 | xmlStrEqual(attr->name, BAD_CAST "name") || |
| 6315 | xmlStrEqual(attr->name, BAD_CAST "id") || |
| 6316 | xmlStrEqual(attr->name, BAD_CAST "maxOccurs") || |
| 6317 | xmlStrEqual(attr->name, BAD_CAST "minOccurs")) |
| 6318 | { |
| 6319 | attr = attr->next; |
| 6320 | continue; |
| 6321 | } else { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6322 | xmlSchemaPCustomAttrErr(ctxt, |
| 6323 | XML_SCHEMAP_SRC_ELEMENT_2_2, |
| 6324 | &repName, (xmlSchemaTypePtr) ret, attr, |
| 6325 | "Only the attributes 'minOccurs', 'maxOccurs' and " |
| 6326 | "'id' are allowed in addition to 'ref'"); |
| 6327 | break; |
| 6328 | } |
| 6329 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 6330 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6331 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6332 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 6333 | } |
| 6334 | attr = attr->next; |
| 6335 | } |
| 6336 | } else { |
| 6337 | const xmlChar *ns = NULL, *fixed; |
| 6338 | |
| 6339 | /* |
| 6340 | * Parse as an element declaration. |
| 6341 | */ |
| 6342 | if (xmlSchemaPValAttrNode(ctxt, |
| 6343 | (xmlChar **) &xmlSchemaElemDesElemDecl, NULL, nameAttr, |
| 6344 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) |
| 6345 | return (NULL); |
| 6346 | /* |
| 6347 | * Evaluate the target namespace. |
| 6348 | */ |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6349 | if (topLevel) { |
| 6350 | ns = schema->targetNamespace; |
| 6351 | } else { |
| 6352 | attr = xmlSchemaGetPropNode(node, "form"); |
| 6353 | if (attr != NULL) { |
| 6354 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 6355 | if (xmlStrEqual(attrValue, BAD_CAST "qualified")) { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6356 | ns = schema->targetNamespace; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6357 | } else if (!xmlStrEqual(attrValue, BAD_CAST "unqualified")) { |
| 6358 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6359 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 6360 | &repName, NULL, (xmlNodePtr) attr, |
| 6361 | NULL, "(qualified | unqualified)", |
| 6362 | attrValue, NULL, NULL, NULL); |
| 6363 | } |
| 6364 | } else if (schema->flags & XML_SCHEMAS_QUALIF_ELEM) |
| 6365 | ns = schema->targetNamespace; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6366 | } |
| 6367 | ret = xmlSchemaAddElement(ctxt, schema, name, ns, node, topLevel); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6368 | if (ret == NULL) { |
| 6369 | if (repName != NULL) |
| 6370 | xmlFree(repName); |
| 6371 | return (NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6372 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6373 | ret->type = XML_SCHEMA_TYPE_ELEMENT; |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 6374 | ret->node = node; |
| 6375 | ret->targetNamespace = ns; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6376 | /* |
| 6377 | * Check for illegal attributes. |
| 6378 | */ |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6379 | attr = node->properties; |
| 6380 | while (attr != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6381 | if (attr->ns == NULL) { |
| 6382 | if ((!xmlStrEqual(attr->name, BAD_CAST "name")) && |
| 6383 | (!xmlStrEqual(attr->name, BAD_CAST "type")) && |
| 6384 | (!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 6385 | (!xmlStrEqual(attr->name, BAD_CAST "default")) && |
| 6386 | (!xmlStrEqual(attr->name, BAD_CAST "fixed")) && |
| 6387 | (!xmlStrEqual(attr->name, BAD_CAST "block")) && |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6388 | (!xmlStrEqual(attr->name, BAD_CAST "nillable"))) |
| 6389 | { |
| 6390 | if (topLevel == 0) { |
| 6391 | if ((!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) && |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6392 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) && |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6393 | (!xmlStrEqual(attr->name, BAD_CAST "form"))) |
| 6394 | { |
| 6395 | if (xmlStrEqual(attr->name, BAD_CAST "substitutionGroup")) { |
| 6396 | /* |
| 6397 | * 3.3.6 : 3 If there is a non-·absent· {substitution |
| 6398 | * group affiliation}, then {scope} must be global. |
| 6399 | * TODO: This one is redundant, since the S4S does |
| 6400 | * prohibit this attribute on local declarations already; |
| 6401 | * so why an explicit error code? Weird spec. |
| 6402 | * TODO: Move this to the proper constraint layer. |
| 6403 | * TODO: Or better wait for spec 1.1 to come. |
| 6404 | */ |
| 6405 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6406 | XML_SCHEMAP_E_PROPS_CORRECT_3, |
| 6407 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 6408 | } else { |
| 6409 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6410 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6411 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 6412 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6413 | } |
| 6414 | } else if ((!xmlStrEqual(attr->name, BAD_CAST "final")) && |
| 6415 | (!xmlStrEqual(attr->name, BAD_CAST "abstract")) && |
| 6416 | (!xmlStrEqual(attr->name, BAD_CAST "substitutionGroup"))) { |
| 6417 | |
| 6418 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6419 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6420 | &repName, (xmlSchemaTypePtr) ret, attr); |
| 6421 | } |
| 6422 | } |
| 6423 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 6424 | |
| 6425 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6426 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6427 | &repName, (xmlSchemaTypePtr) ret, attr); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6428 | } |
| 6429 | attr = attr->next; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6430 | } |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6431 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6432 | * Extract/validate attributes. |
| 6433 | */ |
| 6434 | if (topLevel) { |
| 6435 | /* |
| 6436 | * Process top attributes of global element declarations here. |
| 6437 | */ |
| 6438 | ret->flags |= XML_SCHEMAS_ELEM_GLOBAL; |
| 6439 | ret->flags |= XML_SCHEMAS_ELEM_TOPLEVEL; |
| 6440 | xmlSchemaPValAttrQName(ctxt, schema, &repName, |
| 6441 | (xmlSchemaTypePtr) ret, node, "substitutionGroup", |
| 6442 | &(ret->substGroupNs), NULL, &(ret->substGroup)); |
| 6443 | if (xmlGetBooleanProp(ctxt, &repName, (xmlSchemaTypePtr) ret, |
| 6444 | node, "abstract", 0)) |
| 6445 | ret->flags |= XML_SCHEMAS_ELEM_ABSTRACT; |
| 6446 | /* |
| 6447 | * Attribute "final". |
| 6448 | */ |
| 6449 | attr = xmlSchemaGetPropNode(node, "final"); |
| 6450 | if (attr == NULL) { |
| 6451 | ret->flags |= XML_SCHEMAS_ELEM_FINAL_ABSENT; |
| 6452 | } else { |
| 6453 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 6454 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(ret->flags), |
| 6455 | -1, |
| 6456 | XML_SCHEMAS_ELEM_FINAL_EXTENSION, |
| 6457 | XML_SCHEMAS_ELEM_FINAL_RESTRICTION, -1, -1, -1) != 0) { |
| 6458 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6459 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 6460 | &repName, (xmlSchemaTypePtr) ret, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6461 | NULL, "(#all | List of (extension | restriction))", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6462 | attrValue, NULL, NULL, NULL); |
| 6463 | } |
| 6464 | } |
| 6465 | } |
| 6466 | /* |
| 6467 | * Attribute "block". |
| 6468 | */ |
| 6469 | attr = xmlSchemaGetPropNode(node, "block"); |
| 6470 | if (attr == NULL) { |
| 6471 | ret->flags |= XML_SCHEMAS_ELEM_BLOCK_ABSENT; |
| 6472 | } else { |
| 6473 | attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 6474 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(ret->flags), |
| 6475 | -1, |
| 6476 | XML_SCHEMAS_ELEM_BLOCK_EXTENSION, |
| 6477 | XML_SCHEMAS_ELEM_BLOCK_RESTRICTION, |
| 6478 | XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION, -1, -1) != 0) { |
| 6479 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6480 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 6481 | &repName, (xmlSchemaTypePtr) ret, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6482 | NULL, "(#all | List of (extension | " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6483 | "restriction | substitution))", attrValue, |
| 6484 | NULL, NULL, NULL); |
| 6485 | } |
| 6486 | } |
| 6487 | if (xmlGetBooleanProp(ctxt, &repName, (xmlSchemaTypePtr) ret, |
| 6488 | node, "nillable", 0)) |
| 6489 | ret->flags |= XML_SCHEMAS_ELEM_NILLABLE; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6490 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6491 | xmlSchemaPValAttrQName(ctxt, schema, |
| 6492 | &repName, (xmlSchemaTypePtr) ret, node, |
| 6493 | "type", &(ret->namedTypeNs), NULL, &(ret->namedType)); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6494 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6495 | ret->value = xmlSchemaGetProp(ctxt, node, "default"); |
| 6496 | attr = xmlSchemaGetPropNode(node, "fixed"); |
| 6497 | if (attr != NULL) { |
| 6498 | fixed = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 6499 | if (ret->value != NULL) { |
| 6500 | /* |
| 6501 | * 3.3.3 : 1 |
| 6502 | * default and fixed must not both be present. |
| 6503 | */ |
| 6504 | xmlSchemaPMutualExclAttrErr(ctxt, |
| 6505 | XML_SCHEMAP_SRC_ELEMENT_1, |
| 6506 | &repName, (xmlSchemaTypePtr) ret, attr, |
| 6507 | "default", "fixed"); |
| 6508 | } else { |
| 6509 | ret->flags |= XML_SCHEMAS_ELEM_FIXED; |
| 6510 | ret->value = fixed; |
| 6511 | } |
| 6512 | } |
| 6513 | } |
| 6514 | /* |
| 6515 | * Extract/validate common attributes. |
| 6516 | */ |
| 6517 | /* TODO: Check ID: */ |
| 6518 | ret->id = xmlSchemaGetProp(ctxt, node, "id"); |
| 6519 | ret->minOccurs = minOccurs; |
| 6520 | ret->maxOccurs = maxOccurs; |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 6521 | if (topLevel != 1) |
| 6522 | xmlSchemaPCheckParticleCorrect_2(ctxt, (xmlSchemaTypePtr) ret, |
| 6523 | node, minOccurs, maxOccurs); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6524 | /* |
| 6525 | * And now for the children... |
| 6526 | */ |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 6527 | ctxt->container = ret->name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6528 | child = node->children; |
| 6529 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6530 | ret->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6531 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6532 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6533 | if (isRef) { |
| 6534 | if (child != NULL) { |
| 6535 | xmlSchemaPContentErr(ctxt, |
| 6536 | XML_SCHEMAP_SRC_ELEMENT_2_2, |
| 6537 | &repName, (xmlSchemaTypePtr) ret, node, child, |
| 6538 | NULL, "(annotation?)"); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6539 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6540 | } else { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6541 | if (IS_SCHEMA(child, "complexType")) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6542 | /* |
| 6543 | * 3.3.3 : 3 |
| 6544 | * "type" and either <simpleType> or <complexType> are mutually |
| 6545 | * exclusive |
| 6546 | */ |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6547 | if (ret->namedType != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6548 | xmlSchemaPContentErr(ctxt, |
| 6549 | XML_SCHEMAP_SRC_ELEMENT_3, |
| 6550 | &repName, (xmlSchemaTypePtr) ret, node, child, |
| 6551 | "The attribute 'type' and the <complexType> child are " |
| 6552 | "mutually exclusive", NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6553 | } else |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6554 | ret->subtypes = xmlSchemaParseComplexType(ctxt, schema, child, 0); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6555 | child = child->next; |
| 6556 | } else if (IS_SCHEMA(child, "simpleType")) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6557 | /* |
| 6558 | * 3.3.3 : 3 |
| 6559 | * "type" and either <simpleType> or <complexType> are |
| 6560 | * mutually exclusive |
| 6561 | */ |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6562 | if (ret->namedType != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6563 | xmlSchemaPContentErr(ctxt, |
| 6564 | XML_SCHEMAP_SRC_ELEMENT_3, |
| 6565 | &repName, (xmlSchemaTypePtr) ret, node, child, |
| 6566 | "The attribute 'type' and the <simpleType> child are " |
| 6567 | "mutually exclusive", NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6568 | } else |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6569 | ret->subtypes = xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6570 | child = child->next; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6571 | } |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6572 | while ((IS_SCHEMA(child, "unique")) || |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6573 | (IS_SCHEMA(child, "key")) || (IS_SCHEMA(child, "keyref"))) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6574 | #ifdef IDC_ENABLED |
| 6575 | if (IS_SCHEMA(child, "unique")) { |
| 6576 | curIDC = xmlSchemaParseIDC(ctxt, schema, child, |
| 6577 | XML_SCHEMA_TYPE_IDC_UNIQUE, ret->targetNamespace); |
| 6578 | } else if (IS_SCHEMA(child, "key")) { |
| 6579 | curIDC = xmlSchemaParseIDC(ctxt, schema, child, |
| 6580 | XML_SCHEMA_TYPE_IDC_KEY, ret->targetNamespace); |
| 6581 | } else if (IS_SCHEMA(child, "keyref")) { |
| 6582 | curIDC = xmlSchemaParseIDC(ctxt, schema, child, |
| 6583 | XML_SCHEMA_TYPE_IDC_KEYREF, ret->targetNamespace); |
| 6584 | } |
| 6585 | if (lastIDC != NULL) |
| 6586 | lastIDC->next = curIDC; |
| 6587 | else |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 6588 | ret->idcs = (void *) curIDC; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6589 | lastIDC = curIDC; |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 6590 | #else |
| 6591 | TODO |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 6592 | #endif |
| 6593 | child = child->next; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6594 | } |
| 6595 | if (child != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6596 | xmlSchemaPContentErr(ctxt, |
| 6597 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 6598 | &repName, (xmlSchemaTypePtr) ret, node, child, |
| 6599 | NULL, "(annotation?, ((simpleType | complexType)?, " |
| 6600 | "(unique | key | keyref)*))"); |
| 6601 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6602 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6603 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6604 | ctxt->container = oldcontainer; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6605 | /* |
| 6606 | * Cleanup. |
| 6607 | */ |
| 6608 | if (repName != NULL) |
| 6609 | xmlFree(repName); |
| 6610 | /* |
| 6611 | * NOTE: Element Declaration Representation OK 4. will be checked at a |
| 6612 | * different layer. |
| 6613 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6614 | return (ret); |
| 6615 | } |
| 6616 | |
| 6617 | /** |
| 6618 | * xmlSchemaParseUnion: |
| 6619 | * @ctxt: a schema validation context |
| 6620 | * @schema: the schema being built |
| 6621 | * @node: a subtree containing XML Schema informations |
| 6622 | * |
| 6623 | * parse a XML schema Union definition |
| 6624 | * *WARNING* this interface is highly subject to change |
| 6625 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6626 | * 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] | 6627 | * 1 in case of success. |
| 6628 | */ |
| 6629 | static xmlSchemaTypePtr |
| 6630 | xmlSchemaParseUnion(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6631 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6632 | { |
| 6633 | xmlSchemaTypePtr type, subtype, last = NULL; |
| 6634 | xmlNodePtr child = NULL; |
| 6635 | xmlChar name[30]; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6636 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6637 | |
| 6638 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 6639 | return (NULL); |
| 6640 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 6641 | snprintf((char *) name, 30, "#union%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6642 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6643 | if (type == NULL) |
| 6644 | return (NULL); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 6645 | type->type = XML_SCHEMA_TYPE_UNION; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6646 | type->node = node; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6647 | /* |
| 6648 | * Check for illegal attributes. |
| 6649 | */ |
| 6650 | attr = node->properties; |
| 6651 | while (attr != NULL) { |
| 6652 | if (attr->ns == NULL) { |
| 6653 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 6654 | (!xmlStrEqual(attr->name, BAD_CAST "memberTypes"))) { |
| 6655 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6656 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6657 | NULL, type, attr); |
| 6658 | } |
| 6659 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 6660 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6661 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6662 | NULL, type, attr); |
| 6663 | } |
| 6664 | attr = attr->next; |
| 6665 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 6666 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6667 | /* |
| 6668 | * Attribute "memberTypes". This is a list of QNames. |
| 6669 | * TODO: Validate the QNames. |
| 6670 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 6671 | type->base = xmlSchemaGetProp(ctxt, node, "memberTypes"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6672 | /* |
| 6673 | * And now for the children... |
| 6674 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6675 | child = node->children; |
| 6676 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6677 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6678 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6679 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6680 | while (IS_SCHEMA(child, "simpleType")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6681 | subtype = (xmlSchemaTypePtr) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6682 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6683 | if (subtype != NULL) { |
| 6684 | if (last == NULL) { |
| 6685 | type->subtypes = subtype; |
| 6686 | last = subtype; |
| 6687 | } else { |
| 6688 | last->next = subtype; |
| 6689 | last = subtype; |
| 6690 | } |
| 6691 | last->next = NULL; |
| 6692 | } |
| 6693 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6694 | } |
| 6695 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6696 | /* TODO: Think about the error code. */ |
| 6697 | xmlSchemaPContentErr(ctxt, |
| 6698 | XML_SCHEMAP_UNKNOWN_UNION_CHILD, |
| 6699 | NULL, type, node, child, NULL, "(annotation?, simpleType*)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6700 | } |
| 6701 | return (type); |
| 6702 | } |
| 6703 | |
| 6704 | /** |
| 6705 | * xmlSchemaParseList: |
| 6706 | * @ctxt: a schema validation context |
| 6707 | * @schema: the schema being built |
| 6708 | * @node: a subtree containing XML Schema informations |
| 6709 | * |
| 6710 | * parse a XML schema List definition |
| 6711 | * *WARNING* this interface is highly subject to change |
| 6712 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6713 | * 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] | 6714 | * 1 in case of success. |
| 6715 | */ |
| 6716 | static xmlSchemaTypePtr |
| 6717 | xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6718 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6719 | { |
| 6720 | xmlSchemaTypePtr type, subtype; |
| 6721 | xmlNodePtr child = NULL; |
| 6722 | xmlChar name[30]; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6723 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6724 | |
| 6725 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 6726 | return (NULL); |
| 6727 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 6728 | snprintf((char *) name, 30, "#list%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6729 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6730 | if (type == NULL) |
| 6731 | return (NULL); |
| 6732 | type->node = node; |
| 6733 | type->type = XML_SCHEMA_TYPE_LIST; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 6734 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6735 | /* |
| 6736 | * Check for illegal attributes. |
| 6737 | */ |
| 6738 | attr = node->properties; |
| 6739 | while (attr != NULL) { |
| 6740 | if (attr->ns == NULL) { |
| 6741 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 6742 | (!xmlStrEqual(attr->name, BAD_CAST "itemType"))) { |
| 6743 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6744 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6745 | NULL, type, attr); |
| 6746 | } |
| 6747 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 6748 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6749 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 6750 | NULL, type, attr); |
| 6751 | } |
| 6752 | attr = attr->next; |
| 6753 | } |
| 6754 | /* |
| 6755 | * Attribute "itemType". |
| 6756 | */ |
| 6757 | xmlSchemaPValAttrQName(ctxt, schema, NULL, NULL, |
| 6758 | node, "itemType", &(type->baseNs), NULL, &(type->base)); |
| 6759 | /* |
| 6760 | * And now for the children... |
| 6761 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6762 | child = node->children; |
| 6763 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6764 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6765 | child = child->next; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6766 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6767 | subtype = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6768 | if (IS_SCHEMA(child, "simpleType")) { |
| 6769 | if (type->base != NULL) { |
| 6770 | xmlSchemaPCustomErr(ctxt, |
| 6771 | XML_SCHEMAP_SRC_SIMPLE_TYPE_1, |
| 6772 | NULL, type, node, |
| 6773 | "The attribute 'itemType' and the <simpleType> child " |
| 6774 | "are mutually exclusive", NULL); |
| 6775 | } else { |
| 6776 | subtype = (xmlSchemaTypePtr) |
| 6777 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
| 6778 | type->subtypes = subtype; |
| 6779 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 6780 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6781 | } |
| 6782 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6783 | /* TODO: Think about the error code. */ |
| 6784 | xmlSchemaPContentErr(ctxt, |
| 6785 | XML_SCHEMAP_UNKNOWN_LIST_CHILD, |
| 6786 | NULL, type, node, child, NULL, "(annotation?, simpleType?)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6787 | } |
| 6788 | return (type); |
| 6789 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6790 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6791 | /** |
| 6792 | * xmlSchemaParseSimpleType: |
| 6793 | * @ctxt: a schema validation context |
| 6794 | * @schema: the schema being built |
| 6795 | * @node: a subtree containing XML Schema informations |
| 6796 | * |
| 6797 | * parse a XML schema Simple Type definition |
| 6798 | * *WARNING* this interface is highly subject to change |
| 6799 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6800 | * 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] | 6801 | * 1 in case of success. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6802 | */ |
| 6803 | static xmlSchemaTypePtr |
| 6804 | xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6805 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6806 | { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6807 | xmlSchemaTypePtr type, subtype, oldCtxtType, oldParentItem; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6808 | xmlNodePtr child = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6809 | const xmlChar *attrValue = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6810 | xmlChar *des = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6811 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6812 | |
| 6813 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 6814 | return (NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6815 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6816 | if (topLevel) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6817 | attr = xmlSchemaGetPropNode(node, "name"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6818 | if (attr == NULL) { |
| 6819 | xmlSchemaPMissingAttrErr(ctxt, |
| 6820 | XML_SCHEMAP_S4S_ATTR_MISSING, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6821 | (xmlChar **) &xmlSchemaElemDesST, NULL, node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6822 | "name", NULL); |
| 6823 | return (NULL); |
| 6824 | } else if (xmlSchemaPValAttrNode(ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6825 | (xmlChar **) &xmlSchemaElemDesST, NULL, attr, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6826 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &attrValue) != 0) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 6827 | return (NULL); |
| 6828 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6829 | } |
| 6830 | |
| 6831 | if (topLevel == 0) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6832 | char buf[40]; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6833 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 6834 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6835 | * Parse as local simple type definition. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 6836 | */ |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 6837 | snprintf(buf, 39, "#ST%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6838 | type = xmlSchemaAddType(ctxt, schema, (const xmlChar *)buf, NULL, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6839 | if (type == NULL) |
| 6840 | return (NULL); |
| 6841 | type->node = node; |
| 6842 | type->type = XML_SCHEMA_TYPE_SIMPLE; |
| 6843 | /* |
| 6844 | * Check for illegal attributes. |
| 6845 | */ |
| 6846 | attr = node->properties; |
| 6847 | while (attr != NULL) { |
| 6848 | if (attr->ns == NULL) { |
| 6849 | if (!xmlStrEqual(attr->name, BAD_CAST "id")) { |
| 6850 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6851 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6852 | &des, type, attr); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 6853 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6854 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 6855 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6856 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6857 | &des, type, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6858 | } |
| 6859 | attr = attr->next; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 6860 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6861 | } else { |
| 6862 | /* |
| 6863 | * Parse as global simple type definition. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6864 | * |
| 6865 | * Note that attrValue is the value of the attribute "name" here. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6866 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6867 | type = xmlSchemaAddType(ctxt, schema, attrValue, schema->targetNamespace, node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6868 | if (type == NULL) |
| 6869 | return (NULL); |
| 6870 | type->node = node; |
| 6871 | type->type = XML_SCHEMA_TYPE_SIMPLE; |
| 6872 | type->flags |= XML_SCHEMAS_TYPE_GLOBAL; |
| 6873 | /* |
| 6874 | * Check for illegal attributes. |
| 6875 | */ |
| 6876 | attr = node->properties; |
| 6877 | while (attr != NULL) { |
| 6878 | if (attr->ns == NULL) { |
| 6879 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 6880 | (!xmlStrEqual(attr->name, BAD_CAST "name")) && |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6881 | (!xmlStrEqual(attr->name, BAD_CAST "final"))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6882 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6883 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6884 | &des, type, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6885 | } |
| 6886 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 6887 | xmlSchemaPIllegalAttrErr(ctxt, |
| 6888 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6889 | &des, type, attr); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6890 | } |
| 6891 | attr = attr->next; |
| 6892 | } |
| 6893 | /* |
| 6894 | * Attribute "final". |
| 6895 | */ |
| 6896 | attr = xmlSchemaGetPropNode(node, "final"); |
| 6897 | if (attr == NULL) { |
| 6898 | type->flags |= XML_SCHEMAS_TYPE_FINAL_DEFAULT; |
| 6899 | } else { |
| 6900 | attrValue = xmlSchemaGetProp(ctxt, node, "final"); |
| 6901 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(type->flags), |
| 6902 | -1, -1, XML_SCHEMAS_TYPE_FINAL_RESTRICTION, -1, |
| 6903 | XML_SCHEMAS_TYPE_FINAL_LIST, |
| 6904 | XML_SCHEMAS_TYPE_FINAL_UNION) != 0) { |
| 6905 | |
| 6906 | xmlSchemaPSimpleTypeErr(ctxt, |
| 6907 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6908 | &des, type, (xmlNodePtr) attr, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 6909 | NULL, "(#all | List of (list | union | restriction)", |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6910 | attrValue, NULL, NULL, NULL); |
| 6911 | } |
| 6912 | } |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 6913 | } |
| 6914 | type->targetNamespace = schema->targetNamespace; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6915 | /* TODO: Check id. */ |
| 6916 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
| 6917 | /* |
| 6918 | * And now for the children... |
| 6919 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6920 | oldCtxtType = ctxt->ctxtType; |
| 6921 | oldParentItem = ctxt->parentItem; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6922 | ctxt->ctxtType = type; |
| 6923 | ctxt->parentItem = type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6924 | child = node->children; |
| 6925 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6926 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 6927 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6928 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6929 | subtype = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6930 | if (IS_SCHEMA(child, "restriction")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6931 | subtype = (xmlSchemaTypePtr) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 6932 | xmlSchemaParseRestriction(ctxt, schema, child); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6933 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6934 | } else if (IS_SCHEMA(child, "list")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6935 | subtype = (xmlSchemaTypePtr) |
| 6936 | xmlSchemaParseList(ctxt, schema, child); |
| 6937 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6938 | } else if (IS_SCHEMA(child, "union")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6939 | subtype = (xmlSchemaTypePtr) |
| 6940 | xmlSchemaParseUnion(ctxt, schema, child); |
| 6941 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6942 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6943 | type->subtypes = subtype; |
| 6944 | if ((child != NULL) || (subtype == NULL)) { |
| 6945 | xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6946 | &des, type, node, child, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6947 | "(annotation?, (restriction | list | union))"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6948 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 6949 | ctxt->parentItem = oldParentItem; |
| 6950 | ctxt->ctxtType = oldCtxtType; |
| 6951 | FREE_AND_NULL(des) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 6952 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6953 | return (type); |
| 6954 | } |
| 6955 | |
| 6956 | |
| 6957 | /** |
| 6958 | * xmlSchemaParseGroup: |
| 6959 | * @ctxt: a schema validation context |
| 6960 | * @schema: the schema being built |
| 6961 | * @node: a subtree containing XML Schema informations |
| 6962 | * |
| 6963 | * parse a XML schema Group definition |
| 6964 | * *WARNING* this interface is highly subject to change |
| 6965 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 6966 | * 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] | 6967 | * 1 in case of success. |
| 6968 | */ |
| 6969 | static xmlSchemaTypePtr |
| 6970 | xmlSchemaParseGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 6971 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6972 | { |
| 6973 | xmlSchemaTypePtr type, subtype; |
| 6974 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 6975 | const xmlChar *name, *ns = NULL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 6976 | const xmlChar *ref = NULL, *refNs = NULL; |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 6977 | char buf[50]; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 6978 | int minOccurs, maxOccurs; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6979 | |
| 6980 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 6981 | return (NULL); |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 6982 | /* |
| 6983 | * TODO: Validate the element even if no item is created |
| 6984 | * (i.e. min/maxOccurs == 0). |
| 6985 | */ |
| 6986 | minOccurs = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "nonNegativeInteger"); |
| 6987 | maxOccurs = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, "(nonNegativeInteger | unbounded)"); |
| 6988 | if ((minOccurs == 0) && (maxOccurs == 0)) { |
| 6989 | return (NULL); |
| 6990 | } |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 6991 | if (topLevel) |
| 6992 | ns = schema->targetNamespace; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 6993 | name = xmlSchemaGetProp(ctxt, node, "name"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 6994 | if (name == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 6995 | ref = xmlGetQNameProp(ctxt, node, "ref", &refNs); |
| 6996 | if (ref == NULL) { |
| 6997 | xmlSchemaPErr2(ctxt, node, child, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 6998 | XML_SCHEMAP_GROUP_NONAME_NOREF, |
| 6999 | "Group definition or particle: One of the attributes \"name\" " |
| 7000 | "or \"ref\" must be present.\n", NULL, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7001 | return (NULL); |
| 7002 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 7003 | if (refNs == NULL) |
| 7004 | refNs = schema->targetNamespace; |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 7005 | snprintf(buf, 49, "#grRef%d", ctxt->counter++ + 1); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 7006 | name = (const xmlChar *) buf; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7007 | } |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 7008 | type = xmlSchemaAddGroup(ctxt, schema, name, ns, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7009 | if (type == NULL) |
| 7010 | return (NULL); |
| 7011 | type->node = node; |
| 7012 | type->type = XML_SCHEMA_TYPE_GROUP; |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 7013 | if (topLevel) |
| 7014 | type->flags |= XML_SCHEMAS_TYPE_GLOBAL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 7015 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7016 | type->ref = ref; |
| 7017 | type->refNs = refNs; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 7018 | type->minOccurs = minOccurs; |
| 7019 | type->maxOccurs = maxOccurs; |
| 7020 | xmlSchemaPCheckParticleCorrect_2(ctxt, type, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 7021 | node, type->minOccurs, type->maxOccurs); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7022 | |
| 7023 | child = node->children; |
| 7024 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7025 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7026 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7027 | } |
| 7028 | subtype = NULL; |
| 7029 | if (IS_SCHEMA(child, "all")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7030 | subtype = (xmlSchemaTypePtr) |
| 7031 | xmlSchemaParseAll(ctxt, schema, child); |
| 7032 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7033 | } else if (IS_SCHEMA(child, "choice")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7034 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 7035 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7036 | } else if (IS_SCHEMA(child, "sequence")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7037 | subtype = (xmlSchemaTypePtr) |
| 7038 | xmlSchemaParseSequence(ctxt, schema, child); |
| 7039 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7040 | } |
| 7041 | if (subtype != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7042 | type->subtypes = subtype; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7043 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7044 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_GROUP_CHILD, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7045 | "Group definition \"%s\" has unexpected content.\n", type->name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7046 | NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7047 | } |
| 7048 | |
| 7049 | return (type); |
| 7050 | } |
| 7051 | |
| 7052 | /** |
| 7053 | * xmlSchemaParseAll: |
| 7054 | * @ctxt: a schema validation context |
| 7055 | * @schema: the schema being built |
| 7056 | * @node: a subtree containing XML Schema informations |
| 7057 | * |
| 7058 | * parse a XML schema All definition |
| 7059 | * *WARNING* this interface is highly subject to change |
| 7060 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7061 | * 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] | 7062 | * 1 in case of success. |
| 7063 | */ |
| 7064 | static xmlSchemaTypePtr |
| 7065 | xmlSchemaParseAll(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7066 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7067 | { |
| 7068 | xmlSchemaTypePtr type, subtype, last = NULL; |
| 7069 | xmlNodePtr child = NULL; |
| 7070 | xmlChar name[30]; |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 7071 | const xmlChar *oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7072 | |
| 7073 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 7074 | return (NULL); |
| 7075 | |
| 7076 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 7077 | snprintf((char *) name, 30, "#all%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7078 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7079 | if (type == NULL) |
| 7080 | return (NULL); |
| 7081 | type->node = node; |
Daniel Veillard | 7646b18 | 2002-04-20 06:41:40 +0000 | [diff] [blame] | 7082 | type->type = XML_SCHEMA_TYPE_ALL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 7083 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 7084 | |
| 7085 | type->minOccurs = xmlGetMinOccurs(ctxt, node, 0, 1, 1, "(0 | 1)"); |
| 7086 | type->maxOccurs = xmlGetMaxOccurs(ctxt, node, 1, 1, 1, "1"); |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 7087 | |
| 7088 | oldcontainer = ctxt->container; |
| 7089 | ctxt->container = (const xmlChar *) name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7090 | child = node->children; |
| 7091 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7092 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7093 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7094 | } |
| 7095 | while (IS_SCHEMA(child, "element")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7096 | subtype = (xmlSchemaTypePtr) |
| 7097 | xmlSchemaParseElement(ctxt, schema, child, 0); |
| 7098 | if (subtype != NULL) { |
William M. Brack | b15351e | 2003-12-27 04:34:42 +0000 | [diff] [blame] | 7099 | if (subtype->minOccurs > 1) |
| 7100 | xmlSchemaPErr(ctxt, child, XML_SCHEMAP_INVALID_MINOCCURS, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7101 | "invalid value for minOccurs (must be 0 or 1).\n", |
William M. Brack | b15351e | 2003-12-27 04:34:42 +0000 | [diff] [blame] | 7102 | NULL, NULL); |
| 7103 | if (subtype->maxOccurs > 1) |
| 7104 | xmlSchemaPErr(ctxt, child, XML_SCHEMAP_INVALID_MAXOCCURS, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7105 | "invalid value for maxOccurs (must be 0 or 1).\n", |
William M. Brack | b15351e | 2003-12-27 04:34:42 +0000 | [diff] [blame] | 7106 | NULL, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7107 | if (last == NULL) { |
| 7108 | type->subtypes = subtype; |
| 7109 | last = subtype; |
| 7110 | } else { |
| 7111 | last->next = subtype; |
| 7112 | last = subtype; |
| 7113 | } |
| 7114 | last->next = NULL; |
| 7115 | } |
| 7116 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7117 | } |
| 7118 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7119 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_ALL_CHILD, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7120 | "<all> has unexpected content.\n", type->name, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 7121 | NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7122 | } |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 7123 | ctxt->container = oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 7124 | return (type); |
| 7125 | } |
| 7126 | |
| 7127 | /** |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7128 | * xmlSchemaCleanupDoc: |
| 7129 | * @ctxt: a schema validation context |
| 7130 | * @node: the root of the document. |
| 7131 | * |
| 7132 | * removes unwanted nodes in a schemas document tree |
| 7133 | */ |
| 7134 | static void |
| 7135 | xmlSchemaCleanupDoc(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr root) |
| 7136 | { |
| 7137 | xmlNodePtr delete, cur; |
| 7138 | |
| 7139 | if ((ctxt == NULL) || (root == NULL)) return; |
| 7140 | |
| 7141 | /* |
| 7142 | * Remove all the blank text nodes |
| 7143 | */ |
| 7144 | delete = NULL; |
| 7145 | cur = root; |
| 7146 | while (cur != NULL) { |
| 7147 | if (delete != NULL) { |
| 7148 | xmlUnlinkNode(delete); |
| 7149 | xmlFreeNode(delete); |
| 7150 | delete = NULL; |
| 7151 | } |
| 7152 | if (cur->type == XML_TEXT_NODE) { |
| 7153 | if (IS_BLANK_NODE(cur)) { |
| 7154 | if (xmlNodeGetSpacePreserve(cur) != 1) { |
| 7155 | delete = cur; |
| 7156 | } |
| 7157 | } |
| 7158 | } else if ((cur->type != XML_ELEMENT_NODE) && |
| 7159 | (cur->type != XML_CDATA_SECTION_NODE)) { |
| 7160 | delete = cur; |
| 7161 | goto skip_children; |
| 7162 | } |
| 7163 | |
| 7164 | /* |
| 7165 | * Skip to next node |
| 7166 | */ |
| 7167 | if (cur->children != NULL) { |
| 7168 | if ((cur->children->type != XML_ENTITY_DECL) && |
| 7169 | (cur->children->type != XML_ENTITY_REF_NODE) && |
| 7170 | (cur->children->type != XML_ENTITY_NODE)) { |
| 7171 | cur = cur->children; |
| 7172 | continue; |
| 7173 | } |
| 7174 | } |
| 7175 | skip_children: |
| 7176 | if (cur->next != NULL) { |
| 7177 | cur = cur->next; |
| 7178 | continue; |
| 7179 | } |
| 7180 | |
| 7181 | do { |
| 7182 | cur = cur->parent; |
| 7183 | if (cur == NULL) |
| 7184 | break; |
| 7185 | if (cur == root) { |
| 7186 | cur = NULL; |
| 7187 | break; |
| 7188 | } |
| 7189 | if (cur->next != NULL) { |
| 7190 | cur = cur->next; |
| 7191 | break; |
| 7192 | } |
| 7193 | } while (cur != NULL); |
| 7194 | } |
| 7195 | if (delete != NULL) { |
| 7196 | xmlUnlinkNode(delete); |
| 7197 | xmlFreeNode(delete); |
| 7198 | delete = NULL; |
| 7199 | } |
| 7200 | } |
| 7201 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7202 | |
| 7203 | /** |
| 7204 | * xmlSchemaImportSchema |
| 7205 | * |
| 7206 | * @ctxt: a schema validation context |
| 7207 | * @schemaLocation: an URI defining where to find the imported schema |
| 7208 | * |
| 7209 | * import a XML schema |
| 7210 | * *WARNING* this interface is highly subject to change |
| 7211 | * |
| 7212 | * Returns -1 in case of error and 1 in case of success. |
| 7213 | */ |
| 7214 | #if 0 |
| 7215 | static xmlSchemaImportPtr |
| 7216 | xmlSchemaImportSchema(xmlSchemaParserCtxtPtr ctxt, |
| 7217 | const xmlChar *schemaLocation) |
| 7218 | { |
| 7219 | xmlSchemaImportPtr import; |
| 7220 | xmlSchemaParserCtxtPtr newctxt; |
| 7221 | |
| 7222 | newctxt = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 7223 | if (newctxt == NULL) { |
| 7224 | xmlSchemaPErrMemory(ctxt, "allocating schema parser context", |
| 7225 | NULL); |
| 7226 | return (NULL); |
| 7227 | } |
| 7228 | memset(newctxt, 0, sizeof(xmlSchemaParserCtxt)); |
| 7229 | /* Keep the same dictionnary for parsing, really */ |
| 7230 | xmlDictReference(ctxt->dict); |
| 7231 | newctxt->dict = ctxt->dict; |
| 7232 | newctxt->includes = 0; |
| 7233 | newctxt->URL = xmlDictLookup(newctxt->dict, schemaLocation, -1); |
| 7234 | |
| 7235 | xmlSchemaSetParserErrors(newctxt, ctxt->error, ctxt->warning, |
| 7236 | ctxt->userData); |
| 7237 | |
| 7238 | import = (xmlSchemaImport*) xmlMalloc(sizeof(xmlSchemaImport)); |
| 7239 | if (import == NULL) { |
| 7240 | xmlSchemaPErrMemory(NULL, "allocating imported schema", |
| 7241 | NULL); |
| 7242 | xmlSchemaFreeParserCtxt(newctxt); |
| 7243 | return (NULL); |
| 7244 | } |
| 7245 | |
| 7246 | memset(import, 0, sizeof(xmlSchemaImport)); |
| 7247 | import->schemaLocation = xmlDictLookup(ctxt->dict, schemaLocation, -1); |
| 7248 | import->schema = xmlSchemaParse(newctxt); |
| 7249 | |
| 7250 | if (import->schema == NULL) { |
| 7251 | /* FIXME use another error enum here ? */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 7252 | xmlSchemaPErr(ctxt, NULL, XML_SCHEMAP_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7253 | "Failed to import schema from location \"%s\".\n", |
| 7254 | schemaLocation, NULL); |
| 7255 | |
| 7256 | xmlSchemaFreeParserCtxt(newctxt); |
| 7257 | /* The schemaLocation is held by the dictionary. |
| 7258 | if (import->schemaLocation != NULL) |
| 7259 | xmlFree((xmlChar *)import->schemaLocation); |
| 7260 | */ |
| 7261 | xmlFree(import); |
| 7262 | return NULL; |
| 7263 | } |
| 7264 | |
| 7265 | xmlSchemaFreeParserCtxt(newctxt); |
| 7266 | return import; |
| 7267 | } |
| 7268 | #endif |
| 7269 | |
| 7270 | static void |
| 7271 | xmlSchemaClearSchemaDefaults(xmlSchemaPtr schema) |
| 7272 | { |
| 7273 | if (schema->flags & XML_SCHEMAS_QUALIF_ELEM) |
| 7274 | schema->flags ^= XML_SCHEMAS_QUALIF_ELEM; |
| 7275 | |
| 7276 | if (schema->flags & XML_SCHEMAS_QUALIF_ATTR) |
| 7277 | schema->flags ^= XML_SCHEMAS_QUALIF_ATTR; |
| 7278 | |
| 7279 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION) |
| 7280 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_EXTENSION; |
| 7281 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION) |
| 7282 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION; |
| 7283 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_LIST) |
| 7284 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_LIST; |
| 7285 | if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_UNION) |
| 7286 | schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_UNION; |
| 7287 | |
| 7288 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION) |
| 7289 | schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION; |
| 7290 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION) |
| 7291 | schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION; |
| 7292 | if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION) |
| 7293 | schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION; |
| 7294 | } |
| 7295 | |
| 7296 | static void |
| 7297 | xmlSchemaParseSchemaDefaults(xmlSchemaParserCtxtPtr ctxt, |
| 7298 | xmlSchemaPtr schema, |
| 7299 | xmlNodePtr node) |
| 7300 | { |
| 7301 | xmlAttrPtr attr; |
| 7302 | const xmlChar *val; |
| 7303 | |
| 7304 | attr = xmlSchemaGetPropNode(node, "elementFormDefault"); |
| 7305 | if (attr != NULL) { |
| 7306 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 7307 | if (xmlSchemaPValAttrFormDefault(val, &schema->flags, |
| 7308 | XML_SCHEMAS_QUALIF_ELEM) != 0) { |
| 7309 | xmlSchemaPSimpleTypeErr(ctxt, |
| 7310 | XML_SCHEMAP_ELEMFORMDEFAULT_VALUE, |
| 7311 | NULL, NULL, (xmlNodePtr) attr, NULL, |
| 7312 | "(qualified | unqualified)", val, NULL, NULL, NULL); |
| 7313 | } |
| 7314 | } |
| 7315 | |
| 7316 | attr = xmlSchemaGetPropNode(node, "attributeFormDefault"); |
| 7317 | if (attr != NULL) { |
| 7318 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 7319 | if (xmlSchemaPValAttrFormDefault(val, &schema->flags, |
| 7320 | XML_SCHEMAS_QUALIF_ATTR) != 0) { |
| 7321 | xmlSchemaPSimpleTypeErr(ctxt, |
| 7322 | XML_SCHEMAP_ATTRFORMDEFAULT_VALUE, |
| 7323 | NULL, NULL, (xmlNodePtr) attr, NULL, |
| 7324 | "(qualified | unqualified)", val, NULL, NULL, NULL); |
| 7325 | } |
| 7326 | } |
| 7327 | |
| 7328 | attr = xmlSchemaGetPropNode(node, "finalDefault"); |
| 7329 | if (attr != NULL) { |
| 7330 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 7331 | if (xmlSchemaPValAttrBlockFinal(val, &(schema->flags), -1, |
| 7332 | XML_SCHEMAS_FINAL_DEFAULT_EXTENSION, |
| 7333 | XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION, |
| 7334 | -1, |
| 7335 | XML_SCHEMAS_FINAL_DEFAULT_LIST, |
| 7336 | XML_SCHEMAS_FINAL_DEFAULT_UNION) != 0) { |
| 7337 | xmlSchemaPSimpleTypeErr(ctxt, |
| 7338 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 7339 | NULL, NULL, (xmlNodePtr) attr, NULL, |
| 7340 | "(#all | List of (extension | restriction | list | union))", |
| 7341 | val, NULL, NULL, NULL); |
| 7342 | } |
| 7343 | } |
| 7344 | |
| 7345 | attr = xmlSchemaGetPropNode(node, "blockDefault"); |
| 7346 | if (attr != NULL) { |
| 7347 | val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr); |
| 7348 | if (xmlSchemaPValAttrBlockFinal(val, &(schema->flags), -1, |
| 7349 | XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION, |
| 7350 | XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION, |
| 7351 | XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION, -1, -1) != 0) { |
| 7352 | xmlSchemaPSimpleTypeErr(ctxt, |
| 7353 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 7354 | NULL, NULL, (xmlNodePtr) attr, NULL, |
| 7355 | "(#all | List of (extension | restriction | substitution))", |
| 7356 | val, NULL, NULL, NULL); |
| 7357 | } |
| 7358 | } |
| 7359 | } |
| 7360 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7361 | /** |
| 7362 | * xmlSchemaParseSchemaTopLevel: |
| 7363 | * @ctxt: a schema validation context |
| 7364 | * @schema: the schemas |
| 7365 | * @nodes: the list of top level nodes |
| 7366 | * |
| 7367 | * Returns the internal XML Schema structure built from the resource or |
| 7368 | * NULL in case of error |
| 7369 | */ |
| 7370 | static void |
| 7371 | xmlSchemaParseSchemaTopLevel(xmlSchemaParserCtxtPtr ctxt, |
| 7372 | xmlSchemaPtr schema, xmlNodePtr nodes) |
| 7373 | { |
| 7374 | xmlNodePtr child; |
| 7375 | xmlSchemaAnnotPtr annot; |
| 7376 | |
| 7377 | if ((ctxt == NULL) || (schema == NULL) || (nodes == NULL)) |
| 7378 | return; |
| 7379 | |
| 7380 | child = nodes; |
| 7381 | while ((IS_SCHEMA(child, "include")) || |
| 7382 | (IS_SCHEMA(child, "import")) || |
| 7383 | (IS_SCHEMA(child, "redefine")) || |
| 7384 | (IS_SCHEMA(child, "annotation"))) { |
| 7385 | if (IS_SCHEMA(child, "annotation")) { |
| 7386 | annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7387 | if (schema->annot == NULL) |
| 7388 | schema->annot = annot; |
| 7389 | else |
| 7390 | xmlSchemaFreeAnnot(annot); |
| 7391 | } else if (IS_SCHEMA(child, "import")) { |
| 7392 | xmlSchemaParseImport(ctxt, schema, child); |
| 7393 | } else if (IS_SCHEMA(child, "include")) { |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 7394 | ctxt->includes++; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7395 | xmlSchemaParseInclude(ctxt, schema, child); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 7396 | ctxt->includes--; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7397 | } else if (IS_SCHEMA(child, "redefine")) { |
| 7398 | TODO |
| 7399 | } |
| 7400 | child = child->next; |
| 7401 | } |
| 7402 | while (child != NULL) { |
| 7403 | if (IS_SCHEMA(child, "complexType")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 7404 | xmlSchemaParseComplexType(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7405 | child = child->next; |
| 7406 | } else if (IS_SCHEMA(child, "simpleType")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 7407 | xmlSchemaParseSimpleType(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7408 | child = child->next; |
| 7409 | } else if (IS_SCHEMA(child, "element")) { |
| 7410 | xmlSchemaParseElement(ctxt, schema, child, 1); |
| 7411 | child = child->next; |
| 7412 | } else if (IS_SCHEMA(child, "attribute")) { |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7413 | xmlSchemaParseAttribute(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7414 | child = child->next; |
| 7415 | } else if (IS_SCHEMA(child, "attributeGroup")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 7416 | xmlSchemaParseAttributeGroup(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7417 | child = child->next; |
| 7418 | } else if (IS_SCHEMA(child, "group")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 7419 | xmlSchemaParseGroup(ctxt, schema, child, 1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7420 | child = child->next; |
| 7421 | } else if (IS_SCHEMA(child, "notation")) { |
| 7422 | xmlSchemaParseNotation(ctxt, schema, child); |
| 7423 | child = child->next; |
| 7424 | } else { |
| 7425 | xmlSchemaPErr2(ctxt, NULL, child, |
| 7426 | XML_SCHEMAP_UNKNOWN_SCHEMAS_CHILD, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7427 | "Unexpected element \"%s\" as child of <schema>.\n", |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7428 | child->name, NULL); |
| 7429 | child = child->next; |
| 7430 | } |
| 7431 | while (IS_SCHEMA(child, "annotation")) { |
| 7432 | annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 7433 | if (schema->annot == NULL) |
| 7434 | schema->annot = annot; |
| 7435 | else |
| 7436 | xmlSchemaFreeAnnot(annot); |
| 7437 | child = child->next; |
| 7438 | } |
| 7439 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 7440 | ctxt->parentItem = NULL; |
| 7441 | ctxt->ctxtType = NULL; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7442 | } |
| 7443 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7444 | static xmlSchemaImportPtr |
| 7445 | xmlSchemaAddImport(xmlSchemaParserCtxtPtr ctxt, |
| 7446 | xmlHashTablePtr *imports, |
| 7447 | const xmlChar *nsName) |
| 7448 | { |
| 7449 | xmlSchemaImportPtr ret; |
| 7450 | |
| 7451 | if (*imports == NULL) { |
Daniel Veillard | b9e2f26 | 2005-01-23 23:48:34 +0000 | [diff] [blame] | 7452 | *imports = xmlHashCreateDict(10, ctxt->dict); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7453 | if (*imports == NULL) { |
| 7454 | xmlSchemaPCustomErr(ctxt, |
| 7455 | XML_SCHEMAP_FAILED_BUILD_IMPORT, |
| 7456 | NULL, NULL, (xmlNodePtr) ctxt->doc, |
| 7457 | "Internal error: failed to build the import table", |
| 7458 | NULL); |
| 7459 | return (NULL); |
| 7460 | } |
| 7461 | } |
| 7462 | ret = (xmlSchemaImport*) xmlMalloc(sizeof(xmlSchemaImport)); |
| 7463 | if (ret == NULL) { |
| 7464 | xmlSchemaPErrMemory(NULL, "allocating import struct", NULL); |
| 7465 | return (NULL); |
| 7466 | } |
| 7467 | memset(ret, 0, sizeof(xmlSchemaImport)); |
| 7468 | if (nsName == NULL) |
| 7469 | nsName = XML_SCHEMAS_NO_NAMESPACE; |
| 7470 | xmlHashAddEntry(*imports, nsName, ret); |
| 7471 | |
| 7472 | return (ret); |
| 7473 | } |
| 7474 | |
| 7475 | static int |
| 7476 | xmlSchemaAcquireSchemaDoc(xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7477 | xmlSchemaPtr schema, |
| 7478 | xmlNodePtr node, |
| 7479 | const xmlChar *nsName, |
| 7480 | const xmlChar *location, |
| 7481 | xmlDocPtr *doc, |
| 7482 | const xmlChar **targetNamespace, |
| 7483 | int absolute) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7484 | { |
| 7485 | xmlParserCtxtPtr parserCtxt; |
| 7486 | xmlSchemaImportPtr import; |
| 7487 | const xmlChar *ns; |
| 7488 | xmlNodePtr root; |
| 7489 | |
| 7490 | /* |
| 7491 | * NOTE: This will be used for <import>, <xsi:schemaLocation> and |
| 7492 | * <xsi:noNamespaceSchemaLocation>. |
| 7493 | */ |
| 7494 | *doc = NULL; |
| 7495 | /* |
| 7496 | * Given that the schemaLocation [attribute] is only a hint, it is open |
| 7497 | * to applications to ignore all but the first <import> for a given |
| 7498 | * namespace, regardless of the ·actual value· of schemaLocation, but |
| 7499 | * such a strategy risks missing useful information when new |
| 7500 | * schemaLocations are offered. |
| 7501 | * |
| 7502 | * XSV (ver 2.5-2) does use the first <import> which resolves to a valid schema. |
| 7503 | * Xerces-J (ver 2.5.1) ignores all but the first given <import> - regardless if |
| 7504 | * valid or not. |
| 7505 | * We will follow XSV here. |
| 7506 | */ |
| 7507 | if (location == NULL) { |
| 7508 | /* |
| 7509 | * Schema Document Location Strategy: |
| 7510 | * |
| 7511 | * 3 Based on the namespace name, identify an existing schema document, |
| 7512 | * either as a resource which is an XML document or a <schema> element |
| 7513 | * information item, in some local schema repository; |
| 7514 | * |
| 7515 | * 5 Attempt to resolve the namespace name to locate such a resource. |
| 7516 | * |
| 7517 | * NOTE: Those stategies are not supported, so we will skip. |
| 7518 | */ |
| 7519 | return (0); |
| 7520 | } |
| 7521 | if (nsName == NULL) |
| 7522 | ns = XML_SCHEMAS_NO_NAMESPACE; |
| 7523 | else |
| 7524 | ns = nsName; |
| 7525 | |
| 7526 | import = xmlHashLookup(schema->schemasImports, ns); |
| 7527 | if (import != NULL) { |
| 7528 | /* |
| 7529 | * There was a valid resource for the specified namespace already |
| 7530 | * defined, so skip. |
| 7531 | * TODO: This might be changed someday to allow import of |
| 7532 | * components from multiple documents for a single target namespace. |
| 7533 | */ |
| 7534 | return (0); |
| 7535 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 7536 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7537 | /* |
| 7538 | * Schema Document Location Strategy: |
| 7539 | * |
| 7540 | * 2 Based on the location URI, identify an existing schema document, |
| 7541 | * either as a resource which is an XML document or a <schema> element |
| 7542 | * information item, in some local schema repository; |
| 7543 | * |
| 7544 | * 4 Attempt to resolve the location URI, to locate a resource on the |
| 7545 | * web which is or contains or references a <schema> element; |
| 7546 | * TODO: Hmm, I don't know if the reference stuff in 4. will work. |
| 7547 | * |
| 7548 | */ |
| 7549 | if ((absolute == 0) && (node != NULL)) { |
| 7550 | xmlChar *base, *URI; |
| 7551 | |
| 7552 | base = xmlNodeGetBase(node->doc, node); |
| 7553 | if (base == NULL) { |
| 7554 | URI = xmlBuildURI(location, node->doc->URL); |
| 7555 | } else { |
| 7556 | URI = xmlBuildURI(location, base); |
| 7557 | xmlFree(base); |
| 7558 | } |
| 7559 | if (URI != NULL) { |
| 7560 | location = xmlDictLookup(ctxt->dict, URI, -1); |
| 7561 | xmlFree(URI); |
| 7562 | } |
| 7563 | } |
| 7564 | parserCtxt = xmlNewParserCtxt(); |
| 7565 | if (parserCtxt == NULL) { |
| 7566 | xmlSchemaPErrMemory(NULL, "xmlSchemaParseImport: " |
| 7567 | "allocating a parser context", NULL); |
| 7568 | return(-1); |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 7569 | } |
| 7570 | |
| 7571 | if ((ctxt->dict != NULL) && (parserCtxt->dict != NULL)) { |
| 7572 | xmlDictFree(parserCtxt->dict); |
| 7573 | parserCtxt->dict = ctxt->dict; |
| 7574 | xmlDictReference(parserCtxt->dict); |
| 7575 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7576 | |
| 7577 | *doc = xmlCtxtReadFile(parserCtxt, (const char *) location, |
| 7578 | NULL, SCHEMAS_PARSE_OPTIONS); |
| 7579 | |
| 7580 | /* |
| 7581 | * 2.1 The referent is (a fragment of) a resource which is an |
| 7582 | * XML document (see clause 1.1), which in turn corresponds to |
| 7583 | * a <schema> element information item in a well-formed information |
| 7584 | * set, which in turn corresponds to a valid schema. |
| 7585 | * TODO: What to do with the "fragment" stuff? |
| 7586 | * |
| 7587 | * 2.2 The referent is a <schema> element information item in |
| 7588 | * a well-formed information set, which in turn corresponds |
| 7589 | * to a valid schema. |
| 7590 | * NOTE: 2.2 won't apply, since only XML documents will be processed |
| 7591 | * here. |
| 7592 | */ |
| 7593 | if (*doc == NULL) { |
| 7594 | xmlErrorPtr lerr; |
| 7595 | /* |
| 7596 | * It is *not* an error for the application schema reference |
| 7597 | * strategy to fail. |
| 7598 | * |
| 7599 | * If the doc is NULL and the parser error is an IO error we |
| 7600 | * will assume that the resource could not be located or accessed. |
| 7601 | * |
| 7602 | * TODO: Try to find specific error codes to react only on |
| 7603 | * localisation failures. |
| 7604 | * |
| 7605 | * TODO, FIXME: Check the spec: is a namespace added to the imported |
| 7606 | * namespaces, even if the schemaLocation did not provide |
| 7607 | * a resource? I guess so, since omitting the "schemaLocation" |
| 7608 | * attribute, imports a namespace as well. |
| 7609 | */ |
| 7610 | lerr = xmlGetLastError(); |
| 7611 | if ((lerr != NULL) && (lerr->domain == XML_FROM_IO)) { |
| 7612 | xmlFreeParserCtxt(parserCtxt); |
| 7613 | return(0); |
| 7614 | } |
| 7615 | |
| 7616 | xmlSchemaPCustomErr(ctxt, |
| 7617 | XML_SCHEMAP_SRC_IMPORT_2_1, |
| 7618 | NULL, NULL, node, |
| 7619 | "Failed to parse the resource '%s' for import", |
| 7620 | location); |
| 7621 | xmlFreeParserCtxt(parserCtxt); |
| 7622 | return(XML_SCHEMAP_SRC_IMPORT_2_1); |
| 7623 | } |
| 7624 | xmlFreeParserCtxt(parserCtxt); |
| 7625 | |
| 7626 | root = xmlDocGetRootElement(*doc); |
| 7627 | if (root == NULL) { |
| 7628 | xmlSchemaPCustomErr(ctxt, |
| 7629 | XML_SCHEMAP_SRC_IMPORT_2_1, |
| 7630 | NULL, NULL, node, |
| 7631 | "The XML document '%s' to be imported has no document " |
| 7632 | "element", location); |
| 7633 | xmlFreeDoc(*doc); |
| 7634 | *doc = NULL; |
| 7635 | return (XML_SCHEMAP_SRC_IMPORT_2_1); |
| 7636 | } |
| 7637 | |
| 7638 | xmlSchemaCleanupDoc(ctxt, root); |
| 7639 | |
| 7640 | if (!IS_SCHEMA(root, "schema")) { |
| 7641 | xmlSchemaPCustomErr(ctxt, |
| 7642 | XML_SCHEMAP_SRC_IMPORT_2_1, |
| 7643 | NULL, NULL, node, |
| 7644 | "The XML document '%s' to be imported is not a XML schema document", |
| 7645 | location); |
| 7646 | xmlFreeDoc(*doc); |
| 7647 | *doc = NULL; |
| 7648 | return (XML_SCHEMAP_SRC_IMPORT_2_1); |
| 7649 | } |
| 7650 | *targetNamespace = xmlSchemaGetProp(ctxt, root, "targetNamespace"); |
| 7651 | /* |
| 7652 | * Schema Representation Constraint: Import Constraints and Semantics |
| 7653 | */ |
| 7654 | if (nsName == NULL) { |
| 7655 | if (*targetNamespace != NULL) { |
| 7656 | xmlSchemaPCustomErr(ctxt, |
| 7657 | XML_SCHEMAP_SRC_IMPORT_3_2, |
| 7658 | NULL, NULL, node, |
| 7659 | "The XML schema to be imported is not expected " |
| 7660 | "to have a target namespace; this differs from " |
| 7661 | "its target namespace of '%s'", *targetNamespace); |
| 7662 | xmlFreeDoc(*doc); |
| 7663 | *doc = NULL; |
| 7664 | return (XML_SCHEMAP_SRC_IMPORT_3_2); |
| 7665 | } |
| 7666 | } else { |
| 7667 | if (*targetNamespace == NULL) { |
| 7668 | xmlSchemaPCustomErr(ctxt, |
| 7669 | XML_SCHEMAP_SRC_IMPORT_3_1, |
| 7670 | NULL, NULL, node, |
| 7671 | "The XML schema to be imported is expected to have a target " |
| 7672 | "namespace of '%s'", nsName); |
| 7673 | xmlFreeDoc(*doc); |
| 7674 | *doc = NULL; |
| 7675 | return (XML_SCHEMAP_SRC_IMPORT_3_1); |
| 7676 | } else if (!xmlStrEqual(*targetNamespace, nsName)) { |
| 7677 | xmlSchemaPCustomErrExt(ctxt, |
| 7678 | XML_SCHEMAP_SRC_IMPORT_3_1, |
| 7679 | NULL, NULL, node, |
| 7680 | "The XML schema to be imported is expected to have a " |
| 7681 | "target namespace of '%s'; this differs from " |
| 7682 | "its target namespace of '%s'", |
| 7683 | nsName, *targetNamespace, NULL); |
| 7684 | xmlFreeDoc(*doc); |
| 7685 | *doc = NULL; |
| 7686 | return (XML_SCHEMAP_SRC_IMPORT_3_1); |
| 7687 | } |
| 7688 | } |
| 7689 | |
| 7690 | import = xmlSchemaAddImport(ctxt, &(schema->schemasImports), nsName); |
| 7691 | if (import == NULL) { |
| 7692 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_FAILED_BUILD_IMPORT, |
| 7693 | NULL, NULL, NULL, |
| 7694 | "Internal error: xmlSchemaAcquireSchemaDoc, " |
| 7695 | "failed to build import table", NULL); |
| 7696 | xmlFreeDoc(*doc); |
| 7697 | *doc = NULL; |
| 7698 | return (-1); |
| 7699 | } |
| 7700 | import->schemaLocation = location; |
| 7701 | import->doc = *doc; |
| 7702 | return (0); |
| 7703 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7704 | |
| 7705 | /** |
| 7706 | * xmlSchemaParseImport: |
| 7707 | * @ctxt: a schema validation context |
| 7708 | * @schema: the schema being built |
| 7709 | * @node: a subtree containing XML Schema informations |
| 7710 | * |
| 7711 | * parse a XML schema Import definition |
| 7712 | * *WARNING* this interface is highly subject to change |
| 7713 | * |
| 7714 | * Returns 0 in case of success, a positive error code if |
| 7715 | * not valid and -1 in case of an internal error. |
| 7716 | */ |
| 7717 | static int |
| 7718 | xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 7719 | xmlNodePtr node) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7720 | { |
| 7721 | xmlNodePtr child; |
| 7722 | const xmlChar *namespace = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7723 | const xmlChar *schemaLocation = NULL; |
| 7724 | const xmlChar *targetNamespace, *oldTNS, *url; |
| 7725 | xmlAttrPtr attr; |
| 7726 | xmlDocPtr doc; |
| 7727 | xmlNodePtr root; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7728 | int flags, ret = 0; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7729 | |
| 7730 | |
| 7731 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 7732 | return (-1); |
| 7733 | |
| 7734 | /* |
| 7735 | * Check for illegal attributes. |
| 7736 | */ |
| 7737 | attr = node->properties; |
| 7738 | while (attr != NULL) { |
| 7739 | if (attr->ns == NULL) { |
| 7740 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 7741 | (!xmlStrEqual(attr->name, BAD_CAST "namespace")) && |
| 7742 | (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation"))) { |
| 7743 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7744 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7745 | NULL, NULL, attr); |
| 7746 | } |
| 7747 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 7748 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7749 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7750 | NULL, NULL, attr); |
| 7751 | } |
| 7752 | attr = attr->next; |
| 7753 | } |
| 7754 | /* |
| 7755 | * Extract and validate attributes. |
| 7756 | */ |
| 7757 | if (xmlSchemaPValAttr(ctxt, NULL, NULL, node, |
| 7758 | "namespace", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
| 7759 | &namespace) != 0) { |
| 7760 | xmlSchemaPSimpleTypeErr(ctxt, |
| 7761 | XML_SCHEMAP_IMPORT_NAMESPACE_NOT_URI, |
| 7762 | NULL, NULL, node, |
| 7763 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
| 7764 | NULL, namespace, NULL, NULL, NULL); |
| 7765 | return (XML_SCHEMAP_IMPORT_NAMESPACE_NOT_URI); |
| 7766 | } |
| 7767 | |
| 7768 | if (xmlSchemaPValAttr(ctxt, NULL, NULL, node, |
| 7769 | "schemaLocation", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
| 7770 | &schemaLocation) != 0) { |
| 7771 | xmlSchemaPSimpleTypeErr(ctxt, |
| 7772 | XML_SCHEMAP_IMPORT_SCHEMA_NOT_URI, |
| 7773 | NULL, NULL, node, |
| 7774 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), |
| 7775 | NULL, namespace, NULL, NULL, NULL); |
| 7776 | return (XML_SCHEMAP_IMPORT_SCHEMA_NOT_URI); |
| 7777 | } |
| 7778 | /* |
| 7779 | * And now for the children... |
| 7780 | */ |
| 7781 | child = node->children; |
| 7782 | if (IS_SCHEMA(child, "annotation")) { |
| 7783 | /* |
| 7784 | * the annotation here is simply discarded ... |
| 7785 | */ |
| 7786 | child = child->next; |
| 7787 | } |
| 7788 | if (child != NULL) { |
| 7789 | xmlSchemaPContentErr(ctxt, |
| 7790 | XML_SCHEMAP_UNKNOWN_IMPORT_CHILD, |
| 7791 | NULL, NULL, node, child, NULL, |
| 7792 | "(annotation?)"); |
| 7793 | } |
| 7794 | /* |
| 7795 | * Apply additional constraints. |
| 7796 | */ |
| 7797 | if (namespace != NULL) { |
| 7798 | /* |
| 7799 | * 1.1 If the namespace [attribute] is present, then its ·actual value· |
| 7800 | * must not match the ·actual value· of the enclosing <schema>'s |
| 7801 | * targetNamespace [attribute]. |
| 7802 | */ |
| 7803 | if (xmlStrEqual(schema->targetNamespace, namespace)) { |
| 7804 | xmlSchemaPCustomErr(ctxt, |
| 7805 | XML_SCHEMAP_SRC_IMPORT_1_1, |
| 7806 | NULL, NULL, node, |
| 7807 | "The value of the attribute 'namespace' must not match " |
| 7808 | "the target namespace '%s' of the importing schema", |
| 7809 | schema->targetNamespace); |
| 7810 | return (XML_SCHEMAP_SRC_IMPORT_1_1); |
| 7811 | } |
| 7812 | } else { |
| 7813 | /* |
| 7814 | * 1.2 If the namespace [attribute] is not present, then the enclosing |
| 7815 | * <schema> must have a targetNamespace [attribute]. |
| 7816 | */ |
| 7817 | if (schema->targetNamespace == NULL) { |
| 7818 | xmlSchemaPCustomErr(ctxt, |
| 7819 | XML_SCHEMAP_SRC_IMPORT_1_2, |
| 7820 | NULL, NULL, node, |
| 7821 | "The attribute 'namespace' must be existent if " |
| 7822 | "the importing schema has no target namespace", |
| 7823 | NULL); |
| 7824 | return (XML_SCHEMAP_SRC_IMPORT_1_2); |
| 7825 | } |
| 7826 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7827 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7828 | * Locate and aquire the schema document. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7829 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7830 | ret = xmlSchemaAcquireSchemaDoc(ctxt, schema, node, namespace, |
| 7831 | schemaLocation, &doc, &targetNamespace, 0); |
| 7832 | if (ret != 0) { |
| 7833 | if (doc != NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7834 | xmlFreeDoc(doc); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7835 | return (ret); |
| 7836 | } else if (doc != NULL) { |
| 7837 | /* |
| 7838 | * Save and reset the context & schema. |
| 7839 | */ |
| 7840 | url = ctxt->URL; |
| 7841 | /* TODO: Is using the doc->URL here correct? */ |
| 7842 | ctxt->URL = doc->URL; |
| 7843 | flags = schema->flags; |
| 7844 | oldTNS = schema->targetNamespace; |
| 7845 | /* |
| 7846 | * Parse the schema. |
| 7847 | */ |
| 7848 | root = xmlDocGetRootElement(doc); |
| 7849 | xmlSchemaClearSchemaDefaults(schema); |
| 7850 | xmlSchemaParseSchemaDefaults(ctxt, schema, root); |
| 7851 | schema->targetNamespace = targetNamespace; |
| 7852 | xmlSchemaParseSchemaTopLevel(ctxt, schema, root->children); |
| 7853 | /* |
| 7854 | * Restore the context & schema. |
| 7855 | */ |
| 7856 | schema->flags = flags; |
| 7857 | schema->targetNamespace = oldTNS; |
| 7858 | ctxt->URL = url; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7859 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7860 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 7861 | return (0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7862 | } |
| 7863 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7864 | /** |
| 7865 | * xmlSchemaParseInclude: |
| 7866 | * @ctxt: a schema validation context |
| 7867 | * @schema: the schema being built |
| 7868 | * @node: a subtree containing XML Schema informations |
| 7869 | * |
| 7870 | * parse a XML schema Include definition |
| 7871 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 7872 | * 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] | 7873 | * 1 in case of success. |
| 7874 | */ |
| 7875 | static int |
| 7876 | xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
| 7877 | xmlNodePtr node) |
| 7878 | { |
| 7879 | xmlNodePtr child = NULL; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7880 | const xmlChar *schemaLocation, *targetNamespace; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7881 | xmlDocPtr doc; |
| 7882 | xmlNodePtr root; |
| 7883 | xmlSchemaIncludePtr include; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 7884 | int wasConvertingNs = 0; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7885 | xmlAttrPtr attr; |
| 7886 | int saveFlags; |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 7887 | xmlParserCtxtPtr parserCtxt; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7888 | |
| 7889 | |
| 7890 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 7891 | return (-1); |
| 7892 | |
| 7893 | /* |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7894 | * Check for illegal attributes. |
| 7895 | */ |
| 7896 | attr = node->properties; |
| 7897 | while (attr != NULL) { |
| 7898 | if (attr->ns == NULL) { |
| 7899 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 7900 | (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation"))) { |
| 7901 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7902 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7903 | NULL, NULL, attr); |
| 7904 | } |
| 7905 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 7906 | xmlSchemaPIllegalAttrErr(ctxt, |
| 7907 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 7908 | NULL, NULL, attr); |
| 7909 | } |
| 7910 | attr = attr->next; |
| 7911 | } |
| 7912 | /* |
| 7913 | * Extract and validate attributes. |
| 7914 | */ |
| 7915 | /* |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7916 | * Preliminary step, extract the URI-Reference for the include and |
| 7917 | * make an URI from the base. |
| 7918 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7919 | attr = xmlSchemaGetPropNode(node, "schemaLocation"); |
| 7920 | if (attr != NULL) { |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7921 | xmlChar *base = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7922 | xmlChar *uri = NULL; |
| 7923 | |
| 7924 | if (xmlSchemaPValAttrNode(ctxt, NULL, NULL, attr, |
| 7925 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), &schemaLocation) != 0) |
| 7926 | return (-1); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7927 | base = xmlNodeGetBase(node->doc, node); |
| 7928 | if (base == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7929 | uri = xmlBuildURI(schemaLocation, node->doc->URL); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7930 | } else { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7931 | uri = xmlBuildURI(schemaLocation, base); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7932 | xmlFree(base); |
| 7933 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7934 | if (uri != NULL) { |
| 7935 | schemaLocation = xmlDictLookup(ctxt->dict, uri, -1); |
| 7936 | xmlFree(uri); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7937 | } |
| 7938 | } else { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7939 | xmlSchemaPMissingAttrErr(ctxt, |
| 7940 | XML_SCHEMAP_INCLUDE_SCHEMA_NO_URI, |
| 7941 | NULL, NULL, node, "schemaLocation", NULL); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7942 | return (-1); |
| 7943 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7944 | /* |
| 7945 | * And now for the children... |
| 7946 | */ |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7947 | child = node->children; |
| 7948 | while (IS_SCHEMA(child, "annotation")) { |
| 7949 | /* |
| 7950 | * the annotations here are simply discarded ... |
| 7951 | */ |
| 7952 | child = child->next; |
| 7953 | } |
| 7954 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7955 | xmlSchemaPContentErr(ctxt, |
| 7956 | XML_SCHEMAP_UNKNOWN_INCLUDE_CHILD, |
| 7957 | NULL, NULL, node, child, NULL, |
| 7958 | "(annotation?)"); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7959 | } |
| 7960 | |
| 7961 | /* |
| 7962 | * First step is to parse the input document into an DOM/Infoset |
| 7963 | */ |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 7964 | /* |
| 7965 | * TODO: Use xmlCtxtReadFile to share the dictionary. |
| 7966 | */ |
| 7967 | parserCtxt = xmlNewParserCtxt(); |
| 7968 | if (parserCtxt == NULL) { |
| 7969 | xmlSchemaPErrMemory(NULL, "xmlSchemaParseInclude: " |
| 7970 | "allocating a parser context", NULL); |
| 7971 | return(-1); |
| 7972 | } |
| 7973 | |
| 7974 | if ((ctxt->dict != NULL) && (parserCtxt->dict != NULL)) { |
| 7975 | xmlDictFree(parserCtxt->dict); |
| 7976 | parserCtxt->dict = ctxt->dict; |
| 7977 | xmlDictReference(parserCtxt->dict); |
| 7978 | } |
| 7979 | |
| 7980 | doc = xmlCtxtReadFile(parserCtxt, (const char *) schemaLocation, |
| 7981 | NULL, SCHEMAS_PARSE_OPTIONS); |
| 7982 | xmlFreeParserCtxt(parserCtxt); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7983 | if (doc == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 7984 | /* |
| 7985 | * TODO: It is not an error for the ·actual value· of the |
| 7986 | * schemaLocation [attribute] to fail to resolve it all, in which |
| 7987 | * case no corresponding inclusion is performed. |
| 7988 | * So do we need a warning report here? |
| 7989 | */ |
| 7990 | xmlSchemaPCustomErr(ctxt, |
| 7991 | XML_SCHEMAP_FAILED_LOAD, |
| 7992 | NULL, NULL, node, |
| 7993 | "Failed to load the document '%s' for inclusion", schemaLocation); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 7994 | return(-1); |
| 7995 | } |
| 7996 | |
| 7997 | /* |
| 7998 | * Then extract the root of the schema |
| 7999 | */ |
| 8000 | root = xmlDocGetRootElement(doc); |
| 8001 | if (root == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8002 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8003 | XML_SCHEMAP_NOROOT, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8004 | NULL, NULL, node, |
| 8005 | "The included document '%s' has no document " |
| 8006 | "element", schemaLocation); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8007 | xmlFreeDoc(doc); |
| 8008 | return (-1); |
| 8009 | } |
| 8010 | |
| 8011 | /* |
| 8012 | * Remove all the blank text nodes |
| 8013 | */ |
| 8014 | xmlSchemaCleanupDoc(ctxt, root); |
| 8015 | |
| 8016 | /* |
| 8017 | * Check the schemas top level element |
| 8018 | */ |
| 8019 | if (!IS_SCHEMA(root, "schema")) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8020 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8021 | XML_SCHEMAP_NOT_SCHEMA, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8022 | NULL, NULL, node, |
| 8023 | "The document '%s' to be included is not a schema document", |
| 8024 | schemaLocation); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8025 | xmlFreeDoc(doc); |
| 8026 | return (-1); |
| 8027 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8028 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8029 | targetNamespace = xmlSchemaGetProp(ctxt, root, "targetNamespace"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8030 | /* |
| 8031 | * 2.1 SII has a targetNamespace [attribute], and its ·actual |
| 8032 | * value· is identical to the ·actual value· of the targetNamespace |
| 8033 | * [attribute] of SIIÂ’ (which must have such an [attribute]). |
| 8034 | */ |
| 8035 | if (targetNamespace != NULL) { |
| 8036 | if (schema->targetNamespace == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8037 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8038 | XML_SCHEMAP_SRC_INCLUDE, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8039 | NULL, NULL, node, |
| 8040 | "The target namespace of the included schema " |
| 8041 | "'%s' has to be absent, since the including schema " |
| 8042 | "has no target namespace", |
| 8043 | schemaLocation); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8044 | xmlFreeDoc(doc); |
| 8045 | return (-1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8046 | } else if (!xmlStrEqual(targetNamespace, schema->targetNamespace)) { |
| 8047 | xmlSchemaPCustomErrExt(ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8048 | XML_SCHEMAP_SRC_INCLUDE, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8049 | NULL, NULL, node, |
| 8050 | "The target namespace '%s' of the included schema '%s' " |
| 8051 | "differs from '%s' of the including schema", |
| 8052 | targetNamespace, schemaLocation, schema->targetNamespace); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8053 | xmlFreeDoc(doc); |
| 8054 | return (-1); |
| 8055 | } |
| 8056 | } else if (schema->targetNamespace != NULL) { |
| 8057 | if ((schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) == 0) { |
| 8058 | schema->flags |= XML_SCHEMAS_INCLUDING_CONVERT_NS; |
| 8059 | } else |
| 8060 | wasConvertingNs = 1; |
| 8061 | } |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8062 | /* |
| 8063 | * register the include |
| 8064 | */ |
| 8065 | include = (xmlSchemaIncludePtr) xmlMalloc(sizeof(xmlSchemaInclude)); |
| 8066 | if (include == NULL) { |
| 8067 | xmlSchemaPErrMemory(ctxt, "allocating included schema", NULL); |
| 8068 | xmlFreeDoc(doc); |
| 8069 | return (-1); |
| 8070 | } |
| 8071 | |
| 8072 | memset(include, 0, sizeof(xmlSchemaInclude)); |
| 8073 | include->schemaLocation = xmlDictLookup(ctxt->dict, schemaLocation, -1); |
| 8074 | include->doc = doc; |
| 8075 | include->next = schema->includes; |
| 8076 | schema->includes = include; |
| 8077 | |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8078 | /* |
| 8079 | * parse the declarations in the included file like if they |
| 8080 | * were in the original file. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8081 | */ |
| 8082 | /* |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8083 | * TODO: The complete validation of the <schema> element is not done. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8084 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8085 | /* |
| 8086 | * The default values ("blockDefault", "elementFormDefault", etc.) |
| 8087 | * are set to the values of the included schema and restored afterwards. |
| 8088 | */ |
| 8089 | saveFlags = schema->flags; |
| 8090 | xmlSchemaClearSchemaDefaults(schema); |
| 8091 | xmlSchemaParseSchemaDefaults(ctxt, schema, root); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8092 | xmlSchemaParseSchemaTopLevel(ctxt, schema, root->children); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8093 | schema->flags = saveFlags; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8094 | /* |
| 8095 | * Remove the converting flag. |
| 8096 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8097 | if ((wasConvertingNs == 0) && |
| 8098 | (schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS)) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8099 | schema->flags ^= XML_SCHEMAS_INCLUDING_CONVERT_NS; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 8100 | return (1); |
| 8101 | } |
| 8102 | |
| 8103 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8104 | * xmlSchemaParseChoice: |
| 8105 | * @ctxt: a schema validation context |
| 8106 | * @schema: the schema being built |
| 8107 | * @node: a subtree containing XML Schema informations |
| 8108 | * |
| 8109 | * parse a XML schema Choice definition |
| 8110 | * *WARNING* this interface is highly subject to change |
| 8111 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 8112 | * 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] | 8113 | * 1 in case of success. |
| 8114 | */ |
| 8115 | static xmlSchemaTypePtr |
| 8116 | xmlSchemaParseChoice(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8117 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8118 | { |
| 8119 | xmlSchemaTypePtr type, subtype, last = NULL; |
| 8120 | xmlNodePtr child = NULL; |
| 8121 | xmlChar name[30]; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8122 | xmlAttrPtr attr; |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 8123 | const xmlChar *oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8124 | |
| 8125 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 8126 | return (NULL); |
| 8127 | |
| 8128 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 8129 | snprintf((char *) name, 30, "#ch%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8130 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8131 | if (type == NULL) |
| 8132 | return (NULL); |
| 8133 | type->node = node; |
| 8134 | type->type = XML_SCHEMA_TYPE_CHOICE; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8135 | /* |
| 8136 | * Check for illegal attributes. |
| 8137 | */ |
| 8138 | attr = node->properties; |
| 8139 | while (attr != NULL) { |
| 8140 | if (attr->ns == NULL) { |
| 8141 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 8142 | (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) && |
| 8143 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs"))) { |
| 8144 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8145 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8146 | NULL, type, attr); |
| 8147 | } |
| 8148 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 8149 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8150 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8151 | NULL, type, attr); |
| 8152 | } |
| 8153 | attr = attr->next; |
| 8154 | } |
| 8155 | /* |
| 8156 | * Extract and validate attributes. |
| 8157 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 8158 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 8159 | type->minOccurs = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "nonNegativeInteger"); |
| 8160 | type->maxOccurs = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, |
| 8161 | "(nonNegativeInteger | unbounded)"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8162 | /* |
| 8163 | * And now for the children... |
| 8164 | */ |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 8165 | oldcontainer = ctxt->container; |
| 8166 | ctxt->container = (const xmlChar *) name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8167 | child = node->children; |
| 8168 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8169 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 8170 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8171 | } |
| 8172 | while ((IS_SCHEMA(child, "element")) || |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8173 | (IS_SCHEMA(child, "group")) || |
| 8174 | (IS_SCHEMA(child, "any")) || |
| 8175 | (IS_SCHEMA(child, "choice")) || |
| 8176 | (IS_SCHEMA(child, "sequence"))) { |
| 8177 | subtype = NULL; |
| 8178 | if (IS_SCHEMA(child, "element")) { |
| 8179 | subtype = (xmlSchemaTypePtr) |
| 8180 | xmlSchemaParseElement(ctxt, schema, child, 0); |
| 8181 | } else if (IS_SCHEMA(child, "group")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 8182 | subtype = xmlSchemaParseGroup(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8183 | } else if (IS_SCHEMA(child, "any")) { |
| 8184 | subtype = xmlSchemaParseAny(ctxt, schema, child); |
| 8185 | } else if (IS_SCHEMA(child, "sequence")) { |
| 8186 | subtype = xmlSchemaParseSequence(ctxt, schema, child); |
| 8187 | } else if (IS_SCHEMA(child, "choice")) { |
| 8188 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 8189 | } |
| 8190 | if (subtype != NULL) { |
| 8191 | if (last == NULL) { |
| 8192 | type->subtypes = subtype; |
| 8193 | last = subtype; |
| 8194 | } else { |
| 8195 | last->next = subtype; |
| 8196 | last = subtype; |
| 8197 | } |
| 8198 | last->next = NULL; |
| 8199 | } |
| 8200 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8201 | } |
| 8202 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8203 | /* TODO: error code. */ |
| 8204 | xmlSchemaPContentErr(ctxt, |
| 8205 | XML_SCHEMAP_UNKNOWN_CHOICE_CHILD, |
| 8206 | NULL, type, node, child, NULL, |
| 8207 | "(annotation?, (element | group | choice | sequence | any)*)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8208 | } |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 8209 | ctxt->container = oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8210 | return (type); |
| 8211 | } |
| 8212 | |
| 8213 | /** |
| 8214 | * xmlSchemaParseSequence: |
| 8215 | * @ctxt: a schema validation context |
| 8216 | * @schema: the schema being built |
| 8217 | * @node: a subtree containing XML Schema informations |
| 8218 | * |
| 8219 | * parse a XML schema Sequence definition |
| 8220 | * *WARNING* this interface is highly subject to change |
| 8221 | * |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 8222 | * 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] | 8223 | * 1 in case of success. |
| 8224 | */ |
| 8225 | static xmlSchemaTypePtr |
| 8226 | xmlSchemaParseSequence(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8227 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8228 | { |
| 8229 | xmlSchemaTypePtr type, subtype, last = NULL; |
| 8230 | xmlNodePtr child = NULL; |
| 8231 | xmlChar name[30]; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8232 | xmlAttrPtr attr; |
| 8233 | const xmlChar *oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8234 | |
| 8235 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 8236 | return (NULL); |
| 8237 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8238 | oldcontainer = ctxt->container; |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 8239 | snprintf((char *) name, 30, "#seq%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8240 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8241 | if (type == NULL) |
| 8242 | return (NULL); |
| 8243 | type->node = node; |
| 8244 | type->type = XML_SCHEMA_TYPE_SEQUENCE; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8245 | /* |
| 8246 | * Check for illegal attributes. |
| 8247 | */ |
| 8248 | attr = node->properties; |
| 8249 | while (attr != NULL) { |
| 8250 | if (attr->ns == NULL) { |
| 8251 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 8252 | (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) && |
| 8253 | (!xmlStrEqual(attr->name, BAD_CAST "minOccurs"))) { |
| 8254 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8255 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8256 | NULL, type, attr); |
| 8257 | } |
| 8258 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 8259 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8260 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8261 | NULL, type, attr); |
| 8262 | } |
| 8263 | attr = attr->next; |
| 8264 | } |
| 8265 | /* |
| 8266 | * Extract and validate attributes. |
| 8267 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 8268 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 8269 | type->minOccurs = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "nonNegativeInteger"); |
| 8270 | type->maxOccurs = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, |
| 8271 | "(nonNegativeInteger | unbounded)"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8272 | /* |
| 8273 | * And now for the children... |
| 8274 | */ |
| 8275 | ctxt->container = (const xmlChar *) name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8276 | child = node->children; |
| 8277 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8278 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 8279 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8280 | } |
| 8281 | while ((IS_SCHEMA(child, "element")) || |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8282 | (IS_SCHEMA(child, "group")) || |
| 8283 | (IS_SCHEMA(child, "any")) || |
| 8284 | (IS_SCHEMA(child, "choice")) || |
| 8285 | (IS_SCHEMA(child, "sequence"))) { |
| 8286 | subtype = NULL; |
| 8287 | if (IS_SCHEMA(child, "element")) { |
| 8288 | subtype = (xmlSchemaTypePtr) |
| 8289 | xmlSchemaParseElement(ctxt, schema, child, 0); |
| 8290 | } else if (IS_SCHEMA(child, "group")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 8291 | subtype = xmlSchemaParseGroup(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8292 | } else if (IS_SCHEMA(child, "any")) { |
| 8293 | subtype = xmlSchemaParseAny(ctxt, schema, child); |
| 8294 | } else if (IS_SCHEMA(child, "choice")) { |
| 8295 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 8296 | } else if (IS_SCHEMA(child, "sequence")) { |
| 8297 | subtype = xmlSchemaParseSequence(ctxt, schema, child); |
| 8298 | } |
| 8299 | if (subtype != NULL) { |
| 8300 | if (last == NULL) { |
| 8301 | type->subtypes = subtype; |
| 8302 | last = subtype; |
| 8303 | } else { |
| 8304 | last->next = subtype; |
| 8305 | last = subtype; |
| 8306 | } |
| 8307 | last->next = NULL; |
| 8308 | } |
| 8309 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8310 | } |
| 8311 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8312 | xmlSchemaPContentErr(ctxt, |
| 8313 | XML_SCHEMAP_UNKNOWN_SEQUENCE_CHILD, |
| 8314 | NULL, type, node, child, NULL, |
| 8315 | "(annotation?, (element | group | choice | sequence | any)*)"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8316 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8317 | ctxt->container = oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8318 | |
| 8319 | return (type); |
| 8320 | } |
| 8321 | |
| 8322 | /** |
| 8323 | * xmlSchemaParseRestriction: |
| 8324 | * @ctxt: a schema validation context |
| 8325 | * @schema: the schema being built |
| 8326 | * @node: a subtree containing XML Schema informations |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8327 | * |
| 8328 | * parse a XML schema Restriction definition |
| 8329 | * *WARNING* this interface is highly subject to change |
| 8330 | * |
| 8331 | * Returns the type definition or NULL in case of error |
| 8332 | */ |
| 8333 | static xmlSchemaTypePtr |
| 8334 | xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 8335 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8336 | { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8337 | xmlSchemaTypePtr type, subtype; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8338 | xmlNodePtr child = NULL; |
| 8339 | xmlChar name[30]; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 8340 | const xmlChar *oldcontainer; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8341 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8342 | |
| 8343 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 8344 | return (NULL); |
| 8345 | |
| 8346 | oldcontainer = ctxt->container; |
| 8347 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 8348 | snprintf((char *) name, 30, "#restr%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8349 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8350 | if (type == NULL) |
| 8351 | return (NULL); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 8352 | type->type = XML_SCHEMA_TYPE_RESTRICTION; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8353 | type->node = node; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8354 | /* |
| 8355 | * Check for illegal attributes. |
| 8356 | */ |
| 8357 | attr = node->properties; |
| 8358 | while (attr != NULL) { |
| 8359 | if (attr->ns == NULL) { |
| 8360 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 8361 | (!xmlStrEqual(attr->name, BAD_CAST "base"))) { |
| 8362 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8363 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8364 | NULL, type, attr); |
| 8365 | } |
| 8366 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 8367 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8368 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8369 | NULL, type, attr); |
| 8370 | } |
| 8371 | attr = attr->next; |
| 8372 | } |
| 8373 | /* |
| 8374 | * Extract and validate attributes. |
| 8375 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 8376 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8377 | /* |
| 8378 | * Attribute "base". |
| 8379 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8380 | type->base = xmlGetQNameProp(ctxt, node, "base", &(type->baseNs)); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8381 | if ((type->base == NULL) && |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8382 | (ctxt->ctxtType->type == XML_SCHEMA_TYPE_COMPLEX)) { |
| 8383 | /* TODO: Think about the error code. */ |
| 8384 | xmlSchemaPMissingAttrErr(ctxt, |
| 8385 | XML_SCHEMAP_RESTRICTION_NONAME_NOREF, |
| 8386 | NULL, type, node, "base", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8387 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8388 | /* |
| 8389 | * And now for the children... |
| 8390 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8391 | ctxt->container = name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8392 | child = node->children; |
| 8393 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8394 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 8395 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8396 | } |
| 8397 | subtype = NULL; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8398 | if (ctxt->parentItem->type == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
| 8399 | if (IS_SCHEMA(child, "all")) { |
| 8400 | subtype = (xmlSchemaTypePtr) |
| 8401 | xmlSchemaParseAll(ctxt, schema, child); |
| 8402 | child = child->next; |
| 8403 | type->subtypes = subtype; |
| 8404 | } else if (IS_SCHEMA(child, "choice")) { |
| 8405 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 8406 | child = child->next; |
| 8407 | type->subtypes = subtype; |
| 8408 | } else if (IS_SCHEMA(child, "sequence")) { |
| 8409 | subtype = (xmlSchemaTypePtr) |
| 8410 | xmlSchemaParseSequence(ctxt, schema, child); |
| 8411 | child = child->next; |
| 8412 | type->subtypes = subtype; |
| 8413 | } else if (IS_SCHEMA(child, "group")) { |
| 8414 | subtype = (xmlSchemaTypePtr) |
| 8415 | xmlSchemaParseGroup(ctxt, schema, child, 0); |
| 8416 | child = child->next; |
| 8417 | type->subtypes = subtype; |
| 8418 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8419 | } else if (ctxt->ctxtType->type == XML_SCHEMA_TYPE_SIMPLE) { |
| 8420 | if (IS_SCHEMA(child, "simpleType")) { |
| 8421 | if (type->base != NULL) { |
| 8422 | /* |
| 8423 | * src-restriction-base-or-simpleType |
| 8424 | * Either the base [attribute] or the simpleType [child] of the |
| 8425 | * <restriction> element must be present, but not both. |
| 8426 | */ |
| 8427 | xmlSchemaPContentErr(ctxt, |
| 8428 | XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE, |
| 8429 | NULL, NULL, type->node, child, |
| 8430 | "The attribute 'base' and the <simpleType> child are " |
| 8431 | "mutually exclusive", NULL); |
| 8432 | } else { |
| 8433 | subtype = (xmlSchemaTypePtr) |
| 8434 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
| 8435 | type->baseType = subtype; |
| 8436 | } |
| 8437 | child = child->next; |
| 8438 | } |
| 8439 | } else if (ctxt->parentItem->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8440 | if (IS_SCHEMA(child, "simpleType")) { |
| 8441 | subtype = (xmlSchemaTypePtr) |
| 8442 | xmlSchemaParseSimpleType(ctxt, schema, child, 0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8443 | type->subtypes = subtype; |
| 8444 | child = child->next; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8445 | } |
| 8446 | } |
| 8447 | if ((ctxt->ctxtType->type == XML_SCHEMA_TYPE_SIMPLE) || |
| 8448 | (ctxt->parentItem->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT)) { |
| 8449 | xmlSchemaFacetPtr facet, lastfacet = NULL; |
| 8450 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8451 | /* |
| 8452 | * Add the facets to the parent simpleType/complexType. |
| 8453 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8454 | /* |
| 8455 | * TODO: Datatypes: 4.1.3 Constraints on XML Representation of |
| 8456 | * Simple Type Definition Schema Representation Constraint: |
| 8457 | * *Single Facet Value* |
| 8458 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8459 | while ((IS_SCHEMA(child, "minInclusive")) || |
| 8460 | (IS_SCHEMA(child, "minExclusive")) || |
| 8461 | (IS_SCHEMA(child, "maxInclusive")) || |
| 8462 | (IS_SCHEMA(child, "maxExclusive")) || |
| 8463 | (IS_SCHEMA(child, "totalDigits")) || |
| 8464 | (IS_SCHEMA(child, "fractionDigits")) || |
| 8465 | (IS_SCHEMA(child, "pattern")) || |
| 8466 | (IS_SCHEMA(child, "enumeration")) || |
| 8467 | (IS_SCHEMA(child, "whiteSpace")) || |
| 8468 | (IS_SCHEMA(child, "length")) || |
| 8469 | (IS_SCHEMA(child, "maxLength")) || |
| 8470 | (IS_SCHEMA(child, "minLength"))) { |
| 8471 | facet = xmlSchemaParseFacet(ctxt, schema, child); |
| 8472 | if (facet != NULL) { |
| 8473 | if (lastfacet == NULL) |
| 8474 | ctxt->ctxtType->facets = facet; |
| 8475 | else |
| 8476 | lastfacet->next = facet; |
| 8477 | lastfacet = facet; |
| 8478 | lastfacet->next = NULL; |
| 8479 | } |
| 8480 | child = child->next; |
| 8481 | } |
| 8482 | /* |
| 8483 | * Create links for derivation and validation. |
| 8484 | */ |
| 8485 | if (lastfacet != NULL) { |
| 8486 | xmlSchemaFacetLinkPtr facetLink, lastFacetLink = NULL; |
| 8487 | |
| 8488 | facet = ctxt->ctxtType->facets; |
| 8489 | do { |
| 8490 | facetLink = (xmlSchemaFacetLinkPtr) xmlMalloc(sizeof(xmlSchemaFacetLink)); |
| 8491 | if (facetLink == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8492 | xmlSchemaPErrMemory(ctxt, "allocating a facet link", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8493 | xmlFree(facetLink); |
| 8494 | return (NULL); |
| 8495 | } |
| 8496 | facetLink->facet = facet; |
| 8497 | facetLink->next = NULL; |
| 8498 | if (lastFacetLink == NULL) |
| 8499 | ctxt->ctxtType->facetSet = facetLink; |
| 8500 | else |
| 8501 | lastFacetLink->next = facetLink; |
| 8502 | lastFacetLink = facetLink; |
| 8503 | facet = facet->next; |
| 8504 | } while (facet != NULL); |
| 8505 | } |
| 8506 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8507 | if (ctxt->ctxtType->type == XML_SCHEMA_TYPE_COMPLEX) { |
| 8508 | child = xmlSchemaParseAttrDecls(ctxt, schema, child, type); |
| 8509 | if (IS_SCHEMA(child, "anyAttribute")) { |
| 8510 | ctxt->ctxtType->attributeWildcard = xmlSchemaParseAnyAttribute(ctxt, schema, child); |
| 8511 | child = child->next; |
| 8512 | } |
| 8513 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8514 | if (child != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8515 | /* TODO: Think about the error code. */ |
| 8516 | if (ctxt->parentItem->type == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
| 8517 | xmlSchemaPContentErr(ctxt, |
| 8518 | XML_SCHEMAP_UNKNOWN_RESTRICTION_CHILD, |
| 8519 | NULL, type, node, child, NULL, |
| 8520 | "annotation?, (group | all | choice | sequence)?, " |
| 8521 | "((attribute | attributeGroup)*, anyAttribute?))"); |
| 8522 | } else if (ctxt->parentItem->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT) { |
| 8523 | xmlSchemaPContentErr(ctxt, |
| 8524 | XML_SCHEMAP_UNKNOWN_RESTRICTION_CHILD, |
| 8525 | NULL, type, node, child, NULL, |
| 8526 | "(annotation?, (simpleType?, (minExclusive | minInclusive | " |
| 8527 | "maxExclusive | maxInclusive | totalDigits | fractionDigits | " |
| 8528 | "length | minLength | maxLength | enumeration | whiteSpace | " |
| 8529 | "pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))"); |
| 8530 | } else { |
| 8531 | /* Simple type */ |
| 8532 | xmlSchemaPContentErr(ctxt, |
| 8533 | XML_SCHEMAP_UNKNOWN_RESTRICTION_CHILD, |
| 8534 | NULL, type, node, child, NULL, |
| 8535 | "(annotation?, (simpleType?, (minExclusive | minInclusive | " |
| 8536 | "maxExclusive | maxInclusive | totalDigits | fractionDigits | " |
| 8537 | "length | minLength | maxLength | enumeration | whiteSpace | " |
| 8538 | "pattern)*))"); |
| 8539 | } |
| 8540 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8541 | ctxt->container = oldcontainer; |
| 8542 | return (type); |
| 8543 | } |
| 8544 | |
| 8545 | /** |
| 8546 | * xmlSchemaParseExtension: |
| 8547 | * @ctxt: a schema validation context |
| 8548 | * @schema: the schema being built |
| 8549 | * @node: a subtree containing XML Schema informations |
| 8550 | * |
| 8551 | * parse a XML schema Extension definition |
| 8552 | * *WARNING* this interface is highly subject to change |
| 8553 | * |
| 8554 | * Returns the type definition or NULL in case of error |
| 8555 | */ |
| 8556 | static xmlSchemaTypePtr |
| 8557 | xmlSchemaParseExtension(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8558 | xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8559 | { |
| 8560 | xmlSchemaTypePtr type, subtype; |
| 8561 | xmlNodePtr child = NULL; |
| 8562 | xmlChar name[30]; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 8563 | const xmlChar *oldcontainer; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8564 | |
| 8565 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 8566 | return (NULL); |
| 8567 | |
| 8568 | oldcontainer = ctxt->container; |
| 8569 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 8570 | snprintf((char *) name, 30, "#ext%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8571 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8572 | if (type == NULL) |
| 8573 | return (NULL); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 8574 | type->type = XML_SCHEMA_TYPE_EXTENSION; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8575 | type->node = node; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 8576 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8577 | ctxt->container = name; |
| 8578 | |
| 8579 | type->base = xmlGetQNameProp(ctxt, node, "base", &(type->baseNs)); |
| 8580 | if (type->base == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8581 | xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_EXTENSION_NO_BASE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8582 | "<extension>: The attribute \"base\" is missing.\n", |
| 8583 | type->name, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8584 | } |
| 8585 | child = node->children; |
| 8586 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8587 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 8588 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8589 | } |
| 8590 | subtype = NULL; |
| 8591 | |
| 8592 | if (IS_SCHEMA(child, "all")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8593 | subtype = xmlSchemaParseAll(ctxt, schema, child); |
| 8594 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8595 | } else if (IS_SCHEMA(child, "choice")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8596 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 8597 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8598 | } else if (IS_SCHEMA(child, "sequence")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8599 | subtype = xmlSchemaParseSequence(ctxt, schema, child); |
| 8600 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8601 | } else if (IS_SCHEMA(child, "group")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 8602 | subtype = xmlSchemaParseGroup(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8603 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8604 | } |
| 8605 | if (subtype != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8606 | type->subtypes = subtype; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8607 | if ((ctxt->ctxtType != NULL) && |
| 8608 | (ctxt->ctxtType->type == XML_SCHEMA_TYPE_COMPLEX)) { |
| 8609 | child = xmlSchemaParseAttrDecls(ctxt, schema, child, type); |
| 8610 | if (IS_SCHEMA(child, "anyAttribute")) { |
| 8611 | ctxt->ctxtType->attributeWildcard = |
| 8612 | xmlSchemaParseAnyAttribute(ctxt, schema, child); |
| 8613 | child = child->next; |
| 8614 | } |
| 8615 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8616 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8617 | xmlSchemaPErr2(ctxt, node, child, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8618 | XML_SCHEMAP_UNKNOWN_EXTENSION_CHILD, |
| 8619 | "<extension> has unexpected content.\n", type->name, |
| 8620 | NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8621 | } |
| 8622 | ctxt->container = oldcontainer; |
| 8623 | return (type); |
| 8624 | } |
| 8625 | |
| 8626 | /** |
| 8627 | * xmlSchemaParseSimpleContent: |
| 8628 | * @ctxt: a schema validation context |
| 8629 | * @schema: the schema being built |
| 8630 | * @node: a subtree containing XML Schema informations |
| 8631 | * |
| 8632 | * parse a XML schema SimpleContent definition |
| 8633 | * *WARNING* this interface is highly subject to change |
| 8634 | * |
| 8635 | * Returns the type definition or NULL in case of error |
| 8636 | */ |
| 8637 | static xmlSchemaTypePtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8638 | xmlSchemaParseSimpleContent(xmlSchemaParserCtxtPtr ctxt, |
| 8639 | xmlSchemaPtr schema, xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8640 | { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8641 | xmlSchemaTypePtr type, subtype, oldParentItem; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8642 | xmlNodePtr child = NULL; |
| 8643 | xmlChar name[30]; |
| 8644 | |
| 8645 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 8646 | return (NULL); |
| 8647 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 8648 | snprintf((char *) name, 30, "#SC%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8649 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8650 | if (type == NULL) |
| 8651 | return (NULL); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 8652 | type->type = XML_SCHEMA_TYPE_SIMPLE_CONTENT; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8653 | type->node = node; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 8654 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8655 | |
| 8656 | child = node->children; |
| 8657 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8658 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 8659 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8660 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8661 | oldParentItem = ctxt->parentItem; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8662 | ctxt->parentItem = type; |
| 8663 | subtype = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8664 | if (IS_SCHEMA(child, "restriction")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8665 | subtype = (xmlSchemaTypePtr) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 8666 | xmlSchemaParseRestriction(ctxt, schema, child); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8667 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8668 | } else if (IS_SCHEMA(child, "extension")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8669 | subtype = (xmlSchemaTypePtr) |
| 8670 | xmlSchemaParseExtension(ctxt, schema, child); |
| 8671 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8672 | } |
| 8673 | type->subtypes = subtype; |
| 8674 | if (child != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8675 | xmlSchemaPErr2(ctxt, node, child, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 8676 | XML_SCHEMAP_UNKNOWN_SIMPLECONTENT_CHILD, |
| 8677 | "<simpleContent> has unexpected content.\n", |
| 8678 | NULL, NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8679 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8680 | ctxt->parentItem = oldParentItem; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8681 | return (type); |
| 8682 | } |
| 8683 | |
| 8684 | /** |
| 8685 | * xmlSchemaParseComplexContent: |
| 8686 | * @ctxt: a schema validation context |
| 8687 | * @schema: the schema being built |
| 8688 | * @node: a subtree containing XML Schema informations |
| 8689 | * |
| 8690 | * parse a XML schema ComplexContent definition |
| 8691 | * *WARNING* this interface is highly subject to change |
| 8692 | * |
| 8693 | * Returns the type definition or NULL in case of error |
| 8694 | */ |
| 8695 | static xmlSchemaTypePtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8696 | xmlSchemaParseComplexContent(xmlSchemaParserCtxtPtr ctxt, |
| 8697 | xmlSchemaPtr schema, xmlNodePtr node) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8698 | { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8699 | xmlSchemaTypePtr type, subtype, oldParentItem; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8700 | xmlNodePtr child = NULL; |
| 8701 | xmlChar name[30]; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8702 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8703 | |
| 8704 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 8705 | return (NULL); |
| 8706 | |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 8707 | snprintf((char *) name, 30, "#CC%d", ctxt->counter++ + 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8708 | type = xmlSchemaAddType(ctxt, schema, name, NULL, node); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8709 | if (type == NULL) |
| 8710 | return (NULL); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 8711 | type->type = XML_SCHEMA_TYPE_COMPLEX_CONTENT; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8712 | type->node = node; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8713 | /* |
| 8714 | * Check for illegal attributes. |
| 8715 | */ |
| 8716 | attr = node->properties; |
| 8717 | while (attr != NULL) { |
| 8718 | if (attr->ns == NULL) { |
| 8719 | if ((!xmlStrEqual(attr->name, BAD_CAST "id")) && |
| 8720 | (!xmlStrEqual(attr->name, BAD_CAST "mixed"))) |
| 8721 | { |
| 8722 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8723 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8724 | NULL, NULL, attr); |
| 8725 | } |
| 8726 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 8727 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8728 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8729 | NULL, NULL, attr); |
| 8730 | } |
| 8731 | attr = attr->next; |
| 8732 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 8733 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8734 | /* |
| 8735 | * Handle attribute 'mixed'. |
| 8736 | */ |
| 8737 | if (xmlGetBooleanProp(ctxt, NULL, type, node, "mixed", 0)) { |
| 8738 | if ((ctxt->ctxtType->flags & XML_SCHEMAS_TYPE_MIXED) == 0) |
| 8739 | ctxt->ctxtType->flags |= XML_SCHEMAS_TYPE_MIXED; |
| 8740 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8741 | child = node->children; |
| 8742 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8743 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 8744 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8745 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8746 | oldParentItem = ctxt->parentItem; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8747 | ctxt->parentItem = type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8748 | subtype = NULL; |
| 8749 | if (IS_SCHEMA(child, "restriction")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8750 | subtype = (xmlSchemaTypePtr) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 8751 | xmlSchemaParseRestriction(ctxt, schema, child); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8752 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8753 | } else if (IS_SCHEMA(child, "extension")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8754 | subtype = (xmlSchemaTypePtr) |
| 8755 | xmlSchemaParseExtension(ctxt, schema, child); |
| 8756 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8757 | } |
| 8758 | type->subtypes = subtype; |
| 8759 | if (child != NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8760 | xmlSchemaPContentErr(ctxt, |
| 8761 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 8762 | NULL, NULL, node, child, |
| 8763 | NULL, "(annotation?, (restriction | extension))"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8764 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8765 | ctxt->parentItem = oldParentItem; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8766 | return (type); |
| 8767 | } |
| 8768 | |
| 8769 | /** |
| 8770 | * xmlSchemaParseComplexType: |
| 8771 | * @ctxt: a schema validation context |
| 8772 | * @schema: the schema being built |
| 8773 | * @node: a subtree containing XML Schema informations |
| 8774 | * |
| 8775 | * parse a XML schema Complex Type definition |
| 8776 | * *WARNING* this interface is highly subject to change |
| 8777 | * |
| 8778 | * Returns the type definition or NULL in case of error |
| 8779 | */ |
| 8780 | static xmlSchemaTypePtr |
| 8781 | xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 8782 | xmlNodePtr node, int topLevel) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8783 | { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8784 | xmlSchemaTypePtr type, subtype, ctxtType; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8785 | xmlNodePtr child = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8786 | const xmlChar *name = NULL; |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 8787 | const xmlChar *oldcontainer; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8788 | xmlAttrPtr attr; |
| 8789 | const xmlChar *attrValue; |
| 8790 | xmlChar *des = NULL; /* The reported designation. */ |
Daniel Veillard | 1a380b8 | 2004-10-21 16:00:06 +0000 | [diff] [blame] | 8791 | char buf[40]; |
| 8792 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8793 | |
| 8794 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL)) |
| 8795 | return (NULL); |
| 8796 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8797 | ctxtType = ctxt->ctxtType; |
| 8798 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8799 | if (topLevel) { |
| 8800 | attr = xmlSchemaGetPropNode(node, "name"); |
| 8801 | if (attr == NULL) { |
| 8802 | xmlSchemaPMissingAttrErr(ctxt, |
| 8803 | XML_SCHEMAP_S4S_ATTR_MISSING, |
| 8804 | (xmlChar **) &xmlSchemaElemDesCT, NULL, node, |
| 8805 | "name", NULL); |
| 8806 | return (NULL); |
| 8807 | } else if (xmlSchemaPValAttrNode(ctxt, |
| 8808 | (xmlChar **) &xmlSchemaElemDesCT, NULL, attr, |
| 8809 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) { |
| 8810 | return (NULL); |
| 8811 | } |
| 8812 | } |
| 8813 | |
| 8814 | if (topLevel == 0) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8815 | /* |
| 8816 | * Parse as local complex type definition. |
| 8817 | */ |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 8818 | snprintf(buf, 39, "#CT%d", ctxt->counter++ + 1); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8819 | type = xmlSchemaAddType(ctxt, schema, (const xmlChar *)buf, NULL, node); |
| 8820 | if (type == NULL) |
| 8821 | return (NULL); |
| 8822 | name = (const xmlChar *) buf; |
| 8823 | type->node = node; |
| 8824 | type->type = XML_SCHEMA_TYPE_COMPLEX; |
| 8825 | /* |
| 8826 | * TODO: We need the target namespace. |
| 8827 | */ |
| 8828 | } else { |
| 8829 | /* |
| 8830 | * Parse as global complex type definition. |
| 8831 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 8832 | type = xmlSchemaAddType(ctxt, schema, name, schema->targetNamespace, node); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8833 | if (type == NULL) |
| 8834 | return (NULL); |
| 8835 | type->node = node; |
| 8836 | type->type = XML_SCHEMA_TYPE_COMPLEX; |
| 8837 | type->flags |= XML_SCHEMAS_TYPE_GLOBAL; |
| 8838 | /* |
| 8839 | * Set defaults. |
| 8840 | */ |
| 8841 | type->flags |= XML_SCHEMAS_TYPE_FINAL_DEFAULT; |
| 8842 | type->flags |= XML_SCHEMAS_TYPE_BLOCK_DEFAULT; |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 8843 | } |
| 8844 | type->targetNamespace = schema->targetNamespace; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8845 | /* |
| 8846 | * Handle attributes. |
| 8847 | */ |
| 8848 | attr = node->properties; |
| 8849 | while (attr != NULL) { |
| 8850 | if (attr->ns == NULL) { |
| 8851 | if (xmlStrEqual(attr->name, BAD_CAST "id")) { |
| 8852 | /* |
| 8853 | * Attribute "id". |
| 8854 | */ |
| 8855 | type->id = xmlSchemaGetProp(ctxt, node, "id"); |
| 8856 | } else if (xmlStrEqual(attr->name, BAD_CAST "mixed")) { |
| 8857 | /* |
| 8858 | * Attribute "mixed". |
| 8859 | */ |
| 8860 | if (xmlSchemaPGetBoolNodeValue(ctxt, &des, type, |
| 8861 | (xmlNodePtr) attr)) |
| 8862 | type->flags |= XML_SCHEMAS_TYPE_MIXED; |
| 8863 | } else if (topLevel) { |
| 8864 | /* |
| 8865 | * Attributes of global complex type definitions. |
| 8866 | */ |
| 8867 | if (xmlStrEqual(attr->name, BAD_CAST "name")) { |
| 8868 | /* Pass. */ |
| 8869 | } else if (xmlStrEqual(attr->name, BAD_CAST "abstract")) { |
| 8870 | /* |
| 8871 | * Attribute "abstract". |
| 8872 | */ |
| 8873 | if (xmlSchemaPGetBoolNodeValue(ctxt, &des, type, |
| 8874 | (xmlNodePtr) attr)) |
| 8875 | type->flags |= XML_SCHEMAS_TYPE_ABSTRACT; |
| 8876 | } else if (xmlStrEqual(attr->name, BAD_CAST "final")) { |
| 8877 | /* |
| 8878 | * Attribute "final". |
| 8879 | */ |
| 8880 | attrValue = xmlSchemaGetNodeContent(ctxt, |
| 8881 | (xmlNodePtr) attr); |
| 8882 | if (xmlSchemaPValAttrBlockFinal(attrValue, |
| 8883 | &(type->flags), |
| 8884 | -1, |
| 8885 | XML_SCHEMAS_TYPE_FINAL_EXTENSION, |
| 8886 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION, |
| 8887 | -1, -1, -1) != 0) |
| 8888 | { |
| 8889 | xmlSchemaPSimpleTypeErr(ctxt, |
| 8890 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 8891 | &des, type, (xmlNodePtr) attr, |
| 8892 | NULL, |
| 8893 | "(#all | List of (extension | restriction))", |
| 8894 | attrValue, NULL, NULL, NULL); |
| 8895 | } |
| 8896 | } else if (xmlStrEqual(attr->name, BAD_CAST "block")) { |
| 8897 | /* |
| 8898 | * Attribute "block". |
| 8899 | */ |
| 8900 | attrValue = xmlSchemaGetNodeContent(ctxt, |
| 8901 | (xmlNodePtr) attr); |
| 8902 | if (xmlSchemaPValAttrBlockFinal(attrValue, &(type->flags), |
| 8903 | -1, |
| 8904 | XML_SCHEMAS_TYPE_BLOCK_EXTENSION, |
| 8905 | XML_SCHEMAS_TYPE_BLOCK_RESTRICTION, |
| 8906 | -1, -1, -1) != 0) { |
| 8907 | xmlSchemaPSimpleTypeErr(ctxt, |
| 8908 | XML_SCHEMAP_S4S_ATTR_INVALID_VALUE, |
| 8909 | &des, type, (xmlNodePtr) attr, |
| 8910 | NULL, |
| 8911 | "(#all | List of (extension | restriction)) ", |
| 8912 | attrValue, NULL, NULL, NULL); |
| 8913 | } |
| 8914 | } else { |
| 8915 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8916 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8917 | &des, type, attr); |
| 8918 | } |
| 8919 | } else { |
| 8920 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8921 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8922 | &des, type, attr); |
| 8923 | } |
| 8924 | } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) { |
| 8925 | xmlSchemaPIllegalAttrErr(ctxt, |
| 8926 | XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, |
| 8927 | &des, type, attr); |
| 8928 | } |
| 8929 | attr = attr->next; |
| 8930 | } |
| 8931 | /* |
| 8932 | * Set as default for attribute wildcards. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8933 | * This will be only changed if a complex type |
| 8934 | * inherits an attribute wildcard from a base type. |
| 8935 | */ |
| 8936 | type->flags |= XML_SCHEMAS_TYPE_OWNED_ATTR_WILDCARD; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8937 | /* |
| 8938 | * And now for the children... |
| 8939 | */ |
| 8940 | oldcontainer = ctxt->container; |
| 8941 | ctxt->container = name; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8942 | child = node->children; |
| 8943 | if (IS_SCHEMA(child, "annotation")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8944 | type->annot = xmlSchemaParseAnnotation(ctxt, schema, child); |
| 8945 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8946 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 8947 | ctxt->ctxtType = type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8948 | if (IS_SCHEMA(child, "simpleContent")) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8949 | /* |
| 8950 | * 3.4.3 : 2.2 |
| 8951 | * Specifying mixed='true' when the <simpleContent> |
| 8952 | * alternative is chosen has no effect |
| 8953 | */ |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 8954 | if (type->flags & XML_SCHEMAS_TYPE_MIXED) |
| 8955 | type->flags ^= XML_SCHEMAS_TYPE_MIXED; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8956 | type->subtypes = xmlSchemaParseSimpleContent(ctxt, schema, child); |
| 8957 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8958 | } else if (IS_SCHEMA(child, "complexContent")) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8959 | type->subtypes = xmlSchemaParseComplexContent(ctxt, schema, child); |
| 8960 | child = child->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8961 | } else { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8962 | subtype = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8963 | /* |
| 8964 | * Parse model groups. |
| 8965 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8966 | if (IS_SCHEMA(child, "all")) { |
| 8967 | subtype = xmlSchemaParseAll(ctxt, schema, child); |
| 8968 | child = child->next; |
| 8969 | } else if (IS_SCHEMA(child, "choice")) { |
| 8970 | subtype = xmlSchemaParseChoice(ctxt, schema, child); |
| 8971 | child = child->next; |
| 8972 | } else if (IS_SCHEMA(child, "sequence")) { |
| 8973 | subtype = xmlSchemaParseSequence(ctxt, schema, child); |
| 8974 | child = child->next; |
| 8975 | } else if (IS_SCHEMA(child, "group")) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 8976 | subtype = xmlSchemaParseGroup(ctxt, schema, child, 0); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8977 | child = child->next; |
| 8978 | } |
| 8979 | if (subtype != NULL) |
| 8980 | type->subtypes = subtype; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8981 | /* |
| 8982 | * Parse attribute decls/refs. |
| 8983 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 8984 | child = xmlSchemaParseAttrDecls(ctxt, schema, child, type); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8985 | /* |
| 8986 | * Parse attribute wildcard. |
| 8987 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 8988 | if (IS_SCHEMA(child, "anyAttribute")) { |
| 8989 | type->attributeWildcard = xmlSchemaParseAnyAttribute(ctxt, schema, child); |
| 8990 | child = child->next; |
| 8991 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 8992 | } |
| 8993 | if (child != NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 8994 | xmlSchemaPContentErr(ctxt, |
| 8995 | XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED, |
| 8996 | &des, type, node, child, |
| 8997 | NULL, "(annotation?, (simpleContent | complexContent | " |
| 8998 | "((group | all | choice | sequence)?, ((attribute | " |
| 8999 | "attributeGroup)*, anyAttribute?))))"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9000 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9001 | FREE_AND_NULL(des); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9002 | ctxt->container = oldcontainer; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9003 | ctxt->ctxtType = ctxtType; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9004 | return (type); |
| 9005 | } |
| 9006 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9007 | /** |
| 9008 | * xmlSchemaParseSchema: |
| 9009 | * @ctxt: a schema validation context |
| 9010 | * @node: a subtree containing XML Schema informations |
| 9011 | * |
| 9012 | * parse a XML schema definition from a node set |
| 9013 | * *WARNING* this interface is highly subject to change |
| 9014 | * |
| 9015 | * Returns the internal XML Schema structure built from the resource or |
| 9016 | * NULL in case of error |
| 9017 | */ |
| 9018 | static xmlSchemaPtr |
| 9019 | xmlSchemaParseSchema(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node) |
| 9020 | { |
| 9021 | xmlSchemaPtr schema = NULL; |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 9022 | const xmlChar *val; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 9023 | int nberrors; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9024 | xmlAttrPtr attr; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9025 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9026 | /* |
| 9027 | * This one is called by xmlSchemaParse only and is used if |
| 9028 | * the schema to be parsed was specified via the API; i.e. not |
| 9029 | * automatically by the validated instance document. |
| 9030 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9031 | if ((ctxt == NULL) || (node == NULL)) |
| 9032 | return (NULL); |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 9033 | nberrors = ctxt->nberrors; |
| 9034 | ctxt->nberrors = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9035 | if (IS_SCHEMA(node, "schema")) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9036 | xmlSchemaImportPtr import; |
| 9037 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9038 | schema = xmlSchemaNewSchema(ctxt); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9039 | if (schema == NULL) |
| 9040 | return (NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9041 | /* |
| 9042 | * Disable build of list of items. |
| 9043 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9044 | attr = xmlSchemaGetPropNode(node, "targetNamespace"); |
| 9045 | if (attr != NULL) { |
| 9046 | xmlSchemaPValAttrNode(ctxt, NULL, NULL, attr, |
| 9047 | xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), &val); |
| 9048 | /* |
| 9049 | * TODO: Should we proceed with an invalid target namespace? |
| 9050 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 9051 | schema->targetNamespace = xmlDictLookup(ctxt->dict, val, -1); |
| 9052 | } else { |
| 9053 | schema->targetNamespace = NULL; |
| 9054 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9055 | /* |
| 9056 | * Add the current ns name and location to the import table; |
| 9057 | * this is needed to have a consistent mechanism, regardless |
| 9058 | * if all schemata are constructed dynamically fired by the |
| 9059 | * instance or if the schema to be used was specified via |
| 9060 | * the API. |
| 9061 | */ |
| 9062 | import = xmlSchemaAddImport(ctxt, &(schema->schemasImports), |
| 9063 | schema->targetNamespace); |
| 9064 | if (import == NULL) { |
| 9065 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_FAILED_BUILD_IMPORT, |
| 9066 | NULL, NULL, (xmlNodePtr) ctxt->doc, |
| 9067 | "Internal error: xmlSchemaParseSchema, " |
| 9068 | "failed to add an import entry", NULL); |
| 9069 | xmlSchemaFree(schema); |
| 9070 | schema = NULL; |
| 9071 | return (NULL); |
| 9072 | } |
| 9073 | import->schemaLocation = ctxt->URL; |
| 9074 | /* |
| 9075 | * NOTE: We won't set the doc here, otherwise it will be freed |
| 9076 | * if the import struct is freed. |
| 9077 | * import->doc = ctxt->doc; |
| 9078 | */ |
| 9079 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9080 | /* TODO: Check id. */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 9081 | schema->id = xmlSchemaGetProp(ctxt, node, "id"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9082 | xmlSchemaPValAttr(ctxt, NULL, NULL, node, "version", |
| 9083 | xmlSchemaGetBuiltInType(XML_SCHEMAS_TOKEN), &(schema->version)); |
| 9084 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9085 | xmlSchemaParseSchemaDefaults(ctxt, schema, node); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9086 | xmlSchemaParseSchemaTopLevel(ctxt, schema, node->children); |
| 9087 | } else { |
| 9088 | xmlDocPtr doc; |
| 9089 | |
| 9090 | doc = node->doc; |
| 9091 | |
| 9092 | if ((doc != NULL) && (doc->URL != NULL)) { |
| 9093 | xmlSchemaPErr(ctxt, (xmlNodePtr) doc, |
| 9094 | XML_SCHEMAP_NOT_SCHEMA, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9095 | "The file \"%s\" is not a XML schema.\n", doc->URL, NULL); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9096 | } else { |
| 9097 | xmlSchemaPErr(ctxt, (xmlNodePtr) doc, |
| 9098 | XML_SCHEMAP_NOT_SCHEMA, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9099 | "The file is not a XML schema.\n", NULL, NULL); |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 9100 | } |
| 9101 | return(NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9102 | } |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 9103 | if (ctxt->nberrors != 0) { |
| 9104 | if (schema != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9105 | xmlSchemaFree(schema); |
| 9106 | schema = NULL; |
| 9107 | } |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 9108 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9109 | if (schema != NULL) |
| 9110 | schema->counter = ctxt->counter; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 9111 | ctxt->nberrors = nberrors; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9112 | #ifdef DEBUG |
| 9113 | if (schema == NULL) |
| 9114 | xmlGenericError(xmlGenericErrorContext, |
| 9115 | "xmlSchemaParse() failed\n"); |
| 9116 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9117 | return (schema); |
| 9118 | } |
| 9119 | |
| 9120 | /************************************************************************ |
| 9121 | * * |
| 9122 | * Validating using Schemas * |
| 9123 | * * |
| 9124 | ************************************************************************/ |
| 9125 | |
| 9126 | /************************************************************************ |
| 9127 | * * |
| 9128 | * Reading/Writing Schemas * |
| 9129 | * * |
| 9130 | ************************************************************************/ |
| 9131 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9132 | #if 0 /* Will be enabled if it is clear what options are needed. */ |
| 9133 | /** |
| 9134 | * xmlSchemaParserCtxtSetOptions: |
| 9135 | * @ctxt: a schema parser context |
| 9136 | * @options: a combination of xmlSchemaParserOption |
| 9137 | * |
| 9138 | * Sets the options to be used during the parse. |
| 9139 | * |
| 9140 | * Returns 0 in case of success, -1 in case of an |
| 9141 | * API error. |
| 9142 | */ |
| 9143 | static int |
| 9144 | xmlSchemaParserCtxtSetOptions(xmlSchemaParserCtxtPtr ctxt, |
| 9145 | int options) |
| 9146 | |
| 9147 | { |
| 9148 | int i; |
| 9149 | |
| 9150 | if (ctxt == NULL) |
| 9151 | return (-1); |
| 9152 | /* |
| 9153 | * WARNING: Change the start value if adding to the |
| 9154 | * xmlSchemaParseOption. |
| 9155 | */ |
| 9156 | for (i = 1; i < (int) sizeof(int) * 8; i++) { |
| 9157 | if (options & 1<<i) { |
| 9158 | return (-1); |
| 9159 | } |
| 9160 | } |
| 9161 | ctxt->options = options; |
| 9162 | return (0); |
| 9163 | } |
| 9164 | |
| 9165 | /** |
| 9166 | * xmlSchemaValidCtxtGetOptions: |
| 9167 | * @ctxt: a schema parser context |
| 9168 | * |
| 9169 | * Returns the option combination of the parser context. |
| 9170 | */ |
| 9171 | static int |
| 9172 | xmlSchemaParserCtxtGetOptions(xmlSchemaParserCtxtPtr ctxt) |
| 9173 | |
| 9174 | { |
| 9175 | if (ctxt == NULL) |
| 9176 | return (-1); |
| 9177 | else |
| 9178 | return (ctxt->options); |
| 9179 | } |
| 9180 | |
| 9181 | void *curItems; /* used for dynamic addition of schemata */ |
| 9182 | int nbCurItems; /* used for dynamic addition of schemata */ |
| 9183 | int sizeCurItems; /* used for dynamic addition of schemata */ |
| 9184 | |
| 9185 | #endif |
| 9186 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9187 | /** |
| 9188 | * xmlSchemaNewParserCtxt: |
| 9189 | * @URL: the location of the schema |
| 9190 | * |
| 9191 | * Create an XML Schemas parse context for that file/resource expected |
| 9192 | * to contain an XML Schemas file. |
| 9193 | * |
| 9194 | * Returns the parser context or NULL in case of error |
| 9195 | */ |
| 9196 | xmlSchemaParserCtxtPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9197 | xmlSchemaNewParserCtxt(const char *URL) |
| 9198 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9199 | xmlSchemaParserCtxtPtr ret; |
| 9200 | |
| 9201 | if (URL == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9202 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9203 | |
| 9204 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 9205 | if (ret == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9206 | xmlSchemaPErrMemory(NULL, "allocating schema parser context", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9207 | NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9208 | return (NULL); |
| 9209 | } |
| 9210 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 9211 | ret->dict = xmlDictCreate(); |
| 9212 | ret->URL = xmlDictLookup(ret->dict, (const xmlChar *) URL, -1); |
Daniel Veillard | b0f397e | 2003-12-23 23:30:53 +0000 | [diff] [blame] | 9213 | ret->includes = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9214 | return (ret); |
| 9215 | } |
| 9216 | |
| 9217 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9218 | * xmlSchemaNewParserCtxtUseDict: |
| 9219 | * @URL: the location of the schema |
| 9220 | * @dict: the dictionary to be used |
| 9221 | * |
| 9222 | * Create an XML Schemas parse context for that file/resource expected |
| 9223 | * to contain an XML Schemas file. |
| 9224 | * |
| 9225 | * Returns the parser context or NULL in case of error |
| 9226 | */ |
| 9227 | static xmlSchemaParserCtxtPtr |
| 9228 | xmlSchemaNewParserCtxtUseDict(const char *URL, xmlDictPtr dict) |
| 9229 | { |
| 9230 | xmlSchemaParserCtxtPtr ret; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9231 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9232 | if (URL == NULL) |
| 9233 | return (NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9234 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9235 | |
| 9236 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 9237 | if (ret == NULL) { |
| 9238 | xmlSchemaPErrMemory(NULL, "allocating schema parser context", |
| 9239 | NULL); |
| 9240 | return (NULL); |
| 9241 | } |
| 9242 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
| 9243 | ret->dict = dict; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9244 | xmlDictReference(dict); |
| 9245 | if (URL != NULL) |
| 9246 | ret->URL = xmlDictLookup(dict, (const xmlChar *) URL, -1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9247 | ret->includes = 0; |
| 9248 | return (ret); |
| 9249 | } |
| 9250 | |
| 9251 | |
| 9252 | /** |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 9253 | * xmlSchemaNewMemParserCtxt: |
| 9254 | * @buffer: a pointer to a char array containing the schemas |
| 9255 | * @size: the size of the array |
| 9256 | * |
| 9257 | * Create an XML Schemas parse context for that memory buffer expected |
| 9258 | * to contain an XML Schemas file. |
| 9259 | * |
| 9260 | * Returns the parser context or NULL in case of error |
| 9261 | */ |
| 9262 | xmlSchemaParserCtxtPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9263 | xmlSchemaNewMemParserCtxt(const char *buffer, int size) |
| 9264 | { |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 9265 | xmlSchemaParserCtxtPtr ret; |
| 9266 | |
| 9267 | if ((buffer == NULL) || (size <= 0)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9268 | return (NULL); |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 9269 | |
| 9270 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 9271 | if (ret == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9272 | xmlSchemaPErrMemory(NULL, "allocating schema parser context", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9273 | NULL); |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 9274 | return (NULL); |
| 9275 | } |
| 9276 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
| 9277 | ret->buffer = buffer; |
| 9278 | ret->size = size; |
William M. Brack | cf9eadf | 2003-12-25 13:24:05 +0000 | [diff] [blame] | 9279 | ret->dict = xmlDictCreate(); |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 9280 | return (ret); |
| 9281 | } |
| 9282 | |
| 9283 | /** |
Daniel Veillard | 9d75150 | 2003-10-29 13:21:47 +0000 | [diff] [blame] | 9284 | * xmlSchemaNewDocParserCtxt: |
| 9285 | * @doc: a preparsed document tree |
| 9286 | * |
| 9287 | * Create an XML Schemas parse context for that document. |
| 9288 | * NB. The document may be modified during the parsing process. |
| 9289 | * |
| 9290 | * Returns the parser context or NULL in case of error |
| 9291 | */ |
| 9292 | xmlSchemaParserCtxtPtr |
| 9293 | xmlSchemaNewDocParserCtxt(xmlDocPtr doc) |
| 9294 | { |
| 9295 | xmlSchemaParserCtxtPtr ret; |
| 9296 | |
| 9297 | if (doc == NULL) |
| 9298 | return (NULL); |
| 9299 | |
| 9300 | ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt)); |
| 9301 | if (ret == NULL) { |
| 9302 | xmlSchemaPErrMemory(NULL, "allocating schema parser context", |
| 9303 | NULL); |
| 9304 | return (NULL); |
| 9305 | } |
| 9306 | memset(ret, 0, sizeof(xmlSchemaParserCtxt)); |
| 9307 | ret->doc = doc; |
William M. Brack | cf9eadf | 2003-12-25 13:24:05 +0000 | [diff] [blame] | 9308 | ret->dict = xmlDictCreate(); |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 9309 | /* The application has responsibility for the document */ |
| 9310 | ret->preserve = 1; |
Daniel Veillard | 9d75150 | 2003-10-29 13:21:47 +0000 | [diff] [blame] | 9311 | |
| 9312 | return (ret); |
| 9313 | } |
| 9314 | |
| 9315 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9316 | * xmlSchemaFreeParserCtxt: |
| 9317 | * @ctxt: the schema parser context |
| 9318 | * |
| 9319 | * Free the resources associated to the schema parser context |
| 9320 | */ |
| 9321 | void |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9322 | xmlSchemaFreeParserCtxt(xmlSchemaParserCtxtPtr ctxt) |
| 9323 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9324 | if (ctxt == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9325 | return; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 9326 | if (ctxt->doc != NULL && !ctxt->preserve) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9327 | xmlFreeDoc(ctxt->doc); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9328 | if (ctxt->assemble != NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9329 | xmlFree((xmlSchemaTypePtr *) ctxt->assemble->items); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9330 | xmlFree(ctxt->assemble); |
| 9331 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9332 | if (ctxt->vctxt != NULL) { |
| 9333 | xmlSchemaFreeValidCtxt(ctxt->vctxt); |
| 9334 | } |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 9335 | xmlDictFree(ctxt->dict); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9336 | xmlFree(ctxt); |
| 9337 | } |
| 9338 | |
| 9339 | /************************************************************************ |
| 9340 | * * |
| 9341 | * Building the content models * |
| 9342 | * * |
| 9343 | ************************************************************************/ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9344 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9345 | /** |
| 9346 | * xmlSchemaBuildAContentModel: |
| 9347 | * @type: the schema type definition |
| 9348 | * @ctxt: the schema parser context |
| 9349 | * @name: the element name whose content is being built |
| 9350 | * |
| 9351 | * Generate the automata sequence needed for that type |
| 9352 | */ |
| 9353 | static void |
| 9354 | xmlSchemaBuildAContentModel(xmlSchemaTypePtr type, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9355 | xmlSchemaParserCtxtPtr ctxt, |
| 9356 | const xmlChar * name) |
| 9357 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9358 | if (type == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9359 | xmlGenericError(xmlGenericErrorContext, |
| 9360 | "Found unexpected type = NULL in %s content model\n", |
| 9361 | name); |
| 9362 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9363 | } |
| 9364 | switch (type->type) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9365 | case XML_SCHEMA_TYPE_ANY: { |
| 9366 | xmlAutomataStatePtr start, end; |
| 9367 | xmlSchemaWildcardPtr wild; |
| 9368 | xmlSchemaWildcardNsPtr ns; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 9369 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9370 | wild = type->attributeWildcard; |
| 9371 | |
| 9372 | if (wild == NULL) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 9373 | xmlSchemaPErr(ctxt, type->node, XML_SCHEMAP_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9374 | "Internal error: xmlSchemaBuildAContentModel, " |
| 9375 | "no wildcard on xsd:any.\n", NULL, NULL); |
| 9376 | return; |
| 9377 | } |
| 9378 | |
| 9379 | start = ctxt->state; |
| 9380 | end = xmlAutomataNewState(ctxt->am); |
| 9381 | |
| 9382 | if (type->maxOccurs == 1) { |
| 9383 | if (wild->any == 1) { |
| 9384 | /* |
| 9385 | * We need to add both transitions: |
| 9386 | * |
| 9387 | * 1. the {"*", "*"} for elements in a namespace. |
| 9388 | */ |
| 9389 | ctxt->state = |
| 9390 | xmlAutomataNewTransition2(ctxt->am, |
| 9391 | start, NULL, BAD_CAST "*", BAD_CAST "*", type); |
| 9392 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 9393 | /* |
| 9394 | * 2. the {"*"} for elements in no namespace. |
| 9395 | */ |
| 9396 | ctxt->state = |
| 9397 | xmlAutomataNewTransition2(ctxt->am, |
| 9398 | start, NULL, BAD_CAST "*", NULL, type); |
| 9399 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 9400 | |
| 9401 | } else if (wild->nsSet != NULL) { |
| 9402 | ns = wild->nsSet; |
| 9403 | do { |
| 9404 | ctxt->state = start; |
| 9405 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 9406 | ctxt->state, NULL, BAD_CAST "*", ns->value, type); |
| 9407 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 9408 | ns = ns->next; |
| 9409 | } while (ns != NULL); |
| 9410 | |
| 9411 | } else if (wild->negNsSet != NULL) { |
| 9412 | xmlAutomataStatePtr deadEnd; |
| 9413 | |
| 9414 | deadEnd = xmlAutomataNewState(ctxt->am); |
| 9415 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 9416 | start, deadEnd, BAD_CAST "*", wild->negNsSet->value, type); |
| 9417 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 9418 | start, NULL, BAD_CAST "*", BAD_CAST "*", type); |
| 9419 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 9420 | } |
| 9421 | } else { |
| 9422 | int counter; |
| 9423 | xmlAutomataStatePtr hop; |
| 9424 | int maxOccurs = |
| 9425 | type->maxOccurs == UNBOUNDED ? UNBOUNDED : type->maxOccurs - 1; |
| 9426 | int minOccurs = |
| 9427 | type->minOccurs < 1 ? 0 : type->minOccurs - 1; |
| 9428 | |
| 9429 | counter = xmlAutomataNewCounter(ctxt->am, minOccurs, maxOccurs); |
| 9430 | hop = xmlAutomataNewState(ctxt->am); |
| 9431 | if (wild->any == 1) { |
| 9432 | ctxt->state = |
| 9433 | xmlAutomataNewTransition2(ctxt->am, |
| 9434 | start, NULL, BAD_CAST "*", BAD_CAST "*", type); |
| 9435 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 9436 | ctxt->state = |
| 9437 | xmlAutomataNewTransition2(ctxt->am, |
| 9438 | start, NULL, BAD_CAST "*", NULL, type); |
| 9439 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 9440 | } else if (wild->nsSet != NULL) { |
| 9441 | ns = wild->nsSet; |
| 9442 | do { |
| 9443 | ctxt->state = |
| 9444 | xmlAutomataNewTransition2(ctxt->am, |
| 9445 | start, NULL, BAD_CAST "*", ns->value, type); |
| 9446 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 9447 | ns = ns->next; |
| 9448 | } while (ns != NULL); |
| 9449 | |
| 9450 | } else if (wild->negNsSet != NULL) { |
| 9451 | xmlAutomataStatePtr deadEnd; |
| 9452 | |
| 9453 | deadEnd = xmlAutomataNewState(ctxt->am); |
| 9454 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 9455 | start, deadEnd, BAD_CAST "*", wild->negNsSet->value, type); |
| 9456 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 9457 | start, NULL, BAD_CAST "*", BAD_CAST "*", type); |
| 9458 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 9459 | } |
| 9460 | xmlAutomataNewCountedTrans(ctxt->am, hop, start, counter); |
| 9461 | xmlAutomataNewCounterTrans(ctxt->am, hop, end, counter); |
| 9462 | } |
| 9463 | if (type->minOccurs == 0) { |
| 9464 | xmlAutomataNewEpsilon(ctxt->am, start, end); |
| 9465 | } |
| 9466 | ctxt->state = end; |
| 9467 | break; |
| 9468 | } |
| 9469 | case XML_SCHEMA_TYPE_ELEMENT:{ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9470 | xmlAutomataStatePtr oldstate; |
| 9471 | xmlSchemaElementPtr particle, elemDecl; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 9472 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9473 | /* |
| 9474 | * IMPORTANT: This puts element declarations |
| 9475 | * (and never element decl. references) into the |
| 9476 | * automaton. This is crucial and should not be changed, |
| 9477 | * since validating functions rely now on it. |
| 9478 | */ |
| 9479 | particle = (xmlSchemaElementPtr) type; |
| 9480 | if (particle->ref != NULL) { |
| 9481 | if (particle->refDecl == NULL) { |
| 9482 | /* |
| 9483 | * Skip content model creation if the reference |
| 9484 | * did not resolve to a declaration. |
| 9485 | */ |
| 9486 | break; |
| 9487 | } else { |
| 9488 | /* |
| 9489 | * Referenced global element declaration. |
| 9490 | */ |
| 9491 | elemDecl = particle->refDecl; |
| 9492 | } |
| 9493 | } else { |
| 9494 | /* |
| 9495 | * Anonymous element declaration. |
| 9496 | */ |
| 9497 | elemDecl = particle; |
| 9498 | } |
| 9499 | |
| 9500 | oldstate = ctxt->state; |
| 9501 | |
| 9502 | if (particle->maxOccurs >= UNBOUNDED) { |
| 9503 | if (particle->minOccurs > 1) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9504 | xmlAutomataStatePtr tmp; |
| 9505 | int counter; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 9506 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9507 | ctxt->state = xmlAutomataNewEpsilon(ctxt->am, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9508 | oldstate, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9509 | oldstate = ctxt->state; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9510 | counter = xmlAutomataNewCounter(ctxt->am, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9511 | particle->minOccurs - 1, UNBOUNDED); |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 9512 | ctxt->state = |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9513 | xmlAutomataNewTransition2(ctxt->am, |
| 9514 | ctxt->state, NULL, |
| 9515 | elemDecl->name, |
| 9516 | elemDecl->targetNamespace, |
| 9517 | (xmlSchemaTypePtr) elemDecl); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9518 | tmp = ctxt->state; |
| 9519 | xmlAutomataNewCountedTrans(ctxt->am, tmp, oldstate, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9520 | counter); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9521 | ctxt->state = |
| 9522 | xmlAutomataNewCounterTrans(ctxt->am, tmp, NULL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9523 | counter); |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 9524 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9525 | } else { |
| 9526 | ctxt->state = |
| 9527 | xmlAutomataNewTransition2(ctxt->am, |
| 9528 | ctxt->state, NULL, |
| 9529 | elemDecl->name, |
| 9530 | elemDecl->targetNamespace, |
| 9531 | (xmlSchemaTypePtr) elemDecl); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9532 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, |
| 9533 | oldstate); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9534 | if (particle->minOccurs == 0) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9535 | /* basically an elem* */ |
| 9536 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
| 9537 | ctxt->state); |
| 9538 | } |
| 9539 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9540 | } else if ((particle->maxOccurs > 1) || (particle->minOccurs > 1)) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9541 | xmlAutomataStatePtr tmp; |
| 9542 | int counter; |
Daniel Veillard | 3237023 | 2002-10-16 14:08:14 +0000 | [diff] [blame] | 9543 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9544 | ctxt->state = xmlAutomataNewEpsilon(ctxt->am, |
| 9545 | oldstate, NULL); |
| 9546 | oldstate = ctxt->state; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9547 | counter = xmlAutomataNewCounter(ctxt->am, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9548 | particle->minOccurs - 1, |
| 9549 | particle->maxOccurs - 1); |
| 9550 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 9551 | ctxt->state, |
| 9552 | NULL, |
| 9553 | elemDecl->name, |
| 9554 | elemDecl->targetNamespace, |
| 9555 | (xmlSchemaTypePtr) elemDecl); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9556 | tmp = ctxt->state; |
| 9557 | xmlAutomataNewCountedTrans(ctxt->am, tmp, oldstate, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9558 | counter); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9559 | ctxt->state = xmlAutomataNewCounterTrans(ctxt->am, tmp, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9560 | NULL, counter); |
| 9561 | if (particle->minOccurs == 0) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9562 | /* basically an elem? */ |
| 9563 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9564 | ctxt->state); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9565 | } |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 9566 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9567 | } else { |
| 9568 | ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
| 9569 | ctxt->state, |
| 9570 | NULL, |
| 9571 | elemDecl->name, |
| 9572 | elemDecl->targetNamespace, |
| 9573 | (xmlSchemaTypePtr) elemDecl); |
| 9574 | if (particle->minOccurs == 0) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9575 | /* basically an elem? */ |
| 9576 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9577 | ctxt->state); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9578 | } |
| 9579 | } |
| 9580 | break; |
| 9581 | } |
| 9582 | case XML_SCHEMA_TYPE_SEQUENCE:{ |
| 9583 | xmlSchemaTypePtr subtypes; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 9584 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9585 | /* |
| 9586 | * If max and min occurances are default (1) then |
| 9587 | * simply iterate over the subtypes |
| 9588 | */ |
| 9589 | if ((type->minOccurs == 1) && (type->maxOccurs == 1)) { |
| 9590 | subtypes = type->subtypes; |
| 9591 | while (subtypes != NULL) { |
| 9592 | xmlSchemaBuildAContentModel(subtypes, ctxt, name); |
| 9593 | subtypes = subtypes->next; |
| 9594 | } |
| 9595 | } else { |
| 9596 | xmlAutomataStatePtr oldstate = ctxt->state; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 9597 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9598 | if (type->maxOccurs >= UNBOUNDED) { |
| 9599 | if (type->minOccurs > 1) { |
| 9600 | xmlAutomataStatePtr tmp; |
| 9601 | int counter; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 9602 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9603 | ctxt->state = xmlAutomataNewEpsilon(ctxt->am, |
| 9604 | oldstate, |
| 9605 | NULL); |
| 9606 | oldstate = ctxt->state; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 9607 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9608 | counter = xmlAutomataNewCounter(ctxt->am, |
| 9609 | type-> |
| 9610 | minOccurs - 1, |
| 9611 | UNBOUNDED); |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 9612 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9613 | subtypes = type->subtypes; |
| 9614 | while (subtypes != NULL) { |
| 9615 | xmlSchemaBuildAContentModel(subtypes, ctxt, |
| 9616 | name); |
| 9617 | subtypes = subtypes->next; |
| 9618 | } |
| 9619 | tmp = ctxt->state; |
| 9620 | xmlAutomataNewCountedTrans(ctxt->am, tmp, |
| 9621 | oldstate, counter); |
| 9622 | ctxt->state = |
| 9623 | xmlAutomataNewCounterTrans(ctxt->am, tmp, |
| 9624 | NULL, counter); |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 9625 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9626 | } else { |
| 9627 | subtypes = type->subtypes; |
| 9628 | while (subtypes != NULL) { |
| 9629 | xmlSchemaBuildAContentModel(subtypes, ctxt, |
| 9630 | name); |
| 9631 | subtypes = subtypes->next; |
| 9632 | } |
| 9633 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, |
| 9634 | oldstate); |
| 9635 | if (type->minOccurs == 0) { |
| 9636 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
| 9637 | ctxt->state); |
| 9638 | } |
| 9639 | } |
| 9640 | } else if ((type->maxOccurs > 1) |
| 9641 | || (type->minOccurs > 1)) { |
| 9642 | xmlAutomataStatePtr tmp; |
| 9643 | int counter; |
Daniel Veillard | b39bc39 | 2002-10-26 19:29:51 +0000 | [diff] [blame] | 9644 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9645 | ctxt->state = xmlAutomataNewEpsilon(ctxt->am, |
| 9646 | oldstate, |
| 9647 | NULL); |
| 9648 | oldstate = ctxt->state; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9649 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9650 | counter = xmlAutomataNewCounter(ctxt->am, |
| 9651 | type->minOccurs - |
| 9652 | 1, |
| 9653 | type->maxOccurs - |
| 9654 | 1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9655 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9656 | subtypes = type->subtypes; |
| 9657 | while (subtypes != NULL) { |
| 9658 | xmlSchemaBuildAContentModel(subtypes, ctxt, |
| 9659 | name); |
| 9660 | subtypes = subtypes->next; |
| 9661 | } |
| 9662 | tmp = ctxt->state; |
| 9663 | xmlAutomataNewCountedTrans(ctxt->am, tmp, oldstate, |
| 9664 | counter); |
| 9665 | ctxt->state = |
| 9666 | xmlAutomataNewCounterTrans(ctxt->am, tmp, NULL, |
| 9667 | counter); |
| 9668 | if (type->minOccurs == 0) { |
| 9669 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
| 9670 | ctxt->state); |
| 9671 | } |
Daniel Veillard | b509f15 | 2002-04-17 16:28:10 +0000 | [diff] [blame] | 9672 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9673 | } else { |
| 9674 | subtypes = type->subtypes; |
| 9675 | while (subtypes != NULL) { |
| 9676 | xmlSchemaBuildAContentModel(subtypes, ctxt, |
| 9677 | name); |
| 9678 | subtypes = subtypes->next; |
| 9679 | } |
| 9680 | if (type->minOccurs == 0) { |
| 9681 | xmlAutomataNewEpsilon(ctxt->am, oldstate, |
| 9682 | ctxt->state); |
| 9683 | } |
| 9684 | } |
| 9685 | } |
| 9686 | break; |
| 9687 | } |
| 9688 | case XML_SCHEMA_TYPE_CHOICE:{ |
| 9689 | xmlSchemaTypePtr subtypes; |
| 9690 | xmlAutomataStatePtr start, end; |
Daniel Veillard | b509f15 | 2002-04-17 16:28:10 +0000 | [diff] [blame] | 9691 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9692 | start = ctxt->state; |
| 9693 | end = xmlAutomataNewState(ctxt->am); |
Daniel Veillard | 7646b18 | 2002-04-20 06:41:40 +0000 | [diff] [blame] | 9694 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9695 | /* |
| 9696 | * iterate over the subtypes and remerge the end with an |
| 9697 | * epsilon transition |
| 9698 | */ |
| 9699 | if (type->maxOccurs == 1) { |
| 9700 | subtypes = type->subtypes; |
| 9701 | while (subtypes != NULL) { |
| 9702 | ctxt->state = start; |
| 9703 | xmlSchemaBuildAContentModel(subtypes, ctxt, name); |
| 9704 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 9705 | subtypes = subtypes->next; |
| 9706 | } |
| 9707 | } else { |
| 9708 | int counter; |
| 9709 | xmlAutomataStatePtr hop; |
| 9710 | int maxOccurs = type->maxOccurs == UNBOUNDED ? |
| 9711 | UNBOUNDED : type->maxOccurs - 1; |
| 9712 | int minOccurs = |
| 9713 | type->minOccurs < 1 ? 0 : type->minOccurs - 1; |
Daniel Veillard | 7646b18 | 2002-04-20 06:41:40 +0000 | [diff] [blame] | 9714 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9715 | /* |
| 9716 | * use a counter to keep track of the number of transtions |
| 9717 | * which went through the choice. |
| 9718 | */ |
| 9719 | counter = |
| 9720 | xmlAutomataNewCounter(ctxt->am, minOccurs, |
| 9721 | maxOccurs); |
| 9722 | hop = xmlAutomataNewState(ctxt->am); |
Daniel Veillard | 6231e84 | 2002-04-18 11:54:04 +0000 | [diff] [blame] | 9723 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9724 | subtypes = type->subtypes; |
| 9725 | while (subtypes != NULL) { |
| 9726 | ctxt->state = start; |
| 9727 | xmlSchemaBuildAContentModel(subtypes, ctxt, name); |
| 9728 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 9729 | subtypes = subtypes->next; |
| 9730 | } |
| 9731 | xmlAutomataNewCountedTrans(ctxt->am, hop, start, |
| 9732 | counter); |
| 9733 | xmlAutomataNewCounterTrans(ctxt->am, hop, end, |
| 9734 | counter); |
| 9735 | } |
| 9736 | if (type->minOccurs == 0) { |
| 9737 | xmlAutomataNewEpsilon(ctxt->am, start, end); |
| 9738 | } |
| 9739 | ctxt->state = end; |
| 9740 | break; |
| 9741 | } |
| 9742 | case XML_SCHEMA_TYPE_ALL:{ |
| 9743 | xmlAutomataStatePtr start; |
| 9744 | xmlSchemaTypePtr subtypes; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9745 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 9746 | xmlSchemaElementPtr elem; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9747 | int lax; |
| 9748 | |
| 9749 | subtypes = type->subtypes; |
| 9750 | if (subtypes == NULL) |
| 9751 | break; |
| 9752 | start = ctxt->state; |
| 9753 | while (subtypes != NULL) { |
| 9754 | ctxt->state = start; |
William M. Brack | 9989c7d | 2004-05-12 14:39:38 +0000 | [diff] [blame] | 9755 | /* |
| 9756 | * the following 'if' was needed to fix bug 139897 |
| 9757 | * not quite sure why it only needs to be done for |
| 9758 | * elements with a 'ref', but it seems to work ok. |
| 9759 | */ |
| 9760 | if (subtypes->ref != NULL) |
| 9761 | xmlSchemaBuildAContentModel(subtypes, ctxt, name); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9762 | elem = (xmlSchemaElementPtr) subtypes; |
| 9763 | /* |
| 9764 | * NOTE: The {max occurs} of all the particles in the |
| 9765 | * {particles} of the group must be 0 or 1. |
| 9766 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9767 | if ((elem->minOccurs == 1) && (elem->maxOccurs == 1)) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9768 | xmlAutomataNewOnceTrans2(ctxt->am, ctxt->state, |
| 9769 | ctxt->state, |
| 9770 | elem->name, |
| 9771 | elem->targetNamespace, |
| 9772 | 1, 1, subtypes); |
| 9773 | } else if ((elem->minOccurs == 0) && |
| 9774 | (elem->maxOccurs == 1)) { |
| 9775 | |
| 9776 | xmlAutomataNewCountTrans2(ctxt->am, ctxt->state, |
| 9777 | ctxt->state, |
| 9778 | elem->name, |
| 9779 | elem->targetNamespace, |
| 9780 | 0, |
| 9781 | 1, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9782 | subtypes); |
| 9783 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 9784 | /* |
| 9785 | * NOTE: if maxOccurs == 0 then no transition will be |
| 9786 | * created. |
| 9787 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9788 | subtypes = subtypes->next; |
| 9789 | } |
| 9790 | lax = type->minOccurs == 0; |
| 9791 | ctxt->state = |
| 9792 | xmlAutomataNewAllTrans(ctxt->am, ctxt->state, NULL, |
| 9793 | lax); |
| 9794 | break; |
| 9795 | } |
| 9796 | case XML_SCHEMA_TYPE_RESTRICTION: |
| 9797 | if (type->subtypes != NULL) |
| 9798 | xmlSchemaBuildAContentModel(type->subtypes, ctxt, name); |
| 9799 | break; |
| 9800 | case XML_SCHEMA_TYPE_EXTENSION: |
| 9801 | if (type->baseType != NULL) { |
| 9802 | xmlSchemaTypePtr subtypes; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9803 | |
| 9804 | /* |
| 9805 | * TODO: Circular definitions will be checked at the |
| 9806 | * constraint level. So remove this when the complex type |
| 9807 | * constraints are implemented. |
| 9808 | */ |
Daniel Veillard | f762755 | 2004-04-22 07:15:40 +0000 | [diff] [blame] | 9809 | if (type->recurse) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9810 | /* TODO: Change the error code. */ |
| 9811 | xmlSchemaPCustomErr(ctxt, |
| 9812 | XML_SCHEMAP_UNKNOWN_BASE_TYPE, |
| 9813 | NULL, type, type->node, |
| 9814 | "This item is circular", NULL); |
Daniel Veillard | f762755 | 2004-04-22 07:15:40 +0000 | [diff] [blame] | 9815 | return; |
| 9816 | } |
| 9817 | type->recurse = 1; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9818 | xmlSchemaBuildAContentModel(type->baseType, ctxt, name); |
Daniel Veillard | f762755 | 2004-04-22 07:15:40 +0000 | [diff] [blame] | 9819 | type->recurse = 0; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9820 | subtypes = type->subtypes; |
| 9821 | while (subtypes != NULL) { |
| 9822 | xmlSchemaBuildAContentModel(subtypes, ctxt, name); |
| 9823 | subtypes = subtypes->next; |
| 9824 | } |
| 9825 | } else if (type->subtypes != NULL) |
| 9826 | xmlSchemaBuildAContentModel(type->subtypes, ctxt, name); |
| 9827 | break; |
| 9828 | case XML_SCHEMA_TYPE_GROUP: |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 9829 | /* |
| 9830 | * Handle model group definition references. |
| 9831 | * NOTE: type->subtypes is the referenced model grop definition; |
| 9832 | * and type->subtypes->subtypes is the model group (i.e. <all> or |
| 9833 | * <choice> or <sequence>). |
| 9834 | */ |
| 9835 | if ((type->ref != NULL) && (type->subtypes != NULL) && |
| 9836 | (type->subtypes->subtypes != NULL)) { |
| 9837 | xmlSchemaTypePtr modelGr; |
| 9838 | xmlAutomataStatePtr start, end; |
| 9839 | |
| 9840 | modelGr = type->subtypes->subtypes; |
| 9841 | start = ctxt->state; |
| 9842 | end = xmlAutomataNewState(ctxt->am); |
| 9843 | if (type->maxOccurs == 1) { |
| 9844 | ctxt->state = start; |
| 9845 | xmlSchemaBuildAContentModel(modelGr, ctxt, name); |
| 9846 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, end); |
| 9847 | } else { |
| 9848 | int counter; |
| 9849 | xmlAutomataStatePtr hop; |
| 9850 | int maxOccurs = type->maxOccurs == UNBOUNDED ? |
| 9851 | UNBOUNDED : type->maxOccurs - 1; |
| 9852 | int minOccurs = |
| 9853 | type->minOccurs < 1 ? 0 : type->minOccurs - 1; |
| 9854 | |
| 9855 | counter = |
| 9856 | xmlAutomataNewCounter(ctxt->am, minOccurs, maxOccurs); |
| 9857 | hop = xmlAutomataNewState(ctxt->am); |
| 9858 | ctxt->state = start; |
| 9859 | xmlSchemaBuildAContentModel(modelGr, ctxt, name); |
| 9860 | xmlAutomataNewEpsilon(ctxt->am, ctxt->state, hop); |
| 9861 | xmlAutomataNewCountedTrans(ctxt->am, hop, start, |
| 9862 | counter); |
| 9863 | xmlAutomataNewCounterTrans(ctxt->am, hop, end, |
| 9864 | counter); |
| 9865 | } |
| 9866 | if (type->minOccurs == 0) { |
| 9867 | xmlAutomataNewEpsilon(ctxt->am, start, end); |
| 9868 | } |
| 9869 | ctxt->state = end; |
| 9870 | break; |
| 9871 | } |
| 9872 | break; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9873 | case XML_SCHEMA_TYPE_COMPLEX: |
| 9874 | case XML_SCHEMA_TYPE_COMPLEX_CONTENT: |
| 9875 | if (type->subtypes != NULL) |
| 9876 | xmlSchemaBuildAContentModel(type->subtypes, ctxt, name); |
| 9877 | break; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 9878 | case XML_SCHEMA_TYPE_SIMPLE_CONTENT: |
| 9879 | break; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9880 | default: |
| 9881 | xmlGenericError(xmlGenericErrorContext, |
| 9882 | "Found unexpected type %d in %s content model\n", |
| 9883 | type->type, name); |
| 9884 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9885 | } |
| 9886 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9887 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9888 | /** |
| 9889 | * xmlSchemaBuildContentModel: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9890 | * @type: the type definition (or reference) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9891 | * @ctxt: the schema parser context |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 9892 | * @name: the element name |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9893 | * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9894 | * Builds the content model of the complex type. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9895 | */ |
| 9896 | static void |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9897 | xmlSchemaBuildContentModel(xmlSchemaTypePtr type, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9898 | xmlSchemaParserCtxtPtr ctxt, |
| 9899 | const xmlChar * name) |
| 9900 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9901 | xmlAutomataStatePtr start; |
| 9902 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9903 | if ((type->type != XML_SCHEMA_TYPE_COMPLEX) || (type->ref != NULL) || |
| 9904 | (type->contentType == XML_SCHEMA_CONTENT_BASIC) || |
| 9905 | (type->contentType == XML_SCHEMA_CONTENT_SIMPLE) || |
| 9906 | (type->contModel != NULL)) |
| 9907 | return; |
Daniel Veillard | decd64d | 2002-04-18 14:41:51 +0000 | [diff] [blame] | 9908 | |
| 9909 | #ifdef DEBUG_CONTENT |
| 9910 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9911 | "Building content model for %s\n", name); |
Daniel Veillard | decd64d | 2002-04-18 14:41:51 +0000 | [diff] [blame] | 9912 | #endif |
| 9913 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9914 | ctxt->am = xmlNewAutomata(); |
| 9915 | if (ctxt->am == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9916 | xmlGenericError(xmlGenericErrorContext, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9917 | "Cannot create automata for complex tpye %s\n", name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9918 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9919 | } |
| 9920 | start = ctxt->state = xmlAutomataGetInitState(ctxt->am); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9921 | xmlSchemaBuildAContentModel(type, ctxt, name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9922 | xmlAutomataSetFinalState(ctxt->am, ctxt->state); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9923 | type->contModel = xmlAutomataCompile(ctxt->am); |
| 9924 | if (type->contModel == NULL) { |
| 9925 | xmlSchemaPCustomErr(ctxt, |
| 9926 | XML_SCHEMAP_INTERNAL, |
| 9927 | NULL, type, type->node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9928 | "Failed to compile the content model", NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9929 | } else if (xmlRegexpIsDeterminist(type->contModel) != 1) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 9930 | xmlSchemaPCustomErr(ctxt, |
| 9931 | XML_SCHEMAP_NOT_DETERMINISTIC, |
| 9932 | /* XML_SCHEMAS_ERR_NOTDETERMINIST, */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9933 | NULL, type, type->node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9934 | "The content model is not determinist", NULL); |
Daniel Veillard | e19fc23 | 2002-04-22 16:01:24 +0000 | [diff] [blame] | 9935 | } else { |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 9936 | #ifdef DEBUG_CONTENT_REGEXP |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9937 | xmlGenericError(xmlGenericErrorContext, |
| 9938 | "Content model of %s:\n", name); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 9939 | xmlRegexpPrint(stderr, type->contModel); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9940 | #endif |
Daniel Veillard | e19fc23 | 2002-04-22 16:01:24 +0000 | [diff] [blame] | 9941 | } |
Daniel Veillard | a84c0b3 | 2003-06-02 16:58:46 +0000 | [diff] [blame] | 9942 | ctxt->state = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9943 | xmlFreeAutomata(ctxt->am); |
| 9944 | ctxt->am = NULL; |
| 9945 | } |
| 9946 | |
| 9947 | /** |
| 9948 | * xmlSchemaRefFixupCallback: |
| 9949 | * @elem: the schema element context |
| 9950 | * @ctxt: the schema parser context |
| 9951 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9952 | * Resolves the references of an element declaration |
| 9953 | * or particle, which has an element declaration as it's |
| 9954 | * term. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9955 | */ |
| 9956 | static void |
| 9957 | xmlSchemaRefFixupCallback(xmlSchemaElementPtr elem, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9958 | xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9959 | const xmlChar * name ATTRIBUTE_UNUSED, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9960 | const xmlChar * context ATTRIBUTE_UNUSED, |
| 9961 | const xmlChar * namespace ATTRIBUTE_UNUSED) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9962 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9963 | if ((ctxt == NULL) || (elem == NULL) || |
| 9964 | ((elem != NULL) && (elem->flags & XML_SCHEMAS_ELEM_INTERNAL_RESOLVED))) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9965 | return; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9966 | elem->flags |= XML_SCHEMAS_ELEM_INTERNAL_RESOLVED; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9967 | if (elem->ref != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 9968 | xmlSchemaElementPtr elemDecl; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 9969 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9970 | /* |
| 9971 | * TODO: Evaluate, what errors could occur if the declaration is not |
| 9972 | * found. It might be possible that the "typefixup" might crash if |
| 9973 | * no ref declaration was found. |
| 9974 | */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 9975 | elemDecl = xmlSchemaGetElem(ctxt->schema, elem->ref, elem->refNs); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9976 | if (elemDecl == NULL) { |
| 9977 | xmlSchemaPResCompAttrErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 9978 | XML_SCHEMAP_SRC_RESOLVE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 9979 | NULL, (xmlSchemaTypePtr) elem, elem->node, |
| 9980 | "ref", elem->ref, elem->refNs, |
| 9981 | XML_SCHEMA_TYPE_ELEMENT, NULL); |
| 9982 | } else |
| 9983 | elem->refDecl = elemDecl; |
| 9984 | } else { |
| 9985 | if ((elem->subtypes == NULL) && (elem->namedType != NULL)) { |
| 9986 | xmlSchemaTypePtr type; |
| 9987 | |
| 9988 | /* (type definition) ... otherwise the type definition ·resolved· |
| 9989 | * to by the ·actual value· of the type [attribute] ... |
| 9990 | */ |
| 9991 | type = xmlSchemaGetType(ctxt->schema, elem->namedType, |
| 9992 | elem->namedTypeNs); |
| 9993 | if (type == NULL) { |
| 9994 | xmlSchemaPResCompAttrErr(ctxt, |
| 9995 | XML_SCHEMAP_SRC_RESOLVE, |
| 9996 | NULL, (xmlSchemaTypePtr) elem, elem->node, |
| 9997 | "type", elem->namedType, elem->namedTypeNs, |
| 9998 | XML_SCHEMA_TYPE_BASIC, "type definition"); |
| 9999 | } else |
| 10000 | elem->subtypes = type; |
| 10001 | } |
| 10002 | if (elem->substGroup != NULL) { |
| 10003 | xmlSchemaElementPtr substHead; |
| 10004 | |
| 10005 | /* |
| 10006 | * FIXME TODO: Do we need a new field in _xmlSchemaElement for |
| 10007 | * substitutionGroup? |
| 10008 | */ |
| 10009 | substHead = xmlSchemaGetElem(ctxt->schema, elem->substGroup, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 10010 | elem->substGroupNs); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10011 | if (substHead == NULL) { |
| 10012 | xmlSchemaPResCompAttrErr(ctxt, |
| 10013 | XML_SCHEMAP_SRC_RESOLVE, |
| 10014 | NULL, (xmlSchemaTypePtr) elem, NULL, |
| 10015 | "substitutionGroup", elem->substGroup, elem->substGroupNs, |
| 10016 | XML_SCHEMA_TYPE_ELEMENT, NULL); |
| 10017 | } else { |
| 10018 | xmlSchemaRefFixupCallback(substHead, ctxt, NULL, NULL, NULL); |
| 10019 | /* |
| 10020 | * (type definition)...otherwise the {type definition} of the |
| 10021 | * element declaration ·resolved· to by the ·actual value· of |
| 10022 | * the substitutionGroup [attribute], if present |
| 10023 | */ |
| 10024 | if (elem->subtypes == NULL) |
| 10025 | elem->subtypes = substHead->subtypes; |
| 10026 | } |
| 10027 | } |
| 10028 | if ((elem->subtypes == NULL) && (elem->namedType == NULL) && |
| 10029 | (elem->substGroup == NULL)) |
| 10030 | elem->subtypes = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 10031 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10032 | } |
| 10033 | |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 10034 | /** |
| 10035 | * xmlSchemaParseListRefFixup: |
| 10036 | * @type: the schema type definition |
| 10037 | * @ctxt: the schema parser context |
| 10038 | * |
| 10039 | * Fixup of the itemType reference of the list type. |
| 10040 | */ |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 10041 | static void |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 10042 | xmlSchemaParseListRefFixup(xmlSchemaTypePtr type, xmlSchemaParserCtxtPtr ctxt) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10043 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10044 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10045 | if (((type->base == NULL) && |
| 10046 | (type->subtypes == NULL)) || |
| 10047 | ((type->base != NULL) && |
| 10048 | (type->subtypes != NULL))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10049 | /* |
| 10050 | * src-list-itemType-or-simpleType |
| 10051 | * Either the itemType [attribute] or the <simpleType> [child] of |
| 10052 | * the <list> element must be present, but not both. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10053 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10054 | /* |
| 10055 | * TODO: Move this to the parse function. |
| 10056 | */ |
| 10057 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10058 | XML_SCHEMAP_SRC_LIST_ITEMTYPE_OR_SIMPLETYPE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10059 | NULL, type, type->node, |
| 10060 | "The attribute 'itemType' and the <simpleType> child " |
| 10061 | "are mutually exclusive", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10062 | } else if (type->base!= NULL) { |
| 10063 | type->subtypes = xmlSchemaGetType(ctxt->schema, type->base, type->baseNs); |
| 10064 | if (type->subtypes == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10065 | xmlSchemaPResCompAttrErr(ctxt, |
| 10066 | XML_SCHEMAP_SRC_RESOLVE, |
| 10067 | NULL, type, type->node, |
| 10068 | "itemType", type->base, type->baseNs, |
| 10069 | XML_SCHEMA_TYPE_SIMPLE, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10070 | } |
| 10071 | } |
| 10072 | if ((type->subtypes != NULL) && |
| 10073 | (type->subtypes->contentType == XML_SCHEMA_CONTENT_UNKNOWN)) |
| 10074 | xmlSchemaTypeFixup(type->subtypes, ctxt, NULL); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 10075 | } |
| 10076 | |
| 10077 | /** |
| 10078 | * xmlSchemaParseUnionRefCheck: |
| 10079 | * @typeDecl: the schema type definition |
| 10080 | * @ctxt: the schema parser context |
| 10081 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10082 | * Checks and builds the memberTypes of the union type. |
| 10083 | * Returns -1 in case of an internal error, 0 otherwise. |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 10084 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10085 | static int |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 10086 | xmlSchemaParseUnionRefCheck(xmlSchemaTypePtr type, |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 10087 | xmlSchemaParserCtxtPtr ctxt) |
| 10088 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10089 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10090 | xmlSchemaTypeLinkPtr link, lastLink = NULL, prevLink, subLink, newLink; |
| 10091 | xmlSchemaTypePtr memberType, ctxtType; |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 10092 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10093 | /* 1 If the <union> alternative is chosen, then [Definition:] |
| 10094 | * define the explicit members as the type definitions ·resolved· |
| 10095 | * to by the items in the ·actual value· of the memberTypes [attribute], |
| 10096 | * if any, followed by the type definitions corresponding to the |
| 10097 | * <simpleType>s among the [children] of <union>, if any. |
| 10098 | */ |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 10099 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10100 | if (type->type != XML_SCHEMA_TYPE_UNION) |
| 10101 | return (-1); |
| 10102 | if (ctxt->ctxtType == NULL) { |
| 10103 | xmlSchemaPErr(ctxt, type->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 10104 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10105 | "Internal error: xmlSchemaParseUnionRefCheck, no parent type " |
| 10106 | "available", NULL, NULL); |
| 10107 | return (-1); |
| 10108 | } |
| 10109 | /* |
| 10110 | * src-union-memberTypes-or-simpleTypes |
| 10111 | * Either the memberTypes [attribute] of the <union> element must |
| 10112 | * be non-empty or there must be at least one simpleType [child]. |
| 10113 | */ |
| 10114 | if ((type->base == NULL) && |
| 10115 | (type->subtypes == NULL)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10116 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10117 | XML_SCHEMAP_SRC_UNION_MEMBERTYPES_OR_SIMPLETYPES, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10118 | NULL, NULL, type->node, |
| 10119 | "Either the attribute 'memberTypes' must be non-empty " |
| 10120 | "or there must be at least one <simpleType> child", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10121 | } |
| 10122 | |
| 10123 | ctxtType = ctxt->ctxtType; |
| 10124 | if (type->base != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10125 | xmlAttrPtr attr; |
| 10126 | const xmlChar *cur, *end; |
| 10127 | xmlChar *tmp; |
| 10128 | const xmlChar *localName, *uri; |
| 10129 | |
| 10130 | attr = xmlSchemaGetPropNode(type->node, "memberTypes"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10131 | cur = type->base; |
| 10132 | do { |
| 10133 | while (IS_BLANK_CH(*cur)) |
| 10134 | cur++; |
| 10135 | end = cur; |
| 10136 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 10137 | end++; |
| 10138 | if (end == cur) |
| 10139 | break; |
| 10140 | tmp = xmlStrndup(cur, end - cur); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10141 | xmlSchemaPValAttrNodeQNameValue(ctxt, ctxt->schema, NULL, |
| 10142 | NULL, attr, BAD_CAST tmp, &uri, NULL, &localName); |
| 10143 | memberType = xmlSchemaGetType(ctxt->schema, localName, uri); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10144 | if (memberType == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10145 | xmlSchemaPResCompAttrErr(ctxt, |
| 10146 | XML_SCHEMAP_UNKNOWN_MEMBER_TYPE, |
| 10147 | NULL, NULL, type->node, "memberTypes", localName, uri, |
| 10148 | XML_SCHEMA_TYPE_SIMPLE, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10149 | } else { |
| 10150 | if (memberType->contentType == XML_SCHEMA_CONTENT_UNKNOWN) |
| 10151 | xmlSchemaTypeFixup(memberType, ctxt, NULL); |
| 10152 | link = (xmlSchemaTypeLinkPtr) xmlMalloc(sizeof(xmlSchemaTypeLink)); |
| 10153 | if (link == NULL) { |
| 10154 | xmlSchemaPErrMemory(ctxt, "allocating a type link", NULL); |
| 10155 | return (-1); |
| 10156 | } |
| 10157 | link->type = memberType; |
| 10158 | link->next = NULL; |
| 10159 | if (lastLink == NULL) |
| 10160 | ctxtType->memberTypes = link; |
| 10161 | else |
| 10162 | lastLink->next = link; |
| 10163 | lastLink = link; |
| 10164 | } |
| 10165 | xmlFree(tmp); |
| 10166 | cur = end; |
| 10167 | } while (*cur != 0); |
| 10168 | } |
| 10169 | /* |
| 10170 | * Add local simple types, |
| 10171 | */ |
| 10172 | memberType = type->subtypes; |
| 10173 | while (memberType != NULL) { |
| 10174 | if (memberType->contentType == XML_SCHEMA_CONTENT_UNKNOWN) |
| 10175 | xmlSchemaTypeFixup(memberType, ctxt, NULL); |
| 10176 | link = (xmlSchemaTypeLinkPtr) xmlMalloc(sizeof(xmlSchemaTypeLink)); |
| 10177 | if (link == NULL) { |
| 10178 | xmlSchemaPErrMemory(ctxt, "allocating a type link", NULL); |
| 10179 | return (-1); |
| 10180 | } |
| 10181 | link->type = memberType; |
| 10182 | link->next = NULL; |
| 10183 | if (lastLink == NULL) |
| 10184 | ctxtType->memberTypes = link; |
| 10185 | else |
| 10186 | lastLink->next = link; |
| 10187 | lastLink = link; |
| 10188 | memberType = memberType->next; |
| 10189 | } |
| 10190 | /* |
| 10191 | * The actual value is then formed by replacing any union type |
| 10192 | * definition in the ·explicit members· with the members of their |
| 10193 | * {member type definitions}, in order. |
| 10194 | */ |
| 10195 | link = ctxtType->memberTypes; |
| 10196 | while (link != NULL) { |
| 10197 | if (link->type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
| 10198 | subLink = link->type->memberTypes; |
| 10199 | if (subLink != NULL) { |
| 10200 | link->type = subLink->type; |
| 10201 | if (subLink->next != NULL) { |
| 10202 | lastLink = link->next; |
| 10203 | subLink = subLink->next; |
| 10204 | prevLink = link; |
| 10205 | while (subLink != NULL) { |
| 10206 | newLink = (xmlSchemaTypeLinkPtr) |
| 10207 | xmlMalloc(sizeof(xmlSchemaTypeLink)); |
| 10208 | if (newLink == NULL) { |
| 10209 | xmlSchemaPErrMemory(ctxt, "allocating a type link", |
| 10210 | NULL); |
| 10211 | return (-1); |
| 10212 | } |
| 10213 | newLink->type = memberType; |
| 10214 | prevLink->next = newLink; |
| 10215 | prevLink = newLink; |
| 10216 | newLink->next = lastLink; |
| 10217 | |
| 10218 | subLink = subLink->next; |
| 10219 | } |
| 10220 | } |
| 10221 | } |
| 10222 | } |
| 10223 | link = link->next; |
| 10224 | } |
| 10225 | |
| 10226 | return (0); |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 10227 | } |
| 10228 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 10229 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10230 | * xmlSchemaIsDerivedFromBuiltInType: |
| 10231 | * @ctxt: the schema parser context |
| 10232 | * @type: the type definition |
| 10233 | * @valType: the value type |
| 10234 | * |
| 10235 | * |
| 10236 | * Returns 1 if the type has the given value type, or |
| 10237 | * is derived from such a type. |
| 10238 | */ |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 10239 | static int |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10240 | xmlSchemaIsDerivedFromBuiltInType(xmlSchemaParserCtxtPtr ctxt, |
| 10241 | xmlSchemaTypePtr type, int valType) |
| 10242 | { |
| 10243 | /* TODO: Check if this works in every case. */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10244 | if ((type->type == XML_SCHEMA_TYPE_BASIC) && |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10245 | (type->contentType == XML_SCHEMA_CONTENT_BASIC)) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10246 | if (type->builtInType == valType) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10247 | return(1); |
| 10248 | } else if (type->type == XML_SCHEMA_TYPE_ATTRIBUTE) { |
| 10249 | if (((xmlSchemaAttributePtr) type)->subtypes != NULL) |
| 10250 | return(xmlSchemaIsDerivedFromBuiltInType(ctxt, |
| 10251 | ((xmlSchemaAttributePtr) type)->subtypes, valType)); |
| 10252 | } else if ((type->type == XML_SCHEMA_TYPE_RESTRICTION) || |
| 10253 | (type->type == XML_SCHEMA_TYPE_EXTENSION)) { |
| 10254 | if (type->baseType != NULL) |
| 10255 | return(xmlSchemaIsDerivedFromBuiltInType(ctxt, type->baseType, |
| 10256 | valType)); |
| 10257 | } else if ((type->subtypes != NULL) && |
| 10258 | ((type->subtypes->type == XML_SCHEMA_TYPE_COMPLEX) || |
| 10259 | (type->subtypes->type == XML_SCHEMA_TYPE_COMPLEX_CONTENT) || |
| 10260 | (type->subtypes->type == XML_SCHEMA_TYPE_SIMPLE) || |
| 10261 | (type->subtypes->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT))) { |
| 10262 | return(xmlSchemaIsDerivedFromBuiltInType(ctxt, type->subtypes, |
| 10263 | valType)); |
| 10264 | } |
| 10265 | |
| 10266 | return (0); |
| 10267 | } |
| 10268 | |
| 10269 | /** |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 10270 | * xmlSchemaGetPrimitiveType: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10271 | * @type: the simpleType definition |
| 10272 | * |
| 10273 | * Returns the primitive type of the given type or |
| 10274 | * NULL in case of error. |
| 10275 | */ |
| 10276 | static xmlSchemaTypePtr |
| 10277 | xmlSchemaGetPrimitiveType(xmlSchemaTypePtr type) |
| 10278 | { |
| 10279 | while (type != NULL) { |
| 10280 | if (type->flags & XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE) |
| 10281 | return (type); |
| 10282 | type = type->baseType; |
| 10283 | } |
| 10284 | |
| 10285 | return (NULL); |
| 10286 | } |
| 10287 | |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 10288 | /** |
| 10289 | * xmlSchemaGetBuiltInTypeAncestor: |
| 10290 | * @type: the simpleType definition |
| 10291 | * |
| 10292 | * Returns the primitive type of the given type or |
| 10293 | * NULL in case of error. |
| 10294 | */ |
| 10295 | static xmlSchemaTypePtr |
| 10296 | xmlSchemaGetBuiltInTypeAncestor(xmlSchemaTypePtr type) |
| 10297 | { |
| 10298 | while (type != NULL) { |
| 10299 | if (type->type == XML_SCHEMA_TYPE_BASIC) |
| 10300 | return (type); |
| 10301 | type = type->baseType; |
| 10302 | } |
| 10303 | |
| 10304 | return (NULL); |
| 10305 | } |
| 10306 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 10307 | |
| 10308 | /** |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10309 | * xmlSchemaBuildAttributeUsesOwned: |
| 10310 | * @ctxt: the schema parser context |
| 10311 | * @type: the complex type definition |
| 10312 | * @cur: the attribute declaration list |
| 10313 | * @lastUse: the top of the attribute use list |
| 10314 | * |
| 10315 | * Builds the attribute uses list on the given complex type. |
| 10316 | * This one is supposed to be called by |
| 10317 | * xmlSchemaBuildAttributeValidation only. |
| 10318 | */ |
| 10319 | static int |
| 10320 | xmlSchemaBuildAttributeUsesOwned(xmlSchemaParserCtxtPtr ctxt, |
| 10321 | xmlSchemaAttributePtr cur, |
| 10322 | xmlSchemaAttributeLinkPtr *uses, |
| 10323 | xmlSchemaAttributeLinkPtr *lastUse) |
| 10324 | { |
| 10325 | xmlSchemaAttributeLinkPtr tmp; |
| 10326 | while (cur != NULL) { |
| 10327 | if (cur->type == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) { |
| 10328 | /* |
| 10329 | * W3C: "2 The {attribute uses} of the attribute groups ·resolved· |
| 10330 | * to by the ·actual value·s of the ref [attribute] of the |
| 10331 | * <attributeGroup> [children], if any." |
| 10332 | */ |
| 10333 | if (xmlSchemaBuildAttributeUsesOwned(ctxt, |
| 10334 | ((xmlSchemaAttributeGroupPtr) cur)->attributes, uses, |
| 10335 | lastUse) == -1) { |
| 10336 | return (-1); |
| 10337 | } |
| 10338 | } else { |
| 10339 | /* W3C: "1 The set of attribute uses corresponding to the |
| 10340 | * <attribute> [children], if any." |
| 10341 | */ |
| 10342 | tmp = (xmlSchemaAttributeLinkPtr) |
| 10343 | xmlMalloc(sizeof(xmlSchemaAttributeLink)); |
| 10344 | if (tmp == NULL) { |
| 10345 | xmlSchemaPErrMemory(ctxt, "building attribute uses", NULL); |
| 10346 | return (-1); |
| 10347 | } |
| 10348 | tmp->attr = cur; |
| 10349 | tmp->next = NULL; |
| 10350 | if (*uses == NULL) |
| 10351 | *uses = tmp; |
| 10352 | else |
| 10353 | (*lastUse)->next = tmp; |
| 10354 | *lastUse = tmp; |
| 10355 | } |
| 10356 | cur = cur->next; |
| 10357 | } |
| 10358 | return (0); |
| 10359 | } |
| 10360 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10361 | /** |
| 10362 | * xmlSchemaCloneWildcardNsConstraints: |
| 10363 | * @ctxt: the schema parser context |
| 10364 | * @dest: the destination wildcard |
| 10365 | * @source: the source wildcard |
| 10366 | * |
| 10367 | * Clones the namespace constraints of source |
| 10368 | * and assignes them to dest. |
| 10369 | * Returns -1 on internal error, 0 otherwise. |
| 10370 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10371 | static int |
| 10372 | xmlSchemaCloneWildcardNsConstraints(xmlSchemaParserCtxtPtr ctxt, |
| 10373 | xmlSchemaWildcardPtr *dest, |
| 10374 | xmlSchemaWildcardPtr source) |
| 10375 | { |
| 10376 | xmlSchemaWildcardNsPtr cur, tmp, last; |
| 10377 | |
| 10378 | if ((source == NULL) || (*dest == NULL)) |
| 10379 | return(-1); |
| 10380 | (*dest)->any = source->any; |
| 10381 | cur = source->nsSet; |
| 10382 | last = NULL; |
| 10383 | while (cur != NULL) { |
| 10384 | tmp = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 10385 | if (tmp == NULL) |
| 10386 | return(-1); |
| 10387 | tmp->value = cur->value; |
| 10388 | if (last == NULL) |
| 10389 | (*dest)->nsSet = tmp; |
| 10390 | else |
| 10391 | last->next = tmp; |
| 10392 | last = tmp; |
| 10393 | cur = cur->next; |
| 10394 | } |
| 10395 | if ((*dest)->negNsSet != NULL) |
| 10396 | xmlSchemaFreeWildcardNsSet((*dest)->negNsSet); |
| 10397 | if (source->negNsSet != NULL) { |
| 10398 | (*dest)->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 10399 | if ((*dest)->negNsSet == NULL) |
| 10400 | return(-1); |
| 10401 | (*dest)->negNsSet->value = source->negNsSet->value; |
| 10402 | } else |
| 10403 | (*dest)->negNsSet = NULL; |
| 10404 | return(0); |
| 10405 | } |
| 10406 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10407 | /** |
| 10408 | * xmlSchemaUnionWildcards: |
| 10409 | * @ctxt: the schema parser context |
| 10410 | * @completeWild: the first wildcard |
| 10411 | * @curWild: the second wildcard |
| 10412 | * |
| 10413 | * Unions the namespace constraints of the given wildcards. |
| 10414 | * @completeWild will hold the resulting union. |
| 10415 | * Returns a positive error code on failure, -1 in case of an |
| 10416 | * internal error, 0 otherwise. |
| 10417 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10418 | static int |
| 10419 | xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt, |
| 10420 | xmlSchemaWildcardPtr completeWild, |
| 10421 | xmlSchemaWildcardPtr curWild) |
| 10422 | { |
| 10423 | xmlSchemaWildcardNsPtr cur, curB, tmp; |
| 10424 | |
| 10425 | /* |
| 10426 | * 1 If O1 and O2 are the same value, then that value must be the |
| 10427 | * value. |
| 10428 | */ |
| 10429 | if ((completeWild->any == curWild->any) && |
| 10430 | ((completeWild->nsSet == NULL) == (curWild->nsSet == NULL)) && |
| 10431 | ((completeWild->negNsSet == NULL) == (curWild->negNsSet == NULL))) { |
| 10432 | |
| 10433 | if ((completeWild->negNsSet == NULL) || |
| 10434 | (completeWild->negNsSet->value == curWild->negNsSet->value)) { |
| 10435 | |
| 10436 | if (completeWild->nsSet != NULL) { |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 10437 | int found = 0; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10438 | |
| 10439 | /* |
| 10440 | * Check equality of sets. |
| 10441 | */ |
| 10442 | cur = completeWild->nsSet; |
| 10443 | while (cur != NULL) { |
| 10444 | found = 0; |
| 10445 | curB = curWild->nsSet; |
| 10446 | while (curB != NULL) { |
| 10447 | if (cur->value == curB->value) { |
| 10448 | found = 1; |
| 10449 | break; |
| 10450 | } |
| 10451 | curB = curB->next; |
| 10452 | } |
| 10453 | if (!found) |
| 10454 | break; |
| 10455 | cur = cur->next; |
| 10456 | } |
| 10457 | if (found) |
| 10458 | return(0); |
| 10459 | } else |
| 10460 | return(0); |
| 10461 | } |
| 10462 | } |
| 10463 | /* |
| 10464 | * 2 If either O1 or O2 is any, then any must be the value |
| 10465 | */ |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10466 | if (completeWild->any != curWild->any) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10467 | if (completeWild->any == 0) { |
| 10468 | completeWild->any = 1; |
| 10469 | if (completeWild->nsSet != NULL) { |
| 10470 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 10471 | completeWild->nsSet = NULL; |
| 10472 | } |
| 10473 | if (completeWild->negNsSet != NULL) { |
| 10474 | xmlFree(completeWild->negNsSet); |
| 10475 | completeWild->negNsSet = NULL; |
| 10476 | } |
| 10477 | } |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10478 | return (0); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10479 | } |
| 10480 | /* |
| 10481 | * 3 If both O1 and O2 are sets of (namespace names or ·absent·), |
| 10482 | * then the union of those sets must be the value. |
| 10483 | */ |
| 10484 | if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) { |
| 10485 | int found; |
| 10486 | xmlSchemaWildcardNsPtr start; |
| 10487 | |
| 10488 | cur = curWild->nsSet; |
| 10489 | start = completeWild->nsSet; |
| 10490 | while (cur != NULL) { |
| 10491 | found = 0; |
| 10492 | curB = start; |
| 10493 | while (curB != NULL) { |
| 10494 | if (cur->value == curB->value) { |
| 10495 | found = 1; |
| 10496 | break; |
| 10497 | } |
| 10498 | curB = curB->next; |
| 10499 | } |
| 10500 | if (!found) { |
| 10501 | tmp = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 10502 | if (tmp == NULL) |
| 10503 | return (-1); |
| 10504 | tmp->value = cur->value; |
| 10505 | tmp->next = completeWild->nsSet; |
| 10506 | completeWild->nsSet = tmp; |
| 10507 | } |
| 10508 | cur = cur->next; |
| 10509 | } |
| 10510 | |
| 10511 | return(0); |
| 10512 | } |
| 10513 | /* |
| 10514 | * 4 If the two are negations of different values (namespace names |
| 10515 | * or ·absent·), then a pair of not and ·absent· must be the value. |
| 10516 | */ |
| 10517 | if ((completeWild->negNsSet != NULL) && |
| 10518 | (curWild->negNsSet != NULL) && |
| 10519 | (completeWild->negNsSet->value != curWild->negNsSet->value)) { |
| 10520 | completeWild->negNsSet->value = NULL; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10521 | |
| 10522 | return(0); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10523 | } |
| 10524 | /* |
| 10525 | * 5. |
| 10526 | */ |
| 10527 | if (((completeWild->negNsSet != NULL) && |
| 10528 | (completeWild->negNsSet->value != NULL) && |
| 10529 | (curWild->nsSet != NULL)) || |
| 10530 | ((curWild->negNsSet != NULL) && |
| 10531 | (curWild->negNsSet->value != NULL) && |
| 10532 | (completeWild->nsSet != NULL))) { |
| 10533 | |
| 10534 | int nsFound, absentFound = 0; |
| 10535 | |
| 10536 | if (completeWild->nsSet != NULL) { |
| 10537 | cur = completeWild->nsSet; |
| 10538 | curB = curWild->negNsSet; |
| 10539 | } else { |
| 10540 | cur = curWild->nsSet; |
| 10541 | curB = completeWild->negNsSet; |
| 10542 | } |
| 10543 | nsFound = 0; |
| 10544 | while (cur != NULL) { |
| 10545 | if (cur->value == NULL) |
| 10546 | absentFound = 1; |
| 10547 | else if (cur->value == curB->value) |
| 10548 | nsFound = 1; |
| 10549 | if (nsFound && absentFound) |
| 10550 | break; |
| 10551 | cur = cur->next; |
| 10552 | } |
| 10553 | |
| 10554 | if (nsFound && absentFound) { |
| 10555 | /* |
| 10556 | * 5.1 If the set S includes both the negated namespace |
| 10557 | * name and ·absent·, then any must be the value. |
| 10558 | */ |
| 10559 | completeWild->any = 1; |
| 10560 | if (completeWild->nsSet != NULL) { |
| 10561 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 10562 | completeWild->nsSet = NULL; |
| 10563 | } |
| 10564 | if (completeWild->negNsSet != NULL) { |
| 10565 | xmlFree(completeWild->negNsSet); |
| 10566 | completeWild->negNsSet = NULL; |
| 10567 | } |
| 10568 | } else if (nsFound && (!absentFound)) { |
| 10569 | /* |
| 10570 | * 5.2 If the set S includes the negated namespace name |
| 10571 | * but not ·absent·, then a pair of not and ·absent· must |
| 10572 | * be the value. |
| 10573 | */ |
| 10574 | if (completeWild->nsSet != NULL) { |
| 10575 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 10576 | completeWild->nsSet = NULL; |
| 10577 | } |
| 10578 | if (completeWild->negNsSet == NULL) { |
| 10579 | completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 10580 | if (completeWild->negNsSet == NULL) |
| 10581 | return (-1); |
| 10582 | } |
| 10583 | completeWild->negNsSet->value = NULL; |
| 10584 | } else if ((!nsFound) && absentFound) { |
| 10585 | /* |
| 10586 | * 5.3 If the set S includes ·absent· but not the negated |
| 10587 | * namespace name, then the union is not expressible. |
| 10588 | */ |
| 10589 | xmlSchemaPErr(ctxt, completeWild->node, |
| 10590 | XML_SCHEMAP_UNION_NOT_EXPRESSIBLE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10591 | "The union of the wilcard is not expressible.\n", |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10592 | NULL, NULL); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10593 | return(XML_SCHEMAP_UNION_NOT_EXPRESSIBLE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10594 | } else if ((!nsFound) && (!absentFound)) { |
| 10595 | /* |
| 10596 | * 5.4 If the set S does not include either the negated namespace |
| 10597 | * name or ·absent·, then whichever of O1 or O2 is a pair of not |
| 10598 | * and a namespace name must be the value. |
| 10599 | */ |
| 10600 | if (completeWild->negNsSet == NULL) { |
| 10601 | if (completeWild->nsSet != NULL) { |
| 10602 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 10603 | completeWild->nsSet = NULL; |
| 10604 | } |
| 10605 | completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 10606 | if (completeWild->negNsSet == NULL) |
| 10607 | return (-1); |
| 10608 | completeWild->negNsSet->value = curWild->negNsSet->value; |
| 10609 | } |
| 10610 | } |
| 10611 | return (0); |
| 10612 | } |
| 10613 | /* |
| 10614 | * 6. |
| 10615 | */ |
| 10616 | if (((completeWild->negNsSet != NULL) && |
| 10617 | (completeWild->negNsSet->value == NULL) && |
| 10618 | (curWild->nsSet != NULL)) || |
| 10619 | ((curWild->negNsSet != NULL) && |
| 10620 | (curWild->negNsSet->value == NULL) && |
| 10621 | (completeWild->nsSet != NULL))) { |
| 10622 | |
| 10623 | if (completeWild->nsSet != NULL) { |
| 10624 | cur = completeWild->nsSet; |
| 10625 | } else { |
| 10626 | cur = curWild->nsSet; |
| 10627 | } |
| 10628 | while (cur != NULL) { |
| 10629 | if (cur->value == NULL) { |
| 10630 | /* |
| 10631 | * 6.1 If the set S includes ·absent·, then any must be the |
| 10632 | * value. |
| 10633 | */ |
| 10634 | completeWild->any = 1; |
| 10635 | if (completeWild->nsSet != NULL) { |
| 10636 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 10637 | completeWild->nsSet = NULL; |
| 10638 | } |
| 10639 | if (completeWild->negNsSet != NULL) { |
| 10640 | xmlFree(completeWild->negNsSet); |
| 10641 | completeWild->negNsSet = NULL; |
| 10642 | } |
| 10643 | return (0); |
| 10644 | } |
| 10645 | cur = cur->next; |
| 10646 | } |
| 10647 | if (completeWild->negNsSet == NULL) { |
| 10648 | /* |
| 10649 | * 6.2 If the set S does not include ·absent·, then a pair of not |
| 10650 | * and ·absent· must be the value. |
| 10651 | */ |
| 10652 | if (completeWild->nsSet != NULL) { |
| 10653 | xmlSchemaFreeWildcardNsSet(completeWild->nsSet); |
| 10654 | completeWild->nsSet = NULL; |
| 10655 | } |
| 10656 | completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt); |
| 10657 | if (completeWild->negNsSet == NULL) |
| 10658 | return (-1); |
| 10659 | completeWild->negNsSet->value = NULL; |
| 10660 | } |
| 10661 | return (0); |
| 10662 | } |
| 10663 | return (0); |
| 10664 | |
| 10665 | } |
| 10666 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10667 | /** |
| 10668 | * xmlSchemaIntersectWildcards: |
| 10669 | * @ctxt: the schema parser context |
| 10670 | * @completeWild: the first wildcard |
| 10671 | * @curWild: the second wildcard |
| 10672 | * |
| 10673 | * Intersects the namespace constraints of the given wildcards. |
| 10674 | * @completeWild will hold the resulting intersection. |
| 10675 | * Returns a positive error code on failure, -1 in case of an |
| 10676 | * internal error, 0 otherwise. |
| 10677 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10678 | static int |
| 10679 | xmlSchemaIntersectWildcards(xmlSchemaParserCtxtPtr ctxt, |
| 10680 | xmlSchemaWildcardPtr completeWild, |
| 10681 | xmlSchemaWildcardPtr curWild) |
| 10682 | { |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 10683 | xmlSchemaWildcardNsPtr cur, curB, prev, tmp; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10684 | |
| 10685 | /* |
| 10686 | * 1 If O1 and O2 are the same value, then that value must be the |
| 10687 | * value. |
| 10688 | */ |
| 10689 | if ((completeWild->any == curWild->any) && |
| 10690 | ((completeWild->nsSet == NULL) == (curWild->nsSet == NULL)) && |
| 10691 | ((completeWild->negNsSet == NULL) == (curWild->negNsSet == NULL))) { |
| 10692 | |
| 10693 | if ((completeWild->negNsSet == NULL) || |
| 10694 | (completeWild->negNsSet->value == curWild->negNsSet->value)) { |
| 10695 | |
| 10696 | if (completeWild->nsSet != NULL) { |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 10697 | int found = 0; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10698 | |
| 10699 | /* |
| 10700 | * Check equality of sets. |
| 10701 | */ |
| 10702 | cur = completeWild->nsSet; |
| 10703 | while (cur != NULL) { |
| 10704 | found = 0; |
| 10705 | curB = curWild->nsSet; |
| 10706 | while (curB != NULL) { |
| 10707 | if (cur->value == curB->value) { |
| 10708 | found = 1; |
| 10709 | break; |
| 10710 | } |
| 10711 | curB = curB->next; |
| 10712 | } |
| 10713 | if (!found) |
| 10714 | break; |
| 10715 | cur = cur->next; |
| 10716 | } |
| 10717 | if (found) |
| 10718 | return(0); |
| 10719 | } else |
| 10720 | return(0); |
| 10721 | } |
| 10722 | } |
| 10723 | /* |
| 10724 | * 2 If either O1 or O2 is any, then the other must be the value. |
| 10725 | */ |
| 10726 | if ((completeWild->any != curWild->any) && (completeWild->any)) { |
| 10727 | if (xmlSchemaCloneWildcardNsConstraints(ctxt, &completeWild, curWild) == -1) |
| 10728 | return(-1); |
| 10729 | return(0); |
| 10730 | } |
| 10731 | /* |
| 10732 | * 3 If either O1 or O2 is a pair of not and a value (a namespace |
| 10733 | * name or ·absent·) and the other is a set of (namespace names or |
| 10734 | * ·absent·), then that set, minus the negated value if it was in |
| 10735 | * the set, minus ·absent· if it was in the set, must be the value. |
| 10736 | */ |
| 10737 | if (((completeWild->negNsSet != NULL) && (curWild->nsSet != NULL)) || |
| 10738 | ((curWild->negNsSet != NULL) && (completeWild->nsSet != NULL))) { |
| 10739 | const xmlChar *neg; |
| 10740 | |
| 10741 | if (completeWild->nsSet == NULL) { |
| 10742 | neg = completeWild->negNsSet->value; |
| 10743 | if (xmlSchemaCloneWildcardNsConstraints(ctxt, &completeWild, curWild) == -1) |
| 10744 | return(-1); |
| 10745 | } else |
| 10746 | neg = curWild->negNsSet->value; |
| 10747 | /* |
| 10748 | * Remove absent and negated. |
| 10749 | */ |
| 10750 | prev = NULL; |
| 10751 | cur = completeWild->nsSet; |
| 10752 | while (cur != NULL) { |
| 10753 | if (cur->value == NULL) { |
| 10754 | if (prev == NULL) |
| 10755 | completeWild->nsSet = cur->next; |
| 10756 | else |
| 10757 | prev->next = cur->next; |
| 10758 | xmlFree(cur); |
| 10759 | break; |
| 10760 | } |
| 10761 | prev = cur; |
| 10762 | cur = cur->next; |
| 10763 | } |
| 10764 | if (neg != NULL) { |
| 10765 | prev = NULL; |
| 10766 | cur = completeWild->nsSet; |
| 10767 | while (cur != NULL) { |
| 10768 | if (cur->value == neg) { |
| 10769 | if (prev == NULL) |
| 10770 | completeWild->nsSet = cur->next; |
| 10771 | else |
| 10772 | prev->next = cur->next; |
| 10773 | xmlFree(cur); |
| 10774 | break; |
| 10775 | } |
| 10776 | prev = cur; |
| 10777 | cur = cur->next; |
| 10778 | } |
| 10779 | } |
| 10780 | |
| 10781 | return(0); |
| 10782 | } |
| 10783 | /* |
| 10784 | * 4 If both O1 and O2 are sets of (namespace names or ·absent·), |
| 10785 | * then the intersection of those sets must be the value. |
| 10786 | */ |
| 10787 | if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) { |
| 10788 | int found; |
| 10789 | |
| 10790 | cur = completeWild->nsSet; |
| 10791 | prev = NULL; |
| 10792 | while (cur != NULL) { |
| 10793 | found = 0; |
| 10794 | curB = curWild->nsSet; |
| 10795 | while (curB != NULL) { |
| 10796 | if (cur->value == curB->value) { |
| 10797 | found = 1; |
| 10798 | break; |
| 10799 | } |
| 10800 | curB = curB->next; |
| 10801 | } |
| 10802 | if (!found) { |
| 10803 | if (prev == NULL) |
| 10804 | completeWild->nsSet = cur->next; |
| 10805 | else |
| 10806 | prev->next = cur->next; |
| 10807 | tmp = cur->next; |
| 10808 | xmlFree(cur); |
| 10809 | cur = tmp; |
| 10810 | continue; |
| 10811 | } |
| 10812 | prev = cur; |
| 10813 | cur = cur->next; |
| 10814 | } |
| 10815 | |
| 10816 | return(0); |
| 10817 | } |
| 10818 | /* 5 If the two are negations of different namespace names, |
| 10819 | * then the intersection is not expressible |
| 10820 | */ |
| 10821 | if ((completeWild->negNsSet != NULL) && |
| 10822 | (curWild->negNsSet != NULL) && |
| 10823 | (completeWild->negNsSet->value != curWild->negNsSet->value) && |
| 10824 | (completeWild->negNsSet->value != NULL) && |
| 10825 | (curWild->negNsSet->value != NULL)) { |
| 10826 | |
| 10827 | xmlSchemaPErr(ctxt, completeWild->node, XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10828 | "The intersection of the wilcard is not expressible.\n", |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10829 | NULL, NULL); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10830 | return(XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10831 | } |
| 10832 | /* |
| 10833 | * 6 If the one is a negation of a namespace name and the other |
| 10834 | * is a negation of ·absent·, then the one which is the negation |
| 10835 | * of a namespace name must be the value. |
| 10836 | */ |
| 10837 | if ((completeWild->negNsSet != NULL) && (curWild->negNsSet != NULL) && |
| 10838 | (completeWild->negNsSet->value != curWild->negNsSet->value) && |
| 10839 | (completeWild->negNsSet->value == NULL)) { |
| 10840 | completeWild->negNsSet->value = curWild->negNsSet->value; |
| 10841 | } |
| 10842 | return(0); |
| 10843 | } |
| 10844 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10845 | /** |
| 10846 | * xmlSchemaIsWildcardNsConstraintSubset: |
| 10847 | * @ctxt: the schema parser context |
| 10848 | * @wildA: the first wildcard |
| 10849 | * @wildB: the second wildcard |
| 10850 | * |
| 10851 | * Returns 1 if the namespace constraint of @wildA is an intensional |
| 10852 | * subset of @wildB, 0 otherwise. |
| 10853 | */ |
| 10854 | static int |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 10855 | xmlSchemaIsWildcardNsConstraintSubset(xmlSchemaWildcardPtr wildA, |
| 10856 | xmlSchemaWildcardPtr wildB) |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10857 | { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10858 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10859 | /* |
| 10860 | * Schema Component Constraint: Wildcard Subset |
| 10861 | */ |
| 10862 | /* |
| 10863 | * 1 super must be any. |
| 10864 | */ |
| 10865 | if (wildB->any) |
| 10866 | return (1); |
| 10867 | /* |
| 10868 | * 2.1 sub must be a pair of not and a namespace name or ·absent·. |
| 10869 | * 2.2 super must be a pair of not and the same value. |
| 10870 | */ |
| 10871 | if ((wildA->negNsSet != NULL) && |
| 10872 | (wildB->negNsSet != NULL) && |
| 10873 | (wildA->negNsSet->value == wildA->negNsSet->value)) |
| 10874 | return (1); |
| 10875 | /* |
| 10876 | * 3.1 sub must be a set whose members are either namespace names or ·absent·. |
| 10877 | */ |
| 10878 | if (wildA->nsSet != NULL) { |
| 10879 | /* |
| 10880 | * 3.2.1 super must be the same set or a superset thereof. |
| 10881 | */ |
| 10882 | if (wildB->nsSet != NULL) { |
| 10883 | xmlSchemaWildcardNsPtr cur, curB; |
| 10884 | int found = 0; |
| 10885 | |
| 10886 | cur = wildA->nsSet; |
| 10887 | while (cur != NULL) { |
| 10888 | found = 0; |
| 10889 | curB = wildB->nsSet; |
| 10890 | while (curB != NULL) { |
| 10891 | if (cur->value == curB->value) { |
| 10892 | found = 1; |
| 10893 | break; |
| 10894 | } |
| 10895 | curB = curB->next; |
| 10896 | } |
| 10897 | if (!found) |
| 10898 | return (0); |
| 10899 | cur = cur->next; |
| 10900 | } |
| 10901 | if (found) |
| 10902 | return (1); |
| 10903 | } else if (wildB->negNsSet != NULL) { |
| 10904 | xmlSchemaWildcardNsPtr cur; |
| 10905 | /* |
| 10906 | * 3.2.2 super must be a pair of not and a namespace name or |
| 10907 | * ·absent· and that value must not be in sub's set. |
| 10908 | */ |
| 10909 | cur = wildA->nsSet; |
| 10910 | while (cur != NULL) { |
| 10911 | if (cur->value == wildB->negNsSet->value) |
| 10912 | return (0); |
| 10913 | cur = cur->next; |
| 10914 | } |
| 10915 | return (1); |
| 10916 | } |
| 10917 | } |
| 10918 | return (0); |
| 10919 | } |
| 10920 | |
| 10921 | /** |
| 10922 | * xmlSchemaBuildCompleteAttributeWildcard: |
| 10923 | * @ctxt: the schema parser context |
| 10924 | * @attrs: the attribute list |
| 10925 | * @completeWild: the resulting complete wildcard |
| 10926 | * |
| 10927 | * Returns -1 in case of an internal error, 0 otherwise. |
| 10928 | */ |
| 10929 | static int |
| 10930 | xmlSchemaBuildCompleteAttributeWildcard(xmlSchemaParserCtxtPtr ctxt, |
| 10931 | xmlSchemaAttributePtr attrs, |
| 10932 | xmlSchemaWildcardPtr *completeWild) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10933 | { |
| 10934 | while (attrs != NULL) { |
| 10935 | if (attrs->type == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) { |
| 10936 | xmlSchemaAttributeGroupPtr group; |
| 10937 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10938 | group = (xmlSchemaAttributeGroupPtr) attrs; |
| 10939 | /* |
| 10940 | * Handle attribute group references. |
| 10941 | */ |
| 10942 | if (group->ref != NULL) { |
| 10943 | if (group->refItem == NULL) { |
| 10944 | /* |
| 10945 | * TODO: Should we raise a warning here? |
| 10946 | */ |
| 10947 | /* |
| 10948 | * The referenced attribute group definition could not |
| 10949 | * be resolved beforehand, so skip. |
| 10950 | */ |
| 10951 | attrs = attrs->next; |
| 10952 | continue; |
| 10953 | } else |
| 10954 | group = group->refItem; |
| 10955 | } |
| 10956 | /* |
| 10957 | * For every attribute group definition, an intersected wildcard |
| 10958 | * will be created (assumed that a wildcard exists on the |
| 10959 | * particular attr. gr. def. or on any contained attr. gr. def |
| 10960 | * at all). |
| 10961 | * The flag XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED ensures |
| 10962 | * that the intersection will be performed only once. |
| 10963 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10964 | if ((group->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED) == 0) { |
| 10965 | if (group->attributes != NULL) { |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10966 | if (xmlSchemaBuildCompleteAttributeWildcard(ctxt, |
| 10967 | group->attributes, &group->attributeWildcard) == -1) |
| 10968 | return (-1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10969 | } |
| 10970 | group->flags |= XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED; |
| 10971 | } |
| 10972 | if (group->attributeWildcard != NULL) { |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10973 | if (*completeWild == NULL) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10974 | /* |
| 10975 | * Copy the first encountered wildcard as context, except for the annotation. |
| 10976 | */ |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10977 | *completeWild = xmlSchemaAddWildcard(ctxt); |
| 10978 | (*completeWild)->type = XML_SCHEMA_TYPE_ANY_ATTRIBUTE; |
| 10979 | if (xmlSchemaCloneWildcardNsConstraints(ctxt, |
| 10980 | completeWild, group->attributeWildcard) == -1) |
| 10981 | return (-1); |
| 10982 | (*completeWild)->processContents = group->attributeWildcard->processContents; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10983 | /* |
| 10984 | * Although the complete wildcard might not correspond to any |
| 10985 | * node in the schema, we will save this context node. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 10986 | * TODO: Hmm, is this sane? |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10987 | */ |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10988 | (*completeWild)->node = group->attributeWildcard->node; |
| 10989 | |
| 10990 | } else if (xmlSchemaIntersectWildcards(ctxt, *completeWild, group->attributeWildcard) == -1) { |
| 10991 | xmlSchemaFreeWildcard(*completeWild); |
| 10992 | return (-1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 10993 | } |
| 10994 | } |
| 10995 | } |
| 10996 | attrs = attrs->next; |
| 10997 | } |
| 10998 | |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 10999 | return (0); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11000 | } |
| 11001 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11002 | static int |
| 11003 | xmlSchemaGetEffectiveValueConstraint(xmlSchemaAttributePtr item, |
| 11004 | int *fixed, |
| 11005 | const xmlChar **value, |
| 11006 | xmlSchemaValPtr *val) |
| 11007 | { |
| 11008 | *fixed = 0; |
| 11009 | *value = NULL; |
| 11010 | if (val != 0) |
| 11011 | *val = NULL; |
| 11012 | |
| 11013 | if (item->defValue == NULL) |
| 11014 | item = item->refDecl; |
| 11015 | |
| 11016 | if (item == NULL) |
| 11017 | return (0); |
| 11018 | |
| 11019 | if (item->defValue != NULL) { |
| 11020 | *value = item->defValue; |
| 11021 | if (val != 0) |
| 11022 | *val = item->defVal; |
| 11023 | if (item->flags & XML_SCHEMAS_ATTR_FIXED) |
| 11024 | *fixed = 1; |
| 11025 | return (1); |
| 11026 | } |
| 11027 | return (0); |
| 11028 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11029 | /** |
| 11030 | * xmlSchemaMatchesWildcardNs: |
| 11031 | * @wild: the wildcard |
| 11032 | * @ns: the namespace |
| 11033 | * |
| 11034 | * |
| 11035 | * Returns 1 if the given namespace matches the wildcard, |
| 11036 | * 0 otherwise. |
| 11037 | */ |
| 11038 | static int |
| 11039 | xmlSchemaMatchesWildcardNs(xmlSchemaWildcardPtr wild, const xmlChar* ns) |
| 11040 | { |
| 11041 | if (wild == NULL) |
| 11042 | return(0); |
| 11043 | |
| 11044 | if (wild->any) |
| 11045 | return(1); |
| 11046 | else if (wild->nsSet != NULL) { |
| 11047 | xmlSchemaWildcardNsPtr cur; |
| 11048 | |
| 11049 | cur = wild->nsSet; |
| 11050 | while (cur != NULL) { |
| 11051 | if (xmlStrEqual(cur->value, ns)) |
| 11052 | return(1); |
| 11053 | cur = cur->next; |
| 11054 | } |
| 11055 | } else if ((wild->negNsSet != NULL) && (ns != NULL) && |
| 11056 | (!xmlStrEqual(wild->negNsSet->value, ns))) |
| 11057 | return(1); |
| 11058 | |
| 11059 | return(0); |
| 11060 | } |
| 11061 | |
| 11062 | /** |
| 11063 | * xmlSchemaBuildAttributeValidation: |
| 11064 | * @ctxt: the schema parser context |
| 11065 | * @type: the complex type definition |
| 11066 | * |
| 11067 | * |
| 11068 | * Builds the wildcard and the attribute uses on the given complex type. |
| 11069 | * Returns -1 if an internal error occurs, 0 otherwise. |
| 11070 | */ |
| 11071 | static int |
| 11072 | xmlSchemaBuildAttributeValidation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaTypePtr type) |
| 11073 | { |
| 11074 | xmlSchemaTypePtr baseType = NULL; |
| 11075 | xmlSchemaAttributeLinkPtr cur, base, tmp, id = NULL, prev = NULL, uses = NULL, |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 11076 | lastUse = NULL, lastBaseUse = NULL; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11077 | xmlSchemaAttributePtr attrs; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11078 | xmlSchemaTypePtr anyType; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11079 | int baseIsAnyType = 0; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11080 | xmlChar *str = NULL; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 11081 | int err = 0; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11082 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11083 | anyType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11084 | /* |
| 11085 | * Complex Type Definition with complex content Schema Component. |
| 11086 | * |
| 11087 | * Attribute uses. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11088 | * TODO: Add checks for absent referenced attribute declarations and |
| 11089 | * simple types. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11090 | */ |
| 11091 | if (type->attributeUses != NULL) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 11092 | xmlSchemaPErr(ctxt, type->node, XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11093 | "Internal error: xmlSchemaBuildAttributeValidation: " |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11094 | "attribute uses already builded.\n", |
| 11095 | NULL, NULL); |
| 11096 | return (-1); |
| 11097 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11098 | if (type->baseType == NULL) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 11099 | xmlSchemaPErr(ctxt, type->node, XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11100 | "Internal error: xmlSchemaBuildAttributeValidation: " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11101 | "complex type '%s' has no base type.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11102 | type->name, NULL); |
| 11103 | return (-1); |
| 11104 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11105 | baseType = type->baseType; |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11106 | if (baseType == anyType) |
| 11107 | baseIsAnyType = 1; |
| 11108 | /* |
| 11109 | * Inherit the attribute uses of the base type. |
| 11110 | */ |
| 11111 | /* |
| 11112 | * NOTE: It is allowed to "extend" the anyType complex type. |
| 11113 | */ |
| 11114 | if (!baseIsAnyType) { |
| 11115 | if (baseType != NULL) { |
| 11116 | for (cur = baseType->attributeUses; cur != NULL; cur = cur->next) { |
| 11117 | tmp = (xmlSchemaAttributeLinkPtr) |
| 11118 | xmlMalloc(sizeof(xmlSchemaAttributeLink)); |
| 11119 | if (tmp == NULL) { |
| 11120 | xmlSchemaPErrMemory(ctxt, |
| 11121 | "building attribute uses of complexType", NULL); |
| 11122 | return (-1); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11123 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11124 | tmp->attr = cur->attr; |
| 11125 | tmp->next = NULL; |
| 11126 | if (type->attributeUses == NULL) { |
| 11127 | type->attributeUses = tmp; |
| 11128 | } else |
| 11129 | lastBaseUse->next = tmp; |
| 11130 | lastBaseUse = tmp; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11131 | } |
| 11132 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11133 | } |
| 11134 | if ((type->subtypes != NULL) && |
| 11135 | ((type->subtypes->type == XML_SCHEMA_TYPE_COMPLEX_CONTENT) || |
| 11136 | (type->subtypes->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT))) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11137 | /* |
| 11138 | * type --> (<simpleContent>|<complexContent>) |
| 11139 | * --> (<restriction>|<extension>) --> attributes |
| 11140 | */ |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11141 | attrs = type->subtypes->subtypes->attributes; |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11142 | } else { |
| 11143 | /* Short hand form of the complexType. */ |
| 11144 | attrs = type->attributes; |
| 11145 | } |
| 11146 | /* |
| 11147 | * Handle attribute wildcards. |
| 11148 | */ |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 11149 | err = xmlSchemaBuildCompleteAttributeWildcard(ctxt, |
| 11150 | attrs, &type->attributeWildcard); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11151 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11152 | * NOTE: During the parse time, the wildcard is created on the complexType |
| 11153 | * directly, if encountered in a <restriction> or <extension> element. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11154 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11155 | if (err == -1) { |
| 11156 | xmlSchemaPErr(ctxt, type->node, XML_SCHEMAP_INTERNAL, |
| 11157 | "Internal error: xmlSchemaBuildAttributeValidation: " |
| 11158 | "failed to build an intersected attribute wildcard.\n", |
| 11159 | NULL, NULL); |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 11160 | return (-1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11161 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11162 | |
| 11163 | if ((type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) && |
| 11164 | ((baseIsAnyType) || |
| 11165 | ((baseType != NULL) && |
| 11166 | (baseType->type == XML_SCHEMA_TYPE_COMPLEX) && |
| 11167 | (baseType->attributeWildcard != NULL)))) { |
| 11168 | if (type->attributeWildcard != NULL) { |
| 11169 | /* |
| 11170 | * Union the complete wildcard with the base wildcard. |
| 11171 | */ |
| 11172 | if (xmlSchemaUnionWildcards(ctxt, type->attributeWildcard, |
| 11173 | baseType->attributeWildcard) == -1) |
| 11174 | return (-1); |
| 11175 | } else { |
| 11176 | /* |
| 11177 | * Just inherit the wildcard. |
| 11178 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 11179 | /* |
| 11180 | * NOTE: This is the only case where an attribute |
| 11181 | * wildcard is shared. |
| 11182 | */ |
| 11183 | if (type->flags & XML_SCHEMAS_TYPE_OWNED_ATTR_WILDCARD) |
| 11184 | type->flags ^= XML_SCHEMAS_TYPE_OWNED_ATTR_WILDCARD; |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11185 | type->attributeWildcard = baseType->attributeWildcard; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11186 | } |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11187 | } |
| 11188 | |
| 11189 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
| 11190 | if (type->attributeWildcard != NULL) { |
| 11191 | /* |
| 11192 | * Derivation Valid (Restriction, Complex) |
| 11193 | * 4.1 The {base type definition} must also have one. |
| 11194 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11195 | if (baseType->attributeWildcard == NULL) { |
| 11196 | xmlSchemaPCustomErr(ctxt, |
| 11197 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_1, |
| 11198 | NULL, type, NULL, |
| 11199 | "The type has an attribute wildcard, " |
| 11200 | "but the base type %s does not have one", |
| 11201 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 11202 | FREE_AND_NULL(str) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11203 | return (1); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11204 | } else if (xmlSchemaIsWildcardNsConstraintSubset( |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11205 | type->attributeWildcard, baseType->attributeWildcard) == 0) { |
| 11206 | /* 4.2 */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11207 | xmlSchemaPCustomErr(ctxt, |
| 11208 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_2, |
| 11209 | NULL, type, NULL, |
| 11210 | "The attribute wildcard is not a valid " |
| 11211 | "subset of the wildcard in the base type %s", |
| 11212 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 11213 | FREE_AND_NULL(str) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11214 | return (1); |
| 11215 | } |
| 11216 | /* 4.3 Unless the {base type definition} is the ·ur-type |
| 11217 | * definition·, the complex type definition's {attribute |
| 11218 | * wildcard}'s {process contents} must be identical to or |
| 11219 | * stronger than the {base type definition}'s {attribute |
| 11220 | * wildcard}'s {process contents}, where strict is stronger |
| 11221 | * than lax is stronger than skip. |
| 11222 | */ |
| 11223 | if ((type->baseType != anyType) && |
| 11224 | (type->attributeWildcard->processContents < |
| 11225 | baseType->attributeWildcard->processContents)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11226 | xmlSchemaPCustomErr(ctxt, |
| 11227 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_3, |
| 11228 | NULL, type, NULL, |
| 11229 | "The 'process contents' of the attribute wildcard is weaker than " |
| 11230 | "the one in the base type %s", |
| 11231 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 11232 | FREE_AND_NULL(str) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11233 | return (1); |
| 11234 | } |
| 11235 | } |
| 11236 | } else if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) { |
| 11237 | /* |
| 11238 | * Derivation Valid (Extension) |
| 11239 | * At this point the type and the base have both, either |
| 11240 | * no wildcard or a wildcard. |
| 11241 | */ |
| 11242 | if ((baseType->attributeWildcard != NULL) && |
| 11243 | (baseType->attributeWildcard != type->attributeWildcard)) { |
| 11244 | /* 1.3 */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11245 | if (xmlSchemaIsWildcardNsConstraintSubset( |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11246 | baseType->attributeWildcard, type->attributeWildcard) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11247 | xmlSchemaPCustomErr(ctxt, |
| 11248 | XML_SCHEMAP_COS_CT_EXTENDS_1_3, |
| 11249 | NULL, type, NULL, |
| 11250 | "The attribute wildcard is not a valid " |
| 11251 | "superset of the one in the base type %s", |
| 11252 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 11253 | FREE_AND_NULL(str) |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11254 | return (1); |
| 11255 | } |
| 11256 | } |
| 11257 | } |
| 11258 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11259 | /* |
| 11260 | * Gather attribute uses defined by this type. |
| 11261 | */ |
| 11262 | if (attrs != NULL) { |
| 11263 | if (xmlSchemaBuildAttributeUsesOwned(ctxt, attrs, |
| 11264 | &uses, &lastUse) == -1) { |
| 11265 | return (-1); |
| 11266 | } |
| 11267 | } |
| 11268 | /* 3.4.6 -> Complex Type Definition Properties Correct 4. |
| 11269 | * "Two distinct attribute declarations in the {attribute uses} must |
| 11270 | * not have identical {name}s and {target namespace}s." |
| 11271 | * |
| 11272 | * For "extension" this is done further down. |
| 11273 | */ |
| 11274 | if ((uses != NULL) && ((type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) == 0)) { |
| 11275 | cur = uses; |
| 11276 | while (cur != NULL) { |
| 11277 | tmp = cur->next; |
| 11278 | while (tmp != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11279 | if ((xmlStrEqual(xmlSchemaGetAttrName(cur->attr), |
| 11280 | xmlSchemaGetAttrName(tmp->attr))) && |
| 11281 | (xmlStrEqual(xmlSchemaGetAttrTargetNsURI(cur->attr ), |
| 11282 | xmlSchemaGetAttrTargetNsURI(tmp->attr)))) { |
| 11283 | |
| 11284 | xmlSchemaPAttrUseErr(ctxt, |
| 11285 | XML_SCHEMAP_CT_PROPS_CORRECT_4, |
| 11286 | NULL, type, NULL, cur->attr, |
| 11287 | "Duplicate attribute use %s specified", |
| 11288 | xmlSchemaFormatNsUriLocal(&str, |
| 11289 | xmlSchemaGetAttrTargetNsURI(tmp->attr), |
| 11290 | xmlSchemaGetAttrName(tmp->attr)) |
| 11291 | ); |
| 11292 | FREE_AND_NULL(str) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11293 | break; |
| 11294 | } |
| 11295 | tmp = tmp->next; |
| 11296 | } |
| 11297 | cur = cur->next; |
| 11298 | } |
| 11299 | } |
| 11300 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
| 11301 | /* |
| 11302 | * Derive by restriction. |
| 11303 | */ |
| 11304 | if (baseIsAnyType) { |
| 11305 | type->attributeUses = uses; |
| 11306 | } else { |
| 11307 | int found; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11308 | const xmlChar *bEffValue; |
| 11309 | int effFixed; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11310 | |
| 11311 | cur = uses; |
| 11312 | while (cur != NULL) { |
| 11313 | found = 0; |
| 11314 | base = type->attributeUses; |
| 11315 | while (base != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11316 | if (xmlStrEqual(xmlSchemaGetAttrName(cur->attr), |
| 11317 | xmlSchemaGetAttrName(base->attr)) && |
| 11318 | xmlStrEqual(xmlSchemaGetAttrTargetNsURI(cur->attr), |
| 11319 | xmlSchemaGetAttrTargetNsURI(base->attr))) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11320 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11321 | found = 1; |
| 11322 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11323 | if ((cur->attr->occurs == XML_SCHEMAS_ATTR_USE_OPTIONAL) && |
| 11324 | (base->attr->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED)) { |
| 11325 | /* |
| 11326 | * derivation-ok-restriction 2.1.1 |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11327 | */ |
| 11328 | xmlSchemaPAttrUseErr(ctxt, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11329 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11330 | NULL, type, NULL, cur->attr, |
| 11331 | "The 'optional' use is inconsistent with a matching " |
| 11332 | "'required' use of the base type", NULL); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11333 | } else if ((cur->attr->occurs == XML_SCHEMAS_ATTR_USE_PROHIBITED) && |
| 11334 | (base->attr->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED)) { |
| 11335 | /* |
| 11336 | * derivation-ok-restriction 3 |
| 11337 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11338 | xmlSchemaPCustomErr(ctxt, |
| 11339 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_3, |
| 11340 | NULL, type, NULL, |
| 11341 | "A matching attribute use for the 'required' " |
| 11342 | "attribute use %s of the base type is missing", |
| 11343 | xmlSchemaFormatNsUriLocal(&str, |
| 11344 | xmlSchemaGetAttrTargetNsURI(base->attr), |
| 11345 | xmlSchemaGetAttrName(base->attr))); |
| 11346 | FREE_AND_NULL(str) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11347 | } else { |
| 11348 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11349 | * 2.1.3 [Definition:] Let the effective value |
| 11350 | * constraint of an attribute use be its {value |
| 11351 | * constraint}, if present, otherwise its {attribute |
| 11352 | * declaration}'s {value constraint} . |
| 11353 | */ |
| 11354 | xmlSchemaGetEffectiveValueConstraint(base->attr, &effFixed, |
| 11355 | &bEffValue, 0); |
| 11356 | /* |
| 11357 | * 2.1.3 ... one of the following must be true |
| 11358 | * |
| 11359 | * 2.1.3.1 B's ·effective value constraint· is |
| 11360 | * ·absent· or default. |
| 11361 | */ |
| 11362 | if ((bEffValue != NULL) && |
| 11363 | (effFixed == 1)) { |
| 11364 | const xmlChar *rEffValue = NULL; |
| 11365 | |
| 11366 | xmlSchemaGetEffectiveValueConstraint(base->attr, &effFixed, |
| 11367 | &rEffValue, 0); |
| 11368 | /* |
| 11369 | * 2.1.3.2 R's ·effective value constraint· is |
| 11370 | * fixed with the same string as B's. |
| 11371 | */ |
| 11372 | if ((effFixed == 0) || |
| 11373 | (! xmlStrEqual(rEffValue, bEffValue))) { |
| 11374 | xmlSchemaPAttrUseErr(ctxt, |
| 11375 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_3, |
| 11376 | NULL, type, NULL, cur->attr, |
| 11377 | "The effective value constraint of the " |
| 11378 | "attribute use is inconsistent with " |
| 11379 | "its correspondent of the base type", |
| 11380 | NULL); |
| 11381 | } |
| 11382 | } |
| 11383 | /* |
| 11384 | * TODO: derivation-ok-restriction 2.1.2 ({type definition} must be validly derived) |
| 11385 | */ |
| 11386 | /* |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11387 | * Override the attribute use. |
| 11388 | */ |
| 11389 | base->attr = cur->attr; |
| 11390 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 11391 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11392 | break; |
| 11393 | } |
| 11394 | base = base->next; |
| 11395 | } |
| 11396 | |
| 11397 | if (!found) { |
| 11398 | if (cur->attr->occurs != XML_SCHEMAS_ATTR_USE_PROHIBITED) { |
| 11399 | /* |
| 11400 | * derivation-ok-restriction 2.2 |
| 11401 | */ |
| 11402 | if ((type->attributeWildcard != NULL) && |
| 11403 | xmlSchemaMatchesWildcardNs(type->attributeWildcard, |
| 11404 | cur->attr->targetNamespace)) |
| 11405 | found = 1; |
| 11406 | |
| 11407 | if (!found) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11408 | xmlSchemaPAttrUseErr(ctxt, |
| 11409 | XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_2, |
| 11410 | NULL, type, NULL, cur->attr, |
| 11411 | "Neither a matching attribute use, " |
| 11412 | "nor a matching wildcard in the base type does exist", |
| 11413 | NULL); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11414 | } else { |
| 11415 | /* |
| 11416 | * Add the attribute use. |
| 11417 | * |
| 11418 | * Note that this may lead to funny derivation error reports, if |
| 11419 | * multiple equal attribute uses exist; but this is not |
| 11420 | * allowed anyway, and it will be reported beforehand. |
| 11421 | */ |
| 11422 | tmp = cur; |
| 11423 | if (prev != NULL) |
| 11424 | prev->next = cur->next; |
| 11425 | else |
| 11426 | uses = cur->next; |
| 11427 | cur = cur->next; |
| 11428 | if (type->attributeUses == NULL) { |
| 11429 | type->attributeUses = tmp; |
| 11430 | } else |
| 11431 | lastBaseUse->next = tmp; |
| 11432 | lastBaseUse = tmp; |
| 11433 | |
| 11434 | continue; |
| 11435 | } |
| 11436 | } |
| 11437 | } |
| 11438 | prev = cur; |
| 11439 | cur = cur->next; |
| 11440 | } |
| 11441 | if (uses != NULL) |
| 11442 | xmlSchemaFreeAttributeUseList(uses); |
| 11443 | } |
| 11444 | } else if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) { |
| 11445 | /* |
| 11446 | * The spec allows only appending, and not other kinds of extensions. |
| 11447 | * |
| 11448 | * This ensures: Schema Component Constraint: Derivation Valid (Extension) : 1.2 |
| 11449 | */ |
| 11450 | if (uses != NULL) { |
| 11451 | if (type->attributeUses == NULL) { |
| 11452 | type->attributeUses = uses; |
| 11453 | } else |
| 11454 | lastBaseUse->next = uses; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11455 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11456 | } else { |
| 11457 | /* |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11458 | * Derive implicitely from the ur-type. |
| 11459 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11460 | type->attributeUses = uses; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11461 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11462 | /* |
| 11463 | * 3.4.6 -> Complex Type Definition Properties Correct |
| 11464 | */ |
| 11465 | if (type->attributeUses != NULL) { |
| 11466 | cur = type->attributeUses; |
| 11467 | prev = NULL; |
| 11468 | while (cur != NULL) { |
| 11469 | /* |
| 11470 | * 4. Two distinct attribute declarations in the {attribute uses} must |
| 11471 | * not have identical {name}s and {target namespace}s. |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11472 | * |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11473 | * Note that this was already done for "restriction" and types derived from |
| 11474 | * the ur-type. |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11475 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11476 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) { |
| 11477 | tmp = cur->next; |
| 11478 | while (tmp != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11479 | if ((xmlStrEqual(xmlSchemaGetAttrName(cur->attr), |
| 11480 | xmlSchemaGetAttrName(tmp->attr))) && |
| 11481 | (xmlStrEqual(xmlSchemaGetAttrTargetNsURI(cur->attr ), |
| 11482 | xmlSchemaGetAttrTargetNsURI(tmp->attr)))) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11483 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11484 | xmlSchemaPAttrUseErr(ctxt, |
| 11485 | XML_SCHEMAP_CT_PROPS_CORRECT_4, |
| 11486 | NULL, type, NULL, tmp->attr, |
| 11487 | "Duplicate attribute use specified", NULL); |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11488 | break; |
| 11489 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11490 | tmp = tmp->next; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11491 | } |
| 11492 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11493 | /* |
| 11494 | * 5. Two distinct attribute declarations in the {attribute uses} must |
| 11495 | * not have {type definition}s which are or are derived from ID. |
| 11496 | */ |
| 11497 | if ((cur->attr->subtypes != NULL) && |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11498 | (xmlSchemaIsDerivedFromBuiltInType(ctxt, (xmlSchemaTypePtr) cur->attr, XML_SCHEMAS_ID))) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11499 | if (id != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11500 | xmlSchemaPAttrUseErr(ctxt, |
| 11501 | XML_SCHEMAP_CT_PROPS_CORRECT_5, |
| 11502 | NULL, type, NULL, cur->attr, |
| 11503 | "There must not exist more than one attribute use, " |
| 11504 | "declared of type 'ID' or derived from it", |
| 11505 | NULL); |
| 11506 | FREE_AND_NULL(str) |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11507 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11508 | id = cur; |
| 11509 | } |
| 11510 | /* |
| 11511 | * Remove "prohibited" attribute uses. The reason this is done at this late |
| 11512 | * stage is to be able to catch dublicate attribute uses. So we had to keep |
| 11513 | * prohibited uses in the list as well. |
| 11514 | */ |
| 11515 | if (cur->attr->occurs == XML_SCHEMAS_ATTR_USE_PROHIBITED) { |
| 11516 | tmp = cur; |
| 11517 | if (prev == NULL) |
| 11518 | type->attributeUses = cur->next; |
| 11519 | else |
| 11520 | prev->next = cur->next; |
| 11521 | cur = cur->next; |
Daniel Veillard | 50355f0 | 2004-06-08 17:52:16 +0000 | [diff] [blame] | 11522 | xmlFree(tmp); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11523 | } else { |
| 11524 | prev = cur; |
| 11525 | cur = cur->next; |
| 11526 | } |
| 11527 | } |
| 11528 | } |
| 11529 | /* |
| 11530 | * TODO: This check should be removed if we are 100% sure of |
| 11531 | * the base type attribute uses already being built. |
| 11532 | */ |
| 11533 | if ((baseType != NULL) && (!baseIsAnyType) && |
| 11534 | (baseType->type == XML_SCHEMA_TYPE_COMPLEX) && |
| 11535 | (baseType->contentType == XML_SCHEMA_CONTENT_UNKNOWN)) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 11536 | xmlSchemaPErr(ctxt, baseType->node, XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11537 | "Internal error: xmlSchemaBuildAttributeValidation: " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11538 | "attribute uses not builded on base type '%s'.\n", |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 11539 | baseType->name, NULL); |
| 11540 | } |
| 11541 | return (0); |
| 11542 | } |
| 11543 | |
| 11544 | /** |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11545 | * xmlSchemaTypeFinalContains: |
| 11546 | * @schema: the schema |
| 11547 | * @type: the type definition |
| 11548 | * @final: the final |
| 11549 | * |
| 11550 | * Evaluates if a type definition contains the given "final". |
| 11551 | * This does take "finalDefault" into account as well. |
| 11552 | * |
| 11553 | * Returns 1 if the type does containt the given "final", |
| 11554 | * 0 otherwise. |
| 11555 | */ |
| 11556 | static int |
| 11557 | xmlSchemaTypeFinalContains(xmlSchemaPtr schema, xmlSchemaTypePtr type, int final) |
| 11558 | { |
| 11559 | int tfinal = final, tflags = type->flags; |
| 11560 | |
| 11561 | if (type == NULL) |
| 11562 | return (0); |
| 11563 | if (type->flags & XML_SCHEMAS_TYPE_FINAL_DEFAULT) { |
| 11564 | switch (final) { |
| 11565 | case XML_SCHEMAS_TYPE_FINAL_RESTRICTION: |
| 11566 | tfinal = XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION; |
| 11567 | break; |
| 11568 | case XML_SCHEMAS_TYPE_FINAL_EXTENSION: |
| 11569 | tfinal = XML_SCHEMAS_FINAL_DEFAULT_EXTENSION; |
| 11570 | break; |
| 11571 | case XML_SCHEMAS_TYPE_FINAL_LIST: |
| 11572 | tfinal = XML_SCHEMAS_FINAL_DEFAULT_LIST; |
| 11573 | break; |
| 11574 | case XML_SCHEMAS_TYPE_FINAL_UNION: |
| 11575 | tfinal = XML_SCHEMAS_FINAL_DEFAULT_UNION; |
| 11576 | break; |
| 11577 | } |
| 11578 | tflags = schema->flags; |
| 11579 | } |
| 11580 | if (tflags & tfinal) |
| 11581 | return (1); |
| 11582 | else |
| 11583 | return (0); |
| 11584 | |
| 11585 | } |
| 11586 | |
| 11587 | /** |
| 11588 | * xmlSchemaGetUnionSimpleTypeMemberTypes: |
| 11589 | * @type: the Union Simple Type |
| 11590 | * |
| 11591 | * Returns a list of member types of @type if existing, |
| 11592 | * returns NULL otherwise. |
| 11593 | */ |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 11594 | static xmlSchemaTypeLinkPtr |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11595 | xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type) |
| 11596 | { |
| 11597 | while (type != NULL) { |
| 11598 | if (type->memberTypes != NULL) |
| 11599 | return (type->memberTypes); |
| 11600 | else |
| 11601 | type = type->baseType; |
| 11602 | } |
| 11603 | return (NULL); |
| 11604 | } |
| 11605 | |
| 11606 | /** |
| 11607 | * xmlSchemaGetListSimpleTypeItemType: |
| 11608 | * @type: the simple type definition |
| 11609 | * |
| 11610 | * Returns the item type definition of the list simple type. |
| 11611 | */ |
| 11612 | static xmlSchemaTypePtr |
| 11613 | xmlSchemaGetListSimpleTypeItemType(xmlSchemaTypePtr type) |
| 11614 | { |
| 11615 | if ((type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) == 0) |
| 11616 | return (NULL); |
| 11617 | /* |
| 11618 | * Note: In libxml2, the built-in types do not reflect |
| 11619 | * the datatype hierarchy (yet?) - we have to treat them |
| 11620 | * in a special way. |
| 11621 | */ |
| 11622 | if (type->type == XML_SCHEMA_TYPE_BASIC) |
| 11623 | return (xmlSchemaGetBuiltInListSimpleTypeItemType(type)); |
| 11624 | if (type->subtypes->type == XML_SCHEMA_TYPE_LIST) |
| 11625 | /* 1 If the <list> alternative is chosen, then the type |
| 11626 | * definition ·resolved· to by the ·actual value· of the |
| 11627 | * itemType [attribute] of <list>, if present, otherwise |
| 11628 | * the type definition corresponding to the <simpleType> |
| 11629 | * among the [children] of <list>. |
| 11630 | */ |
| 11631 | return (type->subtypes->subtypes); |
| 11632 | else { |
| 11633 | /* 2 If the <restriction> option is chosen, then the |
| 11634 | * {item type definition} of the {base type definition}. |
| 11635 | */ |
| 11636 | return (xmlSchemaGetListSimpleTypeItemType(type->baseType)); |
| 11637 | } |
| 11638 | } |
| 11639 | |
| 11640 | /** |
| 11641 | * xmlSchemaCheckCOSSTDerivedOK: |
| 11642 | * @type: the derived simple type definition |
| 11643 | * @baseType: the base type definition |
| 11644 | * |
| 11645 | * Checks wheter @type can be validly |
| 11646 | * derived from @baseType. |
| 11647 | * |
| 11648 | * Returns 0 on success, an positive error code otherwise. |
| 11649 | */ |
| 11650 | static int |
| 11651 | xmlSchemaCheckCOSSTDerivedOK(xmlSchemaPtr schema, |
| 11652 | xmlSchemaTypePtr type, |
| 11653 | xmlSchemaTypePtr baseType, |
| 11654 | int subset) |
| 11655 | { |
| 11656 | /* |
| 11657 | * Schema Component Constraint: Type Derivation OK (Simple) |
| 11658 | * |
| 11659 | * |
| 11660 | * 1 They are the same type definition. |
| 11661 | * TODO: The identy check might have to be more complex than this. |
| 11662 | */ |
| 11663 | if (type == baseType) |
| 11664 | return (0); |
| 11665 | /* |
| 11666 | * 2.1 restriction is not in the subset, or in the {final} |
| 11667 | * of its own {base type definition}; |
| 11668 | */ |
| 11669 | if ((subset & XML_SCHEMAS_TYPE_FINAL_RESTRICTION) || |
| 11670 | (xmlSchemaTypeFinalContains(schema, |
| 11671 | type->baseType, XML_SCHEMAS_TYPE_FINAL_RESTRICTION))) { |
| 11672 | return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_1); |
| 11673 | } |
| 11674 | /* 2.2 */ |
| 11675 | if (type->baseType == baseType) { |
| 11676 | /* |
| 11677 | * 2.2.1 D's ·base type definition· is B. |
| 11678 | */ |
| 11679 | return (0); |
| 11680 | } |
| 11681 | /* |
| 11682 | * 2.2.2 D's ·base type definition· is not the ·ur-type definition· |
| 11683 | * and is validly derived from B given the subset, as defined by this |
| 11684 | * constraint. |
| 11685 | */ |
| 11686 | if ((type->baseType != xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE)) && |
| 11687 | (xmlSchemaCheckCOSSTDerivedOK(schema, type->baseType, baseType, subset) == 0)) { |
| 11688 | return (0); |
| 11689 | } |
| 11690 | /* |
| 11691 | * 2.2.3 D's {variety} is list or union and B is the ·simple ur-type |
| 11692 | * definition·. |
| 11693 | */ |
| 11694 | if (((type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) || |
| 11695 | (type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION)) && |
| 11696 | (baseType == xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE))) { |
| 11697 | return (0); |
| 11698 | } |
| 11699 | /* |
| 11700 | * 2.2.4 B's {variety} is union and D is validly derived from a type |
| 11701 | * definition in B's {member type definitions} given the subset, as |
| 11702 | * defined by this constraint. |
| 11703 | * |
| 11704 | * NOTE: This seems not to involve built-in types, since there is no |
| 11705 | * built-in Union Simple Type. |
| 11706 | */ |
| 11707 | if (baseType->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
| 11708 | xmlSchemaTypeLinkPtr cur; |
| 11709 | |
| 11710 | cur = baseType->memberTypes; |
| 11711 | while (cur != NULL) { |
| 11712 | if (xmlSchemaCheckCOSSTDerivedOK(schema, type, |
| 11713 | cur->type, subset) == 0) |
| 11714 | return (0); |
| 11715 | cur = cur->next; |
| 11716 | } |
| 11717 | } |
| 11718 | |
| 11719 | return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_2); |
| 11720 | } |
| 11721 | |
| 11722 | |
| 11723 | /** |
| 11724 | * xmlSchemaCheckSTPropsCorrect: |
| 11725 | * @ctxt: the schema parser context |
| 11726 | * @type: the simple type definition |
| 11727 | * |
| 11728 | * Checks st-props-correct. |
| 11729 | * |
| 11730 | * Returns 0 if the properties are correct, |
| 11731 | * if not, a positive error code and -1 on internal |
| 11732 | * errors. |
| 11733 | */ |
| 11734 | static int |
| 11735 | xmlSchemaCheckSTPropsCorrect(xmlSchemaParserCtxtPtr ctxt, |
| 11736 | xmlSchemaTypePtr type) |
| 11737 | { |
| 11738 | xmlSchemaTypePtr baseType = type->baseType, anySimpleType, |
| 11739 | anyType; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11740 | xmlChar *str = NULL; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11741 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11742 | /* STATE: error funcs converted. */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11743 | /* |
| 11744 | * Schema Component Constraint: Simple Type Definition Properties Correct |
| 11745 | * |
| 11746 | * NOTE: This is somehow redundant, since we actually built a simple type |
| 11747 | * to have all the needed information; this acts as an self test. |
| 11748 | */ |
| 11749 | anySimpleType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 11750 | anyType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 11751 | /* |
| 11752 | * TODO: 1 The values of the properties of a simple type definition must be as |
| 11753 | * described in the property tableau in Datatype definition, modulo the |
| 11754 | * impact of Missing Sub-components (§5.3). |
| 11755 | */ |
| 11756 | /* Base type: If the datatype has been ·derived· by ·restriction· |
| 11757 | * then the Simple Type Definition component from which it is ·derived·, |
| 11758 | * otherwise the Simple Type Definition for anySimpleType (§4.1.6). |
| 11759 | */ |
| 11760 | if (baseType == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11761 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11762 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11763 | NULL, type, NULL, |
| 11764 | "No base type existent", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11765 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
| 11766 | } |
| 11767 | if ((baseType->type != XML_SCHEMA_TYPE_SIMPLE) && |
| 11768 | ((baseType->type != XML_SCHEMA_TYPE_BASIC) || |
| 11769 | (baseType == anyType))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11770 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11771 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11772 | NULL, type, NULL, |
| 11773 | "The base type %s is not a simple type", |
| 11774 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 11775 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11776 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
| 11777 | } |
| 11778 | if ((baseType != anySimpleType) && |
| 11779 | (type->subtypes->type != XML_SCHEMA_TYPE_RESTRICTION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11780 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11781 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11782 | NULL, type, NULL, |
| 11783 | "A type, derived by list or union, must have" |
| 11784 | "the simple ur-type definition as base type, not %s", |
| 11785 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 11786 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11787 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
| 11788 | } |
| 11789 | /* |
| 11790 | * Variety: One of {atomic, list, union}. |
| 11791 | */ |
| 11792 | if (((type->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) == 0) && |
| 11793 | ((type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) == 0) && |
| 11794 | ((type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) == 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11795 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11796 | XML_SCHEMAP_ST_PROPS_CORRECT_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11797 | NULL, type, NULL, |
| 11798 | "The variety is absent", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11799 | return (XML_SCHEMAP_ST_PROPS_CORRECT_1); |
| 11800 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11801 | /* TODO: Finish this. Hmm, is this finished? */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11802 | |
| 11803 | /* |
| 11804 | * 2 All simple type definitions must be derived ultimately from the ·simple |
| 11805 | * ur-type definition (so· circular definitions are disallowed). That is, it |
| 11806 | * must be possible to reach a built-in primitive datatype or the ·simple |
| 11807 | * ur-type definition· by repeatedly following the {base type definition}. |
| 11808 | */ |
| 11809 | baseType = type->baseType; |
| 11810 | while ((baseType != NULL) && (baseType->type != XML_SCHEMA_TYPE_BASIC)) { |
| 11811 | if (baseType->contentType == XML_SCHEMA_CONTENT_UNKNOWN) |
| 11812 | xmlSchemaTypeFixup(baseType, ctxt, NULL); |
| 11813 | if (baseType == anySimpleType) |
| 11814 | break; |
| 11815 | else if (baseType == type) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11816 | xmlSchemaPCustomErr(ctxt, |
| 11817 | XML_SCHEMAP_ST_PROPS_CORRECT_2, |
| 11818 | NULL, type, NULL, |
| 11819 | "The definition is circular", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11820 | return (XML_SCHEMAP_ST_PROPS_CORRECT_2); |
| 11821 | } |
| 11822 | baseType = baseType->baseType; |
| 11823 | } |
| 11824 | /* |
| 11825 | * 3 The {final} of the {base type definition} must not contain restriction. |
| 11826 | */ |
| 11827 | if (xmlSchemaTypeFinalContains(ctxt->schema, baseType, |
| 11828 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11829 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11830 | XML_SCHEMAP_ST_PROPS_CORRECT_3, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11831 | NULL, type, NULL, |
| 11832 | "The 'final' of its base type %s must not contain " |
| 11833 | "'restriction'", |
| 11834 | xmlSchemaFormatItemForReport(&str, NULL, baseType, NULL, 1)); |
| 11835 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11836 | return (XML_SCHEMAP_ST_PROPS_CORRECT_3); |
| 11837 | } |
| 11838 | return (0); |
| 11839 | } |
| 11840 | |
| 11841 | /** |
| 11842 | * xmlSchemaCheckDerivationValidSimpleRestriction: |
| 11843 | * @ctxt: the schema parser context |
| 11844 | * @type: the simple type definition |
| 11845 | * |
| 11846 | * Checks if the given @type (simpleType) is derived |
| 11847 | * validly by restriction. |
| 11848 | * |
| 11849 | * Returns -1 on internal errors, 0 if the type is validly derived, |
| 11850 | * a positive error code otherwise. |
| 11851 | */ |
| 11852 | static int |
| 11853 | xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11854 | xmlSchemaTypePtr type) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11855 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11856 | xmlChar *str = NULL; |
| 11857 | |
| 11858 | /* STATE: error funcs converted. */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11859 | |
| 11860 | if (type->type != XML_SCHEMA_TYPE_SIMPLE) { |
| 11861 | xmlSchemaPErr(ctxt, type->node, |
| 11862 | XML_ERR_INTERNAL_ERROR, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11863 | "xmlSchemaCheckDerivationValidSimpleRestriction: The given " |
| 11864 | "type '%s' is not a user-derived simpleType.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11865 | type->name, NULL); |
| 11866 | return (-1); |
| 11867 | } |
| 11868 | |
| 11869 | if (type->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) { |
| 11870 | xmlSchemaTypePtr primitive; |
| 11871 | /* |
| 11872 | * 1.1 The {base type definition} must be an atomic simple |
| 11873 | * type definition or a built-in primitive datatype. |
| 11874 | */ |
| 11875 | if ((type->baseType->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11876 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11877 | XML_SCHEMAP_COS_ST_RESTRICTS_1_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11878 | NULL, type, NULL, |
| 11879 | "The base type %s is not an atomic simple type", |
| 11880 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 11881 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11882 | return (XML_SCHEMAP_COS_ST_RESTRICTS_1_1); |
| 11883 | } |
| 11884 | /* 1.2 The {final} of the {base type definition} must not contain |
| 11885 | * restriction. |
| 11886 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11887 | /* OPTIMIZE TODO : This is already done in xmlSchemaCheckStPropsCorrect */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11888 | if (xmlSchemaTypeFinalContains(ctxt->schema, type->baseType, |
| 11889 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11890 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11891 | XML_SCHEMAP_COS_ST_RESTRICTS_1_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11892 | NULL, type, NULL, |
| 11893 | "The final of its base type %s must not contain 'restriction'", |
| 11894 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 11895 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11896 | return (XML_SCHEMAP_COS_ST_RESTRICTS_1_2); |
| 11897 | } |
| 11898 | |
| 11899 | /* |
| 11900 | * 1.3.1 DF must be an allowed constraining facet for the {primitive |
| 11901 | * type definition}, as specified in the appropriate subsection of 3.2 |
| 11902 | * Primitive datatypes. |
| 11903 | */ |
| 11904 | if (type->facets != NULL) { |
| 11905 | xmlSchemaFacetPtr facet; |
| 11906 | int ok = 1; |
| 11907 | |
| 11908 | primitive = xmlSchemaGetPrimitiveType(type); |
| 11909 | if (primitive == NULL) { |
| 11910 | xmlSchemaPErr(ctxt, type->node, |
| 11911 | XML_ERR_INTERNAL_ERROR, |
| 11912 | "xmlSchemaCheckDerivationValidSimpleRestriction: failed " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11913 | "to get primitive type of type '%s'.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11914 | type->name, NULL); |
| 11915 | return (-1); |
| 11916 | } |
| 11917 | facet = type->facets; |
| 11918 | do { |
| 11919 | if (xmlSchemaIsBuiltInTypeFacet(primitive, facet->type) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11920 | ok = 0; |
| 11921 | xmlSchemaPIllegalFacetAtomicErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11922 | XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11923 | NULL, type, primitive, facet); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11924 | } |
| 11925 | facet = facet->next; |
| 11926 | } while (facet != NULL); |
| 11927 | if (ok == 0) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11928 | return (XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11929 | } |
| 11930 | /* |
| 11931 | * TODO: 1.3.2 (facet derivation) |
| 11932 | */ |
| 11933 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 11934 | xmlSchemaTypePtr itemType = NULL; |
| 11935 | |
| 11936 | itemType = xmlSchemaGetListSimpleTypeItemType(type); |
| 11937 | if (itemType == NULL) { |
| 11938 | xmlSchemaPErr(ctxt, type->node, |
| 11939 | XML_ERR_INTERNAL_ERROR, |
| 11940 | "Internal error: xmlSchemaCheckDerivationValidSimpleRestriction: " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11941 | "failed to evaluate the item type of type '%s'.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11942 | type->name, NULL); |
| 11943 | return (-1); |
| 11944 | } |
| 11945 | /* |
| 11946 | * 2.1 The {item type definition} must have a {variety} of atomic or |
| 11947 | * union (in which case all the {member type definitions} |
| 11948 | * must be atomic). |
| 11949 | */ |
| 11950 | if (((itemType->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) == 0) && |
| 11951 | ((itemType->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) == 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11952 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11953 | XML_SCHEMAP_COS_ST_RESTRICTS_2_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11954 | NULL, type, NULL, |
| 11955 | "The item type %s must have a variety of atomic or union", |
| 11956 | xmlSchemaFormatItemForReport(&str, NULL, itemType, NULL, 1)); |
| 11957 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11958 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1); |
| 11959 | } else if (itemType->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
| 11960 | xmlSchemaTypeLinkPtr member; |
| 11961 | |
| 11962 | member = itemType->memberTypes; |
| 11963 | while (member != NULL) { |
| 11964 | if ((member->type->flags & |
| 11965 | XML_SCHEMAS_TYPE_VARIETY_ATOMIC) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11966 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11967 | XML_SCHEMAP_COS_ST_RESTRICTS_2_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11968 | NULL, type, NULL, |
| 11969 | "The item type is a union type, but the " |
| 11970 | "member type %s of this item type is not atomic", |
| 11971 | xmlSchemaFormatItemForReport(&str, NULL, member->type, NULL, 1)); |
| 11972 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11973 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1); |
| 11974 | } |
| 11975 | member = member->next; |
| 11976 | } |
| 11977 | } |
| 11978 | |
| 11979 | if (type->baseType == xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE)) { |
| 11980 | xmlSchemaFacetPtr facet; |
| 11981 | /* |
| 11982 | * This is the case if we have: <simpleType><list .. |
| 11983 | */ |
| 11984 | /* |
| 11985 | * 2.3.1 |
| 11986 | * 2.3.1.1 The {final} of the {item type definition} must not |
| 11987 | * contain list. |
| 11988 | */ |
| 11989 | if (xmlSchemaTypeFinalContains(ctxt->schema, |
| 11990 | itemType, XML_SCHEMAS_TYPE_FINAL_LIST)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11991 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11992 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 11993 | NULL, type, NULL, |
| 11994 | "The final of its item type %s must not contain 'list'", |
| 11995 | xmlSchemaFormatItemForReport(&str, NULL, itemType, NULL, 1)); |
| 11996 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 11997 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1); |
| 11998 | } |
| 11999 | /* |
| 12000 | * 2.3.1.2 The {facets} must only contain the whiteSpace |
| 12001 | * facet component. |
| 12002 | */ |
| 12003 | if (type->facets != NULL) { |
| 12004 | facet = type->facets; |
| 12005 | do { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12006 | if (facet->type != XML_SCHEMA_FACET_WHITESPACE) { |
| 12007 | xmlSchemaPIllegalFacetListUnionErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12008 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12009 | NULL, type, facet); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12010 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2); |
| 12011 | } |
| 12012 | facet = facet->next; |
| 12013 | } while (facet != NULL); |
| 12014 | } |
| 12015 | /* |
| 12016 | * TODO: Datatypes states: |
| 12017 | * A ·list· datatype can be ·derived· from an ·atomic· datatype |
| 12018 | * whose ·lexical space· allows space (such as string or anyURI)or |
| 12019 | * a ·union· datatype any of whose {member type definitions}'s |
| 12020 | * ·lexical space· allows space. |
| 12021 | */ |
| 12022 | } else { |
| 12023 | /* |
| 12024 | * This is the case if we have: <simpleType><restriction ... |
| 12025 | */ |
| 12026 | /* |
| 12027 | * 2.3.2 |
| 12028 | * 2.3.2.1 The {base type definition} must have a {variety} of list. |
| 12029 | */ |
| 12030 | if ((type->baseType->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12031 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12032 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12033 | NULL, type, NULL, |
| 12034 | "The base type %s must be a list type", |
| 12035 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 12036 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12037 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1); |
| 12038 | } |
| 12039 | /* |
| 12040 | * 2.3.2.2 The {final} of the {base type definition} must not |
| 12041 | * contain restriction. |
| 12042 | */ |
| 12043 | if (xmlSchemaTypeFinalContains(ctxt->schema, type->baseType, |
| 12044 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12045 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12046 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12047 | NULL, type, NULL, |
| 12048 | "The final of the base type %s must not contain 'restriction'", |
| 12049 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 12050 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12051 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2); |
| 12052 | } |
| 12053 | /* |
| 12054 | * 2.3.2.3 The {item type definition} must be validly derived |
| 12055 | * from the {base type definition}'s {item type definition} given |
| 12056 | * the empty set, as defined in Type Derivation OK (Simple) (§3.14.6). |
| 12057 | */ |
| 12058 | { |
| 12059 | xmlSchemaTypePtr baseItemType; |
| 12060 | |
| 12061 | baseItemType = xmlSchemaGetListSimpleTypeItemType(type->baseType); |
| 12062 | if (baseItemType == NULL) { |
| 12063 | xmlSchemaPErr(ctxt, type->node, |
| 12064 | XML_ERR_INTERNAL_ERROR, |
| 12065 | "xmlSchemaCheckDerivationValidSimpleRestriction: " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12066 | "List simple type '%s': Failed to " |
| 12067 | "evaluate the item type of its base type '%s'.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12068 | type->name, type->baseType->name); |
| 12069 | return (-1); |
| 12070 | } |
| 12071 | if ((itemType != baseItemType) && |
| 12072 | (xmlSchemaCheckCOSSTDerivedOK(ctxt->schema, itemType, |
| 12073 | baseItemType, 0) != 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12074 | xmlChar *strBIT = NULL, *strBT = NULL; |
| 12075 | xmlSchemaPCustomErrExt(ctxt, |
| 12076 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3, |
| 12077 | NULL, type, NULL, |
| 12078 | "The item type %s is not validly derived from the " |
| 12079 | "item type %s of the base type %s", |
| 12080 | xmlSchemaFormatItemForReport(&str, NULL, itemType, NULL, 1), |
| 12081 | xmlSchemaFormatItemForReport(&strBIT, NULL, baseItemType, NULL, 1), |
| 12082 | xmlSchemaFormatItemForReport(&strBT, NULL, type->baseType, NULL, 1)); |
| 12083 | |
| 12084 | FREE_AND_NULL(str) |
| 12085 | FREE_AND_NULL(strBIT) |
| 12086 | FREE_AND_NULL(strBT) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12087 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3); |
| 12088 | } |
| 12089 | } |
| 12090 | |
| 12091 | if (type->facets != NULL) { |
| 12092 | xmlSchemaFacetPtr facet; |
| 12093 | int ok = 1; |
| 12094 | /* |
| 12095 | * 2.3.2.4 Only length, minLength, maxLength, whiteSpace, pattern |
| 12096 | * and enumeration facet components are allowed among the {facets}. |
| 12097 | */ |
| 12098 | facet = type->facets; |
| 12099 | do { |
| 12100 | switch (facet->type) { |
| 12101 | case XML_SCHEMA_FACET_LENGTH: |
| 12102 | case XML_SCHEMA_FACET_MINLENGTH: |
| 12103 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 12104 | case XML_SCHEMA_FACET_WHITESPACE: |
| 12105 | /* |
| 12106 | * TODO: 2.5.1.2 List datatypes |
| 12107 | * The value of ·whiteSpace· is fixed to the value collapse. |
| 12108 | */ |
| 12109 | case XML_SCHEMA_FACET_PATTERN: |
| 12110 | case XML_SCHEMA_FACET_ENUMERATION: |
| 12111 | break; |
| 12112 | default: { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12113 | xmlSchemaPIllegalFacetListUnionErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12114 | XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12115 | NULL, type, facet); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12116 | /* |
| 12117 | * We could return, but it's nicer to report all |
| 12118 | * invalid facets. |
| 12119 | */ |
| 12120 | ok = 0; |
| 12121 | } |
| 12122 | } |
| 12123 | facet = facet->next; |
| 12124 | } while (facet != NULL); |
| 12125 | if (ok == 0) |
| 12126 | return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4); |
| 12127 | /* |
| 12128 | * TODO: 2.3.2.5 For each facet in the {facets} (call this DF), if there |
| 12129 | * is a facet of the same kind in the {facets} of the {base type |
| 12130 | * definition} (call this BF),then the DF's {value} must be a valid |
| 12131 | * restriction of BF's {value} as defined in [XML Schemas: Datatypes]. |
| 12132 | */ |
| 12133 | } |
| 12134 | |
| 12135 | |
| 12136 | } |
| 12137 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
| 12138 | /* |
| 12139 | * 3.1 The {member type definitions} must all have {variety} of |
| 12140 | * atomic or list. |
| 12141 | */ |
| 12142 | xmlSchemaTypeLinkPtr member; |
| 12143 | |
| 12144 | member = type->memberTypes; |
| 12145 | while (member != NULL) { |
| 12146 | if (((member->type->flags & |
| 12147 | XML_SCHEMAS_TYPE_VARIETY_ATOMIC) == 0) && |
| 12148 | ((member->type->flags & |
| 12149 | XML_SCHEMAS_TYPE_VARIETY_LIST) == 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12150 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12151 | XML_SCHEMAP_COS_ST_RESTRICTS_3_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12152 | NULL, type, NULL, |
| 12153 | "The member type %s is neither an atomic, nor a list type", |
| 12154 | xmlSchemaFormatItemForReport(&str, NULL, member->type, NULL, 1)); |
| 12155 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12156 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_1); |
| 12157 | } |
| 12158 | member = member->next; |
| 12159 | } |
| 12160 | /* |
| 12161 | * 3.3.1 If the {base type definition} is the ·simple ur-type |
| 12162 | * definition· |
| 12163 | */ |
| 12164 | if (type->baseType == xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE)) { |
| 12165 | /* |
| 12166 | * 3.3.1.1 All of the {member type definitions} must have a |
| 12167 | * {final} which does not contain union. |
| 12168 | */ |
| 12169 | member = type->memberTypes; |
| 12170 | while (member != NULL) { |
| 12171 | if (xmlSchemaTypeFinalContains(ctxt->schema, member->type, |
| 12172 | XML_SCHEMAS_TYPE_FINAL_UNION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12173 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12174 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12175 | NULL, type, NULL, |
| 12176 | "The final of member type %s contains 'union'", |
| 12177 | xmlSchemaFormatItemForReport(&str, NULL, member->type, NULL, 1)); |
| 12178 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12179 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1); |
| 12180 | } |
| 12181 | member = member->next; |
| 12182 | } |
| 12183 | /* |
| 12184 | * 3.3.1.2 The {facets} must be empty. |
| 12185 | */ |
| 12186 | if (type->facetSet != NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12187 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12188 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12189 | NULL, type, NULL, |
| 12190 | "No facets allowed", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12191 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2); |
| 12192 | } |
| 12193 | } else { |
| 12194 | /* |
| 12195 | * 3.3.2.1 The {base type definition} must have a {variety} of union. |
| 12196 | */ |
| 12197 | if ((type->baseType->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) == 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12198 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12199 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12200 | NULL, type, NULL, |
| 12201 | "The base type %s is not a union type", |
| 12202 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 12203 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12204 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1); |
| 12205 | } |
| 12206 | /* |
| 12207 | * 3.3.2.2 The {final} of the {base type definition} must not contain restriction. |
| 12208 | */ |
| 12209 | if (xmlSchemaTypeFinalContains(ctxt->schema, type->baseType, |
| 12210 | XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12211 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12212 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12213 | NULL, type, NULL, |
| 12214 | "The final of its base type %s must not contain 'restriction'", |
| 12215 | xmlSchemaFormatItemForReport(&str, NULL, type->baseType, NULL, 1)); |
| 12216 | FREE_AND_NULL(str) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12217 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2); |
| 12218 | } |
| 12219 | /* |
| 12220 | * 3.3.2.3 The {member type definitions}, in order, must be validly |
| 12221 | * derived from the corresponding type definitions in the {base |
| 12222 | * type definition}'s {member type definitions} given the empty set, |
| 12223 | * as defined in Type Derivation OK (Simple) (§3.14.6). |
| 12224 | */ |
| 12225 | { |
| 12226 | xmlSchemaTypeLinkPtr baseMember; |
| 12227 | |
| 12228 | /* |
| 12229 | * OPTIMIZE: if the type is restricting, it has no local defined |
| 12230 | * member types and inherits the member types of the base type; |
| 12231 | * thus a check for equality can be skipped. |
| 12232 | */ |
| 12233 | /* |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 12234 | * Even worse: I cannot see a scenario where a restricting |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12235 | * union simple type can have other member types as the member |
| 12236 | * types of it's base type. This check seems not necessary with |
| 12237 | * respect to the derivation process in libxml2. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 12238 | * But necessary if constructing types with an API. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12239 | */ |
| 12240 | if (type->memberTypes != NULL) { |
| 12241 | member = type->memberTypes; |
| 12242 | baseMember = xmlSchemaGetUnionSimpleTypeMemberTypes(type->baseType); |
| 12243 | if ((member == NULL) && (baseMember != NULL)) { |
| 12244 | xmlSchemaPErr(ctxt, type->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 12245 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12246 | "Internal error: " |
| 12247 | "xmlSchemaCheckDerivationValidSimpleRestriction " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12248 | "(3.3.2.3), union simple type '%s', unequal number " |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12249 | "of member types in the base type\n", |
| 12250 | type->name, NULL); |
| 12251 | } |
| 12252 | while (member != NULL) { |
| 12253 | if (baseMember == NULL) { |
| 12254 | xmlSchemaPErr(ctxt, type->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 12255 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12256 | "Internal error: " |
| 12257 | "xmlSchemaCheckDerivationValidSimpleRestriction " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12258 | "(3.3.2.3), union simple type '%s', unequal number " |
| 12259 | "of member types in the base type.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12260 | type->name, NULL); |
| 12261 | } |
| 12262 | if ((member->type != baseMember->type) && |
| 12263 | (xmlSchemaCheckCOSSTDerivedOK(ctxt->schema, |
| 12264 | member->type, baseMember->type, 0) != 0)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12265 | xmlChar *strBMT = NULL, *strBT = NULL; |
| 12266 | |
| 12267 | xmlSchemaPCustomErrExt(ctxt, |
| 12268 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3, |
| 12269 | NULL, type, NULL, |
| 12270 | "The member type %s is not validly derived from its " |
| 12271 | "corresponding member type %s of the base type %s", |
| 12272 | xmlSchemaFormatItemForReport(&str, NULL, member->type, NULL, 1), |
| 12273 | xmlSchemaFormatItemForReport(&strBMT, NULL, baseMember->type, NULL, 1), |
| 12274 | xmlSchemaFormatItemForReport(&strBT, NULL, type->baseType, NULL, 1)); |
| 12275 | FREE_AND_NULL(str) |
| 12276 | FREE_AND_NULL(strBMT) |
| 12277 | FREE_AND_NULL(strBT) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12278 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3); |
| 12279 | } |
| 12280 | member = member->next; |
| 12281 | baseMember = baseMember->next; |
| 12282 | } |
| 12283 | } |
| 12284 | } |
| 12285 | /* |
| 12286 | * 3.3.2.4 Only pattern and enumeration facet components are |
| 12287 | * allowed among the {facets}. |
| 12288 | */ |
| 12289 | if (type->facets != NULL) { |
| 12290 | xmlSchemaFacetPtr facet; |
| 12291 | int ok = 1; |
| 12292 | |
| 12293 | facet = type->facets; |
| 12294 | do { |
| 12295 | if ((facet->type != XML_SCHEMA_FACET_PATTERN) && |
| 12296 | (facet->type != XML_SCHEMA_FACET_ENUMERATION)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12297 | xmlSchemaPIllegalFacetListUnionErr(ctxt, |
| 12298 | XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4, |
| 12299 | NULL, type, facet); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12300 | ok = 0; |
| 12301 | } |
| 12302 | facet = facet->next; |
| 12303 | } while (facet != NULL); |
| 12304 | if (ok == 0) |
| 12305 | return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4); |
| 12306 | |
| 12307 | } |
| 12308 | /* |
| 12309 | * TODO: 3.3.2.5 (facet derivation) |
| 12310 | */ |
| 12311 | } |
| 12312 | } |
| 12313 | |
| 12314 | return (0); |
| 12315 | } |
| 12316 | |
| 12317 | /** |
| 12318 | * xmlSchemaCheckSRCSimpleType: |
| 12319 | * @ctxt: the schema parser context |
| 12320 | * @type: the simple type definition |
| 12321 | * |
| 12322 | * Checks crc-simple-type constraints. |
| 12323 | * |
| 12324 | * Returns 0 if the constraints are satisfied, |
| 12325 | * if not a positive error code and -1 on internal |
| 12326 | * errors. |
| 12327 | */ |
| 12328 | static int |
| 12329 | xmlSchemaCheckSRCSimpleType(xmlSchemaParserCtxtPtr ctxt, |
| 12330 | xmlSchemaTypePtr type) |
| 12331 | { |
| 12332 | /* |
| 12333 | * NOTE: src-simple-type 2-4 are redundant, since the checks |
| 12334 | * were are done for the corresponding <restriction>, <list> and <union> |
| 12335 | * elements, but W3C wants a <simpleType> error as well, so it gets one. |
| 12336 | * Maby this can be skipped in the future, if we get sure it's not needed. |
| 12337 | */ |
| 12338 | if (type->subtypes == NULL) { |
| 12339 | xmlSchemaPErr(ctxt, type->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 12340 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12341 | "Internal error: xmlSchemaCheckSRCSimpleType, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12342 | "no subtype on simple type '%s'.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12343 | type->name, NULL); |
| 12344 | return (-1); |
| 12345 | } |
| 12346 | /* |
| 12347 | * src-simple-type.1 The corresponding simple type definition, if any, |
| 12348 | * must satisfy the conditions set out in Constraints on Simple Type |
| 12349 | * Definition Schema Components (§3.14.6). |
| 12350 | */ |
| 12351 | if ((xmlSchemaCheckSTPropsCorrect(ctxt, type) != 0) || |
| 12352 | (xmlSchemaCheckCOSSTRestricts(ctxt, type) != 0)) { |
| 12353 | /* |
| 12354 | * TODO: Removed this, since it got annoying to get an |
| 12355 | * extra error report, if anything failed until now. |
| 12356 | * Enable this if needed. |
| 12357 | */ |
| 12358 | /* |
| 12359 | xmlSchemaPErr(ctxt, type->node, |
| 12360 | XML_SCHEMAP_SRC_SIMPLE_TYPE_1, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12361 | "Simple type '%s' does not satisfy the constraints " |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12362 | "on simple type definitions.\n", |
| 12363 | type->name, NULL); |
| 12364 | */ |
| 12365 | return (XML_SCHEMAP_SRC_SIMPLE_TYPE_1); |
| 12366 | } |
| 12367 | |
| 12368 | if (type->subtypes->type == XML_SCHEMA_TYPE_RESTRICTION) { |
| 12369 | /* |
| 12370 | * src-simple-type.2 If the <restriction> alternative is chosen, |
| 12371 | * either it must have a base [attribute] or a <simpleType> among its |
| 12372 | * [children], but not both. |
| 12373 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12374 | /* |
| 12375 | * XML_SCHEMAP_SRC_SIMPLE_TYPE_2 |
| 12376 | * NOTE: This was removed, since this will be already handled |
| 12377 | * in the parse function for <restriction>. |
| 12378 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12379 | } else if (type->subtypes->type == XML_SCHEMA_TYPE_LIST) { |
| 12380 | /* src-simple-type.3 If the <list> alternative is chosen, either it must have |
| 12381 | * an itemType [attribute] or a <simpleType> among its [children], |
| 12382 | * but not both. |
| 12383 | * NOTE: baseType is set to the local simple type definiton, |
| 12384 | * if existent, at parse time. This is a hack and not nice. |
| 12385 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12386 | /* |
| 12387 | * TODO: Remove this, and add the check to the parse function of <list>. |
| 12388 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12389 | if (((type->subtypes->base == NULL) && |
| 12390 | (type->baseType == NULL)) || |
| 12391 | ((type->subtypes->base != NULL) && |
| 12392 | (type->subtypes->baseType != NULL))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12393 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12394 | XML_SCHEMAP_SRC_SIMPLE_TYPE_3, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12395 | NULL, type, NULL, |
| 12396 | "Either the attribute 'itemType' or the <simpleType> child " |
| 12397 | "must be present on the <list> child ", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12398 | return (XML_SCHEMAP_SRC_SIMPLE_TYPE_3); |
| 12399 | } |
| 12400 | |
| 12401 | |
| 12402 | } else if (type->subtypes->type == XML_SCHEMA_TYPE_UNION) { |
| 12403 | xmlSchemaTypeLinkPtr member; |
| 12404 | xmlSchemaTypePtr ancestor, anySimpleType; |
| 12405 | |
| 12406 | anySimpleType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 12407 | |
| 12408 | /* src-simple-type.4 Circular union type definition is disallowed. That is, if |
| 12409 | * the <union> alternative is chosen, there must not be any entries |
| 12410 | * in the memberTypes [attribute] at any depth which resolve to the |
| 12411 | * component corresponding to the <simpleType>. |
| 12412 | */ |
| 12413 | member = type->memberTypes; |
| 12414 | while (member != NULL) { |
| 12415 | ancestor = member->type; |
| 12416 | while ((ancestor != NULL) && (ancestor->type != XML_SCHEMA_TYPE_BASIC)) { |
| 12417 | if (ancestor->contentType == XML_SCHEMA_CONTENT_UNKNOWN) |
| 12418 | xmlSchemaTypeFixup(ancestor, ctxt, NULL); |
| 12419 | if (ancestor == anySimpleType) |
| 12420 | break; |
| 12421 | else if (ancestor == type) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12422 | xmlSchemaPCustomErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12423 | XML_SCHEMAP_SRC_SIMPLE_TYPE_4, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12424 | NULL, type, NULL, |
| 12425 | "The definition is circular", NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12426 | return (XML_SCHEMAP_SRC_SIMPLE_TYPE_4); |
| 12427 | } else if (ancestor->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 12428 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 12429 | * 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] | 12430 | * type as item type, which in turn has a list ST as member |
| 12431 | * type, we will assume this here as well, since this check |
| 12432 | * was not yet performed. |
| 12433 | */ |
| 12434 | |
| 12435 | } |
| 12436 | ancestor = ancestor->baseType; |
| 12437 | } |
| 12438 | member = member->next; |
| 12439 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12440 | } |
| 12441 | |
| 12442 | return (0); |
| 12443 | } |
| 12444 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12445 | #if 0 /* Not yet used code for CT schema validation */ |
| 12446 | static int |
| 12447 | xmlSchemaCheckCVCSimpleType(xmlSchemaValidCtxtPtr ctxt, |
| 12448 | const xmlChar * value, |
| 12449 | xmlSchemaTypePtr type, |
| 12450 | int fireErrors) |
| 12451 | { |
| 12452 | int ret; |
| 12453 | /* |
| 12454 | * 3.14.4 Simple Type Definition Validation Rules |
| 12455 | * Validation Rule: String Valid |
| 12456 | */ |
| 12457 | /* |
| 12458 | * 1 It is schema-valid with respect to that definition as defined |
| 12459 | * by Datatype Valid in [XML Schemas: Datatypes]. |
| 12460 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12461 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, type, value, |
| 12462 | fireErrors, 1, 1, 1); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12463 | return (ret); |
| 12464 | /* |
| 12465 | * 2.1 If The definition is ENTITY or is validly derived from ENTITY given |
| 12466 | * the empty set, as defined in Type Derivation OK (Simple) (§3.14.6), then |
| 12467 | * the string must be a ·declared entity name·. |
| 12468 | */ |
| 12469 | /* |
| 12470 | * 2.2 If The definition is ENTITIES or is validly derived from ENTITIES |
| 12471 | * given the empty set, as defined in Type Derivation OK (Simple) (§3.14.6), |
| 12472 | * then every whitespace-delimited substring of the string must be a ·declared |
| 12473 | * entity name·. |
| 12474 | */ |
| 12475 | /* |
| 12476 | * 2.3 otherwise no further condition applies. |
| 12477 | */ |
| 12478 | |
| 12479 | return (0); |
| 12480 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12481 | #endif |
| 12482 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12483 | |
| 12484 | static int |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12485 | xmlSchemaCreatePCtxtOnVCtxt(xmlSchemaValidCtxtPtr vctxt) |
| 12486 | { |
| 12487 | if (vctxt->pctxt == NULL) { |
| 12488 | vctxt->pctxt =xmlSchemaNewParserCtxtUseDict("*", vctxt->schema->dict); |
| 12489 | /* vctxt->pctxt = xmlSchemaNewParserCtxt("*"); */ |
| 12490 | if (vctxt->pctxt == NULL) { |
| 12491 | xmlSchemaVErr(vctxt, NULL, |
| 12492 | XML_SCHEMAV_INTERNAL, |
| 12493 | "Internal error: xmlSchemaCreatePCtxtOnVCtxt, " |
| 12494 | "failed to create a temp. parser context.\n", |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12495 | NULL, NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12496 | return (-1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 12497 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12498 | /* TODO: Pass user data. */ |
| 12499 | xmlSchemaSetParserErrors(vctxt->pctxt, vctxt->error, vctxt->warning, NULL); |
| 12500 | } |
| 12501 | return (0); |
| 12502 | } |
| 12503 | |
| 12504 | static int |
| 12505 | xmlSchemaCreateVCtxtOnPCtxt(xmlSchemaParserCtxtPtr ctxt) |
| 12506 | { |
| 12507 | if (ctxt->vctxt == NULL) { |
| 12508 | ctxt->vctxt = xmlSchemaNewValidCtxt(NULL); |
| 12509 | if (ctxt->vctxt == NULL) { |
| 12510 | xmlSchemaPErr(ctxt, NULL, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 12511 | XML_SCHEMAP_INTERNAL, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12512 | "Internal error: xmlSchemaCreatePCtxtOnVCtxt, " |
| 12513 | "failed to create a temp. validation context.\n", |
| 12514 | NULL, NULL); |
| 12515 | return (-1); |
| 12516 | } |
| 12517 | /* TODO: Pass user data. */ |
| 12518 | xmlSchemaSetValidErrors(ctxt->vctxt, ctxt->error, ctxt->warning, NULL); |
| 12519 | } |
| 12520 | return (0); |
| 12521 | } |
| 12522 | |
| 12523 | /** |
| 12524 | * xmlSchemaCheckCOSValidDefault: |
| 12525 | * @ctxt: the schema parser context |
| 12526 | * @type: the simple type definition |
| 12527 | * @value: the default value |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 12528 | * @val: the precomputed value to be returned |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12529 | * @node: an optional node (the holder of the value) |
| 12530 | * |
| 12531 | * Checks the "cos-valid-default" constraints. |
| 12532 | * |
| 12533 | * Returns 0 if the constraints are satisfied, |
| 12534 | * if not, a positive error code and -1 on internal |
| 12535 | * errors. |
| 12536 | */ |
| 12537 | static int |
| 12538 | xmlSchemaCheckCOSValidDefault(xmlSchemaParserCtxtPtr pctxt, |
| 12539 | xmlSchemaValidCtxtPtr vctxt, |
| 12540 | xmlSchemaTypePtr type, |
| 12541 | const xmlChar *value, |
| 12542 | xmlNodePtr node) |
| 12543 | { |
| 12544 | int ret = 0; |
| 12545 | |
| 12546 | /* |
| 12547 | * cos-valid-default: |
| 12548 | * Schema Component Constraint: Element Default Valid (Immediate) |
| 12549 | * For a string to be a valid default with respect to a type |
| 12550 | * definition the appropriate case among the following must be true: |
| 12551 | */ |
| 12552 | /* |
| 12553 | * NOTE: This has to work without a given node (the holder of the |
| 12554 | * value), since it should work on the component, i.e. an underlying |
| 12555 | * DOM must not be mandatory. |
| 12556 | */ |
| 12557 | if ((pctxt == NULL) || (vctxt == NULL)) { |
| 12558 | xmlSchemaPErr(pctxt, node, |
| 12559 | XML_SCHEMAP_INTERNAL, |
| 12560 | "Internal error: xmlSchemaCheckCOSValidDefault, " |
| 12561 | "bad arguments: the parser and/or validation context is " |
| 12562 | "missing.\n", |
| 12563 | NULL, NULL); |
| 12564 | return (-1); |
| 12565 | } |
| 12566 | if IS_COMPLEX_TYPE(type) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12567 | /* |
| 12568 | * Complex type. |
| 12569 | * |
| 12570 | * 2.1 its {content type} must be a simple type definition or mixed. |
| 12571 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12572 | /* |
| 12573 | * TODO: Adjust this when the content type will be computed |
| 12574 | * correctly. |
| 12575 | */ |
| 12576 | if ((type->contentType != XML_SCHEMA_CONTENT_SIMPLE) && |
| 12577 | (type->contentType != XML_SCHEMA_CONTENT_BASIC) && |
| 12578 | (type->contentType != XML_SCHEMA_CONTENT_MIXED)) { |
| 12579 | xmlSchemaPSimpleTypeErr(pctxt, |
| 12580 | XML_SCHEMAP_COS_VALID_DEFAULT_2_1, |
| 12581 | NULL, NULL, node, |
| 12582 | type, NULL, NULL, |
| 12583 | "If the type of a constraint value is complex, its content " |
| 12584 | "type must be mixed or a simple type", |
| 12585 | NULL, NULL); |
| 12586 | return(XML_SCHEMAP_COS_VALID_DEFAULT_2_1); |
| 12587 | } |
| 12588 | if (type->contentType == XML_SCHEMA_CONTENT_MIXED) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12589 | /* |
| 12590 | * 2.2.2 If the {content type} is mixed, then the {content type}'s |
| 12591 | * particle must be ·emptiable· as defined by Particle Emptiable |
| 12592 | * (§3.9.6). |
| 12593 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12594 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12595 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12596 | * URGENT TODO: Implement this. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12597 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12598 | return (0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12599 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12600 | } |
| 12601 | /* |
| 12602 | * 1 If the type definition is a simple type definition, then the string |
| 12603 | * must be ·valid· with respect to that definition as defined by String |
| 12604 | * Valid (§3.14.4). |
| 12605 | * |
| 12606 | * AND |
| 12607 | * |
| 12608 | * 2.2.1 If the {content type} is a simple type definition, then the |
| 12609 | * string must be ·valid· with respect to that simple type definition |
| 12610 | * as defined by String Valid (§3.14.4). |
| 12611 | */ |
| 12612 | vctxt->node = node; |
| 12613 | vctxt->cur = NULL; |
| 12614 | ret = xmlSchemaValidateSimpleTypeValue(vctxt, type, value, 1, 1, 1, 0); |
| 12615 | /* ret = xmlSchemaCheckCVCSimpleType(vctxt, elemDecl->value, typeDef, 0); */ |
| 12616 | if (ret < 0) { |
| 12617 | xmlSchemaPErr(pctxt, node, |
| 12618 | /* NOTNICE: error code: This function will be used during |
| 12619 | * schema construction and xsi:type validation. |
| 12620 | */ |
| 12621 | XML_SCHEMAP_INTERNAL, |
| 12622 | "Internal error: xmlSchemaCheckCOSValidDefault, " |
| 12623 | "while validating a value constaint value.\n", |
| 12624 | NULL, NULL); |
| 12625 | |
| 12626 | } |
| 12627 | return (ret); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12628 | } |
| 12629 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12630 | #if 0 /* Not yet used code for CT schema validation */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12631 | /** |
| 12632 | * xmlSchemaGetSTContentOfCT: |
| 12633 | * @ctxt: the schema parser context |
| 12634 | * @type: the complex type definition |
| 12635 | * |
| 12636 | * |
| 12637 | * Returns the corresponding simple type for the content of |
| 12638 | * the complex type. |
| 12639 | */ |
| 12640 | static xmlSchemaTypePtr |
| 12641 | xmlSchemaGetSTContentOfCT(xmlSchemaParserCtxtPtr ctxt, |
| 12642 | xmlSchemaTypePtr type) |
| 12643 | { |
| 12644 | xmlSchemaTypePtr orig = type, anyType; |
| 12645 | |
| 12646 | anyType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 12647 | while ((type != NULL) && (type != anyType) && |
| 12648 | (type->type == XML_SCHEMA_TYPE_COMPLEX)) { |
| 12649 | if (type->type == XML_SCHEMA_TYPE_SIMPLE) |
| 12650 | return(type); |
| 12651 | type = type->baseType; |
| 12652 | } |
| 12653 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 12654 | XML_SCHEMAP_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12655 | NULL, orig, NULL, |
| 12656 | "Internal error: xmlSchemaGetSTContentTypeOfCT, " |
| 12657 | "no simple type for the content of complex type '%s' could be " |
| 12658 | "computed", orig->name); |
| 12659 | return (NULL); |
| 12660 | } |
| 12661 | |
| 12662 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12663 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12664 | |
| 12665 | /** |
| 12666 | * xmlSchemaCheckCOSCTExtends: |
| 12667 | * @ctxt: the schema parser context |
| 12668 | * @type: the complex type definition |
| 12669 | * |
| 12670 | * Schema Component Constraint: Derivation Valid (Extension) |
| 12671 | * |
| 12672 | * Returns 0 if the constraints are satisfied, a positive |
| 12673 | * error code if not and -1 if an internal error occured. |
| 12674 | */ |
| 12675 | static int |
| 12676 | xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt, |
| 12677 | xmlSchemaTypePtr type) |
| 12678 | { |
| 12679 | xmlSchemaTypePtr base; |
| 12680 | /* |
| 12681 | * 1 If the {base type definition} is a complex type definition, |
| 12682 | * then all of the following must be true: |
| 12683 | */ |
| 12684 | base = type->baseType; |
| 12685 | if (base == NULL) { |
| 12686 | xmlSchemaPCustomErr(ctxt, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 12687 | XML_SCHEMAP_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12688 | NULL, type, NULL, |
| 12689 | "Internal error: xmlSchemaCheckCOSCTExtends, " |
| 12690 | "the complex type '%s' has no base type", type->name); |
| 12691 | return (-1); |
| 12692 | } |
| 12693 | if (base->type == XML_SCHEMA_TYPE_COMPLEX) { |
| 12694 | /* |
| 12695 | * 1.1 The {final} of the {base type definition} must not |
| 12696 | * contain extension. |
| 12697 | */ |
| 12698 | if (base->flags & XML_SCHEMAS_TYPE_FINAL_EXTENSION) { |
| 12699 | xmlSchemaPCustomErr(ctxt, |
| 12700 | XML_SCHEMAP_COS_CT_EXTENDS_1_1, |
| 12701 | NULL, type, NULL, |
| 12702 | "The 'final' of the base type definition " |
| 12703 | "contains extension", NULL); |
| 12704 | return (XML_SCHEMAP_COS_CT_EXTENDS_1_1); |
| 12705 | } |
| 12706 | /* |
| 12707 | * 1.2 Its {attribute uses} must be a subset of the {attribute uses} |
| 12708 | * of the complex type definition itself, that is, for every attribute |
| 12709 | * use in the {attribute uses} of the {base type definition}, there |
| 12710 | * must be an attribute use in the {attribute uses} of the complex |
| 12711 | * type definition itself whose {attribute declaration} has the same |
| 12712 | * {name}, {target namespace} and {type definition} as its attribute |
| 12713 | * declaration |
| 12714 | * |
| 12715 | * NOTE: This will be already satisfied by the way the attribute uses |
| 12716 | * are extended in xmlSchemaBuildAttributeValidation; thus this check |
| 12717 | * is not needed. |
| 12718 | */ |
| 12719 | |
| 12720 | /* |
| 12721 | * 1.3 If it has an {attribute wildcard}, the complex type definition |
| 12722 | * must also have one, and the base type definition's {attribute |
| 12723 | * wildcard}'s {namespace constraint} must be a subset of the complex |
| 12724 | * type definition's {attribute wildcard}'s {namespace constraint}, |
| 12725 | * as defined by Wildcard Subset (§3.10.6). |
| 12726 | * |
| 12727 | * This is already checked in xmlSchemaBuildAttributeValidation; thus |
| 12728 | * this check is not needed. |
| 12729 | */ |
| 12730 | |
| 12731 | /* |
| 12732 | * 1.4 One of the following must be true: |
| 12733 | * |
| 12734 | * 1.4.1 The {content type} of the {base type definition} and the |
| 12735 | * {content type} of the complex type definition itself must be the same |
| 12736 | * simple type definition |
| 12737 | */ |
| 12738 | |
| 12739 | |
| 12740 | |
| 12741 | } else { |
| 12742 | /* |
| 12743 | * 2 If the {base type definition} is a simple type definition, |
| 12744 | * then all of the following must be true: |
| 12745 | */ |
| 12746 | /* |
| 12747 | * 2.1 The {content type} must be the same simple type definition. |
| 12748 | */ |
| 12749 | /* |
| 12750 | * 2.2 The {final} of the {base type definition} must not contain |
| 12751 | * extension |
| 12752 | */ |
| 12753 | } |
| 12754 | |
| 12755 | } |
| 12756 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12757 | static int |
| 12758 | xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt, |
| 12759 | xmlSchemaTypePtr type) |
| 12760 | { |
| 12761 | xmlSchemaTypePtr base, content; |
| 12762 | int OK = 0; |
| 12763 | |
| 12764 | /* |
| 12765 | * TODO: Adjust the error codes here, as I used |
| 12766 | * XML_SCHEMAP_SRC_CT_1 only yet. |
| 12767 | */ |
| 12768 | /* |
| 12769 | * Schema Representation Constraint: |
| 12770 | * Complex Type Definition Representation OK |
| 12771 | */ |
| 12772 | base = type->baseType; |
| 12773 | if (base == NULL) { |
| 12774 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, NULL, type, NULL, |
| 12775 | "Internal error: xmlSchemaCheckSRCCT, '%s', no base type", |
| 12776 | type->name); |
| 12777 | return (-1); |
| 12778 | } |
| 12779 | |
| 12780 | if (type->subtypes != NULL) { |
| 12781 | if (type->subtypes->type == XML_SCHEMA_TYPE_COMPLEX_CONTENT) { |
| 12782 | if IS_COMPLEX_TYPE(base) { |
| 12783 | /* |
| 12784 | * 1 If the <complexContent> alternative is chosen, the type definition |
| 12785 | * ·resolved· to by the ·actual value· of the base [attribute] |
| 12786 | * must be a complex type definition; |
| 12787 | */ |
| 12788 | xmlSchemaPCustomErr(ctxt, |
| 12789 | XML_SCHEMAP_SRC_CT_1, |
| 12790 | NULL, type, NULL, |
| 12791 | "The base type is not a complex type", NULL); |
| 12792 | return (XML_SCHEMAP_SRC_CT_1); |
| 12793 | } |
| 12794 | } else if (type->subtypes->type == XML_SCHEMA_TYPE_SIMPLE_CONTENT) { |
| 12795 | |
| 12796 | if IS_SIMPLE_TYPE(base) { |
| 12797 | if (type->flags & |
| 12798 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
| 12799 | /* |
| 12800 | * 2.1.3 only if the <extension> alternative is also |
| 12801 | * chosen, a simple type definition. |
| 12802 | */ |
| 12803 | /* TODO: Change error code to ..._SRC_CT_2_1_3. */ |
| 12804 | xmlSchemaPCustomErr(ctxt, |
| 12805 | XML_SCHEMAP_SRC_CT_1, |
| 12806 | NULL, type, NULL, |
| 12807 | "A complex type (simple content) cannot restrict " |
| 12808 | "an other simple type", |
| 12809 | NULL); |
| 12810 | return (XML_SCHEMAP_SRC_CT_1); |
| 12811 | } |
| 12812 | OK = 1; |
| 12813 | |
| 12814 | } else { /* if IS_SIMPLE_TYPE(base) */ |
| 12815 | if (base->contentType = XML_SCHEMA_CONTENT_MIXED) { |
| 12816 | /* |
| 12817 | * 2.1.2 only if the <restriction> alternative is also |
| 12818 | * chosen, a complex type definition whose {content type} |
| 12819 | * is mixed and a particle emptyable. |
| 12820 | */ |
| 12821 | /* |
| 12822 | * FIXME TODO: Check for *empiable particle* is missing. |
| 12823 | */ |
| 12824 | if ((type->flags & |
| 12825 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) == 0) { |
| 12826 | xmlSchemaPCustomErr(ctxt, |
| 12827 | XML_SCHEMAP_SRC_CT_1, |
| 12828 | NULL, type, NULL, |
| 12829 | "A complex type (simple content) cannot " |
| 12830 | "extend an other complex type which has a " |
| 12831 | "content type of: 'mixed' and emptiable particle", |
| 12832 | NULL); |
| 12833 | return (XML_SCHEMAP_SRC_CT_1); |
| 12834 | } |
| 12835 | /* |
| 12836 | * NOTE: This will be fired as well, if the base type |
| 12837 | * is *'anyType'*. |
| 12838 | * NOTE: type->subtypes->subtypes will be the |
| 12839 | * <restriction> item. |
| 12840 | */ |
| 12841 | if (type->subtypes->subtypes == NULL) { |
| 12842 | /* Yes, this is paranoid programming. */ |
| 12843 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, |
| 12844 | NULL, type, NULL, |
| 12845 | "Internal error: xmlSchemaCheckSRCCT, " |
| 12846 | "'%s', <simpleContent> has no <restriction>", |
| 12847 | type->name); |
| 12848 | return (-1); |
| 12849 | } |
| 12850 | /* |
| 12851 | * 2.2 If clause 2.1.2 above is satisfied, then there |
| 12852 | * must be a <simpleType> among the [children] of |
| 12853 | * <restriction>. |
| 12854 | */ |
| 12855 | if (type->subtypes->subtypes->type != |
| 12856 | XML_SCHEMA_TYPE_SIMPLE) { |
| 12857 | /* TODO: Change error code to ..._SRC_CT_2_2. */ |
| 12858 | xmlSchemaPCustomErr(ctxt, |
| 12859 | XML_SCHEMAP_SRC_CT_1, |
| 12860 | NULL, type, NULL, |
| 12861 | "A <simpleType> is expected among the children " |
| 12862 | "of <restriction>", NULL); |
| 12863 | return (XML_SCHEMAP_SRC_CT_1); |
| 12864 | } |
| 12865 | OK = 1; |
| 12866 | } else { /* if (base->contentType = XML_SCHEMA_CONTENT_MIXED)*/ |
| 12867 | /* |
| 12868 | * 2.1.1 a complex type definition whose {content type} is a |
| 12869 | * simple type definition; |
| 12870 | */ |
| 12871 | if (base->contentType == XML_SCHEMA_CONTENT_ELEMENTS) { |
| 12872 | xmlSchemaPCustomErr(ctxt, |
| 12873 | XML_SCHEMAP_SRC_CT_1, |
| 12874 | NULL, type, NULL, |
| 12875 | "A complex type (simple content) cannot " |
| 12876 | "be derived from the complex type '%s'", |
| 12877 | base->name); |
| 12878 | return (XML_SCHEMAP_SRC_CT_1); |
| 12879 | } |
| 12880 | content = base->contentTypeDef; |
| 12881 | if (content == NULL) { |
| 12882 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, |
| 12883 | NULL, type, NULL, |
| 12884 | "Internal error: xmlSchemaCheckSRCCT, " |
| 12885 | "'%s', base type has no content type", |
| 12886 | type->name); |
| 12887 | return (-1); |
| 12888 | } |
| 12889 | if (content->type != XML_SCHEMA_TYPE_SIMPLE) { |
| 12890 | xmlSchemaPCustomErr(ctxt, |
| 12891 | XML_SCHEMAP_SRC_CT_1, |
| 12892 | NULL, type, NULL, |
| 12893 | "A complex type (simple content) cannot " |
| 12894 | "be derived from the complex type '%s'", |
| 12895 | base->name); |
| 12896 | return (XML_SCHEMAP_SRC_CT_1); |
| 12897 | } |
| 12898 | } |
| 12899 | } |
| 12900 | } |
| 12901 | } |
| 12902 | /* |
| 12903 | * TODO: 3 The corresponding complex type definition component must |
| 12904 | * satisfy the conditions set out in Constraints on Complex Type |
| 12905 | * Definition Schema Components (§3.4.6); |
| 12906 | * |
| 12907 | * TODO: 4 If clause 2.2.1 or clause 2.2.2 in the correspondence specification |
| 12908 | * above for {attribute wildcard} is satisfied, the intensional |
| 12909 | * intersection must be expressible, as defined in Attribute Wildcard |
| 12910 | * Intersection (§3.10.6). |
| 12911 | */ |
| 12912 | |
| 12913 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 12914 | #endif |
| 12915 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 12916 | /** |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 12917 | * xmlSchemaGroupDefFixup: |
| 12918 | * @typeDecl: the schema model group definition |
| 12919 | * @ctxt: the schema parser context |
| 12920 | * |
| 12921 | * Fixes model group definitions. |
| 12922 | */ |
| 12923 | static void |
| 12924 | xmlSchemaGroupDefFixup(xmlSchemaTypePtr group, |
| 12925 | xmlSchemaParserCtxtPtr ctxt, |
| 12926 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 12927 | { |
| 12928 | group->contentType = XML_SCHEMA_CONTENT_ELEMENTS; |
| 12929 | if ((group->ref != NULL) && (group->subtypes == NULL)) { |
| 12930 | xmlSchemaTypePtr groupDef; |
| 12931 | /* |
| 12932 | * Resolve the reference. |
| 12933 | */ |
| 12934 | groupDef = xmlSchemaGetGroup(ctxt->schema, group->ref, |
| 12935 | group->refNs); |
| 12936 | if (groupDef == NULL) { |
| 12937 | xmlSchemaPResCompAttrErr(ctxt, |
| 12938 | XML_SCHEMAP_SRC_RESOLVE, |
| 12939 | NULL, group, NULL, |
| 12940 | "ref", group->ref, group->refNs, |
| 12941 | XML_SCHEMA_TYPE_GROUP, NULL); |
| 12942 | return; |
| 12943 | } |
| 12944 | group->subtypes = groupDef; |
| 12945 | } |
| 12946 | } |
| 12947 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 12948 | #if 0 /* Enable when the content type will be computed. */ |
| 12949 | static int |
| 12950 | xmlSchemaComputeContentType(xmlSchemaParserCtxtPtr ctxt, |
| 12951 | xmlSchemaTypePtr type) |
| 12952 | { |
| 12953 | xmlSchemaTypePtr base, res = NULL; |
| 12954 | |
| 12955 | base = type->baseType; |
| 12956 | if (base == NULL) { |
| 12957 | xmlSchemaPCustomErr(ctxt, |
| 12958 | XML_SCHEMAP_INTERNAL, |
| 12959 | NULL, type, NULL, |
| 12960 | "Internal error: xmlSchemaGetContentType, " |
| 12961 | "the complex type '%s' has no base type", type->name); |
| 12962 | return (-1); |
| 12963 | } |
| 12964 | if (IS_ANYTYPE(base) || (type->subtypes->type == |
| 12965 | XML_SCHEMA_TYPE_COMPLEX_CONTENT)) { |
| 12966 | xmlSchemaTypePtr start; |
| 12967 | /* |
| 12968 | * Effective 'mixed'. |
| 12969 | */ |
| 12970 | if (type->flags & XML_SCHEMAS_TYPE_MIXED) |
| 12971 | type->contentType = XML_SCHEMA_CONTENT_MIXED; |
| 12972 | /* |
| 12973 | * Effective content. |
| 12974 | */ |
| 12975 | if (IS_ANYTYPE(base)) |
| 12976 | start = type; |
| 12977 | else |
| 12978 | start = type->subtypes; |
| 12979 | |
| 12980 | } else { /* if XML_SCHEMA_TYPE_COMPLEX_CONTENT */ |
| 12981 | xmlSchemaTypePtr baseContentItem; |
| 12982 | |
| 12983 | /* |
| 12984 | * Complex type with simple content. |
| 12985 | */ |
| 12986 | if IS_COMPLEX_TYPE(base) { |
| 12987 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION) { |
| 12988 | /* |
| 12989 | * Summary: a complex type (simple content) can *restrict* |
| 12990 | * a complex type with the following content type: |
| 12991 | * 1. 'mixed' and an emptiable particle |
| 12992 | * 2. simple type |
| 12993 | */ |
| 12994 | if (base->contentType == XML_SCHEMA_CONTENT_MIXED) { |
| 12995 | /* |
| 12996 | * 2 if the {content type} of the base type is mixed and a |
| 12997 | * particle which is ·emptiable·, |
| 12998 | * [...] |
| 12999 | * then starting from the simple type definition |
| 13000 | * corresponding to the <simpleType> among the [children] |
| 13001 | * of <restriction> (**which must be present**) |
| 13002 | * |
| 13003 | * FIXME TODO: Handle "emptiable particle". |
| 13004 | */ |
| 13005 | res = type->subtypes->subtypes; |
| 13006 | if (res == NULL) { |
| 13007 | xmlSchemaPCustomErr(ctxt, |
| 13008 | XML_SCHEMAP_INTERNAL, |
| 13009 | NULL, type, NULL, |
| 13010 | "Internal error: xmlSchemaGetContentType, " |
| 13011 | "CT '%s' (restricting): <simpleContent> has no " |
| 13012 | "<restriction>", |
| 13013 | type->name); |
| 13014 | return (-1); |
| 13015 | } |
| 13016 | |
| 13017 | res->subtypes; |
| 13018 | if (res == NULL) { |
| 13019 | xmlSchemaPCustomErr(ctxt, |
| 13020 | XML_SCHEMAP_INTERNAL, |
| 13021 | NULL, type, NULL, |
| 13022 | "Internal error: xmlSchemaGetContentType, " |
| 13023 | "CT '%s' (restricting): <restriction> has no " |
| 13024 | "mandatory <simpleType>", |
| 13025 | type->name); |
| 13026 | return (-1); |
| 13027 | } |
| 13028 | } else { |
| 13029 | baseContentItem = base->contentTypeDef; |
| 13030 | if (baseContentItem == NULL) { |
| 13031 | xmlSchemaPCustomErr(ctxt, |
| 13032 | XML_SCHEMAP_INTERNAL, |
| 13033 | NULL, type, NULL, |
| 13034 | "Internal error: xmlSchemaGetContentType, " |
| 13035 | "CT '%s' (restricting), the base type has no " |
| 13036 | "content type", type->name); |
| 13037 | return (-1); |
| 13038 | } |
| 13039 | if IS_SIMPLE_TYPE(baseContentItem) { |
| 13040 | /* |
| 13041 | * 1 If the base type is a complex type whose own |
| 13042 | * {content type} is a simple type and the <restriction> |
| 13043 | * alternative is chosen |
| 13044 | */ |
| 13045 | /* type->subtypes->subtypes will be the restriction item.*/ |
| 13046 | res = type->subtypes->subtypes; |
| 13047 | if (res == NULL) { |
| 13048 | xmlSchemaPCustomErr(ctxt, |
| 13049 | XML_SCHEMAP_INTERNAL, |
| 13050 | NULL, type, NULL, |
| 13051 | "Internal error: xmlSchemaGetContentType, " |
| 13052 | "CT '%s' (restricting): <simpleType> has no " |
| 13053 | "<restriction>", type->name); |
| 13054 | return (-1); |
| 13055 | } |
| 13056 | /* |
| 13057 | * 1.1 the simple type definition corresponding to the |
| 13058 | * <simpleType> among the [children] of <restriction>if |
| 13059 | * there is one; |
| 13060 | */ |
| 13061 | res = res->subtypes; |
| 13062 | if (res == NULL) { |
| 13063 | /* |
| 13064 | * 1.2 otherwise the {content type} |
| 13065 | * of the base type . |
| 13066 | */ |
| 13067 | res = baseContentItem; |
| 13068 | } |
| 13069 | } |
| 13070 | } |
| 13071 | /* |
| 13072 | * SPECIAL TODO: If *restricting* the spec wants us to |
| 13073 | * create an *additional* simple type which restricts the |
| 13074 | * located simple type; we won't do this yet, and look how |
| 13075 | * far we get with it. |
| 13076 | */ |
| 13077 | } else { /* if XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION */ |
| 13078 | /* |
| 13079 | * Summary: a complex type (simple content) can *extend* |
| 13080 | * only a complex base with a simple type as content. |
| 13081 | */ |
| 13082 | /* |
| 13083 | * 3 If the type definition ·resolved· to by the ·actual |
| 13084 | * value· of the base [attribute] is a complex type |
| 13085 | * definition (whose own {content type} *must be* a simple |
| 13086 | * type definition, see below) and the *<extension>* |
| 13087 | * alternative is chosen, then the {content type} of that |
| 13088 | * complex type definition; |
| 13089 | */ |
| 13090 | res = base->contentTypeDef; |
| 13091 | if (res == NULL) { |
| 13092 | xmlSchemaPCustomErr(ctxt, |
| 13093 | XML_SCHEMAP_INTERNAL, |
| 13094 | NULL, type, NULL, |
| 13095 | "Internal error: xmlSchemaGetContentType, " |
| 13096 | "CT '%s' (extending), the base type has no content " |
| 13097 | "type", type->name); |
| 13098 | return (-1); |
| 13099 | } |
| 13100 | if (! IS_SIMPLE_TYPE(res)) { |
| 13101 | xmlSchemaPCustomErr(ctxt, |
| 13102 | XML_SCHEMAP_INTERNAL, |
| 13103 | NULL, type, NULL, |
| 13104 | "Internal error: xmlSchemaGetContentType, " |
| 13105 | "CT '%s' (extending), the content type of the " |
| 13106 | "base is not a simple type", type->name); |
| 13107 | return (-1); |
| 13108 | } |
| 13109 | } |
| 13110 | } else /* if IS_COMPLEX_TYPE(base) */ |
| 13111 | if (type->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION) { |
| 13112 | /* |
| 13113 | * 4 otherwise (the type definition ·resolved· to by the |
| 13114 | * ·actual value· of the base [attribute] is a simple type |
| 13115 | * definition and the <extension> alternative is chosen), |
| 13116 | * then that simple type definition. |
| 13117 | */ |
| 13118 | res = base; |
| 13119 | } |
| 13120 | type->contentTypeDef = res; |
| 13121 | if (res == NULL) { |
| 13122 | xmlSchemaPCustomErr(ctxt, |
| 13123 | XML_SCHEMAP_INTERNAL, |
| 13124 | NULL, type, NULL, |
| 13125 | "Internal error: xmlSchemaGetContentType, " |
| 13126 | "'%s', the content type could not be determined", |
| 13127 | type->name); |
| 13128 | return (-1); |
| 13129 | } |
| 13130 | |
| 13131 | } |
| 13132 | |
| 13133 | } |
| 13134 | #endif |
| 13135 | |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 13136 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13137 | * xmlSchemaTypeFixup: |
| 13138 | * @typeDecl: the schema type definition |
| 13139 | * @ctxt: the schema parser context |
| 13140 | * |
| 13141 | * Fixes the content model of the type. |
| 13142 | */ |
| 13143 | static void |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13144 | xmlSchemaTypeFixup(xmlSchemaTypePtr item, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13145 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13146 | { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13147 | xmlSchemaTypePtr ctxtType; |
| 13148 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13149 | if (item == NULL) |
Daniel Veillard | 82bbbd4 | 2003-05-11 20:16:09 +0000 | [diff] [blame] | 13150 | return; |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 13151 | /* |
| 13152 | * Do not allow the following types to be typefixed, prior to |
| 13153 | * the corresponding simple/complex types. |
| 13154 | */ |
| 13155 | if (ctxt->ctxtType == NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13156 | switch (item->type) { |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 13157 | case XML_SCHEMA_TYPE_SIMPLE_CONTENT: |
| 13158 | case XML_SCHEMA_TYPE_COMPLEX_CONTENT: |
| 13159 | case XML_SCHEMA_TYPE_UNION: |
| 13160 | case XML_SCHEMA_TYPE_RESTRICTION: |
| 13161 | case XML_SCHEMA_TYPE_EXTENSION: |
| 13162 | return; |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 13163 | default: |
| 13164 | break; |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 13165 | } |
| 13166 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13167 | if (name == NULL) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13168 | name = item->name; |
| 13169 | if (item->contentType == XML_SCHEMA_CONTENT_UNKNOWN) { |
| 13170 | switch (item->type) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13171 | case XML_SCHEMA_TYPE_SIMPLE_CONTENT:{ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13172 | if (item->subtypes != NULL) { |
| 13173 | if (item->subtypes->contentType == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13174 | XML_SCHEMA_CONTENT_UNKNOWN) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13175 | xmlSchemaTypeFixup(item->subtypes, ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13176 | NULL); |
| 13177 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13178 | item->contentType = |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13179 | XML_SCHEMA_CONTENT_SIMPLE; |
| 13180 | /* item->subtypes->contentType; */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13181 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13182 | break; |
| 13183 | } |
| 13184 | case XML_SCHEMA_TYPE_RESTRICTION:{ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13185 | xmlSchemaTypePtr base = NULL; |
| 13186 | |
| 13187 | ctxt->ctxtType->flags |= |
| 13188 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13189 | if (item->baseType != NULL) |
| 13190 | base = item->baseType; |
| 13191 | else if (item->base != NULL) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13192 | base = |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13193 | xmlSchemaGetType(ctxt->schema, item->base, |
| 13194 | item->baseNs); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13195 | if (base == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13196 | xmlSchemaPResCompAttrErr(ctxt, |
| 13197 | XML_SCHEMAP_SRC_RESOLVE, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13198 | NULL, NULL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13199 | (xmlNodePtr) xmlSchemaGetPropNode(item->node, "base"), |
| 13200 | "base", item->base, item->baseNs, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13201 | XML_SCHEMA_TYPE_BASIC, "type definition"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13202 | } else if (base->contentType == |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 13203 | XML_SCHEMA_CONTENT_UNKNOWN) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13204 | xmlSchemaTypeFixup(base, ctxt, NULL); |
| 13205 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13206 | } |
| 13207 | ctxt->ctxtType->baseType = base; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13208 | if (ctxt->ctxtType->type == XML_SCHEMA_TYPE_COMPLEX) { |
| 13209 | /* |
| 13210 | * ComplexType restriction. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13211 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13212 | /* |
| 13213 | * Content type. |
| 13214 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13215 | if (item->subtypes == NULL) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13216 | /* 1.1.1 */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13217 | item->contentType = XML_SCHEMA_CONTENT_EMPTY; |
| 13218 | else if ((item->subtypes->subtypes == NULL) && |
| 13219 | ((item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13220 | XML_SCHEMA_TYPE_ALL) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13221 | || (item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13222 | XML_SCHEMA_TYPE_SEQUENCE))) |
| 13223 | /* 1.1.2 */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13224 | item->contentType = XML_SCHEMA_CONTENT_EMPTY; |
| 13225 | else if ((item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13226 | XML_SCHEMA_TYPE_CHOICE) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13227 | && (item->subtypes->subtypes == NULL)) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13228 | /* 1.1.3 */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13229 | item->contentType = XML_SCHEMA_CONTENT_EMPTY; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13230 | else { |
| 13231 | /* 1.2 and 2.X are applied at the other layer */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13232 | item->contentType = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13233 | XML_SCHEMA_CONTENT_ELEMENTS; |
| 13234 | } |
| 13235 | } else { |
| 13236 | /* |
| 13237 | * SimpleType restriction. |
| 13238 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 13239 | /* TODO: Nothing? */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13240 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13241 | break; |
| 13242 | } |
| 13243 | case XML_SCHEMA_TYPE_EXTENSION:{ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13244 | xmlSchemaTypePtr base = NULL; |
| 13245 | xmlSchemaContentType explicitContentType; |
| 13246 | |
| 13247 | /* |
| 13248 | * An extension does exist on a complexType only. |
| 13249 | */ |
| 13250 | ctxt->ctxtType->flags |= |
| 13251 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13252 | if (item->recurse) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 13253 | /* TODO: The word "recursive" should be changed to "circular" here. */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13254 | xmlSchemaPCustomErr(ctxt, |
| 13255 | XML_SCHEMAP_UNKNOWN_BASE_TYPE, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13256 | NULL, item, item->node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13257 | "This item is circular", NULL); |
Daniel Veillard | 2582a33 | 2004-04-18 19:49:46 +0000 | [diff] [blame] | 13258 | return; |
| 13259 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13260 | if (item->base != NULL) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13261 | base = |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13262 | xmlSchemaGetType(ctxt->schema, item->base, |
| 13263 | item->baseNs); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13264 | if (base == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13265 | xmlSchemaPResCompAttrErr(ctxt, |
| 13266 | XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13267 | NULL, item, item->node, |
| 13268 | "base", item->base, item->baseNs, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13269 | XML_SCHEMA_TYPE_BASIC, "type definition"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13270 | } else if (base->contentType == |
| 13271 | XML_SCHEMA_CONTENT_UNKNOWN) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13272 | item->recurse = 1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13273 | xmlSchemaTypeFixup(base, ctxt, NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13274 | item->recurse = 0; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13275 | } |
| 13276 | /* |
| 13277 | * The type definition ·resolved· to by the ·actual |
| 13278 | * value· of the base [attribute] |
| 13279 | */ |
| 13280 | ctxt->ctxtType->baseType = base; |
| 13281 | /* |
| 13282 | * TODO: This one is still needed for computation of |
| 13283 | * the content model by xmlSchemaBuildAContentModel. |
| 13284 | * Try to get rid of it. |
| 13285 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13286 | item->baseType = base; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13287 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13288 | if ((item->subtypes != NULL) && |
| 13289 | (item->subtypes->contentType == XML_SCHEMA_CONTENT_UNKNOWN)) |
| 13290 | xmlSchemaTypeFixup(item->subtypes, ctxt, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13291 | |
| 13292 | explicitContentType = XML_SCHEMA_CONTENT_ELEMENTS; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13293 | if (item->subtypes == NULL) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13294 | /* 1.1.1 */ |
| 13295 | explicitContentType = XML_SCHEMA_CONTENT_EMPTY; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13296 | else if ((item->subtypes->subtypes == NULL) && |
| 13297 | ((item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13298 | XML_SCHEMA_TYPE_ALL) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13299 | || (item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13300 | XML_SCHEMA_TYPE_SEQUENCE))) |
| 13301 | /* 1.1.2 */ |
| 13302 | explicitContentType = XML_SCHEMA_CONTENT_EMPTY; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13303 | else if ((item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13304 | XML_SCHEMA_TYPE_CHOICE) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13305 | && (item->subtypes->subtypes == NULL)) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13306 | /* 1.1.3 */ |
| 13307 | explicitContentType = XML_SCHEMA_CONTENT_EMPTY; |
| 13308 | if (base != NULL) { |
| 13309 | /* It will be reported later, if the base is missing. */ |
| 13310 | if (explicitContentType == XML_SCHEMA_CONTENT_EMPTY) { |
| 13311 | /* 2.1 */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13312 | item->contentType = base->contentType; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13313 | } else if (base->contentType == |
| 13314 | XML_SCHEMA_CONTENT_EMPTY) { |
| 13315 | /* 2.2 imbitable ! */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13316 | item->contentType = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13317 | XML_SCHEMA_CONTENT_ELEMENTS; |
| 13318 | } else { |
| 13319 | /* 2.3 imbitable pareil ! */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13320 | item->contentType = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13321 | XML_SCHEMA_CONTENT_ELEMENTS; |
| 13322 | } |
| 13323 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13324 | break; |
| 13325 | } |
| 13326 | case XML_SCHEMA_TYPE_COMPLEX:{ |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 13327 | ctxtType = ctxt->ctxtType; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13328 | ctxt->ctxtType = item; |
| 13329 | /* |
| 13330 | * Start with an empty content-type type. |
| 13331 | */ |
| 13332 | if (item->subtypes == NULL) |
| 13333 | item->contentType = XML_SCHEMA_CONTENT_EMPTY; |
| 13334 | |
| 13335 | if ((item->subtypes == NULL) || |
| 13336 | ((item->subtypes->type != |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13337 | XML_SCHEMA_TYPE_SIMPLE_CONTENT) && |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13338 | (item->subtypes->type != |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13339 | XML_SCHEMA_TYPE_COMPLEX_CONTENT))) { |
| 13340 | /* |
| 13341 | * This case is understood as shorthand for complex |
| 13342 | * content restricting the ur-type definition, and |
| 13343 | * the details of the mappings should be modified as |
| 13344 | * necessary. |
| 13345 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13346 | item->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 13347 | item->flags |= |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13348 | XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13349 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13350 | * Assume that we inherit the content-type type |
| 13351 | * from 'anyType', which is 'mixed' and a particle |
| 13352 | * emptiable. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13353 | */ |
| 13354 | item->contentType = item->baseType->contentType; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13355 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13356 | /* |
| 13357 | * Fixup the sub components. |
| 13358 | */ |
| 13359 | if ((item->subtypes != NULL) && |
| 13360 | (item->subtypes->contentType == |
| 13361 | XML_SCHEMA_CONTENT_UNKNOWN)) { |
| 13362 | xmlSchemaTypeFixup(item->subtypes, ctxt, NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13363 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13364 | if (item->flags & XML_SCHEMAS_TYPE_MIXED) { |
| 13365 | item->contentType = XML_SCHEMA_CONTENT_MIXED; |
| 13366 | } else if (item->subtypes != NULL) { |
| 13367 | /* |
| 13368 | * Use the content-type type of the model groups |
| 13369 | * defined, if 'mixed' is not set. If 'mixed' is set |
| 13370 | * it will expand the content-type by allowing character |
| 13371 | * content to appear. |
| 13372 | */ |
| 13373 | item->contentType = |
| 13374 | item->subtypes->contentType; |
| 13375 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 13376 | |
| 13377 | /* |
| 13378 | * Some optimization for validation: |
| 13379 | * If there are no facets beside the "whitespace" facet, |
| 13380 | * then a value needs not to checked against against a |
| 13381 | * facet, thus no computed value is needed. |
| 13382 | * TODO URGENT: This is just a workaround, we need to |
| 13383 | * introduce the correct usage of contentType to store the |
| 13384 | * facets in! |
| 13385 | */ |
Daniel Veillard | d3210bc | 2005-01-28 17:56:39 +0000 | [diff] [blame] | 13386 | if ((item->baseType != NULL) && |
| 13387 | (item->baseType->flags & |
| 13388 | XML_SCHEMAS_TYPE_FACETSNEEDVALUE)) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 13389 | item->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE; |
| 13390 | else { |
| 13391 | xmlSchemaFacetLinkPtr cur; |
| 13392 | |
| 13393 | for (cur = item->facetSet; cur != NULL; |
| 13394 | cur = cur->next) { |
| 13395 | if (cur->facet->type != XML_SCHEMA_FACET_WHITESPACE) { |
| 13396 | item->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE; |
| 13397 | break; |
| 13398 | } |
| 13399 | } |
| 13400 | } |
| 13401 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13402 | xmlSchemaBuildAttributeValidation(ctxt, item); |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 13403 | xmlSchemaCheckDefaults(item, ctxt, item->name); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 13404 | ctxt->ctxtType = ctxtType; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13405 | break; |
| 13406 | } |
| 13407 | case XML_SCHEMA_TYPE_COMPLEX_CONTENT:{ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13408 | if (item->subtypes == NULL) { |
| 13409 | item->contentType = XML_SCHEMA_CONTENT_EMPTY; |
| 13410 | if (item->flags & XML_SCHEMAS_TYPE_MIXED) |
| 13411 | item->contentType = |
Daniel Veillard | 1aefc86 | 2004-03-04 11:40:48 +0000 | [diff] [blame] | 13412 | XML_SCHEMA_CONTENT_MIXED; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13413 | } else { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13414 | if (item->flags & XML_SCHEMAS_TYPE_MIXED) { |
| 13415 | item->contentType = |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13416 | XML_SCHEMA_CONTENT_MIXED; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 13417 | } else { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13418 | xmlSchemaTypeFixup(item->subtypes, ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13419 | NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13420 | if (item->subtypes != NULL) |
| 13421 | item->contentType = |
| 13422 | item->subtypes->contentType; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13423 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 13424 | /* |
| 13425 | * Removed due to implementation of the build of attribute uses. |
| 13426 | */ |
| 13427 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13428 | if (item->attributes == NULL) |
| 13429 | item->attributes = |
| 13430 | item->subtypes->attributes; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 13431 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13432 | } |
| 13433 | break; |
| 13434 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13435 | case XML_SCHEMA_TYPE_SIMPLE: |
| 13436 | /* |
| 13437 | * Simple Type Definition Schema Component |
| 13438 | * |
| 13439 | */ |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 13440 | ctxtType = ctxt->ctxtType; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13441 | item->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
| 13442 | if (item->subtypes->contentType == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13443 | XML_SCHEMA_CONTENT_UNKNOWN) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13444 | ctxt->ctxtType = item; |
| 13445 | xmlSchemaTypeFixup(item->subtypes, ctxt, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13446 | } |
| 13447 | /* Fixup base type */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13448 | if ((item->baseType != NULL) && |
| 13449 | (item->baseType->contentType == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13450 | XML_SCHEMA_CONTENT_UNKNOWN)) { |
| 13451 | /* OPTIMIZE: Actually this one will never by hit, since |
| 13452 | * the base type is already type-fixed in <restriction>. |
| 13453 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13454 | ctxt->ctxtType = item; |
| 13455 | xmlSchemaTypeFixup(item->baseType, ctxt, NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13456 | } |
| 13457 | /* Base type: |
| 13458 | * 2 If the <list> or <union> alternative is chosen, |
| 13459 | * then the ·simple ur-type definition·. |
| 13460 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13461 | if (item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13462 | XML_SCHEMA_TYPE_LIST) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13463 | item->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 13464 | item->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST; |
| 13465 | } else if (item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13466 | XML_SCHEMA_TYPE_UNION) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13467 | item->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 13468 | item->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION; |
| 13469 | } else if (item->subtypes->type == |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13470 | XML_SCHEMA_TYPE_RESTRICTION) { |
| 13471 | xmlSchemaFacetLinkPtr facet, cur, last = NULL; |
| 13472 | |
| 13473 | /* |
| 13474 | * Variety |
| 13475 | * If the <restriction> alternative is chosen, then the |
| 13476 | * {variety} of the {base type definition}. |
| 13477 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13478 | if (item->baseType != NULL) { |
| 13479 | if (item->baseType->flags & |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13480 | XML_SCHEMAS_TYPE_VARIETY_ATOMIC) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13481 | item->flags |= XML_SCHEMAS_TYPE_VARIETY_ATOMIC; |
| 13482 | else if (item->baseType->flags & |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13483 | XML_SCHEMAS_TYPE_VARIETY_LIST) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13484 | item->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST; |
| 13485 | else if (item->baseType->flags & |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13486 | XML_SCHEMAS_TYPE_VARIETY_UNION) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13487 | item->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13488 | /* |
| 13489 | * Schema Component Constraint: Simple Type Restriction |
| 13490 | * (Facets) |
| 13491 | * NOTE: Satisfaction of 1 and 2 arise from the fixup |
| 13492 | * applied beforehand. |
| 13493 | * |
| 13494 | * 3 The {facets} of R are the union of S and the {facets} |
| 13495 | * of B, eliminating duplicates. To eliminate duplicates, |
| 13496 | * when a facet of the same kind occurs in both S and the |
| 13497 | * {facets} of B, the one in the {facets} of B is not |
| 13498 | * included, with the exception of enumeration and pattern |
| 13499 | * facets, for which multiple occurrences with distinct values |
| 13500 | * are allowed. |
| 13501 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13502 | if (item->baseType->facetSet != NULL) { |
| 13503 | last = item->facetSet; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13504 | if (last != NULL) |
| 13505 | while (last->next != NULL) |
| 13506 | last = last->next; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 13507 | cur = item->baseType->facetSet; |
| 13508 | for (; cur != NULL; cur = cur->next) { |
| 13509 | /* |
| 13510 | * Base patterns won't be add here: |
| 13511 | * they are ORed in a type and |
| 13512 | * ANDed in derived types. This will |
| 13513 | * happed at validation level by |
| 13514 | * walking the base axis of the type. |
| 13515 | */ |
| 13516 | if (cur->facet->type == |
| 13517 | XML_SCHEMA_FACET_PATTERN) |
| 13518 | continue; |
| 13519 | facet = NULL; |
| 13520 | if ((item->facetSet != NULL) && |
| 13521 | /* REMOVED: a check for |
| 13522 | * XML_SCHEMA_FACET_PATTERN was already |
| 13523 | * performed above. |
| 13524 | |
| 13525 | * (cur->facet->type != |
| 13526 | * XML_SCHEMA_FACET_PATTERN) && |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13527 | */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 13528 | (cur->facet->type != |
| 13529 | XML_SCHEMA_FACET_ENUMERATION)) { |
| 13530 | facet = item->facetSet; |
| 13531 | do { |
| 13532 | if (cur->facet->type == |
| 13533 | facet->facet->type) |
| 13534 | break; |
| 13535 | facet = facet->next; |
| 13536 | } while (facet != NULL); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13537 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 13538 | if (facet == NULL) { |
| 13539 | facet = (xmlSchemaFacetLinkPtr) |
| 13540 | xmlMalloc(sizeof(xmlSchemaFacetLink)); |
| 13541 | if (facet == NULL) { |
| 13542 | xmlSchemaPErrMemory(ctxt, |
| 13543 | "fixing simpleType", NULL); |
| 13544 | return; |
| 13545 | } |
| 13546 | /* |
| 13547 | * The facets are not copied but referenced |
| 13548 | * via the facet link. |
| 13549 | */ |
| 13550 | facet->facet = cur->facet; |
| 13551 | facet->next = NULL; |
| 13552 | if (last == NULL) |
| 13553 | item->facetSet = facet; |
| 13554 | else |
| 13555 | last->next = facet; |
| 13556 | last = facet; |
| 13557 | } |
| 13558 | } |
| 13559 | } |
| 13560 | /* |
| 13561 | * Some optimization for validation: |
| 13562 | * If there are no facets beside the "whitespace" facet, |
| 13563 | * then a value needs not to checked against against a |
| 13564 | * facet, thus no computed value is needed. |
| 13565 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 13566 | if (item->baseType->flags & XML_SCHEMAS_TYPE_FACETSNEEDVALUE) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 13567 | item->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE; |
| 13568 | else { |
| 13569 | for (cur = item->facetSet; cur != NULL; |
| 13570 | cur = cur->next) { |
| 13571 | if (cur->facet->type != XML_SCHEMA_FACET_WHITESPACE) { |
| 13572 | item->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE; |
| 13573 | break; |
| 13574 | } |
| 13575 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13576 | } |
| 13577 | } |
| 13578 | } |
| 13579 | /* |
| 13580 | * Check constraints. |
| 13581 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13582 | xmlSchemaCheckSRCSimpleType(ctxt, item); |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 13583 | xmlSchemaCheckDefaults(item, ctxt, item->name); |
Daniel Veillard | 4e5d665 | 2004-06-29 21:01:12 +0000 | [diff] [blame] | 13584 | ctxt->ctxtType = ctxtType; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13585 | break; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 13586 | case XML_SCHEMA_TYPE_SEQUENCE: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13587 | case XML_SCHEMA_TYPE_ALL: |
| 13588 | case XML_SCHEMA_TYPE_CHOICE: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13589 | item->contentType = XML_SCHEMA_CONTENT_ELEMENTS; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13590 | break; |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 13591 | case XML_SCHEMA_TYPE_GROUP: |
| 13592 | /* |
| 13593 | * TODO: Handling was moved to xmlSchemaGroupDefFixup. |
| 13594 | */ |
| 13595 | break; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13596 | case XML_SCHEMA_TYPE_LIST: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13597 | xmlSchemaParseListRefFixup(item, ctxt); |
| 13598 | item->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13599 | break; |
| 13600 | case XML_SCHEMA_TYPE_UNION: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13601 | xmlSchemaParseUnionRefCheck(item, ctxt); |
| 13602 | item->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13603 | break; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13604 | case XML_SCHEMA_TYPE_BASIC: |
| 13605 | case XML_SCHEMA_TYPE_ANY: |
| 13606 | case XML_SCHEMA_TYPE_FACET: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13607 | case XML_SCHEMA_TYPE_UR: |
| 13608 | case XML_SCHEMA_TYPE_ELEMENT: |
| 13609 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 13610 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
William M. Brack | 29aa772 | 2004-05-12 00:27:56 +0000 | [diff] [blame] | 13611 | case XML_SCHEMA_TYPE_ANY_ATTRIBUTE: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13612 | case XML_SCHEMA_TYPE_NOTATION: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13613 | case XML_SCHEMA_FACET_MININCLUSIVE: |
| 13614 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
| 13615 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
| 13616 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
| 13617 | case XML_SCHEMA_FACET_TOTALDIGITS: |
| 13618 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
| 13619 | case XML_SCHEMA_FACET_PATTERN: |
| 13620 | case XML_SCHEMA_FACET_ENUMERATION: |
| 13621 | case XML_SCHEMA_FACET_WHITESPACE: |
| 13622 | case XML_SCHEMA_FACET_LENGTH: |
| 13623 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 13624 | case XML_SCHEMA_FACET_MINLENGTH: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13625 | item->contentType = XML_SCHEMA_CONTENT_SIMPLE; |
| 13626 | if (item->subtypes != NULL) |
| 13627 | xmlSchemaTypeFixup(item->subtypes, ctxt, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13628 | break; |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 13629 | case XML_SCHEMA_TYPE_IDC_UNIQUE: |
| 13630 | case XML_SCHEMA_TYPE_IDC_KEY: |
| 13631 | case XML_SCHEMA_TYPE_IDC_KEYREF: |
| 13632 | break; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13633 | } |
| 13634 | } |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 13635 | #ifdef DEBUG_TYPE |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13636 | if (item->node != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13637 | xmlGenericError(xmlGenericErrorContext, |
| 13638 | "Type of %s : %s:%d :", name, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13639 | item->node->doc->URL, |
| 13640 | xmlGetLineNo(item->node)); |
Daniel Veillard | decd64d | 2002-04-18 14:41:51 +0000 | [diff] [blame] | 13641 | } else { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13642 | xmlGenericError(xmlGenericErrorContext, "Type of %s :", name); |
Daniel Veillard | decd64d | 2002-04-18 14:41:51 +0000 | [diff] [blame] | 13643 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13644 | switch (item->contentType) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13645 | case XML_SCHEMA_CONTENT_SIMPLE: |
| 13646 | xmlGenericError(xmlGenericErrorContext, "simple\n"); |
| 13647 | break; |
| 13648 | case XML_SCHEMA_CONTENT_ELEMENTS: |
| 13649 | xmlGenericError(xmlGenericErrorContext, "elements\n"); |
| 13650 | break; |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 13651 | case XML_SCHEMA_CONTENT_UNKNOWN: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13652 | xmlGenericError(xmlGenericErrorContext, "unknown !!!\n"); |
| 13653 | break; |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 13654 | case XML_SCHEMA_CONTENT_EMPTY: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13655 | xmlGenericError(xmlGenericErrorContext, "empty\n"); |
| 13656 | break; |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 13657 | case XML_SCHEMA_CONTENT_MIXED: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13658 | xmlGenericError(xmlGenericErrorContext, "mixed\n"); |
| 13659 | break; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13660 | /* Removed, since not used. */ |
| 13661 | /* |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 13662 | case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13663 | xmlGenericError(xmlGenericErrorContext, "mixed or elems\n"); |
| 13664 | break; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13665 | */ |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 13666 | case XML_SCHEMA_CONTENT_BASIC: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13667 | xmlGenericError(xmlGenericErrorContext, "basic\n"); |
| 13668 | break; |
| 13669 | default: |
| 13670 | xmlGenericError(xmlGenericErrorContext, |
| 13671 | "not registered !!!\n"); |
| 13672 | break; |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 13673 | } |
| 13674 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13675 | } |
| 13676 | |
| 13677 | /** |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 13678 | * xmlSchemaCheckFacet: |
| 13679 | * @facet: the facet |
| 13680 | * @typeDecl: the schema type definition |
| 13681 | * @ctxt: the schema parser context or NULL |
| 13682 | * @name: name of the type |
| 13683 | * |
| 13684 | * Checks the default values types, especially for facets |
| 13685 | * |
| 13686 | * Returns 0 if okay or -1 in cae of error |
| 13687 | */ |
| 13688 | int |
| 13689 | xmlSchemaCheckFacet(xmlSchemaFacetPtr facet, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13690 | xmlSchemaTypePtr typeDecl, |
| 13691 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name) |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 13692 | { |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 13693 | xmlSchemaTypePtr nonNegativeIntegerType = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13694 | int ret = 0, reuseValCtxt = 0; |
| 13695 | |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 13696 | if ((facet == NULL) || (typeDecl == NULL)) |
| 13697 | return(-1); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13698 | /* |
| 13699 | * TODO: will the parser context be given if used from |
| 13700 | * the relaxNG module? |
| 13701 | */ |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 13702 | |
| 13703 | if (nonNegativeIntegerType == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13704 | nonNegativeIntegerType = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13705 | xmlSchemaGetBuiltInType(XML_SCHEMAS_NNINTEGER); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 13706 | } |
| 13707 | switch (facet->type) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13708 | case XML_SCHEMA_FACET_MININCLUSIVE: |
| 13709 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
| 13710 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 13711 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
| 13712 | case XML_SCHEMA_FACET_ENUMERATION: { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13713 | /* |
| 13714 | * Okay we need to validate the value |
| 13715 | * at that point. |
| 13716 | */ |
| 13717 | xmlSchemaValidCtxtPtr vctxt; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13718 | xmlSchemaTypePtr base; |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 13719 | |
| 13720 | /* 4.3.5.5 Constraints on enumeration Schema Components |
| 13721 | * Schema Component Constraint: enumeration valid restriction |
| 13722 | * It is an ·error· if any member of {value} is not in the |
| 13723 | * ·value space· of {base type definition}. |
| 13724 | * |
| 13725 | * minInclusive, maxInclusive, minExclusive, maxExclusive: |
| 13726 | * The value ·must· be in the |
| 13727 | * ·value space· of the ·base type·. |
| 13728 | */ |
| 13729 | /* |
| 13730 | * This function is intended to deliver a compiled value |
| 13731 | * on the facet. In XML Schemas the type holding a facet, |
| 13732 | * cannot be a built-in type. Thus to ensure that other API |
| 13733 | * calls (relaxng) do work, if the given type is a built-in |
| 13734 | * type, we will assume that the given built-in type *is |
| 13735 | * already* the base type. |
| 13736 | */ |
| 13737 | if (typeDecl->type != XML_SCHEMA_TYPE_BASIC) { |
| 13738 | base = typeDecl->baseType; |
| 13739 | if (base == NULL) { |
| 13740 | xmlSchemaPErr(ctxt, typeDecl->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 13741 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 13742 | "Internal error: xmlSchemaCheckFacet, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13743 | "the type '%s' has no base type.\n", |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 13744 | typeDecl->name, NULL); |
| 13745 | return (-1); |
| 13746 | } |
| 13747 | } else |
| 13748 | base = typeDecl; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13749 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13750 | * This avoids perseverative creation of the |
| 13751 | * validation context if a parser context is |
| 13752 | * used. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13753 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13754 | if (ctxt != NULL) { |
| 13755 | reuseValCtxt = 1; |
| 13756 | if (ctxt->vctxt == NULL) { |
| 13757 | if (xmlSchemaCreateVCtxtOnPCtxt(ctxt) == -1) |
| 13758 | return (-1); |
| 13759 | } |
| 13760 | vctxt = ctxt->vctxt; |
| 13761 | } else { |
| 13762 | vctxt = xmlSchemaNewValidCtxt(NULL); |
| 13763 | if (vctxt == NULL) { |
| 13764 | xmlSchemaPErr(ctxt, typeDecl->node, |
| 13765 | XML_SCHEMAP_INTERNAL, |
| 13766 | "Internal error: xmlSchemaCheckFacet, " |
| 13767 | "creating a new validation context.\n", |
| 13768 | NULL, NULL); |
| 13769 | return (-1); |
| 13770 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13771 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13772 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 13773 | vctxt->node = facet->node; |
| 13774 | vctxt->cur = NULL; |
| 13775 | /* |
| 13776 | * NOTE: This call does not check the content nodes, |
| 13777 | * since they are not available: |
| 13778 | * facet->node is just the node holding the facet |
| 13779 | * definition, *not* the attribute holding the *value* |
| 13780 | * of the facet. |
| 13781 | */ |
| 13782 | ret = xmlSchemaValidateSimpleTypeValue(vctxt, base, |
| 13783 | facet->value, 0, 1, 1, 0); |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 13784 | facet->val = vctxt->value; |
| 13785 | vctxt->value = NULL; |
| 13786 | if (ret > 0) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13787 | /* error code */ |
| 13788 | if (ctxt != NULL) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13789 | xmlSchemaPErrExt(ctxt, facet->node, |
| 13790 | XML_SCHEMAP_INVALID_FACET, |
| 13791 | NULL, NULL, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13792 | "Type definition '%s': The value '%s' of the " |
| 13793 | "facet '%s' is not valid.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13794 | name, facet->value, |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 13795 | BAD_CAST xmlSchemaFacetTypeToString(facet->type), |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13796 | NULL, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13797 | } |
| 13798 | ret = -1; |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 13799 | } else if (ret < 0) { |
| 13800 | xmlSchemaPErrExt(ctxt, facet->node, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 13801 | XML_SCHEMAP_INTERNAL, |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 13802 | NULL, NULL, NULL, |
| 13803 | "Internal error: xmlSchemaCheckFacet, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13804 | "failed to validate the value '%s' name of the " |
| 13805 | "facet '%s' against the base type '%s'.\n", |
Daniel Veillard | f4b05d0 | 2004-07-05 13:10:37 +0000 | [diff] [blame] | 13806 | facet->value, |
| 13807 | BAD_CAST xmlSchemaFacetTypeToString(facet->type), |
| 13808 | base->name, NULL, NULL); |
| 13809 | ret = -1; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 13810 | } |
| 13811 | if (reuseValCtxt == 0) |
| 13812 | xmlSchemaFreeValidCtxt(vctxt); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13813 | break; |
| 13814 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13815 | case XML_SCHEMA_FACET_PATTERN: |
| 13816 | facet->regexp = xmlRegexpCompile(facet->value); |
| 13817 | if (facet->regexp == NULL) { |
| 13818 | xmlSchemaPErr(ctxt, typeDecl->node, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13819 | XML_SCHEMAP_REGEXP_INVALID, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13820 | "Type definition '%s': The value '%s' of the " |
| 13821 | "facet 'pattern' is not valid.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13822 | name, facet->value); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13823 | ret = -1; |
| 13824 | } |
| 13825 | break; |
| 13826 | case XML_SCHEMA_FACET_TOTALDIGITS: |
| 13827 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
| 13828 | case XML_SCHEMA_FACET_LENGTH: |
| 13829 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 13830 | case XML_SCHEMA_FACET_MINLENGTH:{ |
| 13831 | int tmp; |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 13832 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13833 | tmp = |
| 13834 | xmlSchemaValidatePredefinedType(nonNegativeIntegerType, |
| 13835 | facet->value, |
Kasimier T. Buchcik | b4a9e64 | 2004-08-30 10:56:53 +0000 | [diff] [blame] | 13836 | &(facet->val)); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13837 | if (tmp != 0) { |
| 13838 | /* error code */ |
| 13839 | if (ctxt != NULL) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13840 | xmlSchemaPErrExt(ctxt, facet->node, |
| 13841 | XML_SCHEMAP_INVALID_FACET_VALUE, |
| 13842 | NULL, NULL, NULL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13843 | "Type definition '%s': The value '%s' of the " |
| 13844 | "facet '%s' is not valid.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13845 | name, facet->value, |
Daniel Veillard | b7c6ac4 | 2004-06-29 22:01:27 +0000 | [diff] [blame] | 13846 | BAD_CAST xmlSchemaFacetTypeToString(facet->type), |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13847 | NULL, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13848 | } |
| 13849 | ret = -1; |
| 13850 | } |
| 13851 | break; |
| 13852 | } |
| 13853 | case XML_SCHEMA_FACET_WHITESPACE:{ |
| 13854 | if (xmlStrEqual(facet->value, BAD_CAST "preserve")) { |
| 13855 | facet->whitespace = XML_SCHEMAS_FACET_PRESERVE; |
| 13856 | } else if (xmlStrEqual(facet->value, BAD_CAST "replace")) { |
| 13857 | facet->whitespace = XML_SCHEMAS_FACET_REPLACE; |
| 13858 | } else if (xmlStrEqual(facet->value, BAD_CAST "collapse")) { |
| 13859 | facet->whitespace = XML_SCHEMAS_FACET_COLLAPSE; |
| 13860 | } else { |
| 13861 | if (ctxt != NULL) { |
| 13862 | xmlSchemaPErr(ctxt, facet->node, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13863 | XML_SCHEMAP_INVALID_WHITE_SPACE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 13864 | "Type definition '%s': The value '%s' of the " |
| 13865 | "facet 'whiteSpace' is not valid.\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13866 | name, facet->value); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13867 | } |
| 13868 | ret = -1; |
| 13869 | } |
| 13870 | } |
| 13871 | default: |
| 13872 | break; |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 13873 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13874 | return (ret); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 13875 | } |
| 13876 | |
| 13877 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13878 | * xmlSchemaCheckDefaults: |
| 13879 | * @typeDecl: the schema type definition |
| 13880 | * @ctxt: the schema parser context |
| 13881 | * |
| 13882 | * Checks the default values types, especially for facets |
| 13883 | */ |
| 13884 | static void |
| 13885 | xmlSchemaCheckDefaults(xmlSchemaTypePtr typeDecl, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 13886 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13887 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13888 | if (name == NULL) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 13889 | name = typeDecl->name; |
| 13890 | /* |
| 13891 | * NOTE: It is intended to use the facets list, instead |
| 13892 | * of facetSet. |
| 13893 | */ |
| 13894 | if (typeDecl->facets != NULL) { |
| 13895 | xmlSchemaFacetPtr facet = typeDecl->facets; |
| 13896 | |
| 13897 | while (facet != NULL) { |
| 13898 | xmlSchemaCheckFacet(facet, typeDecl, ctxt, name); |
| 13899 | facet = facet->next; |
| 13900 | } |
| 13901 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 13902 | } |
| 13903 | |
| 13904 | /** |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 13905 | * xmlSchemaGetCircModelGrDefRef: |
| 13906 | * @ctxtGr: the searched model group |
| 13907 | * @list: the list of model groups to be processed |
| 13908 | * |
| 13909 | * This one is intended to be used by |
| 13910 | * xmlSchemaCheckGroupDefCircular only. |
| 13911 | * |
| 13912 | * Returns the circular model group definition reference, otherwise NULL. |
| 13913 | */ |
| 13914 | static xmlSchemaTypePtr |
| 13915 | xmlSchemaGetCircModelGrDefRef(xmlSchemaTypePtr ctxtGrDef, |
| 13916 | xmlSchemaTypePtr gr) |
| 13917 | { |
| 13918 | xmlSchemaTypePtr circ = NULL; |
| 13919 | int marked; |
| 13920 | /* |
| 13921 | * We will search for an model group reference which |
| 13922 | * references the context model group definition. |
| 13923 | */ |
| 13924 | while (gr != NULL) { |
| 13925 | if (((gr->type == XML_SCHEMA_TYPE_GROUP) || |
| 13926 | (gr->type == XML_SCHEMA_TYPE_ALL) || |
| 13927 | (gr->type == XML_SCHEMA_TYPE_SEQUENCE) || |
| 13928 | (gr->type == XML_SCHEMA_TYPE_CHOICE)) && |
| 13929 | (gr->subtypes != NULL)) { |
| 13930 | marked = 0; |
| 13931 | if ((gr->type == XML_SCHEMA_TYPE_GROUP) && |
| 13932 | (gr->ref != NULL)) { |
| 13933 | if (gr->subtypes == ctxtGrDef) |
| 13934 | return (gr); |
| 13935 | else if (gr->subtypes->flags & |
| 13936 | XML_SCHEMAS_TYPE_MARKED) { |
| 13937 | gr = gr->next; |
| 13938 | continue; |
| 13939 | } else { |
| 13940 | /* |
| 13941 | * Mark to avoid infinite recursion on |
| 13942 | * circular references not yet examined. |
| 13943 | */ |
| 13944 | gr->subtypes->flags |= XML_SCHEMAS_TYPE_MARKED; |
| 13945 | marked = 1; |
| 13946 | } |
| 13947 | if (gr->subtypes->subtypes != NULL) |
| 13948 | circ = xmlSchemaGetCircModelGrDefRef(ctxtGrDef, |
| 13949 | gr->subtypes->subtypes); |
| 13950 | /* |
| 13951 | * Unmark the visited model group definition. |
| 13952 | */ |
| 13953 | if (marked) |
| 13954 | gr->subtypes->flags ^= XML_SCHEMAS_TYPE_MARKED; |
| 13955 | if (circ != NULL) |
| 13956 | return (circ); |
| 13957 | } else { |
| 13958 | circ = xmlSchemaGetCircModelGrDefRef(ctxtGrDef, |
| 13959 | (xmlSchemaTypePtr) gr->subtypes); |
| 13960 | if (circ != NULL) |
| 13961 | return (circ); |
| 13962 | } |
| 13963 | |
| 13964 | } |
| 13965 | gr = gr->next; |
| 13966 | } |
| 13967 | return (NULL); |
| 13968 | } |
| 13969 | |
| 13970 | /** |
| 13971 | * xmlSchemaCheckGroupDefCircular: |
| 13972 | * attrGr: the model group definition |
| 13973 | * @ctxt: the parser context |
| 13974 | * @name: the name |
| 13975 | * |
| 13976 | * Checks for circular references to model group definitions. |
| 13977 | */ |
| 13978 | static void |
| 13979 | xmlSchemaCheckGroupDefCircular(xmlSchemaTypePtr modelGrDef, |
| 13980 | xmlSchemaParserCtxtPtr ctxt, |
| 13981 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 13982 | { |
| 13983 | /* |
| 13984 | * Schema Component Constraint: Model Group Correct |
| 13985 | * 2 Circular groups are disallowed. That is, within the {particles} |
| 13986 | * of a group there must not be at any depth a particle whose {term} |
| 13987 | * is the group itself. |
| 13988 | */ |
| 13989 | /* |
| 13990 | * NOTE: "gr->subtypes" holds the referenced group. |
| 13991 | */ |
| 13992 | if ((modelGrDef->type != XML_SCHEMA_TYPE_GROUP) || |
| 13993 | ((modelGrDef->flags & XML_SCHEMAS_TYPE_GLOBAL) == 0) || |
| 13994 | (modelGrDef->subtypes == NULL)) |
| 13995 | return; |
| 13996 | else { |
| 13997 | xmlSchemaTypePtr circ; |
| 13998 | |
| 13999 | circ = xmlSchemaGetCircModelGrDefRef(modelGrDef, modelGrDef->subtypes); |
| 14000 | if (circ != NULL) { |
| 14001 | /* |
| 14002 | * TODO: Report the referenced attr group as QName. |
| 14003 | */ |
| 14004 | xmlSchemaPCustomErr(ctxt, |
| 14005 | XML_SCHEMAP_MG_PROPS_CORRECT_2, |
| 14006 | NULL, NULL, circ->node, |
| 14007 | "Circular reference to the model group definition '%s' " |
| 14008 | "defined", modelGrDef->name); |
| 14009 | /* |
| 14010 | * NOTE: We will cut the reference to avoid further |
| 14011 | * confusion of the processor. |
| 14012 | * TODO: SPEC: Does the spec define how to process here? |
| 14013 | */ |
| 14014 | circ->subtypes = NULL; |
| 14015 | } |
| 14016 | } |
| 14017 | } |
| 14018 | |
| 14019 | |
| 14020 | /** |
| 14021 | * xmlSchemaGetCircAttrGrRef: |
| 14022 | * @ctxtGr: the searched attribute group |
| 14023 | * @attr: the current attribute list to be processed |
| 14024 | * |
| 14025 | * This one is intended to be used by |
| 14026 | * xmlSchemaCheckSRCAttributeGroupCircular only. |
| 14027 | * |
| 14028 | * Returns the circular attribute grou reference, otherwise NULL. |
| 14029 | */ |
| 14030 | static xmlSchemaAttributeGroupPtr |
| 14031 | xmlSchemaGetCircAttrGrRef(xmlSchemaAttributeGroupPtr ctxtGr, |
| 14032 | xmlSchemaAttributePtr attr) |
| 14033 | { |
| 14034 | xmlSchemaAttributeGroupPtr circ = NULL, gr; |
| 14035 | int marked; |
| 14036 | /* |
| 14037 | * We will search for an attribute group reference which |
| 14038 | * references the context attribute group. |
| 14039 | */ |
| 14040 | while (attr != NULL) { |
| 14041 | marked = 0; |
| 14042 | if (attr->type == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) { |
| 14043 | gr = (xmlSchemaAttributeGroupPtr) attr; |
| 14044 | if (gr->refItem != NULL) { |
| 14045 | if (gr->refItem == ctxtGr) |
| 14046 | return (gr); |
| 14047 | else if (gr->refItem->flags & |
| 14048 | XML_SCHEMAS_ATTRGROUP_MARKED) { |
| 14049 | attr = attr->next; |
| 14050 | continue; |
| 14051 | } else { |
| 14052 | /* |
| 14053 | * Mark as visited to avoid infinite recursion on |
| 14054 | * circular references not yet examined. |
| 14055 | */ |
| 14056 | gr->refItem->flags |= XML_SCHEMAS_ATTRGROUP_MARKED; |
| 14057 | marked = 1; |
| 14058 | } |
| 14059 | } |
| 14060 | if (gr->attributes != NULL) |
| 14061 | circ = xmlSchemaGetCircAttrGrRef(ctxtGr, gr->attributes); |
| 14062 | /* |
| 14063 | * Unmark the visited group's attributes. |
| 14064 | */ |
| 14065 | if (marked) |
| 14066 | gr->refItem->flags ^= XML_SCHEMAS_ATTRGROUP_MARKED; |
| 14067 | if (circ != NULL) |
| 14068 | return (circ); |
| 14069 | } |
| 14070 | attr = attr->next; |
| 14071 | } |
| 14072 | return (NULL); |
| 14073 | } |
| 14074 | |
| 14075 | /** |
| 14076 | * xmlSchemaCheckSRCAttributeGroupCircular: |
| 14077 | * attrGr: the attribute group definition |
| 14078 | * @ctxt: the parser context |
| 14079 | * @name: the name |
| 14080 | * |
| 14081 | * Checks for circular references of attribute groups. |
| 14082 | */ |
| 14083 | static void |
| 14084 | xmlSchemaCheckAttributeGroupCircular(xmlSchemaAttributeGroupPtr attrGr, |
| 14085 | xmlSchemaParserCtxtPtr ctxt, |
| 14086 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 14087 | { |
| 14088 | /* |
| 14089 | * Schema Representation Constraint: |
| 14090 | * Attribute Group Definition Representation OK |
| 14091 | * 3 Circular group reference is disallowed outside <redefine>. |
| 14092 | * That is, unless this element information item's parent is |
| 14093 | * <redefine>, then among the [children], if any, there must |
| 14094 | * not be an <attributeGroup> with ref [attribute] which resolves |
| 14095 | * to the component corresponding to this <attributeGroup>. Indirect |
| 14096 | * circularity is also ruled out. That is, when QName resolution |
| 14097 | * (Schema Document) (§3.15.3) is applied to a ·QName· arising from |
| 14098 | * any <attributeGroup>s with a ref [attribute] among the [children], |
| 14099 | * it must not be the case that a ·QName· is encountered at any depth |
| 14100 | * which resolves to the component corresponding to this <attributeGroup>. |
| 14101 | */ |
| 14102 | /* |
| 14103 | * Only global components can be referenced. |
| 14104 | */ |
| 14105 | if (((attrGr->flags & XML_SCHEMAS_ATTRGROUP_GLOBAL) == 0) || |
| 14106 | (attrGr->attributes == NULL)) |
| 14107 | return; |
| 14108 | else { |
| 14109 | xmlSchemaAttributeGroupPtr circ; |
| 14110 | |
| 14111 | circ = xmlSchemaGetCircAttrGrRef(attrGr, attrGr->attributes); |
| 14112 | if (circ != NULL) { |
| 14113 | /* |
| 14114 | * TODO: Report the referenced attr group as QName. |
| 14115 | */ |
| 14116 | xmlSchemaPCustomErr(ctxt, |
| 14117 | XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_3, |
| 14118 | NULL, NULL, circ->node, |
| 14119 | "Circular reference to the attribute group '%s' " |
| 14120 | "defined", attrGr->name); |
| 14121 | /* |
| 14122 | * NOTE: We will cut the reference to avoid further |
| 14123 | * confusion of the processor. |
| 14124 | * BADSPEC: The spec should define how to process in this case. |
| 14125 | */ |
| 14126 | circ->attributes = NULL; |
| 14127 | circ->refItem = NULL; |
| 14128 | } |
| 14129 | } |
| 14130 | } |
| 14131 | |
| 14132 | /** |
Daniel Veillard | 13e04c6 | 2002-04-23 17:51:29 +0000 | [diff] [blame] | 14133 | * xmlSchemaAttrGrpFixup: |
| 14134 | * @attrgrpDecl: the schema attribute definition |
| 14135 | * @ctxt: the schema parser context |
| 14136 | * @name: the attribute name |
| 14137 | * |
| 14138 | * Fixes finish doing the computations on the attributes definitions |
| 14139 | */ |
| 14140 | static void |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14141 | xmlSchemaAttrGrpFixup(xmlSchemaAttributeGroupPtr attrgrp, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14142 | xmlSchemaParserCtxtPtr ctxt, const xmlChar * name) |
Daniel Veillard | 13e04c6 | 2002-04-23 17:51:29 +0000 | [diff] [blame] | 14143 | { |
| 14144 | if (name == NULL) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14145 | name = attrgrp->name; |
| 14146 | if (attrgrp->attributes != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14147 | return; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14148 | if (attrgrp->ref != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14149 | xmlSchemaAttributeGroupPtr ref; |
Daniel Veillard | 13e04c6 | 2002-04-23 17:51:29 +0000 | [diff] [blame] | 14150 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14151 | ref = xmlSchemaGetAttributeGroup(ctxt->schema, attrgrp->ref, |
| 14152 | attrgrp->refNs); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14153 | if (ref == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14154 | xmlSchemaPResCompAttrErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14155 | XML_SCHEMAP_SRC_RESOLVE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14156 | NULL, (xmlSchemaTypePtr) attrgrp, attrgrp->node, |
| 14157 | "ref", attrgrp->ref, attrgrp->refNs, |
| 14158 | XML_SCHEMA_TYPE_ATTRIBUTEGROUP, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14159 | return; |
| 14160 | } |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 14161 | attrgrp->refItem = ref; |
| 14162 | /* |
| 14163 | * Check for self reference! |
| 14164 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14165 | xmlSchemaAttrGrpFixup(ref, ctxt, NULL); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14166 | attrgrp->attributes = ref->attributes; |
| 14167 | attrgrp->attributeWildcard = ref->attributeWildcard; |
| 14168 | } |
Daniel Veillard | 13e04c6 | 2002-04-23 17:51:29 +0000 | [diff] [blame] | 14169 | } |
| 14170 | |
| 14171 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14172 | * xmlSchemaAttrCheckValConstr: |
| 14173 | * @item: an schema attribute declaration/use |
| 14174 | * @ctxt: a schema parser context |
| 14175 | * @name: the name of the attribute |
| 14176 | * |
| 14177 | * Validates the value constraints of an attribute declaration/use. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14178 | * |
| 14179 | * Fixes finish doing the computations on the attributes definitions |
| 14180 | */ |
| 14181 | static void |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14182 | xmlSchemaCheckAttrValConstr(xmlSchemaAttributePtr item, |
| 14183 | xmlSchemaParserCtxtPtr ctxt, |
| 14184 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 14185 | { |
| 14186 | |
| 14187 | /* |
| 14188 | * a-props-correct |
| 14189 | * Schema Component Constraint: Attribute Declaration Properties Correct |
| 14190 | * |
| 14191 | * 2 if there is a {value constraint}, the canonical lexical |
| 14192 | * representation of its value must be ·valid· with respect |
| 14193 | * to the {type definition} as defined in String Valid (§3.14.4). |
| 14194 | */ |
| 14195 | |
| 14196 | if (item->defValue != NULL) { |
| 14197 | int ret; |
| 14198 | xmlNodePtr node; |
| 14199 | xmlSchemaTypePtr type; |
| 14200 | |
| 14201 | if (item->subtypes == NULL) { |
| 14202 | xmlSchemaPErr(ctxt, item->node, |
| 14203 | XML_SCHEMAP_INTERNAL, |
| 14204 | "Internal error: xmlSchemaCheckAttrValConstr, " |
| 14205 | "type is missing... skipping validation of " |
| 14206 | "value constraint", NULL, NULL); |
| 14207 | return; |
| 14208 | } |
| 14209 | |
| 14210 | /* |
| 14211 | * TODO: Try to avoid creating a new context. |
| 14212 | * TODO: This all is not very performant. |
| 14213 | */ |
| 14214 | type = item->subtypes; |
| 14215 | /* |
| 14216 | * Ensure there's validation context. |
| 14217 | */ |
| 14218 | if (ctxt->vctxt == NULL) { |
| 14219 | if (xmlSchemaCreateVCtxtOnPCtxt(ctxt) == -1) { |
| 14220 | xmlSchemaPErr(ctxt, item->node, |
| 14221 | XML_SCHEMAP_INTERNAL, |
| 14222 | "Internal error: xmlSchemaCheckAttrValConstr, " |
| 14223 | "creating a new validation context.\n", |
| 14224 | NULL, NULL); |
| 14225 | return; |
| 14226 | } |
| 14227 | } |
| 14228 | |
| 14229 | if (item->flags & XML_SCHEMAS_ATTR_FIXED) |
| 14230 | node = (xmlNodePtr) xmlHasProp(item->node, BAD_CAST "fixed"); |
| 14231 | else |
| 14232 | node = (xmlNodePtr) xmlHasProp(item->node, BAD_CAST "default"); |
| 14233 | ctxt->vctxt->node = node; |
| 14234 | ctxt->vctxt->cur = NULL; |
| 14235 | /* |
| 14236 | * NOTE: This call does not check the content nodes, |
| 14237 | * since they are not available: |
| 14238 | * facet->node is just the node holding the facet |
| 14239 | * definition, *not* the attribute holding the *value* |
| 14240 | * of the facet. |
| 14241 | */ |
| 14242 | ret = xmlSchemaValidateSimpleTypeValue(ctxt->vctxt, type, |
| 14243 | item->defValue, 0, 1, 1, 0); |
| 14244 | if (ret == 0) { |
| 14245 | /* |
| 14246 | * Store the computed value. |
| 14247 | */ |
| 14248 | item->defVal = ctxt->vctxt->value; |
| 14249 | ctxt->vctxt->value = NULL; |
| 14250 | } else if (ret > 0) { |
| 14251 | if (ctxt != NULL) { |
| 14252 | xmlSchemaPSimpleTypeErr(ctxt, |
| 14253 | XML_SCHEMAP_A_PROPS_CORRECT_2, |
| 14254 | NULL, NULL, node, |
| 14255 | type, NULL, item->defValue, |
| 14256 | NULL, NULL, NULL); |
| 14257 | } |
| 14258 | } else if (ret < 0) { |
| 14259 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, |
| 14260 | NULL, NULL, node, |
| 14261 | "Internal error: xmlSchemaAttrCheckValConstr, " |
| 14262 | "failed to validate the value constraint of the " |
| 14263 | "attribute decl/use against the type '%s'", |
| 14264 | type->name); |
| 14265 | } |
| 14266 | } |
| 14267 | } |
| 14268 | |
| 14269 | #if 0 /* Not used yet. */ |
| 14270 | static int |
| 14271 | xmlSchemaCheckElemPropsCorrect(xmlSchemaParserCtxtPtr ctxt, |
| 14272 | xmlSchemaElementPtr edecl) |
| 14273 | { |
| 14274 | /* |
| 14275 | * TODO: 1 The values of the properties of an element declaration must be as |
| 14276 | * described in the property tableau in The Element Declaration Schema |
| 14277 | * Component (§3.3.1), modulo the impact of Missing Sub-components (§5.3). |
| 14278 | */ |
| 14279 | /* |
| 14280 | * 2 If there is a {value constraint}, the canonical lexical |
| 14281 | * representation of its value must be ·valid· with respect to the {type |
| 14282 | * definition} as defined in Element Default Valid (Immediate) (§3.3.6). |
| 14283 | * |
| 14284 | * NOTE: This is done in xmlSchemaCheckElemValConstr. |
| 14285 | */ |
| 14286 | /* |
| 14287 | * 3 If there is a non-·absent· {substitution group affiliation}, |
| 14288 | * then {scope} must be global. |
| 14289 | * |
| 14290 | * NOTE: This is done in xmlSchemaParseElement. |
| 14291 | * TODO: Move it to this layer here. |
| 14292 | */ |
| 14293 | /* |
| 14294 | * TODO: 4 If there is a {substitution group affiliation}, the {type definition} |
| 14295 | * of the element declaration must be validly derived from the {type |
| 14296 | * definition} of the {substitution group affiliation}, given the value |
| 14297 | * of the {substitution group exclusions} of the {substitution group |
| 14298 | * affiliation}, as defined in Type Derivation OK (Complex) (§3.4.6) |
| 14299 | * (if the {type definition} is complex) or as defined in |
| 14300 | * Type Derivation OK (Simple) (§3.14.6) (if the {type definition} is |
| 14301 | * simple). |
| 14302 | */ |
| 14303 | /* |
| 14304 | * TODO: 5 If the {type definition} or {type definition}'s {content type} |
| 14305 | * is or is derived from ID then there must not be a {value constraint}. |
| 14306 | * Note: The use of ID as a type definition for elements goes beyond |
| 14307 | * XML 1.0, and should be avoided if backwards compatibility is desired |
| 14308 | */ |
| 14309 | /* |
| 14310 | * TODO: 6 Circular substitution groups are disallowed. That is, it must not |
| 14311 | * be possible to return to an element declaration by repeatedly following |
| 14312 | * the {substitution group affiliation} property. |
| 14313 | */ |
| 14314 | } |
| 14315 | #endif |
| 14316 | |
| 14317 | /** |
| 14318 | * xmlSchemaCheckElemValConstr: |
| 14319 | * @item: an schema element declaration/particle |
| 14320 | * @ctxt: a schema parser context |
| 14321 | * @name: the name of the attribute |
| 14322 | * |
| 14323 | * Validates the value constraints of an element declaration. |
| 14324 | * |
| 14325 | * Fixes finish doing the computations on the element declarations. |
| 14326 | */ |
| 14327 | static void |
| 14328 | xmlSchemaCheckElemValConstr(xmlSchemaElementPtr decl, |
| 14329 | xmlSchemaParserCtxtPtr ctxt, |
| 14330 | const xmlChar * name ATTRIBUTE_UNUSED) |
| 14331 | { |
| 14332 | if (decl->value != NULL) { |
| 14333 | int ret; |
| 14334 | xmlNodePtr node = NULL; |
| 14335 | xmlSchemaTypePtr type; |
| 14336 | |
| 14337 | /* |
| 14338 | * 2 If there is a {value constraint}, the canonical lexical |
| 14339 | * representation of its value must be ·valid· with respect to the {type |
| 14340 | * definition} as defined in Element Default Valid (Immediate) (§3.3.6). |
| 14341 | */ |
| 14342 | if (decl->subtypes == NULL) { |
| 14343 | xmlSchemaPErr(ctxt, decl->node, |
| 14344 | XML_SCHEMAP_INTERNAL, |
| 14345 | "Internal error: xmlSchemaCheckElemValConstr, " |
| 14346 | "type is missing... skipping validation of " |
| 14347 | "the value constraint", NULL, NULL); |
| 14348 | return; |
| 14349 | } |
| 14350 | /* |
| 14351 | * Ensure there's a validation context. |
| 14352 | */ |
| 14353 | if (xmlSchemaCreateVCtxtOnPCtxt(ctxt) == -1) |
| 14354 | return; |
| 14355 | |
| 14356 | type = decl->subtypes; |
| 14357 | |
| 14358 | if (decl->node != NULL) { |
| 14359 | if (decl->flags & XML_SCHEMAS_ELEM_FIXED) |
| 14360 | node = (xmlNodePtr) xmlHasProp(decl->node, BAD_CAST "fixed"); |
| 14361 | else |
| 14362 | node = (xmlNodePtr) xmlHasProp(decl->node, BAD_CAST "default"); |
| 14363 | } |
| 14364 | ctxt->vctxt->node = node; |
| 14365 | ctxt->vctxt->cur = NULL; |
| 14366 | ret = xmlSchemaCheckCOSValidDefault(ctxt, ctxt->vctxt, type, decl->value, |
| 14367 | node); |
| 14368 | if (ret == 0) { |
| 14369 | /* |
| 14370 | * Consume the computed value. |
| 14371 | */ |
| 14372 | decl->defVal = ctxt->vctxt->value; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 14373 | ctxt->vctxt->value = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14374 | } else if (ret < 0) { |
| 14375 | xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL, |
| 14376 | NULL, NULL, node, |
| 14377 | "Internal error: xmlSchemaElemCheckValConstr, " |
| 14378 | "failed to validate the value constraint of the " |
| 14379 | "element declaration '%s'", |
| 14380 | decl->name); |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 14381 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14382 | } |
| 14383 | } |
| 14384 | |
| 14385 | /** |
| 14386 | * xmlSchemaAttrFixup: |
| 14387 | * @item: an schema attribute declaration/use. |
| 14388 | * @ctxt: a schema parser context |
| 14389 | * @name: the name of the attribute |
| 14390 | * |
| 14391 | * Fixes finish doing the computations on attribute declarations/uses. |
| 14392 | */ |
| 14393 | static void |
| 14394 | xmlSchemaAttrFixup(xmlSchemaAttributePtr item, |
| 14395 | xmlSchemaParserCtxtPtr ctxt, |
| 14396 | const xmlChar * name ATTRIBUTE_UNUSED) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14397 | { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14398 | /* |
| 14399 | * TODO: If including this is done twice (!) for every attribute. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14400 | * -> Hmm, check if this is still done. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14401 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14402 | /* |
| 14403 | * The simple type definition corresponding to the <simpleType> element |
| 14404 | * information item in the [children], if present, otherwise the simple |
| 14405 | * type definition ·resolved· to by the ·actual value· of the type |
| 14406 | * [attribute], if present, otherwise the ·simple ur-type definition·. |
| 14407 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14408 | if (item->flags & XML_SCHEMAS_ATTR_INTERNAL_RESOLVED) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14409 | return; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14410 | item->flags |= XML_SCHEMAS_ATTR_INTERNAL_RESOLVED; |
| 14411 | if (item->subtypes != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14412 | return; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14413 | if (item->typeName != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14414 | xmlSchemaTypePtr type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14415 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14416 | type = xmlSchemaGetType(ctxt->schema, item->typeName, |
| 14417 | item->typeNs); |
| 14418 | if ((type == NULL) || (! IS_SIMPLE_TYPE(type))) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14419 | xmlSchemaPResCompAttrErr(ctxt, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14420 | XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14421 | NULL, (xmlSchemaTypePtr) item, item->node, |
| 14422 | "type", item->typeName, item->typeNs, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14423 | XML_SCHEMA_TYPE_SIMPLE, NULL); |
| 14424 | } else |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14425 | item->subtypes = type; |
| 14426 | |
| 14427 | } else if (item->ref != NULL) { |
| 14428 | xmlSchemaAttributePtr decl; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14429 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14430 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14431 | * We have an attribute use here; assign the referenced |
| 14432 | * attribute declaration. |
| 14433 | */ |
| 14434 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14435 | * TODO: Evaluate, what errors could occur if the declaration is not |
| 14436 | * found. It might be possible that the "typefixup" might crash if |
| 14437 | * no ref declaration was found. |
| 14438 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14439 | decl = xmlSchemaGetAttribute(ctxt->schema, item->ref, item->refNs); |
| 14440 | if (decl == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14441 | xmlSchemaPResCompAttrErr(ctxt, |
| 14442 | XML_SCHEMAP_SRC_RESOLVE, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14443 | NULL, (xmlSchemaTypePtr) item, item->node, |
| 14444 | "ref", item->ref, item->refNs, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14445 | XML_SCHEMA_TYPE_ATTRIBUTE, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14446 | return; |
| 14447 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14448 | item->refDecl = decl; |
| 14449 | xmlSchemaAttrFixup(decl, ctxt, NULL); |
| 14450 | |
| 14451 | item->subtypes = decl->subtypes; |
| 14452 | /* |
| 14453 | * Attribute Use Correct |
| 14454 | * au-props-correct.2: If the {attribute declaration} has a fixed |
| 14455 | * {value constraint}, then if the attribute use itself has a |
| 14456 | * {value constraint}, it must also be fixed and its value must match |
| 14457 | * that of the {attribute declaration}'s {value constraint}. |
| 14458 | */ |
| 14459 | if ((decl->flags & XML_SCHEMAS_ATTR_FIXED) && |
| 14460 | (item->defValue != NULL)) { |
| 14461 | if (((item->flags & XML_SCHEMAS_ATTR_FIXED) == 0) || |
| 14462 | (!xmlStrEqual(item->defValue, decl->defValue))) { |
| 14463 | xmlSchemaPCustomErr(ctxt, |
| 14464 | XML_SCHEMAP_AU_PROPS_CORRECT_2, |
| 14465 | NULL, NULL, item->node, |
| 14466 | "The value constraint must be fixed " |
| 14467 | "and match the referenced attribute " |
| 14468 | "declarations's value constraint '%s'", |
| 14469 | decl->defValue); |
| 14470 | } |
| 14471 | /* |
| 14472 | * FUTURE: One should change the values of the attr. use |
| 14473 | * if ever validation should be attempted even if the |
| 14474 | * schema itself was not fully valid. |
| 14475 | */ |
| 14476 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 14477 | } else { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14478 | item->subtypes = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 14479 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14480 | } |
| 14481 | |
| 14482 | /** |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 14483 | * xmlSchemaResolveIDCKeyRef: |
| 14484 | * @idc: the identity-constraint definition |
| 14485 | * @ctxt: the schema parser context |
| 14486 | * @name: the attribute name |
| 14487 | * |
| 14488 | * Resolve keyRef references to key/unique IDCs. |
| 14489 | */ |
| 14490 | static void |
| 14491 | xmlSchemaResolveIDCKeyRef(xmlSchemaIDCPtr idc, |
| 14492 | xmlSchemaParserCtxtPtr ctxt, |
Kasimier T. Buchcik | 87250a9 | 2005-01-28 15:59:53 +0000 | [diff] [blame] | 14493 | const xmlChar * name ATTRIBUTE_UNUSED) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 14494 | { |
| 14495 | if (idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) |
| 14496 | return; |
| 14497 | if (idc->ref->name != NULL) { |
| 14498 | idc->ref->item = (xmlSchemaBasicItemPtr) xmlHashLookup2( |
| 14499 | ctxt->schema->idcDef, |
| 14500 | idc->ref->name, |
| 14501 | idc->ref->targetNamespace); |
| 14502 | if (idc->ref->item == NULL) { |
| 14503 | /* |
| 14504 | * TODO: It is actually not an error to fail to resolve. |
| 14505 | */ |
| 14506 | xmlSchemaPResCompAttrErr(ctxt, |
| 14507 | XML_SCHEMAP_SRC_RESOLVE, |
| 14508 | NULL, (xmlSchemaTypePtr) idc, idc->node, |
| 14509 | "refer", idc->ref->name, |
| 14510 | idc->ref->targetNamespace, |
| 14511 | XML_SCHEMA_TYPE_IDC_KEYREF, NULL); |
| 14512 | return; |
| 14513 | } |
| 14514 | } |
| 14515 | } |
| 14516 | |
| 14517 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14518 | * xmlSchemaParse: |
| 14519 | * @ctxt: a schema validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14520 | * |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 14521 | * parse a schema definition resource and build an internal |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14522 | * XML Shema struture which can be used to validate instances. |
| 14523 | * *WARNING* this interface is highly subject to change |
| 14524 | * |
| 14525 | * Returns the internal XML Schema structure built from the resource or |
| 14526 | * NULL in case of error |
| 14527 | */ |
| 14528 | xmlSchemaPtr |
| 14529 | xmlSchemaParse(xmlSchemaParserCtxtPtr ctxt) |
| 14530 | { |
| 14531 | xmlSchemaPtr ret = NULL; |
| 14532 | xmlDocPtr doc; |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 14533 | xmlNodePtr root; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 14534 | int preserve = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14535 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14536 | /* |
| 14537 | * This one is used if the schema to be parsed was specified via |
| 14538 | * the API; i.e. not automatically by the validated instance document. |
| 14539 | */ |
| 14540 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14541 | xmlSchemaInitTypes(); |
| 14542 | |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 14543 | if (ctxt == NULL) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14544 | return (NULL); |
| 14545 | |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 14546 | ctxt->nberrors = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14547 | ctxt->counter = 0; |
| 14548 | ctxt->container = NULL; |
| 14549 | |
| 14550 | /* |
| 14551 | * First step is to parse the input document into an DOM/Infoset |
| 14552 | */ |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 14553 | if (ctxt->URL != NULL) { |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 14554 | doc = xmlReadFile((const char *) ctxt->URL, NULL, |
| 14555 | SCHEMAS_PARSE_OPTIONS); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14556 | if (doc == NULL) { |
| 14557 | xmlSchemaPErr(ctxt, NULL, |
| 14558 | XML_SCHEMAP_FAILED_LOAD, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14559 | "xmlSchemaParse: could not load '%s'.\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14560 | ctxt->URL, NULL); |
| 14561 | return (NULL); |
| 14562 | } |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 14563 | } else if (ctxt->buffer != NULL) { |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 14564 | doc = xmlReadMemory(ctxt->buffer, ctxt->size, NULL, NULL, |
| 14565 | SCHEMAS_PARSE_OPTIONS); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14566 | if (doc == NULL) { |
| 14567 | xmlSchemaPErr(ctxt, NULL, |
| 14568 | XML_SCHEMAP_FAILED_PARSE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14569 | "xmlSchemaParse: could not parse.\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14570 | NULL, NULL); |
| 14571 | return (NULL); |
| 14572 | } |
| 14573 | doc->URL = xmlStrdup(BAD_CAST "in_memory_buffer"); |
Daniel Veillard | 6576528 | 2004-01-08 16:59:30 +0000 | [diff] [blame] | 14574 | ctxt->URL = xmlDictLookup(ctxt->dict, BAD_CAST "in_memory_buffer", -1); |
Daniel Veillard | 9d75150 | 2003-10-29 13:21:47 +0000 | [diff] [blame] | 14575 | } else if (ctxt->doc != NULL) { |
| 14576 | doc = ctxt->doc; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 14577 | preserve = 1; |
Daniel Veillard | 6045c90 | 2002-10-09 21:13:59 +0000 | [diff] [blame] | 14578 | } else { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14579 | xmlSchemaPErr(ctxt, NULL, |
| 14580 | XML_SCHEMAP_NOTHING_TO_PARSE, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14581 | "xmlSchemaParse: could not parse.\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14582 | NULL, NULL); |
| 14583 | return (NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14584 | } |
| 14585 | |
| 14586 | /* |
| 14587 | * Then extract the root and Schema parse it |
| 14588 | */ |
| 14589 | root = xmlDocGetRootElement(doc); |
| 14590 | if (root == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14591 | xmlSchemaPErr(ctxt, (xmlNodePtr) doc, |
| 14592 | XML_SCHEMAP_NOROOT, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14593 | "The schema has no document element.\n", NULL, NULL); |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 14594 | if (!preserve) { |
| 14595 | xmlFreeDoc(doc); |
| 14596 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14597 | return (NULL); |
| 14598 | } |
| 14599 | |
| 14600 | /* |
| 14601 | * Remove all the blank text nodes |
| 14602 | */ |
Daniel Veillard | bd2904b | 2003-11-25 15:38:59 +0000 | [diff] [blame] | 14603 | xmlSchemaCleanupDoc(ctxt, root); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14604 | |
| 14605 | /* |
| 14606 | * Then do the parsing for good |
| 14607 | */ |
| 14608 | ret = xmlSchemaParseSchema(ctxt, root); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 14609 | if (ret == NULL) { |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 14610 | if (!preserve) { |
| 14611 | xmlFreeDoc(doc); |
| 14612 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14613 | return (NULL); |
Daniel Veillard | 1d91386 | 2003-11-21 00:28:39 +0000 | [diff] [blame] | 14614 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14615 | ret->doc = doc; |
Daniel Veillard | dda22c1 | 2004-01-24 08:31:30 +0000 | [diff] [blame] | 14616 | ret->preserve = preserve; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14617 | ctxt->schema = ret; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14618 | ctxt->ctxtType = NULL; |
| 14619 | ctxt->parentItem = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14620 | /* |
Daniel Veillard | f2a1283 | 2003-11-24 13:04:35 +0000 | [diff] [blame] | 14621 | * Then fixup all attributes declarations |
| 14622 | */ |
| 14623 | xmlHashScan(ret->attrDecl, (xmlHashScanner) xmlSchemaAttrFixup, ctxt); |
| 14624 | |
| 14625 | /* |
| 14626 | * Then fixup all attributes group declarations |
| 14627 | */ |
| 14628 | xmlHashScan(ret->attrgrpDecl, (xmlHashScanner) xmlSchemaAttrGrpFixup, |
| 14629 | ctxt); |
| 14630 | |
| 14631 | /* |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 14632 | * Resolve identity-constraint keyRefs. |
| 14633 | */ |
| 14634 | xmlHashScan(ret->idcDef, (xmlHashScanner) xmlSchemaResolveIDCKeyRef, ctxt); |
| 14635 | |
| 14636 | /* |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 14637 | * Check attribute groups for circular references. |
| 14638 | */ |
| 14639 | xmlHashScan(ret->attrgrpDecl, (xmlHashScanner) |
| 14640 | xmlSchemaCheckAttributeGroupCircular, ctxt); |
| 14641 | |
| 14642 | /* |
| 14643 | * Then fixup all model group definitions. |
| 14644 | */ |
| 14645 | xmlHashScan(ret->groupDecl, (xmlHashScanner) xmlSchemaGroupDefFixup, ctxt); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14646 | |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 14647 | /* |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14648 | * Then fixup all types properties |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14649 | */ |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 14650 | xmlHashScan(ret->typeDecl, (xmlHashScanner) xmlSchemaTypeFixup, ctxt); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14651 | |
| 14652 | /* |
| 14653 | * Then fix references of element declaration; apply constraints. |
| 14654 | */ |
| 14655 | xmlHashScanFull(ret->elemDecl, |
| 14656 | (xmlHashScannerFull) xmlSchemaRefFixupCallback, ctxt); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14657 | |
Kasimier T. Buchcik | 383434b | 2004-09-03 18:55:35 +0000 | [diff] [blame] | 14658 | /* |
| 14659 | * Check model groups defnitions for circular references. |
| 14660 | */ |
| 14661 | xmlHashScan(ret->groupDecl, (xmlHashScanner) |
| 14662 | xmlSchemaCheckGroupDefCircular, ctxt); |
| 14663 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14664 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14665 | * Then build the content model for all complex types |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14666 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14667 | xmlHashScan(ret->typeDecl, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14668 | (xmlHashScanner) xmlSchemaBuildContentModel, ctxt); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14669 | |
| 14670 | /* |
| 14671 | * Then check the defaults part of the type like facets values |
| 14672 | */ |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 14673 | /* OLD: xmlHashScan(ret->typeDecl, (xmlHashScanner) xmlSchemaCheckDefaults, ctxt); */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14674 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 14675 | /* |
| 14676 | * Validate the value constraint of attribute declarations/uses. |
| 14677 | */ |
| 14678 | xmlHashScan(ret->attrDecl, (xmlHashScanner) xmlSchemaCheckAttrValConstr, ctxt); |
| 14679 | |
| 14680 | /* |
| 14681 | * Validate the value constraint of element declarations. |
| 14682 | */ |
| 14683 | xmlHashScan(ret->elemDecl, (xmlHashScanner) xmlSchemaCheckElemValConstr, ctxt); |
| 14684 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14685 | |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 14686 | if (ctxt->nberrors != 0) { |
| 14687 | xmlSchemaFree(ret); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14688 | ret = NULL; |
Daniel Veillard | 75bb3bb | 2003-05-12 15:25:56 +0000 | [diff] [blame] | 14689 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14690 | return (ret); |
| 14691 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14692 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14693 | /** |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 14694 | * xmlSchemaSetParserErrors: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14695 | * @ctxt: a schema validation context |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 14696 | * @err: the error callback |
| 14697 | * @warn: the warning callback |
| 14698 | * @ctx: contextual data for the callbacks |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14699 | * |
Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 14700 | * Set the callback functions used to handle errors for a validation context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14701 | */ |
| 14702 | void |
| 14703 | xmlSchemaSetParserErrors(xmlSchemaParserCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14704 | xmlSchemaValidityErrorFunc err, |
| 14705 | xmlSchemaValidityWarningFunc warn, void *ctx) |
| 14706 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14707 | if (ctxt == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14708 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 14709 | ctxt->error = err; |
| 14710 | ctxt->warning = warn; |
| 14711 | ctxt->userData = ctx; |
| 14712 | } |
| 14713 | |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14714 | /** |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 14715 | * xmlSchemaGetParserErrors: |
| 14716 | * @ctxt: a XMl-Schema parser context |
| 14717 | * @err: the error callback result |
| 14718 | * @warn: the warning callback result |
| 14719 | * @ctx: contextual data for the callbacks result |
| 14720 | * |
| 14721 | * Get the callback information used to handle errors for a parser context |
| 14722 | * |
| 14723 | * Returns -1 in case of failure, 0 otherwise |
| 14724 | */ |
| 14725 | int |
| 14726 | xmlSchemaGetParserErrors(xmlSchemaParserCtxtPtr ctxt, |
| 14727 | xmlSchemaValidityErrorFunc * err, |
| 14728 | xmlSchemaValidityWarningFunc * warn, void **ctx) |
| 14729 | { |
| 14730 | if (ctxt == NULL) |
| 14731 | return(-1); |
| 14732 | if (err != NULL) |
| 14733 | *err = ctxt->error; |
| 14734 | if (warn != NULL) |
| 14735 | *warn = ctxt->warning; |
| 14736 | if (ctx != NULL) |
| 14737 | *ctx = ctxt->userData; |
| 14738 | return(0); |
| 14739 | } |
| 14740 | |
| 14741 | /** |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14742 | * xmlSchemaFacetTypeToString: |
| 14743 | * @type: the facet type |
| 14744 | * |
| 14745 | * Convert the xmlSchemaTypeType to a char string. |
| 14746 | * |
| 14747 | * Returns the char string representation of the facet type if the |
| 14748 | * type is a facet and an "Internal Error" string otherwise. |
| 14749 | */ |
| 14750 | static const char * |
| 14751 | xmlSchemaFacetTypeToString(xmlSchemaTypeType type) |
| 14752 | { |
| 14753 | switch (type) { |
| 14754 | case XML_SCHEMA_FACET_PATTERN: |
| 14755 | return ("pattern"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14756 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14757 | return ("maxExclusive"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14758 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14759 | return ("maxInclusive"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14760 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14761 | return ("minExclusive"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14762 | case XML_SCHEMA_FACET_MININCLUSIVE: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14763 | return ("minInclusive"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14764 | case XML_SCHEMA_FACET_WHITESPACE: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14765 | return ("whiteSpace"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14766 | case XML_SCHEMA_FACET_ENUMERATION: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14767 | return ("enumeration"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14768 | case XML_SCHEMA_FACET_LENGTH: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14769 | return ("length"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14770 | case XML_SCHEMA_FACET_MAXLENGTH: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14771 | return ("maxLength"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14772 | case XML_SCHEMA_FACET_MINLENGTH: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14773 | return ("minLength"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14774 | case XML_SCHEMA_FACET_TOTALDIGITS: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14775 | return ("totalDigits"); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 14776 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14777 | return ("fractionDigits"); |
| 14778 | default: |
| 14779 | break; |
| 14780 | } |
| 14781 | return ("Internal Error"); |
| 14782 | } |
| 14783 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14784 | static int |
| 14785 | xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type) |
| 14786 | { |
| 14787 | xmlSchemaTypePtr anc; |
| 14788 | |
| 14789 | /* |
| 14790 | * The normalization type can be changed only for types which are derived |
| 14791 | * from xsd:string. |
| 14792 | */ |
| 14793 | if (type->type == XML_SCHEMA_TYPE_BASIC) { |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 14794 | if (type->builtInType == XML_SCHEMAS_STRING) |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 14795 | return(XML_SCHEMAS_FACET_PRESERVE); |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 14796 | else if (type->builtInType == XML_SCHEMAS_NORMSTRING) |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 14797 | return(XML_SCHEMAS_FACET_REPLACE); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14798 | else { |
| 14799 | /* |
| 14800 | * For all ·atomic· datatypes other than string (and types ·derived· |
| 14801 | * by ·restriction· from it) the value of whiteSpace is fixed to |
| 14802 | * collapse |
| 14803 | */ |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 14804 | return(XML_SCHEMAS_FACET_COLLAPSE); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14805 | } |
| 14806 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 14807 | /* |
| 14808 | * For list types the facet "whiteSpace" is fixed to "collapse". |
| 14809 | */ |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 14810 | return (XML_SCHEMAS_FACET_COLLAPSE); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14811 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 14812 | return (XML_SCHEMAS_FACET_UNKNOWN); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14813 | } else if (type->facetSet != NULL) { |
| 14814 | xmlSchemaTypePtr anyST; |
| 14815 | xmlSchemaFacetLinkPtr lin; |
| 14816 | |
| 14817 | /* |
| 14818 | * Atomic types. |
| 14819 | */ |
| 14820 | anyST = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE); |
| 14821 | anc = type->baseType; |
| 14822 | do { |
| 14823 | /* |
| 14824 | * For all ·atomic· datatypes other than string (and types ·derived· |
| 14825 | * by ·restriction· from it) the value of whiteSpace is fixed to |
| 14826 | * collapse |
| 14827 | */ |
| 14828 | if ((anc->type == XML_SCHEMA_TYPE_BASIC) && |
| 14829 | (anc->builtInType == XML_SCHEMAS_STRING)) { |
| 14830 | |
| 14831 | lin = type->facetSet; |
| 14832 | do { |
| 14833 | if (lin->facet->type == XML_SCHEMA_FACET_WHITESPACE) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 14834 | return(lin->facet->whitespace); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14835 | break; |
| 14836 | } |
| 14837 | lin = lin->next; |
| 14838 | } while (lin != NULL); |
| 14839 | break; |
| 14840 | } |
| 14841 | anc = anc->baseType; |
| 14842 | } while (anc != anyST); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 14843 | return (XML_SCHEMAS_FACET_COLLAPSE); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14844 | } |
| 14845 | return (-1); |
| 14846 | } |
| 14847 | |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14848 | /** |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 14849 | * xmlSchemaValidateFacetsInternal: |
| 14850 | * @ctxt: a schema validation context |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14851 | * @type: the type holding the facets |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 14852 | * @facets: the list of facets to check |
| 14853 | * @value: the lexical repr of the value to validate |
| 14854 | * @val: the precomputed value |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 14855 | * @fireErrors: if 0, only internal errors will be fired; |
| 14856 | * otherwise all errors will be fired. |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 14857 | * |
| 14858 | * Check a value against all facet conditions |
| 14859 | * |
| 14860 | * Returns 0 if the element is schemas valid, a positive error code |
| 14861 | * number otherwise and -1 in case of internal or API error. |
| 14862 | */ |
| 14863 | static int |
| 14864 | xmlSchemaValidateFacetsInternal(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14865 | xmlSchemaTypePtr type, |
| 14866 | const xmlChar * value, |
| 14867 | unsigned long length, |
| 14868 | int fireErrors) |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 14869 | { |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14870 | int ret = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14871 | xmlNodePtr node; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14872 | xmlSchemaTypePtr biType; /* The build-in type. */ |
| 14873 | xmlSchemaTypePtr tmpType; |
| 14874 | xmlSchemaFacetLinkPtr facetLink; |
Daniel Veillard | c7e3cc4 | 2004-09-28 12:33:52 +0000 | [diff] [blame] | 14875 | int retFacet; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14876 | xmlSchemaFacetPtr facet; |
| 14877 | unsigned long len = 0; |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14878 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14879 | #ifdef DEBUG_UNION_VALIDATION |
| 14880 | printf("Facets of type: '%s'\n", (const char *) type->name); |
| 14881 | printf(" fireErrors: %d\n", fireErrors); |
| 14882 | #endif |
| 14883 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14884 | node = ctxt->node; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14885 | /* |
| 14886 | * NOTE: Do not jump away, if the facetSet of the given type is |
| 14887 | * empty: until now, "pattern" facets of the *base types* need to |
| 14888 | * be checked as well. |
| 14889 | */ |
| 14890 | biType = type->baseType; |
| 14891 | while ((biType != NULL) && (biType->type != XML_SCHEMA_TYPE_BASIC)) |
| 14892 | biType = biType->baseType; |
| 14893 | if (biType == NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14894 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14895 | "Internal error: xmlSchemaValidateFacetsInternal, " |
| 14896 | "the base type axis of the given type '%s' does not resolve to " |
| 14897 | "a built-in type.\n", |
| 14898 | type->name, NULL); |
| 14899 | return (-1); |
| 14900 | } |
| 14901 | |
| 14902 | if (type->facetSet != NULL) { |
| 14903 | facetLink = type->facetSet; |
| 14904 | while (facetLink != NULL) { |
| 14905 | facet = facetLink->facet; |
| 14906 | /* |
| 14907 | * Skip the pattern "whiteSpace": it is used to |
| 14908 | * format the character content beforehand. |
| 14909 | */ |
| 14910 | switch (facet->type) { |
| 14911 | case XML_SCHEMA_FACET_WHITESPACE: |
| 14912 | case XML_SCHEMA_FACET_PATTERN: |
| 14913 | case XML_SCHEMA_FACET_ENUMERATION: |
| 14914 | break; |
| 14915 | case XML_SCHEMA_FACET_LENGTH: |
| 14916 | case XML_SCHEMA_FACET_MINLENGTH: |
| 14917 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 14918 | if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 14919 | ret = xmlSchemaValidateListSimpleTypeFacet(facet, |
| 14920 | value, length, 0); |
| 14921 | len = length; |
| 14922 | } else |
| 14923 | ret = xmlSchemaValidateLengthFacet(biType, facet, |
| 14924 | value, ctxt->value, &len); |
| 14925 | break; |
| 14926 | default: |
| 14927 | ret = xmlSchemaValidateFacet(biType, facet, value, |
| 14928 | ctxt->value); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 14929 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14930 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14931 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14932 | "Internal error: xmlSchemaValidateFacetsInternal, " |
| 14933 | "validating facet of type '%s'.\n", |
| 14934 | type->name, NULL); |
| 14935 | break; |
| 14936 | } else if ((ret > 0) && (fireErrors)) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14937 | xmlSchemaVFacetErr(ctxt, ret, node, value, len, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14938 | type, facet, NULL, NULL, NULL, NULL); |
| 14939 | } |
| 14940 | |
| 14941 | facetLink = facetLink->next; |
| 14942 | } |
| 14943 | if (ret >= 0) { |
| 14944 | /* |
| 14945 | * Process enumerations. |
| 14946 | */ |
| 14947 | retFacet = 0; |
| 14948 | facetLink = type->facetSet; |
| 14949 | while (facetLink != NULL) { |
| 14950 | if (facetLink->facet->type == XML_SCHEMA_FACET_ENUMERATION) { |
| 14951 | retFacet = xmlSchemaValidateFacet(biType, facetLink->facet, |
| 14952 | value, ctxt->value); |
| 14953 | if (retFacet <= 0) |
| 14954 | break; |
| 14955 | } |
| 14956 | facetLink = facetLink->next; |
| 14957 | } |
| 14958 | if (retFacet > 0) { |
| 14959 | ret = XML_SCHEMAV_CVC_ENUMERATION_VALID; |
| 14960 | if (fireErrors) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14961 | xmlSchemaVFacetErr(ctxt, ret, node, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14962 | value, 0, type, NULL, NULL, NULL, NULL, NULL); |
| 14963 | } else if (retFacet < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14964 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14965 | "Internal error: xmlSchemaValidateFacetsInternal, " |
| 14966 | "validating facet of type '%s'.\n", |
| 14967 | BAD_CAST "enumeration", NULL); |
| 14968 | ret = -1; |
| 14969 | } |
| 14970 | } |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 14971 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14972 | if (ret >= 0) { |
| 14973 | /* |
| 14974 | * Process patters. Pattern facets are ORed at type level |
| 14975 | * and ANDed if derived. Walk the base type axis. |
| 14976 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14977 | tmpType = type; |
| 14978 | facet = NULL; |
| 14979 | do { |
| 14980 | retFacet = 0; |
| 14981 | for (facetLink = tmpType->facetSet; facetLink != NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14982 | facetLink = facetLink->next) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14983 | if (facetLink->facet->type != XML_SCHEMA_FACET_PATTERN) |
| 14984 | continue; |
| 14985 | retFacet = xmlSchemaValidateFacet(biType, facetLink->facet, |
| 14986 | value, ctxt->value); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14987 | if (retFacet == 0) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14988 | break; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 14989 | else if (retFacet < 0) { |
| 14990 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
| 14991 | "Internal error: xmlSchemaValidateFacetsInternal, " |
| 14992 | "validating 'pattern' facet '%s' of type '%s'.\n", |
| 14993 | facetLink->facet->value, tmpType->name); |
| 14994 | ret = -1; |
| 14995 | break; |
| 14996 | } else |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 14997 | /* Save the last non-validating facet. */ |
| 14998 | facet = facetLink->facet; |
| 14999 | } |
| 15000 | if (retFacet != 0) |
| 15001 | break; |
| 15002 | tmpType = tmpType->baseType; |
| 15003 | } while ((tmpType != NULL) && (tmpType->type != XML_SCHEMA_TYPE_BASIC)); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15004 | if (retFacet > 0) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15005 | ret = XML_SCHEMAV_CVC_PATTERN_VALID; |
| 15006 | if (fireErrors) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15007 | xmlSchemaVFacetErr(ctxt, ret, node, value, 0, type, facet, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15008 | NULL, NULL, NULL, NULL); |
| 15009 | } |
| 15010 | } |
| 15011 | } |
| 15012 | |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 15013 | return (ret); |
| 15014 | } |
| 15015 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15016 | /************************************************************************ |
| 15017 | * * |
| 15018 | * Simple type validation * |
| 15019 | * * |
| 15020 | ************************************************************************/ |
Daniel Veillard | 377e1a9 | 2004-04-16 16:30:05 +0000 | [diff] [blame] | 15021 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15022 | |
| 15023 | /************************************************************************ |
| 15024 | * * |
| 15025 | * DOM Validation code * |
| 15026 | * * |
| 15027 | ************************************************************************/ |
| 15028 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15029 | static int xmlSchemaValidateAttributes(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15030 | xmlNodePtr elem, |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15031 | xmlSchemaTypePtr type); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15032 | static int xmlSchemaValidateElementByType(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15033 | xmlSchemaTypePtr type, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 15034 | int isNil, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15035 | int valSimpleContent); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15036 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15037 | static void xmlSchemaBeginElement(xmlSchemaValidCtxtPtr vctxt); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 15038 | static int xmlSchemaEndElement(xmlSchemaValidCtxtPtr vctxt); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15039 | |
| 15040 | #ifdef ELEM_INFO_ENABLED |
| 15041 | /** |
| 15042 | * xmlSchemaGetFreshElemInfo: |
| 15043 | * @vctxt: the schema validation context |
| 15044 | * |
| 15045 | * Creates/reuses and initializes the element info item for |
| 15046 | * the currect tree depth. |
| 15047 | * |
| 15048 | * Returns the element info item or NULL on API or internal errors. |
| 15049 | */ |
| 15050 | static xmlSchemaElemInfoPtr |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 15051 | xmlSchemaGetFreshElemInfo(xmlSchemaValidCtxtPtr vctxt, |
| 15052 | int depth) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15053 | { |
| 15054 | xmlSchemaElemInfoPtr info = NULL; |
| 15055 | |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 15056 | if (depth > vctxt->sizeElemInfos) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15057 | xmlSchemaVErr(vctxt, NULL, XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 15058 | "Internal error: xmlSchemaGetFreshElemInfo, " |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15059 | "an inconsistent depth encountered.\n", |
| 15060 | NULL, NULL); |
| 15061 | return (NULL); |
| 15062 | } |
| 15063 | if (vctxt->elemInfos == NULL) { |
| 15064 | vctxt->elemInfos = (xmlSchemaElemInfoPtr *) |
| 15065 | xmlMalloc(10 * sizeof(xmlSchemaElemInfoPtr)); |
| 15066 | if (vctxt->elemInfos == NULL) { |
| 15067 | xmlSchemaVErrMemory(vctxt, |
| 15068 | "allocating the element info array", NULL); |
| 15069 | return (NULL); |
| 15070 | } |
| 15071 | memset(vctxt->elemInfos, 0, 10 * sizeof(xmlSchemaElemInfoPtr)); |
| 15072 | vctxt->sizeElemInfos = 10; |
| 15073 | } else if (vctxt->sizeElemInfos == vctxt->depth) { |
| 15074 | int i = vctxt->sizeElemInfos; |
| 15075 | |
| 15076 | vctxt->sizeElemInfos *= 2; |
| 15077 | vctxt->elemInfos = (xmlSchemaElemInfoPtr *) |
| 15078 | xmlRealloc(vctxt->elemInfos, vctxt->sizeElemInfos * |
| 15079 | sizeof(xmlSchemaElemInfoPtr)); |
| 15080 | if (vctxt->elemInfos == NULL) { |
| 15081 | xmlSchemaVErrMemory(vctxt, |
| 15082 | "re-allocating the element info array", NULL); |
| 15083 | return (NULL); |
| 15084 | } |
| 15085 | /* |
| 15086 | * We need the new memory to be NULLed. |
| 15087 | * TODO: Use memset instead? |
| 15088 | */ |
| 15089 | for (; i < vctxt->sizeElemInfos; i++) |
| 15090 | vctxt->elemInfos[i] = NULL; |
| 15091 | } else |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 15092 | info = vctxt->elemInfos[depth]; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15093 | |
| 15094 | if (info == NULL) { |
| 15095 | info = (xmlSchemaElemInfoPtr) |
| 15096 | xmlMalloc(sizeof(xmlSchemaElemInfo)); |
| 15097 | if (info == NULL) { |
| 15098 | xmlSchemaVErrMemory(vctxt, |
| 15099 | "allocating an element info", NULL); |
| 15100 | return (NULL); |
| 15101 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 15102 | vctxt->elemInfos[depth] = info; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15103 | } |
| 15104 | memset(info, 0, sizeof(xmlSchemaElemInfo)); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 15105 | info->depth = depth; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15106 | |
| 15107 | return (info); |
| 15108 | } |
| 15109 | #endif /* ELEM_INFO_ENABLED */ |
| 15110 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15111 | |
| 15112 | /** |
| 15113 | * xmlSchemaFreeAttrStates: |
| 15114 | * @state: a list of attribute states |
| 15115 | * |
| 15116 | * Free the given list of attribute states |
| 15117 | * |
| 15118 | */ |
| 15119 | static void |
| 15120 | xmlSchemaFreeAttributeStates(xmlSchemaAttrStatePtr state) |
| 15121 | { |
| 15122 | xmlSchemaAttrStatePtr tmp; |
| 15123 | while (state != NULL) { |
| 15124 | tmp = state; |
| 15125 | state = state->next; |
| 15126 | xmlFree(tmp); |
| 15127 | } |
| 15128 | } |
| 15129 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15130 | /** |
| 15131 | * xmlSchemaRegisterAttributes: |
| 15132 | * @ctxt: a schema validation context |
| 15133 | * @attrs: a list of attributes |
| 15134 | * |
| 15135 | * Register the list of attributes as the set to be validated on that element |
| 15136 | * |
| 15137 | * Returns -1 in case of error, 0 otherwise |
| 15138 | */ |
| 15139 | static int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15140 | xmlSchemaRegisterAttributes(xmlSchemaValidCtxtPtr ctxt, xmlAttrPtr attrs) |
| 15141 | { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15142 | xmlSchemaAttrStatePtr tmp; |
| 15143 | |
| 15144 | ctxt->attr = NULL; |
| 15145 | ctxt->attrTop = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15146 | while (attrs != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15147 | if ((attrs->ns != NULL) && |
| 15148 | (xmlStrEqual(attrs->ns->href, xmlSchemaInstanceNs))) { |
| 15149 | attrs = attrs->next; |
| 15150 | continue; |
| 15151 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15152 | tmp = (xmlSchemaAttrStatePtr) |
| 15153 | xmlMalloc(sizeof(xmlSchemaAttrState)); |
| 15154 | if (tmp == NULL) { |
| 15155 | xmlSchemaVErrMemory(ctxt, "registering attributes", NULL); |
| 15156 | return (-1); |
| 15157 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15158 | tmp->attr = attrs; |
| 15159 | tmp->state = XML_SCHEMAS_ATTR_UNKNOWN; |
| 15160 | tmp->next = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15161 | tmp->decl = NULL; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15162 | if (ctxt->attr == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15163 | ctxt->attr = tmp; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 15164 | else |
| 15165 | ctxt->attrTop->next = tmp; |
| 15166 | ctxt->attrTop = tmp; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15167 | attrs = attrs->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15168 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15169 | return (0); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15170 | } |
| 15171 | |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15172 | #if 0 /* Currently not used */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15173 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15174 | * xmlSchemaValidateCheckNodeList |
| 15175 | * @nodelist: the list of nodes |
| 15176 | * |
| 15177 | * Check the node list is only made of text nodes and entities pointing |
| 15178 | * to text nodes |
| 15179 | * |
| 15180 | * Returns 1 if true, 0 if false and -1 in case of error |
| 15181 | */ |
| 15182 | static int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15183 | xmlSchemaValidateCheckNodeList(xmlNodePtr nodelist) |
| 15184 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15185 | while (nodelist != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15186 | if (nodelist->type == XML_ENTITY_REF_NODE) { |
| 15187 | TODO /* implement recursion in the entity content */ |
| 15188 | } |
| 15189 | if ((nodelist->type != XML_TEXT_NODE) && |
| 15190 | (nodelist->type != XML_COMMENT_NODE) && |
| 15191 | (nodelist->type != XML_PI_NODE) && |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 15192 | (nodelist->type != XML_CDATA_SECTION_NODE)) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15193 | return (0); |
| 15194 | } |
| 15195 | nodelist = nodelist->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15196 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15197 | return (1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15198 | } |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 15199 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15200 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15201 | static void |
| 15202 | xmlSchemaPostSchemaAssembleFixup(xmlSchemaParserCtxtPtr ctxt) |
| 15203 | { |
| 15204 | int i, nbItems; |
| 15205 | xmlSchemaTypePtr item, *items; |
| 15206 | |
| 15207 | |
| 15208 | /* |
| 15209 | * During the Assemble of the schema ctxt->curItems has |
| 15210 | * been filled with the relevant new items. Fix those up. |
| 15211 | */ |
| 15212 | nbItems = ctxt->assemble->nbItems; |
| 15213 | items = (xmlSchemaTypePtr *) ctxt->assemble->items; |
| 15214 | |
| 15215 | for (i = 0; i < nbItems; i++) { |
| 15216 | item = items[i]; |
| 15217 | switch (item->type) { |
| 15218 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 15219 | xmlSchemaAttrFixup((xmlSchemaAttributePtr) item, ctxt, NULL); |
| 15220 | break; |
| 15221 | case XML_SCHEMA_TYPE_ELEMENT: |
| 15222 | xmlSchemaRefFixupCallback((xmlSchemaElementPtr) item, ctxt, |
| 15223 | NULL, NULL, NULL); |
| 15224 | break; |
| 15225 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
| 15226 | xmlSchemaAttrGrpFixup((xmlSchemaAttributeGroupPtr) item, |
| 15227 | ctxt, NULL); |
| 15228 | break; |
| 15229 | case XML_SCHEMA_TYPE_GROUP: |
| 15230 | xmlSchemaGroupDefFixup(item, ctxt, NULL); |
| 15231 | default: |
| 15232 | break; |
| 15233 | } |
| 15234 | } |
| 15235 | /* |
| 15236 | * Circularity checks. |
| 15237 | */ |
| 15238 | for (i = 0; i < nbItems; i++) { |
| 15239 | item = items[i]; |
| 15240 | switch (item->type) { |
| 15241 | case XML_SCHEMA_TYPE_GROUP: |
| 15242 | xmlSchemaCheckGroupDefCircular(item, ctxt, NULL); |
| 15243 | break; |
| 15244 | case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: |
| 15245 | xmlSchemaCheckAttributeGroupCircular( |
| 15246 | (xmlSchemaAttributeGroupPtr) item, ctxt, NULL); |
| 15247 | break; |
| 15248 | default: |
| 15249 | break; |
| 15250 | } |
| 15251 | } |
| 15252 | /* |
| 15253 | * Fixup for all other item. |
| 15254 | * TODO: Hmm, not sure if starting from complex/simple types, |
| 15255 | * all subsequent items will be reached. |
| 15256 | */ |
| 15257 | for (i = 0; i < nbItems; i++) { |
| 15258 | item = items[i]; |
| 15259 | switch (item->type) { |
| 15260 | case XML_SCHEMA_TYPE_SIMPLE: |
| 15261 | case XML_SCHEMA_TYPE_COMPLEX: |
| 15262 | xmlSchemaTypeFixup(item, ctxt, NULL); |
| 15263 | break; |
| 15264 | default: |
| 15265 | break; |
| 15266 | } |
| 15267 | } |
| 15268 | /* |
| 15269 | * Check facet values. Note that facets are |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 15270 | * hold by simple type components only (and |
| 15271 | * by complex types in the current implementation). |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15272 | */ |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 15273 | /* OLD: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15274 | for (i = 0; i < nbItems; i++) { |
| 15275 | item = items[i]; |
| 15276 | switch (item->type) { |
| 15277 | case XML_SCHEMA_TYPE_SIMPLE: |
| 15278 | case XML_SCHEMA_TYPE_COMPLEX: |
| 15279 | xmlSchemaCheckDefaults(item, ctxt, NULL); |
| 15280 | break; |
| 15281 | default: |
| 15282 | break; |
| 15283 | } |
| 15284 | } |
Kasimier T. Buchcik | b884124 | 2004-11-15 12:11:56 +0000 | [diff] [blame] | 15285 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15286 | /* |
| 15287 | * Build the content model for complex types. |
| 15288 | */ |
| 15289 | for (i = 0; i < nbItems; i++) { |
| 15290 | item = items[i]; |
| 15291 | switch (item->type) { |
| 15292 | case XML_SCHEMA_TYPE_COMPLEX: |
| 15293 | xmlSchemaBuildContentModel(item, ctxt, NULL); |
| 15294 | break; |
| 15295 | default: |
| 15296 | break; |
| 15297 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15298 | } |
| 15299 | /* |
| 15300 | * Validate value contraint values. |
| 15301 | */ |
| 15302 | for (i = 0; i < nbItems; i++) { |
| 15303 | item = items[i]; |
| 15304 | switch (item->type) { |
| 15305 | case XML_SCHEMA_TYPE_ATTRIBUTE: |
| 15306 | xmlSchemaCheckAttrValConstr((xmlSchemaAttributePtr) item, ctxt, NULL); |
| 15307 | break; |
| 15308 | case XML_SCHEMA_TYPE_ELEMENT: |
| 15309 | xmlSchemaCheckElemValConstr((xmlSchemaElementPtr) item, ctxt, NULL); |
| 15310 | break; |
| 15311 | default: |
| 15312 | break; |
| 15313 | } |
| 15314 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15315 | } |
| 15316 | |
| 15317 | /** |
| 15318 | * xmlSchemaAssembleByLocation: |
| 15319 | * @pctxt: a schema parser context |
| 15320 | * @vctxt: a schema validation context |
| 15321 | * @schema: the existing schema |
| 15322 | * @node: the node that fired the assembling |
| 15323 | * @nsName: the namespace name of the new schema |
| 15324 | * @location: the location of the schema |
| 15325 | * |
| 15326 | * Expands an existing schema by an additional schema. |
| 15327 | * |
| 15328 | * Returns 0 if the new schema is correct, a positive error code |
| 15329 | * number otherwise and -1 in case of an internal or API error. |
| 15330 | */ |
| 15331 | static int |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15332 | xmlSchemaAssembleByLocation(xmlSchemaValidCtxtPtr vctxt, |
| 15333 | xmlSchemaPtr schema, |
| 15334 | xmlNodePtr node, |
| 15335 | const xmlChar *nsName, |
| 15336 | const xmlChar *location) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15337 | { |
| 15338 | const xmlChar *targetNs, *oldtns; |
| 15339 | xmlDocPtr doc, olddoc; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15340 | int oldflags, ret = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15341 | xmlNodePtr docElem; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15342 | xmlSchemaParserCtxtPtr pctxt; |
| 15343 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15344 | /* |
| 15345 | * This should be used: |
| 15346 | * 1. on <import>(s) |
| 15347 | * 2. if requested by the validated instance |
| 15348 | * 3. if requested via the API |
| 15349 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15350 | if ((vctxt == NULL) || (schema == NULL)) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15351 | return (-1); |
| 15352 | /* |
| 15353 | * Create a temporary parser context. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15354 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15355 | if ((vctxt->pctxt == NULL) && |
| 15356 | (xmlSchemaCreatePCtxtOnVCtxt(vctxt) == -1)) { |
| 15357 | xmlSchemaVErr(vctxt, node, |
| 15358 | XML_SCHEMAV_INTERNAL, |
| 15359 | "Internal error: xmlSchemaAssembleByLocation, " |
| 15360 | "failed to create a temp. parser context.\n", |
| 15361 | NULL, NULL); |
| 15362 | return (-1); |
| 15363 | } |
| 15364 | pctxt = vctxt->pctxt; |
| 15365 | /* |
| 15366 | * Set the counter to produce unique names for anonymous items. |
| 15367 | */ |
| 15368 | pctxt->counter = schema->counter; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15369 | /* |
| 15370 | * Acquire the schema document. |
| 15371 | */ |
| 15372 | ret = xmlSchemaAcquireSchemaDoc(pctxt, schema, node, |
| 15373 | nsName, location, &doc, &targetNs, 0); |
| 15374 | if (ret != 0) { |
| 15375 | if (doc != NULL) |
| 15376 | xmlFreeDoc(doc); |
| 15377 | } else if (doc != NULL) { |
| 15378 | docElem = xmlDocGetRootElement(doc); |
| 15379 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15380 | * Create new assemble info. |
| 15381 | */ |
| 15382 | if (pctxt->assemble == NULL) { |
| 15383 | pctxt->assemble = xmlSchemaNewAssemble(); |
| 15384 | if (pctxt->assemble == NULL) { |
| 15385 | xmlSchemaVErrMemory(vctxt, |
| 15386 | "Memory error: xmlSchemaAssembleByLocation, " |
| 15387 | "allocating assemble info", NULL); |
| 15388 | xmlFreeDoc(doc); |
| 15389 | return (-1); |
| 15390 | } |
| 15391 | } |
| 15392 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15393 | * Save and reset the context & schema. |
| 15394 | */ |
| 15395 | oldflags = schema->flags; |
| 15396 | oldtns = schema->targetNamespace; |
| 15397 | olddoc = schema->doc; |
| 15398 | |
| 15399 | xmlSchemaClearSchemaDefaults(schema); |
| 15400 | schema->targetNamespace = targetNs; |
| 15401 | /* schema->nbCurItems = 0; */ |
| 15402 | pctxt->schema = schema; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15403 | pctxt->ctxtType = NULL; |
| 15404 | pctxt->parentItem = NULL; |
| 15405 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15406 | xmlSchemaParseSchemaDefaults(pctxt, schema, docElem); |
| 15407 | xmlSchemaParseSchemaTopLevel(pctxt, schema, docElem->children); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15408 | xmlSchemaPostSchemaAssembleFixup(pctxt); |
| 15409 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15410 | * Set the counter of items. |
| 15411 | */ |
| 15412 | schema->counter = pctxt->counter; |
| 15413 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15414 | * Free the list of assembled components. |
| 15415 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15416 | pctxt->assemble->nbItems = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15417 | /* |
| 15418 | * Restore the context & schema. |
| 15419 | */ |
| 15420 | schema->flags = oldflags; |
| 15421 | schema->targetNamespace = oldtns; |
| 15422 | schema->doc = olddoc; |
| 15423 | ret = pctxt->err; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15424 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15425 | return (ret); |
| 15426 | } |
| 15427 | |
| 15428 | /** |
| 15429 | * xmlSchemaAssembleByXSIAttr: |
| 15430 | * @vctxt: a schema validation context |
| 15431 | * @xsiAttr: an xsi attribute |
| 15432 | * @noNamespace: whether a schema with no target namespace is exptected |
| 15433 | * |
| 15434 | * Expands an existing schema by an additional schema using |
| 15435 | * the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attribute |
| 15436 | * of an instance. If xsi:noNamespaceSchemaLocation is used, @noNamespace |
| 15437 | * must be set to 1. |
| 15438 | * |
| 15439 | * Returns 0 if the new schema is correct, a positive error code |
| 15440 | * number otherwise and -1 in case of an internal or API error. |
| 15441 | */ |
| 15442 | static int |
| 15443 | xmlSchemaAssembleByXSIAttr(xmlSchemaValidCtxtPtr vctxt, |
| 15444 | xmlAttrPtr xsiAttr, |
| 15445 | int noNamespace) |
| 15446 | { |
| 15447 | xmlChar *value; |
| 15448 | const xmlChar *cur, *end; |
| 15449 | const xmlChar *nsname = NULL, *location; |
| 15450 | int count = 0; |
| 15451 | int ret = 0; |
| 15452 | |
| 15453 | if (xsiAttr == NULL) { |
| 15454 | xmlSchemaVCustomErr(vctxt, XML_SCHEMAV_INTERNAL, |
| 15455 | NULL, NULL, |
| 15456 | "Internal error: xmlSchemaAssembleByXSIAttr, " |
| 15457 | "bad arguments", NULL); |
| 15458 | return (-1); |
| 15459 | } |
| 15460 | /* |
| 15461 | * Parse the value; we will assume an even number of values |
| 15462 | * to be given (this is how Xerces and XSV work). |
| 15463 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15464 | value = xmlNodeGetContent((xmlNodePtr) xsiAttr); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15465 | cur = value; |
| 15466 | do { |
| 15467 | if (noNamespace != 1) { |
| 15468 | /* |
| 15469 | * Get the namespace name. |
| 15470 | */ |
| 15471 | while (IS_BLANK_CH(*cur)) |
| 15472 | cur++; |
| 15473 | end = cur; |
| 15474 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 15475 | end++; |
| 15476 | if (end == cur) |
| 15477 | break; |
| 15478 | count++; |
| 15479 | nsname = xmlDictLookup(vctxt->schema->dict, cur, end - cur); |
| 15480 | cur = end; |
| 15481 | } |
| 15482 | /* |
| 15483 | * Get the URI. |
| 15484 | */ |
| 15485 | while (IS_BLANK_CH(*cur)) |
| 15486 | cur++; |
| 15487 | end = cur; |
| 15488 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 15489 | end++; |
| 15490 | if (end == cur) |
| 15491 | break; |
| 15492 | count++; |
| 15493 | location = xmlDictLookup(vctxt->schema->dict, cur, end - cur); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15494 | cur = end; |
| 15495 | ret = xmlSchemaAssembleByLocation(vctxt, vctxt->schema, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15496 | xsiAttr->parent, nsname, location); |
| 15497 | if (ret == -1) { |
| 15498 | xmlSchemaVCustomErr(vctxt, |
| 15499 | XML_SCHEMAV_INTERNAL, |
| 15500 | (xmlNodePtr) xsiAttr, NULL, |
| 15501 | "Internal error: xmlSchemaAssembleByXSIAttr, " |
| 15502 | "assembling schemata", NULL); |
| 15503 | if (value != NULL) |
| 15504 | xmlFree(value); |
| 15505 | return (-1); |
| 15506 | } |
| 15507 | } while (*cur != 0); |
| 15508 | if (value != NULL) |
| 15509 | xmlFree(value); |
| 15510 | return (ret); |
| 15511 | } |
| 15512 | |
| 15513 | /** |
| 15514 | * xmlSchemaAssembleByXSIElem: |
| 15515 | * @vctxt: a schema validation context |
| 15516 | * @elem: an element node possibly holding xsi attributes |
| 15517 | * @noNamespace: whether a schema with no target namespace is exptected |
| 15518 | * |
| 15519 | * Assembles an existing schema by an additional schema using |
| 15520 | * the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attributes |
| 15521 | * of the given @elem. |
| 15522 | * |
| 15523 | * Returns 0 if the new schema is correct, a positive error code |
| 15524 | * number otherwise and -1 in case of an internal or API error. |
| 15525 | */ |
| 15526 | static int |
| 15527 | xmlSchemaAssembleByXSIElem(xmlSchemaValidCtxtPtr vctxt, |
| 15528 | xmlNodePtr elem) |
| 15529 | { |
| 15530 | int ret = 0, retNs = 0; |
| 15531 | xmlAttrPtr attr; |
| 15532 | |
| 15533 | attr = xmlHasNsProp(elem, BAD_CAST "schemaLocation", xmlSchemaInstanceNs); |
| 15534 | if (attr != NULL) { |
| 15535 | retNs = xmlSchemaAssembleByXSIAttr(vctxt, attr, 0); |
| 15536 | if (retNs == -1) |
| 15537 | return (-1); |
| 15538 | } |
| 15539 | attr = xmlHasNsProp(elem, BAD_CAST "noNamespaceSchemaLocation", xmlSchemaInstanceNs); |
| 15540 | if (attr != NULL) { |
| 15541 | ret = xmlSchemaAssembleByXSIAttr(vctxt, attr, 1); |
| 15542 | if (ret == -1) |
| 15543 | return (-1); |
| 15544 | } |
| 15545 | if (retNs != 0) |
| 15546 | return (retNs); |
| 15547 | else |
| 15548 | return (ret); |
| 15549 | } |
| 15550 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15551 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15552 | * xmlSchemaValidateCallback: |
| 15553 | * @ctxt: a schema validation context |
| 15554 | * @name: the name of the element detected (might be NULL) |
| 15555 | * @type: the type |
| 15556 | * |
| 15557 | * A transition has been made in the automata associated to an element |
| 15558 | * content model |
| 15559 | */ |
| 15560 | static void |
| 15561 | xmlSchemaValidateCallback(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15562 | const xmlChar * name ATTRIBUTE_UNUSED, |
| 15563 | xmlSchemaTypePtr type, xmlNodePtr node) |
| 15564 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15565 | xmlSchemaTypePtr oldtype = ctxt->type; |
| 15566 | xmlNodePtr oldnode = ctxt->node; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15567 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15568 | #ifdef DEBUG_CONTENT |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 15569 | xmlGenericError(xmlGenericErrorContext, |
| 15570 | "xmlSchemaValidateCallback: %s, %s, %s\n", |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 15571 | name, type->name, node->name); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15572 | #endif |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15573 | /* |
| 15574 | * @type->type will be XML_SCHEMA_TYPE_ANY or XML_SCHEMA_TYPE_ELEMENT. |
| 15575 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15576 | ctxt->type = type; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15577 | ctxt->node = node; |
| 15578 | ctxt->cur = node->children; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15579 | |
| 15580 | #ifdef ELEM_INFO_ENABLED |
| 15581 | xmlSchemaBeginElement(ctxt); |
| 15582 | #endif |
| 15583 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15584 | /* |
| 15585 | * Assemble new schemata using xsi. |
| 15586 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15587 | if (ctxt->xsiAssemble) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15588 | int ret; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15589 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15590 | ret = xmlSchemaAssembleByXSIElem(ctxt, ctxt->node); |
| 15591 | if (ret == -1) { |
| 15592 | xmlSchemaVCustomErr(ctxt, |
| 15593 | XML_SCHEMAV_INTERNAL, |
| 15594 | ctxt->node, NULL, |
| 15595 | "Internal error: xmlSchemaValidateElement, " |
| 15596 | "assembling schema by xsi", NULL); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15597 | goto leave; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15598 | } |
| 15599 | /* |
| 15600 | * NOTE: We won't react on schema parser errors here. |
| 15601 | * TODO: But a warning would be nice. |
| 15602 | */ |
| 15603 | } |
| 15604 | switch (type->type) { |
| 15605 | case XML_SCHEMA_TYPE_ELEMENT: { |
| 15606 | /* |
| 15607 | * NOTE: The build of the content model |
| 15608 | * (xmlSchemaBuildAContentModel) ensures that the element |
| 15609 | * declaration (and not a reference to it) will be given. |
| 15610 | */ |
| 15611 | if (((xmlSchemaElementPtr) ctxt->type)->ref != NULL) { |
| 15612 | /* |
| 15613 | * This is paranoid coding ;-)... it should not |
| 15614 | * happen here any more. |
| 15615 | */ |
| 15616 | xmlSchemaVCustomErr(ctxt, |
| 15617 | XML_SCHEMAV_INTERNAL, |
| 15618 | node, NULL, |
| 15619 | "Internal error: xmlSchemaValidateCallback, " |
| 15620 | "element declaration 'reference' encountered, " |
| 15621 | "but an element declaration was expected", |
| 15622 | NULL); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15623 | goto leave; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15624 | } |
| 15625 | xmlSchemaValidateElementByDeclaration(ctxt, |
| 15626 | (xmlSchemaElementPtr) type); |
| 15627 | break; |
| 15628 | } |
| 15629 | case XML_SCHEMA_TYPE_ANY: |
| 15630 | xmlSchemaValidateElementByWildcard(ctxt, type); |
| 15631 | break; |
| 15632 | default: |
| 15633 | break; |
| 15634 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15635 | leave: |
| 15636 | |
| 15637 | #ifdef ELEM_INFO_ENABLED |
| 15638 | xmlSchemaEndElement(ctxt); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 15639 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15640 | ctxt->type = oldtype; |
| 15641 | ctxt->node = oldnode; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15642 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 15643 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15644 | /** |
| 15645 | * xmlSchemaValidateSimpleTypeValue: |
| 15646 | * @ctxt: a schema validation context |
| 15647 | * @value: the value to be validated |
| 15648 | * @fireErrors: shall errors be reported? |
| 15649 | * @applyFacets: shall facets be applied? |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15650 | * @normalize: shall the value be normalized? |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15651 | * @checkNodes: shall the content nodes be checked? |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15652 | * |
| 15653 | * Validates a value by the given type (user derived or built-in). |
| 15654 | * |
| 15655 | * Returns 0 if the value is valid, a positive error code |
| 15656 | * number otherwise and -1 in case of an internal or API error. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15657 | */ |
| 15658 | static int |
| 15659 | xmlSchemaValidateSimpleTypeValue(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15660 | xmlSchemaTypePtr type, |
| 15661 | const xmlChar *value, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15662 | int fireErrors, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15663 | int applyFacets, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15664 | int normalize, |
| 15665 | int checkNodes) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15666 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15667 | xmlNodePtr node; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15668 | int ret = 0; |
| 15669 | xmlChar *normValue = NULL; |
| 15670 | int wtsp; |
| 15671 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15672 | node = ctxt->node; |
| 15673 | /* Save the current whitespace normalization type. */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15674 | wtsp = ctxt->valueWS; |
| 15675 | /* |
| 15676 | * Normalize the value. |
| 15677 | */ |
| 15678 | if (normalize && |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 15679 | (ctxt->valueWS != XML_SCHEMAS_FACET_COLLAPSE)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15680 | int norm = xmlSchemaGetWhiteSpaceFacetValue(type); |
| 15681 | |
| 15682 | if ((norm != -1) && (norm > ctxt->valueWS)) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 15683 | if (norm == XML_SCHEMAS_FACET_COLLAPSE) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15684 | normValue = xmlSchemaCollapseString(value); |
| 15685 | else |
| 15686 | normValue = xmlSchemaWhiteSpaceReplace(value); |
| 15687 | ctxt->valueWS = norm; |
| 15688 | if (normValue != NULL) |
| 15689 | value = (const xmlChar *) normValue; |
| 15690 | } |
| 15691 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15692 | /* |
| 15693 | * The nodes of a content must be checked only once, |
| 15694 | * this is not working since list types will fire this |
| 15695 | * multiple times. |
| 15696 | */ |
| 15697 | if ((checkNodes == 1) && (ctxt->cur != NULL)) { |
| 15698 | xmlNodePtr cur = ctxt->cur; |
| 15699 | |
| 15700 | do { |
| 15701 | switch (cur->type) { |
| 15702 | case XML_TEXT_NODE: |
| 15703 | case XML_CDATA_SECTION_NODE: |
| 15704 | case XML_PI_NODE: |
| 15705 | case XML_COMMENT_NODE: |
| 15706 | case XML_XINCLUDE_START: |
| 15707 | case XML_XINCLUDE_END: |
| 15708 | break; |
| 15709 | case XML_ENTITY_REF_NODE: |
| 15710 | case XML_ENTITY_NODE: |
| 15711 | /* TODO: Scour the entities for illegal nodes. */ |
| 15712 | TODO break; |
| 15713 | case XML_ELEMENT_NODE: { |
| 15714 | /* NOTE: Changed to an internal error, since the |
| 15715 | * existence of an element node will be already checked in |
| 15716 | * xmlSchemaValidateElementBySimpleType and in |
| 15717 | * xmlSchemaValidateElementByComplexType. |
| 15718 | */ |
| 15719 | xmlSchemaVCustomErr(ctxt, |
| 15720 | XML_SCHEMAV_INTERNAL, |
| 15721 | /* XML_SCHEMAS_ERR_INVALIDELEM, */ |
| 15722 | node, type, |
| 15723 | "Element '%s' found in simple type content", |
| 15724 | cur->name); |
| 15725 | return (XML_SCHEMAV_INTERNAL); |
| 15726 | } |
| 15727 | case XML_ATTRIBUTE_NODE: |
| 15728 | case XML_DOCUMENT_NODE: |
| 15729 | case XML_DOCUMENT_TYPE_NODE: |
| 15730 | case XML_DOCUMENT_FRAG_NODE: |
| 15731 | case XML_NOTATION_NODE: |
| 15732 | case XML_HTML_DOCUMENT_NODE: |
| 15733 | case XML_DTD_NODE: |
| 15734 | case XML_ELEMENT_DECL: |
| 15735 | case XML_ATTRIBUTE_DECL: |
| 15736 | case XML_ENTITY_DECL: |
| 15737 | case XML_NAMESPACE_DECL: |
| 15738 | #ifdef LIBXML_DOCB_ENABLED |
| 15739 | case XML_DOCB_DOCUMENT_NODE: |
| 15740 | #endif |
| 15741 | xmlSchemaVCustomErr(ctxt, |
| 15742 | XML_SCHEMAV_INTERNAL, |
| 15743 | /* XML_SCHEMAS_ERR_INVALIDELEM, */ |
| 15744 | node, NULL, |
| 15745 | "Node of unexpected type found in simple type content", |
| 15746 | NULL); |
| 15747 | return (XML_SCHEMAV_INTERNAL); |
| 15748 | } |
| 15749 | cur = cur->next; |
| 15750 | } while (cur != NULL); |
| 15751 | } |
| 15752 | |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15753 | if (type->type == XML_SCHEMA_TYPE_COMPLEX) { |
| 15754 | xmlSchemaTypePtr base, anyType; |
| 15755 | |
| 15756 | anyType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE); |
| 15757 | |
| 15758 | base = type->baseType; |
| 15759 | while ((base != NULL) && |
| 15760 | (base->type != XML_SCHEMA_TYPE_SIMPLE) && |
| 15761 | (base->type != XML_SCHEMA_TYPE_BASIC) && |
| 15762 | (base != anyType)) { |
| 15763 | base = base->baseType; |
| 15764 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15765 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, base, value, 1, 0, 1, 0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15766 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15767 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15768 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 15769 | "validating complex type '%s'\n", |
| 15770 | type->name, NULL); |
| 15771 | } else if ((ret == 0) && (applyFacets) && (type->facetSet != NULL)) { |
| 15772 | /* |
| 15773 | * Check facets. |
| 15774 | */ |
| 15775 | /* |
| 15776 | * This is somehow not nice, since if an error occurs |
| 15777 | * the reported type will be the complex type; the spec |
| 15778 | * wants a simple type to be created on the complex type |
| 15779 | * if it has a simple content. For now we have to live with |
| 15780 | * it. |
| 15781 | */ |
| 15782 | ret = xmlSchemaValidateFacetsInternal(ctxt, type, |
| 15783 | value, 0, fireErrors); |
| 15784 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15785 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15786 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 15787 | "validating facets of complex type '%s'\n", |
| 15788 | type->name, NULL); |
| 15789 | } else if (ret > 0) { |
| 15790 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15791 | if (fireErrors) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 15792 | xmlSchemaVSimpleTypeErr(ctxt, ret, node, value, type); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 15793 | } |
| 15794 | } |
| 15795 | } else if (type->type == XML_SCHEMA_TYPE_BASIC) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15796 | |
| 15797 | if (ctxt->value != NULL) { |
| 15798 | xmlSchemaFreeValue(ctxt->value); |
| 15799 | ctxt->value = NULL; |
| 15800 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15801 | /* |
| 15802 | * STREAM-READ-CHILDREN. |
| 15803 | */ |
| 15804 | ret = xmlSchemaValPredefTypeNodeNoNorm(type, value, &(ctxt->value), node); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15805 | if (ret > 0) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15806 | if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) |
| 15807 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
| 15808 | else |
| 15809 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15810 | if (fireErrors) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15811 | xmlSchemaVSimpleTypeErr(ctxt, ret, node, value, type); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15812 | } else if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15813 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15814 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15815 | "validating built-in type '%s'\n", type->name, NULL); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 15816 | } else if ((ctxt->value == NULL) && |
| 15817 | (type->builtInType == XML_SCHEMAS_STRING) && |
| 15818 | (ctxt->nodeInfo != NULL) && |
| 15819 | (ctxt->nodeInfo->flags & XML_SCHEMA_ELEM_INFO_VALUE_NEEDED)) { |
| 15820 | #ifdef IDC_VALUE_SUPPORT |
| 15821 | xmlChar *valdup; |
| 15822 | /* |
| 15823 | * Create a precomputed string value for "string" as well if |
| 15824 | * requested. |
| 15825 | */ |
| 15826 | valdup = xmlStrdup(value); |
| 15827 | ctxt->value = xmlSchemaNewStringValue(XML_SCHEMAS_STRING, |
| 15828 | BAD_CAST valdup); |
| 15829 | if ((valdup != NULL) && (ctxt->value == NULL)) |
| 15830 | xmlFree(valdup); |
| 15831 | #endif |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15832 | } |
| 15833 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC) { |
| 15834 | /* 1.2.1 if {variety} is ·atomic· then the string must ·match· |
| 15835 | * a literal in the ·lexical space· of {base type definition} |
| 15836 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15837 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, type->baseType, value, 0, 0, 0, 0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15838 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15839 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15840 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15841 | "validating atomic simple type '%s'\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15842 | type->name, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15843 | } else if (ret > 0) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15844 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15845 | if (fireErrors) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15846 | xmlSchemaVSimpleTypeErr(ctxt, ret, node, value, type); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15847 | } else if ((applyFacets) && (type->facetSet != NULL)) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15848 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15849 | * Check facets. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15850 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15851 | ret = xmlSchemaValidateFacetsInternal(ctxt, type, |
| 15852 | value, 0, fireErrors); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15853 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15854 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15855 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15856 | "validating facets of atomic simple type '%s'\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15857 | type->name, NULL); |
| 15858 | } else if (ret > 0) { |
| 15859 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15860 | /* |
| 15861 | Disabled, since the facet validation already reports errors. |
| 15862 | if (fireErrors) |
| 15863 | xmlSchemaVSimpleTypeErr(ctxt, ret, ctxt->cur, value, type); |
| 15864 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15865 | } |
| 15866 | } |
| 15867 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) { |
| 15868 | |
| 15869 | xmlSchemaTypePtr tmpType; |
| 15870 | const xmlChar *cur, *end; |
| 15871 | xmlChar *tmp; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15872 | unsigned long len = 0; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15873 | |
| 15874 | /* 1.2.2 if {variety} is ·list· then the string must be a sequence |
| 15875 | * of white space separated tokens, each of which ·match·es a literal |
| 15876 | * in the ·lexical space· of {item type definition} |
| 15877 | */ |
Kasimier T. Buchcik | 31113c7 | 2005-01-13 16:57:20 +0000 | [diff] [blame] | 15878 | |
Kasimier T. Buchcik | de938cd | 2005-01-13 12:25:57 +0000 | [diff] [blame] | 15879 | if (value == NULL) |
| 15880 | value = BAD_CAST ""; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15881 | tmpType = xmlSchemaGetListSimpleTypeItemType(type); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15882 | cur = value; |
| 15883 | do { |
| 15884 | while (IS_BLANK_CH(*cur)) |
| 15885 | cur++; |
| 15886 | end = cur; |
| 15887 | while ((*end != 0) && (!(IS_BLANK_CH(*end)))) |
| 15888 | end++; |
| 15889 | if (end == cur) |
| 15890 | break; |
| 15891 | tmp = xmlStrndup(cur, end - cur); |
| 15892 | len++; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15893 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, tmpType, tmp, 0, 1, 0, 0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15894 | xmlFree(tmp); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15895 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15896 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15897 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 15898 | "validating an item of list simple type '%s'\n", |
| 15899 | type->name, NULL); |
| 15900 | break; |
| 15901 | } else if (ret > 0) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15902 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15903 | if (fireErrors) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15904 | xmlSchemaVSimpleTypeErr(ctxt, ret, node, value, type); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15905 | break; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15906 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15907 | cur = end; |
| 15908 | } while (*cur != 0); |
| 15909 | /* |
| 15910 | * Check facets. |
| 15911 | */ |
| 15912 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15913 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15914 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15915 | "validating list simple type '%s'\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15916 | type->name, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15917 | } else if ((ret == 0) && (applyFacets)) { |
| 15918 | ret = xmlSchemaValidateFacetsInternal(ctxt, type, |
| 15919 | value, len, fireErrors); |
| 15920 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15921 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15922 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 15923 | "validating facets of list simple type '%s'\n", |
| 15924 | type->name, NULL); |
| 15925 | } else if (ret > 0) { |
| 15926 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15927 | /* |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15928 | Disabled, since the facet validation already reports errors. |
| 15929 | if (fireErrors) |
| 15930 | xmlSchemaVSimpleTypeErr(ctxt, ret, ctxt->cur, value, type); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15931 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15932 | } |
| 15933 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15934 | } |
| 15935 | } else if (type->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) { |
| 15936 | xmlSchemaTypeLinkPtr memberLink; |
| 15937 | |
| 15938 | /* |
| 15939 | * TODO: For all datatypes ·derived· by ·union· whiteSpace does |
| 15940 | * not apply directly; however, the normalization behavior of ·union· |
| 15941 | * types is controlled by the value of whiteSpace on that one of the |
| 15942 | * ·memberTypes· against which the ·union· is successfully validated. |
| 15943 | * |
| 15944 | * This means that the value is normalized by the first validating |
| 15945 | * member type, then the facets of the union type are applied. This |
| 15946 | * needs changing of the value! |
| 15947 | */ |
| 15948 | |
| 15949 | /* |
| 15950 | * 1.2.3 if {variety} is ·union· then the string must ·match· a |
| 15951 | * literal in the ·lexical space· of at least one member of |
| 15952 | * {member type definitions} |
| 15953 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15954 | #ifdef DEBUG_UNION_VALIDATION |
| 15955 | printf("Union ST : '%s'\n", (const char *) type->name); |
| 15956 | printf(" fireErrors : %d\n", fireErrors); |
| 15957 | printf(" applyFacets: %d\n", applyFacets); |
| 15958 | #endif |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15959 | memberLink = xmlSchemaGetUnionSimpleTypeMemberTypes(type); |
| 15960 | if (memberLink == NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15961 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15962 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15963 | "union simple type '%s' has no member types\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15964 | type->name, NULL); |
| 15965 | ret = -1; |
| 15966 | } |
| 15967 | if (ret == 0) { |
| 15968 | while (memberLink != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15969 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, memberLink->type, |
| 15970 | value, 0, 1, 1, 0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15971 | if ((ret <= 0) || (ret == 0)) |
| 15972 | break; |
| 15973 | memberLink = memberLink->next; |
| 15974 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15975 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15976 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15977 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15978 | "validating members of union simple type '%s'\n", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 15979 | type->name, NULL); |
| 15980 | } else if (ret > 0) { |
| 15981 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15982 | if (fireErrors) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15983 | xmlSchemaVSimpleTypeErr(ctxt, ret, node, value, type); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15984 | } |
| 15985 | } |
| 15986 | /* |
| 15987 | * Apply facets (pattern, enumeration). |
| 15988 | */ |
| 15989 | if ((ret == 0) && (applyFacets) && (type->facetSet != NULL)) { |
| 15990 | int mws; |
| 15991 | /* |
| 15992 | * The normalization behavior of ·union· types is controlled by |
| 15993 | * the value of whiteSpace on that one of the ·memberTypes· |
| 15994 | * against which the ·union· is successfully validated. |
| 15995 | */ |
| 15996 | if (normValue != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 15997 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 15998 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 15999 | "the value was already normalized for the union simple " |
| 16000 | "type '%s'.\n", type->name, NULL); |
| 16001 | } |
| 16002 | mws = xmlSchemaGetWhiteSpaceFacetValue(memberLink->type); |
| 16003 | if (mws > ctxt->valueWS) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 16004 | if (mws == XML_SCHEMAS_FACET_COLLAPSE) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16005 | normValue = xmlSchemaCollapseString(value); |
| 16006 | else |
| 16007 | normValue = xmlSchemaWhiteSpaceReplace(value); |
| 16008 | if (normValue != NULL) |
| 16009 | value = (const xmlChar *) normValue; |
| 16010 | } |
| 16011 | |
| 16012 | ret = xmlSchemaValidateFacetsInternal(ctxt, type, |
| 16013 | value, 0, fireErrors); |
| 16014 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16015 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16016 | "Internal error: xmlSchemaValidateSimpleTypeValue, " |
| 16017 | "validating facets of union simple type '%s'\n", |
| 16018 | type->name, NULL); |
| 16019 | } else if (ret > 0) { |
| 16020 | ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3; |
| 16021 | /* |
| 16022 | if (fireErrors) |
| 16023 | xmlSchemaVSimpleTypeErr(ctxt, ret, ctxt->cur, value, type); |
| 16024 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16025 | } |
| 16026 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16027 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 16028 | ctxt->valueWS = wtsp; |
| 16029 | if (normValue != NULL) |
| 16030 | xmlFree(normValue); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16031 | return (ret); |
| 16032 | } |
| 16033 | |
| 16034 | /** |
| 16035 | * xmlSchemaValidateSimpleTypeElement: |
| 16036 | * @ctxt: a schema validation context |
| 16037 | * @node: the element node to be validated. |
| 16038 | * |
| 16039 | * Validate the element against a simple type. |
| 16040 | * |
| 16041 | * Returns 0 if the element is valid, a positive error code |
| 16042 | * number otherwise and -1 in case of an internal or API error. |
| 16043 | */ |
| 16044 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16045 | xmlSchemaValidateElementBySimpleType(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16046 | xmlSchemaTypePtr type, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 16047 | int isNil, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16048 | int valSimpleContent) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16049 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16050 | xmlSchemaTypePtr oldtype; |
| 16051 | xmlNodePtr node; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16052 | xmlAttrPtr attr; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16053 | xmlNodePtr cur; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16054 | int ret = 0, retval = 0; |
| 16055 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16056 | if ((ctxt == NULL) || (type == NULL)) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16057 | xmlSchemaVCustomErr(ctxt, XML_SCHEMAV_INTERNAL, NULL, NULL, |
| 16058 | "Internal error: xmlSchemaValidateElementBySimpleType, " |
| 16059 | "bad arguments", NULL); |
| 16060 | return (-1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16061 | } |
| 16062 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16063 | oldtype = ctxt->type; |
| 16064 | node = ctxt->node; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16065 | /* |
| 16066 | * cvc-type: 3.1.2 The element information item must have no element |
| 16067 | * information item [children]. |
| 16068 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16069 | /* |
| 16070 | * STREAM: Child nodes are processed. |
| 16071 | */ |
| 16072 | cur = node->children; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16073 | while (cur != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16074 | /* |
| 16075 | * TODO: Entities, will they produce elements as well? |
| 16076 | */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16077 | if (cur->type == XML_ELEMENT_NODE) { |
| 16078 | xmlSchemaVCustomErr(ctxt, |
| 16079 | XML_SCHEMAV_CVC_TYPE_3_1_2, |
| 16080 | node, type, |
| 16081 | "No element content allowed", NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16082 | ret = XML_SCHEMAV_CVC_TYPE_3_1_2; |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16083 | } |
| 16084 | cur = cur->next; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16085 | } |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16086 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16087 | /* |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16088 | * cvc-type 3.1.1: |
| 16089 | * |
| 16090 | * The attributes of must be empty, excepting those whose namespace name |
| 16091 | * is identical to http://www.w3.org/2001/XMLSchema-instance and whose local |
| 16092 | * name is one of type, nil, schemaLocation or noNamespaceSchemaLocation. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16093 | */ |
| 16094 | /* |
| 16095 | * STREAM: Attribute nodes are processed. |
| 16096 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16097 | attr = node->properties; |
| 16098 | while (attr != NULL) { |
| 16099 | if ((attr->ns == NULL) || |
| 16100 | (!xmlStrEqual(attr->ns->href, xmlSchemaInstanceNs)) || |
| 16101 | ((!xmlStrEqual(attr->name, BAD_CAST "type")) && |
| 16102 | (!xmlStrEqual(attr->name, BAD_CAST "nil")) && |
| 16103 | (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation")) && |
| 16104 | (!xmlStrEqual |
| 16105 | (attr->name, BAD_CAST "noNamespaceSchemaLocation")))) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 16106 | xmlSchemaVIllegalAttrErr(ctxt, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16107 | XML_SCHEMAV_CVC_TYPE_3_1_1, attr); |
| 16108 | ret = XML_SCHEMAV_CVC_TYPE_3_1_1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16109 | } |
| 16110 | attr = attr->next; |
| 16111 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16112 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16113 | * This will skip validation if the type is 'anySimpleType' and |
| 16114 | * if the value was already validated (e.g. default values). |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16115 | */ |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 16116 | if ((! isNil) && |
| 16117 | (valSimpleContent == 1) && |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16118 | ((type->type != XML_SCHEMA_TYPE_BASIC) || |
| 16119 | (type->builtInType != XML_SCHEMAS_ANYSIMPLETYPE))) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16120 | xmlChar *value; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16121 | |
| 16122 | value = xmlNodeGetContent(node); |
| 16123 | /* |
| 16124 | * NOTE: This call will not check the content nodes, since |
| 16125 | * this should be checked here already. |
| 16126 | */ |
| 16127 | retval = xmlSchemaValidateSimpleTypeValue(ctxt, type, value, |
| 16128 | 1, 1, 1, 0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16129 | if (value != NULL) |
| 16130 | xmlFree(value); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16131 | if (retval != 0) |
| 16132 | ret = retval; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 16133 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16134 | ctxt->type = oldtype; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 16135 | return (ret); |
| 16136 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 16137 | |
| 16138 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16139 | * xmlSchemaValQNameAcquire: |
| 16140 | * @value: the lexical represantation of the QName value |
| 16141 | * @node: the node to search for the corresponding namespace declaration |
| 16142 | * @nsName: the resulting namespace name if found |
| 16143 | * |
| 16144 | * Checks that a value conforms to the lexical space of the type QName; |
| 16145 | * if valid, the corresponding namespace name is searched and retured |
| 16146 | * as a copy in @nsName. The local name is returned in @localName as |
| 16147 | * a copy. |
| 16148 | * |
| 16149 | * Returns 0 if valid, 1 if not valid by type, 2 if no corresponding |
| 16150 | * namespace declaration was found in scope; -1 in case of an internal or |
| 16151 | * API error. |
| 16152 | */ |
| 16153 | static int |
| 16154 | xmlSchemaValQNameAcquire(const xmlChar *value, xmlNodePtr node, |
| 16155 | xmlChar **nsName, xmlChar **localName) |
| 16156 | { |
| 16157 | int ret; |
| 16158 | xmlChar *local = NULL; |
| 16159 | |
| 16160 | if ((nsName == NULL) || (localName == NULL) || (node == NULL)) |
| 16161 | return (-1); |
| 16162 | *nsName = NULL; |
| 16163 | *localName = NULL; |
| 16164 | ret = xmlValidateQName(value, 1); |
| 16165 | if (ret == 0) { |
| 16166 | xmlChar *prefix; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16167 | xmlNsPtr ns; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16168 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16169 | /* |
| 16170 | * NOTE: xmlSplitQName2 will return a duplicated |
| 16171 | * string. |
| 16172 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16173 | local = xmlSplitQName2(value, &prefix); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16174 | if (local == NULL) |
| 16175 | local = xmlStrdup(value); |
| 16176 | ns = xmlSearchNs(node->doc, node, prefix); |
| 16177 | /* |
| 16178 | * A namespace need not to be found if the prefix is NULL. |
| 16179 | */ |
| 16180 | if (ns != NULL) { |
| 16181 | /* |
| 16182 | * TODO: Is it necessary to duplicate the URI here? |
| 16183 | */ |
| 16184 | *nsName = xmlStrdup(ns->href); |
| 16185 | } else if (prefix != NULL) { |
| 16186 | xmlFree(prefix); |
| 16187 | if (local != NULL) |
| 16188 | xmlFree(local); |
| 16189 | return (2); |
| 16190 | } |
| 16191 | *localName = local; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16192 | if (prefix != NULL) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16193 | xmlFree(prefix); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 16194 | } else |
| 16195 | return (1); |
| 16196 | return (ret); |
| 16197 | } |
| 16198 | |
| 16199 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 16200 | * xmlSchemaHasElemContent: |
| 16201 | * @node: the node |
| 16202 | * |
| 16203 | * Scours the content of the given node for element |
| 16204 | * nodes. |
| 16205 | * |
| 16206 | * Returns 1 if an element node is found, |
| 16207 | * 0 otherwise. |
| 16208 | */ |
| 16209 | static int |
| 16210 | xmlSchemaHasElemContent(xmlNodePtr node) |
| 16211 | { |
| 16212 | if (node == NULL) |
| 16213 | return (0); |
| 16214 | node = node->children; |
| 16215 | while (node != NULL) { |
| 16216 | if (node->type == XML_ELEMENT_NODE) |
| 16217 | return (1); |
| 16218 | node = node->next; |
| 16219 | } |
| 16220 | return (0); |
| 16221 | } |
| 16222 | /** |
| 16223 | * xmlSchemaHasElemOrCharContent: |
| 16224 | * @node: the node |
| 16225 | * |
| 16226 | * Scours the content of the given node for element |
| 16227 | * and character nodes. |
| 16228 | * |
| 16229 | * Returns 1 if an element or character node is found, |
| 16230 | * 0 otherwise. |
| 16231 | */ |
| 16232 | static int |
| 16233 | xmlSchemaHasElemOrCharContent(xmlNodePtr node) |
| 16234 | { |
| 16235 | if (node == NULL) |
| 16236 | return (0); |
| 16237 | node = node->children; |
| 16238 | while (node != NULL) { |
| 16239 | switch (node->type) { |
| 16240 | case XML_ELEMENT_NODE: |
| 16241 | /* |
| 16242 | * TODO: Ask Daniel if these are all character nodes. |
| 16243 | */ |
| 16244 | case XML_TEXT_NODE: |
| 16245 | case XML_CDATA_SECTION_NODE: |
| 16246 | /* |
| 16247 | * TODO: How XML_ENTITY_NODEs evaluated? |
| 16248 | */ |
| 16249 | case XML_ENTITY_REF_NODE: |
| 16250 | case XML_ENTITY_NODE: |
| 16251 | return (1); |
| 16252 | break; |
| 16253 | default: |
| 16254 | break; |
| 16255 | } |
| 16256 | node = node->next; |
| 16257 | } |
| 16258 | return (0); |
| 16259 | } |
| 16260 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16261 | /************************************************************************ |
| 16262 | * * |
| 16263 | * Identity-constraints (IDC) * |
| 16264 | * * |
| 16265 | ************************************************************************/ |
| 16266 | |
| 16267 | #ifdef IDC_ENABLED |
| 16268 | |
| 16269 | /** |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16270 | * xmlSchemaAugmentIDC: |
| 16271 | * @idcDef: the IDC definition |
| 16272 | * |
| 16273 | * Creates an augmented IDC definition item. |
| 16274 | * |
| 16275 | * Returns the item, or NULL on internal errors. |
| 16276 | */ |
| 16277 | static void |
| 16278 | xmlSchemaAugmentIDC(xmlSchemaIDCPtr idcDef, |
| 16279 | xmlSchemaValidCtxtPtr vctxt) |
| 16280 | { |
| 16281 | xmlSchemaIDCAugPtr aidc; |
| 16282 | |
| 16283 | aidc = (xmlSchemaIDCAugPtr) xmlMalloc(sizeof(xmlSchemaIDCAug)); |
| 16284 | if (aidc == NULL) { |
| 16285 | xmlSchemaVErrMemory(vctxt, |
| 16286 | "xmlSchemaAugmentIDC: allocating an augmented IDC definition", |
| 16287 | NULL); |
| 16288 | return; |
| 16289 | } |
| 16290 | aidc->bubbleDepth = -1; |
| 16291 | aidc->def = idcDef; |
| 16292 | aidc->next = NULL; |
| 16293 | if (vctxt->aidcs == NULL) |
| 16294 | vctxt->aidcs = aidc; |
| 16295 | else { |
| 16296 | aidc->next = vctxt->aidcs; |
| 16297 | vctxt->aidcs = aidc; |
| 16298 | } |
| 16299 | } |
| 16300 | |
| 16301 | /** |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16302 | * xmlSchemaIDCNewBinding: |
| 16303 | * @idcDef: the IDC definition of this binding |
| 16304 | * |
| 16305 | * Creates a new IDC binding. |
| 16306 | * |
| 16307 | * Returns the new binding in case of succeeded, NULL on internal errors. |
| 16308 | */ |
| 16309 | static xmlSchemaPSVIIDCBindingPtr |
| 16310 | xmlSchemaIDCNewBinding(xmlSchemaIDCPtr idcDef) |
| 16311 | { |
| 16312 | xmlSchemaPSVIIDCBindingPtr ret; |
| 16313 | |
| 16314 | ret = (xmlSchemaPSVIIDCBindingPtr) xmlMalloc( |
| 16315 | sizeof(xmlSchemaPSVIIDCBinding)); |
| 16316 | if (ret == NULL) { |
| 16317 | xmlSchemaVErrMemory(NULL, |
| 16318 | "allocating a PSVI IDC binding item", NULL); |
| 16319 | return (NULL); |
| 16320 | } |
| 16321 | memset(ret, 0, sizeof(xmlSchemaPSVIIDCBinding)); |
| 16322 | ret->definition = idcDef; |
| 16323 | return (ret); |
| 16324 | } |
| 16325 | |
| 16326 | /** |
| 16327 | * xmlSchemaIDCStoreNodeTableItem: |
| 16328 | * @vctxt: the WXS validation context |
| 16329 | * @item: the IDC node table item |
| 16330 | * |
| 16331 | * The validation context is used to store an IDC node table items. |
| 16332 | * They are stored to avoid copying them if IDC node-tables are merged |
| 16333 | * with corresponding parent IDC node-tables (bubbling). |
| 16334 | * |
| 16335 | * Returns 0 if succeeded, -1 on internal errors. |
| 16336 | */ |
| 16337 | static int |
| 16338 | xmlSchemaIDCStoreNodeTableItem(xmlSchemaValidCtxtPtr vctxt, |
| 16339 | xmlSchemaPSVIIDCNodePtr item) |
| 16340 | { |
| 16341 | /* |
| 16342 | * Add to gobal list. |
| 16343 | */ |
| 16344 | if (vctxt->idcNodes == NULL) { |
| 16345 | vctxt->idcNodes = (xmlSchemaPSVIIDCNodePtr *) |
| 16346 | xmlMalloc(20 * sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 16347 | if (vctxt->idcNodes == NULL) { |
| 16348 | xmlSchemaVErrMemory(vctxt, |
| 16349 | "allocating the IDC node table item list", NULL); |
| 16350 | return (-1); |
| 16351 | } |
| 16352 | vctxt->sizeIdcNodes = 20; |
| 16353 | } else if (vctxt->sizeIdcNodes <= vctxt->nbIdcNodes) { |
| 16354 | vctxt->sizeIdcNodes *= 2; |
| 16355 | vctxt->idcNodes = (xmlSchemaPSVIIDCNodePtr *) |
| 16356 | xmlRealloc(vctxt->idcNodes, vctxt->sizeIdcNodes * |
| 16357 | sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 16358 | if (vctxt->idcNodes == NULL) { |
| 16359 | xmlSchemaVErrMemory(vctxt, |
| 16360 | "re-allocating the IDC node table item list", NULL); |
| 16361 | return (-1); |
| 16362 | } |
| 16363 | } |
| 16364 | vctxt->idcNodes[vctxt->nbIdcNodes++] = item; |
| 16365 | |
| 16366 | return (0); |
| 16367 | } |
| 16368 | |
| 16369 | /** |
| 16370 | * xmlSchemaIDCStoreKey: |
| 16371 | * @vctxt: the WXS validation context |
| 16372 | * @item: the IDC key |
| 16373 | * |
| 16374 | * The validation context is used to store an IDC key. |
| 16375 | * |
| 16376 | * Returns 0 if succeeded, -1 on internal errors. |
| 16377 | */ |
| 16378 | static int |
| 16379 | xmlSchemaIDCStoreKey(xmlSchemaValidCtxtPtr vctxt, |
| 16380 | xmlSchemaPSVIIDCKeyPtr key) |
| 16381 | { |
| 16382 | /* |
| 16383 | * Add to gobal list. |
| 16384 | */ |
| 16385 | if (vctxt->idcKeys == NULL) { |
| 16386 | vctxt->idcKeys = (xmlSchemaPSVIIDCKeyPtr *) |
| 16387 | xmlMalloc(40 * sizeof(xmlSchemaPSVIIDCKeyPtr)); |
| 16388 | if (vctxt->idcKeys == NULL) { |
| 16389 | xmlSchemaVErrMemory(vctxt, |
| 16390 | "allocating the IDC key storage list", NULL); |
| 16391 | return (-1); |
| 16392 | } |
| 16393 | vctxt->sizeIdcKeys = 40; |
| 16394 | } else if (vctxt->sizeIdcKeys <= vctxt->nbIdcKeys) { |
| 16395 | vctxt->sizeIdcKeys *= 2; |
| 16396 | vctxt->idcKeys = (xmlSchemaPSVIIDCKeyPtr *) |
| 16397 | xmlRealloc(vctxt->idcKeys, vctxt->sizeIdcKeys * |
| 16398 | sizeof(xmlSchemaPSVIIDCKeyPtr)); |
| 16399 | if (vctxt->idcKeys == NULL) { |
| 16400 | xmlSchemaVErrMemory(vctxt, |
| 16401 | "re-allocating the IDC key storage list", NULL); |
| 16402 | return (-1); |
| 16403 | } |
| 16404 | } |
| 16405 | vctxt->idcKeys[vctxt->nbIdcKeys++] = key; |
| 16406 | |
| 16407 | return (0); |
| 16408 | } |
| 16409 | |
| 16410 | /** |
| 16411 | * xmlSchemaIDCAppendNodeTableItem: |
| 16412 | * @bind: the IDC binding |
| 16413 | * @ntItem: the node-table item |
| 16414 | * |
| 16415 | * Appends the IDC node-table item to the binding. |
| 16416 | * |
| 16417 | * Returns 0 on success and -1 on internal errors. |
| 16418 | */ |
| 16419 | static int |
| 16420 | xmlSchemaIDCAppendNodeTableItem(xmlSchemaPSVIIDCBindingPtr bind, |
| 16421 | xmlSchemaPSVIIDCNodePtr ntItem) |
| 16422 | { |
| 16423 | if (bind->nodeTable == NULL) { |
| 16424 | bind->sizeNodes = 10; |
| 16425 | bind->nodeTable = (xmlSchemaPSVIIDCNodePtr *) |
| 16426 | xmlMalloc(10 * sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 16427 | if (bind->nodeTable == NULL) { |
| 16428 | xmlSchemaVErrMemory(NULL, |
| 16429 | "allocating an array of IDC node-table items", NULL); |
| 16430 | return(-1); |
| 16431 | } |
| 16432 | } else if (bind->sizeNodes <= bind->nbNodes) { |
| 16433 | bind->sizeNodes *= 2; |
| 16434 | bind->nodeTable = (xmlSchemaPSVIIDCNodePtr *) |
| 16435 | xmlRealloc(bind->nodeTable, bind->sizeNodes * |
| 16436 | sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 16437 | if (bind->nodeTable == NULL) { |
| 16438 | xmlSchemaVErrMemory(NULL, |
| 16439 | "re-allocating an array of IDC node-table items", NULL); |
| 16440 | return(-1); |
| 16441 | } |
| 16442 | } |
| 16443 | bind->nodeTable[bind->nbNodes++] = ntItem; |
| 16444 | return(0); |
| 16445 | } |
| 16446 | |
| 16447 | /** |
| 16448 | * xmlSchemaIDCAquireBinding: |
| 16449 | * @vctxt: the WXS validation context |
| 16450 | * @matcher: the IDC matcher |
| 16451 | * |
| 16452 | * Looks up an PSVI IDC binding, for the IDC definition and |
| 16453 | * of the given matcher. If none found, a new one is created |
| 16454 | * and added to the IDC table. |
| 16455 | * |
| 16456 | * Returns an IDC binding or NULL on internal errors. |
| 16457 | */ |
| 16458 | static xmlSchemaPSVIIDCBindingPtr |
| 16459 | xmlSchemaIDCAquireBinding(xmlSchemaValidCtxtPtr vctxt, |
| 16460 | xmlSchemaIDCMatcherPtr matcher) |
| 16461 | { |
| 16462 | xmlSchemaElemInfoPtr info; |
| 16463 | |
| 16464 | info = vctxt->elemInfos[matcher->depth]; |
| 16465 | |
| 16466 | if (info->idcTable == NULL) { |
| 16467 | info->idcTable = xmlSchemaIDCNewBinding(matcher->aidc->def); |
| 16468 | if (info->idcTable == NULL) |
| 16469 | return (NULL); |
| 16470 | return(info->idcTable); |
| 16471 | } else { |
| 16472 | xmlSchemaPSVIIDCBindingPtr bind = NULL; |
| 16473 | |
| 16474 | bind = info->idcTable; |
| 16475 | do { |
| 16476 | if (bind->definition == matcher->aidc->def) |
| 16477 | return(bind); |
| 16478 | if (bind->next == NULL) { |
| 16479 | bind->next = xmlSchemaIDCNewBinding(matcher->aidc->def); |
| 16480 | if (bind->next == NULL) |
| 16481 | return (NULL); |
| 16482 | return(bind->next); |
| 16483 | } |
| 16484 | bind = bind->next; |
| 16485 | } while (bind != NULL); |
| 16486 | } |
| 16487 | return (NULL); |
| 16488 | } |
| 16489 | |
| 16490 | /** |
| 16491 | * xmlSchemaIDCFreeKey: |
| 16492 | * @key: the IDC key |
| 16493 | * |
| 16494 | * Frees an IDC key together with its compiled value. |
| 16495 | */ |
| 16496 | static void |
| 16497 | xmlSchemaIDCFreeKey(xmlSchemaPSVIIDCKeyPtr key) |
| 16498 | { |
| 16499 | if (key->compValue != NULL) |
| 16500 | xmlSchemaFreeValue(key->compValue); |
| 16501 | xmlFree(key); |
| 16502 | } |
| 16503 | |
| 16504 | /** |
| 16505 | * xmlSchemaIDCFreeBinding: |
| 16506 | * |
| 16507 | * Frees an IDC binding. Note that the node table-items |
| 16508 | * are not freed. |
| 16509 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16510 | static void |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16511 | xmlSchemaIDCFreeBinding(xmlSchemaPSVIIDCBindingPtr bind) |
| 16512 | { |
| 16513 | if (bind->nodeTable != NULL) { |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 16514 | if (bind->definition->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 16515 | int i; |
| 16516 | /* |
| 16517 | * Node-table items for keyrefs are not stored globally |
| 16518 | * to the validation context, since they are not bubbled. |
| 16519 | * We need to free them here. |
| 16520 | */ |
| 16521 | for (i = 0; i < bind->nbNodes; i++) { |
| 16522 | xmlFree(bind->nodeTable[i]->keys); |
| 16523 | xmlFree(bind->nodeTable[i]); |
| 16524 | } |
| 16525 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16526 | xmlFree(bind->nodeTable); |
| 16527 | } |
| 16528 | xmlFree(bind); |
| 16529 | } |
| 16530 | |
| 16531 | /** |
| 16532 | * xmlSchemaIDCFreeIDCTable: |
| 16533 | * @bind: the first IDC binding in the list |
| 16534 | * |
| 16535 | * Frees an IDC table, i.e. all the IDC bindings in the list. |
| 16536 | */ |
| 16537 | static void |
| 16538 | xmlSchemaIDCFreeIDCTable(xmlSchemaPSVIIDCBindingPtr bind) |
| 16539 | { |
| 16540 | xmlSchemaPSVIIDCBindingPtr prev; |
| 16541 | |
| 16542 | while (bind != NULL) { |
| 16543 | prev = bind; |
| 16544 | bind = bind->next; |
| 16545 | xmlSchemaIDCFreeBinding(prev); |
| 16546 | } |
| 16547 | } |
| 16548 | |
| 16549 | /** |
| 16550 | * xmlSchemaIDCFreeMatcherList: |
| 16551 | * @matcher: the first IDC matcher in the list |
| 16552 | * |
| 16553 | * Frees a list of IDC matchers. |
| 16554 | */ |
| 16555 | static void |
| 16556 | xmlSchemaIDCFreeMatcherList(xmlSchemaIDCMatcherPtr matcher) |
| 16557 | { |
| 16558 | xmlSchemaIDCMatcherPtr next; |
| 16559 | |
| 16560 | while (matcher != NULL) { |
| 16561 | next = matcher->next; |
| 16562 | if (matcher->keySeqs != NULL) { |
| 16563 | int i; |
| 16564 | for (i = 0; i < matcher->sizeKeySeqs; i++) |
| 16565 | if (matcher->keySeqs[i] != NULL) |
| 16566 | xmlFree(matcher->keySeqs[i]); |
| 16567 | xmlFree(matcher->keySeqs); |
| 16568 | } |
| 16569 | xmlFree(matcher); |
| 16570 | matcher = next; |
| 16571 | } |
| 16572 | } |
| 16573 | |
| 16574 | /** |
| 16575 | * xmlSchemaAreValuesEqual: |
| 16576 | * @ta: the first type |
| 16577 | * @a: the first value |
| 16578 | * @tb: the second type |
| 16579 | * @b: the second value |
| 16580 | * |
| 16581 | * Compares two values. |
| 16582 | * |
| 16583 | * Returns 1 if they are equal, 0 if not and -1 on internal errors. |
| 16584 | */ |
| 16585 | static int |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16586 | xmlSchemaAreValuesEqual(xmlSchemaValidCtxtPtr vctxt, |
| 16587 | xmlSchemaTypePtr ta, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16588 | xmlSchemaValPtr a, |
| 16589 | xmlSchemaTypePtr tb, |
| 16590 | xmlSchemaValPtr b) |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16591 | { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16592 | /* Same user derived/built-in derived/built-in primitive types. */ |
| 16593 | if (ta == tb) |
| 16594 | goto compareValue; |
| 16595 | |
| 16596 | /* |
| 16597 | * Comparison with anySimpleTypes is not supported by this implemention. |
| 16598 | */ |
| 16599 | if ((ta->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) || |
| 16600 | (tb->builtInType == XML_SCHEMAS_ANYSIMPLETYPE)) |
| 16601 | return(0); |
| 16602 | |
| 16603 | /* |
| 16604 | * 4.2.1 equal (data-types) |
| 16605 | * |
| 16606 | * the ·value space·s of all ·primitive· datatypes are disjoint |
| 16607 | * (they do not share any values) |
| 16608 | */ |
| 16609 | if ((ta->builtInType != 0) && (tb->builtInType != 0) && |
| 16610 | (ta->flags & XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE) && |
| 16611 | (tb->flags & XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE)) |
| 16612 | return(0); |
| 16613 | |
| 16614 | if ((ta->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) || |
| 16615 | (ta->flags & XML_SCHEMAS_TYPE_VARIETY_UNION) || |
| 16616 | (tb->flags & XML_SCHEMAS_TYPE_VARIETY_LIST) || |
| 16617 | (tb->flags & XML_SCHEMAS_TYPE_VARIETY_UNION)) { |
| 16618 | TODO |
| 16619 | return(0); |
| 16620 | } |
| 16621 | /* |
| 16622 | * (1) if a datatype T' is ·derived· by ·restriction· from an atomic datatype |
| 16623 | * T then the ·value space· of T' is a subset of the ·value space· of T. |
| 16624 | */ |
| 16625 | /* |
| 16626 | * (2) if datatypes T' and T'' are ·derived· by ·restriction· from a common |
| 16627 | * atomic ancestor T then the ·value space·s of T' and T'' may overlap. |
| 16628 | */ |
| 16629 | |
| 16630 | { |
| 16631 | xmlSchemaTypePtr pta = ta, ptb = tb; |
| 16632 | |
| 16633 | /* Note that we will compare the primitives here. */ |
| 16634 | while ((pta->builtInType == 0) || |
| 16635 | ((pta->flags & XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE) == 0)) |
| 16636 | pta = pta->baseType; |
| 16637 | while ((ptb->builtInType == 0) || |
| 16638 | ((ptb->flags & XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE) == 0)) |
| 16639 | ptb = ptb->baseType; |
| 16640 | if (pta == ptb) |
| 16641 | goto compareValue; |
| 16642 | return(0); |
| 16643 | } |
| 16644 | compareValue: |
| 16645 | { |
| 16646 | #ifdef IDC_VALUE_SUPPORT |
| 16647 | int ret; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 16648 | int aws, bws; |
| 16649 | |
| 16650 | aws = xmlSchemaGetWhiteSpaceFacetValue(ta); |
| 16651 | bws = xmlSchemaGetWhiteSpaceFacetValue(tb); |
| 16652 | |
| 16653 | ret = xmlSchemaCompareValuesWhtsp( |
| 16654 | a, (xmlSchemaWhitespaceValueType) aws, |
| 16655 | b, (xmlSchemaWhitespaceValueType) bws); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16656 | if (ret == 0) |
| 16657 | return(1); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16658 | else if (ret == -2) { |
| 16659 | xmlSchemaVErr(vctxt, vctxt->node, |
| 16660 | XML_SCHEMAV_INTERNAL, |
| 16661 | "Internal error: xmlSchemaAreValuesEqual, " |
| 16662 | "failed to compare the values.\n", |
| 16663 | NULL, NULL); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16664 | return(-1); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16665 | } else |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16666 | return(0); |
| 16667 | #else |
| 16668 | return (1); |
| 16669 | #endif |
| 16670 | } |
| 16671 | } |
| 16672 | |
| 16673 | /** |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16674 | * xmlSchemaIDCAddStateObject: |
| 16675 | * @vctxt: the WXS validation context |
| 16676 | * @matcher: the IDC matcher |
| 16677 | * @sel: the XPath information |
| 16678 | * @parent: the parent "selector" state object if any |
| 16679 | * @type: "selector" or "field" |
| 16680 | * |
| 16681 | * Creates/reuses and activates state objects for the given |
| 16682 | * XPath information; if the XPath expression consists of unions, |
| 16683 | * multiple state objects are created for every unioned expression. |
| 16684 | * |
| 16685 | * Returns 0 on success and -1 on internal errors. |
| 16686 | */ |
| 16687 | static int |
| 16688 | xmlSchemaIDCAddStateObject(xmlSchemaValidCtxtPtr vctxt, |
| 16689 | xmlSchemaIDCMatcherPtr matcher, |
| 16690 | xmlSchemaIDCSelectPtr sel, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16691 | int type) |
| 16692 | { |
| 16693 | xmlSchemaIDCStateObjPtr sto; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16694 | |
| 16695 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16696 | * Reuse the state objects from the pool. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16697 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16698 | if (vctxt->xpathStatePool != NULL) { |
| 16699 | sto = vctxt->xpathStatePool; |
| 16700 | vctxt->xpathStatePool = sto->next; |
| 16701 | sto->next = NULL; |
| 16702 | } else { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16703 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16704 | * Create a new state object. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16705 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16706 | sto = (xmlSchemaIDCStateObjPtr) xmlMalloc(sizeof(xmlSchemaIDCStateObj)); |
| 16707 | if (sto == NULL) { |
| 16708 | xmlSchemaVErrMemory(NULL, |
| 16709 | "allocating an IDC state object", NULL); |
| 16710 | return (-1); |
| 16711 | } |
| 16712 | memset(sto, 0, sizeof(xmlSchemaIDCStateObj)); |
| 16713 | } |
| 16714 | /* |
| 16715 | * Add to global list. |
| 16716 | */ |
| 16717 | if (vctxt->xpathStates != NULL) |
| 16718 | sto->next = vctxt->xpathStates; |
| 16719 | vctxt->xpathStates = sto; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16720 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16721 | /* |
| 16722 | * Free the old xpath validation context. |
| 16723 | */ |
| 16724 | if (sto->xpathCtxt != NULL) |
| 16725 | xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt); |
| 16726 | |
| 16727 | /* |
| 16728 | * Create a new XPath (pattern) validation context. |
| 16729 | */ |
| 16730 | sto->xpathCtxt = (void *) xmlPatternGetStreamCtxt( |
| 16731 | (xmlPatternPtr) sel->xpathComp); |
| 16732 | if (sto->xpathCtxt == NULL) { |
| 16733 | xmlSchemaVErr(vctxt, vctxt->node, |
| 16734 | XML_SCHEMAV_INTERNAL, |
| 16735 | "Internal error: xmlSchemaIDCAddStateObject, " |
| 16736 | "failed to create the XPath validation context.\n", |
| 16737 | NULL, NULL); |
| 16738 | return (-1); |
| 16739 | } |
| 16740 | sto->type = type; |
| 16741 | sto->depth = vctxt->depth; |
| 16742 | sto->matcher = matcher; |
| 16743 | sto->sel = sel; |
| 16744 | sto->nbHistory = 0; |
| 16745 | |
| 16746 | #if DEBUG_IDC |
| 16747 | xmlGenericError(xmlGenericErrorContext, "IDC: STO push '%s'\n", |
| 16748 | sto->sel->xpath); |
| 16749 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16750 | return (0); |
| 16751 | } |
| 16752 | |
| 16753 | /** |
| 16754 | * xmlSchemaXPathEvaluate: |
| 16755 | * @vctxt: the WXS validation context |
| 16756 | * @nodeType: the nodeType of the current node |
| 16757 | * |
| 16758 | * Evaluates all active XPath state objects. |
| 16759 | * |
| 16760 | * Returns the number of IC "field" state objects which resolved to |
| 16761 | * this node, 0 if none resolved and -1 on internal errors. |
| 16762 | */ |
| 16763 | static int |
| 16764 | xmlSchemaXPathEvaluate(xmlSchemaValidCtxtPtr vctxt, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16765 | xmlElementType nodeType) |
| 16766 | { |
| 16767 | xmlSchemaIDCStateObjPtr sto, head = NULL, first; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16768 | int res, resolved = 0, depth = vctxt->depth; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16769 | |
| 16770 | if (vctxt->xpathStates == NULL) |
| 16771 | return (0); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16772 | |
| 16773 | if (nodeType == XML_ATTRIBUTE_NODE) |
| 16774 | depth++; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16775 | #if DEBUG_IDC |
| 16776 | { |
| 16777 | xmlChar *str = NULL; |
| 16778 | xmlGenericError(xmlGenericErrorContext, |
| 16779 | "IDC: EVAL on %s, depth %d, type %d\n", |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16780 | xmlSchemaFormatNsUriLocal(&str, vctxt->nodeInfo->namespaceName, |
| 16781 | vctxt->nodeInfo->localName), depth, nodeType); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16782 | FREE_AND_NULL(str) |
| 16783 | } |
| 16784 | #endif |
| 16785 | /* |
| 16786 | * Process all active XPath state objects. |
| 16787 | */ |
| 16788 | first = vctxt->xpathStates; |
| 16789 | sto = first; |
| 16790 | while (sto != head) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16791 | #if DEBUG_IDC |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16792 | if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16793 | xmlGenericError(xmlGenericErrorContext, "IDC: ['%s'] selector '%s'\n", |
| 16794 | sto->matcher->aidc->def->name, sto->sel->xpath); |
| 16795 | else |
| 16796 | xmlGenericError(xmlGenericErrorContext, "IDC: ['%s'] field '%s'\n", |
| 16797 | sto->matcher->aidc->def->name, sto->sel->xpath); |
| 16798 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16799 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16800 | #ifdef IDC_XPATH_SUPPORT |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16801 | if (nodeType == XML_ELEMENT_NODE) |
| 16802 | res = xmlStreamPush((xmlStreamCtxtPtr) sto->xpathCtxt, |
| 16803 | vctxt->nodeInfo->localName, vctxt->nodeInfo->namespaceName); |
| 16804 | else |
| 16805 | res = xmlStreamPushAttr((xmlStreamCtxtPtr) sto->xpathCtxt, |
| 16806 | vctxt->nodeInfo->localName, vctxt->nodeInfo->namespaceName); |
| 16807 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16808 | #else |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16809 | res = 0; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 16810 | #endif |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16811 | if (res == -1) { |
| 16812 | xmlSchemaVErr(vctxt, vctxt->node, |
| 16813 | XML_SCHEMAV_INTERNAL, |
| 16814 | "Internal error: xmlSchemaXPathEvaluate, " |
| 16815 | "failed to evaluate a node.\n", |
| 16816 | NULL, NULL); |
| 16817 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16818 | } |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16819 | if (res == 0) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16820 | goto next_sto; |
| 16821 | /* |
| 16822 | * Full match. |
| 16823 | */ |
| 16824 | #if DEBUG_IDC |
| 16825 | xmlGenericError(xmlGenericErrorContext, "IDC: " |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16826 | "MATCH\n"); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16827 | #endif |
| 16828 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16829 | * Register a match in the state object history. |
| 16830 | */ |
| 16831 | if (sto->history == NULL) { |
| 16832 | sto->history = (int *) xmlMalloc(5 * sizeof(int)); |
| 16833 | if (sto->history == NULL) { |
| 16834 | xmlSchemaVErrMemory(NULL, |
| 16835 | "allocating the state object history", NULL); |
| 16836 | return(-1); |
| 16837 | } |
| 16838 | sto->sizeHistory = 10; |
| 16839 | } else if (sto->sizeHistory <= sto->nbHistory) { |
| 16840 | sto->sizeHistory *= 2; |
| 16841 | sto->history = (int *) xmlRealloc(sto->history, |
| 16842 | sto->sizeHistory * sizeof(int)); |
| 16843 | if (sto->history == NULL) { |
| 16844 | xmlSchemaVErrMemory(NULL, |
| 16845 | "re-allocating the state object history", NULL); |
| 16846 | return(-1); |
| 16847 | } |
| 16848 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16849 | sto->history[sto->nbHistory++] = depth; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16850 | |
| 16851 | #ifdef DEBUG_IDC |
| 16852 | xmlGenericError(xmlGenericErrorContext, "IDC: push match '%d'\n", |
| 16853 | vctxt->depth); |
| 16854 | #endif |
| 16855 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16856 | if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) { |
| 16857 | xmlSchemaIDCSelectPtr sel; |
| 16858 | /* |
| 16859 | * Activate state objects for the IDC fields of |
| 16860 | * the IDC selector. |
| 16861 | */ |
| 16862 | #if DEBUG_IDC |
| 16863 | xmlGenericError(xmlGenericErrorContext, "IDC: " |
| 16864 | "activating field states\n"); |
| 16865 | #endif |
| 16866 | sel = sto->matcher->aidc->def->fields; |
| 16867 | while (sel != NULL) { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16868 | if (xmlSchemaIDCAddStateObject(vctxt, sto->matcher, |
| 16869 | sel, XPATH_STATE_OBJ_TYPE_IDC_FIELD) == -1) |
| 16870 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16871 | sel = sel->next; |
| 16872 | } |
| 16873 | } else if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_FIELD) { |
| 16874 | /* |
| 16875 | * An IDC key node was found. |
| 16876 | */ |
| 16877 | #if DEBUG_IDC |
| 16878 | xmlGenericError(xmlGenericErrorContext, |
| 16879 | "IDC: key found\n"); |
| 16880 | #endif |
| 16881 | /* |
| 16882 | * Notify that the character value of this node is |
| 16883 | * needed. |
| 16884 | */ |
| 16885 | if (resolved == 0) |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16886 | vctxt->nodeInfo->flags |= XML_SCHEMA_ELEM_INFO_VALUE_NEEDED; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16887 | resolved++; |
| 16888 | } |
| 16889 | next_sto: |
| 16890 | if (sto->next == NULL) { |
| 16891 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16892 | * Evaluate field state objects created on this node as well. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16893 | */ |
| 16894 | head = first; |
| 16895 | sto = vctxt->xpathStates; |
| 16896 | } else |
| 16897 | sto = sto->next; |
| 16898 | } |
| 16899 | return (resolved); |
| 16900 | } |
| 16901 | |
| 16902 | /** |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 16903 | * xmlSchemaXPathProcessHistory: |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16904 | * @vctxt: the WXS validation context |
| 16905 | * @type: the simple/complex type of the current node if any at all |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 16906 | * @compValue: the precompiled value |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16907 | * |
| 16908 | * Processes and pops the history items of the IDC state objects. |
| 16909 | * IDC key-sequences are validated/created on IDC bindings. |
| 16910 | * |
| 16911 | * Returns 0 on success and -1 on internal errors. |
| 16912 | */ |
| 16913 | static int |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 16914 | xmlSchemaXPathProcessHistory(xmlSchemaValidCtxtPtr vctxt, |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16915 | int depth) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16916 | { |
| 16917 | xmlSchemaIDCStateObjPtr sto, nextsto; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16918 | int res, matchDepth; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16919 | xmlSchemaPSVIIDCKeyPtr key = NULL; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16920 | xmlSchemaTypePtr type = vctxt->nodeInfo->typeDef; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16921 | |
| 16922 | if (vctxt->xpathStates == NULL) |
| 16923 | return (0); |
| 16924 | sto = vctxt->xpathStates; |
| 16925 | |
| 16926 | #if DEBUG_IDC |
| 16927 | { |
| 16928 | xmlChar *str = NULL; |
| 16929 | xmlGenericError(xmlGenericErrorContext, |
| 16930 | "IDC: BACK on %s, depth %d\n", |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16931 | xmlSchemaFormatNsUriLocal(&str, vctxt->nodeInfo->namespaceName, |
| 16932 | vctxt->nodeInfo->localName), vctxt->depth); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16933 | FREE_AND_NULL(str) |
| 16934 | } |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 16935 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16936 | /* |
| 16937 | * Evaluate the state objects. |
| 16938 | */ |
| 16939 | while (sto != NULL) { |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 16940 | #ifdef IDC_XPATH_SUPPORT |
| 16941 | xmlStreamPop((xmlStreamCtxtPtr) sto->xpathCtxt); |
| 16942 | #if DEBUG_IDC |
| 16943 | xmlGenericError(xmlGenericErrorContext, "IDC: stream pop '%s'\n", |
| 16944 | sto->sel->xpath); |
| 16945 | #endif |
| 16946 | #endif |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16947 | if (sto->nbHistory == 0) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16948 | goto deregister_check; |
| 16949 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16950 | matchDepth = sto->history[sto->nbHistory -1]; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16951 | |
| 16952 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16953 | * Only matches at the current depth are of interest. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16954 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16955 | if (matchDepth != depth) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 16956 | sto = sto->next; |
| 16957 | continue; |
| 16958 | } |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16959 | |
| 16960 | if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_FIELD) { |
| 16961 | if (! IS_SIMPLE_TYPE(type)) { |
| 16962 | /* |
| 16963 | * Not qualified if the field resolves to a node of non |
| 16964 | * simple type. |
| 16965 | */ |
| 16966 | xmlSchemaVCustomErr(vctxt, |
| 16967 | XML_SCHEMAV_CVC_IDC, |
| 16968 | vctxt->node, |
| 16969 | (xmlSchemaTypePtr) sto->matcher->aidc->def, |
| 16970 | "The field '%s' does evaluate to a node of " |
| 16971 | "non-simple type", sto->sel->xpath); |
| 16972 | |
| 16973 | sto->nbHistory--; |
| 16974 | goto deregister_check; |
| 16975 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16976 | if ((key == NULL) && (vctxt->nodeInfo->value == NULL)) { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16977 | /* |
| 16978 | * Failed to provide the normalized value; maby |
| 16979 | * the value was invalid. |
| 16980 | */ |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 16981 | xmlSchemaVCustomErr(vctxt, |
| 16982 | XML_SCHEMAV_CVC_IDC, |
| 16983 | vctxt->nodeInfo->node, |
| 16984 | (xmlSchemaTypePtr) sto->matcher->aidc->def, |
| 16985 | "Warning: No precomputed value available, the value " |
| 16986 | "was either invalid or something strange happend", NULL); |
| 16987 | /* |
| 16988 | xmlSchemaVErr(vctxt, vctxt->nodeInfo->node, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16989 | XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 16990 | "Internal error: xmlSchemaXPathProcessHistory, " |
| 16991 | "computed value not available.\n", |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16992 | NULL, NULL); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 16993 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 16994 | sto->nbHistory--; |
| 16995 | goto deregister_check; |
| 16996 | } else { |
| 16997 | xmlSchemaIDCMatcherPtr matcher = sto->matcher; |
| 16998 | xmlSchemaPSVIIDCKeyPtr *keySeq; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 16999 | int pos, idx; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17000 | |
| 17001 | /* |
| 17002 | * The key will be anchored on the matcher's list of |
| 17003 | * key-sequences. The position in this list is determined |
| 17004 | * by the target node's depth relative to the matcher's |
| 17005 | * depth of creation (i.e. the depth of the scope element). |
| 17006 | */ |
| 17007 | pos = sto->depth - matcher->depth; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17008 | idx = sto->sel->index; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17009 | |
| 17010 | /* |
| 17011 | * Create/grow the array of key-sequences. |
| 17012 | */ |
| 17013 | if (matcher->keySeqs == NULL) { |
| 17014 | if (pos > 9) |
| 17015 | matcher->sizeKeySeqs = pos * 2; |
| 17016 | else |
| 17017 | matcher->sizeKeySeqs = 10; |
| 17018 | matcher->keySeqs = (xmlSchemaPSVIIDCKeyPtr **) |
| 17019 | xmlMalloc(matcher->sizeKeySeqs * |
| 17020 | sizeof(xmlSchemaPSVIIDCKeyPtr *)); |
| 17021 | if (matcher->keySeqs == NULL) { |
| 17022 | xmlSchemaVErrMemory(NULL, |
| 17023 | "allocating an array of key-sequences", |
| 17024 | NULL); |
| 17025 | return(-1); |
| 17026 | } |
| 17027 | memset(matcher->keySeqs, 0, |
| 17028 | matcher->sizeKeySeqs * |
| 17029 | sizeof(xmlSchemaPSVIIDCKeyPtr *)); |
| 17030 | } else if (pos >= matcher->sizeKeySeqs) { |
| 17031 | int i = matcher->sizeKeySeqs; |
| 17032 | |
| 17033 | matcher->sizeKeySeqs *= 2; |
| 17034 | matcher->keySeqs = (xmlSchemaPSVIIDCKeyPtr **) |
| 17035 | xmlRealloc(matcher->keySeqs, |
| 17036 | matcher->sizeKeySeqs * |
| 17037 | sizeof(xmlSchemaPSVIIDCKeyPtr *)); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17038 | if (matcher->keySeqs == NULL) { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17039 | xmlSchemaVErrMemory(NULL, |
| 17040 | "reallocating an array of key-sequences", |
| 17041 | NULL); |
| 17042 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17043 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17044 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17045 | * The array needs to be NULLed. |
| 17046 | * TODO: Use memset? |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17047 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17048 | for (; i < matcher->sizeKeySeqs; i++) |
| 17049 | matcher->keySeqs[i] = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17050 | } |
| 17051 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17052 | /* |
| 17053 | * Get/create the key-sequence. |
| 17054 | */ |
| 17055 | keySeq = matcher->keySeqs[pos]; |
| 17056 | if (keySeq == NULL) { |
| 17057 | goto create_sequence; |
| 17058 | } else { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17059 | if (keySeq[idx] != NULL) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17060 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17061 | * cvc-identity-constraint: |
| 17062 | * 3 For each node in the ·target node set· all |
| 17063 | * of the {fields}, with that node as the context |
| 17064 | * node, evaluate to either an empty node-set or |
| 17065 | * a node-set with exactly one member, which must |
| 17066 | * have a simple type. |
| 17067 | * |
| 17068 | * The key was already set; report an error. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17069 | */ |
| 17070 | xmlSchemaVCustomErr(vctxt, |
| 17071 | XML_SCHEMAV_CVC_IDC, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17072 | vctxt->node, (xmlSchemaTypePtr) matcher->aidc->def, |
| 17073 | "The field '%s' evaluates to a node-set " |
| 17074 | "with more than one member", sto->sel->xpath); |
| 17075 | sto->nbHistory--; |
| 17076 | goto deregister_check; |
| 17077 | } else { |
| 17078 | goto create_key; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17079 | } |
| 17080 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17081 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17082 | create_sequence: |
| 17083 | /* |
| 17084 | * Create a key-sequence. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17085 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17086 | keySeq = (xmlSchemaPSVIIDCKeyPtr *) xmlMalloc( |
| 17087 | matcher->aidc->def->nbFields * |
| 17088 | sizeof(xmlSchemaPSVIIDCKeyPtr)); |
| 17089 | if (keySeq == NULL) { |
| 17090 | xmlSchemaVErrMemory(NULL, |
| 17091 | "allocating an IDC key-sequence", NULL); |
| 17092 | return(-1); |
| 17093 | } |
| 17094 | memset(keySeq, 0, matcher->aidc->def->nbFields * |
| 17095 | sizeof(xmlSchemaPSVIIDCKeyPtr)); |
| 17096 | matcher->keySeqs[pos] = keySeq; |
| 17097 | create_key: |
| 17098 | /* |
| 17099 | * Created a key once per node only. |
| 17100 | */ |
| 17101 | if (key == NULL) { |
| 17102 | key = (xmlSchemaPSVIIDCKeyPtr) xmlMalloc( |
| 17103 | sizeof(xmlSchemaPSVIIDCKey)); |
| 17104 | if (key == NULL) { |
| 17105 | xmlSchemaVErrMemory(NULL, |
| 17106 | "allocating a IDC key", NULL); |
| 17107 | xmlFree(keySeq); |
| 17108 | matcher->keySeqs[pos] = NULL; |
| 17109 | return(-1); |
| 17110 | } |
| 17111 | /* |
| 17112 | * Consume the compiled value. |
| 17113 | */ |
| 17114 | key->type = type; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17115 | key->compValue = vctxt->nodeInfo->value; |
| 17116 | vctxt->nodeInfo->value = NULL; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17117 | /* |
| 17118 | * Store the key in a global list. |
| 17119 | */ |
| 17120 | if (xmlSchemaIDCStoreKey(vctxt, key) == -1) { |
| 17121 | xmlSchemaIDCFreeKey(key); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17122 | return (-1); |
| 17123 | } |
| 17124 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17125 | keySeq[idx] = key; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17126 | } |
| 17127 | } else if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17128 | |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17129 | xmlSchemaPSVIIDCKeyPtr **keySeq = NULL; |
| 17130 | xmlSchemaPSVIIDCBindingPtr bind; |
| 17131 | xmlSchemaPSVIIDCNodePtr ntItem; |
| 17132 | xmlSchemaIDCMatcherPtr matcher; |
| 17133 | xmlSchemaIDCPtr idc; |
| 17134 | int pos, i, j, nbKeys; |
| 17135 | /* |
| 17136 | * Here we have the following scenario: |
| 17137 | * An IDC 'selector' state object resolved to a target node, |
| 17138 | * during the time this target node was in the |
| 17139 | * ancestor-or-self axis, the 'field' state object(s) looked |
| 17140 | * out for matching nodes to create a key-sequence for this |
| 17141 | * target node. Now we are back to this target node and need |
| 17142 | * to put the key-sequence, together with the target node |
| 17143 | * itself, into the node-table of the corresponding IDC |
| 17144 | * binding. |
| 17145 | */ |
| 17146 | matcher = sto->matcher; |
| 17147 | idc = matcher->aidc->def; |
| 17148 | nbKeys = idc->nbFields; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17149 | pos = depth - matcher->depth; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17150 | /* |
| 17151 | * Check if the matcher has any key-sequences at all, plus |
| 17152 | * if it has a key-sequence for the current target node. |
| 17153 | */ |
| 17154 | if ((matcher->keySeqs == NULL) || |
| 17155 | (matcher->sizeKeySeqs <= pos)) { |
| 17156 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEY) |
| 17157 | goto selector_key_error; |
| 17158 | else |
| 17159 | goto selector_leave; |
| 17160 | } |
| 17161 | |
| 17162 | keySeq = &(matcher->keySeqs[pos]); |
| 17163 | if (*keySeq == NULL) { |
| 17164 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEY) |
| 17165 | goto selector_key_error; |
| 17166 | else |
| 17167 | goto selector_leave; |
| 17168 | } |
| 17169 | |
| 17170 | for (i = 0; i < nbKeys; i++) { |
| 17171 | if ((*keySeq)[i] == NULL) { |
| 17172 | /* |
| 17173 | * Not qualified, if not all fields did resolve. |
| 17174 | */ |
| 17175 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEY) { |
| 17176 | /* |
| 17177 | * All fields of a "key" IDC must resolve. |
| 17178 | */ |
| 17179 | goto selector_key_error; |
| 17180 | } |
| 17181 | goto selector_leave; |
| 17182 | } |
| 17183 | } |
| 17184 | /* |
| 17185 | * All fields did resolve. |
| 17186 | */ |
| 17187 | |
| 17188 | /* |
| 17189 | * 4.1 If the {identity-constraint category} is unique(/key), |
| 17190 | * then no two members of the ·qualified node set· have |
| 17191 | * ·key-sequences· whose members are pairwise equal, as |
| 17192 | * defined by Equal in [XML Schemas: Datatypes]. |
| 17193 | * |
| 17194 | * Get the IDC binding from the matcher and check for |
| 17195 | * duplicate key-sequences. |
| 17196 | */ |
| 17197 | bind = xmlSchemaIDCAquireBinding(vctxt, matcher); |
| 17198 | if ((idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) && |
| 17199 | (bind->nbNodes != 0)) { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17200 | xmlSchemaPSVIIDCKeyPtr ckey, bkey, *bkeySeq; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17201 | |
| 17202 | i = 0; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17203 | res = 0; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17204 | /* |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17205 | * Compare the key-sequences, key by key. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17206 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17207 | do { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17208 | bkeySeq = bind->nodeTable[i]->keys; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17209 | for (j = 0; j < nbKeys; j++) { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17210 | ckey = (*keySeq)[j]; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17211 | bkey = bkeySeq[j]; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17212 | res = xmlSchemaAreValuesEqual(vctxt, ckey->type, |
| 17213 | ckey->compValue, bkey->type, bkey->compValue); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17214 | if (res == -1) { |
| 17215 | return (-1); |
| 17216 | } else if (res == 0) |
| 17217 | break; |
| 17218 | } |
| 17219 | if (res == 1) { |
| 17220 | /* |
| 17221 | * Duplicate found. |
| 17222 | */ |
| 17223 | break; |
| 17224 | } |
| 17225 | i++; |
| 17226 | } while (i < bind->nbNodes); |
| 17227 | if (i != bind->nbNodes) { |
| 17228 | /* |
| 17229 | * TODO: Try to report the key-sequence. |
| 17230 | */ |
| 17231 | xmlSchemaVCustomErr(vctxt, |
| 17232 | XML_SCHEMAV_CVC_IDC, |
| 17233 | vctxt->node, |
| 17234 | (xmlSchemaTypePtr) idc, |
| 17235 | "Duplicate key-sequence found", NULL); |
| 17236 | |
| 17237 | goto selector_leave; |
| 17238 | } |
| 17239 | } |
| 17240 | /* |
| 17241 | * Add a node-table item to the IDC binding. |
| 17242 | */ |
| 17243 | ntItem = (xmlSchemaPSVIIDCNodePtr) xmlMalloc( |
| 17244 | sizeof(xmlSchemaPSVIIDCNode)); |
| 17245 | if (ntItem == NULL) { |
| 17246 | xmlSchemaVErrMemory(NULL, |
| 17247 | "allocating an IDC node-table item", NULL); |
| 17248 | xmlFree(*keySeq); |
| 17249 | *keySeq = NULL; |
| 17250 | return(-1); |
| 17251 | } |
| 17252 | memset(ntItem, 0, sizeof(xmlSchemaPSVIIDCNode)); |
| 17253 | |
| 17254 | /* |
| 17255 | * Store the node-table item on global list. |
| 17256 | */ |
| 17257 | if (idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 17258 | if (xmlSchemaIDCStoreNodeTableItem(vctxt, ntItem) == -1) { |
| 17259 | xmlFree(ntItem); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17260 | xmlFree(*keySeq); |
| 17261 | *keySeq = NULL; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17262 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17263 | } |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17264 | } |
| 17265 | /* |
| 17266 | * Init the node-table item. Consume the key-sequence. |
| 17267 | */ |
| 17268 | ntItem->node = vctxt->node; |
| 17269 | ntItem->keys = *keySeq; |
| 17270 | *keySeq = NULL; |
| 17271 | if (xmlSchemaIDCAppendNodeTableItem(bind, ntItem) == -1) { |
| 17272 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 17273 | /* |
| 17274 | * Free the item, since keyref items won't be |
| 17275 | * put on a global list. |
| 17276 | */ |
| 17277 | xmlFree(ntItem->keys); |
| 17278 | xmlFree(ntItem); |
| 17279 | } |
| 17280 | return (-1); |
| 17281 | } |
| 17282 | |
| 17283 | goto selector_leave; |
| 17284 | selector_key_error: |
| 17285 | /* |
| 17286 | * 4.2.1 (KEY) The ·target node set· and the |
| 17287 | * ·qualified node set· are equal, that is, every |
| 17288 | * member of the ·target node set· is also a member |
| 17289 | * of the ·qualified node set· and vice versa. |
| 17290 | */ |
| 17291 | xmlSchemaVCustomErr(vctxt, |
| 17292 | XML_SCHEMAV_CVC_IDC, |
| 17293 | vctxt->node, |
| 17294 | (xmlSchemaTypePtr) idc, |
| 17295 | "All 'key' fields must evaluate to a node", |
| 17296 | NULL); |
| 17297 | selector_leave: |
| 17298 | /* |
| 17299 | * Free the key-sequence if not added to the IDC table. |
| 17300 | */ |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 17301 | if ((keySeq != NULL) && (*keySeq != NULL)) { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17302 | xmlFree(*keySeq); |
| 17303 | *keySeq = NULL; |
| 17304 | } |
| 17305 | } /* if selector */ |
| 17306 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17307 | sto->nbHistory--; |
| 17308 | |
| 17309 | deregister_check: |
| 17310 | /* |
| 17311 | * Deregister state objects if they reach the depth of creation. |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17312 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17313 | if ((sto->nbHistory == 0) && (sto->depth == depth)) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17314 | #if DEBUG_IDC |
| 17315 | xmlGenericError(xmlGenericErrorContext, "IDC: STO pop '%s'\n", |
| 17316 | sto->sel->xpath); |
| 17317 | #endif |
| 17318 | if (vctxt->xpathStates != sto) { |
| 17319 | xmlSchemaVErr(vctxt, vctxt->node, |
| 17320 | XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 17321 | "Internal error: xmlSchemaXPathProcessHistory, " |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17322 | "The state object to be removed is not the first " |
| 17323 | "in the list.\n", |
| 17324 | NULL, NULL); |
| 17325 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17326 | nextsto = sto->next; |
| 17327 | /* |
| 17328 | * Unlink from the list of active XPath state objects. |
| 17329 | */ |
| 17330 | vctxt->xpathStates = sto->next; |
| 17331 | sto->next = vctxt->xpathStatePool; |
| 17332 | /* |
| 17333 | * Link it to the pool of reusable state objects. |
| 17334 | */ |
| 17335 | vctxt->xpathStatePool = sto; |
| 17336 | sto = nextsto; |
| 17337 | } else |
| 17338 | sto = sto->next; |
| 17339 | } /* while (sto != NULL) */ |
| 17340 | return (0); |
| 17341 | } |
| 17342 | |
| 17343 | /** |
| 17344 | * xmlSchemaIDCRegisterMatchers: |
| 17345 | * @vctxt: the WXS validation context |
| 17346 | * @elemDecl: the element declaration |
| 17347 | * |
| 17348 | * Creates helper objects to evaluate IDC selectors/fields |
| 17349 | * successively. |
| 17350 | * |
| 17351 | * Returns 0 if OK and -1 on internal errors. |
| 17352 | */ |
| 17353 | static int |
| 17354 | xmlSchemaIDCRegisterMatchers(xmlSchemaValidCtxtPtr vctxt, |
| 17355 | xmlSchemaElementPtr elemDecl) |
| 17356 | { |
| 17357 | xmlSchemaIDCMatcherPtr matcher, last = NULL; |
| 17358 | xmlSchemaIDCPtr idc, refIdc; |
| 17359 | xmlSchemaIDCAugPtr aidc; |
| 17360 | |
| 17361 | idc = (xmlSchemaIDCPtr) elemDecl->idcs; |
| 17362 | if (idc == NULL) |
| 17363 | return (0); |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 17364 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17365 | #if DEBUG_IDC |
| 17366 | { |
| 17367 | xmlChar *str = NULL; |
| 17368 | xmlGenericError(xmlGenericErrorContext, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17369 | "IDC: REGISTER on %s, depth %d\n", |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17370 | (char *) xmlSchemaFormatNsUriLocal(&str, vctxt->nodeInfo->namespaceName, |
| 17371 | vctxt->nodeInfo->localName), vctxt->depth); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17372 | FREE_AND_NULL(str) |
| 17373 | } |
| 17374 | #endif |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17375 | if (vctxt->nodeInfo->idcMatchers != NULL) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17376 | xmlSchemaVErr(vctxt, vctxt->node, |
| 17377 | XML_SCHEMAV_INTERNAL, |
| 17378 | "Internal error: xmlSchemaIDCRegisterMatchers: " |
| 17379 | "The chain of IDC matchers is expected to be empty.\n", |
| 17380 | NULL, NULL); |
| 17381 | return (-1); |
| 17382 | } |
| 17383 | do { |
| 17384 | if (idc->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 17385 | /* |
| 17386 | * Since IDCs bubbles are expensive we need to know the |
| 17387 | * depth at which the bubbles should stop; this will be |
| 17388 | * the depth of the top-most keyref IDC. If no keyref |
| 17389 | * references a key/unique IDC, the bubbleDepth will |
| 17390 | * be -1, indicating that no bubbles are needed. |
| 17391 | */ |
| 17392 | refIdc = (xmlSchemaIDCPtr) idc->ref->item; |
| 17393 | if (refIdc != NULL) { |
| 17394 | /* |
| 17395 | * Lookup the augmented IDC. |
| 17396 | */ |
| 17397 | aidc = vctxt->aidcs; |
| 17398 | while (aidc != NULL) { |
| 17399 | if (aidc->def == refIdc) |
| 17400 | break; |
| 17401 | aidc = aidc->next; |
| 17402 | } |
| 17403 | if (aidc == NULL) { |
| 17404 | xmlSchemaVErr(vctxt, vctxt->node, |
| 17405 | XML_SCHEMAV_INTERNAL, |
| 17406 | "Internal error: xmlSchemaIDCRegisterMatchers: " |
| 17407 | "Could not find an augmented IDC item for an IDC " |
| 17408 | "definition.\n", |
| 17409 | NULL, NULL); |
| 17410 | return (-1); |
| 17411 | } |
| 17412 | if ((aidc->bubbleDepth == -1) || |
| 17413 | (vctxt->depth < aidc->bubbleDepth)) |
| 17414 | aidc->bubbleDepth = vctxt->depth; |
| 17415 | } |
| 17416 | } |
| 17417 | /* |
| 17418 | * Lookup the augmented IDC item for the IDC definition. |
| 17419 | */ |
| 17420 | aidc = vctxt->aidcs; |
| 17421 | while (aidc != NULL) { |
| 17422 | if (aidc->def == idc) |
| 17423 | break; |
| 17424 | aidc = aidc->next; |
| 17425 | } |
| 17426 | if (aidc == NULL) { |
| 17427 | xmlSchemaVErr(vctxt, vctxt->node, |
| 17428 | XML_SCHEMAV_INTERNAL, |
| 17429 | "Internal error: xmlSchemaIDCRegisterMatchers: " |
| 17430 | "Could not find an augmented IDC item for an IDC definition.\n", |
| 17431 | NULL, NULL); |
| 17432 | return (-1); |
| 17433 | } |
| 17434 | /* |
| 17435 | * Create an IDC matcher for every IDC definition. |
| 17436 | */ |
| 17437 | matcher = (xmlSchemaIDCMatcherPtr) |
| 17438 | xmlMalloc(sizeof(xmlSchemaIDCMatcher)); |
| 17439 | if (matcher == NULL) { |
| 17440 | xmlSchemaVErrMemory(vctxt, |
| 17441 | "allocating an IDC matcher", NULL); |
| 17442 | return (-1); |
| 17443 | } |
| 17444 | memset(matcher, 0, sizeof(xmlSchemaIDCMatcher)); |
| 17445 | if (last == NULL) |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17446 | vctxt->nodeInfo->idcMatchers = matcher; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17447 | else |
| 17448 | last->next = matcher; |
| 17449 | last = matcher; |
| 17450 | |
| 17451 | matcher->type = IDC_MATCHER; |
| 17452 | matcher->depth = vctxt->depth; |
| 17453 | matcher->aidc = aidc; |
| 17454 | #if DEBUG_IDC |
| 17455 | xmlGenericError(xmlGenericErrorContext, "IDC: register matcher\n"); |
| 17456 | #endif |
| 17457 | /* |
| 17458 | * Init the automaton state object. |
| 17459 | */ |
| 17460 | if (xmlSchemaIDCAddStateObject(vctxt, matcher, |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17461 | idc->selector, XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) == -1) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17462 | return (-1); |
| 17463 | |
| 17464 | idc = idc->next; |
| 17465 | } while (idc != NULL); |
| 17466 | return (0); |
| 17467 | } |
| 17468 | |
| 17469 | /** |
| 17470 | * xmlSchemaBubbleIDCNodeTables: |
| 17471 | * @depth: the current tree depth |
| 17472 | * |
| 17473 | * Merges IDC bindings of an element at @depth into the corresponding IDC |
| 17474 | * bindings of its parent element. If a duplicate note-table entry is found, |
| 17475 | * both, the parent node-table entry and child entry are discarded from the |
| 17476 | * node-table of the parent. |
| 17477 | * |
| 17478 | * Returns 0 if OK and -1 on internal errors. |
| 17479 | */ |
| 17480 | static int |
| 17481 | xmlSchemaBubbleIDCNodeTables(xmlSchemaValidCtxtPtr vctxt) |
| 17482 | { |
| 17483 | xmlSchemaPSVIIDCBindingPtr bind; /* IDC bindings of the current node. */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17484 | xmlSchemaPSVIIDCBindingPtr *parTable, parBind = NULL, lastParBind = NULL; /* parent IDC bindings. */ |
| 17485 | xmlSchemaPSVIIDCNodePtr node, parNode = NULL; /* node-table entries. */ |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17486 | xmlSchemaPSVIIDCKeyPtr key, parKey; /* keys of in a key-sequence. */ |
| 17487 | xmlSchemaIDCAugPtr aidc; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17488 | int i, j, k, ret = 0, oldNum, newDupls = 0; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17489 | int duplTop; |
| 17490 | |
| 17491 | /* |
| 17492 | * The node table has the following sections: |
| 17493 | * |
| 17494 | * O --> old node-table entries (first) |
| 17495 | * O |
| 17496 | * + --> new node-table entries |
| 17497 | * + |
| 17498 | * % --> new duplicate node-table entries |
| 17499 | * % |
| 17500 | * # --> old duplicate node-table entries |
| 17501 | * # (last) |
| 17502 | * |
| 17503 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17504 | bind = vctxt->nodeInfo->idcTable; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17505 | if (bind == NULL) { |
| 17506 | /* Fine, no table, no bubbles. */ |
| 17507 | return (0); |
| 17508 | } |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 17509 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17510 | parTable = &(vctxt->elemInfos[vctxt->depth -1]->idcTable); |
| 17511 | /* |
| 17512 | * Walk all bindings; create new or add to existing bindings. |
| 17513 | * Remove duplicate key-sequences. |
| 17514 | */ |
| 17515 | start_binding: |
| 17516 | while (bind != NULL) { |
| 17517 | /* |
| 17518 | * Skip keyref IDCs. |
| 17519 | */ |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17520 | if (bind->definition->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 17521 | bind = bind->next; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17522 | continue; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17523 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17524 | /* |
| 17525 | * Check if the key/unique IDC table needs to be bubbled. |
| 17526 | */ |
| 17527 | aidc = vctxt->aidcs; |
| 17528 | do { |
| 17529 | if (aidc->def == bind->definition) { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17530 | if (aidc->bubbleDepth >= vctxt->depth) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17531 | bind = bind->next; |
| 17532 | goto start_binding; |
| 17533 | } |
| 17534 | break; |
| 17535 | } |
| 17536 | aidc = aidc->next; |
| 17537 | } while (aidc != NULL); |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17538 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17539 | if (parTable != NULL) |
| 17540 | parBind = *parTable; |
| 17541 | while (parBind != NULL) { |
| 17542 | /* |
| 17543 | * Search a matching parent binding for the |
| 17544 | * IDC definition. |
| 17545 | */ |
| 17546 | if (parBind->definition == bind->definition) { |
| 17547 | |
| 17548 | /* |
| 17549 | * Compare every node-table entry of the child node, |
| 17550 | * i.e. the key-sequence within, ... |
| 17551 | */ |
| 17552 | oldNum = parBind->nbNodes; /* Skip newly added items. */ |
| 17553 | duplTop = oldNum + parBind->nbDupls; |
| 17554 | |
| 17555 | for (i = 0; i < bind->nbNodes; i++) { |
| 17556 | node = bind->nodeTable[i]; |
| 17557 | if (node == NULL) |
| 17558 | continue; |
| 17559 | /* |
| 17560 | * ...with every key-sequence of the parent node, already |
| 17561 | * evaluated to be a duplicate key-sequence. |
| 17562 | */ |
| 17563 | if (parBind->nbDupls != 0) { |
| 17564 | j = bind->nbNodes + newDupls; |
| 17565 | while (j < duplTop) { |
| 17566 | parNode = parBind->nodeTable[j]; |
| 17567 | for (k = 0; k < bind->definition->nbFields; k++) { |
| 17568 | key = node->keys[k]; |
| 17569 | parKey = parNode->keys[k]; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17570 | ret = xmlSchemaAreValuesEqual(vctxt, key->type, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17571 | key->compValue, |
| 17572 | parKey->type, parKey->compValue); |
| 17573 | if (ret == -1) { |
| 17574 | /* TODO: Internal error */ |
| 17575 | return(-1); |
| 17576 | } else if (ret == 0) |
| 17577 | break; |
| 17578 | |
| 17579 | } |
| 17580 | if (ret == 1) |
| 17581 | /* Duplicate found. */ |
| 17582 | break; |
| 17583 | j++; |
| 17584 | } |
| 17585 | if (j != duplTop) { |
| 17586 | /* Duplicate found. */ |
| 17587 | continue; |
| 17588 | } |
| 17589 | } |
| 17590 | /* |
| 17591 | * ... and with every key-sequence of the parent node. |
| 17592 | */ |
| 17593 | j = 0; |
| 17594 | while (j < oldNum) { |
| 17595 | parNode = parBind->nodeTable[j]; |
| 17596 | /* |
| 17597 | * Compare key by key. |
| 17598 | */ |
| 17599 | for (k = 0; k < parBind->definition->nbFields; k++) { |
| 17600 | key = node->keys[k]; |
| 17601 | parKey = parNode->keys[k]; |
| 17602 | |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17603 | ret = xmlSchemaAreValuesEqual(vctxt, key->type, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17604 | key->compValue, |
| 17605 | parKey->type, parKey->compValue); |
| 17606 | if (ret == -1) { |
| 17607 | /* TODO: Internal error */ |
| 17608 | } else if (ret == 0) |
| 17609 | break; |
| 17610 | |
| 17611 | } |
| 17612 | if (ret == 1) |
| 17613 | /* |
| 17614 | * The key-sequences are equal. |
| 17615 | */ |
| 17616 | break; |
| 17617 | j++; |
| 17618 | } |
| 17619 | if (j != oldNum) { |
| 17620 | /* |
| 17621 | * Handle duplicates. |
| 17622 | */ |
| 17623 | newDupls++; |
| 17624 | oldNum--; |
| 17625 | parBind->nbNodes--; |
| 17626 | /* |
| 17627 | * Move last old item to pos of duplicate. |
| 17628 | */ |
| 17629 | parBind->nodeTable[j] = |
| 17630 | parBind->nodeTable[oldNum]; |
| 17631 | |
| 17632 | if (parBind->nbNodes != oldNum) { |
| 17633 | /* |
| 17634 | * If new items exist, move last new item to |
| 17635 | * last of old items. |
| 17636 | */ |
| 17637 | parBind->nodeTable[oldNum] = |
| 17638 | parBind->nodeTable[parBind->nbNodes]; |
| 17639 | } |
| 17640 | /* |
| 17641 | * Move duplicate to last pos of new/old items. |
| 17642 | */ |
| 17643 | parBind->nodeTable[parBind->nbNodes] = parNode; |
| 17644 | |
| 17645 | } else { |
| 17646 | /* |
| 17647 | * Add the node-table entry (node and key-sequence) of |
| 17648 | * the child node to the node table of the parent node. |
| 17649 | */ |
| 17650 | if (parBind->nodeTable == NULL) { |
| 17651 | parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *) |
| 17652 | xmlMalloc(1 * sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 17653 | if (parBind->nodeTable == NULL) { |
| 17654 | xmlSchemaVErrMemory(NULL, |
| 17655 | "allocating IDC list of node-table items", NULL); |
| 17656 | return(-1); |
| 17657 | } |
| 17658 | parBind->sizeNodes = 1; |
| 17659 | } else if (duplTop >= parBind->sizeNodes) { |
| 17660 | parBind->sizeNodes++; |
| 17661 | parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *) |
| 17662 | xmlRealloc(parBind->nodeTable, parBind->sizeNodes * |
| 17663 | sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 17664 | if (parBind->nodeTable == NULL) { |
| 17665 | xmlSchemaVErrMemory(NULL, |
| 17666 | "re-allocating IDC list of node-table items", NULL); |
| 17667 | return(-1); |
| 17668 | } |
| 17669 | } |
| 17670 | |
| 17671 | /* |
| 17672 | * Move first old duplicate to last position |
| 17673 | * of old duplicates +1. |
| 17674 | */ |
| 17675 | if (parBind->nbDupls != 0) { |
| 17676 | parBind->nodeTable[duplTop] = |
| 17677 | parBind->nodeTable[parBind->nbNodes + newDupls]; |
| 17678 | } |
| 17679 | /* |
| 17680 | * Move first new duplicate to last position of |
| 17681 | * new duplicates +1. |
| 17682 | */ |
| 17683 | if (newDupls != 0) { |
| 17684 | parBind->nodeTable[parBind->nbNodes + newDupls] = |
| 17685 | parBind->nodeTable[parBind->nbNodes]; |
| 17686 | } |
| 17687 | /* |
| 17688 | * Append the new node-table entry to the 'new node-table |
| 17689 | * entries' section. |
| 17690 | */ |
| 17691 | parBind->nodeTable[parBind->nbNodes] = node; |
| 17692 | parBind->nbNodes++; |
| 17693 | duplTop++; |
| 17694 | } |
| 17695 | } |
| 17696 | parBind->nbDupls += newDupls; |
| 17697 | break; |
| 17698 | } |
| 17699 | if (parBind->next == NULL) |
| 17700 | lastParBind = parBind; |
| 17701 | parBind = parBind->next; |
| 17702 | } |
| 17703 | if (parBind == NULL) { |
| 17704 | /* |
| 17705 | * No binding for the IDC was found: create a new one and |
| 17706 | * copy all node-tables. |
| 17707 | */ |
| 17708 | parBind = xmlSchemaIDCNewBinding(bind->definition); |
| 17709 | if (parBind == NULL) |
| 17710 | return(-1); |
| 17711 | |
| 17712 | parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *) |
| 17713 | xmlMalloc(bind->nbNodes * sizeof(xmlSchemaPSVIIDCNodePtr)); |
| 17714 | if (parBind->nodeTable == NULL) { |
| 17715 | xmlSchemaVErrMemory(NULL, |
| 17716 | "allocating an array of IDC node-table items", NULL); |
| 17717 | xmlSchemaIDCFreeBinding(parBind); |
| 17718 | return(-1); |
| 17719 | } |
| 17720 | parBind->sizeNodes = bind->nbNodes; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17721 | parBind->nbNodes = bind->nbNodes; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17722 | memcpy(parBind->nodeTable, bind->nodeTable, |
| 17723 | bind->nbNodes * sizeof(xmlSchemaPSVIIDCNodePtr)); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17724 | if (*parTable == NULL) |
| 17725 | *parTable = parBind; |
| 17726 | else |
| 17727 | lastParBind->next = parBind; |
| 17728 | } |
| 17729 | bind = bind->next; |
| 17730 | } |
| 17731 | return (0); |
| 17732 | } |
| 17733 | |
| 17734 | /** |
| 17735 | * xmlSchemaCheckCVCIDCKeyRef: |
| 17736 | * @vctxt: the WXS validation context |
| 17737 | * @elemDecl: the element declaration |
| 17738 | * |
| 17739 | * Check the cvc-idc-keyref constraints. |
| 17740 | */ |
| 17741 | static int |
| 17742 | xmlSchemaCheckCVCIDCKeyRef(xmlSchemaValidCtxtPtr vctxt) |
| 17743 | { |
| 17744 | xmlSchemaPSVIIDCBindingPtr refbind, bind; |
| 17745 | |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17746 | refbind = vctxt->nodeInfo->idcTable; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17747 | /* |
| 17748 | * Find a keyref. |
| 17749 | */ |
| 17750 | while (refbind != NULL) { |
| 17751 | if (refbind->definition->type == XML_SCHEMA_TYPE_IDC_KEYREF) { |
| 17752 | int i, j, k, res; |
| 17753 | xmlSchemaPSVIIDCKeyPtr *refKeys, *keys; |
| 17754 | xmlSchemaPSVIIDCKeyPtr refKey, key; |
| 17755 | |
| 17756 | /* |
| 17757 | * Find the referred key/unique. |
| 17758 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17759 | bind = vctxt->nodeInfo->idcTable; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17760 | do { |
| 17761 | if ((xmlSchemaIDCPtr) refbind->definition->ref->item == |
| 17762 | bind->definition) |
| 17763 | break; |
| 17764 | bind = bind->next; |
| 17765 | } while (bind != NULL); |
| 17766 | |
| 17767 | /* |
| 17768 | * Search for a matching key-sequences. |
| 17769 | */ |
| 17770 | for (i = 0; i < refbind->nbNodes; i++) { |
| 17771 | res = 0; |
| 17772 | if (bind != NULL) { |
| 17773 | refKeys = refbind->nodeTable[i]->keys; |
| 17774 | for (j = 0; j < bind->nbNodes; j++) { |
| 17775 | keys = bind->nodeTable[j]->keys; |
| 17776 | for (k = 0; k < bind->definition->nbFields; k++) { |
| 17777 | refKey = refKeys[k]; |
| 17778 | key = keys[k]; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17779 | res = xmlSchemaAreValuesEqual(vctxt, |
| 17780 | key->type, key->compValue, |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17781 | refKey->type, refKey->compValue); |
| 17782 | if (res == 0) |
| 17783 | break; |
| 17784 | else if (res == -1) { |
| 17785 | return (-1); |
| 17786 | } |
| 17787 | } |
| 17788 | if (res == 1) { |
| 17789 | /* |
| 17790 | * Match found. |
| 17791 | */ |
| 17792 | break; |
| 17793 | } |
| 17794 | } |
| 17795 | } |
| 17796 | if (res == 0) { |
| 17797 | /* TODO: Report the key-sequence. */ |
| 17798 | xmlSchemaVCustomErr(vctxt, |
| 17799 | XML_SCHEMAV_CVC_IDC, |
| 17800 | refbind->nodeTable[i]->node, |
| 17801 | (xmlSchemaTypePtr) refbind->definition, |
| 17802 | "No matching key-sequence found", NULL); |
| 17803 | } |
| 17804 | } |
| 17805 | } |
| 17806 | refbind = refbind->next; |
| 17807 | } |
| 17808 | return (0); |
| 17809 | } |
| 17810 | #endif /* IDC_ENABLED */ |
| 17811 | |
| 17812 | #ifdef ELEM_INFO_ENABLED |
| 17813 | /** |
| 17814 | * xmlSchemaBeginElement: |
| 17815 | * @vctxt: the WXS validation context |
| 17816 | * |
| 17817 | * Just a temporary workaround to simulate streaming validation |
| 17818 | * a bit. |
| 17819 | */ |
| 17820 | static void |
| 17821 | xmlSchemaBeginElement(xmlSchemaValidCtxtPtr vctxt) |
| 17822 | { |
| 17823 | vctxt->depth++; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17824 | vctxt->nodeInfo = xmlSchemaGetFreshElemInfo(vctxt, vctxt->depth); |
| 17825 | vctxt->nodeInfo->node = vctxt->node; |
| 17826 | vctxt->nodeInfo->localName = vctxt->node->name; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17827 | if (vctxt->node->ns != NULL) |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17828 | vctxt->nodeInfo->namespaceName = vctxt->node->ns->href; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17829 | else |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17830 | vctxt->nodeInfo->namespaceName = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17831 | } |
| 17832 | |
| 17833 | /** |
| 17834 | * xmlSchemaEndElement: |
| 17835 | * @vctxt: the WXS validation context |
| 17836 | * |
| 17837 | * Just a temporary workaround to simulate streaming validation |
| 17838 | * a bit. |
| 17839 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17840 | static int |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17841 | xmlSchemaEndElement(xmlSchemaValidCtxtPtr vctxt) |
| 17842 | { |
| 17843 | if (vctxt->depth < 0) { |
| 17844 | /* TODO: raise error? */ |
| 17845 | vctxt->depth--; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17846 | return (0); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17847 | } |
| 17848 | #ifdef IDC_ENABLED |
| 17849 | /* |
| 17850 | * Evaluate the history of changes of active state objects. |
| 17851 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17852 | if (xmlSchemaXPathProcessHistory(vctxt, vctxt->depth) == -1) |
| 17853 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17854 | |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17855 | if (vctxt->nodeInfo->value != NULL) { |
| 17856 | xmlSchemaFreeValue(vctxt->nodeInfo->value); |
| 17857 | vctxt->nodeInfo->value = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17858 | } |
| 17859 | /* |
| 17860 | * TODO: 6 The element information item must be ·valid· with respect to each of |
| 17861 | * the {identity-constraint definitions} as per Identity-constraint |
| 17862 | * Satisfied (§3.11.4). |
| 17863 | */ |
| 17864 | /* |
| 17865 | * Validate IDC keyrefs. |
| 17866 | */ |
| 17867 | xmlSchemaCheckCVCIDCKeyRef(vctxt); |
| 17868 | #endif |
| 17869 | |
| 17870 | /* |
| 17871 | * Merge/free the IDC table. |
| 17872 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17873 | if (vctxt->nodeInfo->idcTable != NULL) { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 17874 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17875 | #ifdef DEBUG_IDC |
| 17876 | xmlSchemaDebugDumpIDCTable(stdout, |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17877 | vctxt->nodeInfo->namespaceName, |
| 17878 | vctxt->nodeInfo->localName, |
| 17879 | vctxt->nodeInfo->idcTable); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17880 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17881 | if (vctxt->depth > 0) { |
| 17882 | /* |
| 17883 | * Merge the IDC node table with the table of the parent node. |
| 17884 | */ |
| 17885 | xmlSchemaBubbleIDCNodeTables(vctxt); |
| 17886 | } |
| 17887 | /* |
| 17888 | * TODO: Don't free the PSVI IDC tables if they are |
| 17889 | * requested for the PSVI. |
| 17890 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17891 | xmlSchemaIDCFreeIDCTable(vctxt->nodeInfo->idcTable); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17892 | #endif |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17893 | vctxt->nodeInfo->idcTable = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17894 | } |
| 17895 | |
| 17896 | /* |
| 17897 | * Cleanup IDC matchers. |
| 17898 | */ |
| 17899 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17900 | if (vctxt->nodeInfo->idcMatchers != NULL) { |
| 17901 | xmlSchemaIDCFreeMatcherList(vctxt->nodeInfo->idcMatchers); |
| 17902 | vctxt->nodeInfo->idcMatchers = NULL; |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17903 | } |
| 17904 | #endif |
| 17905 | |
| 17906 | /* |
| 17907 | * Skip further processing if we are on the validation root. |
| 17908 | */ |
| 17909 | if (vctxt->depth == 0) { |
| 17910 | vctxt->depth--; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17911 | return (0); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17912 | } |
| 17913 | |
| 17914 | /* |
| 17915 | * Reset the bubbleDepth if needed. |
| 17916 | */ |
| 17917 | #ifdef IDC_ENABLED |
| 17918 | if (vctxt->aidcs != NULL) { |
| 17919 | xmlSchemaIDCAugPtr aidc = vctxt->aidcs; |
| 17920 | do { |
| 17921 | if (aidc->bubbleDepth == vctxt->depth) { |
| 17922 | /* |
| 17923 | * A bubbleDepth of a key/unique IDC matches the current |
| 17924 | * depth, this means that we are leaving the scope of the |
| 17925 | * top-most keyref IDC. |
| 17926 | */ |
| 17927 | aidc->bubbleDepth = -1; |
| 17928 | } |
| 17929 | aidc = aidc->next; |
| 17930 | } while (aidc != NULL); |
| 17931 | } |
| 17932 | #endif |
| 17933 | vctxt->depth--; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 17934 | /* |
| 17935 | * Clear the current elemInfo. |
| 17936 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17937 | if (vctxt->nodeInfo->value != NULL) { |
| 17938 | xmlSchemaFreeValue(vctxt->nodeInfo->value); |
| 17939 | vctxt->nodeInfo->value = NULL; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 17940 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 17941 | vctxt->nodeInfo = vctxt->elemInfos[vctxt->depth]; |
| 17942 | vctxt->node = vctxt->nodeInfo->node; |
| 17943 | |
| 17944 | return (0); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17945 | } |
| 17946 | |
| 17947 | #endif /* ELEM_INFO_ENABLED */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17948 | |
| 17949 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17950 | * xmlSchemaValidateElementByDeclaration: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17951 | * @ctxt: a schema validation context |
| 17952 | * @node: the top node. |
| 17953 | * |
| 17954 | * Validate the content of an element type. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17955 | * Validation Rule: Element Locally Valid (Element) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17956 | * |
| 17957 | * Returns 0 if the element is schemas valid, a positive error code |
| 17958 | * number otherwise and -1 in case of internal or API error. |
| 17959 | */ |
| 17960 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17961 | xmlSchemaValidateElementByDeclaration(xmlSchemaValidCtxtPtr ctxt, |
| 17962 | xmlSchemaElementPtr elemDecl) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17963 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17964 | xmlNodePtr elem; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17965 | int ret = 0; |
| 17966 | xmlSchemaTypePtr actualType = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17967 | xmlAttrPtr attr; |
| 17968 | xmlChar *attrValue; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17969 | int nilled = 0, elemHasContent = -1; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 17970 | |
| 17971 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17972 | * This one is called by xmlSchemaValidateElementByWildcardInternal, |
| 17973 | * xmlSchemaValidateElementByAnyType and xmlSchemaValidateElement. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 17974 | * Note that @elemDecl will be the declaration and never the |
| 17975 | * reference to a declaration. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17976 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 17977 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17978 | if (ctxt == NULL) { |
| 17979 | xmlSchemaVErr(ctxt, NULL, XML_SCHEMAV_INTERNAL, |
| 17980 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 17981 | "bad arguments.\n", |
| 17982 | NULL, NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 17983 | return (-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 17984 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 17985 | |
| 17986 | elem = ctxt->node; |
| 17987 | |
| 17988 | /* |
| 17989 | * cvc-elt (3.3.4) : 1 |
| 17990 | */ |
| 17991 | if (elemDecl == NULL) { |
| 17992 | xmlSchemaVCustomErr(ctxt, |
| 17993 | XML_SCHEMAV_CVC_ELT_1, |
| 17994 | elem, NULL, |
| 17995 | "No matching declaration available", NULL); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 17996 | /* |
| 17997 | * Evaluate IDCs even if an error occured. |
| 17998 | */ |
| 17999 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18000 | if (xmlSchemaXPathEvaluate(ctxt, XML_ELEMENT_NODE) == -1) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18001 | return (-1); |
| 18002 | #endif |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18003 | return (ctxt->err); |
| 18004 | } |
| 18005 | /* |
| 18006 | * cvc-elt (3.3.4) : 2 |
| 18007 | */ |
| 18008 | if (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT) { |
| 18009 | xmlSchemaVCustomErr(ctxt, |
| 18010 | XML_SCHEMAV_CVC_ELT_2, |
| 18011 | elem, NULL, |
| 18012 | "The element declaration is abstract", NULL); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18013 | /* |
| 18014 | * Evaluate IDCs even if an error occured. |
| 18015 | */ |
| 18016 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18017 | if (xmlSchemaXPathEvaluate(ctxt, XML_ELEMENT_NODE) == -1) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18018 | return (-1); |
| 18019 | #endif |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18020 | return (ctxt->err); |
| 18021 | } |
| 18022 | |
| 18023 | /* |
| 18024 | * cvc-elt (3.3.4) : 3 |
| 18025 | * Handle 'xsi:nil'. |
| 18026 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18027 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18028 | attr = xmlHasNsProp(elem, BAD_CAST "nil", xmlSchemaInstanceNs); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18029 | if (attr != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18030 | attrValue = xmlNodeGetContent((xmlNodePtr) attr); |
| 18031 | ctxt->node = (xmlNodePtr) attr; |
| 18032 | ctxt->cur = attr->children; |
| 18033 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, |
| 18034 | xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN), |
| 18035 | BAD_CAST attrValue, 1, 1, 1, 1); |
| 18036 | ctxt->node = elem; |
| 18037 | ctxt->type = (xmlSchemaTypePtr) elemDecl; |
| 18038 | if (ret < 0) { |
| 18039 | xmlSchemaVCustomErr(ctxt, |
| 18040 | XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18041 | (xmlNodePtr) attr, (xmlSchemaTypePtr) elemDecl, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18042 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 18043 | "validating the attribute 'xsi:nil'", NULL); |
| 18044 | if (attrValue != NULL) |
| 18045 | xmlFree(attrValue); |
| 18046 | return (-1); |
| 18047 | } |
| 18048 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_NILLABLE) == 0) { |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18049 | /* |
| 18050 | * cvc-elt (3.3.4) : 3.1 |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18051 | */ |
| 18052 | xmlSchemaVCustomErr(ctxt, |
| 18053 | XML_SCHEMAV_CVC_ELT_3_1, |
| 18054 | elem, NULL, |
| 18055 | "The element is not 'nillable'", NULL); |
| 18056 | } else { |
| 18057 | if (xmlStrEqual(BAD_CAST attrValue, BAD_CAST "true") || |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18058 | xmlStrEqual(BAD_CAST attrValue, BAD_CAST "1")) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18059 | ret = 0; |
| 18060 | /* |
| 18061 | * cvc-elt (3.3.4) : 3.2.1 |
| 18062 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18063 | elemHasContent = xmlSchemaHasElemOrCharContent(elem); |
| 18064 | if (elemHasContent == 1) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18065 | xmlSchemaVCustomErr(ctxt, |
| 18066 | XML_SCHEMAV_CVC_ELT_3_2_1, |
| 18067 | /* XML_SCHEMAS_ERR_NOTEMPTY, */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18068 | elem, (xmlSchemaTypePtr) elemDecl, |
| 18069 | "The 'nilled' element must have no character or " |
| 18070 | "element content", NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18071 | ret = XML_SCHEMAV_CVC_ELT_3_2_1; |
| 18072 | } |
| 18073 | /* |
| 18074 | * cvc-elt (3.3.4) : 3.2.2 |
| 18075 | */ |
| 18076 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_FIXED) && |
| 18077 | (elemDecl->value != NULL)) { |
| 18078 | xmlSchemaVCustomErr(ctxt, XML_SCHEMAV_CVC_ELT_3_2_2, |
| 18079 | /* XML_SCHEMAS_ERR_HAVEDEFAULT, */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18080 | elem, (xmlSchemaTypePtr) elemDecl, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18081 | "There is a fixed value constraint defined for " |
| 18082 | "the 'nilled' element", NULL); |
| 18083 | ret = XML_SCHEMAV_CVC_ELT_3_2_2; |
| 18084 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18085 | if (ret == 0) |
| 18086 | nilled = 1; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18087 | } |
| 18088 | } |
| 18089 | if (attrValue != NULL) |
| 18090 | xmlFree(attrValue); |
| 18091 | } |
| 18092 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18093 | |
| 18094 | actualType = elemDecl->subtypes; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18095 | /* |
| 18096 | * cvc-elt (3.3.4) : 4 |
| 18097 | * Handle 'xsi:type'. |
| 18098 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18099 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18100 | attr = xmlHasNsProp(elem, BAD_CAST "type", xmlSchemaInstanceNs); |
| 18101 | if (attr != NULL) { |
| 18102 | xmlChar *nsName = NULL, *local = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18103 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18104 | /* |
| 18105 | * TODO: We should report a *warning* that the type was overriden |
| 18106 | * by the instance. |
| 18107 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18108 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18109 | /* |
| 18110 | * cvc-elt (3.3.4) : 4.1 |
| 18111 | */ |
| 18112 | attrValue = xmlNodeGetContent((xmlNodePtr) attr); |
| 18113 | ret = xmlSchemaValQNameAcquire(attrValue, attr->parent, |
| 18114 | &nsName, &local); |
| 18115 | if (ret < 0) { |
| 18116 | xmlSchemaVCustomErr(ctxt, |
| 18117 | XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18118 | (xmlNodePtr) attr, (xmlSchemaTypePtr) elemDecl, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18119 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 18120 | "validating the attribute 'xsi:type'", NULL);; |
| 18121 | FREE_AND_NULL(attrValue) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18122 | FREE_AND_NULL(nsName) |
| 18123 | FREE_AND_NULL(local) |
| 18124 | return (-1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18125 | } else if (ret == 1) { |
| 18126 | xmlSchemaVSimpleTypeErr(ctxt, |
| 18127 | XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, |
| 18128 | (xmlNodePtr) attr, attrValue, |
| 18129 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME)); |
| 18130 | } else if (ret == 2) { |
| 18131 | xmlSchemaVCustomErr(ctxt, |
| 18132 | XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, |
| 18133 | (xmlNodePtr) attr, |
| 18134 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
| 18135 | "The QName value '%s' has no " |
| 18136 | "corresponding namespace declaration in scope", |
| 18137 | attrValue); |
| 18138 | } else { |
| 18139 | /* |
| 18140 | * cvc-elt (3.3.4) : 4.2 |
| 18141 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18142 | actualType = xmlSchemaGetType(ctxt->schema, local, nsName); |
| 18143 | if (actualType == NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18144 | xmlChar *strA = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18145 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18146 | xmlSchemaVCustomErr(ctxt, |
| 18147 | XML_SCHEMAV_CVC_ELT_4_2, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18148 | (xmlNodePtr) attr, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18149 | xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), |
| 18150 | "The value %s does not resolve to a type " |
| 18151 | "definition", |
| 18152 | xmlSchemaFormatNsUriLocal(&strA, nsName, local)); |
| 18153 | FREE_AND_NULL(strA); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18154 | } else { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18155 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18156 | * 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] | 18157 | */ |
| 18158 | } |
| 18159 | } |
| 18160 | FREE_AND_NULL(attrValue) |
| 18161 | FREE_AND_NULL(nsName) |
| 18162 | FREE_AND_NULL(local) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18163 | } |
| 18164 | /* TODO: Change the handling of missing types according to |
| 18165 | * the spec. |
| 18166 | */ |
| 18167 | if (actualType == NULL) { |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 18168 | xmlSchemaVCustomErr(ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18169 | XML_SCHEMAV_CVC_TYPE_1, |
| 18170 | elem, (xmlSchemaTypePtr) elemDecl, |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 18171 | "The type definition is absent", NULL); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18172 | /* |
| 18173 | * Evaluate IDCs even if an error occured. |
| 18174 | */ |
| 18175 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18176 | if (xmlSchemaXPathEvaluate(ctxt, XML_ELEMENT_NODE) == -1) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18177 | return (-1); |
| 18178 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18179 | return (XML_SCHEMAV_CVC_TYPE_1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18180 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18181 | |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 18182 | /* |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18183 | * Remember the actual-type definition. |
| 18184 | */ |
| 18185 | #ifdef ELEM_INFO_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18186 | ctxt->nodeInfo->typeDef = actualType; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18187 | #endif |
| 18188 | |
| 18189 | /* |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 18190 | * TODO: Since this should be already checked by the content model automaton, |
| 18191 | * and we want to get rid of the XML_SCHEMAS_ERR... types, the error code |
| 18192 | * has been changed to XML_SCHEMAV_INTERNAL. |
| 18193 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18194 | /* |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 18195 | if (child == NULL) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18196 | if (decl->minOccurs > 0) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 18197 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18198 | XML_SCHEMAS_ERR_MISSING, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 18199 | "Element %s: missing child %s\n", |
| 18200 | node->name, decl->name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 18201 | } |
| 18202 | return (ctxt->err); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18203 | } |
| 18204 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 18205 | /* |
| 18206 | * Verify the element matches |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 18207 | * 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] | 18208 | * by the content model automaton? |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18209 | if (!xmlStrEqual(child->name, decl->name)) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 18210 | xmlSchemaVErr3(ctxt, node, XML_SCHEMAV_INTERNAL, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18211 | XML_SCHEMAS_ERR_WRONGELEM, |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 18212 | "Element %s: missing child %s found %s\n", |
| 18213 | node->name, decl->name, child->name); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 18214 | return (ctxt->err); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 18215 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18216 | */ |
| 18217 | if (elemHasContent == -1) |
| 18218 | elemHasContent = xmlSchemaHasElemOrCharContent(elem); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18219 | |
| 18220 | /* |
| 18221 | * IDC: Register identity-constraint XPath matchers. |
| 18222 | */ |
| 18223 | #ifdef IDC_ENABLED |
| 18224 | if (elemDecl->idcs != NULL) |
| 18225 | xmlSchemaIDCRegisterMatchers(ctxt, elemDecl); |
| 18226 | /* |
| 18227 | * Evaluate IDCs. |
| 18228 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18229 | if (xmlSchemaXPathEvaluate(ctxt, XML_ELEMENT_NODE) == -1) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18230 | return (-1); |
| 18231 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18232 | /* |
| 18233 | * cvc-elt (3.3.4) : 5 |
| 18234 | * The appropriate case among the following must be true: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18235 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 18236 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18237 | * cvc-elt (3.3.4) : 5.1 |
| 18238 | * If the declaration has a {value constraint}, |
| 18239 | * the item has neither element nor character [children] and |
| 18240 | * 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] | 18241 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18242 | if ((elemHasContent == 0) && (nilled == 0) && (elemDecl->value != NULL)) { |
| 18243 | /* |
| 18244 | * cvc-elt (3.3.4) : 5.1.1 |
| 18245 | * If the ·actual type definition· is a ·local type definition· |
| 18246 | * then the canonical lexical representation of the {value constraint} |
| 18247 | * value must be a valid default for the ·actual type definition· as |
| 18248 | * defined in Element Default Valid (Immediate) (§3.3.6). |
| 18249 | */ |
| 18250 | /* |
| 18251 | * NOTE: 'local' above means types aquired by xsi:type. |
| 18252 | */ |
| 18253 | ret = 0; |
| 18254 | if (actualType != elemDecl->subtypes) { |
| 18255 | xmlSchemaCreatePCtxtOnVCtxt(ctxt); |
| 18256 | ret = xmlSchemaCheckCOSValidDefault(ctxt->pctxt, ctxt, actualType, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18257 | elemDecl->value, NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18258 | if (ret < 0) { |
| 18259 | xmlSchemaVCustomErr(ctxt, |
| 18260 | XML_SCHEMAV_INTERNAL, |
| 18261 | elem, actualType, |
| 18262 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 18263 | "validating a default value", NULL); |
| 18264 | return (-1); |
| 18265 | } |
| 18266 | } |
| 18267 | /* |
| 18268 | * cvc-elt (3.3.4) : 5.1.2 |
| 18269 | * The element information item with the canonical lexical |
| 18270 | * representation of the {value constraint} value used as its |
| 18271 | * ·normalized value· must be ·valid· with respect to the |
| 18272 | * ·actual type definition· as defined by Element Locally Valid (Type) |
| 18273 | * (§3.3.4). |
| 18274 | */ |
| 18275 | /* |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18276 | * Disable validation of the simple content, if it was already |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18277 | * done above. |
| 18278 | */ |
| 18279 | if (ret == 0) { |
| 18280 | if (actualType != elemDecl->subtypes) |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18281 | ret = xmlSchemaValidateElementByType(ctxt, actualType, 0, 0); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18282 | else |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18283 | ret = xmlSchemaValidateElementByType(ctxt, actualType, 0, 1); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18284 | ctxt->node = elem; |
| 18285 | if (ret < 0) { |
| 18286 | xmlSchemaVCustomErr(ctxt, |
| 18287 | XML_SCHEMAV_INTERNAL, |
| 18288 | elem, actualType, |
| 18289 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 18290 | "validating against the type", NULL); |
| 18291 | return (-1); |
| 18292 | } |
| 18293 | /* |
| 18294 | * PSVI: Create a text node on the instance element. |
| 18295 | */ |
| 18296 | if (ctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) { |
| 18297 | xmlNodePtr textChild; |
| 18298 | |
| 18299 | textChild = xmlNewText(elemDecl->value); |
| 18300 | if (textChild == NULL) { |
| 18301 | xmlSchemaVCustomErr(ctxt, |
| 18302 | XML_SCHEMAV_INTERNAL, |
| 18303 | elem, actualType, |
| 18304 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
| 18305 | "could not create a default text node for the instance", |
| 18306 | NULL); |
| 18307 | } else |
| 18308 | xmlAddChild(elem, textChild); |
| 18309 | } |
| 18310 | } |
| 18311 | |
| 18312 | } else { |
| 18313 | /* |
| 18314 | * 5.2.1 The element information item must be ·valid· with respect |
| 18315 | * to the ·actual type definition· as defined by Element Locally |
| 18316 | * Valid (Type) (§3.3.4). |
| 18317 | */ |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18318 | ret = xmlSchemaValidateElementByType(ctxt, actualType, nilled, 1); |
| 18319 | /* |
| 18320 | * Consume the computed value for IDCs, ect. Note that default |
| 18321 | * values are not supported yet. |
| 18322 | */ |
| 18323 | #ifdef ELEM_INFO_ENABLED |
| 18324 | if (ctxt->value != NULL) { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18325 | ctxt->nodeInfo->value = ctxt->value; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18326 | ctxt->value = NULL; |
| 18327 | } |
| 18328 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18329 | ctxt->node = elem; |
| 18330 | if (ret < 0) { |
| 18331 | xmlSchemaVCustomErr(ctxt, |
| 18332 | XML_SCHEMAV_INTERNAL, |
| 18333 | elem, actualType, |
| 18334 | "Internal error: xmlSchemaValidateElementByDeclaration, " |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 18335 | "calling validation by type", NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18336 | return (-1); |
| 18337 | } |
| 18338 | /* |
| 18339 | * 5.2.2 If there is a fixed {value constraint} and clause 3.2 has |
| 18340 | * not applied, all of the following must be true: |
| 18341 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18342 | if ((elemDecl->flags & XML_SCHEMAS_ELEM_FIXED) && (nilled == 0)) { |
| 18343 | /* |
| 18344 | * 5.2.2.1 The element information item must have no element |
| 18345 | * information item [children]. |
| 18346 | * |
| 18347 | * TODO REDUNDANT: If the actual type exists, the above call to |
| 18348 | * xmlSchemaValidateElementByType will already check for element |
| 18349 | * nodes. |
| 18350 | */ |
| 18351 | if (xmlSchemaHasElemContent(elem)) { |
| 18352 | xmlSchemaVCustomErr(ctxt, |
| 18353 | XML_SCHEMAV_CVC_ELT_5_2_2_1, |
| 18354 | elem, (xmlSchemaTypePtr) elemDecl, |
| 18355 | "Elements in the content are not allowed if it is " |
| 18356 | "constrained by a fixed value", NULL); |
| 18357 | } else { |
| 18358 | /* |
| 18359 | * 5.2.2.2 The appropriate case among the following must |
| 18360 | * be true: |
| 18361 | */ |
| 18362 | |
| 18363 | if (actualType->contentType == XML_SCHEMA_CONTENT_MIXED) { |
| 18364 | xmlChar *value; |
| 18365 | /* |
| 18366 | * 5.2.2.2.1 If the {content type} of the ·actual type |
| 18367 | * definition· is mixed, then the *initial value* of the |
| 18368 | * item must match the canonical lexical representation |
| 18369 | * of the {value constraint} value. |
| 18370 | * |
| 18371 | * ... the *initial value* of an element information |
| 18372 | * item is the string composed of, in order, the |
| 18373 | * [character code] of each character information item in |
| 18374 | * the [children] of that element information item. |
| 18375 | */ |
| 18376 | value = xmlNodeListGetString(elem->doc, elem->children, 1); |
| 18377 | if (! xmlStrEqual(BAD_CAST value, elemDecl->value)) { |
| 18378 | /* |
| 18379 | * TODO: Report invalid & expected values as well. |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18380 | * TODO: Implement the canonical stuff. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18381 | */ |
| 18382 | xmlSchemaVCustomErr(ctxt, |
| 18383 | XML_SCHEMAV_CVC_ELT_5_2_2_2_1, |
| 18384 | elem, (xmlSchemaTypePtr) elemDecl, |
| 18385 | "The value does not match the cononical " |
| 18386 | "lexical representation of the fixed constraint", |
| 18387 | NULL); |
| 18388 | } |
| 18389 | if (value != NULL) |
| 18390 | xmlFree(value); |
| 18391 | } else if ((actualType->contentType == |
| 18392 | XML_SCHEMA_CONTENT_SIMPLE) || |
| 18393 | (actualType->contentType == XML_SCHEMA_CONTENT_BASIC)) { |
| 18394 | xmlChar *value; |
| 18395 | |
| 18396 | /* |
| 18397 | * 5.2.2.2.2 If the {content type} of the ·actual type |
| 18398 | * definition· is a simple type definition, then the |
| 18399 | * *actual value* of the item must match the canonical |
| 18400 | * lexical representation of the {value constraint} value. |
| 18401 | */ |
| 18402 | /* |
| 18403 | * TODO: *actual value* is the normalized value, impl. this. |
| 18404 | * TODO: Report invalid & expected values as well. |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18405 | * TODO: Implement the canonical stuff. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18406 | * |
| 18407 | */ |
| 18408 | value = xmlNodeListGetString(elem->doc, elem->children, 1); |
| 18409 | if (! xmlStrEqual(BAD_CAST value, elemDecl->value)) { |
| 18410 | xmlSchemaVCustomErr(ctxt, |
| 18411 | XML_SCHEMAV_CVC_ELT_5_2_2_2_2, |
| 18412 | elem, (xmlSchemaTypePtr) elemDecl, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 18413 | "The normalized value does not match the canonical " |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18414 | "lexical representation of the fixed constraint", |
| 18415 | NULL); |
| 18416 | } |
| 18417 | if (value != NULL) |
| 18418 | xmlFree(value); |
| 18419 | |
| 18420 | } |
| 18421 | /* |
| 18422 | * TODO: What if the content type is not 'mixed' or simple? |
| 18423 | */ |
| 18424 | |
| 18425 | } |
| 18426 | |
| 18427 | } |
| 18428 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18429 | /* |
| 18430 | * TODO: 7 If the element information item is the ·validation root·, it must be |
| 18431 | * ·valid· per Validation Root Valid (ID/IDREF) (§3.3.4). |
| 18432 | */ |
| 18433 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 18434 | return (ctxt->err); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 18435 | } |
| 18436 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 18437 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18438 | * xmlSchemaValidateElementByWildcardInternal: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18439 | * @ctxt: a schema validation context |
| 18440 | * @node: the top node. |
| 18441 | * |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18442 | * Represents the recursive portion of xmlSchemaValidateElementByWildcard. |
| 18443 | * Not intended to be used by other functions. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18444 | * |
| 18445 | * Returns 0 if the element is valid, a positive error code |
| 18446 | * number otherwise and -1 in case of an internal error. |
| 18447 | */ |
| 18448 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18449 | xmlSchemaValidateElementByWildcardInternal(xmlSchemaValidCtxtPtr ctxt, |
| 18450 | xmlSchemaWildcardPtr wild, |
| 18451 | xmlNodePtr node) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18452 | { |
| 18453 | const xmlChar *uri; |
| 18454 | int ret = 0; |
| 18455 | xmlNodePtr child; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18456 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18457 | if (ctxt->xsiAssemble) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18458 | ret = xmlSchemaAssembleByXSIElem(ctxt, ctxt->node); |
| 18459 | if (ret == -1) { |
| 18460 | xmlSchemaVCustomErr(ctxt, |
| 18461 | XML_SCHEMAV_INTERNAL, |
| 18462 | ctxt->node, NULL, |
| 18463 | "Internal error: xmlSchemaValidateElement, " |
| 18464 | "assembling schema by xsi", NULL); |
| 18465 | return (-1); |
| 18466 | } |
| 18467 | /* |
| 18468 | * NOTE: We won't react on schema parser errors here. |
| 18469 | * TODO: But a warning would be nice. |
| 18470 | */ |
| 18471 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18472 | if (wild->processContents != XML_SCHEMAS_ANY_SKIP) { |
| 18473 | xmlSchemaElementPtr decl = NULL; |
| 18474 | |
| 18475 | if (node->ns != NULL) |
| 18476 | decl = xmlHashLookup3(ctxt->schema->elemDecl, |
| 18477 | node->name, node->ns->href, NULL); |
| 18478 | else |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18479 | decl = xmlHashLookup3(ctxt->schema->elemDecl, node->name, |
| 18480 | NULL, NULL); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18481 | if (decl != NULL) { |
| 18482 | ctxt->node = node; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18483 | ret = xmlSchemaValidateElementByDeclaration(ctxt, decl); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18484 | if (ret < 0) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 18485 | xmlSchemaVErr(ctxt, node, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18486 | "Internal error: xmlSchemaValidateAnyInternal, " |
| 18487 | "validating an element in the context of a wildcard.", |
| 18488 | NULL, NULL); |
Kasimier T. Buchcik | 5dd55d9 | 2004-11-26 12:35:21 +0000 | [diff] [blame] | 18489 | } |
| 18490 | return (ret); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18491 | } else if (wild->processContents == XML_SCHEMAS_ANY_STRICT) { |
| 18492 | /* TODO: Change to proper error code. */ |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 18493 | xmlSchemaVWildcardErr(ctxt, XML_SCHEMAV_CVC_ELT_1, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18494 | node, wild, "No matching global declaration available"); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18495 | /* |
| 18496 | * Evaluate IDCs even if a validation error occured. |
| 18497 | */ |
| 18498 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18499 | if (xmlSchemaXPathEvaluate(ctxt,XML_ELEMENT_NODE) == -1) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18500 | return(-1); |
| 18501 | #endif |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18502 | return (ctxt->err); |
| 18503 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18504 | /* |
| 18505 | * Evaluate IDCs; we need to know if an IDC field resolves to |
| 18506 | * such a node. This node has no type definition and will |
| 18507 | * definitely result in an IDC validation error if an IDC field |
| 18508 | * resolves. |
| 18509 | */ |
| 18510 | #ifdef IDC_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18511 | if (xmlSchemaXPathEvaluate(ctxt, XML_ELEMENT_NODE) == -1) |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18512 | return(-1); |
| 18513 | #endif |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18514 | } |
| 18515 | if (node->children != NULL) { |
| 18516 | child = node->children; |
| 18517 | do { |
| 18518 | if (child->type == XML_ELEMENT_NODE) { |
| 18519 | if (child->ns != NULL) |
| 18520 | uri = child->ns->href; |
| 18521 | else |
| 18522 | uri = NULL; |
| 18523 | if (xmlSchemaMatchesWildcardNs(wild, uri) == 0) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 18524 | /* TODO: error code. */ |
| 18525 | xmlSchemaVWildcardErr(ctxt, XML_SCHEMAV_ELEMENT_CONTENT, |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18526 | child, wild, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18527 | "The namespace of the element is not allowed"); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18528 | return (ctxt->err); |
| 18529 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18530 | #ifdef ELEM_INFO_ENABLED |
| 18531 | ctxt->node = child; |
| 18532 | xmlSchemaBeginElement(ctxt); |
| 18533 | #endif |
| 18534 | /* |
| 18535 | * Recurse over the children. |
| 18536 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18537 | ret = xmlSchemaValidateElementByWildcardInternal(ctxt, |
| 18538 | wild, child); |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18539 | if (ret == -1) |
| 18540 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18541 | #ifdef ELEM_INFO_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18542 | if (xmlSchemaEndElement(ctxt) == -1) |
| 18543 | return (-1); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 18544 | #endif |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18545 | if (ret != 0) |
| 18546 | return (ret); |
| 18547 | } |
| 18548 | child = child->next; |
| 18549 | } while (child != NULL); |
| 18550 | } |
| 18551 | return (0); |
| 18552 | } |
| 18553 | |
| 18554 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18555 | * xmlSchemaValidateElementContByWildcard: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18556 | * @ctxt: a schema validation context |
| 18557 | * |
| 18558 | * Returns 0 if the element is valid, a positive error code |
| 18559 | * number otherwise and -1 in case of an internal or API error. |
| 18560 | */ |
| 18561 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18562 | xmlSchemaValidateElementByWildcard(xmlSchemaValidCtxtPtr ctxt, |
| 18563 | xmlSchemaTypePtr type) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18564 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18565 | if ((type == NULL) || (type->type != XML_SCHEMA_TYPE_ANY) || |
| 18566 | (ctxt->node == NULL)) { |
| 18567 | xmlSchemaVCustomErr(ctxt, |
| 18568 | XML_SCHEMAV_INTERNAL, ctxt->node, NULL, |
| 18569 | "Internal error: xmlSchemaValidateElementByWildcard, " |
| 18570 | "bad arguments", NULL); |
| 18571 | return (-1); |
| 18572 | } |
| 18573 | return(xmlSchemaValidateElementByWildcardInternal(ctxt, |
| 18574 | type->attributeWildcard, ctxt->node)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18575 | } |
| 18576 | |
| 18577 | /** |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18578 | * xmlSchemaValidateAnyTypeContent: |
| 18579 | * @ctxt: a schema validation context |
| 18580 | * @node: the current element |
| 18581 | * |
| 18582 | * This one validates the content of an element of the type |
| 18583 | * 'anyType'. The process contents of the wildcard of 'anyType' is "lax", |
| 18584 | * thus elements in the subtree will be validated, if a corresponding |
| 18585 | * declaration in the schema exists. |
| 18586 | * |
| 18587 | * Returns 0 if the element and its subtree is valid, a positive error code |
| 18588 | * otherwise and -1 in case of an internal or API error. |
| 18589 | */ |
| 18590 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18591 | xmlSchemaValidateElementByAnyType(xmlSchemaValidCtxtPtr ctxt, |
| 18592 | xmlSchemaTypePtr type) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18593 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18594 | xmlSchemaTypePtr oldtype; |
| 18595 | xmlNodePtr top, cur; |
| 18596 | xmlSchemaElementPtr decl; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18597 | int skipContent, ret; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18598 | |
| 18599 | if ((type == NULL) || (ctxt->node == NULL)) |
| 18600 | return (-1); |
| 18601 | |
| 18602 | if (ctxt->node->children == NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18603 | return (0); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18604 | |
| 18605 | oldtype = ctxt->type; |
| 18606 | top = ctxt->node; |
| 18607 | /* |
| 18608 | * STREAM: Child nodes are processed. |
| 18609 | */ |
| 18610 | cur = ctxt->node->children; |
| 18611 | while (cur != NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18612 | skipContent = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18613 | if (cur->type == XML_ELEMENT_NODE) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18614 | /* |
| 18615 | * The process contents of the wildcard is "lax", thus |
| 18616 | * we need to validate the element if a declaration |
| 18617 | * exists. |
| 18618 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18619 | if (cur->ns != NULL) |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18620 | decl = xmlHashLookup3(ctxt->schema->elemDecl, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18621 | cur->name, cur->ns->href, NULL); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18622 | else |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18623 | decl = xmlHashLookup3(ctxt->schema->elemDecl, cur->name, NULL, NULL); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18624 | if (decl != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18625 | ctxt->node = cur; |
| 18626 | ret = xmlSchemaValidateElementByDeclaration(ctxt, decl); |
| 18627 | ctxt->node = top; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18628 | if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18629 | xmlSchemaVErr(ctxt, cur, XML_SCHEMAV_INTERNAL, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18630 | "Internal error: xmlSchemaValidateAnyTypeContent, " |
| 18631 | "validating an element in the context of a wildcard.", |
| 18632 | NULL, NULL); |
| 18633 | return (ret); |
| 18634 | } else if (ret > 0) |
| 18635 | return (ret); |
| 18636 | skipContent = 1; |
| 18637 | } |
| 18638 | } |
| 18639 | /* |
| 18640 | * Browse the full subtree, deep first. |
| 18641 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18642 | if ((skipContent == 0) && (cur->children != NULL)) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18643 | /* deep first */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18644 | cur = cur->children; |
| 18645 | } else if ((cur != top) && (cur->next != NULL)) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18646 | /* then siblings */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18647 | cur = cur->next; |
| 18648 | } else if (cur != top) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18649 | /* go up to parents->next if needed */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18650 | while (cur != top) { |
| 18651 | if (cur->parent != NULL) |
| 18652 | cur = cur->parent; |
| 18653 | if ((cur != top) && (cur->next != NULL)) { |
| 18654 | cur = cur->next; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18655 | break; |
| 18656 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18657 | if (cur->parent == NULL) { |
| 18658 | cur = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18659 | break; |
| 18660 | } |
| 18661 | } |
| 18662 | /* exit condition */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18663 | if (cur == top) |
| 18664 | cur = NULL; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18665 | } else |
| 18666 | break; |
| 18667 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18668 | ctxt->type = oldtype; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18669 | return (0); |
| 18670 | } |
| 18671 | |
| 18672 | /** |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18673 | * xmlSchemaValidateElementByComplexType: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 18674 | * @ctxt: a schema validation context |
| 18675 | * @node: the top node. |
| 18676 | * |
| 18677 | * Validate the content of an element expected to be a complex type type |
| 18678 | * xmlschema-1.html#cvc-complex-type |
| 18679 | * Validation Rule: Element Locally Valid (Complex Type) |
| 18680 | * |
| 18681 | * Returns 0 if the element is schemas valid, a positive error code |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18682 | * number otherwise and -1 in case of internal or API error. |
| 18683 | * Note on reported errors: Although it might be nice to report |
| 18684 | * the name of the simple/complex type, used to validate the content |
| 18685 | * of a node, it is quite unnecessary: for global defined types |
| 18686 | * the local name of the element is equal to the NCName of the type, |
| 18687 | * for local defined types it makes no sense to output the internal |
| 18688 | * computed name of the type. TODO: Instead, one should attach the |
| 18689 | * struct of the type involved to the error handler - this allows |
| 18690 | * the report of any additional information by the user. |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 18691 | */ |
| 18692 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18693 | xmlSchemaValidateElementByComplexType(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18694 | xmlSchemaTypePtr type, |
| 18695 | int valSimpleContent) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 18696 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18697 | xmlSchemaTypePtr oldtype; |
| 18698 | xmlNodePtr elem, child; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18699 | int ret = 0; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18700 | const xmlChar *nsUri; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18701 | xmlSchemaAttrStatePtr attrs = NULL, attrTop = NULL; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 18702 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18703 | if ((ctxt == NULL) || (type->type != XML_SCHEMA_TYPE_COMPLEX)) |
| 18704 | return (-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 18705 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18706 | oldtype = ctxt->type; |
| 18707 | ctxt->type = type; |
| 18708 | elem = ctxt->node; |
| 18709 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18710 | /* |
| 18711 | * Verify the attributes |
| 18712 | */ |
| 18713 | /* |
| 18714 | * TODO: This "attrTop" thing is not needed any more. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18715 | */ |
| 18716 | /* NOTE: removed, since a check for abstract is |
| 18717 | * done in the cvc-type constraint. |
| 18718 | * |
| 18719 | * |
| 18720 | * if (type->flags & XML_SCHEMAS_TYPE_ABSTRACT) { |
| 18721 | * xmlSchemaVComplexTypeErr(ctxt, |
| 18722 | * XML_SCHEMAV_CVC_COMPLEX_TYPE_1, |
| 18723 | * elem, type, |
| 18724 | * "The type definition is abstract"); |
| 18725 | * return (XML_SCHEMAV_CVC_COMPLEX_TYPE_1); |
| 18726 | *} |
| 18727 | */ |
| 18728 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18729 | attrs = ctxt->attr; |
| 18730 | attrTop = ctxt->attrTop; |
| 18731 | /* |
| 18732 | * STREAM: Attribute nodes are processed. |
| 18733 | */ |
| 18734 | xmlSchemaRegisterAttributes(ctxt, elem->properties); |
| 18735 | xmlSchemaValidateAttributes(ctxt, elem, type); |
| 18736 | if (ctxt->attr != NULL) |
| 18737 | xmlSchemaFreeAttributeStates(ctxt->attr); |
| 18738 | ctxt->attr = attrs; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18739 | ctxt->attrTop = attrTop; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18740 | |
| 18741 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18742 | * TODO: This one creates a regexp even if no content |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18743 | * model was defined. Somehow ->contModel is always not NULL |
| 18744 | * for complex types, even if they are empty. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18745 | * TODO: Check if the obove still occurs. |
| 18746 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 18747 | switch (type->contentType) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18748 | case XML_SCHEMA_CONTENT_EMPTY: { |
| 18749 | /* |
| 18750 | * 1 If the {content type} is empty, then the element information |
| 18751 | * item has no character or element information item [children]. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 18752 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18753 | /* |
| 18754 | * TODO: Is the entity stuff correct? |
| 18755 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18756 | if (xmlSchemaHasElemOrCharContent(elem) == 1) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18757 | xmlSchemaVComplexTypeErr(ctxt, |
| 18758 | XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18759 | elem, type, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18760 | "Character or element content is not allowed, " |
| 18761 | "because the content type is empty"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18762 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 18763 | break; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18764 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18765 | case XML_SCHEMA_CONTENT_MIXED: |
| 18766 | if ((type->subtypes == NULL) && |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18767 | (type->baseType->builtInType == XML_SCHEMAS_ANYTYPE)) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18768 | /* |
| 18769 | * The type has 'anyType' as its base and no content model |
| 18770 | * is defined -> use 'anyType' as the type to validate |
| 18771 | * against. |
| 18772 | */ |
| 18773 | ret = xmlSchemaValidateElementByAnyType(ctxt, type->baseType); |
| 18774 | /* TODO: Handle -1. */ |
| 18775 | break; |
| 18776 | } |
| 18777 | /* No break on purpose. */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18778 | case XML_SCHEMA_CONTENT_ELEMENTS: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18779 | { |
| 18780 | xmlRegExecCtxtPtr oldregexp = NULL; |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 18781 | xmlChar *values[10]; |
| 18782 | int terminal, nbval = 10, nbneg; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18783 | |
| 18784 | /* |
| 18785 | * Content model check initialization. |
| 18786 | */ |
| 18787 | if (type->contModel != NULL) { |
| 18788 | oldregexp = ctxt->regexp; |
| 18789 | ctxt->regexp = xmlRegNewExecCtxt(type->contModel, |
| 18790 | (xmlRegExecCallbacks) |
| 18791 | xmlSchemaValidateCallback, ctxt); |
| 18792 | #ifdef DEBUG_AUTOMATA |
| 18793 | xmlGenericError(xmlGenericErrorContext, "====> %s\n", elem->name); |
| 18794 | #endif |
| 18795 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18796 | /* |
| 18797 | * STREAM: Children are processed. |
| 18798 | */ |
| 18799 | child = elem->children; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18800 | while (child != NULL) { |
| 18801 | if (child->type == XML_ELEMENT_NODE) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18802 | if (child->ns != NULL) |
| 18803 | nsUri = child->ns->href; |
| 18804 | else |
| 18805 | nsUri = NULL; |
| 18806 | ret = xmlRegExecPushString2(ctxt->regexp, |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 18807 | child->name, nsUri, child); |
| 18808 | if (ctxt->err == XML_SCHEMAV_INTERNAL) |
| 18809 | return (-1); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18810 | /* |
| 18811 | * URGENT TODO: Could we anchor an error report |
| 18812 | * here to notify of invalid elements? |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 18813 | * TODO: Perhaps it would be better to report |
| 18814 | * only the first erroneous element and then break. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18815 | */ |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 18816 | #ifdef DEBUG_AUTOMATA |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18817 | if (ret < 0) |
| 18818 | xmlGenericError(xmlGenericErrorContext, |
| 18819 | " --> %s Error\n", child->name); |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 18820 | else |
| 18821 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18822 | " --> %s\n", child->name); |
| 18823 | #endif |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 18824 | if (ret < 0) { |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 18825 | xmlRegExecErrInfo(ctxt->regexp, NULL, &nbval, &nbneg, |
| 18826 | &values[0], &terminal); |
| 18827 | xmlSchemaVComplexTypeElemErr(ctxt, |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 18828 | XML_SCHEMAV_ELEMENT_CONTENT, |
| 18829 | child, NULL/* type */, |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 18830 | "This element is not expected", |
| 18831 | nbval, nbneg, values); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 18832 | ret = 1; |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 18833 | /* |
| 18834 | * Note that this will skip further validation of the |
| 18835 | * content. |
| 18836 | */ |
| 18837 | break; |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 18838 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18839 | } else if ((type->contentType == XML_SCHEMA_CONTENT_ELEMENTS) && |
| 18840 | /* |
| 18841 | * TODO: Ask Daniel if this are all character nodes. |
| 18842 | */ |
| 18843 | (((child->type == XML_TEXT_NODE) && (!IS_BLANK_NODE(child))) || |
| 18844 | (child->type == XML_ENTITY_NODE) || |
| 18845 | (child->type == XML_ENTITY_REF_NODE) || |
| 18846 | (child->type == XML_CDATA_SECTION_NODE))) { |
| 18847 | /* |
| 18848 | * 2.3 If the {content type} is element-only, then the |
| 18849 | * element information item has no character information |
| 18850 | * item [children] other than those whose [character |
| 18851 | * code] is defined as a white space in [XML 1.0 (Second |
| 18852 | * Edition)]. |
| 18853 | */ |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18854 | xmlSchemaVComplexTypeErr(ctxt, |
| 18855 | XML_SCHEMAV_CVC_COMPLEX_TYPE_2_3, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18856 | elem, type, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18857 | "Character content is not allowed, " |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 18858 | "because the content type is element-only"); |
| 18859 | ret = 1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18860 | break; |
| 18861 | } |
| 18862 | child = child->next; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18863 | } |
| 18864 | /* |
| 18865 | * Content model check finalization. |
| 18866 | */ |
| 18867 | if (type->contModel != NULL) { |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 18868 | if (ret == 0) { |
| 18869 | xmlRegExecNextValues(ctxt->regexp, &nbval, &nbneg, |
| 18870 | &values[0], &terminal); |
| 18871 | if (nbval + nbneg != 0) { |
| 18872 | /* |
| 18873 | * If a next value still exists, I does not have to |
| 18874 | * mean that there's an element missing, since it |
| 18875 | * might be an optional element. So double check it. |
| 18876 | */ |
| 18877 | ret = xmlRegExecPushString(ctxt->regexp, |
| 18878 | NULL, NULL); |
| 18879 | if (ret <= 0) { |
| 18880 | ret = 1; |
| 18881 | xmlSchemaVComplexTypeElemErr(ctxt, |
| 18882 | XML_SCHEMAV_ELEMENT_CONTENT, |
| 18883 | elem, type, "Missing child element(s)", |
| 18884 | nbval, nbneg, values); |
| 18885 | } else |
| 18886 | ret = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18887 | #ifdef DEBUG_AUTOMATA |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 18888 | xmlGenericError(xmlGenericErrorContext, |
| 18889 | "====> %s : %d\n", elem->name, ret); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18890 | #endif |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 18891 | } |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 18892 | #ifdef DEBUG_CONTENT |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 18893 | if (ret == 0) |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 18894 | xmlGenericError(xmlGenericErrorContext, |
| 18895 | "Element %s content check succeeded\n", |
| 18896 | elem->name); |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 18897 | #endif |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18898 | } |
| 18899 | xmlRegFreeExecCtxt(ctxt->regexp); |
| 18900 | ctxt->regexp = oldregexp; |
| 18901 | } |
| 18902 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18903 | break; |
| 18904 | case XML_SCHEMA_CONTENT_SIMPLE: |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 18905 | case XML_SCHEMA_CONTENT_BASIC: |
| 18906 | /* |
| 18907 | * If the simple content was already validated |
| 18908 | * (e.g. a default value), the content need not |
| 18909 | * to be validated again. |
| 18910 | */ |
| 18911 | if (valSimpleContent == 1) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18912 | xmlChar *value = NULL; |
| 18913 | /* |
| 18914 | * We hit a complexType with a simpleContent resolving |
| 18915 | * to a user derived or built-in simple type. |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18916 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18917 | /* |
| 18918 | * 2.2 If the {content type} is a simple type definition, |
| 18919 | * then the element information item has no element |
| 18920 | * information item [children], and the ·normalized value· |
| 18921 | * of the element information item is ·valid· with respect |
| 18922 | * to that simple type definition as defined by String |
| 18923 | * Valid (§3.14.4). |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18924 | */ |
| 18925 | /* |
| 18926 | * STREAM: Children are processed. |
| 18927 | */ |
| 18928 | child = elem->children; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18929 | while (child != NULL) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18930 | /* |
| 18931 | * TODO: Could the entity stuff produce elements |
| 18932 | * as well? |
| 18933 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18934 | if (child->type == XML_ELEMENT_NODE) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18935 | xmlSchemaVComplexTypeErr(ctxt, |
| 18936 | XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18937 | elem, type, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18938 | "Element content is not allowed, because " |
| 18939 | "the content type is a simple type"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18940 | ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2; |
| 18941 | break; |
| 18942 | } |
| 18943 | child = child->next; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18944 | } |
| 18945 | ctxt->node = elem; |
| 18946 | ctxt->cur = elem->children; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18947 | if (ret == 0) { |
| 18948 | /* |
| 18949 | * Validate the character content against a simple type. |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 18950 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18951 | /* |
| 18952 | * STREAM: Children are processed. |
| 18953 | */ |
| 18954 | if (elem->children == NULL) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18955 | value = NULL; |
| 18956 | else |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18957 | value = xmlNodeGetContent(elem); |
| 18958 | /* |
| 18959 | * URGENT TODO: Should facets for the simple type validation be |
| 18960 | * disabled, if the derivation of facets for complex types |
| 18961 | * is implemented? |
| 18962 | */ |
| 18963 | /* |
| 18964 | * NOTE: This call won't check the correct types of the |
| 18965 | * content nodes, since this should be done here. |
| 18966 | */ |
| 18967 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, type, value, 1, 1, 1, 0); |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18968 | if (ret > 0) { |
| 18969 | /* |
| 18970 | * NOTE: Although an error will be reported by |
| 18971 | * xmlSchemaValidateSimpleTypeValue, the spec wants |
| 18972 | * a specific complex type error to be reported |
| 18973 | * additionally. |
| 18974 | */ |
| 18975 | xmlSchemaVComplexTypeErr(ctxt, |
| 18976 | XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18977 | elem, type, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18978 | "The character content is not valid"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18979 | ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2; |
| 18980 | } else if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18981 | xmlSchemaVErr(ctxt, elem, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18982 | "Internal error: xmlSchemaValidateComplexType, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 18983 | "Element '%s': Error while validating character " |
| 18984 | "content against complex type '%s'.\n", |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18985 | elem->name, type->name); |
| 18986 | if (value != NULL) |
| 18987 | xmlFree(value); |
| 18988 | ctxt->type = oldtype; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18989 | return (-1); |
| 18990 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 18991 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 18992 | if (ret == 0) { |
| 18993 | /* |
| 18994 | * Apply facets of the complexType. Be sure to pass the |
| 18995 | * built-in type to xmlSchemaValidateFacetsInternal. |
| 18996 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 18997 | /* 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] | 18998 | * are used, or if the facets, defined by this complex type, |
| 18999 | * are to be used only. This here applies both facet sets. |
| 19000 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19001 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19002 | ret = xmlSchemaValidateFacetsInternal(ctxt, |
| 19003 | type, value, 0, 1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19004 | if (ret > 0) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19005 | xmlSchemaVComplexTypeErr(ctxt, |
| 19006 | XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2, |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19007 | elem, type, |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 19008 | "The character content is not valid"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19009 | ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2; |
| 19010 | } else if (ret < 0) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19011 | xmlSchemaVErr(ctxt, elem, XML_SCHEMAV_INTERNAL, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19012 | "Internal error: xmlSchemaValidateComplexType, " |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19013 | "Element '%s': Error while validating character " |
| 19014 | "content against complex type '%s'; failed to " |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19015 | "apply facets.\n", |
| 19016 | type->name, NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19017 | if (value != NULL) |
| 19018 | xmlFree(value); |
| 19019 | ctxt->type = oldtype; |
| 19020 | return (-1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19021 | } |
| 19022 | } |
| 19023 | if (value != NULL) |
Kasimier T. Buchcik | c3af19d | 2005-01-13 12:10:11 +0000 | [diff] [blame] | 19024 | xmlFree(value); |
| 19025 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19026 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19027 | break; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19028 | default: |
| 19029 | TODO xmlGenericError(xmlGenericErrorContext, |
| 19030 | "unimplemented content type %d\n", |
| 19031 | type->contentType); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19032 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19033 | ctxt->type = oldtype; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19034 | return (ctxt->err); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19035 | } |
| 19036 | |
| 19037 | /** |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19038 | * xmlSchemaValidateElementByType: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19039 | * @ctxt: a schema validation context |
| 19040 | * @elem: an element |
| 19041 | * @type: the list of type declarations |
| 19042 | * |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19043 | * Validation Rule: Element Locally Valid (Type). |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19044 | * |
| 19045 | * Returns 0 if the element is schemas valid, a positive error code |
| 19046 | * number otherwise and -1 in case of internal or API error. |
| 19047 | */ |
| 19048 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19049 | xmlSchemaValidateElementByType(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19050 | xmlSchemaTypePtr type, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19051 | int isNil, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19052 | int valSimpleContent) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19053 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19054 | int ret; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19055 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19056 | |
| 19057 | if ((ctxt == NULL) || (type == NULL)) { |
| 19058 | xmlSchemaVCustomErr(ctxt, XML_SCHEMAV_INTERNAL, NULL, NULL, |
| 19059 | "Internal error: xmlSchemaValidateElementByType, " |
| 19060 | "bad arguments", NULL); |
| 19061 | return (-1); |
| 19062 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19063 | /* |
| 19064 | * This one is called by "xmlSchemaValidateElementByDeclaration". |
| 19065 | * It will forward to the proper validation |
| 19066 | * procedures for the given type. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19067 | */ |
| 19068 | if (type == NULL) { |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 19069 | xmlSchemaVCustomErr(ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19070 | XML_SCHEMAV_CVC_TYPE_1, |
| 19071 | ctxt->node, NULL, |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 19072 | "The type definition is absent", NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19073 | return (XML_SCHEMAV_CVC_TYPE_1); |
| 19074 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19075 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19076 | if (type->flags & XML_SCHEMAS_TYPE_ABSTRACT) { |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 19077 | xmlSchemaVCustomErr(ctxt, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19078 | XML_SCHEMAV_CVC_TYPE_2, |
| 19079 | ctxt->node, type, |
Kasimier T. Buchcik | 8b41817 | 2004-11-17 13:14:27 +0000 | [diff] [blame] | 19080 | "The type definition is abstract", NULL); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19081 | return (XML_SCHEMAV_CVC_TYPE_2); |
| 19082 | } |
| 19083 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19084 | switch (type->type) { |
| 19085 | case XML_SCHEMA_TYPE_COMPLEX: |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19086 | ret = xmlSchemaValidateElementByComplexType(ctxt, type, |
| 19087 | valSimpleContent); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19088 | break; |
| 19089 | case XML_SCHEMA_TYPE_SIMPLE: |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19090 | ret = xmlSchemaValidateElementBySimpleType(ctxt, type, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19091 | isNil, valSimpleContent); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19092 | break; |
| 19093 | case XML_SCHEMA_TYPE_BASIC: |
| 19094 | if (type->builtInType == XML_SCHEMAS_ANYTYPE) |
| 19095 | ret = xmlSchemaValidateElementByAnyType(ctxt, type); |
| 19096 | else |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19097 | ret = xmlSchemaValidateElementBySimpleType(ctxt, type, |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19098 | isNil, valSimpleContent); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19099 | break; |
| 19100 | default: |
| 19101 | ret = -1; |
| 19102 | break; |
| 19103 | } |
| 19104 | if (ret == -1) |
| 19105 | return (-1); |
| 19106 | else |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19107 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19108 | } |
| 19109 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19110 | static int |
| 19111 | xmlSchemaCheckAttrLocallyValid(xmlSchemaValidCtxtPtr ctxt, |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19112 | xmlSchemaAttrStatePtr state) |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19113 | { |
| 19114 | xmlChar *value; |
| 19115 | const xmlChar *defValue; |
| 19116 | xmlSchemaValPtr defVal; |
| 19117 | int fixed; |
| 19118 | int ret; |
| 19119 | |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19120 | if (ctxt->attrInfo->typeDef == NULL) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19121 | state->state = XML_SCHEMAS_ATTR_TYPE_NOT_RESOLVED; |
| 19122 | return (XML_SCHEMAS_ATTR_TYPE_NOT_RESOLVED); |
| 19123 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19124 | ctxt->node = ctxt->attrInfo->node; |
| 19125 | ctxt->cur = ctxt->node->children; |
| 19126 | value = xmlNodeListGetString(ctxt->node->doc, ctxt->cur, 1); |
| 19127 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19128 | /* |
| 19129 | * NOTE: This call also checks the content nodes for correct type. |
| 19130 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19131 | ret = xmlSchemaValidateSimpleTypeValue(ctxt, ctxt->attrInfo->typeDef, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19132 | value, 1, 1, 1, 1); |
| 19133 | |
| 19134 | /* |
| 19135 | * Handle 'fixed' attributes. |
| 19136 | */ |
| 19137 | if (ret > 0) { |
| 19138 | state->state = XML_SCHEMAS_ATTR_INVALID_VALUE; |
| 19139 | /* |
| 19140 | * NOTE: Fixed value constraints will be not |
| 19141 | * applied if the value was invalid, because: |
| 19142 | * 1. The validation process does not return a precomputed |
| 19143 | * value. |
| 19144 | * 2. An invalid value implies a violation of a fixed |
| 19145 | * value constraint. |
| 19146 | */ |
| 19147 | } else if (ret == 0) { |
| 19148 | state->state = XML_SCHEMAS_ATTR_CHECKED; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19149 | if (xmlSchemaGetEffectiveValueConstraint( |
| 19150 | (xmlSchemaAttributePtr) ctxt->attrInfo->decl, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19151 | &fixed, &defValue, &defVal) && (fixed == 1)) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 19152 | |
| 19153 | int ws = xmlSchemaGetWhiteSpaceFacetValue( |
| 19154 | ctxt->attrInfo->typeDef); |
| 19155 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19156 | /* |
| 19157 | * cvc-au : Attribute Locally Valid (Use) |
| 19158 | * For an attribute information item to be·valid· |
| 19159 | * with respect to an attribute use its ·normalized |
| 19160 | * value· must match the canonical lexical representation |
| 19161 | * of the attribute use's {value constraint} value, if it |
| 19162 | * is present and fixed. |
| 19163 | */ |
| 19164 | /* |
| 19165 | * NOTE: the validation context holds in ctxt->value the |
| 19166 | * precomputed value of the attribute; well for some types, |
| 19167 | * fallback to string comparison if no computed value |
| 19168 | * exists. |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19169 | * TODO: Use the *normalized* value and the *canonical* fixed |
| 19170 | * value. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19171 | */ |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 19172 | if (ctxt->value != NULL) { |
| 19173 | if (defVal == NULL) { |
| 19174 | xmlSchemaTypePtr prim; |
| 19175 | /* |
| 19176 | * Oops, the value was not computed. |
| 19177 | */ |
| 19178 | prim = xmlSchemaGetPrimitiveType(ctxt->attrInfo->typeDef); |
| 19179 | if (prim->builtInType == XML_SCHEMAS_STRING) { |
| 19180 | xmlSchemaTypePtr builtIn; |
| 19181 | |
| 19182 | builtIn = xmlSchemaGetBuiltInTypeAncestor( |
| 19183 | ctxt->attrInfo->typeDef); |
| 19184 | defVal = xmlSchemaNewStringValue( |
| 19185 | builtIn->builtInType, value); |
| 19186 | ((xmlSchemaAttributePtr) ctxt->attrInfo->decl)->defVal = |
| 19187 | defVal; |
| 19188 | value = NULL; |
| 19189 | } else { |
| 19190 | xmlSchemaVErr(ctxt, ctxt->attrInfo->node, |
| 19191 | XML_SCHEMAV_INTERNAL, |
| 19192 | "Internal error: xmlSchemaCheckAttrLocallyValid, " |
| 19193 | "could not aquire a precomputed vale", |
| 19194 | NULL, NULL); |
| 19195 | } |
| 19196 | } |
| 19197 | if (defVal != NULL) { |
| 19198 | if (xmlSchemaCompareValuesWhtsp(ctxt->value, |
| 19199 | (xmlSchemaWhitespaceValueType) ws, |
| 19200 | defVal, (xmlSchemaWhitespaceValueType) ws) != 0) |
| 19201 | state->state = |
| 19202 | XML_SCHEMAS_ATTR_INVALID_FIXED_VALUE; |
| 19203 | } |
| 19204 | } else if (! xmlStrEqual(defValue, BAD_CAST value)) { |
| 19205 | /* |
| 19206 | * TODO: Remove this and ensure computed values to be |
| 19207 | * existent. |
| 19208 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19209 | state->state = |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame^] | 19210 | XML_SCHEMAS_ATTR_INVALID_FIXED_VALUE; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19211 | } |
| 19212 | } |
| 19213 | } |
| 19214 | if (value != NULL) { |
| 19215 | xmlFree(value); |
| 19216 | } |
| 19217 | return (ret); |
| 19218 | } |
| 19219 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19220 | /** |
| 19221 | * xmlSchemaValidateAttributes: |
| 19222 | * @ctxt: a schema validation context |
| 19223 | * @elem: an element |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19224 | * @type: the complexType holding the attribute uses |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19225 | * |
| 19226 | * Validate the attributes of an element. |
| 19227 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19228 | * 1. Existent, invalid attributes are reported in the form |
| 19229 | * "prefix:localName". |
| 19230 | * Reason: readability - it is easier to find the actual XML |
| 19231 | * representation of the attributes QName. |
| 19232 | * 2. Missing attributes are reported in the form |
| 19233 | * {"URI", "localName"}. |
| 19234 | * This is necessary, since the the prefix need not to be declared |
| 19235 | * at all, and thus is not computable. |
| 19236 | * |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19237 | * Returns 0 if the element is schemas valid, a positive error code |
| 19238 | * number otherwise and -1 in case of internal or API error. |
| 19239 | */ |
| 19240 | static int |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19241 | xmlSchemaValidateAttributes(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem, xmlSchemaTypePtr type) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19242 | { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19243 | const xmlChar *nsURI; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19244 | int ret; |
| 19245 | xmlAttrPtr attr; /* An attribute on the element. */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19246 | const xmlChar *defValue; |
| 19247 | xmlSchemaValPtr defVal; |
| 19248 | int fixed; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19249 | xmlSchemaAttributeLinkPtr attrUse = NULL; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19250 | xmlSchemaAttributePtr attrDecl; |
Daniel Veillard | c85d0fe | 2004-04-16 16:46:51 +0000 | [diff] [blame] | 19251 | int found; |
William M. Brack | 803812b | 2004-06-03 02:11:24 +0000 | [diff] [blame] | 19252 | xmlSchemaAttrStatePtr curState, reqAttrStates = NULL, reqAttrStatesTop = NULL; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19253 | xmlSchemaAttrStatePtr defAttrStates = NULL, defAttrStatesTop = NULL; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19254 | xmlNodePtr oldnode; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19255 | #ifdef DEBUG_ATTR_VALIDATION |
| 19256 | int redundant = 0; |
| 19257 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19258 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19259 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19260 | /* |
| 19261 | * Allow all attributes if the type is anyType. |
| 19262 | */ |
| 19263 | if (type == xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE)) |
| 19264 | return (0); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19265 | |
| 19266 | oldnode = ctxt->node; |
| 19267 | if (type != NULL) |
| 19268 | attrUse = type->attributeUses; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19269 | while (attrUse != NULL) { |
Daniel Veillard | c85d0fe | 2004-04-16 16:46:51 +0000 | [diff] [blame] | 19270 | found = 0; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19271 | attrDecl = attrUse->attr; |
| 19272 | #ifdef DEBUG_ATTR_VALIDATION |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19273 | printf("attr use - name: %s\n", xmlSchemaGetAttrName(attrDecl)); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19274 | printf("attr use - use: %d\n", attrDecl->occurs); |
| 19275 | #endif |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19276 | for (curState = ctxt->attr; curState != NULL; curState = curState->next) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19277 | |
| 19278 | if (curState->decl == attrUse->attr) { |
| 19279 | #ifdef DEBUG_ATTR_VALIDATION |
| 19280 | redundant = 1; |
| 19281 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19282 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19283 | attr = curState->attr; |
| 19284 | #ifdef DEBUG_ATTR_VALIDATION |
| 19285 | printf("attr - name: %s\n", attr->name); |
| 19286 | if (attr->ns != NULL) |
| 19287 | printf("attr - ns: %s\n", attr->ns->href); |
| 19288 | else |
| 19289 | printf("attr - ns: none\n"); |
| 19290 | #endif |
| 19291 | /* TODO: Can this ever happen? */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19292 | if (attr == NULL) |
| 19293 | continue; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19294 | if (attrDecl->ref != NULL) { |
| 19295 | if (!xmlStrEqual(attr->name, attrDecl->ref)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19296 | continue; |
| 19297 | if (attr->ns != NULL) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19298 | if ((attrDecl->refNs == NULL) || |
| 19299 | (!xmlStrEqual(attr->ns->href, attrDecl->refNs))) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19300 | continue; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19301 | } else if (attrDecl->refNs != NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19302 | continue; |
| 19303 | } |
| 19304 | } else { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19305 | if (!xmlStrEqual(attr->name, attrDecl->name)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19306 | continue; |
| 19307 | /* |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 19308 | * handle the namespaces checks here |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19309 | */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 19310 | if (attr->ns == NULL) { |
| 19311 | /* |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 19312 | * accept an unqualified attribute only if the target |
| 19313 | * namespace of the declaration is absent. |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 19314 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19315 | if (attrDecl->targetNamespace != NULL) |
William M. Brack | e709195 | 2004-05-11 15:09:58 +0000 | [diff] [blame] | 19316 | /* |
| 19317 | * This check was removed, since the target namespace |
| 19318 | * was evaluated during parsing and already took |
| 19319 | * "attributeFormDefault" into account. |
| 19320 | */ |
| 19321 | /* ((attributes->flags & XML_SCHEMAS_ATTR_NSDEFAULT) == 0)) */ |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 19322 | continue; |
| 19323 | } else { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19324 | if (attrDecl->targetNamespace == NULL) |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 19325 | continue; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19326 | if (!xmlStrEqual(attrDecl->targetNamespace, |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 19327 | attr->ns->href)) |
| 19328 | continue; |
| 19329 | } |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19330 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19331 | #ifdef DEBUG_ATTR_VALIDATION |
| 19332 | printf("found\n"); |
| 19333 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19334 | found = 1; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19335 | curState->decl = attrDecl; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19336 | curState->state = XML_SCHEMAS_ATTR_VALIDATE_VALUE; |
| 19337 | /* |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19338 | ret = xmlSchemaCheckAttrLocallyValid(ctxt, attrDecl, curState, attr); |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19339 | */ |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19340 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19341 | if (!found) { |
| 19342 | if (attrDecl->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED) { |
| 19343 | xmlSchemaAttrStatePtr tmp; |
| 19344 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19345 | #ifdef DEBUG_ATTR_VALIDATION |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19346 | printf("required attr not found\n"); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19347 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19348 | /* |
| 19349 | * Add a new dummy attribute state. |
| 19350 | */ |
| 19351 | tmp = (xmlSchemaAttrStatePtr) xmlMalloc(sizeof(xmlSchemaAttrState)); |
| 19352 | if (tmp == NULL) { |
| 19353 | xmlSchemaVErrMemory(ctxt, "registering required attributes", NULL); |
| 19354 | ctxt->node = oldnode; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19355 | goto fatal_exit; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19356 | } |
| 19357 | tmp->attr = NULL; |
| 19358 | tmp->state = XML_SCHEMAS_ATTR_MISSING; |
| 19359 | tmp->decl = attrDecl; |
| 19360 | tmp->next = NULL; |
| 19361 | |
| 19362 | if (reqAttrStates == NULL) { |
| 19363 | reqAttrStates = tmp; |
| 19364 | reqAttrStatesTop = tmp; |
| 19365 | } else { |
| 19366 | reqAttrStatesTop->next = tmp; |
| 19367 | reqAttrStatesTop = tmp; |
| 19368 | } |
| 19369 | } else if ((attrDecl->occurs == XML_SCHEMAS_ATTR_USE_OPTIONAL) && |
| 19370 | (xmlSchemaGetEffectiveValueConstraint(attrDecl, |
| 19371 | &fixed, &defValue, &defVal))) { |
| 19372 | xmlSchemaAttrStatePtr tmp; |
| 19373 | /* |
| 19374 | * Handle non existent default/fixed attributes. |
| 19375 | */ |
| 19376 | tmp = (xmlSchemaAttrStatePtr) |
| 19377 | xmlMalloc(sizeof(xmlSchemaAttrState)); |
| 19378 | if (tmp == NULL) { |
| 19379 | xmlSchemaVErrMemory(ctxt, |
| 19380 | "registering schema specified attributes", NULL); |
| 19381 | ctxt->node = oldnode; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19382 | goto fatal_exit; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19383 | } |
| 19384 | tmp->attr = NULL; |
| 19385 | tmp->state = XML_SCHEMAS_ATTR_DEFAULT; |
| 19386 | tmp->decl = attrDecl; |
| 19387 | tmp->value = defValue; |
| 19388 | tmp->next = NULL; |
| 19389 | |
| 19390 | if (defAttrStates == NULL) { |
| 19391 | defAttrStates = tmp; |
| 19392 | defAttrStates = tmp; |
| 19393 | } else { |
| 19394 | defAttrStates->next = tmp; |
| 19395 | defAttrStatesTop = tmp; |
| 19396 | } |
| 19397 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19398 | } |
| 19399 | attrUse = attrUse->next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19400 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19401 | /* |
| 19402 | * Add required attributes to the attribute states of the context. |
| 19403 | */ |
| 19404 | if (reqAttrStates != NULL) { |
| 19405 | if (ctxt->attr == NULL) { |
| 19406 | ctxt->attr = reqAttrStates; |
| 19407 | } else { |
| 19408 | ctxt->attrTop->next = reqAttrStates; |
| 19409 | } |
| 19410 | ctxt->attrTop = reqAttrStatesTop; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19411 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19412 | /* |
| 19413 | * Process wildcards. |
| 19414 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19415 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19416 | if ((type != NULL) && (type->attributeWildcard != NULL)) { |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19417 | #ifdef DEBUG_ATTR_VALIDATION |
| 19418 | xmlSchemaWildcardNsPtr ns; |
| 19419 | printf("matching wildcard: [%d] of complexType: %s\n", type->attributeWildcard, type->name); |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 19420 | if (type->attributeWildcard->processContents == |
| 19421 | XML_SCHEMAS_ANY_LAX) |
| 19422 | printf("processContents: lax\n"); |
| 19423 | else if (type->attributeWildcard->processContents == |
| 19424 | XML_SCHEMAS_ANY_STRICT) |
| 19425 | printf("processContents: strict\n"); |
| 19426 | else |
| 19427 | printf("processContents: skip\n"); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19428 | if (type->attributeWildcard->any) |
| 19429 | printf("type: any\n"); |
| 19430 | else if (type->attributeWildcard->negNsSet != NULL) { |
| 19431 | printf("type: negated\n"); |
| 19432 | if (type->attributeWildcard->negNsSet->value == NULL) |
| 19433 | printf("ns: (absent)\n"); |
| 19434 | else |
| 19435 | printf("ns: %s\n", type->attributeWildcard->negNsSet->value); |
| 19436 | } else if (type->attributeWildcard->nsSet != NULL) { |
| 19437 | printf("type: set\n"); |
| 19438 | ns = type->attributeWildcard->nsSet; |
| 19439 | while (ns != NULL) { |
| 19440 | if (ns->value == NULL) |
| 19441 | printf("ns: (absent)\n"); |
| 19442 | else |
| 19443 | printf("ns: %s\n", ns->value); |
| 19444 | ns = ns->next; |
| 19445 | } |
| 19446 | } else |
| 19447 | printf("empty\n"); |
| 19448 | |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 19449 | |
| 19450 | #endif |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19451 | curState = ctxt->attr; |
| 19452 | while (curState != NULL) { |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 19453 | if (curState->state == XML_SCHEMAS_ATTR_UNKNOWN) { |
| 19454 | if (curState->attr->ns != NULL) |
| 19455 | nsURI = curState->attr->ns->href; |
| 19456 | else |
| 19457 | nsURI = NULL; |
| 19458 | if (xmlSchemaMatchesWildcardNs(type->attributeWildcard, |
| 19459 | nsURI)) { |
| 19460 | /* |
| 19461 | * Handle processContents. |
| 19462 | */ |
| 19463 | if ((type->attributeWildcard->processContents == |
| 19464 | XML_SCHEMAS_ANY_LAX) || |
| 19465 | (type->attributeWildcard->processContents == |
| 19466 | XML_SCHEMAS_ANY_STRICT)) { |
| 19467 | |
| 19468 | attr = curState->attr; |
| 19469 | attrDecl = xmlSchemaGetAttribute(ctxt->schema, |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19470 | attr->name, nsURI); |
| 19471 | curState->decl = attrDecl; |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 19472 | if (attrDecl != NULL) { |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 19473 | curState->decl = attrDecl; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19474 | curState->state = XML_SCHEMAS_ATTR_VALIDATE_VALUE; |
| 19475 | /* TODO |
| 19476 | ret = xmlSchemaCheckAttrLocallyValid(ctxt, attrDecl, curState, attr); |
| 19477 | */ |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 19478 | } else if (type->attributeWildcard->processContents == |
| 19479 | XML_SCHEMAS_ANY_LAX) { |
| 19480 | curState->state = XML_SCHEMAS_ATTR_CHECKED; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19481 | } else |
| 19482 | curState->state = XML_SCHEMAS_ATTR_WILD_NO_DECL; |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 19483 | } else |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19484 | curState->state = XML_SCHEMAS_ATTR_CHECKED; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19485 | } |
Daniel Veillard | 8acdfbf | 2004-06-03 16:00:59 +0000 | [diff] [blame] | 19486 | } |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19487 | curState = curState->next; |
| 19488 | } |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19489 | } |
| 19490 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19491 | if (ctxt->attr != NULL) { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19492 | int valueNeeded; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19493 | |
| 19494 | /* |
| 19495 | * Validate the value of the attribute. |
| 19496 | */ |
| 19497 | if (ctxt->value != NULL) { |
| 19498 | xmlSchemaFreeValue(ctxt->value); |
| 19499 | ctxt->value = NULL; |
| 19500 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19501 | curState = ctxt->attr; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19502 | while ((curState != NULL) && (curState != ctxt->attrTop->next)) { |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19503 | valueNeeded = 0; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19504 | switch (curState->state) { |
| 19505 | case XML_SCHEMAS_ATTR_VALIDATE_VALUE: |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19506 | |
| 19507 | /* |
| 19508 | * Create an attribute info if needed. |
| 19509 | */ |
| 19510 | if (ctxt->attrInfo == NULL) { |
| 19511 | ctxt->attrInfo = (xmlSchemaElemInfoPtr) |
| 19512 | xmlMalloc(sizeof(xmlSchemaElemInfo)); |
| 19513 | if (ctxt->attrInfo == NULL) { |
| 19514 | xmlSchemaVErrMemory(ctxt, |
| 19515 | "allocating an attribute info", NULL); |
| 19516 | goto fatal_exit; |
| 19517 | } |
| 19518 | } |
| 19519 | /* |
| 19520 | * Init the attribute info. |
| 19521 | */ |
| 19522 | ctxt->attrInfo->flags = 0; |
| 19523 | ctxt->attrInfo->node = (xmlNodePtr) curState->attr; |
| 19524 | ctxt->attrInfo->decl = (xmlSchemaTypePtr) curState->decl; |
| 19525 | ctxt->attrInfo->value = NULL; |
| 19526 | if (curState->decl != NULL) |
| 19527 | ctxt->attrInfo->typeDef = curState->decl->subtypes; |
| 19528 | else |
| 19529 | ctxt->attrInfo->typeDef = NULL; |
| 19530 | if (curState->attr->ns != NULL) |
| 19531 | ctxt->attrInfo->namespaceName = |
| 19532 | curState->attr->ns->href; |
| 19533 | else |
| 19534 | ctxt->attrInfo->namespaceName = NULL; |
| 19535 | ctxt->attrInfo->localName = curState->attr->name; |
| 19536 | |
| 19537 | ctxt->nodeInfo = ctxt->attrInfo; |
| 19538 | |
| 19539 | #ifdef IDC_ENABLED |
| 19540 | /* |
| 19541 | * Evaluate IDCs. |
| 19542 | */ |
| 19543 | if (ctxt->xpathStates != NULL) { |
| 19544 | ret = xmlSchemaXPathEvaluate(ctxt, |
| 19545 | XML_ATTRIBUTE_NODE); |
| 19546 | if (ret == -1) |
| 19547 | goto fatal_exit; |
| 19548 | } |
| 19549 | |
| 19550 | #endif |
| 19551 | ret = xmlSchemaCheckAttrLocallyValid(ctxt, curState); |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19552 | if (ret == -1) |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19553 | goto fatal_exit; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19554 | if ((ret != 0) && (ctxt->value != NULL)) { |
| 19555 | xmlSchemaFreeValue(ctxt->value); |
| 19556 | ctxt->value = NULL; |
| 19557 | } |
| 19558 | /* No break on purpose. */ |
| 19559 | case XML_SCHEMAS_ATTR_CHECKED: |
| 19560 | #ifdef IDC_ENABLED |
| 19561 | if (ctxt->xpathStates != NULL) { |
| 19562 | /* |
| 19563 | * Evaluate IDCs. |
| 19564 | */ |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19565 | if (ctxt->value != NULL) { |
| 19566 | ctxt->attrInfo->value = ctxt->value; |
| 19567 | ctxt->value = NULL; |
| 19568 | } |
| 19569 | if (xmlSchemaXPathProcessHistory(ctxt, ctxt->depth +1) == -1) |
| 19570 | goto fatal_exit; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19571 | } |
| 19572 | break; |
| 19573 | #endif |
| 19574 | default: |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19575 | break; |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19576 | } |
| 19577 | curState = curState->next; |
| 19578 | } |
| 19579 | |
| 19580 | /* |
| 19581 | * Report missing and illegal attributes. |
| 19582 | */ |
| 19583 | curState = ctxt->attr; |
| 19584 | while ((curState != NULL) && (curState != ctxt->attrTop->next)) { |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19585 | if (curState->state != XML_SCHEMAS_ATTR_CHECKED) { |
| 19586 | attr = curState->attr; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19587 | if (curState->decl != NULL) { |
| 19588 | if (curState->decl->ref != NULL) |
| 19589 | attrDecl = curState->decl->refDecl; |
| 19590 | else |
| 19591 | attrDecl = curState->decl; |
| 19592 | } else |
| 19593 | attrDecl = NULL; |
| 19594 | if (curState->state == XML_SCHEMAS_ATTR_MISSING) { |
| 19595 | xmlSchemaVMissingAttrErr(ctxt, elem, attrDecl); |
| 19596 | } else if (curState->state == |
| 19597 | XML_SCHEMAS_ATTR_TYPE_NOT_RESOLVED) { |
| 19598 | xmlSchemaVCustomErr(ctxt, |
| 19599 | XML_SCHEMAV_CVC_ATTRIBUTE_2, |
| 19600 | (xmlNodePtr) attr, |
| 19601 | (xmlSchemaTypePtr) attrDecl, |
| 19602 | "The type definition is absent", |
| 19603 | NULL); |
| 19604 | } else if (curState->state == |
| 19605 | XML_SCHEMAS_ATTR_INVALID_FIXED_VALUE) { |
| 19606 | xmlSchemaVCustomErr(ctxt, |
| 19607 | XML_SCHEMAV_CVC_AU, |
| 19608 | (xmlNodePtr) attr, (xmlSchemaTypePtr) attrDecl, |
| 19609 | "The value does not match the fixed value " |
| 19610 | "constraint", NULL); |
Kasimier T. Buchcik | 25799ce | 2005-02-15 14:39:48 +0000 | [diff] [blame] | 19611 | } else if (curState->state == XML_SCHEMAS_ATTR_WILD_NO_DECL) { |
| 19612 | xmlSchemaVWildcardErr(ctxt, |
| 19613 | XML_SCHEMAV_CVC_WILDCARD, |
| 19614 | (xmlNodePtr) attr, |
| 19615 | type->attributeWildcard, |
| 19616 | "No global attribute declaration found, but " |
| 19617 | "stipulated by the strict processContents of " |
| 19618 | "the wildcard"); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19619 | } else if (curState->state == XML_SCHEMAS_ATTR_UNKNOWN) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 19620 | /* TODO: "prohibited" won't ever be touched here!. |
| 19621 | (curState->state == XML_SCHEMAS_ATTR_PROHIBITED)) |
| 19622 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19623 | /* |
| 19624 | * TODO: One might report different error messages |
| 19625 | * for the following errors. |
| 19626 | */ |
| 19627 | if ((type == NULL) || (type->attributeWildcard == NULL)) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 19628 | xmlSchemaVIllegalAttrErr(ctxt, |
| 19629 | XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_1, attr); |
| 19630 | } else { |
| 19631 | xmlSchemaVIllegalAttrErr(ctxt, |
| 19632 | XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_2, attr); |
| 19633 | } |
| 19634 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19635 | } |
| 19636 | curState = curState->next; |
| 19637 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19638 | } |
| 19639 | |
| 19640 | /* |
| 19641 | * Add missing default/fixed attributes. |
| 19642 | */ |
| 19643 | if (ctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) { |
| 19644 | curState = defAttrStates; |
| 19645 | while (curState != NULL) { |
| 19646 | attrDecl = curState->decl; |
| 19647 | if (attrDecl->ref != NULL) |
| 19648 | attrDecl = attrDecl->refDecl; |
| 19649 | /* |
| 19650 | * PSVI: Add a new attribute node to the current element. |
| 19651 | */ |
| 19652 | if (attrDecl->targetNamespace == NULL) { |
| 19653 | xmlNewProp(elem, attrDecl->name, curState->value); |
| 19654 | } else { |
| 19655 | xmlNsPtr ns; |
| 19656 | |
| 19657 | ns = xmlSearchNsByHref(elem->doc, elem, |
| 19658 | attrDecl->targetNamespace); |
| 19659 | if (ns == NULL) { |
| 19660 | xmlChar prefix[12]; |
| 19661 | int counter = 1; |
| 19662 | |
| 19663 | attr = curState->attr; |
| 19664 | /* |
| 19665 | * Create a namespace declaration on the validation |
| 19666 | * root node if no namespace declaration is in scope. |
| 19667 | */ |
| 19668 | snprintf((char *) prefix, sizeof(prefix), "p"); |
| 19669 | /* |
| 19670 | * This is somehow not performant, since the ancestor |
| 19671 | * axis beyond @elem will be searched as well. |
| 19672 | */ |
| 19673 | ns = xmlSearchNs(elem->doc, elem, BAD_CAST prefix); |
| 19674 | while (ns != NULL) { |
| 19675 | if (counter > 1000) { |
| 19676 | xmlSchemaVErr(ctxt, (xmlNodePtr) attr, |
| 19677 | XML_SCHEMAV_INTERNAL, |
| 19678 | "Internal error: xmlSchemaValidateAttributes, " |
| 19679 | "could not compute a ns prefix for " |
| 19680 | "default/fixed attribute '%s'.\n", |
| 19681 | attrDecl->name, NULL); |
| 19682 | |
| 19683 | break; |
| 19684 | } |
| 19685 | snprintf((char *) prefix, |
| 19686 | sizeof(prefix), "p%d", counter++); |
| 19687 | ns = xmlSearchNs(elem->doc, elem, |
| 19688 | BAD_CAST prefix); |
| 19689 | } |
| 19690 | if (ns == NULL) { |
| 19691 | ns = xmlNewNs(ctxt->validationRoot, |
| 19692 | attrDecl->targetNamespace, BAD_CAST prefix); |
| 19693 | xmlNewNsProp(elem, ns, attrDecl->name, |
| 19694 | curState->value); |
| 19695 | } |
| 19696 | } else { |
| 19697 | xmlNewNsProp(elem, ns, attrDecl->name, |
| 19698 | curState->value); |
| 19699 | } |
| 19700 | } |
| 19701 | curState = curState->next; |
| 19702 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19703 | } |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19704 | ret = ctxt->err; |
| 19705 | goto exit; |
| 19706 | |
| 19707 | fatal_exit: |
| 19708 | ret = -1; |
| 19709 | |
| 19710 | exit: |
| 19711 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19712 | if (defAttrStates != NULL) |
| 19713 | xmlSchemaFreeAttributeStates(defAttrStates); |
| 19714 | |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19715 | #ifdef DEBUG_ATTR_VALIDATION |
| 19716 | if (redundant) |
| 19717 | xmlGenericError(xmlGenericErrorContext, |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19718 | "xmlSchemaValidateAttributes: redundant call by " |
| 19719 | "type: %s\n", type->name); |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19720 | #endif |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19721 | ctxt->nodeInfo = ctxt->elemInfos[ctxt->depth]; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19722 | ctxt->node = oldnode; |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19723 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19724 | } |
| 19725 | |
| 19726 | /** |
| 19727 | * xmlSchemaValidateElement: |
| 19728 | * @ctxt: a schema validation context |
| 19729 | * @elem: an element |
| 19730 | * |
| 19731 | * Validate an element in a tree |
| 19732 | * |
| 19733 | * Returns 0 if the element is schemas valid, a positive error code |
| 19734 | * number otherwise and -1 in case of internal or API error. |
| 19735 | */ |
| 19736 | static int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19737 | xmlSchemaValidateElement(xmlSchemaValidCtxtPtr ctxt) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19738 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19739 | xmlSchemaElementPtr elemDecl; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19740 | int ret = 0; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19741 | |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19742 | /* |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19743 | * This one is called by xmlSchemaValidateDocument and |
| 19744 | * xmlSchemaValidateOneElement. |
| 19745 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19746 | if (ctxt->schema == NULL) { |
| 19747 | /* |
| 19748 | * No schema was specified at time of creation of the validation |
| 19749 | * context. Use xsi:schemaLocation and xsi:noNamespaceSchemaLocation |
| 19750 | * of the instance to build a schema. |
| 19751 | */ |
| 19752 | if (ctxt->pctxt == NULL) |
| 19753 | ctxt->pctxt = xmlSchemaNewParserCtxt("*"); |
| 19754 | if (ctxt->pctxt == NULL) |
| 19755 | return (-1); |
| 19756 | ctxt->schema = xmlSchemaNewSchema(ctxt->pctxt); |
| 19757 | if (ctxt->schema == NULL) |
| 19758 | return (-1); |
| 19759 | /* TODO: assign user data. */ |
| 19760 | ctxt->pctxt->error = ctxt->error; |
| 19761 | ctxt->pctxt->warning = ctxt->warning; |
| 19762 | ctxt->xsiAssemble = 1; |
| 19763 | } else |
| 19764 | ctxt->xsiAssemble = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19765 | /* |
| 19766 | * Assemble new schemata using xsi. |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19767 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19768 | if (ctxt->xsiAssemble) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19769 | ret = xmlSchemaAssembleByXSIElem(ctxt, ctxt->node); |
| 19770 | if (ret == -1) { |
| 19771 | xmlSchemaVCustomErr(ctxt, |
| 19772 | XML_SCHEMAV_INTERNAL, |
| 19773 | ctxt->node, NULL, |
| 19774 | "Internal error: xmlSchemaValidateElement, " |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19775 | "assembling schema by xsi", NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19776 | } |
| 19777 | /* |
| 19778 | * NOTE: We won't react on schema parser errors here. |
| 19779 | * TODO: But a warning would be nice. |
| 19780 | */ |
| 19781 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19782 | if (ret != -1) { |
| 19783 | if (ctxt->node->ns != NULL) |
| 19784 | elemDecl = xmlSchemaGetElem(ctxt->schema, ctxt->node->name, |
| 19785 | ctxt->node->ns->href); |
| 19786 | else |
| 19787 | elemDecl = xmlSchemaGetElem(ctxt->schema, ctxt->node->name, NULL); |
| 19788 | |
| 19789 | if (elemDecl == NULL) { |
| 19790 | xmlSchemaVCustomErr(ctxt, |
| 19791 | XML_SCHEMAV_CVC_ELT_1, |
| 19792 | ctxt->node, NULL, |
| 19793 | "No matching global declaration available", NULL); |
| 19794 | ret = XML_SCHEMAV_CVC_ELT_1; |
| 19795 | } else { |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 19796 | #ifdef IDC_ENABLED |
| 19797 | /* |
| 19798 | * Augment the IDC definitions. |
| 19799 | */ |
| 19800 | if (ctxt->schema->idcDef != NULL) { |
| 19801 | xmlHashScan(ctxt->schema->idcDef, |
| 19802 | (xmlHashScanner) xmlSchemaAugmentIDC, ctxt); |
| 19803 | } |
| 19804 | #endif |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19805 | #ifdef ELEM_INFO_ENABLED |
| 19806 | ctxt->depth = -1; |
| 19807 | xmlSchemaBeginElement(ctxt); |
| 19808 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19809 | ret = xmlSchemaValidateElementByDeclaration(ctxt, elemDecl); |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19810 | #ifdef ELEM_INFO_ENABLED |
| 19811 | xmlSchemaEndElement(ctxt); |
| 19812 | #endif |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19813 | if (ret < 0) { |
| 19814 | xmlSchemaVCustomErr(ctxt, |
| 19815 | XML_SCHEMAV_INTERNAL, ctxt->node, NULL, |
| 19816 | "Internal error: xmlSchemaValidateElement, " |
| 19817 | "calling validation by declaration", NULL); |
| 19818 | } |
| 19819 | } |
| 19820 | } |
| 19821 | /* ctxt->xsiAssemble = 0; */ |
| 19822 | if (ctxt->xsiAssemble) { |
| 19823 | if (ctxt->schema != NULL) { |
| 19824 | xmlSchemaFree(ctxt->schema); |
| 19825 | ctxt->schema = NULL; |
| 19826 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19827 | } |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19828 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19829 | } |
| 19830 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19831 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19832 | /** |
Kasimier T. Buchcik | 5eba91f | 2004-09-08 09:17:27 +0000 | [diff] [blame] | 19833 | * xmlSchemaValidateOneElement: |
| 19834 | * @ctxt: a schema validation context |
| 19835 | * @elem: an element node |
| 19836 | * |
| 19837 | * Validate a branch of a tree, starting with the given @elem. |
| 19838 | * |
| 19839 | * Returns 0 if the element and its subtree is valid, a positive error |
| 19840 | * code number otherwise and -1 in case of an internal or API error. |
| 19841 | */ |
| 19842 | int |
| 19843 | xmlSchemaValidateOneElement(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem) |
| 19844 | { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19845 | if ((ctxt == NULL) || (elem == NULL) || (elem->type != XML_ELEMENT_NODE)) |
Kasimier T. Buchcik | 5eba91f | 2004-09-08 09:17:27 +0000 | [diff] [blame] | 19846 | return (-1); |
| 19847 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19848 | if (ctxt->schema == NULL) { |
| 19849 | xmlSchemaVErr(ctxt, NULL, |
| 19850 | XML_SCHEMAV_INTERNAL, |
| 19851 | "API error: xmlSchemaValidateOneElement, " |
| 19852 | "no schema specified.\n", NULL, NULL); |
| 19853 | return (-1); |
| 19854 | } |
| 19855 | |
Kasimier T. Buchcik | 5eba91f | 2004-09-08 09:17:27 +0000 | [diff] [blame] | 19856 | ctxt->doc = elem->doc; |
| 19857 | ctxt->err = 0; |
| 19858 | ctxt->nberrors = 0; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19859 | ctxt->node = elem; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19860 | ctxt->validationRoot = elem; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19861 | return (xmlSchemaValidateElement(ctxt)); |
Kasimier T. Buchcik | 5eba91f | 2004-09-08 09:17:27 +0000 | [diff] [blame] | 19862 | } |
| 19863 | |
| 19864 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19865 | * xmlSchemaValidateDocument: |
| 19866 | * @ctxt: a schema validation context |
| 19867 | * @doc: a parsed document tree |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19868 | * @xsiAssemble: should schemata be added if requested by the instance? |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19869 | * |
| 19870 | * Validate a document tree in memory. |
| 19871 | * |
| 19872 | * Returns 0 if the document is schemas valid, a positive error code |
| 19873 | * number otherwise and -1 in case of internal or API error. |
| 19874 | */ |
| 19875 | static int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19876 | xmlSchemaValidateDocument(xmlSchemaValidCtxtPtr ctxt, xmlDocPtr doc) |
| 19877 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19878 | xmlNodePtr root; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 19879 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19880 | root = xmlDocGetRootElement(doc); |
| 19881 | if (root == NULL) { |
Kasimier T. Buchcik | bea2354 | 2004-08-25 20:35:45 +0000 | [diff] [blame] | 19882 | xmlSchemaVCustomErr(ctxt, |
| 19883 | XML_SCHEMAV_DOCUMENT_ELEMENT_MISSING, |
| 19884 | (xmlNodePtr) doc, NULL, |
| 19885 | "The document has no document element", NULL); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19886 | return (ctxt->err); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19887 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19888 | /* |
| 19889 | * Okay, start the recursive validation |
| 19890 | */ |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19891 | ctxt->node = root; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19892 | ctxt->validationRoot = root; |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 19893 | xmlSchemaValidateElement(ctxt); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19894 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19895 | return (ctxt->err); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19896 | } |
| 19897 | |
| 19898 | /************************************************************************ |
| 19899 | * * |
| 19900 | * SAX Validation code * |
| 19901 | * * |
| 19902 | ************************************************************************/ |
| 19903 | |
| 19904 | /************************************************************************ |
| 19905 | * * |
| 19906 | * Validation interfaces * |
| 19907 | * * |
| 19908 | ************************************************************************/ |
| 19909 | |
| 19910 | /** |
| 19911 | * xmlSchemaNewValidCtxt: |
| 19912 | * @schema: a precompiled XML Schemas |
| 19913 | * |
| 19914 | * Create an XML Schemas validation context based on the given schema |
| 19915 | * |
| 19916 | * Returns the validation context or NULL in case of error |
| 19917 | */ |
| 19918 | xmlSchemaValidCtxtPtr |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19919 | xmlSchemaNewValidCtxt(xmlSchemaPtr schema) |
| 19920 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19921 | xmlSchemaValidCtxtPtr ret; |
| 19922 | |
| 19923 | ret = (xmlSchemaValidCtxtPtr) xmlMalloc(sizeof(xmlSchemaValidCtxt)); |
| 19924 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19925 | xmlSchemaVErrMemory(NULL, "allocating validation context", NULL); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19926 | return (NULL); |
| 19927 | } |
| 19928 | memset(ret, 0, sizeof(xmlSchemaValidCtxt)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 19929 | ret->schema = schema; |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19930 | ret->attrTop = NULL; |
| 19931 | ret->attr = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19932 | return (ret); |
| 19933 | } |
| 19934 | |
| 19935 | /** |
| 19936 | * xmlSchemaFreeValidCtxt: |
| 19937 | * @ctxt: the schema validation context |
| 19938 | * |
| 19939 | * Free the resources associated to the schema validation context |
| 19940 | */ |
| 19941 | void |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19942 | xmlSchemaFreeValidCtxt(xmlSchemaValidCtxtPtr ctxt) |
| 19943 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19944 | if (ctxt == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19945 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 19946 | if (ctxt->attr != NULL) |
Daniel Veillard | 3646d64 | 2004-06-02 19:19:14 +0000 | [diff] [blame] | 19947 | xmlSchemaFreeAttributeStates(ctxt->attr); |
Daniel Veillard | 88c5891 | 2002-04-23 07:12:20 +0000 | [diff] [blame] | 19948 | if (ctxt->value != NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 19949 | xmlSchemaFreeValue(ctxt->value); |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 19950 | if (ctxt->pctxt != NULL) { |
| 19951 | xmlSchemaFreeParserCtxt(ctxt->pctxt); |
| 19952 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19953 | |
| 19954 | #ifdef IDC_ENABLED |
| 19955 | if (ctxt->idcNodes != NULL) { |
| 19956 | int i; |
| 19957 | xmlSchemaPSVIIDCNodePtr item; |
| 19958 | |
| 19959 | for (i = 0; i < ctxt->nbIdcNodes; i++) { |
| 19960 | item = ctxt->idcNodes[i]; |
| 19961 | xmlFree(item->keys); |
| 19962 | xmlFree(item); |
| 19963 | } |
| 19964 | xmlFree(ctxt->idcNodes); |
| 19965 | } |
| 19966 | |
| 19967 | if (ctxt->idcKeys != NULL) { |
| 19968 | int i; |
| 19969 | for (i = 0; i < ctxt->nbIdcKeys; i++) |
| 19970 | xmlSchemaIDCFreeKey(ctxt->idcKeys[i]); |
| 19971 | xmlFree(ctxt->idcKeys); |
| 19972 | } |
| 19973 | |
| 19974 | if (ctxt->xpathStates != NULL) |
| 19975 | xmlSchemaFreeIDCStateObjList(ctxt->xpathStates); |
| 19976 | if (ctxt->xpathStatePool != NULL) |
| 19977 | xmlSchemaFreeIDCStateObjList(ctxt->xpathStatePool); |
| 19978 | |
| 19979 | /* |
| 19980 | * Augmented IDC information. |
| 19981 | */ |
| 19982 | if (ctxt->aidcs != NULL) { |
| 19983 | xmlSchemaIDCAugPtr cur = ctxt->aidcs, next; |
| 19984 | do { |
| 19985 | next = cur->next; |
| 19986 | xmlFree(cur); |
| 19987 | cur = next; |
| 19988 | } while (cur != NULL); |
| 19989 | } |
| 19990 | #endif /* IDC_ENABLED */ |
| 19991 | #ifdef ELEM_INFO_ENABLED |
Kasimier T. Buchcik | bd2a7d1 | 2005-02-16 12:27:25 +0000 | [diff] [blame] | 19992 | if (ctxt->attrInfo != NULL) { |
| 19993 | if (ctxt->attrInfo->value != NULL) |
| 19994 | xmlSchemaFreeValue(ctxt->attrInfo->value); |
| 19995 | xmlFree(ctxt->attrInfo); |
| 19996 | } |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 19997 | if (ctxt->elemInfos != NULL) { |
| 19998 | int i; |
| 19999 | xmlSchemaElemInfoPtr info; |
Kasimier T. Buchcik | 0a59852 | 2005-01-31 17:02:07 +0000 | [diff] [blame] | 20000 | |
Kasimier T. Buchcik | e8a550b | 2005-01-27 12:49:31 +0000 | [diff] [blame] | 20001 | for (i = 0; i < ctxt->sizeElemInfos; i++) { |
| 20002 | info = ctxt->elemInfos[i]; |
| 20003 | if (info == NULL) |
| 20004 | continue; |
| 20005 | if (info->value != NULL) |
| 20006 | xmlSchemaFreeValue(info->value); |
| 20007 | #ifdef IDC_ENABLED |
| 20008 | if (info->idcMatchers != NULL) |
| 20009 | xmlSchemaIDCFreeMatcherList(info->idcMatchers); |
| 20010 | #endif |
| 20011 | /* |
| 20012 | * TODO: Free the IDC table if still existent. |
| 20013 | */ |
| 20014 | |
| 20015 | /* |
| 20016 | xmlFree(info->localName); |
| 20017 | if (info->namespaceName != NULL) |
| 20018 | xmlFree(info->namespaceName); |
| 20019 | */ |
| 20020 | xmlFree(info); |
| 20021 | } |
| 20022 | xmlFree(ctxt->elemInfos); |
| 20023 | } |
| 20024 | #endif |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20025 | xmlFree(ctxt); |
| 20026 | } |
| 20027 | |
| 20028 | /** |
| 20029 | * xmlSchemaSetValidErrors: |
| 20030 | * @ctxt: a schema validation context |
| 20031 | * @err: the error function |
| 20032 | * @warn: the warning function |
Daniel Veillard | a9b66d0 | 2002-12-11 14:23:49 +0000 | [diff] [blame] | 20033 | * @ctx: the functions context |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20034 | * |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 20035 | * Set the error and warning callback informations |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20036 | */ |
| 20037 | void |
| 20038 | xmlSchemaSetValidErrors(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20039 | xmlSchemaValidityErrorFunc err, |
| 20040 | xmlSchemaValidityWarningFunc warn, void *ctx) |
| 20041 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20042 | if (ctxt == NULL) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20043 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20044 | ctxt->error = err; |
| 20045 | ctxt->warning = warn; |
| 20046 | ctxt->userData = ctx; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20047 | if (ctxt->pctxt != NULL) |
| 20048 | xmlSchemaSetParserErrors(ctxt->pctxt, err, warn, ctx); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20049 | } |
| 20050 | |
| 20051 | /** |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 20052 | * xmlSchemaGetValidErrors: |
| 20053 | * @ctxt: a XML-Schema validation context |
| 20054 | * @err: the error function result |
| 20055 | * @warn: the warning function result |
| 20056 | * @ctx: the functions context result |
| 20057 | * |
| 20058 | * Get the error and warning callback informations |
| 20059 | * |
| 20060 | * Returns -1 in case of error and 0 otherwise |
| 20061 | */ |
| 20062 | int |
| 20063 | xmlSchemaGetValidErrors(xmlSchemaValidCtxtPtr ctxt, |
| 20064 | xmlSchemaValidityErrorFunc * err, |
| 20065 | xmlSchemaValidityWarningFunc * warn, void **ctx) |
| 20066 | { |
| 20067 | if (ctxt == NULL) |
| 20068 | return (-1); |
| 20069 | if (err != NULL) |
| 20070 | *err = ctxt->error; |
| 20071 | if (warn != NULL) |
| 20072 | *warn = ctxt->warning; |
| 20073 | if (ctx != NULL) |
| 20074 | *ctx = ctxt->userData; |
| 20075 | return (0); |
| 20076 | } |
| 20077 | |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20078 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20079 | /** |
Daniel Veillard | 6927b10 | 2004-10-27 17:29:04 +0000 | [diff] [blame] | 20080 | * xmlSchemaSetValidOptions: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20081 | * @ctxt: a schema validation context |
| 20082 | * @options: a combination of xmlSchemaValidOption |
| 20083 | * |
| 20084 | * Sets the options to be used during the validation. |
| 20085 | * |
| 20086 | * Returns 0 in case of success, -1 in case of an |
| 20087 | * API error. |
| 20088 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20089 | int |
| 20090 | xmlSchemaSetValidOptions(xmlSchemaValidCtxtPtr ctxt, |
| 20091 | int options) |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20092 | |
| 20093 | { |
| 20094 | int i; |
| 20095 | |
| 20096 | if (ctxt == NULL) |
| 20097 | return (-1); |
| 20098 | /* |
| 20099 | * WARNING: Change the start value if adding to the |
| 20100 | * xmlSchemaValidOption. |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20101 | * TODO: Is there an other, more easy to maintain, |
| 20102 | * way? |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20103 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20104 | for (i = 1; i < (int) sizeof(int) * 8; i++) { |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20105 | if (options & 1<<i) { |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20106 | xmlSchemaVErr(ctxt, NULL, |
| 20107 | XML_SCHEMAV_INTERNAL, |
| 20108 | "Internal error: xmlSchemaSetValidOptions, " |
| 20109 | "invalid option argument.\n", NULL, NULL); |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20110 | return (-1); |
| 20111 | } |
| 20112 | } |
| 20113 | ctxt->options = options; |
| 20114 | return (0); |
| 20115 | } |
| 20116 | |
| 20117 | /** |
Daniel Veillard | 6927b10 | 2004-10-27 17:29:04 +0000 | [diff] [blame] | 20118 | * xmlSchemaValidCtxtGetOptions: |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20119 | * @ctxt: a schema validation context |
| 20120 | * |
William M. Brack | 21e4ef2 | 2005-01-02 09:53:13 +0000 | [diff] [blame] | 20121 | * Get the validation context options. |
| 20122 | * |
| 20123 | * Returns the option combination or -1 on error. |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20124 | */ |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20125 | int |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20126 | xmlSchemaValidCtxtGetOptions(xmlSchemaValidCtxtPtr ctxt) |
| 20127 | |
| 20128 | { |
| 20129 | if (ctxt == NULL) |
| 20130 | return (-1); |
| 20131 | else |
| 20132 | return (ctxt->options); |
| 20133 | } |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20134 | |
Kasimier T. Buchcik | 876a6db | 2004-09-16 11:31:52 +0000 | [diff] [blame] | 20135 | |
Daniel Veillard | 259f0df | 2004-08-18 09:13:18 +0000 | [diff] [blame] | 20136 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20137 | * xmlSchemaValidateDoc: |
| 20138 | * @ctxt: a schema validation context |
| 20139 | * @doc: a parsed document tree |
| 20140 | * |
| 20141 | * Validate a document tree in memory. |
| 20142 | * |
| 20143 | * Returns 0 if the document is schemas valid, a positive error code |
| 20144 | * number otherwise and -1 in case of internal or API error. |
| 20145 | */ |
| 20146 | int |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20147 | xmlSchemaValidateDoc(xmlSchemaValidCtxtPtr ctxt, xmlDocPtr doc) |
| 20148 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20149 | int ret; |
| 20150 | |
| 20151 | if ((ctxt == NULL) || (doc == NULL)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20152 | return (-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20153 | |
| 20154 | ctxt->doc = doc; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 20155 | ctxt->err = 0; |
Kasimier T. Buchcik | 8787640 | 2004-09-29 13:29:03 +0000 | [diff] [blame] | 20156 | ctxt->nberrors = 0; |
| 20157 | |
| 20158 | /* |
| 20159 | if (ctxt->schema == NULL) { |
| 20160 | xmlSchemaVErr(ctxt, NULL, |
| 20161 | XML_SCHEMAV_INTERNAL, |
| 20162 | "API error: xmlSchemaValidateDoc, " |
| 20163 | "no schema specified and assembling of schemata " |
| 20164 | "using xsi:schemaLocation and xsi:noNamespaceSchemaLocation " |
| 20165 | "is not enabled.\n", NULL, NULL); |
| 20166 | return (-1); |
| 20167 | } |
| 20168 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20169 | ret = xmlSchemaValidateDocument(ctxt, doc); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20170 | return (ret); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20171 | } |
| 20172 | |
| 20173 | /** |
| 20174 | * xmlSchemaValidateStream: |
| 20175 | * @ctxt: a schema validation context |
| 20176 | * @input: the input to use for reading the data |
| 20177 | * @enc: an optional encoding information |
| 20178 | * @sax: a SAX handler for the resulting events |
| 20179 | * @user_data: the context to provide to the SAX handler. |
| 20180 | * |
| 20181 | * Validate a document tree in memory. |
| 20182 | * |
| 20183 | * Returns 0 if the document is schemas valid, a positive error code |
| 20184 | * number otherwise and -1 in case of internal or API error. |
| 20185 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20186 | int |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20187 | xmlSchemaValidateStream(xmlSchemaValidCtxtPtr ctxt, |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20188 | xmlParserInputBufferPtr input, xmlCharEncoding enc, |
| 20189 | xmlSAXHandlerPtr sax, void *user_data) |
| 20190 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20191 | if ((ctxt == NULL) || (input == NULL)) |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20192 | return (-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20193 | ctxt->input = input; |
| 20194 | ctxt->enc = enc; |
| 20195 | ctxt->sax = sax; |
| 20196 | ctxt->user_data = user_data; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 20197 | TODO return (0); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 20198 | } |
| 20199 | |
| 20200 | #endif /* LIBXML_SCHEMAS_ENABLED */ |