2 * schemas.c : implementation of the XML Schema handling and
3 * schema validity checking
5 * See Copyright for the status of this software.
7 * Daniel Veillard <veillard@redhat.com>
12 * - when types are redefined in includes, check that all
13 * types in the redef list are equal
14 * -> need a type equality operation.
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.
18 * - Eliminate item creation for: ??
21 * - For xsi-driven schema acquisition, augment the IDCs after every
22 * acquisition episode (xmlSchemaAugmentIDC).
25 * - Elimated item creation for: <restriction>, <extension>,
26 * <simpleContent>, <complexContent>, <list>, <union>
29 * - http://lists.w3.org/Archives/Public/www-xml-schema-comments/2005JulSep/0337.html
30 * IDC XPath expression and chameleon includes: the targetNamespace is changed, so
31 * XPath will have trouble to resolve to this namespace, since not known.
36 * Schema Component Constraint:
37 * All Group Limited (cos-all-limited)
40 * In xmlSchemaGroupDefReferenceTermFixup() and
42 * In xmlSchemaParseModelGroup()
43 * TODO: Actually this should go to component-level checks,
44 * but is done here due to performance. Move it to an other layer
45 * is schema construction via an API is implemented.
48 /* To avoid EBCDIC trouble when parsing on zOS */
50 #pragma convert("ISO8859-1")
56 #ifdef LIBXML_SCHEMAS_ENABLED
59 #include <libxml/xmlmemory.h>
60 #include <libxml/parser.h>
61 #include <libxml/parserInternals.h>
62 #include <libxml/hash.h>
63 #include <libxml/uri.h>
64 #include <libxml/xmlschemas.h>
65 #include <libxml/schemasInternals.h>
66 #include <libxml/xmlschemastypes.h>
67 #include <libxml/xmlautomata.h>
68 #include <libxml/xmlregexp.h>
69 #include <libxml/dict.h>
70 #include <libxml/encoding.h>
71 #include <libxml/xmlIO.h>
72 #ifdef LIBXML_PATTERN_ENABLED
73 #include <libxml/pattern.h>
75 #ifdef LIBXML_READER_ENABLED
76 #include <libxml/xmlreader.h>
81 /* #define DEBUG_CONTENT 1 */
83 /* #define DEBUG_TYPE 1 */
85 /* #define DEBUG_CONTENT_REGEXP 1 */
87 /* #define DEBUG_AUTOMATA 1 */
89 /* #define DEBUG_IDC */
91 /* #define DEBUG_IDC_NODE_TABLE */
93 /* #define WXS_ELEM_DECL_CONS_ENABLED */
96 #ifndef DEBUG_IDC_NODE_TABLE
97 #define DEBUG_IDC_NODE_TABLE
101 /* #define ENABLE_PARTICLE_RESTRICTION 1 */
103 #define ENABLE_REDEFINE
105 /* #define ENABLE_NAMED_LOCALS */
107 /* #define ENABLE_IDC_NODE_TABLES_TEST */
109 #define DUMP_CONTENT_MODEL
111 #ifdef LIBXML_READER_ENABLED
112 /* #define XML_SCHEMA_READER_ENABLED */
115 #define UNBOUNDED (1 << 30)
117 xmlGenericError(xmlGenericErrorContext, \
118 "Unimplemented block at %s:%d\n", \
121 #define XML_SCHEMAS_NO_NAMESPACE (const xmlChar *) "##"
124 * The XML Schemas namespaces
126 static const xmlChar *xmlSchemaNs = (const xmlChar *)
127 "http://www.w3.org/2001/XMLSchema";
129 static const xmlChar *xmlSchemaInstanceNs = (const xmlChar *)
130 "http://www.w3.org/2001/XMLSchema-instance";
132 static const xmlChar *xmlNamespaceNs = (const xmlChar *)
133 "http://www.w3.org/2000/xmlns/";
136 * Come casting macros.
138 #define ACTXT_CAST (xmlSchemaAbstractCtxtPtr)
139 #define PCTXT_CAST (xmlSchemaParserCtxtPtr)
140 #define VCTXT_CAST (xmlSchemaValidCtxtPtr)
141 #define WXS_BASIC_CAST (xmlSchemaBasicItemPtr)
142 #define WXS_TREE_CAST (xmlSchemaTreeItemPtr)
143 #define WXS_PTC_CAST (xmlSchemaParticlePtr)
144 #define WXS_TYPE_CAST (xmlSchemaTypePtr)
145 #define WXS_ELEM_CAST (xmlSchemaElementPtr)
146 #define WXS_ATTR_GROUP_CAST (xmlSchemaAttributeGroupPtr)
147 #define WXS_ATTR_CAST (xmlSchemaAttributePtr)
148 #define WXS_ATTR_USE_CAST (xmlSchemaAttributeUsePtr)
149 #define WXS_ATTR_PROHIB_CAST (xmlSchemaAttributeUseProhibPtr)
150 #define WXS_MODEL_GROUPDEF_CAST (xmlSchemaModelGroupDefPtr)
151 #define WXS_MODEL_GROUP_CAST (xmlSchemaModelGroupPtr)
152 #define WXS_IDC_CAST (xmlSchemaIDCPtr)
153 #define WXS_QNAME_CAST (xmlSchemaQNameRefPtr)
154 #define WXS_LIST_CAST (xmlSchemaItemListPtr)
157 * Macros to query common properties of components.
159 #define WXS_ITEM_NODE(i) xmlSchemaGetComponentNode(WXS_BASIC_CAST (i))
161 #define WXS_ITEM_TYPE_NAME(i) xmlSchemaGetComponentTypeStr(WXS_BASIC_CAST (i))
163 * Macros for element declarations.
165 #define WXS_ELEM_TYPEDEF(e) (e)->subtypes
167 #define WXS_SUBST_HEAD(item) (item)->refDecl
169 * Macros for attribute declarations.
171 #define WXS_ATTR_TYPEDEF(a) (a)->subtypes
173 * Macros for attribute uses.
175 #define WXS_ATTRUSE_DECL(au) (WXS_ATTR_USE_CAST (au))->attrDecl
177 #define WXS_ATTRUSE_TYPEDEF(au) WXS_ATTR_TYPEDEF(WXS_ATTRUSE_DECL( WXS_ATTR_USE_CAST au))
179 #define WXS_ATTRUSE_DECL_NAME(au) (WXS_ATTRUSE_DECL(au))->name
181 #define WXS_ATTRUSE_DECL_TNS(au) (WXS_ATTRUSE_DECL(au))->targetNamespace
183 * Macros for attribute groups.
185 #define WXS_ATTR_GROUP_HAS_REFS(ag) ((WXS_ATTR_GROUP_CAST (ag))->flags & XML_SCHEMAS_ATTRGROUP_HAS_REFS)
186 #define WXS_ATTR_GROUP_EXPANDED(ag) ((WXS_ATTR_GROUP_CAST (ag))->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED)
188 * Macros for particles.
190 #define WXS_PARTICLE(p) WXS_PTC_CAST (p)
192 #define WXS_PARTICLE_TERM(p) (WXS_PARTICLE(p))->children
194 #define WXS_PARTICLE_TERM_AS_ELEM(p) (WXS_ELEM_CAST WXS_PARTICLE_TERM(p))
196 #define WXS_PARTICLE_MODEL(p) WXS_MODEL_GROUP_CAST WXS_PARTICLE(p)->children
198 * Macros for model groups definitions.
200 #define WXS_MODELGROUPDEF_MODEL(mgd) (WXS_MODEL_GROUP_CAST (mgd))->children
202 * Macros for model groups.
204 #define WXS_IS_MODEL_GROUP(i) \
205 (((i)->type == XML_SCHEMA_TYPE_SEQUENCE) || \
206 ((i)->type == XML_SCHEMA_TYPE_CHOICE) || \
207 ((i)->type == XML_SCHEMA_TYPE_ALL))
209 #define WXS_MODELGROUP_PARTICLE(mg) WXS_PTC_CAST (mg)->children
211 * Macros for schema buckets.
213 #define WXS_IS_BUCKET_INCREDEF(t) (((t) == XML_SCHEMA_SCHEMA_INCLUDE) || \
214 ((t) == XML_SCHEMA_SCHEMA_REDEFINE))
216 #define WXS_IS_BUCKET_IMPMAIN(t) (((t) == XML_SCHEMA_SCHEMA_MAIN) || \
217 ((t) == XML_SCHEMA_SCHEMA_IMPORT))
219 #define WXS_IMPBUCKET(b) ((xmlSchemaImportPtr) (b))
221 #define WXS_INCBUCKET(b) ((xmlSchemaIncludePtr) (b))
223 * Macros for complex/simple types.
225 #define WXS_IS_ANYTYPE(i) \
226 (( (i)->type == XML_SCHEMA_TYPE_BASIC) && \
227 ( (WXS_TYPE_CAST (i))->builtInType == XML_SCHEMAS_ANYTYPE))
229 #define WXS_IS_COMPLEX(i) \
230 (((i)->type == XML_SCHEMA_TYPE_COMPLEX) || \
231 ((i)->builtInType == XML_SCHEMAS_ANYTYPE))
233 #define WXS_IS_SIMPLE(item) \
234 ((item->type == XML_SCHEMA_TYPE_SIMPLE) || \
235 ((item->type == XML_SCHEMA_TYPE_BASIC) && \
236 (item->builtInType != XML_SCHEMAS_ANYTYPE)))
238 #define WXS_IS_ANY_SIMPLE_TYPE(i) \
239 (((i)->type == XML_SCHEMA_TYPE_BASIC) && \
240 ((i)->builtInType == XML_SCHEMAS_ANYSIMPLETYPE))
242 #define WXS_IS_RESTRICTION(t) \
243 ((t)->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION)
245 #define WXS_IS_EXTENSION(t) \
246 ((t)->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION)
248 #define WXS_IS_TYPE_NOT_FIXED(i) \
249 (((i)->type != XML_SCHEMA_TYPE_BASIC) && \
250 (((i)->flags & XML_SCHEMAS_TYPE_INTERNAL_RESOLVED) == 0))
252 #define WXS_IS_TYPE_NOT_FIXED_1(item) \
253 (((item)->type != XML_SCHEMA_TYPE_BASIC) && \
254 (((item)->flags & XML_SCHEMAS_TYPE_FIXUP_1) == 0))
256 #define WXS_TYPE_IS_GLOBAL(t) ((t)->flags & XML_SCHEMAS_TYPE_GLOBAL)
258 #define WXS_TYPE_IS_LOCAL(t) (((t)->flags & XML_SCHEMAS_TYPE_GLOBAL) == 0)
260 * Macros for exclusively for complex types.
262 #define WXS_HAS_COMPLEX_CONTENT(item) \
263 ((item->contentType == XML_SCHEMA_CONTENT_MIXED) || \
264 (item->contentType == XML_SCHEMA_CONTENT_EMPTY) || \
265 (item->contentType == XML_SCHEMA_CONTENT_ELEMENTS))
267 #define WXS_HAS_SIMPLE_CONTENT(item) \
268 ((item->contentType == XML_SCHEMA_CONTENT_SIMPLE) || \
269 (item->contentType == XML_SCHEMA_CONTENT_BASIC))
271 #define WXS_HAS_MIXED_CONTENT(item) \
272 (item->contentType == XML_SCHEMA_CONTENT_MIXED)
274 #define WXS_EMPTIABLE(t) \
275 (xmlSchemaIsParticleEmptiable(WXS_PTC_CAST (t)->subtypes))
277 #define WXS_TYPE_CONTENTTYPE(t) (t)->subtypes
279 #define WXS_TYPE_PARTICLE(t) WXS_PTC_CAST (t)->subtypes
281 #define WXS_TYPE_PARTICLE_TERM(t) WXS_PARTICLE_TERM(WXS_TYPE_PARTICLE(t))
283 * Macros for exclusively for simple types.
285 #define WXS_LIST_ITEMTYPE(t) (t)->subtypes
287 #define WXS_IS_ATOMIC(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC)
289 #define WXS_IS_LIST(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_LIST)
291 #define WXS_IS_UNION(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_UNION)
293 * Misc parser context macros.
295 #define WXS_CONSTRUCTOR(ctx) (ctx)->constructor
297 #define WXS_HAS_BUCKETS(ctx) \
298 ( (WXS_CONSTRUCTOR((ctx))->buckets != NULL) && \
299 (WXS_CONSTRUCTOR((ctx))->buckets->nbItems > 0) )
301 #define WXS_SUBST_GROUPS(ctx) WXS_CONSTRUCTOR((ctx))->substGroups
303 #define WXS_BUCKET(ctx) WXS_CONSTRUCTOR((ctx))->bucket
305 #define WXS_SCHEMA(ctx) (ctx)->schema
307 #define WXS_ADD_LOCAL(ctx, item) \
308 xmlSchemaAddItemSize(&(WXS_BUCKET(ctx)->locals), 10, item)
310 #define WXS_ADD_GLOBAL(ctx, item) \
311 xmlSchemaAddItemSize(&(WXS_BUCKET(ctx)->globals), 5, item)
313 #define WXS_ADD_PENDING(ctx, item) \
314 xmlSchemaAddItemSize(&((ctx)->constructor->pending), 10, item)
316 * xmlSchemaItemList macros.
318 #define WXS_ILIST_IS_EMPTY(l) ((l == NULL) || ((l)->nbItems == 0))
322 #define IS_SCHEMA(node, type) \
323 ((node != NULL) && (node->ns != NULL) && \
324 (xmlStrEqual(node->name, (const xmlChar *) type)) && \
325 (xmlStrEqual(node->ns->href, xmlSchemaNs)))
327 #define FREE_AND_NULL(str) if ((str) != NULL) { xmlFree((xmlChar *) (str)); str = NULL; }
330 * Since we put the default/fixed values into the dict, we can
331 * use pointer comparison for those values.
332 * REMOVED: (xmlStrEqual((v1), (v2)))
334 #define WXS_ARE_DEFAULT_STR_EQUAL(v1, v2) ((v1) == (v2))
336 #define INODE_NILLED(item) (item->flags & XML_SCHEMA_ELEM_INFO_NILLED)
338 #define CAN_PARSE_SCHEMA(b) (((b)->doc != NULL) && ((b)->parsed == 0))
340 #define HFAILURE if (res == -1) goto exit_failure;
342 #define HERROR if (res != 0) goto exit_error;
344 #define HSTOP(ctx) if ((ctx)->stop) goto exit;
346 * Some flags used for various schema constraints.
348 #define SUBSET_RESTRICTION 1<<0
349 #define SUBSET_EXTENSION 1<<1
350 #define SUBSET_SUBSTITUTION 1<<2
351 #define SUBSET_LIST 1<<3
352 #define SUBSET_UNION 1<<4
354 typedef struct _xmlSchemaNodeInfo xmlSchemaNodeInfo;
355 typedef xmlSchemaNodeInfo *xmlSchemaNodeInfoPtr;
357 typedef struct _xmlSchemaItemList xmlSchemaItemList;
358 typedef xmlSchemaItemList *xmlSchemaItemListPtr;
359 struct _xmlSchemaItemList {
360 void **items; /* used for dynamic addition of schemata */
361 int nbItems; /* used for dynamic addition of schemata */
362 int sizeItems; /* used for dynamic addition of schemata */
365 #define XML_SCHEMA_CTXT_PARSER 1
366 #define XML_SCHEMA_CTXT_VALIDATOR 2
368 typedef struct _xmlSchemaAbstractCtxt xmlSchemaAbstractCtxt;
369 typedef xmlSchemaAbstractCtxt *xmlSchemaAbstractCtxtPtr;
370 struct _xmlSchemaAbstractCtxt {
371 int type; /* E.g. XML_SCHEMA_CTXT_VALIDATOR */
372 void *dummy; /* Fix alignment issues */
375 typedef struct _xmlSchemaBucket xmlSchemaBucket;
376 typedef xmlSchemaBucket *xmlSchemaBucketPtr;
378 #define XML_SCHEMA_SCHEMA_MAIN 0
379 #define XML_SCHEMA_SCHEMA_IMPORT 1
380 #define XML_SCHEMA_SCHEMA_INCLUDE 2
381 #define XML_SCHEMA_SCHEMA_REDEFINE 3
384 * xmlSchemaSchemaRelation:
386 * Used to create a graph of schema relationships.
388 typedef struct _xmlSchemaSchemaRelation xmlSchemaSchemaRelation;
389 typedef xmlSchemaSchemaRelation *xmlSchemaSchemaRelationPtr;
390 struct _xmlSchemaSchemaRelation {
391 xmlSchemaSchemaRelationPtr next;
392 int type; /* E.g. XML_SCHEMA_SCHEMA_IMPORT */
393 const xmlChar *importNamespace;
394 xmlSchemaBucketPtr bucket;
397 #define XML_SCHEMA_BUCKET_MARKED 1<<0
398 #define XML_SCHEMA_BUCKET_COMPS_ADDED 1<<1
400 struct _xmlSchemaBucket {
403 const xmlChar *schemaLocation;
404 const xmlChar *origTargetNamespace;
405 const xmlChar *targetNamespace;
407 xmlSchemaSchemaRelationPtr relations;
412 xmlSchemaItemListPtr globals; /* Global components. */
413 xmlSchemaItemListPtr locals; /* Local components. */
418 * (extends xmlSchemaBucket)
420 * Reflects a schema. Holds some information
421 * about the schema and its toplevel components. Duplicate
422 * toplevel components are not checked at this level.
424 typedef struct _xmlSchemaImport xmlSchemaImport;
425 typedef xmlSchemaImport *xmlSchemaImportPtr;
426 struct _xmlSchemaImport {
427 int type; /* Main OR import OR include. */
429 const xmlChar *schemaLocation; /* The URI of the schema document. */
430 /* For chameleon includes, @origTargetNamespace will be NULL */
431 const xmlChar *origTargetNamespace;
433 * For chameleon includes, @targetNamespace will be the
434 * targetNamespace of the including schema.
436 const xmlChar *targetNamespace;
437 xmlDocPtr doc; /* The schema node-tree. */
438 /* @relations will hold any included/imported/redefined schemas. */
439 xmlSchemaSchemaRelationPtr relations;
444 xmlSchemaItemListPtr globals;
445 xmlSchemaItemListPtr locals;
446 /* The imported schema. */
451 * (extends xmlSchemaBucket)
453 typedef struct _xmlSchemaInclude xmlSchemaInclude;
454 typedef xmlSchemaInclude *xmlSchemaIncludePtr;
455 struct _xmlSchemaInclude {
458 const xmlChar *schemaLocation;
459 const xmlChar *origTargetNamespace;
460 const xmlChar *targetNamespace;
462 xmlSchemaSchemaRelationPtr relations;
467 xmlSchemaItemListPtr globals; /* Global components. */
468 xmlSchemaItemListPtr locals; /* Local components. */
470 /* The owning main or import schema bucket. */
471 xmlSchemaImportPtr ownerImport;
475 * xmlSchemaBasicItem:
477 * The abstract base type for schema components.
479 typedef struct _xmlSchemaBasicItem xmlSchemaBasicItem;
480 typedef xmlSchemaBasicItem *xmlSchemaBasicItemPtr;
481 struct _xmlSchemaBasicItem {
482 xmlSchemaTypeType type;
483 void *dummy; /* Fix alignment issues */
487 * xmlSchemaAnnotItem:
489 * The abstract base type for annotated schema components.
490 * (Extends xmlSchemaBasicItem)
492 typedef struct _xmlSchemaAnnotItem xmlSchemaAnnotItem;
493 typedef xmlSchemaAnnotItem *xmlSchemaAnnotItemPtr;
494 struct _xmlSchemaAnnotItem {
495 xmlSchemaTypeType type;
496 xmlSchemaAnnotPtr annot;
502 * The abstract base type for tree-like structured schema components.
503 * (Extends xmlSchemaAnnotItem)
505 typedef struct _xmlSchemaTreeItem xmlSchemaTreeItem;
506 typedef xmlSchemaTreeItem *xmlSchemaTreeItemPtr;
507 struct _xmlSchemaTreeItem {
508 xmlSchemaTypeType type;
509 xmlSchemaAnnotPtr annot;
510 xmlSchemaTreeItemPtr next;
511 xmlSchemaTreeItemPtr children;
515 #define XML_SCHEMA_ATTR_USE_FIXED 1<<0
517 * xmlSchemaAttributeUsePtr:
519 * The abstract base type for tree-like structured schema components.
520 * (Extends xmlSchemaTreeItem)
522 typedef struct _xmlSchemaAttributeUse xmlSchemaAttributeUse;
523 typedef xmlSchemaAttributeUse *xmlSchemaAttributeUsePtr;
524 struct _xmlSchemaAttributeUse {
525 xmlSchemaTypeType type;
526 xmlSchemaAnnotPtr annot;
527 xmlSchemaAttributeUsePtr next; /* The next attr. use. */
529 * The attr. decl. OR a QName-ref. to an attr. decl. OR
530 * a QName-ref. to an attribute group definition.
532 xmlSchemaAttributePtr attrDecl;
536 int occurs; /* required, optional */
537 const xmlChar * defValue;
538 xmlSchemaValPtr defVal;
542 * xmlSchemaAttributeUseProhibPtr:
544 * A helper component to reflect attribute prohibitions.
545 * (Extends xmlSchemaBasicItem)
547 typedef struct _xmlSchemaAttributeUseProhib xmlSchemaAttributeUseProhib;
548 typedef xmlSchemaAttributeUseProhib *xmlSchemaAttributeUseProhibPtr;
549 struct _xmlSchemaAttributeUseProhib {
550 xmlSchemaTypeType type; /* == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB */
553 const xmlChar *targetNamespace;
560 typedef struct _xmlSchemaRedef xmlSchemaRedef;
561 typedef xmlSchemaRedef *xmlSchemaRedefPtr;
562 struct _xmlSchemaRedef {
563 xmlSchemaRedefPtr next;
564 xmlSchemaBasicItemPtr item; /* The redefining component. */
565 xmlSchemaBasicItemPtr reference; /* The referencing component. */
566 xmlSchemaBasicItemPtr target; /* The to-be-redefined component. */
567 const xmlChar *refName; /* The name of the to-be-redefined component. */
568 const xmlChar *refTargetNs; /* The target namespace of the
569 to-be-redefined comp. */
570 xmlSchemaBucketPtr targetBucket; /* The redefined schema. */
574 * xmlSchemaConstructionCtxt:
576 typedef struct _xmlSchemaConstructionCtxt xmlSchemaConstructionCtxt;
577 typedef xmlSchemaConstructionCtxt *xmlSchemaConstructionCtxtPtr;
578 struct _xmlSchemaConstructionCtxt {
579 xmlSchemaPtr mainSchema; /* The main schema. */
580 xmlSchemaBucketPtr mainBucket; /* The main schema bucket */
582 xmlSchemaItemListPtr buckets; /* List of schema buckets. */
583 /* xmlSchemaItemListPtr relations; */ /* List of schema relations. */
584 xmlSchemaBucketPtr bucket; /* The current schema bucket */
585 xmlSchemaItemListPtr pending; /* All Components of all schemas that
587 xmlHashTablePtr substGroups;
588 xmlSchemaRedefPtr redefs;
589 xmlSchemaRedefPtr lastRedef;
592 #define XML_SCHEMAS_PARSE_ERROR 1
593 #define SCHEMAS_PARSE_OPTIONS XML_PARSE_NOENT
595 struct _xmlSchemaParserCtxt {
597 void *errCtxt; /* user specific error context */
598 xmlSchemaValidityErrorFunc error; /* the callback in case of errors */
599 xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */
602 xmlStructuredErrorFunc serror;
604 xmlSchemaConstructionCtxtPtr constructor;
605 int ownsConstructor; /* TODO: Move this to parser *flags*. */
607 /* xmlSchemaPtr topschema; */
608 /* xmlHashTablePtr namespaces; */
610 xmlSchemaPtr schema; /* The main schema in use */
615 int preserve; /* Whether the doc should be freed */
621 * Used to build complex element content models
624 xmlAutomataStatePtr start;
625 xmlAutomataStatePtr end;
626 xmlAutomataStatePtr state;
628 xmlDictPtr dict; /* dictionary for interned string names */
629 xmlSchemaTypePtr ctxtType; /* The current context simple/complex type */
631 xmlSchemaValidCtxtPtr vctxt;
635 int stop; /* If the parser should stop; i.e. a critical error. */
636 const xmlChar *targetNamespace;
637 xmlSchemaBucketPtr redefined; /* The schema to be redefined. */
639 xmlSchemaRedefPtr redef; /* Used for redefinitions. */
640 int redefCounter; /* Used for redefinitions. */
641 xmlSchemaItemListPtr attrProhibs;
647 * A component reference item (not a schema component)
648 * (Extends xmlSchemaBasicItem)
650 typedef struct _xmlSchemaQNameRef xmlSchemaQNameRef;
651 typedef xmlSchemaQNameRef *xmlSchemaQNameRefPtr;
652 struct _xmlSchemaQNameRef {
653 xmlSchemaTypeType type;
654 xmlSchemaBasicItemPtr item; /* The resolved referenced item. */
655 xmlSchemaTypeType itemType;
657 const xmlChar *targetNamespace;
664 * A particle component.
665 * (Extends xmlSchemaTreeItem)
667 typedef struct _xmlSchemaParticle xmlSchemaParticle;
668 typedef xmlSchemaParticle *xmlSchemaParticlePtr;
669 struct _xmlSchemaParticle {
670 xmlSchemaTypeType type;
671 xmlSchemaAnnotPtr annot;
672 xmlSchemaTreeItemPtr next; /* next particle */
673 xmlSchemaTreeItemPtr children; /* the "term" (e.g. a model group,
674 a group definition, a XML_SCHEMA_EXTRA_QNAMEREF (if a reference),
682 * xmlSchemaModelGroup:
684 * A model group component.
685 * (Extends xmlSchemaTreeItem)
687 typedef struct _xmlSchemaModelGroup xmlSchemaModelGroup;
688 typedef xmlSchemaModelGroup *xmlSchemaModelGroupPtr;
689 struct _xmlSchemaModelGroup {
690 xmlSchemaTypeType type; /* XML_SCHEMA_TYPE_SEQUENCE, XML_SCHEMA_TYPE_CHOICE, XML_SCHEMA_TYPE_ALL */
691 xmlSchemaAnnotPtr annot;
692 xmlSchemaTreeItemPtr next; /* not used */
693 xmlSchemaTreeItemPtr children; /* first particle (OR "element decl" OR "wildcard") */
697 #define XML_SCHEMA_MODEL_GROUP_DEF_MARKED 1<<0
698 #define XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED 1<<1
700 * xmlSchemaModelGroupDef:
702 * A model group definition component.
703 * (Extends xmlSchemaTreeItem)
705 typedef struct _xmlSchemaModelGroupDef xmlSchemaModelGroupDef;
706 typedef xmlSchemaModelGroupDef *xmlSchemaModelGroupDefPtr;
707 struct _xmlSchemaModelGroupDef {
708 xmlSchemaTypeType type; /* XML_SCHEMA_TYPE_GROUP */
709 xmlSchemaAnnotPtr annot;
710 xmlSchemaTreeItemPtr next; /* not used */
711 xmlSchemaTreeItemPtr children; /* the "model group" */
713 const xmlChar *targetNamespace;
718 typedef struct _xmlSchemaIDC xmlSchemaIDC;
719 typedef xmlSchemaIDC *xmlSchemaIDCPtr;
722 * xmlSchemaIDCSelect:
724 * The identity-constraint "field" and "selector" item, holding the
727 typedef struct _xmlSchemaIDCSelect xmlSchemaIDCSelect;
728 typedef xmlSchemaIDCSelect *xmlSchemaIDCSelectPtr;
729 struct _xmlSchemaIDCSelect {
730 xmlSchemaIDCSelectPtr next;
732 int index; /* an index position if significant for IDC key-sequences */
733 const xmlChar *xpath; /* the XPath expression */
734 void *xpathComp; /* the compiled XPath expression */
740 * The identity-constraint definition component.
741 * (Extends xmlSchemaAnnotItem)
744 struct _xmlSchemaIDC {
745 xmlSchemaTypeType type;
746 xmlSchemaAnnotPtr annot;
747 xmlSchemaIDCPtr next;
750 const xmlChar *targetNamespace;
751 xmlSchemaIDCSelectPtr selector;
752 xmlSchemaIDCSelectPtr fields;
754 xmlSchemaQNameRefPtr ref;
760 * The augmented IDC information used for validation.
762 typedef struct _xmlSchemaIDCAug xmlSchemaIDCAug;
763 typedef xmlSchemaIDCAug *xmlSchemaIDCAugPtr;
764 struct _xmlSchemaIDCAug {
765 xmlSchemaIDCAugPtr next; /* next in a list */
766 xmlSchemaIDCPtr def; /* the IDC definition */
767 int keyrefDepth; /* the lowest tree level to which IDC
768 tables need to be bubbled upwards */
772 * xmlSchemaPSVIIDCKeySequence:
774 * The key sequence of a node table item.
776 typedef struct _xmlSchemaPSVIIDCKey xmlSchemaPSVIIDCKey;
777 typedef xmlSchemaPSVIIDCKey *xmlSchemaPSVIIDCKeyPtr;
778 struct _xmlSchemaPSVIIDCKey {
779 xmlSchemaTypePtr type;
784 * xmlSchemaPSVIIDCNode:
786 * The node table item of a node table.
788 typedef struct _xmlSchemaPSVIIDCNode xmlSchemaPSVIIDCNode;
789 typedef xmlSchemaPSVIIDCNode *xmlSchemaPSVIIDCNodePtr;
790 struct _xmlSchemaPSVIIDCNode {
792 xmlSchemaPSVIIDCKeyPtr *keys;
799 * xmlSchemaPSVIIDCBinding:
801 * The identity-constraint binding item of the [identity-constraint table].
803 typedef struct _xmlSchemaPSVIIDCBinding xmlSchemaPSVIIDCBinding;
804 typedef xmlSchemaPSVIIDCBinding *xmlSchemaPSVIIDCBindingPtr;
805 struct _xmlSchemaPSVIIDCBinding {
806 xmlSchemaPSVIIDCBindingPtr next; /* next binding of a specific node */
807 xmlSchemaIDCPtr definition; /* the IDC definition */
808 xmlSchemaPSVIIDCNodePtr *nodeTable; /* array of key-sequences */
809 int nbNodes; /* number of entries in the node table */
810 int sizeNodes; /* size of the node table */
811 xmlSchemaItemListPtr dupls;
815 #define XPATH_STATE_OBJ_TYPE_IDC_SELECTOR 1
816 #define XPATH_STATE_OBJ_TYPE_IDC_FIELD 2
818 #define XPATH_STATE_OBJ_MATCHES -2
819 #define XPATH_STATE_OBJ_BLOCKED -3
821 typedef struct _xmlSchemaIDCMatcher xmlSchemaIDCMatcher;
822 typedef xmlSchemaIDCMatcher *xmlSchemaIDCMatcherPtr;
825 * xmlSchemaIDCStateObj:
827 * The state object used to evaluate XPath expressions.
829 typedef struct _xmlSchemaIDCStateObj xmlSchemaIDCStateObj;
830 typedef xmlSchemaIDCStateObj *xmlSchemaIDCStateObjPtr;
831 struct _xmlSchemaIDCStateObj {
833 xmlSchemaIDCStateObjPtr next; /* next if in a list */
834 int depth; /* depth of creation */
835 int *history; /* list of (depth, state-id) tuples */
838 xmlSchemaIDCMatcherPtr matcher; /* the correspondent field/selector
840 xmlSchemaIDCSelectPtr sel;
844 #define IDC_MATCHER 0
847 * xmlSchemaIDCMatcher:
849 * Used to evaluate IDC selectors (and fields).
851 struct _xmlSchemaIDCMatcher {
853 int depth; /* the tree depth at creation time */
854 xmlSchemaIDCMatcherPtr next; /* next in the list */
855 xmlSchemaIDCMatcherPtr nextCached; /* next in the cache list */
856 xmlSchemaIDCAugPtr aidc; /* the augmented IDC item */
858 xmlSchemaPSVIIDCKeyPtr **keySeqs; /* the key-sequences of the target
861 xmlSchemaItemListPtr targets; /* list of target-node
862 (xmlSchemaPSVIIDCNodePtr) entries */
866 * Element info flags.
868 #define XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES 1<<0
869 #define XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES 1<<1
870 #define XML_SCHEMA_ELEM_INFO_NILLED 1<<2
871 #define XML_SCHEMA_ELEM_INFO_LOCAL_TYPE 1<<3
873 #define XML_SCHEMA_NODE_INFO_VALUE_NEEDED 1<<4
874 #define XML_SCHEMA_ELEM_INFO_EMPTY 1<<5
875 #define XML_SCHEMA_ELEM_INFO_HAS_CONTENT 1<<6
877 #define XML_SCHEMA_ELEM_INFO_HAS_ELEM_CONTENT 1<<7
878 #define XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT 1<<8
879 #define XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED 1<<9
880 #define XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE 1<<10
885 * Holds information of an element node.
887 struct _xmlSchemaNodeInfo {
891 const xmlChar *localName;
892 const xmlChar *nsName;
893 const xmlChar *value;
894 xmlSchemaValPtr val; /* the pre-computed value if any */
895 xmlSchemaTypePtr typeDef; /* the complex/simple type definition if any */
897 int flags; /* combination of node info flags */
902 xmlSchemaElementPtr decl; /* the element/attribute declaration */
904 xmlSchemaPSVIIDCBindingPtr idcTable; /* the table of PSVI IDC bindings
905 for the scope element*/
906 xmlSchemaIDCMatcherPtr idcMatchers; /* the IDC matchers for the scope
908 xmlRegExecCtxtPtr regexCtxt;
910 const xmlChar **nsBindings; /* Namespace bindings on this element */
915 int appliedXPath; /* Indicates that an XPath has been applied. */
918 #define XML_SCHEMAS_ATTR_UNKNOWN 1
919 #define XML_SCHEMAS_ATTR_ASSESSED 2
920 #define XML_SCHEMAS_ATTR_PROHIBITED 3
921 #define XML_SCHEMAS_ATTR_ERR_MISSING 4
922 #define XML_SCHEMAS_ATTR_INVALID_VALUE 5
923 #define XML_SCHEMAS_ATTR_ERR_NO_TYPE 6
924 #define XML_SCHEMAS_ATTR_ERR_FIXED_VALUE 7
925 #define XML_SCHEMAS_ATTR_DEFAULT 8
926 #define XML_SCHEMAS_ATTR_VALIDATE_VALUE 9
927 #define XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL 10
928 #define XML_SCHEMAS_ATTR_HAS_ATTR_USE 11
929 #define XML_SCHEMAS_ATTR_HAS_ATTR_DECL 12
930 #define XML_SCHEMAS_ATTR_WILD_SKIP 13
931 #define XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL 14
932 #define XML_SCHEMAS_ATTR_ERR_WILD_DUPLICATE_ID 15
933 #define XML_SCHEMAS_ATTR_ERR_WILD_AND_USE_ID 16
934 #define XML_SCHEMAS_ATTR_META 17
936 * @metaType values of xmlSchemaAttrInfo.
938 #define XML_SCHEMA_ATTR_INFO_META_XSI_TYPE 1
939 #define XML_SCHEMA_ATTR_INFO_META_XSI_NIL 2
940 #define XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC 3
941 #define XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC 4
942 #define XML_SCHEMA_ATTR_INFO_META_XMLNS 5
944 typedef struct _xmlSchemaAttrInfo xmlSchemaAttrInfo;
945 typedef xmlSchemaAttrInfo *xmlSchemaAttrInfoPtr;
946 struct _xmlSchemaAttrInfo {
950 const xmlChar *localName;
951 const xmlChar *nsName;
952 const xmlChar *value;
953 xmlSchemaValPtr val; /* the pre-computed value if any */
954 xmlSchemaTypePtr typeDef; /* the complex/simple type definition if any */
955 int flags; /* combination of node info flags */
957 xmlSchemaAttributePtr decl; /* the attribute declaration */
958 xmlSchemaAttributeUsePtr use; /* the attribute use */
961 const xmlChar *vcValue; /* the value constraint value */
962 xmlSchemaNodeInfoPtr parent;
966 #define XML_SCHEMA_VALID_CTXT_FLAG_STREAM 1
968 * xmlSchemaValidCtxt:
970 * A Schemas validation context
972 struct _xmlSchemaValidCtxt {
974 void *errCtxt; /* user specific data block */
975 xmlSchemaValidityErrorFunc error; /* the callback in case of errors */
976 xmlSchemaValidityWarningFunc warning; /* the callback in case of warning */
977 xmlStructuredErrorFunc serror;
979 xmlSchemaPtr schema; /* The schema in use */
981 xmlParserInputBufferPtr input;
983 xmlSAXHandlerPtr sax;
984 xmlParserCtxtPtr parserCtxt;
985 void *user_data; /* TODO: What is this for? */
993 /* xmlSchemaTypePtr type; */
995 xmlRegExecCtxtPtr regexp;
996 xmlSchemaValPtr value;
1000 xmlNodePtr validationRoot;
1001 xmlSchemaParserCtxtPtr pctxt;
1005 xmlSchemaNodeInfoPtr *elemInfos; /* array of element informations */
1007 xmlSchemaNodeInfoPtr inode; /* the current element information */
1009 xmlSchemaIDCAugPtr aidcs; /* a list of augmented IDC informations */
1011 xmlSchemaIDCStateObjPtr xpathStates; /* first active state object. */
1012 xmlSchemaIDCStateObjPtr xpathStatePool; /* first stored state object. */
1013 xmlSchemaIDCMatcherPtr idcMatcherCache; /* Cache for IDC matcher objects. */
1015 xmlSchemaPSVIIDCNodePtr *idcNodes; /* list of all IDC node-table entries*/
1019 xmlSchemaPSVIIDCKeyPtr *idcKeys; /* list of all IDC node-table entries */
1027 #ifdef LIBXML_READER_ENABLED
1028 xmlTextReaderPtr reader;
1031 xmlSchemaAttrInfoPtr *attrInfos;
1036 xmlSchemaItemListPtr nodeQNames;
1038 int createIDCNodeTables;
1039 int psviExposeIDCNodeTables;
1041 /* Locator for error reporting in streaming mode */
1042 xmlSchemaValidityLocatorFunc locFunc;
1047 * xmlSchemaSubstGroup:
1051 typedef struct _xmlSchemaSubstGroup xmlSchemaSubstGroup;
1052 typedef xmlSchemaSubstGroup *xmlSchemaSubstGroupPtr;
1053 struct _xmlSchemaSubstGroup {
1054 xmlSchemaElementPtr head;
1055 xmlSchemaItemListPtr members;
1058 /************************************************************************
1060 * Some predeclarations *
1062 ************************************************************************/
1064 static int xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt,
1065 xmlSchemaPtr schema,
1067 static int xmlSchemaParseRedefine(xmlSchemaParserCtxtPtr ctxt,
1068 xmlSchemaPtr schema,
1071 xmlSchemaTypeFixup(xmlSchemaTypePtr type,
1072 xmlSchemaAbstractCtxtPtr ctxt);
1073 static const xmlChar *
1074 xmlSchemaFacetTypeToString(xmlSchemaTypeType type);
1076 xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
1079 xmlSchemaCheckFacetValues(xmlSchemaTypePtr typeDecl,
1080 xmlSchemaParserCtxtPtr ctxt);
1082 xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt);
1083 static xmlSchemaWhitespaceValueType
1084 xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type);
1085 static xmlSchemaTreeItemPtr
1086 xmlSchemaParseModelGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
1087 xmlNodePtr node, xmlSchemaTypeType type,
1089 static const xmlChar *
1090 xmlSchemaGetComponentTypeStr(xmlSchemaBasicItemPtr item);
1091 static xmlSchemaTypeLinkPtr
1092 xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type);
1094 xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
1095 const char *funcName,
1096 const char *message) LIBXML_ATTR_FORMAT(3,0);
1098 xmlSchemaCheckCOSSTDerivedOK(xmlSchemaAbstractCtxtPtr ctxt,
1099 xmlSchemaTypePtr type,
1100 xmlSchemaTypePtr baseType,
1103 xmlSchemaCheckElementDeclComponent(xmlSchemaElementPtr elemDecl,
1104 xmlSchemaParserCtxtPtr ctxt);
1106 xmlSchemaComponentListFree(xmlSchemaItemListPtr list);
1107 static xmlSchemaQNameRefPtr
1108 xmlSchemaParseAttributeGroupRef(xmlSchemaParserCtxtPtr pctxt,
1109 xmlSchemaPtr schema,
1112 /************************************************************************
1114 * Helper functions *
1116 ************************************************************************/
1119 * xmlSchemaItemTypeToStr:
1120 * @type: the type of the schema item
1122 * Returns the component name of a schema item.
1124 static const xmlChar *
1125 xmlSchemaItemTypeToStr(xmlSchemaTypeType type)
1128 case XML_SCHEMA_TYPE_BASIC:
1129 return(BAD_CAST "simple type definition");
1130 case XML_SCHEMA_TYPE_SIMPLE:
1131 return(BAD_CAST "simple type definition");
1132 case XML_SCHEMA_TYPE_COMPLEX:
1133 return(BAD_CAST "complex type definition");
1134 case XML_SCHEMA_TYPE_ELEMENT:
1135 return(BAD_CAST "element declaration");
1136 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1137 return(BAD_CAST "attribute use");
1138 case XML_SCHEMA_TYPE_ATTRIBUTE:
1139 return(BAD_CAST "attribute declaration");
1140 case XML_SCHEMA_TYPE_GROUP:
1141 return(BAD_CAST "model group definition");
1142 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1143 return(BAD_CAST "attribute group definition");
1144 case XML_SCHEMA_TYPE_NOTATION:
1145 return(BAD_CAST "notation declaration");
1146 case XML_SCHEMA_TYPE_SEQUENCE:
1147 return(BAD_CAST "model group (sequence)");
1148 case XML_SCHEMA_TYPE_CHOICE:
1149 return(BAD_CAST "model group (choice)");
1150 case XML_SCHEMA_TYPE_ALL:
1151 return(BAD_CAST "model group (all)");
1152 case XML_SCHEMA_TYPE_PARTICLE:
1153 return(BAD_CAST "particle");
1154 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1155 return(BAD_CAST "unique identity-constraint");
1156 /* return(BAD_CAST "IDC (unique)"); */
1157 case XML_SCHEMA_TYPE_IDC_KEY:
1158 return(BAD_CAST "key identity-constraint");
1159 /* return(BAD_CAST "IDC (key)"); */
1160 case XML_SCHEMA_TYPE_IDC_KEYREF:
1161 return(BAD_CAST "keyref identity-constraint");
1162 /* return(BAD_CAST "IDC (keyref)"); */
1163 case XML_SCHEMA_TYPE_ANY:
1164 return(BAD_CAST "wildcard (any)");
1165 case XML_SCHEMA_EXTRA_QNAMEREF:
1166 return(BAD_CAST "[helper component] QName reference");
1167 case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB:
1168 return(BAD_CAST "[helper component] attribute use prohibition");
1170 return(BAD_CAST "Not a schema component");
1175 * xmlSchemaGetComponentTypeStr:
1176 * @type: the type of the schema item
1178 * Returns the component name of a schema item.
1180 static const xmlChar *
1181 xmlSchemaGetComponentTypeStr(xmlSchemaBasicItemPtr item)
1183 switch (item->type) {
1184 case XML_SCHEMA_TYPE_BASIC:
1185 if (WXS_IS_COMPLEX(WXS_TYPE_CAST item))
1186 return(BAD_CAST "complex type definition");
1188 return(BAD_CAST "simple type definition");
1190 return(xmlSchemaItemTypeToStr(item->type));
1195 * xmlSchemaGetComponentNode:
1196 * @item: a schema component
1198 * Returns node associated with the schema component.
1199 * NOTE that such a node need not be available; plus, a component's
1200 * node need not to reflect the component directly, since there is no
1201 * one-to-one relationship between the XML Schema representation and
1202 * the component representation.
1205 xmlSchemaGetComponentNode(xmlSchemaBasicItemPtr item)
1207 switch (item->type) {
1208 case XML_SCHEMA_TYPE_ELEMENT:
1209 return (((xmlSchemaElementPtr) item)->node);
1210 case XML_SCHEMA_TYPE_ATTRIBUTE:
1211 return (((xmlSchemaAttributePtr) item)->node);
1212 case XML_SCHEMA_TYPE_COMPLEX:
1213 case XML_SCHEMA_TYPE_SIMPLE:
1214 return (((xmlSchemaTypePtr) item)->node);
1215 case XML_SCHEMA_TYPE_ANY:
1216 case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
1217 return (((xmlSchemaWildcardPtr) item)->node);
1218 case XML_SCHEMA_TYPE_PARTICLE:
1219 return (((xmlSchemaParticlePtr) item)->node);
1220 case XML_SCHEMA_TYPE_SEQUENCE:
1221 case XML_SCHEMA_TYPE_CHOICE:
1222 case XML_SCHEMA_TYPE_ALL:
1223 return (((xmlSchemaModelGroupPtr) item)->node);
1224 case XML_SCHEMA_TYPE_GROUP:
1225 return (((xmlSchemaModelGroupDefPtr) item)->node);
1226 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1227 return (((xmlSchemaAttributeGroupPtr) item)->node);
1228 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1229 case XML_SCHEMA_TYPE_IDC_KEY:
1230 case XML_SCHEMA_TYPE_IDC_KEYREF:
1231 return (((xmlSchemaIDCPtr) item)->node);
1232 case XML_SCHEMA_EXTRA_QNAMEREF:
1233 return(((xmlSchemaQNameRefPtr) item)->node);
1234 /* TODO: What to do with NOTATIONs?
1235 case XML_SCHEMA_TYPE_NOTATION:
1236 return (((xmlSchemaNotationPtr) item)->node);
1238 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1239 return (((xmlSchemaAttributeUsePtr) item)->node);
1247 * xmlSchemaGetNextComponent:
1248 * @item: a schema component
1250 * Returns the next sibling of the schema component.
1252 static xmlSchemaBasicItemPtr
1253 xmlSchemaGetNextComponent(xmlSchemaBasicItemPtr item)
1255 switch (item->type) {
1256 case XML_SCHEMA_TYPE_ELEMENT:
1257 return ((xmlSchemaBasicItemPtr) ((xmlSchemaElementPtr) item)->next);
1258 case XML_SCHEMA_TYPE_ATTRIBUTE:
1259 return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributePtr) item)->next);
1260 case XML_SCHEMA_TYPE_COMPLEX:
1261 case XML_SCHEMA_TYPE_SIMPLE:
1262 return ((xmlSchemaBasicItemPtr) ((xmlSchemaTypePtr) item)->next);
1263 case XML_SCHEMA_TYPE_ANY:
1264 case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
1266 case XML_SCHEMA_TYPE_PARTICLE:
1267 return ((xmlSchemaBasicItemPtr) ((xmlSchemaParticlePtr) item)->next);
1268 case XML_SCHEMA_TYPE_SEQUENCE:
1269 case XML_SCHEMA_TYPE_CHOICE:
1270 case XML_SCHEMA_TYPE_ALL:
1272 case XML_SCHEMA_TYPE_GROUP:
1274 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1275 return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributeGroupPtr) item)->next);
1276 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1277 case XML_SCHEMA_TYPE_IDC_KEY:
1278 case XML_SCHEMA_TYPE_IDC_KEYREF:
1279 return ((xmlSchemaBasicItemPtr) ((xmlSchemaIDCPtr) item)->next);
1288 * xmlSchemaFormatQName:
1289 * @buf: the string buffer
1290 * @namespaceName: the namespace name
1291 * @localName: the local name
1293 * Returns the given QName in the format "{namespaceName}localName" or
1294 * just "localName" if @namespaceName is NULL.
1296 * Returns the localName if @namespaceName is NULL, a formatted
1299 static const xmlChar*
1300 xmlSchemaFormatQName(xmlChar **buf,
1301 const xmlChar *namespaceName,
1302 const xmlChar *localName)
1305 if (namespaceName != NULL) {
1306 *buf = xmlStrdup(BAD_CAST "{");
1307 *buf = xmlStrcat(*buf, namespaceName);
1308 *buf = xmlStrcat(*buf, BAD_CAST "}");
1310 if (localName != NULL) {
1311 if (namespaceName == NULL)
1313 *buf = xmlStrcat(*buf, localName);
1315 *buf = xmlStrcat(*buf, BAD_CAST "(NULL)");
1317 return ((const xmlChar *) *buf);
1320 static const xmlChar*
1321 xmlSchemaFormatQNameNs(xmlChar **buf, xmlNsPtr ns, const xmlChar *localName)
1324 return (xmlSchemaFormatQName(buf, ns->href, localName));
1326 return (xmlSchemaFormatQName(buf, NULL, localName));
1329 static const xmlChar *
1330 xmlSchemaGetComponentName(xmlSchemaBasicItemPtr item)
1332 switch (item->type) {
1333 case XML_SCHEMA_TYPE_ELEMENT:
1334 return (((xmlSchemaElementPtr) item)->name);
1335 case XML_SCHEMA_TYPE_ATTRIBUTE:
1336 return (((xmlSchemaAttributePtr) item)->name);
1337 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1338 return (((xmlSchemaAttributeGroupPtr) item)->name);
1339 case XML_SCHEMA_TYPE_BASIC:
1340 case XML_SCHEMA_TYPE_SIMPLE:
1341 case XML_SCHEMA_TYPE_COMPLEX:
1342 return (((xmlSchemaTypePtr) item)->name);
1343 case XML_SCHEMA_TYPE_GROUP:
1344 return (((xmlSchemaModelGroupDefPtr) item)->name);
1345 case XML_SCHEMA_TYPE_IDC_KEY:
1346 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1347 case XML_SCHEMA_TYPE_IDC_KEYREF:
1348 return (((xmlSchemaIDCPtr) item)->name);
1349 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1350 if (WXS_ATTRUSE_DECL(item) != NULL) {
1351 return(xmlSchemaGetComponentName(
1352 WXS_BASIC_CAST WXS_ATTRUSE_DECL(item)));
1355 case XML_SCHEMA_EXTRA_QNAMEREF:
1356 return (((xmlSchemaQNameRefPtr) item)->name);
1357 case XML_SCHEMA_TYPE_NOTATION:
1358 return (((xmlSchemaNotationPtr) item)->name);
1361 * Other components cannot have names.
1368 #define xmlSchemaGetQNameRefName(r) (WXS_QNAME_CAST (r))->name
1369 #define xmlSchemaGetQNameRefTargetNs(r) (WXS_QNAME_CAST (r))->targetNamespace
1371 static const xmlChar *
1372 xmlSchemaGetQNameRefName(void *ref)
1374 return(((xmlSchemaQNameRefPtr) ref)->name);
1377 static const xmlChar *
1378 xmlSchemaGetQNameRefTargetNs(void *ref)
1380 return(((xmlSchemaQNameRefPtr) ref)->targetNamespace);
1384 static const xmlChar *
1385 xmlSchemaGetComponentTargetNs(xmlSchemaBasicItemPtr item)
1387 switch (item->type) {
1388 case XML_SCHEMA_TYPE_ELEMENT:
1389 return (((xmlSchemaElementPtr) item)->targetNamespace);
1390 case XML_SCHEMA_TYPE_ATTRIBUTE:
1391 return (((xmlSchemaAttributePtr) item)->targetNamespace);
1392 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1393 return (((xmlSchemaAttributeGroupPtr) item)->targetNamespace);
1394 case XML_SCHEMA_TYPE_BASIC:
1395 return (BAD_CAST "http://www.w3.org/2001/XMLSchema");
1396 case XML_SCHEMA_TYPE_SIMPLE:
1397 case XML_SCHEMA_TYPE_COMPLEX:
1398 return (((xmlSchemaTypePtr) item)->targetNamespace);
1399 case XML_SCHEMA_TYPE_GROUP:
1400 return (((xmlSchemaModelGroupDefPtr) item)->targetNamespace);
1401 case XML_SCHEMA_TYPE_IDC_KEY:
1402 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1403 case XML_SCHEMA_TYPE_IDC_KEYREF:
1404 return (((xmlSchemaIDCPtr) item)->targetNamespace);
1405 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
1406 if (WXS_ATTRUSE_DECL(item) != NULL) {
1407 return(xmlSchemaGetComponentTargetNs(
1408 WXS_BASIC_CAST WXS_ATTRUSE_DECL(item)));
1410 /* TODO: Will returning NULL break something? */
1412 case XML_SCHEMA_EXTRA_QNAMEREF:
1413 return (((xmlSchemaQNameRefPtr) item)->targetNamespace);
1414 case XML_SCHEMA_TYPE_NOTATION:
1415 return (((xmlSchemaNotationPtr) item)->targetNamespace);
1418 * Other components cannot have names.
1425 static const xmlChar*
1426 xmlSchemaGetComponentQName(xmlChar **buf,
1429 return (xmlSchemaFormatQName(buf,
1430 xmlSchemaGetComponentTargetNs((xmlSchemaBasicItemPtr) item),
1431 xmlSchemaGetComponentName((xmlSchemaBasicItemPtr) item)));
1434 static const xmlChar*
1435 xmlSchemaGetComponentDesignation(xmlChar **buf, void *item)
1437 xmlChar *str = NULL;
1439 *buf = xmlStrcat(*buf, WXS_ITEM_TYPE_NAME(item));
1440 *buf = xmlStrcat(*buf, BAD_CAST " '");
1441 *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str,
1442 (xmlSchemaBasicItemPtr) item));
1443 *buf = xmlStrcat(*buf, BAD_CAST "'");
1448 static const xmlChar*
1449 xmlSchemaGetIDCDesignation(xmlChar **buf, xmlSchemaIDCPtr idc)
1451 return(xmlSchemaGetComponentDesignation(buf, idc));
1455 * xmlSchemaWildcardPCToString:
1456 * @pc: the type of processContents
1458 * Returns a string representation of the type of
1461 static const xmlChar *
1462 xmlSchemaWildcardPCToString(int pc)
1465 case XML_SCHEMAS_ANY_SKIP:
1466 return (BAD_CAST "skip");
1467 case XML_SCHEMAS_ANY_LAX:
1468 return (BAD_CAST "lax");
1469 case XML_SCHEMAS_ANY_STRICT:
1470 return (BAD_CAST "strict");
1472 return (BAD_CAST "invalid process contents");
1477 * xmlSchemaGetCanonValueWhtspExt:
1478 * @val: the precomputed value
1479 * @retValue: the returned value
1480 * @ws: the whitespace type of the value
1482 * Get a the canonical representation of the value.
1483 * The caller has to free the returned retValue.
1485 * Returns 0 if the value could be built and -1 in case of
1486 * API errors or if the value type is not supported yet.
1489 xmlSchemaGetCanonValueWhtspExt(xmlSchemaValPtr val,
1490 xmlSchemaWhitespaceValueType ws,
1494 xmlSchemaValType valType;
1495 const xmlChar *value, *value2 = NULL;
1498 if ((retValue == NULL) || (val == NULL))
1500 list = xmlSchemaValueGetNext(val) ? 1 : 0;
1504 valType = xmlSchemaGetValType(val);
1506 case XML_SCHEMAS_STRING:
1507 case XML_SCHEMAS_NORMSTRING:
1508 case XML_SCHEMAS_ANYSIMPLETYPE:
1509 value = xmlSchemaValueGetAsString(val);
1510 if (value != NULL) {
1511 if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE)
1512 value2 = xmlSchemaCollapseString(value);
1513 else if (ws == XML_SCHEMA_WHITESPACE_REPLACE)
1514 value2 = xmlSchemaWhiteSpaceReplace(value);
1520 if (xmlSchemaGetCanonValue(val, &value2) == -1) {
1522 xmlFree((xmlChar *) value2);
1523 goto internal_error;
1527 if (*retValue == NULL)
1528 if (value == NULL) {
1530 *retValue = xmlStrdup(BAD_CAST "");
1532 *retValue = xmlStrdup(value);
1533 else if (value != NULL) {
1535 *retValue = xmlStrcat((xmlChar *) *retValue, BAD_CAST " ");
1536 *retValue = xmlStrcat((xmlChar *) *retValue, value);
1538 FREE_AND_NULL(value2)
1539 val = xmlSchemaValueGetNext(val);
1540 } while (val != NULL);
1544 if (*retValue != NULL)
1545 xmlFree((xmlChar *) (*retValue));
1547 xmlFree((xmlChar *) value2);
1552 * xmlSchemaFormatItemForReport:
1553 * @buf: the string buffer
1554 * @itemDes: the designation of the item
1555 * @itemName: the name of the item
1556 * @item: the item as an object
1557 * @itemNode: the node of the item
1558 * @local: the local name
1559 * @parsing: if the function is used during the parse
1561 * Returns a representation of the given item used
1562 * for error reports.
1564 * The following order is used to build the resulting
1565 * designation if the arguments are not NULL:
1566 * 1a. If itemDes not NULL -> itemDes
1567 * 1b. If (itemDes not NULL) and (itemName not NULL)
1568 * -> itemDes + itemName
1569 * 2. If the preceding was NULL and (item not NULL) -> item
1570 * 3. If the preceding was NULL and (itemNode not NULL) -> itemNode
1572 * If the itemNode is an attribute node, the name of the attribute
1573 * will be appended to the result.
1575 * Returns the formatted string and sets @buf to the resulting value.
1578 xmlSchemaFormatItemForReport(xmlChar **buf,
1579 const xmlChar *itemDes,
1580 xmlSchemaBasicItemPtr item,
1581 xmlNodePtr itemNode)
1583 xmlChar *str = NULL;
1591 if (itemDes != NULL) {
1592 *buf = xmlStrdup(itemDes);
1593 } else if (item != NULL) {
1594 switch (item->type) {
1595 case XML_SCHEMA_TYPE_BASIC: {
1596 xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1598 if (WXS_IS_ATOMIC(type))
1599 *buf = xmlStrdup(BAD_CAST "atomic type 'xs:");
1600 else if (WXS_IS_LIST(type))
1601 *buf = xmlStrdup(BAD_CAST "list type 'xs:");
1602 else if (WXS_IS_UNION(type))
1603 *buf = xmlStrdup(BAD_CAST "union type 'xs:");
1605 *buf = xmlStrdup(BAD_CAST "simple type 'xs:");
1606 *buf = xmlStrcat(*buf, type->name);
1607 *buf = xmlStrcat(*buf, BAD_CAST "'");
1610 case XML_SCHEMA_TYPE_SIMPLE: {
1611 xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1613 if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
1614 *buf = xmlStrdup(BAD_CAST"");
1616 *buf = xmlStrdup(BAD_CAST "local ");
1618 if (WXS_IS_ATOMIC(type))
1619 *buf = xmlStrcat(*buf, BAD_CAST "atomic type");
1620 else if (WXS_IS_LIST(type))
1621 *buf = xmlStrcat(*buf, BAD_CAST "list type");
1622 else if (WXS_IS_UNION(type))
1623 *buf = xmlStrcat(*buf, BAD_CAST "union type");
1625 *buf = xmlStrcat(*buf, BAD_CAST "simple type");
1626 if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
1627 *buf = xmlStrcat(*buf, BAD_CAST " '");
1628 *buf = xmlStrcat(*buf, type->name);
1629 *buf = xmlStrcat(*buf, BAD_CAST "'");
1633 case XML_SCHEMA_TYPE_COMPLEX: {
1634 xmlSchemaTypePtr type = WXS_TYPE_CAST item;
1636 if (type->flags & XML_SCHEMAS_TYPE_GLOBAL)
1637 *buf = xmlStrdup(BAD_CAST "");
1639 *buf = xmlStrdup(BAD_CAST "local ");
1640 *buf = xmlStrcat(*buf, BAD_CAST "complex type");
1641 if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
1642 *buf = xmlStrcat(*buf, BAD_CAST " '");
1643 *buf = xmlStrcat(*buf, type->name);
1644 *buf = xmlStrcat(*buf, BAD_CAST "'");
1648 case XML_SCHEMA_TYPE_ATTRIBUTE_USE: {
1649 xmlSchemaAttributeUsePtr ause;
1651 ause = WXS_ATTR_USE_CAST item;
1652 *buf = xmlStrdup(BAD_CAST "attribute use ");
1653 if (WXS_ATTRUSE_DECL(ause) != NULL) {
1654 *buf = xmlStrcat(*buf, BAD_CAST "'");
1655 *buf = xmlStrcat(*buf,
1656 xmlSchemaGetComponentQName(&str, WXS_ATTRUSE_DECL(ause)));
1658 *buf = xmlStrcat(*buf, BAD_CAST "'");
1660 *buf = xmlStrcat(*buf, BAD_CAST "(unknown)");
1664 case XML_SCHEMA_TYPE_ATTRIBUTE: {
1665 xmlSchemaAttributePtr attr;
1667 attr = (xmlSchemaAttributePtr) item;
1668 *buf = xmlStrdup(BAD_CAST "attribute decl.");
1669 *buf = xmlStrcat(*buf, BAD_CAST " '");
1670 *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1671 attr->targetNamespace, attr->name));
1673 *buf = xmlStrcat(*buf, BAD_CAST "'");
1676 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
1677 xmlSchemaGetComponentDesignation(buf, item);
1679 case XML_SCHEMA_TYPE_ELEMENT: {
1680 xmlSchemaElementPtr elem;
1682 elem = (xmlSchemaElementPtr) item;
1683 *buf = xmlStrdup(BAD_CAST "element decl.");
1684 *buf = xmlStrcat(*buf, BAD_CAST " '");
1685 *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1686 elem->targetNamespace, elem->name));
1687 *buf = xmlStrcat(*buf, BAD_CAST "'");
1690 case XML_SCHEMA_TYPE_IDC_UNIQUE:
1691 case XML_SCHEMA_TYPE_IDC_KEY:
1692 case XML_SCHEMA_TYPE_IDC_KEYREF:
1693 if (item->type == XML_SCHEMA_TYPE_IDC_UNIQUE)
1694 *buf = xmlStrdup(BAD_CAST "unique '");
1695 else if (item->type == XML_SCHEMA_TYPE_IDC_KEY)
1696 *buf = xmlStrdup(BAD_CAST "key '");
1698 *buf = xmlStrdup(BAD_CAST "keyRef '");
1699 *buf = xmlStrcat(*buf, ((xmlSchemaIDCPtr) item)->name);
1700 *buf = xmlStrcat(*buf, BAD_CAST "'");
1702 case XML_SCHEMA_TYPE_ANY:
1703 case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
1704 *buf = xmlStrdup(xmlSchemaWildcardPCToString(
1705 ((xmlSchemaWildcardPtr) item)->processContents));
1706 *buf = xmlStrcat(*buf, BAD_CAST " wildcard");
1708 case XML_SCHEMA_FACET_MININCLUSIVE:
1709 case XML_SCHEMA_FACET_MINEXCLUSIVE:
1710 case XML_SCHEMA_FACET_MAXINCLUSIVE:
1711 case XML_SCHEMA_FACET_MAXEXCLUSIVE:
1712 case XML_SCHEMA_FACET_TOTALDIGITS:
1713 case XML_SCHEMA_FACET_FRACTIONDIGITS:
1714 case XML_SCHEMA_FACET_PATTERN:
1715 case XML_SCHEMA_FACET_ENUMERATION:
1716 case XML_SCHEMA_FACET_WHITESPACE:
1717 case XML_SCHEMA_FACET_LENGTH:
1718 case XML_SCHEMA_FACET_MAXLENGTH:
1719 case XML_SCHEMA_FACET_MINLENGTH:
1720 *buf = xmlStrdup(BAD_CAST "facet '");
1721 *buf = xmlStrcat(*buf, xmlSchemaFacetTypeToString(item->type));
1722 *buf = xmlStrcat(*buf, BAD_CAST "'");
1724 case XML_SCHEMA_TYPE_GROUP: {
1725 *buf = xmlStrdup(BAD_CAST "model group def.");
1726 *buf = xmlStrcat(*buf, BAD_CAST " '");
1727 *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str, item));
1728 *buf = xmlStrcat(*buf, BAD_CAST "'");
1732 case XML_SCHEMA_TYPE_SEQUENCE:
1733 case XML_SCHEMA_TYPE_CHOICE:
1734 case XML_SCHEMA_TYPE_ALL:
1735 case XML_SCHEMA_TYPE_PARTICLE:
1736 *buf = xmlStrdup(WXS_ITEM_TYPE_NAME(item));
1738 case XML_SCHEMA_TYPE_NOTATION: {
1739 *buf = xmlStrdup(WXS_ITEM_TYPE_NAME(item));
1740 *buf = xmlStrcat(*buf, BAD_CAST " '");
1741 *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str, item));
1742 *buf = xmlStrcat(*buf, BAD_CAST "'");
1745 /* Falls through. */
1752 if ((named == 0) && (itemNode != NULL)) {
1755 if (itemNode->type == XML_ATTRIBUTE_NODE)
1756 elem = itemNode->parent;
1759 *buf = xmlStrdup(BAD_CAST "Element '");
1760 if (elem->ns != NULL) {
1761 *buf = xmlStrcat(*buf,
1762 xmlSchemaFormatQName(&str, elem->ns->href, elem->name));
1765 *buf = xmlStrcat(*buf, elem->name);
1766 *buf = xmlStrcat(*buf, BAD_CAST "'");
1769 if ((itemNode != NULL) && (itemNode->type == XML_ATTRIBUTE_NODE)) {
1770 *buf = xmlStrcat(*buf, BAD_CAST ", attribute '");
1771 if (itemNode->ns != NULL) {
1772 *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
1773 itemNode->ns->href, itemNode->name));
1776 *buf = xmlStrcat(*buf, itemNode->name);
1777 *buf = xmlStrcat(*buf, BAD_CAST "'");
1781 return (xmlEscapeFormatString(buf));
1785 * xmlSchemaFormatFacetEnumSet:
1786 * @buf: the string buffer
1787 * @type: the type holding the enumeration facets
1789 * Builds a string consisting of all enumeration elements.
1791 * Returns a string of all enumeration elements.
1793 static const xmlChar *
1794 xmlSchemaFormatFacetEnumSet(xmlSchemaAbstractCtxtPtr actxt,
1795 xmlChar **buf, xmlSchemaTypePtr type)
1797 xmlSchemaFacetPtr facet;
1798 xmlSchemaWhitespaceValueType ws;
1799 xmlChar *value = NULL;
1808 * Use the whitespace type of the base type.
1810 ws = xmlSchemaGetWhiteSpaceFacetValue(type->baseType);
1811 for (facet = type->facets; facet != NULL; facet = facet->next) {
1812 if (facet->type != XML_SCHEMA_FACET_ENUMERATION)
1815 res = xmlSchemaGetCanonValueWhtspExt(facet->val,
1818 xmlSchemaInternalErr(actxt,
1819 "xmlSchemaFormatFacetEnumSet",
1820 "compute the canonical lexical representation");
1827 *buf = xmlStrdup(BAD_CAST "'");
1829 *buf = xmlStrcat(*buf, BAD_CAST ", '");
1830 *buf = xmlStrcat(*buf, BAD_CAST value);
1831 *buf = xmlStrcat(*buf, BAD_CAST "'");
1832 if (value != NULL) {
1833 xmlFree((xmlChar *)value);
1838 * The enumeration facet of a type restricts the enumeration
1839 * facet of the ancestor type; i.e., such restricted enumerations
1840 * do not belong to the set of the given type. Thus we break
1841 * on the first found enumeration.
1845 type = type->baseType;
1846 } while ((type != NULL) && (type->type != XML_SCHEMA_TYPE_BASIC));
1848 return ((const xmlChar *) *buf);
1851 /************************************************************************
1855 ************************************************************************/
1859 xmlSchemaErrMemory(const char *msg)
1861 __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, NULL, NULL,
1867 xmlSchemaPSimpleErr(const char *msg)
1869 __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, NULL, NULL,
1874 * xmlSchemaPErrMemory:
1875 * @node: a context node
1876 * @extra: extra informations
1878 * Handle an out of memory condition
1881 xmlSchemaPErrMemory(xmlSchemaParserCtxtPtr ctxt,
1882 const char *extra, xmlNodePtr node)
1886 __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, node, NULL,
1892 * @ctxt: the parsing context
1893 * @node: the context node
1894 * @error: the error code
1895 * @msg: the error message
1899 * Handle a parser error
1901 static void LIBXML_ATTR_FORMAT(4,0)
1902 xmlSchemaPErr(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
1903 const char *msg, const xmlChar * str1, const xmlChar * str2)
1905 xmlGenericErrorFunc channel = NULL;
1906 xmlStructuredErrorFunc schannel = NULL;
1912 channel = ctxt->error;
1913 data = ctxt->errCtxt;
1914 schannel = ctxt->serror;
1916 __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP,
1917 error, XML_ERR_ERROR, NULL, 0,
1918 (const char *) str1, (const char *) str2, NULL, 0, 0,
1924 * @ctxt: the parsing context
1925 * @node: the context node
1926 * @node: the current child
1927 * @error: the error code
1928 * @msg: the error message
1932 * Handle a parser error
1934 static void LIBXML_ATTR_FORMAT(5,0)
1935 xmlSchemaPErr2(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
1936 xmlNodePtr child, int error,
1937 const char *msg, const xmlChar * str1, const xmlChar * str2)
1940 xmlSchemaPErr(ctxt, child, error, msg, str1, str2);
1942 xmlSchemaPErr(ctxt, node, error, msg, str1, str2);
1948 * @ctxt: the parsing context
1949 * @node: the context node
1950 * @error: the error code
1951 * @strData1: extra data
1952 * @strData2: extra data
1953 * @strData3: extra data
1955 * @str1: extra parameter for the message display
1956 * @str2: extra parameter for the message display
1957 * @str3: extra parameter for the message display
1958 * @str4: extra parameter for the message display
1959 * @str5: extra parameter for the message display
1961 * Handle a parser error
1963 static void LIBXML_ATTR_FORMAT(7,0)
1964 xmlSchemaPErrExt(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
1965 const xmlChar * strData1, const xmlChar * strData2,
1966 const xmlChar * strData3, const char *msg, const xmlChar * str1,
1967 const xmlChar * str2, const xmlChar * str3, const xmlChar * str4,
1968 const xmlChar * str5)
1971 xmlGenericErrorFunc channel = NULL;
1972 xmlStructuredErrorFunc schannel = NULL;
1978 channel = ctxt->error;
1979 data = ctxt->errCtxt;
1980 schannel = ctxt->serror;
1982 __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP,
1983 error, XML_ERR_ERROR, NULL, 0,
1984 (const char *) strData1, (const char *) strData2,
1985 (const char *) strData3, 0, 0, msg, str1, str2,
1989 /************************************************************************
1991 * Allround error functions *
1993 ************************************************************************/
1996 * xmlSchemaVTypeErrMemory:
1997 * @node: a context node
1998 * @extra: extra informations
2000 * Handle an out of memory condition
2003 xmlSchemaVErrMemory(xmlSchemaValidCtxtPtr ctxt,
2004 const char *extra, xmlNodePtr node)
2008 ctxt->err = XML_SCHEMAV_INTERNAL;
2010 __xmlSimpleError(XML_FROM_SCHEMASV, XML_ERR_NO_MEMORY, node, NULL,
2014 static void LIBXML_ATTR_FORMAT(2,0)
2015 xmlSchemaPSimpleInternalErr(xmlNodePtr node,
2016 const char *msg, const xmlChar *str)
2018 __xmlSimpleError(XML_FROM_SCHEMASP, XML_SCHEMAP_INTERNAL, node,
2019 msg, (const char *) str);
2022 #define WXS_ERROR_TYPE_ERROR 1
2023 #define WXS_ERROR_TYPE_WARNING 2
2025 * xmlSchemaErr4Line:
2026 * @ctxt: the validation context
2027 * @errorLevel: the error level
2028 * @error: the error code
2029 * @node: the context node
2030 * @line: the line number
2031 * @msg: the error message
2037 * Handle a validation error
2039 static void LIBXML_ATTR_FORMAT(6,0)
2040 xmlSchemaErr4Line(xmlSchemaAbstractCtxtPtr ctxt,
2041 xmlErrorLevel errorLevel,
2042 int error, xmlNodePtr node, int line, const char *msg,
2043 const xmlChar *str1, const xmlChar *str2,
2044 const xmlChar *str3, const xmlChar *str4)
2046 xmlStructuredErrorFunc schannel = NULL;
2047 xmlGenericErrorFunc channel = NULL;
2051 if (ctxt->type == XML_SCHEMA_CTXT_VALIDATOR) {
2052 xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctxt;
2053 const char *file = NULL;
2055 if (errorLevel != XML_ERR_WARNING) {
2058 channel = vctxt->error;
2060 channel = vctxt->warning;
2062 schannel = vctxt->serror;
2063 data = vctxt->errCtxt;
2066 * Error node. If we specify a line number, then
2067 * do not channel any node to the error function.
2070 if ((node == NULL) &&
2071 (vctxt->depth >= 0) &&
2072 (vctxt->inode != NULL)) {
2073 node = vctxt->inode->node;
2076 * Get filename and line if no node-tree.
2078 if ((node == NULL) &&
2079 (vctxt->parserCtxt != NULL) &&
2080 (vctxt->parserCtxt->input != NULL)) {
2081 file = vctxt->parserCtxt->input->filename;
2082 line = vctxt->parserCtxt->input->line;
2083 col = vctxt->parserCtxt->input->col;
2087 * Override the given node's (if any) position
2088 * and channel only the given line number.
2094 if (vctxt->doc != NULL)
2095 file = (const char *) vctxt->doc->URL;
2096 else if ((vctxt->parserCtxt != NULL) &&
2097 (vctxt->parserCtxt->input != NULL))
2098 file = vctxt->parserCtxt->input->filename;
2100 if (vctxt->locFunc != NULL) {
2101 if ((file == NULL) || (line == 0)) {
2104 vctxt->locFunc(vctxt->locCtxt, &f, &l);
2111 if ((file == NULL) && (vctxt->filename != NULL))
2112 file = vctxt->filename;
2114 __xmlRaiseError(schannel, channel, data, ctxt,
2115 node, XML_FROM_SCHEMASV,
2116 error, errorLevel, file, line,
2117 (const char *) str1, (const char *) str2,
2118 (const char *) str3, 0, col, msg, str1, str2, str3, str4);
2120 } else if (ctxt->type == XML_SCHEMA_CTXT_PARSER) {
2121 xmlSchemaParserCtxtPtr pctxt = (xmlSchemaParserCtxtPtr) ctxt;
2122 if (errorLevel != XML_ERR_WARNING) {
2125 channel = pctxt->error;
2127 channel = pctxt->warning;
2129 schannel = pctxt->serror;
2130 data = pctxt->errCtxt;
2131 __xmlRaiseError(schannel, channel, data, ctxt,
2132 node, XML_FROM_SCHEMASP, error,
2133 errorLevel, NULL, 0,
2134 (const char *) str1, (const char *) str2,
2135 (const char *) str3, 0, 0, msg, str1, str2, str3, str4);
2144 * @ctxt: the validation context
2145 * @node: the context node
2146 * @error: the error code
2147 * @msg: the error message
2152 * Handle a validation error
2154 static void LIBXML_ATTR_FORMAT(4,0)
2155 xmlSchemaErr3(xmlSchemaAbstractCtxtPtr actxt,
2156 int error, xmlNodePtr node, const char *msg,
2157 const xmlChar *str1, const xmlChar *str2, const xmlChar *str3)
2159 xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0,
2160 msg, str1, str2, str3, NULL);
2163 static void LIBXML_ATTR_FORMAT(4,0)
2164 xmlSchemaErr4(xmlSchemaAbstractCtxtPtr actxt,
2165 int error, xmlNodePtr node, const char *msg,
2166 const xmlChar *str1, const xmlChar *str2,
2167 const xmlChar *str3, const xmlChar *str4)
2169 xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0,
2170 msg, str1, str2, str3, str4);
2173 static void LIBXML_ATTR_FORMAT(4,0)
2174 xmlSchemaErr(xmlSchemaAbstractCtxtPtr actxt,
2175 int error, xmlNodePtr node, const char *msg,
2176 const xmlChar *str1, const xmlChar *str2)
2178 xmlSchemaErr4(actxt, error, node, msg, str1, str2, NULL, NULL);
2182 xmlSchemaFormatNodeForError(xmlChar ** msg,
2183 xmlSchemaAbstractCtxtPtr actxt,
2186 xmlChar *str = NULL;
2189 if ((node != NULL) &&
2190 (node->type != XML_ELEMENT_NODE) &&
2191 (node->type != XML_ATTRIBUTE_NODE))
2194 * Don't try to format other nodes than element and
2196 * Play safe and return an empty string.
2198 *msg = xmlStrdup(BAD_CAST "");
2203 * Work on tree nodes.
2205 if (node->type == XML_ATTRIBUTE_NODE) {
2206 xmlNodePtr elem = node->parent;
2208 *msg = xmlStrdup(BAD_CAST "Element '");
2209 if (elem->ns != NULL)
2210 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2211 elem->ns->href, elem->name));
2213 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2216 *msg = xmlStrcat(*msg, BAD_CAST "', ");
2217 *msg = xmlStrcat(*msg, BAD_CAST "attribute '");
2219 *msg = xmlStrdup(BAD_CAST "Element '");
2221 if (node->ns != NULL)
2222 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2223 node->ns->href, node->name));
2225 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2228 *msg = xmlStrcat(*msg, BAD_CAST "': ");
2229 } else if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR) {
2230 xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) actxt;
2232 * Work on node infos.
2234 if (vctxt->inode->nodeType == XML_ATTRIBUTE_NODE) {
2235 xmlSchemaNodeInfoPtr ielem =
2236 vctxt->elemInfos[vctxt->depth];
2238 *msg = xmlStrdup(BAD_CAST "Element '");
2239 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2240 ielem->nsName, ielem->localName));
2242 *msg = xmlStrcat(*msg, BAD_CAST "', ");
2243 *msg = xmlStrcat(*msg, BAD_CAST "attribute '");
2245 *msg = xmlStrdup(BAD_CAST "Element '");
2247 *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
2248 vctxt->inode->nsName, vctxt->inode->localName));
2250 *msg = xmlStrcat(*msg, BAD_CAST "': ");
2251 } else if (actxt->type == XML_SCHEMA_CTXT_PARSER) {
2253 * Hmm, no node while parsing?
2254 * Return an empty string, in case NULL will break something.
2256 *msg = xmlStrdup(BAD_CAST "");
2263 * xmlSchemaFormatItemForReport() also returns an escaped format
2264 * string, so do this before calling it below (in the future).
2266 xmlEscapeFormatString(msg);
2269 * VAL TODO: The output of the given schema component is currently
2273 if ((type != NULL) && (xmlSchemaIsGlobalItem(type))) {
2274 *msg = xmlStrcat(*msg, BAD_CAST " [");
2275 *msg = xmlStrcat(*msg, xmlSchemaFormatItemForReport(&str,
2276 NULL, type, NULL, 0));
2278 *msg = xmlStrcat(*msg, BAD_CAST "]");
2284 static void LIBXML_ATTR_FORMAT(3,0)
2285 xmlSchemaInternalErr2(xmlSchemaAbstractCtxtPtr actxt,
2286 const char *funcName,
2287 const char *message,
2288 const xmlChar *str1,
2289 const xmlChar *str2)
2291 xmlChar *msg = NULL;
2295 msg = xmlStrdup(BAD_CAST "Internal error: %s, ");
2296 msg = xmlStrcat(msg, BAD_CAST message);
2297 msg = xmlStrcat(msg, BAD_CAST ".\n");
2299 if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR)
2300 xmlSchemaErr3(actxt, XML_SCHEMAV_INTERNAL, NULL,
2301 (const char *) msg, (const xmlChar *) funcName, str1, str2);
2302 else if (actxt->type == XML_SCHEMA_CTXT_PARSER)
2303 xmlSchemaErr3(actxt, XML_SCHEMAP_INTERNAL, NULL,
2304 (const char *) msg, (const xmlChar *) funcName, str1, str2);
2309 static void LIBXML_ATTR_FORMAT(3,0)
2310 xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
2311 const char *funcName,
2312 const char *message)
2314 xmlSchemaInternalErr2(actxt, funcName, message, NULL, NULL);
2318 static void LIBXML_ATTR_FORMAT(3,0)
2319 xmlSchemaPInternalErr(xmlSchemaParserCtxtPtr pctxt,
2320 const char *funcName,
2321 const char *message,
2322 const xmlChar *str1,
2323 const xmlChar *str2)
2325 xmlSchemaInternalErr2(ACTXT_CAST pctxt, funcName, message,
2330 static void LIBXML_ATTR_FORMAT(5,0)
2331 xmlSchemaCustomErr4(xmlSchemaAbstractCtxtPtr actxt,
2332 xmlParserErrors error,
2334 xmlSchemaBasicItemPtr item,
2335 const char *message,
2336 const xmlChar *str1, const xmlChar *str2,
2337 const xmlChar *str3, const xmlChar *str4)
2339 xmlChar *msg = NULL;
2341 if ((node == NULL) && (item != NULL) &&
2342 (actxt->type == XML_SCHEMA_CTXT_PARSER)) {
2343 node = WXS_ITEM_NODE(item);
2344 xmlSchemaFormatItemForReport(&msg, NULL, item, NULL);
2345 msg = xmlStrcat(msg, BAD_CAST ": ");
2347 xmlSchemaFormatNodeForError(&msg, actxt, node);
2348 msg = xmlStrcat(msg, (const xmlChar *) message);
2349 msg = xmlStrcat(msg, BAD_CAST ".\n");
2350 xmlSchemaErr4(actxt, error, node,
2351 (const char *) msg, str1, str2, str3, str4);
2355 static void LIBXML_ATTR_FORMAT(5,0)
2356 xmlSchemaCustomErr(xmlSchemaAbstractCtxtPtr actxt,
2357 xmlParserErrors error,
2359 xmlSchemaBasicItemPtr item,
2360 const char *message,
2361 const xmlChar *str1,
2362 const xmlChar *str2)
2364 xmlSchemaCustomErr4(actxt, error, node, item,
2365 message, str1, str2, NULL, NULL);
2370 static void LIBXML_ATTR_FORMAT(5,0)
2371 xmlSchemaCustomWarning(xmlSchemaAbstractCtxtPtr actxt,
2372 xmlParserErrors error,
2374 xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
2375 const char *message,
2376 const xmlChar *str1,
2377 const xmlChar *str2,
2378 const xmlChar *str3)
2380 xmlChar *msg = NULL;
2382 xmlSchemaFormatNodeForError(&msg, actxt, node);
2383 msg = xmlStrcat(msg, (const xmlChar *) message);
2384 msg = xmlStrcat(msg, BAD_CAST ".\n");
2386 /* URGENT TODO: Set the error code to something sane. */
2387 xmlSchemaErr4Line(actxt, XML_ERR_WARNING, error, node, 0,
2388 (const char *) msg, str1, str2, str3, NULL);
2395 static void LIBXML_ATTR_FORMAT(5,0)
2396 xmlSchemaKeyrefErr(xmlSchemaValidCtxtPtr vctxt,
2397 xmlParserErrors error,
2398 xmlSchemaPSVIIDCNodePtr idcNode,
2399 xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
2400 const char *message,
2401 const xmlChar *str1,
2402 const xmlChar *str2)
2404 xmlChar *msg = NULL, *qname = NULL;
2406 msg = xmlStrdup(BAD_CAST "Element '%s': ");
2407 msg = xmlStrcat(msg, (const xmlChar *) message);
2408 msg = xmlStrcat(msg, BAD_CAST ".\n");
2409 xmlSchemaErr4Line(ACTXT_CAST vctxt, XML_ERR_ERROR,
2410 error, NULL, idcNode->nodeLine, (const char *) msg,
2411 xmlSchemaFormatQName(&qname,
2412 vctxt->nodeQNames->items[idcNode->nodeQNameID +1],
2413 vctxt->nodeQNames->items[idcNode->nodeQNameID]),
2415 FREE_AND_NULL(qname);
2420 xmlSchemaEvalErrorNodeType(xmlSchemaAbstractCtxtPtr actxt,
2424 return (node->type);
2425 if ((actxt->type == XML_SCHEMA_CTXT_VALIDATOR) &&
2426 (((xmlSchemaValidCtxtPtr) actxt)->inode != NULL))
2427 return ( ((xmlSchemaValidCtxtPtr) actxt)->inode->nodeType);
2432 xmlSchemaIsGlobalItem(xmlSchemaTypePtr item)
2434 switch (item->type) {
2435 case XML_SCHEMA_TYPE_COMPLEX:
2436 case XML_SCHEMA_TYPE_SIMPLE:
2437 if (item->flags & XML_SCHEMAS_TYPE_GLOBAL)
2440 case XML_SCHEMA_TYPE_GROUP:
2442 case XML_SCHEMA_TYPE_ELEMENT:
2443 if ( ((xmlSchemaElementPtr) item)->flags &
2444 XML_SCHEMAS_ELEM_GLOBAL)
2447 case XML_SCHEMA_TYPE_ATTRIBUTE:
2448 if ( ((xmlSchemaAttributePtr) item)->flags &
2449 XML_SCHEMAS_ATTR_GLOBAL)
2452 /* Note that attribute groups are always global. */
2460 xmlSchemaSimpleTypeErr(xmlSchemaAbstractCtxtPtr actxt,
2461 xmlParserErrors error,
2463 const xmlChar *value,
2464 xmlSchemaTypePtr type,
2467 xmlChar *msg = NULL;
2469 xmlSchemaFormatNodeForError(&msg, actxt, node);
2471 if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) ==
2472 XML_ATTRIBUTE_NODE))
2473 msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of ");
2475 msg = xmlStrcat(msg, BAD_CAST "The character content is not a valid "
2478 if (! xmlSchemaIsGlobalItem(type))
2479 msg = xmlStrcat(msg, BAD_CAST "the local ");
2481 msg = xmlStrcat(msg, BAD_CAST "the ");
2483 if (WXS_IS_ATOMIC(type))
2484 msg = xmlStrcat(msg, BAD_CAST "atomic type");
2485 else if (WXS_IS_LIST(type))
2486 msg = xmlStrcat(msg, BAD_CAST "list type");
2487 else if (WXS_IS_UNION(type))
2488 msg = xmlStrcat(msg, BAD_CAST "union type");
2490 if (xmlSchemaIsGlobalItem(type)) {
2491 xmlChar *str = NULL;
2492 msg = xmlStrcat(msg, BAD_CAST " '");
2493 if (type->builtInType != 0) {
2494 msg = xmlStrcat(msg, BAD_CAST "xs:");
2495 str = xmlStrdup(type->name);
2497 const xmlChar *qName = xmlSchemaFormatQName(&str, type->targetNamespace, type->name);
2499 str = xmlStrdup(qName);
2501 msg = xmlStrcat(msg, xmlEscapeFormatString(&str));
2502 msg = xmlStrcat(msg, BAD_CAST "'");
2505 msg = xmlStrcat(msg, BAD_CAST ".\n");
2506 if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) ==
2507 XML_ATTRIBUTE_NODE))
2508 xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL);
2510 xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
2514 static const xmlChar *
2515 xmlSchemaFormatErrorNodeQName(xmlChar ** str,
2516 xmlSchemaNodeInfoPtr ni,
2520 if (node->ns != NULL)
2521 return (xmlSchemaFormatQName(str, node->ns->href, node->name));
2523 return (xmlSchemaFormatQName(str, NULL, node->name));
2524 } else if (ni != NULL)
2525 return (xmlSchemaFormatQName(str, ni->nsName, ni->localName));
2530 xmlSchemaIllegalAttrErr(xmlSchemaAbstractCtxtPtr actxt,
2531 xmlParserErrors error,
2532 xmlSchemaAttrInfoPtr ni,
2535 xmlChar *msg = NULL, *str = NULL;
2537 xmlSchemaFormatNodeForError(&msg, actxt, node);
2538 msg = xmlStrcat(msg, BAD_CAST "The attribute '%s' is not allowed.\n");
2539 xmlSchemaErr(actxt, error, node, (const char *) msg,
2540 xmlSchemaFormatErrorNodeQName(&str, (xmlSchemaNodeInfoPtr) ni, node),
2546 static void LIBXML_ATTR_FORMAT(5,0)
2547 xmlSchemaComplexTypeErr(xmlSchemaAbstractCtxtPtr actxt,
2548 xmlParserErrors error,
2550 xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
2551 const char *message,
2556 xmlChar *str = NULL, *msg = NULL;
2557 xmlChar *localName, *nsName;
2558 const xmlChar *cur, *end;
2561 xmlSchemaFormatNodeForError(&msg, actxt, node);
2562 msg = xmlStrcat(msg, (const xmlChar *) message);
2563 msg = xmlStrcat(msg, BAD_CAST ".");
2565 * Note that is does not make sense to report that we have a
2566 * wildcard here, since the wildcard might be unfolded into
2567 * multiple transitions.
2569 if (nbval + nbneg > 0) {
2570 if (nbval + nbneg > 1) {
2571 str = xmlStrdup(BAD_CAST " Expected is one of ( ");
2573 str = xmlStrdup(BAD_CAST " Expected is ( ");
2576 for (i = 0; i < nbval + nbneg; i++) {
2580 if ((cur[0] == 'n') && (cur[1] == 'o') && (cur[2] == 't') &&
2583 str = xmlStrcat(str, BAD_CAST "##other");
2586 * Get the local name.
2592 localName = xmlStrdup(BAD_CAST "*");
2595 while ((*end != 0) && (*end != '|'))
2597 localName = xmlStrncat(localName, BAD_CAST cur, end - cur);
2602 * Skip "*|*" if they come with negated expressions, since
2603 * they represent the same negated wildcard.
2605 if ((nbneg == 0) || (*end != '*') || (*localName != '*')) {
2607 * Get the namespace name.
2611 nsName = xmlStrdup(BAD_CAST "{*}");
2617 nsName = xmlStrdup(BAD_CAST "{##other:");
2619 nsName = xmlStrdup(BAD_CAST "{");
2621 nsName = xmlStrncat(nsName, BAD_CAST cur, end - cur);
2622 nsName = xmlStrcat(nsName, BAD_CAST "}");
2624 str = xmlStrcat(str, BAD_CAST nsName);
2625 FREE_AND_NULL(nsName)
2627 FREE_AND_NULL(localName);
2631 str = xmlStrcat(str, BAD_CAST localName);
2632 FREE_AND_NULL(localName);
2634 if (i < nbval + nbneg -1)
2635 str = xmlStrcat(str, BAD_CAST ", ");
2637 str = xmlStrcat(str, BAD_CAST " ).\n");
2638 msg = xmlStrcat(msg, xmlEscapeFormatString(&str));
2641 msg = xmlStrcat(msg, BAD_CAST "\n");
2642 xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
2646 static void LIBXML_ATTR_FORMAT(8,0)
2647 xmlSchemaFacetErr(xmlSchemaAbstractCtxtPtr actxt,
2648 xmlParserErrors error,
2650 const xmlChar *value,
2651 unsigned long length,
2652 xmlSchemaTypePtr type,
2653 xmlSchemaFacetPtr facet,
2654 const char *message,
2655 const xmlChar *str1,
2656 const xmlChar *str2)
2658 xmlChar *str = NULL, *msg = NULL;
2659 xmlSchemaTypeType facetType;
2660 int nodeType = xmlSchemaEvalErrorNodeType(actxt, node);
2662 xmlSchemaFormatNodeForError(&msg, actxt, node);
2663 if (error == XML_SCHEMAV_CVC_ENUMERATION_VALID) {
2664 facetType = XML_SCHEMA_FACET_ENUMERATION;
2666 * If enumerations are validated, one must not expect the
2667 * facet to be given.
2670 facetType = facet->type;
2671 msg = xmlStrcat(msg, BAD_CAST "[");
2672 msg = xmlStrcat(msg, BAD_CAST "facet '");
2673 msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facetType));
2674 msg = xmlStrcat(msg, BAD_CAST "'] ");
2675 if (message == NULL) {
2677 * Use a default message.
2679 if ((facetType == XML_SCHEMA_FACET_LENGTH) ||
2680 (facetType == XML_SCHEMA_FACET_MINLENGTH) ||
2681 (facetType == XML_SCHEMA_FACET_MAXLENGTH)) {
2683 char len[25], actLen[25];
2685 /* FIXME, TODO: What is the max expected string length of the
2688 if (nodeType == XML_ATTRIBUTE_NODE)
2689 msg = xmlStrcat(msg, BAD_CAST "The value '%s' has a length of '%s'; ");
2691 msg = xmlStrcat(msg, BAD_CAST "The value has a length of '%s'; ");
2693 snprintf(len, 24, "%lu", xmlSchemaGetFacetValueAsULong(facet));
2694 snprintf(actLen, 24, "%lu", length);
2696 if (facetType == XML_SCHEMA_FACET_LENGTH)
2697 msg = xmlStrcat(msg,
2698 BAD_CAST "this differs from the allowed length of '%s'.\n");
2699 else if (facetType == XML_SCHEMA_FACET_MAXLENGTH)
2700 msg = xmlStrcat(msg,
2701 BAD_CAST "this exceeds the allowed maximum length of '%s'.\n");
2702 else if (facetType == XML_SCHEMA_FACET_MINLENGTH)
2703 msg = xmlStrcat(msg,
2704 BAD_CAST "this underruns the allowed minimum length of '%s'.\n");
2706 if (nodeType == XML_ATTRIBUTE_NODE)
2707 xmlSchemaErr3(actxt, error, node, (const char *) msg,
2708 value, (const xmlChar *) actLen, (const xmlChar *) len);
2710 xmlSchemaErr(actxt, error, node, (const char *) msg,
2711 (const xmlChar *) actLen, (const xmlChar *) len);
2713 } else if (facetType == XML_SCHEMA_FACET_ENUMERATION) {
2714 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not an element "
2715 "of the set {%s}.\n");
2716 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2717 xmlSchemaFormatFacetEnumSet(actxt, &str, type));
2718 } else if (facetType == XML_SCHEMA_FACET_PATTERN) {
2719 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not accepted "
2720 "by the pattern '%s'.\n");
2721 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2723 } else if (facetType == XML_SCHEMA_FACET_MININCLUSIVE) {
2724 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is less than the "
2725 "minimum value allowed ('%s').\n");
2726 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2728 } else if (facetType == XML_SCHEMA_FACET_MAXINCLUSIVE) {
2729 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is greater than the "
2730 "maximum value allowed ('%s').\n");
2731 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2733 } else if (facetType == XML_SCHEMA_FACET_MINEXCLUSIVE) {
2734 msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be greater than "
2736 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2738 } else if (facetType == XML_SCHEMA_FACET_MAXEXCLUSIVE) {
2739 msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be less than "
2741 xmlSchemaErr(actxt, error, node, (const char *) msg, value,
2743 } else if (facetType == XML_SCHEMA_FACET_TOTALDIGITS) {
2744 msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more "
2745 "digits than are allowed ('%s').\n");
2746 xmlSchemaErr(actxt, error, node, (const char*) msg, value,
2748 } else if (facetType == XML_SCHEMA_FACET_FRACTIONDIGITS) {
2749 msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more fractional "
2750 "digits than are allowed ('%s').\n");
2751 xmlSchemaErr(actxt, error, node, (const char*) msg, value,
2753 } else if (nodeType == XML_ATTRIBUTE_NODE) {
2754 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not facet-valid.\n");
2755 xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL);
2757 msg = xmlStrcat(msg, BAD_CAST "The value is not facet-valid.\n");
2758 xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
2761 msg = xmlStrcat(msg, (const xmlChar *) message);
2762 msg = xmlStrcat(msg, BAD_CAST ".\n");
2763 xmlSchemaErr(actxt, error, node, (const char *) msg, str1, str2);
2769 #define VERROR(err, type, msg) \
2770 xmlSchemaCustomErr(ACTXT_CAST vctxt, err, NULL, type, msg, NULL, NULL);
2772 #define VERROR_INT(func, msg) xmlSchemaInternalErr(ACTXT_CAST vctxt, func, msg);
2774 #define PERROR_INT(func, msg) xmlSchemaInternalErr(ACTXT_CAST pctxt, func, msg);
2775 #define PERROR_INT2(func, msg) xmlSchemaInternalErr(ACTXT_CAST ctxt, func, msg);
2777 #define AERROR_INT(func, msg) xmlSchemaInternalErr(actxt, func, msg);
2781 * xmlSchemaPMissingAttrErr:
2782 * @ctxt: the schema validation context
2783 * @ownerDes: the designation of the owner
2784 * @ownerName: the name of the owner
2785 * @ownerItem: the owner as a schema object
2786 * @ownerElem: the owner as an element node
2787 * @node: the parent element node of the missing attribute node
2788 * @type: the corresponding type of the attribute node
2790 * Reports an illegal attribute.
2793 xmlSchemaPMissingAttrErr(xmlSchemaParserCtxtPtr ctxt,
2794 xmlParserErrors error,
2795 xmlSchemaBasicItemPtr ownerItem,
2796 xmlNodePtr ownerElem,
2798 const char *message)
2800 xmlChar *des = NULL;
2802 xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
2804 if (message != NULL)
2805 xmlSchemaPErr(ctxt, ownerElem, error, "%s: %s.\n", BAD_CAST des, BAD_CAST message);
2807 xmlSchemaPErr(ctxt, ownerElem, error,
2808 "%s: The attribute '%s' is required but missing.\n",
2809 BAD_CAST des, BAD_CAST name);
2815 * xmlSchemaPResCompAttrErr:
2816 * @ctxt: the schema validation context
2817 * @error: the error code
2818 * @ownerDes: the designation of the owner
2819 * @ownerItem: the owner as a schema object
2820 * @ownerElem: the owner as an element node
2821 * @name: the name of the attribute holding the QName
2822 * @refName: the referenced local name
2823 * @refURI: the referenced namespace URI
2824 * @message: optional message
2826 * Used to report QName attribute values that failed to resolve
2827 * to schema components.
2830 xmlSchemaPResCompAttrErr(xmlSchemaParserCtxtPtr ctxt,
2831 xmlParserErrors error,
2832 xmlSchemaBasicItemPtr ownerItem,
2833 xmlNodePtr ownerElem,
2835 const xmlChar *refName,
2836 const xmlChar *refURI,
2837 xmlSchemaTypeType refType,
2838 const char *refTypeStr)
2840 xmlChar *des = NULL, *strA = NULL;
2842 xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
2843 if (refTypeStr == NULL)
2844 refTypeStr = (const char *) xmlSchemaItemTypeToStr(refType);
2845 xmlSchemaPErrExt(ctxt, ownerElem, error,
2847 "%s, attribute '%s': The QName value '%s' does not resolve to a(n) "
2848 "%s.\n", BAD_CAST des, BAD_CAST name,
2849 xmlSchemaFormatQName(&strA, refURI, refName),
2850 BAD_CAST refTypeStr, NULL);
2856 * xmlSchemaPCustomAttrErr:
2857 * @ctxt: the schema parser context
2858 * @error: the error code
2859 * @ownerDes: the designation of the owner
2860 * @ownerItem: the owner as a schema object
2861 * @attr: the illegal attribute node
2863 * Reports an illegal attribute during the parse.
2866 xmlSchemaPCustomAttrErr(xmlSchemaParserCtxtPtr ctxt,
2867 xmlParserErrors error,
2869 xmlSchemaBasicItemPtr ownerItem,
2873 xmlChar *des = NULL;
2875 if (ownerDes == NULL)
2876 xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent);
2877 else if (*ownerDes == NULL) {
2878 xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent);
2883 xmlSchemaPErrExt(ctxt, NULL, error, NULL, NULL, NULL,
2884 "%s, attribute '%s': %s.\n",
2885 BAD_CAST des, (const xmlChar *) "Unknown",
2886 (const xmlChar *) msg, NULL, NULL);
2888 xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL,
2889 "%s, attribute '%s': %s.\n",
2890 BAD_CAST des, attr->name, (const xmlChar *) msg, NULL, NULL);
2892 if (ownerDes == NULL)
2897 * xmlSchemaPIllegalAttrErr:
2898 * @ctxt: the schema parser context
2899 * @error: the error code
2900 * @ownerDes: the designation of the attribute's owner
2901 * @ownerItem: the attribute's owner item
2902 * @attr: the illegal attribute node
2904 * Reports an illegal attribute during the parse.
2907 xmlSchemaPIllegalAttrErr(xmlSchemaParserCtxtPtr ctxt,
2908 xmlParserErrors error,
2909 xmlSchemaBasicItemPtr ownerComp ATTRIBUTE_UNUSED,
2912 xmlChar *strA = NULL, *strB = NULL;
2914 xmlSchemaFormatNodeForError(&strA, ACTXT_CAST ctxt, attr->parent);
2915 xmlSchemaErr4(ACTXT_CAST ctxt, error, (xmlNodePtr) attr,
2916 "%sThe attribute '%s' is not allowed.\n", BAD_CAST strA,
2917 xmlSchemaFormatQNameNs(&strB, attr->ns, attr->name),
2919 FREE_AND_NULL(strA);
2920 FREE_AND_NULL(strB);
2924 * xmlSchemaPCustomErr:
2925 * @ctxt: the schema parser context
2926 * @error: the error code
2927 * @itemDes: the designation of the schema item
2928 * @item: the schema item
2929 * @itemElem: the node of the schema item
2930 * @message: the error message
2931 * @str1: an optional param for the error message
2932 * @str2: an optional param for the error message
2933 * @str3: an optional param for the error message
2935 * Reports an error during parsing.
2937 static void LIBXML_ATTR_FORMAT(5,0)
2938 xmlSchemaPCustomErrExt(xmlSchemaParserCtxtPtr ctxt,
2939 xmlParserErrors error,
2940 xmlSchemaBasicItemPtr item,
2941 xmlNodePtr itemElem,
2942 const char *message,
2943 const xmlChar *str1,
2944 const xmlChar *str2,
2945 const xmlChar *str3)
2947 xmlChar *des = NULL, *msg = NULL;
2949 xmlSchemaFormatItemForReport(&des, NULL, item, itemElem);
2950 msg = xmlStrdup(BAD_CAST "%s: ");
2951 msg = xmlStrcat(msg, (const xmlChar *) message);
2952 msg = xmlStrcat(msg, BAD_CAST ".\n");
2953 if ((itemElem == NULL) && (item != NULL))
2954 itemElem = WXS_ITEM_NODE(item);
2955 xmlSchemaPErrExt(ctxt, itemElem, error, NULL, NULL, NULL,
2956 (const char *) msg, BAD_CAST des, str1, str2, str3, NULL);
2962 * xmlSchemaPCustomErr:
2963 * @ctxt: the schema parser context
2964 * @error: the error code
2965 * @itemDes: the designation of the schema item
2966 * @item: the schema item
2967 * @itemElem: the node of the schema item
2968 * @message: the error message
2969 * @str1: the optional param for the error message
2971 * Reports an error during parsing.
2973 static void LIBXML_ATTR_FORMAT(5,0)
2974 xmlSchemaPCustomErr(xmlSchemaParserCtxtPtr ctxt,
2975 xmlParserErrors error,
2976 xmlSchemaBasicItemPtr item,
2977 xmlNodePtr itemElem,
2978 const char *message,
2979 const xmlChar *str1)
2981 xmlSchemaPCustomErrExt(ctxt, error, item, itemElem, message,
2986 * xmlSchemaPAttrUseErr:
2987 * @ctxt: the schema parser context
2988 * @error: the error code
2989 * @itemDes: the designation of the schema type
2990 * @item: the schema type
2991 * @itemElem: the node of the schema type
2992 * @attr: the invalid schema attribute
2993 * @message: the error message
2994 * @str1: the optional param for the error message
2996 * Reports an attribute use error during parsing.
2998 static void LIBXML_ATTR_FORMAT(6,0)
2999 xmlSchemaPAttrUseErr4(xmlSchemaParserCtxtPtr ctxt,
3000 xmlParserErrors error,
3002 xmlSchemaBasicItemPtr ownerItem,
3003 const xmlSchemaAttributeUsePtr attruse,
3004 const char *message,
3005 const xmlChar *str1, const xmlChar *str2,
3006 const xmlChar *str3,const xmlChar *str4)
3008 xmlChar *str = NULL, *msg = NULL;
3010 xmlSchemaFormatItemForReport(&msg, NULL, ownerItem, NULL);
3011 msg = xmlStrcat(msg, BAD_CAST ", ");
3012 msg = xmlStrcat(msg,
3013 BAD_CAST xmlSchemaFormatItemForReport(&str, NULL,
3014 WXS_BASIC_CAST attruse, NULL));
3016 msg = xmlStrcat(msg, BAD_CAST ": ");
3017 msg = xmlStrcat(msg, (const xmlChar *) message);
3018 msg = xmlStrcat(msg, BAD_CAST ".\n");
3019 xmlSchemaErr4(ACTXT_CAST ctxt, error, node,
3020 (const char *) msg, str1, str2, str3, str4);
3025 * xmlSchemaPIllegalFacetAtomicErr:
3026 * @ctxt: the schema parser context
3027 * @error: the error code
3028 * @type: the schema type
3029 * @baseType: the base type of type
3030 * @facet: the illegal facet
3032 * Reports an illegal facet for atomic simple types.
3035 xmlSchemaPIllegalFacetAtomicErr(xmlSchemaParserCtxtPtr ctxt,
3036 xmlParserErrors error,
3037 xmlSchemaTypePtr type,
3038 xmlSchemaTypePtr baseType,
3039 xmlSchemaFacetPtr facet)
3041 xmlChar *des = NULL, *strT = NULL;
3043 xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST type, type->node);
3044 xmlSchemaPErrExt(ctxt, type->node, error, NULL, NULL, NULL,
3045 "%s: The facet '%s' is not allowed on types derived from the "
3047 BAD_CAST des, xmlSchemaFacetTypeToString(facet->type),
3048 xmlSchemaFormatItemForReport(&strT, NULL, WXS_BASIC_CAST baseType, NULL),
3051 FREE_AND_NULL(strT);
3055 * xmlSchemaPIllegalFacetListUnionErr:
3056 * @ctxt: the schema parser context
3057 * @error: the error code
3058 * @itemDes: the designation of the schema item involved
3059 * @item: the schema item involved
3060 * @facet: the illegal facet
3062 * Reports an illegal facet for <list> and <union>.
3065 xmlSchemaPIllegalFacetListUnionErr(xmlSchemaParserCtxtPtr ctxt,
3066 xmlParserErrors error,
3067 xmlSchemaTypePtr type,
3068 xmlSchemaFacetPtr facet)
3070 xmlChar *des = NULL;
3072 xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST type,
3074 xmlSchemaPErr(ctxt, type->node, error,
3075 "%s: The facet '%s' is not allowed.\n",
3076 BAD_CAST des, xmlSchemaFacetTypeToString(facet->type));
3081 * xmlSchemaPMutualExclAttrErr:
3082 * @ctxt: the schema validation context
3083 * @error: the error code
3084 * @elemDes: the designation of the parent element node
3085 * @attr: the bad attribute node
3086 * @type: the corresponding type of the attribute node
3088 * Reports an illegal attribute.
3091 xmlSchemaPMutualExclAttrErr(xmlSchemaParserCtxtPtr ctxt,
3092 xmlParserErrors error,
3093 xmlSchemaBasicItemPtr ownerItem,
3098 xmlChar *des = NULL;
3100 xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST ownerItem, attr->parent);
3101 xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL,
3102 "%s: The attributes '%s' and '%s' are mutually exclusive.\n",
3103 BAD_CAST des, BAD_CAST name1, BAD_CAST name2, NULL, NULL);
3108 * xmlSchemaPSimpleTypeErr:
3109 * @ctxt: the schema validation context
3110 * @error: the error code
3111 * @type: the type specifier
3112 * @ownerDes: the designation of the owner
3113 * @ownerItem: the schema object if existent
3114 * @node: the validated node
3115 * @value: the validated value
3117 * Reports a simple type validation error.
3118 * TODO: Should this report the value of an element as well?
3120 static void LIBXML_ATTR_FORMAT(8,0)
3121 xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt,
3122 xmlParserErrors error,
3123 xmlSchemaBasicItemPtr ownerItem ATTRIBUTE_UNUSED,
3125 xmlSchemaTypePtr type,
3126 const char *expected,
3127 const xmlChar *value,
3128 const char *message,
3129 const xmlChar *str1,
3130 const xmlChar *str2)
3132 xmlChar *msg = NULL;
3134 xmlSchemaFormatNodeForError(&msg, ACTXT_CAST ctxt, node);
3135 if (message == NULL) {
3137 * Use default messages.
3140 if (node->type == XML_ATTRIBUTE_NODE)
3141 msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of ");
3143 msg = xmlStrcat(msg, BAD_CAST "The character content is not a "
3145 if (! xmlSchemaIsGlobalItem(type))
3146 msg = xmlStrcat(msg, BAD_CAST "the local ");
3148 msg = xmlStrcat(msg, BAD_CAST "the ");
3150 if (WXS_IS_ATOMIC(type))
3151 msg = xmlStrcat(msg, BAD_CAST "atomic type");
3152 else if (WXS_IS_LIST(type))
3153 msg = xmlStrcat(msg, BAD_CAST "list type");
3154 else if (WXS_IS_UNION(type))
3155 msg = xmlStrcat(msg, BAD_CAST "union type");
3157 if (xmlSchemaIsGlobalItem(type)) {
3158 xmlChar *str = NULL;
3159 msg = xmlStrcat(msg, BAD_CAST " '");
3160 if (type->builtInType != 0) {
3161 msg = xmlStrcat(msg, BAD_CAST "xs:");
3162 str = xmlStrdup(type->name);
3164 const xmlChar *qName = xmlSchemaFormatQName(&str, type->targetNamespace, type->name);
3166 str = xmlStrdup(qName);
3168 msg = xmlStrcat(msg, xmlEscapeFormatString(&str));
3169 msg = xmlStrcat(msg, BAD_CAST "'.");
3173 if (node->type == XML_ATTRIBUTE_NODE)
3174 msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not valid.");
3176 msg = xmlStrcat(msg, BAD_CAST "The character content is not "
3180 xmlChar *expectedEscaped = xmlCharStrdup(expected);
3181 msg = xmlStrcat(msg, BAD_CAST " Expected is '");
3182 msg = xmlStrcat(msg, xmlEscapeFormatString(&expectedEscaped));
3183 FREE_AND_NULL(expectedEscaped);
3184 msg = xmlStrcat(msg, BAD_CAST "'.\n");
3186 msg = xmlStrcat(msg, BAD_CAST "\n");
3187 if (node->type == XML_ATTRIBUTE_NODE)
3188 xmlSchemaPErr(ctxt, node, error, (const char *) msg, value, NULL);
3190 xmlSchemaPErr(ctxt, node, error, (const char *) msg, NULL, NULL);
3192 msg = xmlStrcat(msg, BAD_CAST message);
3193 msg = xmlStrcat(msg, BAD_CAST ".\n");
3194 xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL,
3195 (const char*) msg, str1, str2, NULL, NULL, NULL);
3202 * xmlSchemaPContentErr:
3203 * @ctxt: the schema parser context
3204 * @error: the error code
3205 * @onwerDes: the designation of the holder of the content
3206 * @ownerItem: the owner item of the holder of the content
3207 * @ownerElem: the node of the holder of the content
3208 * @child: the invalid child node
3209 * @message: the optional error message
3210 * @content: the optional string describing the correct content
3212 * Reports an error concerning the content of a schema element.
3215 xmlSchemaPContentErr(xmlSchemaParserCtxtPtr ctxt,
3216 xmlParserErrors error,
3217 xmlSchemaBasicItemPtr ownerItem,
3218 xmlNodePtr ownerElem,
3220 const char *message,
3221 const char *content)
3223 xmlChar *des = NULL;
3225 xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
3226 if (message != NULL)
3227 xmlSchemaPErr2(ctxt, ownerElem, child, error,
3229 BAD_CAST des, BAD_CAST message);
3231 if (content != NULL) {
3232 xmlSchemaPErr2(ctxt, ownerElem, child, error,
3233 "%s: The content is not valid. Expected is %s.\n",
3234 BAD_CAST des, BAD_CAST content);
3236 xmlSchemaPErr2(ctxt, ownerElem, child, error,
3237 "%s: The content is not valid.\n",
3238 BAD_CAST des, NULL);
3244 /************************************************************************
3246 * Streamable error functions *
3248 ************************************************************************/
3253 /************************************************************************
3255 * Validation helper functions *
3257 ************************************************************************/
3260 /************************************************************************
3262 * Allocation functions *
3264 ************************************************************************/
3267 * xmlSchemaNewSchemaForParserCtxt:
3268 * @ctxt: a schema validation context
3270 * Allocate a new Schema structure.
3272 * Returns the newly allocated structure or NULL in case or error
3275 xmlSchemaNewSchema(xmlSchemaParserCtxtPtr ctxt)
3279 ret = (xmlSchemaPtr) xmlMalloc(sizeof(xmlSchema));
3281 xmlSchemaPErrMemory(ctxt, "allocating schema", NULL);
3284 memset(ret, 0, sizeof(xmlSchema));
3285 ret->dict = ctxt->dict;
3286 xmlDictReference(ret->dict);
3292 * xmlSchemaNewFacet:
3294 * Allocate a new Facet structure.
3296 * Returns the newly allocated structure or NULL in case or error
3299 xmlSchemaNewFacet(void)
3301 xmlSchemaFacetPtr ret;
3303 ret = (xmlSchemaFacetPtr) xmlMalloc(sizeof(xmlSchemaFacet));
3307 memset(ret, 0, sizeof(xmlSchemaFacet));
3313 * xmlSchemaNewAnnot:
3314 * @ctxt: a schema validation context
3317 * Allocate a new annotation structure.
3319 * Returns the newly allocated structure or NULL in case or error
3321 static xmlSchemaAnnotPtr
3322 xmlSchemaNewAnnot(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node)
3324 xmlSchemaAnnotPtr ret;
3326 ret = (xmlSchemaAnnotPtr) xmlMalloc(sizeof(xmlSchemaAnnot));
3328 xmlSchemaPErrMemory(ctxt, "allocating annotation", node);
3331 memset(ret, 0, sizeof(xmlSchemaAnnot));
3332 ret->content = node;
3336 static xmlSchemaItemListPtr
3337 xmlSchemaItemListCreate(void)
3339 xmlSchemaItemListPtr ret;
3341 ret = xmlMalloc(sizeof(xmlSchemaItemList));
3343 xmlSchemaPErrMemory(NULL,
3344 "allocating an item list structure", NULL);
3347 memset(ret, 0, sizeof(xmlSchemaItemList));
3352 xmlSchemaItemListClear(xmlSchemaItemListPtr list)
3354 if (list->items != NULL) {
3355 xmlFree(list->items);
3359 list->sizeItems = 0;
3363 xmlSchemaItemListAdd(xmlSchemaItemListPtr list, void *item)
3365 if (list->items == NULL) {
3366 list->items = (void **) xmlMalloc(
3367 20 * sizeof(void *));
3368 if (list->items == NULL) {
3369 xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
3372 list->sizeItems = 20;
3373 } else if (list->sizeItems <= list->nbItems) {
3374 list->sizeItems *= 2;
3375 list->items = (void **) xmlRealloc(list->items,
3376 list->sizeItems * sizeof(void *));
3377 if (list->items == NULL) {
3378 xmlSchemaPErrMemory(NULL, "growing item list", NULL);
3379 list->sizeItems = 0;
3383 list->items[list->nbItems++] = item;
3388 xmlSchemaItemListAddSize(xmlSchemaItemListPtr list,
3392 if (list->items == NULL) {
3393 if (initialSize <= 0)
3395 list->items = (void **) xmlMalloc(
3396 initialSize * sizeof(void *));
3397 if (list->items == NULL) {
3398 xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
3401 list->sizeItems = initialSize;
3402 } else if (list->sizeItems <= list->nbItems) {
3403 list->sizeItems *= 2;
3404 list->items = (void **) xmlRealloc(list->items,
3405 list->sizeItems * sizeof(void *));
3406 if (list->items == NULL) {
3407 xmlSchemaPErrMemory(NULL, "growing item list", NULL);
3408 list->sizeItems = 0;
3412 list->items[list->nbItems++] = item;
3417 xmlSchemaItemListInsert(xmlSchemaItemListPtr list, void *item, int idx)
3419 if (list->items == NULL) {
3420 list->items = (void **) xmlMalloc(
3421 20 * sizeof(void *));
3422 if (list->items == NULL) {
3423 xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
3426 list->sizeItems = 20;
3427 } else if (list->sizeItems <= list->nbItems) {
3428 list->sizeItems *= 2;
3429 list->items = (void **) xmlRealloc(list->items,
3430 list->sizeItems * sizeof(void *));
3431 if (list->items == NULL) {
3432 xmlSchemaPErrMemory(NULL, "growing item list", NULL);
3433 list->sizeItems = 0;
3438 * Just append if the index is greater/equal than the item count.
3440 if (idx >= list->nbItems) {
3441 list->items[list->nbItems++] = item;
3444 for (i = list->nbItems; i > idx; i--)
3445 list->items[i] = list->items[i-1];
3446 list->items[idx] = item;
3452 #if 0 /* enable if ever needed */
3454 xmlSchemaItemListInsertSize(xmlSchemaItemListPtr list,
3459 if (list->items == NULL) {
3460 if (initialSize <= 0)
3462 list->items = (void **) xmlMalloc(
3463 initialSize * sizeof(void *));
3464 if (list->items == NULL) {
3465 xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
3468 list->sizeItems = initialSize;
3469 } else if (list->sizeItems <= list->nbItems) {
3470 list->sizeItems *= 2;
3471 list->items = (void **) xmlRealloc(list->items,
3472 list->sizeItems * sizeof(void *));
3473 if (list->items == NULL) {
3474 xmlSchemaPErrMemory(NULL, "growing item list", NULL);
3475 list->sizeItems = 0;
3480 * Just append if the index is greater/equal than the item count.
3482 if (idx >= list->nbItems) {
3483 list->items[list->nbItems++] = item;
3486 for (i = list->nbItems; i > idx; i--)
3487 list->items[i] = list->items[i-1];
3488 list->items[idx] = item;
3496 xmlSchemaItemListRemove(xmlSchemaItemListPtr list, int idx)
3499 if ((list->items == NULL) || (idx >= list->nbItems)) {
3500 xmlSchemaPSimpleErr("Internal error: xmlSchemaItemListRemove, "
3505 if (list->nbItems == 1) {
3506 /* TODO: Really free the list? */
3507 xmlFree(list->items);
3510 list->sizeItems = 0;
3511 } else if (list->nbItems -1 == idx) {
3514 for (i = idx; i < list->nbItems -1; i++)
3515 list->items[i] = list->items[i+1];
3522 * xmlSchemaItemListFree:
3523 * @annot: a schema type structure
3525 * Deallocate a annotation structure
3528 xmlSchemaItemListFree(xmlSchemaItemListPtr list)
3532 if (list->items != NULL)
3533 xmlFree(list->items);
3538 xmlSchemaBucketFree(xmlSchemaBucketPtr bucket)
3542 if (bucket->globals != NULL) {
3543 xmlSchemaComponentListFree(bucket->globals);
3544 xmlSchemaItemListFree(bucket->globals);
3546 if (bucket->locals != NULL) {
3547 xmlSchemaComponentListFree(bucket->locals);
3548 xmlSchemaItemListFree(bucket->locals);
3550 if (bucket->relations != NULL) {
3551 xmlSchemaSchemaRelationPtr prev, cur = bucket->relations;
3556 } while (cur != NULL);
3558 if ((! bucket->preserveDoc) && (bucket->doc != NULL)) {
3559 xmlFreeDoc(bucket->doc);
3561 if (bucket->type == XML_SCHEMA_SCHEMA_IMPORT) {
3562 if (WXS_IMPBUCKET(bucket)->schema != NULL)
3563 xmlSchemaFree(WXS_IMPBUCKET(bucket)->schema);
3568 static xmlSchemaBucketPtr
3569 xmlSchemaBucketCreate(xmlSchemaParserCtxtPtr pctxt,
3570 int type, const xmlChar *targetNamespace)
3572 xmlSchemaBucketPtr ret;
3574 xmlSchemaPtr mainSchema;
3576 if (WXS_CONSTRUCTOR(pctxt)->mainSchema == NULL) {
3577 PERROR_INT("xmlSchemaBucketCreate",
3578 "no main schema on constructor");
3581 mainSchema = WXS_CONSTRUCTOR(pctxt)->mainSchema;
3582 /* Create the schema bucket. */
3583 if (WXS_IS_BUCKET_INCREDEF(type))
3584 size = sizeof(xmlSchemaInclude);
3586 size = sizeof(xmlSchemaImport);
3587 ret = (xmlSchemaBucketPtr) xmlMalloc(size);
3589 xmlSchemaPErrMemory(NULL, "allocating schema bucket", NULL);
3592 memset(ret, 0, size);
3593 ret->targetNamespace = targetNamespace;
3595 ret->globals = xmlSchemaItemListCreate();
3596 if (ret->globals == NULL) {
3600 ret->locals = xmlSchemaItemListCreate();
3601 if (ret->locals == NULL) {
3606 * The following will assure that only the first bucket is marked as
3607 * XML_SCHEMA_SCHEMA_MAIN and it points to the *main* schema.
3608 * For each following import buckets an xmlSchema will be created.
3609 * An xmlSchema will be created for every distinct targetNamespace.
3610 * We assign the targetNamespace to the schemata here.
3612 if (! WXS_HAS_BUCKETS(pctxt)) {
3613 if (WXS_IS_BUCKET_INCREDEF(type)) {
3614 PERROR_INT("xmlSchemaBucketCreate",
3615 "first bucket but it's an include or redefine");
3616 xmlSchemaBucketFree(ret);
3619 /* Force the type to be XML_SCHEMA_SCHEMA_MAIN. */
3620 ret->type = XML_SCHEMA_SCHEMA_MAIN;
3621 /* Point to the *main* schema. */
3622 WXS_CONSTRUCTOR(pctxt)->mainBucket = ret;
3623 WXS_IMPBUCKET(ret)->schema = mainSchema;
3625 * Ensure that the main schema gets a targetNamespace.
3627 mainSchema->targetNamespace = targetNamespace;
3629 if (type == XML_SCHEMA_SCHEMA_MAIN) {
3630 PERROR_INT("xmlSchemaBucketCreate",
3631 "main bucket but it's not the first one");
3632 xmlSchemaBucketFree(ret);
3634 } else if (type == XML_SCHEMA_SCHEMA_IMPORT) {
3636 * Create a schema for imports and assign the
3639 WXS_IMPBUCKET(ret)->schema = xmlSchemaNewSchema(pctxt);
3640 if (WXS_IMPBUCKET(ret)->schema == NULL) {
3641 xmlSchemaBucketFree(ret);
3644 WXS_IMPBUCKET(ret)->schema->targetNamespace = targetNamespace;
3647 if (WXS_IS_BUCKET_IMPMAIN(type)) {
3650 * Imports go into the "schemasImports" slot of the main *schema*.
3651 * Note that we create an import entry for the main schema as well; i.e.,
3652 * even if there's only one schema, we'll get an import.
3654 if (mainSchema->schemasImports == NULL) {
3655 mainSchema->schemasImports = xmlHashCreateDict(5,
3656 WXS_CONSTRUCTOR(pctxt)->dict);
3657 if (mainSchema->schemasImports == NULL) {
3658 xmlSchemaBucketFree(ret);
3662 if (targetNamespace == NULL)
3663 res = xmlHashAddEntry(mainSchema->schemasImports,
3664 XML_SCHEMAS_NO_NAMESPACE, ret);
3666 res = xmlHashAddEntry(mainSchema->schemasImports,
3667 targetNamespace, ret);
3669 PERROR_INT("xmlSchemaBucketCreate",
3670 "failed to add the schema bucket to the hash");
3671 xmlSchemaBucketFree(ret);
3675 /* Set the @ownerImport of an include bucket. */
3676 if (WXS_IS_BUCKET_IMPMAIN(WXS_CONSTRUCTOR(pctxt)->bucket->type))
3677 WXS_INCBUCKET(ret)->ownerImport =
3678 WXS_IMPBUCKET(WXS_CONSTRUCTOR(pctxt)->bucket);
3680 WXS_INCBUCKET(ret)->ownerImport =
3681 WXS_INCBUCKET(WXS_CONSTRUCTOR(pctxt)->bucket)->ownerImport;
3683 /* Includes got into the "includes" slot of the *main* schema. */
3684 if (mainSchema->includes == NULL) {
3685 mainSchema->includes = xmlSchemaItemListCreate();
3686 if (mainSchema->includes == NULL) {
3687 xmlSchemaBucketFree(ret);
3691 xmlSchemaItemListAdd(mainSchema->includes, ret);
3694 * Add to list of all buckets; this is used for lookup
3695 * during schema construction time only.
3697 if (xmlSchemaItemListAdd(WXS_CONSTRUCTOR(pctxt)->buckets, ret) == -1)
3703 xmlSchemaAddItemSize(xmlSchemaItemListPtr *list, int initialSize, void *item)
3705 if (*list == NULL) {
3706 *list = xmlSchemaItemListCreate();
3710 xmlSchemaItemListAddSize(*list, initialSize, item);
3715 * xmlSchemaFreeAnnot:
3716 * @annot: a schema type structure
3718 * Deallocate a annotation structure
3721 xmlSchemaFreeAnnot(xmlSchemaAnnotPtr annot)
3725 if (annot->next == NULL) {
3728 xmlSchemaAnnotPtr prev;
3732 annot = annot->next;
3734 } while (annot != NULL);
3739 * xmlSchemaFreeNotation:
3740 * @schema: a schema notation structure
3742 * Deallocate a Schema Notation structure.
3745 xmlSchemaFreeNotation(xmlSchemaNotationPtr nota)
3753 * xmlSchemaFreeAttribute:
3754 * @attr: an attribute declaration
3756 * Deallocates an attribute declaration structure.
3759 xmlSchemaFreeAttribute(xmlSchemaAttributePtr attr)
3763 if (attr->annot != NULL)
3764 xmlSchemaFreeAnnot(attr->annot);
3765 if (attr->defVal != NULL)
3766 xmlSchemaFreeValue(attr->defVal);
3771 * xmlSchemaFreeAttributeUse:
3772 * @use: an attribute use
3774 * Deallocates an attribute use structure.
3777 xmlSchemaFreeAttributeUse(xmlSchemaAttributeUsePtr use)
3781 if (use->annot != NULL)
3782 xmlSchemaFreeAnnot(use->annot);
3783 if (use->defVal != NULL)
3784 xmlSchemaFreeValue(use->defVal);
3789 * xmlSchemaFreeAttributeUseProhib:
3790 * @prohib: an attribute use prohibition
3792 * Deallocates an attribute use structure.
3795 xmlSchemaFreeAttributeUseProhib(xmlSchemaAttributeUseProhibPtr prohib)
3803 * xmlSchemaFreeWildcardNsSet:
3804 * set: a schema wildcard namespace
3806 * Deallocates a list of wildcard constraint structures.
3809 xmlSchemaFreeWildcardNsSet(xmlSchemaWildcardNsPtr set)
3811 xmlSchemaWildcardNsPtr next;
3813 while (set != NULL) {
3821 * xmlSchemaFreeWildcard:
3822 * @wildcard: a wildcard structure
3824 * Deallocates a wildcard structure.
3827 xmlSchemaFreeWildcard(xmlSchemaWildcardPtr wildcard)
3829 if (wildcard == NULL)
3831 if (wildcard->annot != NULL)
3832 xmlSchemaFreeAnnot(wildcard->annot);
3833 if (wildcard->nsSet != NULL)
3834 xmlSchemaFreeWildcardNsSet(wildcard->nsSet);
3835 if (wildcard->negNsSet != NULL)
3836 xmlFree(wildcard->negNsSet);
3841 * xmlSchemaFreeAttributeGroup:
3842 * @schema: a schema attribute group structure
3844 * Deallocate a Schema Attribute Group structure.
3847 xmlSchemaFreeAttributeGroup(xmlSchemaAttributeGroupPtr attrGr)
3851 if (attrGr->annot != NULL)
3852 xmlSchemaFreeAnnot(attrGr->annot);
3853 if (attrGr->attrUses != NULL)
3854 xmlSchemaItemListFree(WXS_LIST_CAST attrGr->attrUses);
3859 * xmlSchemaFreeQNameRef:
3860 * @item: a QName reference structure
3862 * Deallocatea a QName reference structure.
3865 xmlSchemaFreeQNameRef(xmlSchemaQNameRefPtr item)
3871 * xmlSchemaFreeTypeLinkList:
3872 * @alink: a type link
3874 * Deallocate a list of types.
3877 xmlSchemaFreeTypeLinkList(xmlSchemaTypeLinkPtr link)
3879 xmlSchemaTypeLinkPtr next;
3881 while (link != NULL) {
3889 xmlSchemaFreeIDCStateObjList(xmlSchemaIDCStateObjPtr sto)
3891 xmlSchemaIDCStateObjPtr next;
3892 while (sto != NULL) {
3894 if (sto->history != NULL)
3895 xmlFree(sto->history);
3896 if (sto->xpathCtxt != NULL)
3897 xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt);
3905 * @idc: a identity-constraint definition
3907 * Deallocates an identity-constraint definition.
3910 xmlSchemaFreeIDC(xmlSchemaIDCPtr idcDef)
3912 xmlSchemaIDCSelectPtr cur, prev;
3916 if (idcDef->annot != NULL)
3917 xmlSchemaFreeAnnot(idcDef->annot);
3919 if (idcDef->selector != NULL) {
3920 if (idcDef->selector->xpathComp != NULL)
3921 xmlFreePattern((xmlPatternPtr) idcDef->selector->xpathComp);
3922 xmlFree(idcDef->selector);
3925 if (idcDef->fields != NULL) {
3926 cur = idcDef->fields;
3930 if (prev->xpathComp != NULL)
3931 xmlFreePattern((xmlPatternPtr) prev->xpathComp);
3933 } while (cur != NULL);
3939 * xmlSchemaFreeElement:
3940 * @schema: a schema element structure
3942 * Deallocate a Schema Element structure.
3945 xmlSchemaFreeElement(xmlSchemaElementPtr elem)
3949 if (elem->annot != NULL)
3950 xmlSchemaFreeAnnot(elem->annot);
3951 if (elem->contModel != NULL)
3952 xmlRegFreeRegexp(elem->contModel);
3953 if (elem->defVal != NULL)
3954 xmlSchemaFreeValue(elem->defVal);
3959 * xmlSchemaFreeFacet:
3960 * @facet: a schema facet structure
3962 * Deallocate a Schema Facet structure.
3965 xmlSchemaFreeFacet(xmlSchemaFacetPtr facet)
3969 if (facet->val != NULL)
3970 xmlSchemaFreeValue(facet->val);
3971 if (facet->regexp != NULL)
3972 xmlRegFreeRegexp(facet->regexp);
3973 if (facet->annot != NULL)
3974 xmlSchemaFreeAnnot(facet->annot);
3979 * xmlSchemaFreeType:
3980 * @type: a schema type structure
3982 * Deallocate a Schema Type structure.
3985 xmlSchemaFreeType(xmlSchemaTypePtr type)
3989 if (type->annot != NULL)
3990 xmlSchemaFreeAnnot(type->annot);
3991 if (type->facets != NULL) {
3992 xmlSchemaFacetPtr facet, next;
3994 facet = type->facets;
3995 while (facet != NULL) {
3997 xmlSchemaFreeFacet(facet);
4001 if (type->attrUses != NULL)
4002 xmlSchemaItemListFree((xmlSchemaItemListPtr) type->attrUses);
4003 if (type->memberTypes != NULL)
4004 xmlSchemaFreeTypeLinkList(type->memberTypes);
4005 if (type->facetSet != NULL) {
4006 xmlSchemaFacetLinkPtr next, link;
4008 link = type->facetSet;
4013 } while (link != NULL);
4015 if (type->contModel != NULL)
4016 xmlRegFreeRegexp(type->contModel);
4021 * xmlSchemaFreeModelGroupDef:
4022 * @item: a schema model group definition
4024 * Deallocates a schema model group definition.
4027 xmlSchemaFreeModelGroupDef(xmlSchemaModelGroupDefPtr item)
4029 if (item->annot != NULL)
4030 xmlSchemaFreeAnnot(item->annot);
4035 * xmlSchemaFreeModelGroup:
4036 * @item: a schema model group
4038 * Deallocates a schema model group structure.
4041 xmlSchemaFreeModelGroup(xmlSchemaModelGroupPtr item)
4043 if (item->annot != NULL)
4044 xmlSchemaFreeAnnot(item->annot);
4049 xmlSchemaComponentListFree(xmlSchemaItemListPtr list)
4051 if ((list == NULL) || (list->nbItems == 0))
4054 xmlSchemaTreeItemPtr item;
4055 xmlSchemaTreeItemPtr *items = (xmlSchemaTreeItemPtr *) list->items;
4058 for (i = 0; i < list->nbItems; i++) {
4062 switch (item->type) {
4063 case XML_SCHEMA_TYPE_SIMPLE:
4064 case XML_SCHEMA_TYPE_COMPLEX:
4065 xmlSchemaFreeType((xmlSchemaTypePtr) item);
4067 case XML_SCHEMA_TYPE_ATTRIBUTE:
4068 xmlSchemaFreeAttribute((xmlSchemaAttributePtr) item);
4070 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
4071 xmlSchemaFreeAttributeUse((xmlSchemaAttributeUsePtr) item);
4073 case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB:
4074 xmlSchemaFreeAttributeUseProhib(
4075 (xmlSchemaAttributeUseProhibPtr) item);
4077 case XML_SCHEMA_TYPE_ELEMENT:
4078 xmlSchemaFreeElement((xmlSchemaElementPtr) item);
4080 case XML_SCHEMA_TYPE_PARTICLE:
4081 if (item->annot != NULL)
4082 xmlSchemaFreeAnnot(item->annot);
4085 case XML_SCHEMA_TYPE_SEQUENCE:
4086 case XML_SCHEMA_TYPE_CHOICE:
4087 case XML_SCHEMA_TYPE_ALL:
4088 xmlSchemaFreeModelGroup((xmlSchemaModelGroupPtr) item);
4090 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
4091 xmlSchemaFreeAttributeGroup(
4092 (xmlSchemaAttributeGroupPtr) item);
4094 case XML_SCHEMA_TYPE_GROUP:
4095 xmlSchemaFreeModelGroupDef(
4096 (xmlSchemaModelGroupDefPtr) item);
4098 case XML_SCHEMA_TYPE_ANY:
4099 case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
4100 xmlSchemaFreeWildcard((xmlSchemaWildcardPtr) item);
4102 case XML_SCHEMA_TYPE_IDC_KEY:
4103 case XML_SCHEMA_TYPE_IDC_UNIQUE:
4104 case XML_SCHEMA_TYPE_IDC_KEYREF:
4105 xmlSchemaFreeIDC((xmlSchemaIDCPtr) item);
4107 case XML_SCHEMA_TYPE_NOTATION:
4108 xmlSchemaFreeNotation((xmlSchemaNotationPtr) item);
4110 case XML_SCHEMA_EXTRA_QNAMEREF:
4111 xmlSchemaFreeQNameRef((xmlSchemaQNameRefPtr) item);
4114 /* TODO: This should never be hit. */
4115 xmlSchemaPSimpleInternalErr(NULL,
4116 "Internal error: xmlSchemaComponentListFree, "
4117 "unexpected component type '%s'\n",
4118 (const xmlChar *) WXS_ITEM_TYPE_NAME(item));
4129 * @schema: a schema structure
4131 * Deallocate a Schema structure.
4134 xmlSchemaFree(xmlSchemaPtr schema)
4138 /* @volatiles is not used anymore :-/ */
4139 if (schema->volatiles != NULL)
4142 * Note that those slots are not responsible for freeing
4143 * schema components anymore; this will now be done by
4144 * the schema buckets.
4146 if (schema->notaDecl != NULL)
4147 xmlHashFree(schema->notaDecl, NULL);
4148 if (schema->attrDecl != NULL)
4149 xmlHashFree(schema->attrDecl, NULL);
4150 if (schema->attrgrpDecl != NULL)
4151 xmlHashFree(schema->attrgrpDecl, NULL);
4152 if (schema->elemDecl != NULL)
4153 xmlHashFree(schema->elemDecl, NULL);
4154 if (schema->typeDecl != NULL)
4155 xmlHashFree(schema->typeDecl, NULL);
4156 if (schema->groupDecl != NULL)
4157 xmlHashFree(schema->groupDecl, NULL);
4158 if (schema->idcDef != NULL)
4159 xmlHashFree(schema->idcDef, NULL);
4161 if (schema->schemasImports != NULL)
4162 xmlHashFree(schema->schemasImports,
4163 (xmlHashDeallocator) xmlSchemaBucketFree);
4164 if (schema->includes != NULL) {
4165 xmlSchemaItemListPtr list = (xmlSchemaItemListPtr) schema->includes;
4167 for (i = 0; i < list->nbItems; i++) {
4168 xmlSchemaBucketFree((xmlSchemaBucketPtr) list->items[i]);
4170 xmlSchemaItemListFree(list);
4172 if (schema->annot != NULL)
4173 xmlSchemaFreeAnnot(schema->annot);
4174 /* Never free the doc here, since this will be done by the buckets. */
4176 xmlDictFree(schema->dict);
4180 /************************************************************************
4184 ************************************************************************/
4186 #ifdef LIBXML_OUTPUT_ENABLED
4189 xmlSchemaTypeDump(xmlSchemaTypePtr type, FILE * output); /* forward */
4192 * xmlSchemaElementDump:
4194 * @output: the file output
4199 xmlSchemaElementDump(xmlSchemaElementPtr elem, FILE * output,
4200 const xmlChar * name ATTRIBUTE_UNUSED,
4201 const xmlChar * namespace ATTRIBUTE_UNUSED,
4202 const xmlChar * context ATTRIBUTE_UNUSED)
4208 fprintf(output, "Element");
4209 if (elem->flags & XML_SCHEMAS_ELEM_GLOBAL)
4210 fprintf(output, " (global)");
4211 fprintf(output, ": '%s' ", elem->name);
4212 if (namespace != NULL)
4213 fprintf(output, "ns '%s'", namespace);
4214 fprintf(output, "\n");
4216 if ((elem->minOccurs != 1) || (elem->maxOccurs != 1)) {
4217 fprintf(output, " min %d ", elem->minOccurs);
4218 if (elem->maxOccurs >= UNBOUNDED)
4219 fprintf(output, "max: unbounded\n");
4220 else if (elem->maxOccurs != 1)
4221 fprintf(output, "max: %d\n", elem->maxOccurs);
4223 fprintf(output, "\n");
4227 * Misc other properties.
4229 if ((elem->flags & XML_SCHEMAS_ELEM_NILLABLE) ||
4230 (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT) ||
4231 (elem->flags & XML_SCHEMAS_ELEM_FIXED) ||
4232 (elem->flags & XML_SCHEMAS_ELEM_DEFAULT)) {
4233 fprintf(output, " props: ");
4234 if (elem->flags & XML_SCHEMAS_ELEM_FIXED)
4235 fprintf(output, "[fixed] ");
4236 if (elem->flags & XML_SCHEMAS_ELEM_DEFAULT)
4237 fprintf(output, "[default] ");
4238 if (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT)
4239 fprintf(output, "[abstract] ");
4240 if (elem->flags & XML_SCHEMAS_ELEM_NILLABLE)
4241 fprintf(output, "[nillable] ");
4242 fprintf(output, "\n");
4245 * Default/fixed value.
4247 if (elem->value != NULL)
4248 fprintf(output, " value: '%s'\n", elem->value);
4252 if (elem->namedType != NULL) {
4253 fprintf(output, " type: '%s' ", elem->namedType);
4254 if (elem->namedTypeNs != NULL)
4255 fprintf(output, "ns '%s'\n", elem->namedTypeNs);
4257 fprintf(output, "\n");
4258 } else if (elem->subtypes != NULL) {
4262 xmlSchemaTypeDump(elem->subtypes, output);
4265 * Substitution group.
4267 if (elem->substGroup != NULL) {
4268 fprintf(output, " substitutionGroup: '%s' ", elem->substGroup);
4269 if (elem->substGroupNs != NULL)
4270 fprintf(output, "ns '%s'\n", elem->substGroupNs);
4272 fprintf(output, "\n");
4277 * xmlSchemaAnnotDump:
4278 * @output: the file output
4279 * @annot: a annotation
4281 * Dump the annotation
4284 xmlSchemaAnnotDump(FILE * output, xmlSchemaAnnotPtr annot)
4291 content = xmlNodeGetContent(annot->content);
4292 if (content != NULL) {
4293 fprintf(output, " Annot: %s\n", content);
4296 fprintf(output, " Annot: empty\n");
4300 * xmlSchemaContentModelDump:
4301 * @particle: the schema particle
4302 * @output: the file output
4303 * @depth: the depth used for intentation
4305 * Dump a SchemaType structure
4308 xmlSchemaContentModelDump(xmlSchemaParticlePtr particle, FILE * output, int depth)
4310 xmlChar *str = NULL;
4311 xmlSchemaTreeItemPtr term;
4315 if (particle == NULL)
4317 for (i = 0;((i < depth) && (i < 25));i++)
4318 shift[2 * i] = shift[2 * i + 1] = ' ';
4319 shift[2 * i] = shift[2 * i + 1] = 0;
4320 fprintf(output, "%s", shift);
4321 if (particle->children == NULL) {
4322 fprintf(output, "MISSING particle term\n");
4325 term = particle->children;
4327 fprintf(output, "(NULL)");
4329 switch (term->type) {
4330 case XML_SCHEMA_TYPE_ELEMENT:
4331 fprintf(output, "ELEM '%s'", xmlSchemaFormatQName(&str,
4332 ((xmlSchemaElementPtr)term)->targetNamespace,
4333 ((xmlSchemaElementPtr)term)->name));
4336 case XML_SCHEMA_TYPE_SEQUENCE:
4337 fprintf(output, "SEQUENCE");
4339 case XML_SCHEMA_TYPE_CHOICE:
4340 fprintf(output, "CHOICE");
4342 case XML_SCHEMA_TYPE_ALL:
4343 fprintf(output, "ALL");
4345 case XML_SCHEMA_TYPE_ANY:
4346 fprintf(output, "ANY");
4349 fprintf(output, "UNKNOWN\n");
4353 if (particle->minOccurs != 1)
4354 fprintf(output, " min: %d", particle->minOccurs);
4355 if (particle->maxOccurs >= UNBOUNDED)
4356 fprintf(output, " max: unbounded");
4357 else if (particle->maxOccurs != 1)
4358 fprintf(output, " max: %d", particle->maxOccurs);
4359 fprintf(output, "\n");
4361 ((term->type == XML_SCHEMA_TYPE_SEQUENCE) ||
4362 (term->type == XML_SCHEMA_TYPE_CHOICE) ||
4363 (term->type == XML_SCHEMA_TYPE_ALL)) &&
4364 (term->children != NULL)) {
4365 xmlSchemaContentModelDump((xmlSchemaParticlePtr) term->children,
4368 if (particle->next != NULL)
4369 xmlSchemaContentModelDump((xmlSchemaParticlePtr) particle->next,
4374 * xmlSchemaAttrUsesDump:
4375 * @uses: attribute uses list
4376 * @output: the file output
4378 * Dumps a list of attribute use components.
4381 xmlSchemaAttrUsesDump(xmlSchemaItemListPtr uses, FILE * output)
4383 xmlSchemaAttributeUsePtr use;
4384 xmlSchemaAttributeUseProhibPtr prohib;
4385 xmlSchemaQNameRefPtr ref;
4386 const xmlChar *name, *tns;
4387 xmlChar *str = NULL;
4390 if ((uses == NULL) || (uses->nbItems == 0))
4393 fprintf(output, " attributes:\n");
4394 for (i = 0; i < uses->nbItems; i++) {
4395 use = uses->items[i];
4396 if (use->type == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB) {
4397 fprintf(output, " [prohibition] ");
4398 prohib = (xmlSchemaAttributeUseProhibPtr) use;
4399 name = prohib->name;
4400 tns = prohib->targetNamespace;
4401 } else if (use->type == XML_SCHEMA_EXTRA_QNAMEREF) {
4402 fprintf(output, " [reference] ");
4403 ref = (xmlSchemaQNameRefPtr) use;
4405 tns = ref->targetNamespace;
4407 fprintf(output, " [use] ");
4408 name = WXS_ATTRUSE_DECL_NAME(use);
4409 tns = WXS_ATTRUSE_DECL_TNS(use);
4411 fprintf(output, "'%s'\n",
4412 (const char *) xmlSchemaFormatQName(&str, tns, name));
4418 * xmlSchemaTypeDump:
4419 * @output: the file output
4420 * @type: a type structure
4422 * Dump a SchemaType structure
4425 xmlSchemaTypeDump(xmlSchemaTypePtr type, FILE * output)
4428 fprintf(output, "Type: NULL\n");
4431 fprintf(output, "Type: ");
4432 if (type->name != NULL)
4433 fprintf(output, "'%s' ", type->name);
4435 fprintf(output, "(no name) ");
4436 if (type->targetNamespace != NULL)
4437 fprintf(output, "ns '%s' ", type->targetNamespace);
4438 switch (type->type) {
4439 case XML_SCHEMA_TYPE_BASIC:
4440 fprintf(output, "[basic] ");
4442 case XML_SCHEMA_TYPE_SIMPLE:
4443 fprintf(output, "[simple] ");
4445 case XML_SCHEMA_TYPE_COMPLEX:
4446 fprintf(output, "[complex] ");
4448 case XML_SCHEMA_TYPE_SEQUENCE:
4449 fprintf(output, "[sequence] ");
4451 case XML_SCHEMA_TYPE_CHOICE:
4452 fprintf(output, "[choice] ");
4454 case XML_SCHEMA_TYPE_ALL:
4455 fprintf(output, "[all] ");
4457 case XML_SCHEMA_TYPE_UR:
4458 fprintf(output, "[ur] ");
4460 case XML_SCHEMA_TYPE_RESTRICTION:
4461 fprintf(output, "[restriction] ");
4463 case XML_SCHEMA_TYPE_EXTENSION:
4464 fprintf(output, "[extension] ");
4467 fprintf(output, "[unknown type %d] ", type->type);
4470 fprintf(output, "content: ");
4471 switch (type->contentType) {
4472 case XML_SCHEMA_CONTENT_UNKNOWN:
4473 fprintf(output, "[unknown] ");
4475 case XML_SCHEMA_CONTENT_EMPTY:
4476 fprintf(output, "[empty] ");
4478 case XML_SCHEMA_CONTENT_ELEMENTS:
4479 fprintf(output, "[element] ");
4481 case XML_SCHEMA_CONTENT_MIXED:
4482 fprintf(output, "[mixed] ");
4484 case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS:
4487 case XML_SCHEMA_CONTENT_BASIC:
4488 fprintf(output, "[basic] ");
4490 case XML_SCHEMA_CONTENT_SIMPLE:
4491 fprintf(output, "[simple] ");
4493 case XML_SCHEMA_CONTENT_ANY:
4494 fprintf(output, "[any] ");
4497 fprintf(output, "\n");
4498 if (type->base != NULL) {
4499 fprintf(output, " base type: '%s'", type->base);
4500 if (type->baseNs != NULL)
4501 fprintf(output, " ns '%s'\n", type->baseNs);
4503 fprintf(output, "\n");
4505 if (type->attrUses != NULL)
4506 xmlSchemaAttrUsesDump(type->attrUses, output);
4507 if (type->annot != NULL)
4508 xmlSchemaAnnotDump(output, type->annot);
4509 #ifdef DUMP_CONTENT_MODEL
4510 if ((type->type == XML_SCHEMA_TYPE_COMPLEX) &&
4511 (type->subtypes != NULL)) {
4512 xmlSchemaContentModelDump((xmlSchemaParticlePtr) type->subtypes,
4520 * @output: the file output
4521 * @schema: a schema structure
4523 * Dump a Schema structure.
4526 xmlSchemaDump(FILE * output, xmlSchemaPtr schema)
4530 if (schema == NULL) {
4531 fprintf(output, "Schemas: NULL\n");
4534 fprintf(output, "Schemas: ");
4535 if (schema->name != NULL)
4536 fprintf(output, "%s, ", schema->name);
4538 fprintf(output, "no name, ");
4539 if (schema->targetNamespace != NULL)
4540 fprintf(output, "%s", (const char *) schema->targetNamespace);
4542 fprintf(output, "no target namespace");
4543 fprintf(output, "\n");
4544 if (schema->annot != NULL)
4545 xmlSchemaAnnotDump(output, schema->annot);
4546 xmlHashScan(schema->typeDecl, (xmlHashScanner) xmlSchemaTypeDump,
4548 xmlHashScanFull(schema->elemDecl,
4549 (xmlHashScannerFull) xmlSchemaElementDump, output);
4552 #ifdef DEBUG_IDC_NODE_TABLE
4554 * xmlSchemaDebugDumpIDCTable:
4555 * @vctxt: the WXS validation context
4557 * Displays the current IDC table for debug purposes.
4560 xmlSchemaDebugDumpIDCTable(FILE * output,
4561 const xmlChar *namespaceName,
4562 const xmlChar *localName,
4563 xmlSchemaPSVIIDCBindingPtr bind)
4565 xmlChar *str = NULL;
4566 const xmlChar *value;
4567 xmlSchemaPSVIIDCNodePtr tab;
4568 xmlSchemaPSVIIDCKeyPtr key;
4571 fprintf(output, "IDC: TABLES on '%s'\n",
4572 xmlSchemaFormatQName(&str, namespaceName, localName));
4578 fprintf(output, "IDC: BINDING '%s' (%d)\n",
4579 xmlSchemaGetComponentQName(&str,
4580 bind->definition), bind->nbNodes);
4582 for (i = 0; i < bind->nbNodes; i++) {
4583 tab = bind->nodeTable[i];
4584 fprintf(output, " ( ");
4585 for (j = 0; j < bind->definition->nbFields; j++) {
4587 if ((key != NULL) && (key->val != NULL)) {
4588 res = xmlSchemaGetCanonValue(key->val, &value);
4590 fprintf(output, "'%s' ", value);
4592 fprintf(output, "CANON-VALUE-FAILED ");
4594 FREE_AND_NULL(value)
4595 } else if (key != NULL)
4596 fprintf(output, "(no val), ");
4598 fprintf(output, "(key missing), ");
4600 fprintf(output, ")\n");
4602 if (bind->dupls && bind->dupls->nbItems) {
4603 fprintf(output, "IDC: dupls (%d):\n", bind->dupls->nbItems);
4604 for (i = 0; i < bind->dupls->nbItems; i++) {
4605 tab = bind->dupls->items[i];
4606 fprintf(output, " ( ");
4607 for (j = 0; j < bind->definition->nbFields; j++) {
4609 if ((key != NULL) && (key->val != NULL)) {
4610 res = xmlSchemaGetCanonValue(key->val, &value);
4612 fprintf(output, "'%s' ", value);
4614 fprintf(output, "CANON-VALUE-FAILED ");
4616 FREE_AND_NULL(value)
4617 } else if (key != NULL)
4618 fprintf(output, "(no val), ");
4620 fprintf(output, "(key missing), ");
4622 fprintf(output, ")\n");
4626 } while (bind != NULL);
4628 #endif /* DEBUG_IDC */
4629 #endif /* LIBXML_OUTPUT_ENABLED */
4631 /************************************************************************
4635 ************************************************************************/
4638 * xmlSchemaGetPropNode:
4639 * @node: the element node
4640 * @name: the name of the attribute
4642 * Seeks an attribute with a name of @name in
4645 * Returns the attribute or NULL if not present.
4648 xmlSchemaGetPropNode(xmlNodePtr node, const char *name)
4652 if ((node == NULL) || (name == NULL))
4654 prop = node->properties;
4655 while (prop != NULL) {
4656 if ((prop->ns == NULL) && xmlStrEqual(prop->name, BAD_CAST name))
4664 * xmlSchemaGetPropNodeNs:
4665 * @node: the element node
4667 * @name: the name of the attribute
4669 * Seeks an attribute with a local name of @name and
4670 * a namespace URI of @uri.
4672 * Returns the attribute or NULL if not present.
4675 xmlSchemaGetPropNodeNs(xmlNodePtr node, const char *uri, const char *name)
4679 if ((node == NULL) || (name == NULL))
4681 prop = node->properties;
4682 while (prop != NULL) {
4683 if ((prop->ns != NULL) &&
4684 xmlStrEqual(prop->name, BAD_CAST name) &&
4685 xmlStrEqual(prop->ns->href, BAD_CAST uri))
4692 static const xmlChar *
4693 xmlSchemaGetNodeContent(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node)
4698 val = xmlNodeGetContent(node);
4700 val = xmlStrdup((xmlChar *)"");
4701 ret = xmlDictLookup(ctxt->dict, val, -1);
4706 static const xmlChar *
4707 xmlSchemaGetNodeContentNoDict(xmlNodePtr node)
4709 return((const xmlChar*) xmlNodeGetContent(node));
4714 * @ctxt: the parser context
4716 * @name: the property name
4718 * Read a attribute value and internalize the string
4720 * Returns the string or NULL if not present.
4722 static const xmlChar *
4723 xmlSchemaGetProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
4729 val = xmlGetNoNsProp(node, BAD_CAST name);
4732 ret = xmlDictLookup(ctxt->dict, val, -1);
4737 /************************************************************************
4739 * Parsing functions *
4741 ************************************************************************/
4743 #define WXS_FIND_GLOBAL_ITEM(slot) \
4744 if (xmlStrEqual(nsName, schema->targetNamespace)) { \
4745 ret = xmlHashLookup(schema->slot, name); \
4746 if (ret != NULL) goto exit; \
4748 if (xmlHashSize(schema->schemasImports) > 1) { \
4749 xmlSchemaImportPtr import; \
4750 if (nsName == NULL) \
4751 import = xmlHashLookup(schema->schemasImports, \
4752 XML_SCHEMAS_NO_NAMESPACE); \
4754 import = xmlHashLookup(schema->schemasImports, nsName); \
4755 if (import == NULL) \
4757 ret = xmlHashLookup(import->schema->slot, name); \
4762 * @schema: the schema context
4763 * @name: the element name
4764 * @ns: the element namespace
4766 * Lookup a global element declaration in the schema.
4768 * Returns the element declaration or NULL if not found.
4770 static xmlSchemaElementPtr
4771 xmlSchemaGetElem(xmlSchemaPtr schema, const xmlChar * name,
4772 const xmlChar * nsName)
4774 xmlSchemaElementPtr ret = NULL;
4776 if ((name == NULL) || (schema == NULL))
4778 if (schema != NULL) {
4779 WXS_FIND_GLOBAL_ITEM(elemDecl)
4785 fprintf(stderr, "Unable to lookup element decl. %s", name);
4787 fprintf(stderr, "Unable to lookup element decl. %s:%s", name,
4796 * @schema: the main schema
4797 * @name: the type's name
4798 * nsName: the type's namespace
4800 * Lookup a type in the schemas or the predefined types
4802 * Returns the group definition or NULL if not found.
4804 static xmlSchemaTypePtr
4805 xmlSchemaGetType(xmlSchemaPtr schema, const xmlChar * name,
4806 const xmlChar * nsName)
4808 xmlSchemaTypePtr ret = NULL;
4812 /* First try the built-in types. */
4813 if ((nsName != NULL) && xmlStrEqual(nsName, xmlSchemaNs)) {
4814 ret = xmlSchemaGetPredefinedType(name, nsName);
4818 * Note that we try the parsed schemas as well here
4819 * since one might have parsed the S4S, which contain more
4820 * than the built-in types.
4821 * TODO: Can we optimize this?
4824 if (schema != NULL) {
4825 WXS_FIND_GLOBAL_ITEM(typeDecl)
4832 fprintf(stderr, "Unable to lookup type %s", name);
4834 fprintf(stderr, "Unable to lookup type %s:%s", name,
4842 * xmlSchemaGetAttributeDecl:
4843 * @schema: the context of the schema
4844 * @name: the name of the attribute
4845 * @ns: the target namespace of the attribute
4847 * Lookup a an attribute in the schema or imported schemas
4849 * Returns the attribute declaration or NULL if not found.
4851 static xmlSchemaAttributePtr
4852 xmlSchemaGetAttributeDecl(xmlSchemaPtr schema, const xmlChar * name,
4853 const xmlChar * nsName)
4855 xmlSchemaAttributePtr ret = NULL;
4857 if ((name == NULL) || (schema == NULL))
4859 if (schema != NULL) {
4860 WXS_FIND_GLOBAL_ITEM(attrDecl)
4866 fprintf(stderr, "Unable to lookup attribute %s", name);
4868 fprintf(stderr, "Unable to lookup attribute %s:%s", name,
4876 * xmlSchemaGetAttributeGroup:
4877 * @schema: the context of the schema
4878 * @name: the name of the attribute group
4879 * @ns: the target namespace of the attribute group
4881 * Lookup a an attribute group in the schema or imported schemas
4883 * Returns the attribute group definition or NULL if not found.
4885 static xmlSchemaAttributeGroupPtr
4886 xmlSchemaGetAttributeGroup(xmlSchemaPtr schema, const xmlChar * name,
4887 const xmlChar * nsName)
4889 xmlSchemaAttributeGroupPtr ret = NULL;
4891 if ((name == NULL) || (schema == NULL))
4893 if (schema != NULL) {
4894 WXS_FIND_GLOBAL_ITEM(attrgrpDecl)
4898 if ((ret != NULL) && (ret->redef != NULL)) {
4899 * Return the last redefinition. *
4906 fprintf(stderr, "Unable to lookup attribute group %s", name);
4908 fprintf(stderr, "Unable to lookup attribute group %s:%s", name,
4916 * xmlSchemaGetGroup:
4917 * @schema: the context of the schema
4918 * @name: the name of the group
4919 * @ns: the target namespace of the group
4921 * Lookup a group in the schema or imported schemas
4923 * Returns the group definition or NULL if not found.
4925 static xmlSchemaModelGroupDefPtr
4926 xmlSchemaGetGroup(xmlSchemaPtr schema, const xmlChar * name,
4927 const xmlChar * nsName)
4929 xmlSchemaModelGroupDefPtr ret = NULL;
4931 if ((name == NULL) || (schema == NULL))
4933 if (schema != NULL) {
4934 WXS_FIND_GLOBAL_ITEM(groupDecl)
4941 fprintf(stderr, "Unable to lookup group %s", name);
4943 fprintf(stderr, "Unable to lookup group %s:%s", name,
4950 static xmlSchemaNotationPtr
4951 xmlSchemaGetNotation(xmlSchemaPtr schema,
4952 const xmlChar *name,
4953 const xmlChar *nsName)
4955 xmlSchemaNotationPtr ret = NULL;
4957 if ((name == NULL) || (schema == NULL))
4959 if (schema != NULL) {
4960 WXS_FIND_GLOBAL_ITEM(notaDecl)
4966 static xmlSchemaIDCPtr
4967 xmlSchemaGetIDC(xmlSchemaPtr schema,
4968 const xmlChar *name,
4969 const xmlChar *nsName)
4971 xmlSchemaIDCPtr ret = NULL;
4973 if ((name == NULL) || (schema == NULL))
4975 if (schema != NULL) {
4976 WXS_FIND_GLOBAL_ITEM(idcDef)
4983 * xmlSchemaGetNamedComponent:
4984 * @schema: the schema
4985 * @name: the name of the group
4986 * @ns: the target namespace of the group
4988 * Lookup a group in the schema or imported schemas
4990 * Returns the group definition or NULL if not found.
4992 static xmlSchemaBasicItemPtr
4993 xmlSchemaGetNamedComponent(xmlSchemaPtr schema,
4994 xmlSchemaTypeType itemType,
4995 const xmlChar *name,
4996 const xmlChar *targetNs)
4999 case XML_SCHEMA_TYPE_GROUP:
5000 return ((xmlSchemaBasicItemPtr) xmlSchemaGetGroup(schema,
5002 case XML_SCHEMA_TYPE_ELEMENT:
5003 return ((xmlSchemaBasicItemPtr) xmlSchemaGetElem(schema,
5011 /************************************************************************
5013 * Parsing functions *
5015 ************************************************************************/
5017 #define IS_BLANK_NODE(n) \
5018 (((n)->type == XML_TEXT_NODE) && (xmlSchemaIsBlank((n)->content, -1)))
5023 * @len: the length of the string or -1
5025 * Check if a string is ignorable
5027 * Returns 1 if the string is NULL or made of blanks chars, 0 otherwise
5030 xmlSchemaIsBlank(xmlChar * str, int len)
5036 if (!(IS_BLANK_CH(*str)))
5040 } else while ((*str != 0) && (len != 0)) {
5041 if (!(IS_BLANK_CH(*str)))
5050 #define WXS_COMP_NAME(c, t) ((t) (c))->name
5051 #define WXS_COMP_TNS(c, t) ((t) (c))->targetNamespace
5053 * xmlSchemaFindRedefCompInGraph:
5054 * ATTENTION TODO: This uses pointer comp. for strings.
5056 static xmlSchemaBasicItemPtr
5057 xmlSchemaFindRedefCompInGraph(xmlSchemaBucketPtr bucket,
5058 xmlSchemaTypeType type,
5059 const xmlChar *name,
5060 const xmlChar *nsName)
5062 xmlSchemaBasicItemPtr ret;
5065 if ((bucket == NULL) || (name == NULL))
5067 if ((bucket->globals == NULL) ||
5068 (bucket->globals->nbItems == 0))
5071 * Search in global components.
5073 for (i = 0; i < bucket->globals->nbItems; i++) {
5074 ret = bucket->globals->items[i];
5075 if (ret->type == type) {
5077 case XML_SCHEMA_TYPE_COMPLEX:
5078 case XML_SCHEMA_TYPE_SIMPLE:
5079 if ((WXS_COMP_NAME(ret, xmlSchemaTypePtr) == name) &&
5080 (WXS_COMP_TNS(ret, xmlSchemaTypePtr) ==
5086 case XML_SCHEMA_TYPE_GROUP:
5087 if ((WXS_COMP_NAME(ret,
5088 xmlSchemaModelGroupDefPtr) == name) &&
5090 xmlSchemaModelGroupDefPtr) == nsName))
5095 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
5096 if ((WXS_COMP_NAME(ret,
5097 xmlSchemaAttributeGroupPtr) == name) &&
5099 xmlSchemaAttributeGroupPtr) == nsName))
5105 /* Should not be hit. */
5112 * Process imported/included schemas.
5114 if (bucket->relations != NULL) {
5115 xmlSchemaSchemaRelationPtr rel = bucket->relations;
5118 * TODO: Marking the bucket will not avoid multiple searches
5119 * in the same schema, but avoids at least circularity.
5121 bucket->flags |= XML_SCHEMA_BUCKET_MARKED;
5123 if ((rel->bucket != NULL) &&
5124 ((rel->bucket->flags & XML_SCHEMA_BUCKET_MARKED) == 0)) {
5125 ret = xmlSchemaFindRedefCompInGraph(rel->bucket,
5126 type, name, nsName);
5131 } while (rel != NULL);
5132 bucket->flags ^= XML_SCHEMA_BUCKET_MARKED;
5138 * xmlSchemaAddNotation:
5139 * @ctxt: a schema parser context
5140 * @schema: the schema being built
5141 * @name: the item name
5143 * Add an XML schema annotation declaration
5144 * *WARNING* this interface is highly subject to change
5146 * Returns the new struture or NULL in case of error
5148 static xmlSchemaNotationPtr
5149 xmlSchemaAddNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
5150 const xmlChar *name, const xmlChar *nsName,
5151 xmlNodePtr node ATTRIBUTE_UNUSED)
5153 xmlSchemaNotationPtr ret = NULL;
5155 if ((ctxt == NULL) || (schema == NULL) || (name == NULL))
5158 ret = (xmlSchemaNotationPtr) xmlMalloc(sizeof(xmlSchemaNotation));
5160 xmlSchemaPErrMemory(ctxt, "add annotation", NULL);
5163 memset(ret, 0, sizeof(xmlSchemaNotation));
5164 ret->type = XML_SCHEMA_TYPE_NOTATION;
5166 ret->targetNamespace = nsName;
5167 /* TODO: do we need the node to be set?
5168 * ret->node = node;*/
5169 WXS_ADD_GLOBAL(ctxt, ret);
5174 * xmlSchemaAddAttribute:
5175 * @ctxt: a schema parser context
5176 * @schema: the schema being built
5177 * @name: the item name
5178 * @namespace: the namespace
5180 * Add an XML schema Attrribute declaration
5181 * *WARNING* this interface is highly subject to change
5183 * Returns the new struture or NULL in case of error
5185 static xmlSchemaAttributePtr
5186 xmlSchemaAddAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
5187 const xmlChar * name, const xmlChar * nsName,
5188 xmlNodePtr node, int topLevel)
5190 xmlSchemaAttributePtr ret = NULL;
5192 if ((ctxt == NULL) || (schema == NULL))
5195 ret = (xmlSchemaAttributePtr) xmlMalloc(sizeof(xmlSchemaAttribute));
5197 xmlSchemaPErrMemory(ctxt, "allocating attribute", NULL);
5200 memset(ret, 0, sizeof(xmlSchemaAttribute));
5201 ret->type = XML_SCHEMA_TYPE_ATTRIBUTE;
5204 ret->targetNamespace = nsName;
5207 WXS_ADD_GLOBAL(ctxt, ret);
5209 WXS_ADD_LOCAL(ctxt, ret);
5210 WXS_ADD_PENDING(ctxt, ret);
5215 * xmlSchemaAddAttributeUse:
5216 * @ctxt: a schema parser context
5217 * @schema: the schema being built
5218 * @name: the item name
5219 * @namespace: the namespace
5221 * Add an XML schema Attrribute declaration
5222 * *WARNING* this interface is highly subject to change
5224 * Returns the new struture or NULL in case of error
5226 static xmlSchemaAttributeUsePtr
5227 xmlSchemaAddAttributeUse(xmlSchemaParserCtxtPtr pctxt,
5230 xmlSchemaAttributeUsePtr ret = NULL;
5235 ret = (xmlSchemaAttributeUsePtr) xmlMalloc(sizeof(xmlSchemaAttributeUse));
5237 xmlSchemaPErrMemory(pctxt, "allocating attribute", NULL);
5240 memset(ret, 0, sizeof(xmlSchemaAttributeUse));
5241 ret->type = XML_SCHEMA_TYPE_ATTRIBUTE_USE;
5244 WXS_ADD_LOCAL(pctxt, ret);
5249 * xmlSchemaAddRedef:
5251 * Adds a redefinition information. This is used at a later stage to:
5252 * resolve references to the redefined components and to check constraints.
5254 static xmlSchemaRedefPtr
5255 xmlSchemaAddRedef(xmlSchemaParserCtxtPtr pctxt,
5256 xmlSchemaBucketPtr targetBucket,
5258 const xmlChar *refName,
5259 const xmlChar *refTargetNs)
5261 xmlSchemaRedefPtr ret;
5263 ret = (xmlSchemaRedefPtr)
5264 xmlMalloc(sizeof(xmlSchemaRedef));
5266 xmlSchemaPErrMemory(pctxt,
5267 "allocating redefinition info", NULL);
5270 memset(ret, 0, sizeof(xmlSchemaRedef));
5272 ret->targetBucket = targetBucket;
5273 ret->refName = refName;
5274 ret->refTargetNs = refTargetNs;
5275 if (WXS_CONSTRUCTOR(pctxt)->redefs == NULL)
5276 WXS_CONSTRUCTOR(pctxt)->redefs = ret;
5278 WXS_CONSTRUCTOR(pctxt)->lastRedef->next = ret;
5279 WXS_CONSTRUCTOR(pctxt)->lastRedef = ret;
5285 * xmlSchemaAddAttributeGroupDefinition:
5286 * @ctxt: a schema parser context
5287 * @schema: the schema being built
5288 * @name: the item name
5289 * @nsName: the target namespace
5290 * @node: the corresponding node
5292 * Add an XML schema Attrribute Group definition.
5294 * Returns the new struture or NULL in case of error
5296 static xmlSchemaAttributeGroupPtr
5297 xmlSchemaAddAttributeGroupDefinition(xmlSchemaParserCtxtPtr pctxt,
5298 xmlSchemaPtr schema ATTRIBUTE_UNUSED,
5299 const xmlChar *name,
5300 const xmlChar *nsName,
5303 xmlSchemaAttributeGroupPtr ret = NULL;
5305 if ((pctxt == NULL) || (name == NULL))
5308 ret = (xmlSchemaAttributeGroupPtr)
5309 xmlMalloc(sizeof(xmlSchemaAttributeGroup));
5311 xmlSchemaPErrMemory(pctxt, "allocating attribute group", NULL);
5314 memset(ret, 0, sizeof(xmlSchemaAttributeGroup));
5315 ret->type = XML_SCHEMA_TYPE_ATTRIBUTEGROUP;
5317 ret->targetNamespace = nsName;
5320 /* TODO: Remove the flag. */
5321 ret->flags |= XML_SCHEMAS_ATTRGROUP_GLOBAL;
5322 if (pctxt->isRedefine) {
5323 pctxt->redef = xmlSchemaAddRedef(pctxt, pctxt->redefined,
5325 if (pctxt->redef == NULL) {
5329 pctxt->redefCounter = 0;
5331 WXS_ADD_GLOBAL(pctxt, ret);
5332 WXS_ADD_PENDING(pctxt, ret);
5337 * xmlSchemaAddElement:
5338 * @ctxt: a schema parser context
5339 * @schema: the schema being built
5340 * @name: the type name
5341 * @namespace: the type namespace
5343 * Add an XML schema Element declaration
5344 * *WARNING* this interface is highly subject to change
5346 * Returns the new struture or NULL in case of error
5348 static xmlSchemaElementPtr
5349 xmlSchemaAddElement(xmlSchemaParserCtxtPtr ctxt,
5350 const xmlChar * name, const xmlChar * nsName,
5351 xmlNodePtr node, int topLevel)
5353 xmlSchemaElementPtr ret = NULL;
5355 if ((ctxt == NULL) || (name == NULL))
5358 ret = (xmlSchemaElementPtr) xmlMalloc(sizeof(xmlSchemaElement));
5360 xmlSchemaPErrMemory(ctxt, "allocating element", NULL);
5363 memset(ret, 0, sizeof(xmlSchemaElement));
5364 ret->type = XML_SCHEMA_TYPE_ELEMENT;
5366 ret->targetNamespace = nsName;
5370 WXS_ADD_GLOBAL(ctxt, ret);
5372 WXS_ADD_LOCAL(ctxt, ret);
5373 WXS_ADD_PENDING(ctxt, ret);
5379 * @ctxt: a schema parser context
5380 * @schema: the schema being built
5381 * @name: the item name
5382 * @namespace: the namespace
5384 * Add an XML schema item
5385 * *WARNING* this interface is highly subject to change
5387 * Returns the new struture or NULL in case of error
5389 static xmlSchemaTypePtr
5390 xmlSchemaAddType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
5391 xmlSchemaTypeType type,
5392 const xmlChar * name, const xmlChar * nsName,
5393 xmlNodePtr node, int topLevel)
5395 xmlSchemaTypePtr ret = NULL;
5397 if ((ctxt == NULL) || (schema == NULL))
5400 ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType));
5402 xmlSchemaPErrMemory(ctxt, "allocating type", NULL);
5405 memset(ret, 0, sizeof(xmlSchemaType));
5408 ret->targetNamespace = nsName;
5411 if (ctxt->isRedefine) {
5412 ctxt->redef = xmlSchemaAddRedef(ctxt, ctxt->redefined,
5414 if (ctxt->redef == NULL) {
5418 ctxt->redefCounter = 0;
5420 WXS_ADD_GLOBAL(ctxt, ret);
5422 WXS_ADD_LOCAL(ctxt, ret);
5423 WXS_ADD_PENDING(ctxt, ret);
5427 static xmlSchemaQNameRefPtr
5428 xmlSchemaNewQNameRef(xmlSchemaParserCtxtPtr pctxt,
5429 xmlSchemaTypeType refType,
5430 const xmlChar *refName,
5431 const xmlChar *refNs)
5433 xmlSchemaQNameRefPtr ret;
5435 ret = (xmlSchemaQNameRefPtr)
5436 xmlMalloc(sizeof(xmlSchemaQNameRef));
5438 xmlSchemaPErrMemory(pctxt,
5439 "allocating QName reference item", NULL);
5443 ret->type = XML_SCHEMA_EXTRA_QNAMEREF;
5444 ret->name = refName;
5445 ret->targetNamespace = refNs;
5447 ret->itemType = refType;
5449 * Store the reference item in the schema.
5451 WXS_ADD_LOCAL(pctxt, ret);
5455 static xmlSchemaAttributeUseProhibPtr
5456 xmlSchemaAddAttributeUseProhib(xmlSchemaParserCtxtPtr pctxt)
5458 xmlSchemaAttributeUseProhibPtr ret;
5460 ret = (xmlSchemaAttributeUseProhibPtr)
5461 xmlMalloc(sizeof(xmlSchemaAttributeUseProhib));
5463 xmlSchemaPErrMemory(pctxt,
5464 "allocating attribute use prohibition", NULL);
5467 memset(ret, 0, sizeof(xmlSchemaAttributeUseProhib));
5468 ret->type = XML_SCHEMA_EXTRA_ATTR_USE_PROHIB;
5469 WXS_ADD_LOCAL(pctxt, ret);
5475 * xmlSchemaAddModelGroup:
5476 * @ctxt: a schema parser context
5477 * @schema: the schema being built
5478 * @type: the "compositor" type of the model group
5479 * @node: the node in the schema doc
5481 * Adds a schema model group
5482 * *WARNING* this interface is highly subject to change
5484 * Returns the new struture or NULL in case of error
5486 static xmlSchemaModelGroupPtr
5487 xmlSchemaAddModelGroup(xmlSchemaParserCtxtPtr ctxt,
5488 xmlSchemaPtr schema,
5489 xmlSchemaTypeType type,
5492 xmlSchemaModelGroupPtr ret = NULL;
5494 if ((ctxt == NULL) || (schema == NULL))
5497 ret = (xmlSchemaModelGroupPtr)
5498 xmlMalloc(sizeof(xmlSchemaModelGroup));
5500 xmlSchemaPErrMemory(ctxt, "allocating model group component",
5504 memset(ret, 0, sizeof(xmlSchemaModelGroup));
5507 WXS_ADD_LOCAL(ctxt, ret);
5508 if ((type == XML_SCHEMA_TYPE_SEQUENCE) ||
5509 (type == XML_SCHEMA_TYPE_CHOICE))
5510 WXS_ADD_PENDING(ctxt, ret);
5516 * xmlSchemaAddParticle:
5517 * @ctxt: a schema parser context
5518 * @schema: the schema being built
5519 * @node: the corresponding node in the schema doc
5520 * @min: the minOccurs
5521 * @max: the maxOccurs
5523 * Adds an XML schema particle component.
5524 * *WARNING* this interface is highly subject to change
5526 * Returns the new struture or NULL in case of error
5528 static xmlSchemaParticlePtr
5529 xmlSchemaAddParticle(xmlSchemaParserCtxtPtr ctxt,
5530 xmlNodePtr node, int min, int max)
5532 xmlSchemaParticlePtr ret = NULL;
5537 fprintf(stderr, "Adding particle component\n");
5539 ret = (xmlSchemaParticlePtr)
5540 xmlMalloc(sizeof(xmlSchemaParticle));
5542 xmlSchemaPErrMemory(ctxt, "allocating particle component",
5546 ret->type = XML_SCHEMA_TYPE_PARTICLE;
5549 ret->minOccurs = min;
5550 ret->maxOccurs = max;
5552 ret->children = NULL;
5554 WXS_ADD_LOCAL(ctxt, ret);
5556 * Note that addition to pending components will be done locally
5557 * to the specific parsing function, since the most particles
5558 * need not to be fixed up (i.e. the reference to be resolved).
5559 * REMOVED: WXS_ADD_PENDING(ctxt, ret);
5565 * xmlSchemaAddModelGroupDefinition:
5566 * @ctxt: a schema validation context
5567 * @schema: the schema being built
5568 * @name: the group name
5570 * Add an XML schema Group definition
5572 * Returns the new struture or NULL in case of error
5574 static xmlSchemaModelGroupDefPtr
5575 xmlSchemaAddModelGroupDefinition(xmlSchemaParserCtxtPtr ctxt,
5576 xmlSchemaPtr schema,
5577 const xmlChar *name,
5578 const xmlChar *nsName,
5581 xmlSchemaModelGroupDefPtr ret = NULL;
5583 if ((ctxt == NULL) || (schema == NULL) || (name == NULL))
5586 ret = (xmlSchemaModelGroupDefPtr)
5587 xmlMalloc(sizeof(xmlSchemaModelGroupDef));
5589 xmlSchemaPErrMemory(ctxt, "adding group", NULL);
5592 memset(ret, 0, sizeof(xmlSchemaModelGroupDef));
5594 ret->type = XML_SCHEMA_TYPE_GROUP;
5596 ret->targetNamespace = nsName;
5598 if (ctxt->isRedefine) {
5599 ctxt->redef = xmlSchemaAddRedef(ctxt, ctxt->redefined,
5601 if (ctxt->redef == NULL) {
5605 ctxt->redefCounter = 0;
5607 WXS_ADD_GLOBAL(ctxt, ret);
5608 WXS_ADD_PENDING(ctxt, ret);
5613 * xmlSchemaNewWildcardNs:
5614 * @ctxt: a schema validation context
5616 * Creates a new wildcard namespace constraint.
5618 * Returns the new struture or NULL in case of error
5620 static xmlSchemaWildcardNsPtr
5621 xmlSchemaNewWildcardNsConstraint(xmlSchemaParserCtxtPtr ctxt)
5623 xmlSchemaWildcardNsPtr ret;
5625 ret = (xmlSchemaWildcardNsPtr)
5626 xmlMalloc(sizeof(xmlSchemaWildcardNs));
5628 xmlSchemaPErrMemory(ctxt, "creating wildcard namespace constraint", NULL);
5636 static xmlSchemaIDCPtr
5637 xmlSchemaAddIDC(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
5638 const xmlChar *name, const xmlChar *nsName,
5639 int category, xmlNodePtr node)
5641 xmlSchemaIDCPtr ret = NULL;
5643 if ((ctxt == NULL) || (schema == NULL) || (name == NULL))
5646 ret = (xmlSchemaIDCPtr) xmlMalloc(sizeof(xmlSchemaIDC));
5648 xmlSchemaPErrMemory(ctxt,
5649 "allocating an identity-constraint definition", NULL);
5652 memset(ret, 0, sizeof(xmlSchemaIDC));
5653 /* The target namespace of the parent element declaration. */
5654 ret->targetNamespace = nsName;
5656 ret->type = category;
5659 WXS_ADD_GLOBAL(ctxt, ret);
5661 * Only keyrefs need to be fixup up.
5663 if (category == XML_SCHEMA_TYPE_IDC_KEYREF)
5664 WXS_ADD_PENDING(ctxt, ret);
5669 * xmlSchemaAddWildcard:
5670 * @ctxt: a schema validation context
5674 * It corresponds to a xsd:anyAttribute and xsd:any.
5676 * Returns the new struture or NULL in case of error
5678 static xmlSchemaWildcardPtr
5679 xmlSchemaAddWildcard(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
5680 xmlSchemaTypeType type, xmlNodePtr node)
5682 xmlSchemaWildcardPtr ret = NULL;
5684 if ((ctxt == NULL) || (schema == NULL))
5687 ret = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard));
5689 xmlSchemaPErrMemory(ctxt, "adding wildcard", NULL);
5692 memset(ret, 0, sizeof(xmlSchemaWildcard));
5695 WXS_ADD_LOCAL(ctxt, ret);
5700 xmlSchemaSubstGroupFree(xmlSchemaSubstGroupPtr group)
5704 if (group->members != NULL)
5705 xmlSchemaItemListFree(group->members);
5709 static xmlSchemaSubstGroupPtr
5710 xmlSchemaSubstGroupAdd(xmlSchemaParserCtxtPtr pctxt,
5711 xmlSchemaElementPtr head)
5713 xmlSchemaSubstGroupPtr ret;
5715 /* Init subst group hash. */
5716 if (WXS_SUBST_GROUPS(pctxt) == NULL) {
5717 WXS_SUBST_GROUPS(pctxt) = xmlHashCreateDict(10, pctxt->dict);
5718 if (WXS_SUBST_GROUPS(pctxt) == NULL)
5721 /* Create a new substitution group. */
5722 ret = (xmlSchemaSubstGroupPtr) xmlMalloc(sizeof(xmlSchemaSubstGroup));
5724 xmlSchemaPErrMemory(NULL,
5725 "allocating a substitution group container", NULL);
5728 memset(ret, 0, sizeof(xmlSchemaSubstGroup));
5730 /* Create list of members. */
5731 ret->members = xmlSchemaItemListCreate();
5732 if (ret->members == NULL) {
5733 xmlSchemaSubstGroupFree(ret);
5736 /* Add subst group to hash. */
5737 if (xmlHashAddEntry2(WXS_SUBST_GROUPS(pctxt),
5738 head->name, head->targetNamespace, ret) != 0) {
5739 PERROR_INT("xmlSchemaSubstGroupAdd",
5740 "failed to add a new substitution container");
5741 xmlSchemaSubstGroupFree(ret);
5747 static xmlSchemaSubstGroupPtr
5748 xmlSchemaSubstGroupGet(xmlSchemaParserCtxtPtr pctxt,
5749 xmlSchemaElementPtr head)
5751 if (WXS_SUBST_GROUPS(pctxt) == NULL)
5753 return(xmlHashLookup2(WXS_SUBST_GROUPS(pctxt),
5754 head->name, head->targetNamespace));
5759 * xmlSchemaAddElementSubstitutionMember:
5760 * @pctxt: a schema parser context
5761 * @head: the head of the substitution group
5762 * @member: the new member of the substitution group
5764 * Allocate a new annotation structure.
5766 * Returns the newly allocated structure or NULL in case or error
5769 xmlSchemaAddElementSubstitutionMember(xmlSchemaParserCtxtPtr pctxt,
5770 xmlSchemaElementPtr head,
5771 xmlSchemaElementPtr member)
5773 xmlSchemaSubstGroupPtr substGroup = NULL;
5775 if ((pctxt == NULL) || (head == NULL) || (member == NULL))
5778 substGroup = xmlSchemaSubstGroupGet(pctxt, head);
5779 if (substGroup == NULL)
5780 substGroup = xmlSchemaSubstGroupAdd(pctxt, head);
5781 if (substGroup == NULL)
5783 if (xmlSchemaItemListAdd(substGroup->members, member) == -1)
5788 /************************************************************************
5790 * Utilities for parsing *
5792 ************************************************************************/
5795 * xmlSchemaPValAttrNodeQNameValue:
5796 * @ctxt: a schema parser context
5797 * @schema: the schema context
5798 * @ownerDes: the designation of the parent element
5799 * @ownerItem: the parent as a schema object
5800 * @value: the QName value
5801 * @local: the resulting local part if found, the attribute value otherwise
5802 * @uri: the resulting namespace URI if found
5804 * Extracts the local name and the URI of a QName value and validates it.
5805 * This one is intended to be used on attribute values that
5806 * should resolve to schema components.
5808 * Returns 0, in case the QName is valid, a positive error code
5809 * if not valid and -1 if an internal error occurs.
5812 xmlSchemaPValAttrNodeQNameValue(xmlSchemaParserCtxtPtr ctxt,
5813 xmlSchemaPtr schema,
5814 xmlSchemaBasicItemPtr ownerItem,
5816 const xmlChar *value,
5817 const xmlChar **uri,
5818 const xmlChar **local)
5820 const xmlChar *pref;
5826 ret = xmlValidateQName(value, 1);
5828 xmlSchemaPSimpleTypeErr(ctxt,
5829 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
5830 ownerItem, (xmlNodePtr) attr,
5831 xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME),
5832 NULL, value, NULL, NULL, NULL);
5838 if (!strchr((char *) value, ':')) {
5839 ns = xmlSearchNs(attr->doc, attr->parent, NULL);
5841 *uri = xmlDictLookup(ctxt->dict, ns->href, -1);
5842 else if (schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) {
5843 /* TODO: move XML_SCHEMAS_INCLUDING_CONVERT_NS to the
5844 * parser context. */
5846 * This one takes care of included schemas with no
5849 *uri = ctxt->targetNamespace;
5851 *local = xmlDictLookup(ctxt->dict, value, -1);
5855 * At this point xmlSplitQName3 has to return a local name.
5857 *local = xmlSplitQName3(value, &len);
5858 *local = xmlDictLookup(ctxt->dict, *local, -1);
5859 pref = xmlDictLookup(ctxt->dict, value, len);
5860 ns = xmlSearchNs(attr->doc, attr->parent, pref);
5862 xmlSchemaPSimpleTypeErr(ctxt,
5863 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
5864 ownerItem, (xmlNodePtr) attr,
5865 xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), NULL, value,
5866 "The value '%s' of simple type 'xs:QName' has no "
5867 "corresponding namespace declaration in scope", value, NULL);
5870 *uri = xmlDictLookup(ctxt->dict, ns->href, -1);
5876 * xmlSchemaPValAttrNodeQName:
5877 * @ctxt: a schema parser context
5878 * @schema: the schema context
5879 * @ownerDes: the designation of the owner element
5880 * @ownerItem: the owner as a schema object
5881 * @attr: the attribute node
5882 * @local: the resulting local part if found, the attribute value otherwise
5883 * @uri: the resulting namespace URI if found
5885 * Extracts and validates the QName of an attribute value.
5886 * This one is intended to be used on attribute values that
5887 * should resolve to schema components.
5889 * Returns 0, in case the QName is valid, a positive error code
5890 * if not valid and -1 if an internal error occurs.
5893 xmlSchemaPValAttrNodeQName(xmlSchemaParserCtxtPtr ctxt,
5894 xmlSchemaPtr schema,
5895 xmlSchemaBasicItemPtr ownerItem,
5897 const xmlChar **uri,
5898 const xmlChar **local)
5900 const xmlChar *value;
5902 value = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
5903 return (xmlSchemaPValAttrNodeQNameValue(ctxt, schema,
5904 ownerItem, attr, value, uri, local));
5908 * xmlSchemaPValAttrQName:
5909 * @ctxt: a schema parser context
5910 * @schema: the schema context
5911 * @ownerDes: the designation of the parent element
5912 * @ownerItem: the owner as a schema object
5913 * @ownerElem: the parent node of the attribute
5914 * @name: the name of the attribute
5915 * @local: the resulting local part if found, the attribute value otherwise
5916 * @uri: the resulting namespace URI if found
5918 * Extracts and validates the QName of an attribute value.
5920 * Returns 0, in case the QName is valid, a positive error code
5921 * if not valid and -1 if an internal error occurs.
5924 xmlSchemaPValAttrQName(xmlSchemaParserCtxtPtr ctxt,
5925 xmlSchemaPtr schema,
5926 xmlSchemaBasicItemPtr ownerItem,
5927 xmlNodePtr ownerElem,
5929 const xmlChar **uri,
5930 const xmlChar **local)
5934 attr = xmlSchemaGetPropNode(ownerElem, name);
5940 return (xmlSchemaPValAttrNodeQName(ctxt, schema,
5941 ownerItem, attr, uri, local));
5945 * xmlSchemaPValAttrID:
5946 * @ctxt: a schema parser context
5947 * @schema: the schema context
5948 * @ownerDes: the designation of the parent element
5949 * @ownerItem: the owner as a schema object
5950 * @ownerElem: the parent node of the attribute
5951 * @name: the name of the attribute
5953 * Extracts and validates the ID of an attribute value.
5955 * Returns 0, in case the ID is valid, a positive error code
5956 * if not valid and -1 if an internal error occurs.
5959 xmlSchemaPValAttrNodeID(xmlSchemaParserCtxtPtr ctxt, xmlAttrPtr attr)
5962 const xmlChar *value;
5966 value = xmlSchemaGetNodeContentNoDict((xmlNodePtr) attr);
5967 ret = xmlValidateNCName(value, 1);
5970 * NOTE: the IDness might have already be declared in the DTD
5972 if (attr->atype != XML_ATTRIBUTE_ID) {
5977 * TODO: Use xmlSchemaStrip here; it's not exported at this
5980 strip = xmlSchemaCollapseString(value);
5981 if (strip != NULL) {
5982 xmlFree((xmlChar *) value);
5985 res = xmlAddID(NULL, attr->doc, value, attr);
5987 ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE;
5988 xmlSchemaPSimpleTypeErr(ctxt,
5989 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
5990 NULL, (xmlNodePtr) attr,
5991 xmlSchemaGetBuiltInType(XML_SCHEMAS_ID),
5992 NULL, NULL, "Duplicate value '%s' of simple "
5993 "type 'xs:ID'", value, NULL);
5995 attr->atype = XML_ATTRIBUTE_ID;
5997 } else if (ret > 0) {
5998 ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE;
5999 xmlSchemaPSimpleTypeErr(ctxt,
6000 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
6001 NULL, (xmlNodePtr) attr,
6002 xmlSchemaGetBuiltInType(XML_SCHEMAS_ID),
6003 NULL, NULL, "The value '%s' of simple type 'xs:ID' is "
6004 "not a valid 'xs:NCName'",
6008 xmlFree((xmlChar *)value);
6014 xmlSchemaPValAttrID(xmlSchemaParserCtxtPtr ctxt,
6015 xmlNodePtr ownerElem,
6016 const xmlChar *name)
6020 attr = xmlSchemaGetPropNode(ownerElem, (const char *) name);
6023 return(xmlSchemaPValAttrNodeID(ctxt, attr));
6029 * @ctxt: a schema validation context
6030 * @node: a subtree containing XML Schema informations
6032 * Get the maxOccurs property
6034 * Returns the default if not found, or the value
6037 xmlGetMaxOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
6038 int min, int max, int def, const char *expected)
6040 const xmlChar *val, *cur;
6044 attr = xmlSchemaGetPropNode(node, "maxOccurs");
6047 val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
6049 if (xmlStrEqual(val, (const xmlChar *) "unbounded")) {
6050 if (max != UNBOUNDED) {
6051 xmlSchemaPSimpleTypeErr(ctxt,
6052 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
6053 /* XML_SCHEMAP_INVALID_MINOCCURS, */
6054 NULL, (xmlNodePtr) attr, NULL, expected,
6055 val, NULL, NULL, NULL);
6058 return (UNBOUNDED); /* encoding it with -1 might be another option */
6062 while (IS_BLANK_CH(*cur))
6065 xmlSchemaPSimpleTypeErr(ctxt,
6066 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
6067 /* XML_SCHEMAP_INVALID_MINOCCURS, */
6068 NULL, (xmlNodePtr) attr, NULL, expected,
6069 val, NULL, NULL, NULL);
6072 while ((*cur >= '0') && (*cur <= '9')) {
6073 ret = ret * 10 + (*cur - '0');
6076 while (IS_BLANK_CH(*cur))
6079 * TODO: Restrict the maximal value to Integer.
6081 if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) {
6082 xmlSchemaPSimpleTypeErr(ctxt,
6083 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
6084 /* XML_SCHEMAP_INVALID_MINOCCURS, */
6085 NULL, (xmlNodePtr) attr, NULL, expected,
6086 val, NULL, NULL, NULL);
6094 * @ctxt: a schema validation context
6095 * @node: a subtree containing XML Schema informations
6097 * Get the minOccurs property
6099 * Returns the default if not found, or the value
6102 xmlGetMinOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
6103 int min, int max, int def, const char *expected)
6105 const xmlChar *val, *cur;
6109 attr = xmlSchemaGetPropNode(node, "minOccurs");
6112 val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
6114 while (IS_BLANK_CH(*cur))
6117 xmlSchemaPSimpleTypeErr(ctxt,
6118 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
6119 /* XML_SCHEMAP_INVALID_MINOCCURS, */
6120 NULL, (xmlNodePtr) attr, NULL, expected,
6121 val, NULL, NULL, NULL);
6124 while ((*cur >= '0') && (*cur <= '9')) {
6125 ret = ret * 10 + (*cur - '0');
6128 while (IS_BLANK_CH(*cur))
6131 * TODO: Restrict the maximal value to Integer.
6133 if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) {
6134 xmlSchemaPSimpleTypeErr(ctxt,
6135 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
6136 /* XML_SCHEMAP_INVALID_MINOCCURS, */
6137 NULL, (xmlNodePtr) attr, NULL, expected,
6138 val, NULL, NULL, NULL);
6145 * xmlSchemaPGetBoolNodeValue:
6146 * @ctxt: a schema validation context
6147 * @ownerDes: owner designation
6148 * @ownerItem: the owner as a schema item
6149 * @node: the node holding the value
6151 * Converts a boolean string value into 1 or 0.
6156 xmlSchemaPGetBoolNodeValue(xmlSchemaParserCtxtPtr ctxt,
6157 xmlSchemaBasicItemPtr ownerItem,
6160 xmlChar *value = NULL;
6163 value = xmlNodeGetContent(node);
6165 * 3.2.2.1 Lexical representation
6166 * An instance of a datatype that is defined as `boolean`
6167 * can have the following legal literals {true, false, 1, 0}.
6169 if (xmlStrEqual(BAD_CAST value, BAD_CAST "true"))
6171 else if (xmlStrEqual(BAD_CAST value, BAD_CAST "false"))
6173 else if (xmlStrEqual(BAD_CAST value, BAD_CAST "1"))
6175 else if (xmlStrEqual(BAD_CAST value, BAD_CAST "0"))
6178 xmlSchemaPSimpleTypeErr(ctxt,
6179 XML_SCHEMAP_INVALID_BOOLEAN,
6181 xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN),
6182 NULL, BAD_CAST value,
6191 * xmlGetBooleanProp:
6192 * @ctxt: a schema validation context
6193 * @node: a subtree containing XML Schema informations
6194 * @name: the attribute name
6195 * @def: the default value
6197 * Evaluate if a boolean property is set
6199 * Returns the default if not found, 0 if found to be false,
6200 * 1 if found to be true
6203 xmlGetBooleanProp(xmlSchemaParserCtxtPtr ctxt,
6205 const char *name, int def)
6209 val = xmlSchemaGetProp(ctxt, node, name);
6213 * 3.2.2.1 Lexical representation
6214 * An instance of a datatype that is defined as `boolean`
6215 * can have the following legal literals {true, false, 1, 0}.
6217 if (xmlStrEqual(val, BAD_CAST "true"))
6219 else if (xmlStrEqual(val, BAD_CAST "false"))
6221 else if (xmlStrEqual(val, BAD_CAST "1"))
6223 else if (xmlStrEqual(val, BAD_CAST "0"))
6226 xmlSchemaPSimpleTypeErr(ctxt,
6227 XML_SCHEMAP_INVALID_BOOLEAN,
6229 (xmlNodePtr) xmlSchemaGetPropNode(node, name),
6230 xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN),
6231 NULL, val, NULL, NULL, NULL);
6236 /************************************************************************
6238 * Shema extraction from an Infoset *
6240 ************************************************************************/
6241 static xmlSchemaTypePtr xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr
6242 ctxt, xmlSchemaPtr schema,
6245 static xmlSchemaTypePtr xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr
6247 xmlSchemaPtr schema,
6250 static xmlSchemaTypePtr xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr
6252 xmlSchemaPtr schema,
6254 xmlSchemaTypeType parentType);
6255 static xmlSchemaBasicItemPtr
6256 xmlSchemaParseLocalAttribute(xmlSchemaParserCtxtPtr pctxt,
6257 xmlSchemaPtr schema,
6259 xmlSchemaItemListPtr uses,
6261 static xmlSchemaTypePtr xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt,
6262 xmlSchemaPtr schema,
6264 static xmlSchemaWildcardPtr
6265 xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt,
6266 xmlSchemaPtr schema, xmlNodePtr node);
6269 * xmlSchemaPValAttrNodeValue:
6271 * @ctxt: a schema parser context
6272 * @ownerDes: the designation of the parent element
6273 * @ownerItem: the schema object owner if existent
6274 * @attr: the schema attribute node being validated
6276 * @type: the built-in type to be validated against
6278 * Validates a value against the given built-in type.
6279 * This one is intended to be used internally for validation
6280 * of schema attribute values during parsing of the schema.
6282 * Returns 0 if the value is valid, a positive error code
6283 * number otherwise and -1 in case of an internal or API error.
6286 xmlSchemaPValAttrNodeValue(xmlSchemaParserCtxtPtr pctxt,
6287 xmlSchemaBasicItemPtr ownerItem,
6289 const xmlChar *value,
6290 xmlSchemaTypePtr type)
6296 * NOTE: Should we move this to xmlschematypes.c? Hmm, but this
6297 * one is really meant to be used internally, so better not.
6299 if ((pctxt == NULL) || (type == NULL) || (attr == NULL))
6301 if (type->type != XML_SCHEMA_TYPE_BASIC) {
6302 PERROR_INT("xmlSchemaPValAttrNodeValue",
6303 "the given type is not a built-in type");
6306 switch (type->builtInType) {
6307 case XML_SCHEMAS_NCNAME:
6308 case XML_SCHEMAS_QNAME:
6309 case XML_SCHEMAS_ANYURI:
6310 case XML_SCHEMAS_TOKEN:
6311 case XML_SCHEMAS_LANGUAGE:
6312 ret = xmlSchemaValPredefTypeNode(type, value, NULL,
6316 PERROR_INT("xmlSchemaPValAttrNodeValue",
6317 "validation using the given type is not supported while "
6318 "parsing a schema");
6323 * TODO: Should we use the S4S error codes instead?
6326 PERROR_INT("xmlSchemaPValAttrNodeValue",
6327 "failed to validate a schema attribute value");
6329 } else if (ret > 0) {
6330 if (WXS_IS_LIST(type))
6331 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2;
6333 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1;
6334 xmlSchemaPSimpleTypeErr(pctxt,
6335 ret, ownerItem, (xmlNodePtr) attr,
6336 type, NULL, value, NULL, NULL, NULL);
6342 * xmlSchemaPValAttrNode:
6344 * @ctxt: a schema parser context
6345 * @ownerDes: the designation of the parent element
6346 * @ownerItem: the schema object owner if existent
6347 * @attr: the schema attribute node being validated
6348 * @type: the built-in type to be validated against
6349 * @value: the resulting value if any
6351 * Extracts and validates a value against the given built-in type.
6352 * This one is intended to be used internally for validation
6353 * of schema attribute values during parsing of the schema.
6355 * Returns 0 if the value is valid, a positive error code
6356 * number otherwise and -1 in case of an internal or API error.
6359 xmlSchemaPValAttrNode(xmlSchemaParserCtxtPtr ctxt,
6360 xmlSchemaBasicItemPtr ownerItem,
6362 xmlSchemaTypePtr type,
6363 const xmlChar **value)
6367 if ((ctxt == NULL) || (type == NULL) || (attr == NULL))
6370 val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
6374 return (xmlSchemaPValAttrNodeValue(ctxt, ownerItem, attr,
6379 * xmlSchemaPValAttr:
6381 * @ctxt: a schema parser context
6382 * @node: the element node of the attribute
6383 * @ownerDes: the designation of the parent element
6384 * @ownerItem: the schema object owner if existent
6385 * @ownerElem: the owner element node
6386 * @name: the name of the schema attribute node
6387 * @type: the built-in type to be validated against
6388 * @value: the resulting value if any
6390 * Extracts and validates a value against the given built-in type.
6391 * This one is intended to be used internally for validation
6392 * of schema attribute values during parsing of the schema.
6394 * Returns 0 if the value is valid, a positive error code
6395 * number otherwise and -1 in case of an internal or API error.
6398 xmlSchemaPValAttr(xmlSchemaParserCtxtPtr ctxt,
6399 xmlSchemaBasicItemPtr ownerItem,
6400 xmlNodePtr ownerElem,
6402 xmlSchemaTypePtr type,
6403 const xmlChar **value)
6407 if ((ctxt == NULL) || (type == NULL)) {
6412 if (type->type != XML_SCHEMA_TYPE_BASIC) {
6415 xmlSchemaPErr(ctxt, ownerElem,
6416 XML_SCHEMAP_INTERNAL,
6417 "Internal error: xmlSchemaPValAttr, the given "
6418 "type '%s' is not a built-in type.\n",
6422 attr = xmlSchemaGetPropNode(ownerElem, name);
6428 return (xmlSchemaPValAttrNode(ctxt, ownerItem, attr,
6433 xmlSchemaCheckReference(xmlSchemaParserCtxtPtr pctxt,
6434 xmlSchemaPtr schema ATTRIBUTE_UNUSED,
6437 const xmlChar *namespaceName)
6439 /* TODO: Pointer comparison instead? */
6440 if (xmlStrEqual(pctxt->targetNamespace, namespaceName))
6442 if (xmlStrEqual(xmlSchemaNs, namespaceName))
6445 * Check if the referenced namespace was <import>ed.
6447 if (WXS_BUCKET(pctxt)->relations != NULL) {
6448 xmlSchemaSchemaRelationPtr rel;
6450 rel = WXS_BUCKET(pctxt)->relations;
6452 if (WXS_IS_BUCKET_IMPMAIN(rel->type) &&
6453 xmlStrEqual(namespaceName, rel->importNamespace))
6456 } while (rel != NULL);
6459 * No matching <import>ed namespace found.
6462 xmlNodePtr n = (attr != NULL) ? (xmlNodePtr) attr : node;
6464 if (namespaceName == NULL)
6465 xmlSchemaCustomErr(ACTXT_CAST pctxt,
6466 XML_SCHEMAP_SRC_RESOLVE, n, NULL,
6467 "References from this schema to components in no "
6468 "namespace are not allowed, since not indicated by an "
6469 "import statement", NULL, NULL);
6471 xmlSchemaCustomErr(ACTXT_CAST pctxt,
6472 XML_SCHEMAP_SRC_RESOLVE, n, NULL,
6473 "References from this schema to components in the "
6474 "namespace '%s' are not allowed, since not indicated by an "
6475 "import statement", namespaceName, NULL);
6477 return (XML_SCHEMAP_SRC_RESOLVE);
6481 * xmlSchemaParseLocalAttributes:
6482 * @ctxt: a schema validation context
6483 * @schema: the schema being built
6484 * @node: a subtree containing XML Schema informations
6485 * @type: the hosting type where the attributes will be anchored
6487 * Parses attribute uses and attribute declarations and
6488 * attribute group references.
6491 xmlSchemaParseLocalAttributes(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
6492 xmlNodePtr *child, xmlSchemaItemListPtr *list,
6493 int parentType, int *hasRefs)
6497 while ((IS_SCHEMA((*child), "attribute")) ||
6498 (IS_SCHEMA((*child), "attributeGroup"))) {
6499 if (IS_SCHEMA((*child), "attribute")) {
6500 item = xmlSchemaParseLocalAttribute(ctxt, schema, *child,
6503 item = xmlSchemaParseAttributeGroupRef(ctxt, schema, *child);
6504 if ((item != NULL) && (hasRefs != NULL))
6508 if (*list == NULL) {
6509 /* TODO: Customize grow factor. */
6510 *list = xmlSchemaItemListCreate();
6514 if (xmlSchemaItemListAddSize(*list, 2, item) == -1)
6517 *child = (*child)->next;
6523 * xmlSchemaParseAnnotation:
6524 * @ctxt: a schema validation context
6525 * @schema: the schema being built
6526 * @node: a subtree containing XML Schema informations
6528 * parse a XML schema Attrribute declaration
6529 * *WARNING* this interface is highly subject to change
6531 * Returns -1 in case of error, 0 if the declaration is improper and
6532 * 1 in case of success.
6534 static xmlSchemaAnnotPtr
6535 xmlSchemaParseAnnotation(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int needed)
6537 xmlSchemaAnnotPtr ret;
6538 xmlNodePtr child = NULL;
6543 * INFO: S4S completed.
6547 * {any attributes with non-schema namespace . . .}>
6548 * Content: (appinfo | documentation)*
6550 if ((ctxt == NULL) || (node == NULL))
6553 ret = xmlSchemaNewAnnot(ctxt, node);
6556 attr = node->properties;
6557 while (attr != NULL) {
6558 if (((attr->ns == NULL) &&
6559 (!xmlStrEqual(attr->name, BAD_CAST "id"))) ||
6560 ((attr->ns != NULL) &&
6561 xmlStrEqual(attr->ns->href, xmlSchemaNs))) {
6563 xmlSchemaPIllegalAttrErr(ctxt,
6564 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
6568 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
6570 * And now for the children...
6572 child = node->children;
6573 while (child != NULL) {
6574 if (IS_SCHEMA(child, "appinfo")) {
6575 /* TODO: make available the content of "appinfo". */
6578 * {any attributes with non-schema namespace . . .}>
6581 attr = child->properties;
6582 while (attr != NULL) {
6583 if (((attr->ns == NULL) &&
6584 (!xmlStrEqual(attr->name, BAD_CAST "source"))) ||
6585 ((attr->ns != NULL) &&
6586 xmlStrEqual(attr->ns->href, xmlSchemaNs))) {
6588 xmlSchemaPIllegalAttrErr(ctxt,
6589 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
6593 xmlSchemaPValAttr(ctxt, NULL, child, "source",
6594 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), NULL);
6595 child = child->next;
6596 } else if (IS_SCHEMA(child, "documentation")) {
6597 /* TODO: make available the content of "documentation". */
6600 * {any attributes with non-schema namespace . . .}>
6603 attr = child->properties;
6604 while (attr != NULL) {
6605 if (attr->ns == NULL) {
6606 if (!xmlStrEqual(attr->name, BAD_CAST "source")) {
6607 xmlSchemaPIllegalAttrErr(ctxt,
6608 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
6611 if (xmlStrEqual(attr->ns->href, xmlSchemaNs) ||
6612 (xmlStrEqual(attr->name, BAD_CAST "lang") &&
6613 (!xmlStrEqual(attr->ns->href, XML_XML_NAMESPACE)))) {
6615 xmlSchemaPIllegalAttrErr(ctxt,
6616 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
6622 * Attribute "xml:lang".
6624 attr = xmlSchemaGetPropNodeNs(child, (const char *) XML_XML_NAMESPACE, "lang");
6626 xmlSchemaPValAttrNode(ctxt, NULL, attr,
6627 xmlSchemaGetBuiltInType(XML_SCHEMAS_LANGUAGE), NULL);
6628 child = child->next;
6631 xmlSchemaPContentErr(ctxt,
6632 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
6633 NULL, node, child, NULL, "(appinfo | documentation)*");
6635 child = child->next;
6643 * xmlSchemaParseFacet:
6644 * @ctxt: a schema validation context
6645 * @schema: the schema being built
6646 * @node: a subtree containing XML Schema informations
6648 * parse a XML schema Facet declaration
6649 * *WARNING* this interface is highly subject to change
6651 * Returns the new type structure or NULL in case of error
6653 static xmlSchemaFacetPtr
6654 xmlSchemaParseFacet(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
6657 xmlSchemaFacetPtr facet;
6658 xmlNodePtr child = NULL;
6659 const xmlChar *value;
6661 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
6664 facet = xmlSchemaNewFacet();
6665 if (facet == NULL) {
6666 xmlSchemaPErrMemory(ctxt, "allocating facet", node);
6670 value = xmlSchemaGetProp(ctxt, node, "value");
6671 if (value == NULL) {
6672 xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_FACET_NO_VALUE,
6673 "Facet %s has no value\n", node->name, NULL);
6674 xmlSchemaFreeFacet(facet);
6677 if (IS_SCHEMA(node, "minInclusive")) {
6678 facet->type = XML_SCHEMA_FACET_MININCLUSIVE;
6679 } else if (IS_SCHEMA(node, "minExclusive")) {
6680 facet->type = XML_SCHEMA_FACET_MINEXCLUSIVE;
6681 } else if (IS_SCHEMA(node, "maxInclusive")) {
6682 facet->type = XML_SCHEMA_FACET_MAXINCLUSIVE;
6683 } else if (IS_SCHEMA(node, "maxExclusive")) {
6684 facet->type = XML_SCHEMA_FACET_MAXEXCLUSIVE;
6685 } else if (IS_SCHEMA(node, "totalDigits")) {
6686 facet->type = XML_SCHEMA_FACET_TOTALDIGITS;
6687 } else if (IS_SCHEMA(node, "fractionDigits")) {
6688 facet->type = XML_SCHEMA_FACET_FRACTIONDIGITS;
6689 } else if (IS_SCHEMA(node, "pattern")) {
6690 facet->type = XML_SCHEMA_FACET_PATTERN;
6691 } else if (IS_SCHEMA(node, "enumeration")) {
6692 facet->type = XML_SCHEMA_FACET_ENUMERATION;
6693 } else if (IS_SCHEMA(node, "whiteSpace")) {
6694 facet->type = XML_SCHEMA_FACET_WHITESPACE;
6695 } else if (IS_SCHEMA(node, "length")) {
6696 facet->type = XML_SCHEMA_FACET_LENGTH;
6697 } else if (IS_SCHEMA(node, "maxLength")) {
6698 facet->type = XML_SCHEMA_FACET_MAXLENGTH;
6699 } else if (IS_SCHEMA(node, "minLength")) {
6700 facet->type = XML_SCHEMA_FACET_MINLENGTH;
6702 xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_TYPE,
6703 "Unknown facet type %s\n", node->name, NULL);
6704 xmlSchemaFreeFacet(facet);
6707 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
6708 facet->value = value;
6709 if ((facet->type != XML_SCHEMA_FACET_PATTERN) &&
6710 (facet->type != XML_SCHEMA_FACET_ENUMERATION)) {
6711 const xmlChar *fixed;
6713 fixed = xmlSchemaGetProp(ctxt, node, "fixed");
6714 if (fixed != NULL) {
6715 if (xmlStrEqual(fixed, BAD_CAST "true"))
6719 child = node->children;
6721 if (IS_SCHEMA(child, "annotation")) {
6722 facet->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
6723 child = child->next;
6725 if (child != NULL) {
6726 xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_CHILD,
6727 "Facet %s has unexpected child content\n",
6734 * xmlSchemaParseWildcardNs:
6735 * @ctxt: a schema parser context
6736 * @wildc: the wildcard, already created
6737 * @node: a subtree containing XML Schema informations
6739 * Parses the attribute "processContents" and "namespace"
6740 * of a xsd:anyAttribute and xsd:any.
6741 * *WARNING* this interface is highly subject to change
6743 * Returns 0 if everything goes fine, a positive error code
6744 * if something is not valid and -1 if an internal error occurs.
6747 xmlSchemaParseWildcardNs(xmlSchemaParserCtxtPtr ctxt,
6748 xmlSchemaPtr schema ATTRIBUTE_UNUSED,
6749 xmlSchemaWildcardPtr wildc,
6752 const xmlChar *pc, *ns, *dictnsItem;
6755 xmlSchemaWildcardNsPtr tmp, lastNs = NULL;
6758 pc = xmlSchemaGetProp(ctxt, node, "processContents");
6760 || (xmlStrEqual(pc, (const xmlChar *) "strict"))) {
6761 wildc->processContents = XML_SCHEMAS_ANY_STRICT;
6762 } else if (xmlStrEqual(pc, (const xmlChar *) "skip")) {
6763 wildc->processContents = XML_SCHEMAS_ANY_SKIP;
6764 } else if (xmlStrEqual(pc, (const xmlChar *) "lax")) {
6765 wildc->processContents = XML_SCHEMAS_ANY_LAX;
6767 xmlSchemaPSimpleTypeErr(ctxt,
6768 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
6770 NULL, "(strict | skip | lax)", pc,
6772 wildc->processContents = XML_SCHEMAS_ANY_STRICT;
6773 ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE;
6776 * Build the namespace constraints.
6778 attr = xmlSchemaGetPropNode(node, "namespace");
6779 ns = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
6780 if ((attr == NULL) || (xmlStrEqual(ns, BAD_CAST "##any")))
6782 else if (xmlStrEqual(ns, BAD_CAST "##other")) {
6783 wildc->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt);
6784 if (wildc->negNsSet == NULL) {
6787 wildc->negNsSet->value = ctxt->targetNamespace;
6789 const xmlChar *end, *cur;
6793 while (IS_BLANK_CH(*cur))
6796 while ((*end != 0) && (!(IS_BLANK_CH(*end))))
6800 nsItem = xmlStrndup(cur, end - cur);
6801 if ((xmlStrEqual(nsItem, BAD_CAST "##other")) ||
6802 (xmlStrEqual(nsItem, BAD_CAST "##any"))) {
6803 xmlSchemaPSimpleTypeErr(ctxt,
6804 XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER,
6805 NULL, (xmlNodePtr) attr,
6807 "((##any | ##other) | List of (xs:anyURI | "
6808 "(##targetNamespace | ##local)))",
6809 nsItem, NULL, NULL, NULL);
6810 ret = XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER;
6812 if (xmlStrEqual(nsItem, BAD_CAST "##targetNamespace")) {
6813 dictnsItem = ctxt->targetNamespace;
6814 } else if (xmlStrEqual(nsItem, BAD_CAST "##local")) {
6818 * Validate the item (anyURI).
6820 xmlSchemaPValAttrNodeValue(ctxt, NULL, attr,
6821 nsItem, xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI));
6822 dictnsItem = xmlDictLookup(ctxt->dict, nsItem, -1);
6825 * Avoid dublicate namespaces.
6828 while (tmp != NULL) {
6829 if (dictnsItem == tmp->value)
6834 tmp = xmlSchemaNewWildcardNsConstraint(ctxt);
6839 tmp->value = dictnsItem;
6841 if (wildc->nsSet == NULL)
6843 else if (lastNs != NULL)
6851 } while (*cur != 0);
6857 xmlSchemaPCheckParticleCorrect_2(xmlSchemaParserCtxtPtr ctxt,
6858 xmlSchemaParticlePtr item ATTRIBUTE_UNUSED,
6863 if ((maxOccurs == 0) && ( minOccurs == 0))
6865 if (maxOccurs != UNBOUNDED) {
6867 * TODO: Maybe we should better not create the particle,
6868 * if min/max is invalid, since it could confuse the build of the
6872 * 3.9.6 Schema Component Constraint: Particle Correct
6875 if (maxOccurs < 1) {
6877 * 2.2 {max occurs} must be greater than or equal to 1.
6879 xmlSchemaPCustomAttrErr(ctxt,
6880 XML_SCHEMAP_P_PROPS_CORRECT_2_2,
6882 xmlSchemaGetPropNode(node, "maxOccurs"),
6883 "The value must be greater than or equal to 1");
6884 return (XML_SCHEMAP_P_PROPS_CORRECT_2_2);
6885 } else if (minOccurs > maxOccurs) {
6887 * 2.1 {min occurs} must not be greater than {max occurs}.
6889 xmlSchemaPCustomAttrErr(ctxt,
6890 XML_SCHEMAP_P_PROPS_CORRECT_2_1,
6892 xmlSchemaGetPropNode(node, "minOccurs"),
6893 "The value must not be greater than the value of 'maxOccurs'");
6894 return (XML_SCHEMAP_P_PROPS_CORRECT_2_1);
6901 * xmlSchemaParseAny:
6902 * @ctxt: a schema validation context
6903 * @schema: the schema being built
6904 * @node: a subtree containing XML Schema informations
6906 * Parsea a XML schema <any> element. A particle and wildcard
6907 * will be created (except if minOccurs==maxOccurs==0, in this case
6908 * nothing will be created).
6909 * *WARNING* this interface is highly subject to change
6911 * Returns the particle or NULL in case of error or if minOccurs==maxOccurs==0
6913 static xmlSchemaParticlePtr
6914 xmlSchemaParseAny(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
6917 xmlSchemaParticlePtr particle;
6918 xmlNodePtr child = NULL;
6919 xmlSchemaWildcardPtr wild;
6922 xmlSchemaAnnotPtr annot = NULL;
6924 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
6927 * Check for illegal attributes.
6929 attr = node->properties;
6930 while (attr != NULL) {
6931 if (attr->ns == NULL) {
6932 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
6933 (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) &&
6934 (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) &&
6935 (!xmlStrEqual(attr->name, BAD_CAST "namespace")) &&
6936 (!xmlStrEqual(attr->name, BAD_CAST "processContents"))) {
6937 xmlSchemaPIllegalAttrErr(ctxt,
6938 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
6940 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
6941 xmlSchemaPIllegalAttrErr(ctxt,
6942 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
6946 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
6948 * minOccurs/maxOccurs.
6950 max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1,
6951 "(xs:nonNegativeInteger | unbounded)");
6952 min = xmlGetMinOccurs(ctxt, node, 0, -1, 1,
6953 "xs:nonNegativeInteger");
6954 xmlSchemaPCheckParticleCorrect_2(ctxt, NULL, node, min, max);
6956 * Create & parse the wildcard.
6958 wild = xmlSchemaAddWildcard(ctxt, schema, XML_SCHEMA_TYPE_ANY, node);
6961 xmlSchemaParseWildcardNs(ctxt, schema, wild, node);
6963 * And now for the children...
6965 child = node->children;
6966 if (IS_SCHEMA(child, "annotation")) {
6967 annot = xmlSchemaParseAnnotation(ctxt, child, 1);
6968 child = child->next;
6970 if (child != NULL) {
6971 xmlSchemaPContentErr(ctxt,
6972 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
6974 NULL, "(annotation?)");
6977 * No component if minOccurs==maxOccurs==0.
6979 if ((min == 0) && (max == 0)) {
6980 /* Don't free the wildcard, since it's already on the list. */
6984 * Create the particle.
6986 particle = xmlSchemaAddParticle(ctxt, node, min, max);
6987 if (particle == NULL)
6989 particle->annot = annot;
6990 particle->children = (xmlSchemaTreeItemPtr) wild;
6996 * xmlSchemaParseNotation:
6997 * @ctxt: a schema validation context
6998 * @schema: the schema being built
6999 * @node: a subtree containing XML Schema informations
7001 * parse a XML schema Notation declaration
7003 * Returns the new structure or NULL in case of error
7005 static xmlSchemaNotationPtr
7006 xmlSchemaParseNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
7009 const xmlChar *name;
7010 xmlSchemaNotationPtr ret;
7011 xmlNodePtr child = NULL;
7013 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
7015 name = xmlSchemaGetProp(ctxt, node, "name");
7017 xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_NOTATION_NO_NAME,
7018 "Notation has no name\n", NULL, NULL);
7021 ret = xmlSchemaAddNotation(ctxt, schema, name,
7022 ctxt->targetNamespace, node);
7025 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
7027 child = node->children;
7028 if (IS_SCHEMA(child, "annotation")) {
7029 ret->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
7030 child = child->next;
7032 if (child != NULL) {
7033 xmlSchemaPContentErr(ctxt,
7034 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
7036 NULL, "(annotation?)");
7043 * xmlSchemaParseAnyAttribute:
7044 * @ctxt: a schema validation context
7045 * @schema: the schema being built
7046 * @node: a subtree containing XML Schema informations
7048 * parse a XML schema AnyAttrribute declaration
7049 * *WARNING* this interface is highly subject to change
7051 * Returns a wildcard or NULL.
7053 static xmlSchemaWildcardPtr
7054 xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt,
7055 xmlSchemaPtr schema, xmlNodePtr node)
7057 xmlSchemaWildcardPtr ret;
7058 xmlNodePtr child = NULL;
7061 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
7064 ret = xmlSchemaAddWildcard(ctxt, schema, XML_SCHEMA_TYPE_ANY_ATTRIBUTE,
7070 * Check for illegal attributes.
7072 attr = node->properties;
7073 while (attr != NULL) {
7074 if (attr->ns == NULL) {
7075 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
7076 (!xmlStrEqual(attr->name, BAD_CAST "namespace")) &&
7077 (!xmlStrEqual(attr->name, BAD_CAST "processContents"))) {
7078 xmlSchemaPIllegalAttrErr(ctxt,
7079 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
7081 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
7082 xmlSchemaPIllegalAttrErr(ctxt,
7083 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
7087 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
7089 * Parse the namespace list.
7091 if (xmlSchemaParseWildcardNs(ctxt, schema, ret, node) != 0)
7094 * And now for the children...
7096 child = node->children;
7097 if (IS_SCHEMA(child, "annotation")) {
7098 ret->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
7099 child = child->next;
7101 if (child != NULL) {
7102 xmlSchemaPContentErr(ctxt,
7103 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
7105 NULL, "(annotation?)");
7113 * xmlSchemaParseAttribute:
7114 * @ctxt: a schema validation context
7115 * @schema: the schema being built
7116 * @node: a subtree containing XML Schema informations
7118 * parse a XML schema Attrribute declaration
7119 * *WARNING* this interface is highly subject to change
7121 * Returns the attribute declaration.
7123 static xmlSchemaBasicItemPtr
7124 xmlSchemaParseLocalAttribute(xmlSchemaParserCtxtPtr pctxt,
7125 xmlSchemaPtr schema,
7127 xmlSchemaItemListPtr uses,
7130 const xmlChar *attrValue, *name = NULL, *ns = NULL;
7131 xmlSchemaAttributeUsePtr use = NULL;
7132 xmlNodePtr child = NULL;
7134 const xmlChar *tmpNs = NULL, *tmpName = NULL, *defValue = NULL;
7135 int isRef = 0, occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL;
7136 int nberrors, hasForm = 0, defValueType = 0;
7138 #define WXS_ATTR_DEF_VAL_DEFAULT 1
7139 #define WXS_ATTR_DEF_VAL_FIXED 2
7142 * 3.2.3 Constraints on XML Representations of Attribute Declarations
7145 if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
7147 attr = xmlSchemaGetPropNode(node, "ref");
7149 if (xmlSchemaPValAttrNodeQName(pctxt, schema,
7150 NULL, attr, &tmpNs, &tmpName) != 0) {
7153 if (xmlSchemaCheckReference(pctxt, schema, node, attr, tmpNs) != 0)
7157 nberrors = pctxt->nberrors;
7159 * Check for illegal attributes.
7161 attr = node->properties;
7162 while (attr != NULL) {
7163 if (attr->ns == NULL) {
7165 if (xmlStrEqual(attr->name, BAD_CAST "id")) {
7166 xmlSchemaPValAttrNodeID(pctxt, attr);
7168 } else if (xmlStrEqual(attr->name, BAD_CAST "ref")) {
7172 if (xmlStrEqual(attr->name, BAD_CAST "name")) {
7174 } else if (xmlStrEqual(attr->name, BAD_CAST "id")) {
7175 xmlSchemaPValAttrNodeID(pctxt, attr);
7177 } else if (xmlStrEqual(attr->name, BAD_CAST "type")) {
7178 xmlSchemaPValAttrNodeQName(pctxt, schema, NULL,
7179 attr, &tmpNs, &tmpName);
7181 } else if (xmlStrEqual(attr->name, BAD_CAST "form")) {
7183 * Evaluate the target namespace
7186 attrValue = xmlSchemaGetNodeContent(pctxt,
7188 if (xmlStrEqual(attrValue, BAD_CAST "qualified")) {
7189 ns = pctxt->targetNamespace;
7190 } else if (!xmlStrEqual(attrValue, BAD_CAST "unqualified"))
7192 xmlSchemaPSimpleTypeErr(pctxt,
7193 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
7194 NULL, (xmlNodePtr) attr,
7195 NULL, "(qualified | unqualified)",
7196 attrValue, NULL, NULL, NULL);
7201 if (xmlStrEqual(attr->name, BAD_CAST "use")) {
7203 attrValue = xmlSchemaGetNodeContent(pctxt, (xmlNodePtr) attr);
7204 /* TODO: Maybe we need to normalize the value beforehand. */
7205 if (xmlStrEqual(attrValue, BAD_CAST "optional"))
7206 occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL;
7207 else if (xmlStrEqual(attrValue, BAD_CAST "prohibited"))
7208 occurs = XML_SCHEMAS_ATTR_USE_PROHIBITED;
7209 else if (xmlStrEqual(attrValue, BAD_CAST "required"))
7210 occurs = XML_SCHEMAS_ATTR_USE_REQUIRED;
7212 xmlSchemaPSimpleTypeErr(pctxt,
7213 XML_SCHEMAP_INVALID_ATTR_USE,
7214 NULL, (xmlNodePtr) attr,
7215 NULL, "(optional | prohibited | required)",
7216 attrValue, NULL, NULL, NULL);
7219 } else if (xmlStrEqual(attr->name, BAD_CAST "default")) {
7222 * default and fixed must not both be present.
7225 xmlSchemaPMutualExclAttrErr(pctxt,
7226 XML_SCHEMAP_SRC_ATTRIBUTE_1,
7227 NULL, attr, "default", "fixed");
7229 defValue = xmlSchemaGetNodeContent(pctxt, (xmlNodePtr) attr);
7230 defValueType = WXS_ATTR_DEF_VAL_DEFAULT;
7233 } else if (xmlStrEqual(attr->name, BAD_CAST "fixed")) {
7236 * default and fixed must not both be present.
7239 xmlSchemaPMutualExclAttrErr(pctxt,
7240 XML_SCHEMAP_SRC_ATTRIBUTE_1,
7241 NULL, attr, "default", "fixed");
7243 defValue = xmlSchemaGetNodeContent(pctxt, (xmlNodePtr) attr);
7244 defValueType = WXS_ATTR_DEF_VAL_FIXED;
7248 } else if (! xmlStrEqual(attr->ns->href, xmlSchemaNs))
7251 xmlSchemaPIllegalAttrErr(pctxt,
7252 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
7259 * If default and use are both present, use must have
7260 * the actual value optional.
7262 if ((defValueType == WXS_ATTR_DEF_VAL_DEFAULT) &&
7263 (occurs != XML_SCHEMAS_ATTR_USE_OPTIONAL)) {
7264 xmlSchemaPSimpleTypeErr(pctxt,
7265 XML_SCHEMAP_SRC_ATTRIBUTE_2,
7267 "(optional | prohibited | required)", NULL,
7268 "The value of the attribute 'use' must be 'optional' "
7269 "if the attribute 'default' is present",
7273 * We want correct attributes.
7275 if (nberrors != pctxt->nberrors)
7278 xmlSchemaAttributePtr attrDecl;
7280 /* TODO: move XML_SCHEMAS_QUALIF_ATTR to the parser. */
7281 if ((! hasForm) && (schema->flags & XML_SCHEMAS_QUALIF_ATTR))
7282 ns = pctxt->targetNamespace;
7284 * 3.2.6 Schema Component Constraint: xsi: Not Allowed
7285 * TODO: Move this to the component layer.
7287 if (xmlStrEqual(ns, xmlSchemaInstanceNs)) {
7288 xmlSchemaCustomErr(ACTXT_CAST pctxt,
7291 "The target namespace must not match '%s'",
7292 xmlSchemaInstanceNs, NULL);
7294 attr = xmlSchemaGetPropNode(node, "name");
7296 xmlSchemaPMissingAttrErr(pctxt, XML_SCHEMAP_S4S_ATTR_MISSING,
7297 NULL, node, "name", NULL);
7300 if (xmlSchemaPValAttrNode(pctxt, NULL, attr,
7301 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) {
7305 * 3.2.6 Schema Component Constraint: xmlns Not Allowed
7306 * TODO: Move this to the component layer.
7308 if (xmlStrEqual(name, BAD_CAST "xmlns")) {
7309 xmlSchemaPSimpleTypeErr(pctxt,
7310 XML_SCHEMAP_NO_XMLNS,
7311 NULL, (xmlNodePtr) attr,
7312 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), NULL, NULL,
7313 "The value of the attribute must not match 'xmlns'",
7317 if (occurs == XML_SCHEMAS_ATTR_USE_PROHIBITED)
7318 goto check_children;
7320 * Create the attribute use component.
7322 use = xmlSchemaAddAttributeUse(pctxt, node);
7325 use->occurs = occurs;
7327 * Create the attribute declaration.
7329 attrDecl = xmlSchemaAddAttribute(pctxt, schema, name, ns, node, 0);
7330 if (attrDecl == NULL)
7332 if (tmpName != NULL) {
7333 attrDecl->typeName = tmpName;
7334 attrDecl->typeNs = tmpNs;
7336 use->attrDecl = attrDecl;
7340 if (defValue != NULL) {
7341 attrDecl->defValue = defValue;
7342 if (defValueType == WXS_ATTR_DEF_VAL_FIXED)
7343 attrDecl->flags |= XML_SCHEMAS_ATTR_FIXED;
7345 } else if (occurs != XML_SCHEMAS_ATTR_USE_PROHIBITED) {
7346 xmlSchemaQNameRefPtr ref;
7349 * Create the attribute use component.
7351 use = xmlSchemaAddAttributeUse(pctxt, node);
7355 * We need to resolve the reference at later stage.
7357 WXS_ADD_PENDING(pctxt, use);
7358 use->occurs = occurs;
7360 * Create a QName reference to the attribute declaration.
7362 ref = xmlSchemaNewQNameRef(pctxt, XML_SCHEMA_TYPE_ATTRIBUTE,
7367 * Assign the reference. This will be substituted for the
7368 * referenced attribute declaration when the QName is resolved.
7370 use->attrDecl = WXS_ATTR_CAST ref;
7374 if (defValue != NULL)
7375 use->defValue = defValue;
7376 if (defValueType == WXS_ATTR_DEF_VAL_FIXED)
7377 use->flags |= XML_SCHEMA_ATTR_USE_FIXED;
7382 * And now for the children...
7384 child = node->children;
7385 if (occurs == XML_SCHEMAS_ATTR_USE_PROHIBITED) {
7386 xmlSchemaAttributeUseProhibPtr prohib;
7388 if (IS_SCHEMA(child, "annotation")) {
7389 xmlSchemaParseAnnotation(pctxt, child, 0);
7390 child = child->next;
7392 if (child != NULL) {
7393 xmlSchemaPContentErr(pctxt,
7394 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
7395 NULL, node, child, NULL,
7399 * Check for pointlessness of attribute prohibitions.
7401 if (parentType == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) {
7402 xmlSchemaCustomWarning(ACTXT_CAST pctxt,
7403 XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH,
7405 "Skipping attribute use prohibition, since it is "
7406 "pointless inside an <attributeGroup>",
7409 } else if (parentType == XML_SCHEMA_TYPE_EXTENSION) {
7410 xmlSchemaCustomWarning(ACTXT_CAST pctxt,
7411 XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH,
7413 "Skipping attribute use prohibition, since it is "
7414 "pointless when extending a type",
7423 * Check for duplicate attribute prohibitions.
7428 for (i = 0; i < uses->nbItems; i++) {
7429 use = uses->items[i];
7430 if ((use->type == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB) &&
7431 (tmpName == (WXS_ATTR_PROHIB_CAST use)->name) &&
7432 (tmpNs == (WXS_ATTR_PROHIB_CAST use)->targetNamespace))
7434 xmlChar *str = NULL;
7436 xmlSchemaCustomWarning(ACTXT_CAST pctxt,
7437 XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH,
7439 "Skipping duplicate attribute use prohibition '%s'",
7440 xmlSchemaFormatQName(&str, tmpNs, tmpName),
7448 * Create the attribute prohibition helper component.
7450 prohib = xmlSchemaAddAttributeUseProhib(pctxt);
7453 prohib->node = node;
7454 prohib->name = tmpName;
7455 prohib->targetNamespace = tmpNs;
7458 * We need at least to resolve to the attribute declaration.
7460 WXS_ADD_PENDING(pctxt, prohib);
7462 return(WXS_BASIC_CAST prohib);
7464 if (IS_SCHEMA(child, "annotation")) {
7466 * TODO: Should this go into the attr decl?
7468 use->annot = xmlSchemaParseAnnotation(pctxt, child, 1);
7469 child = child->next;
7472 if (child != NULL) {
7473 if (IS_SCHEMA(child, "simpleType"))
7476 * If ref is present, then all of <simpleType>,
7477 * form and type must be absent.
7479 xmlSchemaPContentErr(pctxt,
7480 XML_SCHEMAP_SRC_ATTRIBUTE_3_2,
7481 NULL, node, child, NULL,
7484 xmlSchemaPContentErr(pctxt,
7485 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
7486 NULL, node, child, NULL,
7490 if (IS_SCHEMA(child, "simpleType")) {
7491 if (WXS_ATTRUSE_DECL(use)->typeName != NULL) {
7494 * type and <simpleType> must not both be present.
7496 xmlSchemaPContentErr(pctxt, XML_SCHEMAP_SRC_ATTRIBUTE_4,
7498 "The attribute 'type' and the <simpleType> child "
7499 "are mutually exclusive", NULL);
7501 WXS_ATTRUSE_TYPEDEF(use) =
7502 xmlSchemaParseSimpleType(pctxt, schema, child, 0);
7503 child = child->next;
7506 xmlSchemaPContentErr(pctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
7507 NULL, node, child, NULL,
7508 "(annotation?, simpleType?)");
7511 return (WXS_BASIC_CAST use);
7515 static xmlSchemaAttributePtr
7516 xmlSchemaParseGlobalAttribute(xmlSchemaParserCtxtPtr pctxt,
7517 xmlSchemaPtr schema,
7520 const xmlChar *attrValue;
7521 xmlSchemaAttributePtr ret;
7522 xmlNodePtr child = NULL;
7526 * Note that the w3c spec assumes the schema to be validated with schema
7527 * for schemas beforehand.
7529 * 3.2.3 Constraints on XML Representations of Attribute Declarations
7531 if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
7535 * One of ref or name must be present, but not both
7537 attr = xmlSchemaGetPropNode(node, "name");
7539 xmlSchemaPMissingAttrErr(pctxt, XML_SCHEMAP_S4S_ATTR_MISSING,
7540 NULL, node, "name", NULL);
7543 if (xmlSchemaPValAttrNode(pctxt, NULL, attr,
7544 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &attrValue) != 0) {
7548 * 3.2.6 Schema Component Constraint: xmlns Not Allowed
7549 * TODO: Move this to the component layer.
7551 if (xmlStrEqual(attrValue, BAD_CAST "xmlns")) {
7552 xmlSchemaPSimpleTypeErr(pctxt,
7553 XML_SCHEMAP_NO_XMLNS,
7554 NULL, (xmlNodePtr) attr,
7555 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), NULL, NULL,
7556 "The value of the attribute must not match 'xmlns'",
7561 * 3.2.6 Schema Component Constraint: xsi: Not Allowed
7562 * TODO: Move this to the component layer.
7563 * Or better leave it here and add it to the component layer
7564 * if we have a schema construction API.
7566 if (xmlStrEqual(pctxt->targetNamespace, xmlSchemaInstanceNs)) {
7567 xmlSchemaCustomErr(ACTXT_CAST pctxt,
7568 XML_SCHEMAP_NO_XSI, node, NULL,
7569 "The target namespace must not match '%s'",
7570 xmlSchemaInstanceNs, NULL);
7573 ret = xmlSchemaAddAttribute(pctxt, schema, attrValue,
7574 pctxt->targetNamespace, node, 1);
7577 ret->flags |= XML_SCHEMAS_ATTR_GLOBAL;
7580 * Check for illegal attributes.
7582 attr = node->properties;
7583 while (attr != NULL) {
7584 if (attr->ns == NULL) {
7585 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
7586 (!xmlStrEqual(attr->name, BAD_CAST "default")) &&
7587 (!xmlStrEqual(attr->name, BAD_CAST "fixed")) &&
7588 (!xmlStrEqual(attr->name, BAD_CAST "name")) &&
7589 (!xmlStrEqual(attr->name, BAD_CAST "type")))
7591 xmlSchemaPIllegalAttrErr(pctxt,
7592 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
7594 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
7595 xmlSchemaPIllegalAttrErr(pctxt,
7596 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
7600 xmlSchemaPValAttrQName(pctxt, schema, NULL,
7601 node, "type", &ret->typeNs, &ret->typeName);
7603 xmlSchemaPValAttrID(pctxt, node, BAD_CAST "id");
7605 * Attribute "fixed".
7607 ret->defValue = xmlSchemaGetProp(pctxt, node, "fixed");
7608 if (ret->defValue != NULL)
7609 ret->flags |= XML_SCHEMAS_ATTR_FIXED;
7611 * Attribute "default".
7613 attr = xmlSchemaGetPropNode(node, "default");
7617 * default and fixed must not both be present.
7619 if (ret->flags & XML_SCHEMAS_ATTR_FIXED) {
7620 xmlSchemaPMutualExclAttrErr(pctxt, XML_SCHEMAP_SRC_ATTRIBUTE_1,
7621 WXS_BASIC_CAST ret, attr, "default", "fixed");
7623 ret->defValue = xmlSchemaGetNodeContent(pctxt, (xmlNodePtr) attr);
7626 * And now for the children...
7628 child = node->children;
7629 if (IS_SCHEMA(child, "annotation")) {
7630 ret->annot = xmlSchemaParseAnnotation(pctxt, child, 1);
7631 child = child->next;
7633 if (IS_SCHEMA(child, "simpleType")) {
7634 if (ret->typeName != NULL) {
7637 * type and <simpleType> must not both be present.
7639 xmlSchemaPContentErr(pctxt, XML_SCHEMAP_SRC_ATTRIBUTE_4,
7641 "The attribute 'type' and the <simpleType> child "
7642 "are mutually exclusive", NULL);
7644 ret->subtypes = xmlSchemaParseSimpleType(pctxt, schema, child, 0);
7645 child = child->next;
7648 xmlSchemaPContentErr(pctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
7649 NULL, node, child, NULL,
7650 "(annotation?, simpleType?)");
7656 * xmlSchemaParseAttributeGroupRef:
7657 * @ctxt: a schema validation context
7658 * @schema: the schema being built
7659 * @node: a subtree containing XML Schema informations
7661 * Parse an attribute group definition reference.
7662 * Note that a reference to an attribute group does not
7663 * correspond to any component at all.
7664 * *WARNING* this interface is highly subject to change
7666 * Returns the attribute group or NULL in case of error.
7668 static xmlSchemaQNameRefPtr
7669 xmlSchemaParseAttributeGroupRef(xmlSchemaParserCtxtPtr pctxt,
7670 xmlSchemaPtr schema,
7673 xmlSchemaQNameRefPtr ret;
7674 xmlNodePtr child = NULL;
7676 const xmlChar *refNs = NULL, *ref = NULL;
7678 if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
7681 attr = xmlSchemaGetPropNode(node, "ref");
7683 xmlSchemaPMissingAttrErr(pctxt,
7684 XML_SCHEMAP_S4S_ATTR_MISSING,
7685 NULL, node, "ref", NULL);
7688 xmlSchemaPValAttrNodeQName(pctxt, schema,
7689 NULL, attr, &refNs, &ref);
7690 if (xmlSchemaCheckReference(pctxt, schema, node, attr, refNs) != 0)
7694 * Check for illegal attributes.
7696 attr = node->properties;
7697 while (attr != NULL) {
7698 if (attr->ns == NULL) {
7699 if ((!xmlStrEqual(attr->name, BAD_CAST "ref")) &&
7700 (!xmlStrEqual(attr->name, BAD_CAST "id")))
7702 xmlSchemaPIllegalAttrErr(pctxt,
7703 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
7705 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
7706 xmlSchemaPIllegalAttrErr(pctxt,
7707 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
7712 xmlSchemaPValAttrID(pctxt, node, BAD_CAST "id");
7715 * And now for the children...
7717 child = node->children;
7718 if (IS_SCHEMA(child, "annotation")) {
7720 * TODO: We do not have a place to store the annotation, do we?
7722 xmlSchemaParseAnnotation(pctxt, child, 0);
7723 child = child->next;
7725 if (child != NULL) {
7726 xmlSchemaPContentErr(pctxt,
7727 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
7728 NULL, node, child, NULL,
7733 * Handle attribute group redefinitions.
7735 if (pctxt->isRedefine && pctxt->redef &&
7736 (pctxt->redef->item->type ==
7737 XML_SCHEMA_TYPE_ATTRIBUTEGROUP) &&
7738 (ref == pctxt->redef->refName) &&
7739 (refNs == pctxt->redef->refTargetNs))
7742 * SPEC src-redefine:
7743 * (7.1) "If it has an <attributeGroup> among its contents
7744 * the `actual value` of whose ref [attribute] is the same
7745 * as the `actual value` of its own name attribute plus
7746 * target namespace, then it must have exactly one such group."
7748 if (pctxt->redefCounter != 0) {
7749 xmlChar *str = NULL;
7751 xmlSchemaCustomErr(ACTXT_CAST pctxt,
7752 XML_SCHEMAP_SRC_REDEFINE, node, NULL,
7753 "The redefining attribute group definition "
7754 "'%s' must not contain more than one "
7755 "reference to the redefined definition",
7756 xmlSchemaFormatQName(&str, refNs, ref), NULL);
7760 pctxt->redefCounter++;
7762 * URGENT TODO: How to ensure that the reference will not be
7763 * handled by the normal component resolution mechanism?
7765 ret = xmlSchemaNewQNameRef(pctxt,
7766 XML_SCHEMA_TYPE_ATTRIBUTEGROUP, ref, refNs);
7770 pctxt->redef->reference = WXS_BASIC_CAST ret;
7773 * Create a QName-reference helper component. We will substitute this
7774 * component for the attribute uses of the referenced attribute group
7777 ret = xmlSchemaNewQNameRef(pctxt,
7778 XML_SCHEMA_TYPE_ATTRIBUTEGROUP, ref, refNs);
7782 /* Add to pending items, to be able to resolve the reference. */
7783 WXS_ADD_PENDING(pctxt, ret);
7789 * xmlSchemaParseAttributeGroupDefinition:
7790 * @pctxt: a schema validation context
7791 * @schema: the schema being built
7792 * @node: a subtree containing XML Schema informations
7794 * parse a XML schema Attribute Group declaration
7795 * *WARNING* this interface is highly subject to change
7797 * Returns the attribute group definition or NULL in case of error.
7799 static xmlSchemaAttributeGroupPtr
7800 xmlSchemaParseAttributeGroupDefinition(xmlSchemaParserCtxtPtr pctxt,
7801 xmlSchemaPtr schema,
7804 const xmlChar *name;
7805 xmlSchemaAttributeGroupPtr ret;
7806 xmlNodePtr child = NULL;
7810 if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
7813 attr = xmlSchemaGetPropNode(node, "name");
7815 xmlSchemaPMissingAttrErr(pctxt,
7816 XML_SCHEMAP_S4S_ATTR_MISSING,
7817 NULL, node, "name", NULL);
7821 * The name is crucial, exit if invalid.
7823 if (xmlSchemaPValAttrNode(pctxt,
7825 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) {
7828 ret = xmlSchemaAddAttributeGroupDefinition(pctxt, schema,
7829 name, pctxt->targetNamespace, node);
7833 * Check for illegal attributes.
7835 attr = node->properties;
7836 while (attr != NULL) {
7837 if (attr->ns == NULL) {
7838 if ((!xmlStrEqual(attr->name, BAD_CAST "name")) &&
7839 (!xmlStrEqual(attr->name, BAD_CAST "id")))
7841 xmlSchemaPIllegalAttrErr(pctxt,
7842 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
7844 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
7845 xmlSchemaPIllegalAttrErr(pctxt,
7846 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
7851 xmlSchemaPValAttrID(pctxt, node, BAD_CAST "id");
7853 * And now for the children...
7855 child = node->children;
7856 if (IS_SCHEMA(child, "annotation")) {
7857 ret->annot = xmlSchemaParseAnnotation(pctxt, child, 1);
7858 child = child->next;
7861 * Parse contained attribute decls/refs.
7863 if (xmlSchemaParseLocalAttributes(pctxt, schema, &child,
7864 (xmlSchemaItemListPtr *) &(ret->attrUses),
7865 XML_SCHEMA_TYPE_ATTRIBUTEGROUP, &hasRefs) == -1)
7868 ret->flags |= XML_SCHEMAS_ATTRGROUP_HAS_REFS;
7870 * Parse the attribute wildcard.
7872 if (IS_SCHEMA(child, "anyAttribute")) {
7873 ret->attributeWildcard = xmlSchemaParseAnyAttribute(pctxt,
7875 child = child->next;
7877 if (child != NULL) {
7878 xmlSchemaPContentErr(pctxt,
7879 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
7880 NULL, node, child, NULL,
7881 "(annotation?, ((attribute | attributeGroup)*, anyAttribute?))");
7887 * xmlSchemaPValAttrFormDefault:
7889 * @flags: the flags to be modified
7890 * @flagQualified: the specific flag for "qualified"
7892 * Returns 0 if the value is valid, 1 otherwise.
7895 xmlSchemaPValAttrFormDefault(const xmlChar *value,
7899 if (xmlStrEqual(value, BAD_CAST "qualified")) {
7900 if ((*flags & flagQualified) == 0)
7901 *flags |= flagQualified;
7902 } else if (!xmlStrEqual(value, BAD_CAST "unqualified"))
7909 * xmlSchemaPValAttrBlockFinal:
7911 * @flags: the flags to be modified
7912 * @flagAll: the specific flag for "#all"
7913 * @flagExtension: the specific flag for "extension"
7914 * @flagRestriction: the specific flag for "restriction"
7915 * @flagSubstitution: the specific flag for "substitution"
7916 * @flagList: the specific flag for "list"
7917 * @flagUnion: the specific flag for "union"
7919 * Validates the value of the attribute "final" and "block". The value
7920 * is converted into the specified flag values and returned in @flags.
7922 * Returns 0 if the value is valid, 1 otherwise.
7926 xmlSchemaPValAttrBlockFinal(const xmlChar *value,
7930 int flagRestriction,
7931 int flagSubstitution,
7938 * TODO: This does not check for dublicate entries.
7940 if ((flags == NULL) || (value == NULL))
7944 if (xmlStrEqual(value, BAD_CAST "#all")) {
7948 if (flagExtension != -1)
7949 *flags |= flagExtension;
7950 if (flagRestriction != -1)
7951 *flags |= flagRestriction;
7952 if (flagSubstitution != -1)
7953 *flags |= flagSubstitution;
7956 if (flagUnion != -1)
7957 *flags |= flagUnion;
7960 const xmlChar *end, *cur = value;
7964 while (IS_BLANK_CH(*cur))
7967 while ((*end != 0) && (!(IS_BLANK_CH(*end))))
7971 item = xmlStrndup(cur, end - cur);
7972 if (xmlStrEqual(item, BAD_CAST "extension")) {
7973 if (flagExtension != -1) {
7974 if ((*flags & flagExtension) == 0)
7975 *flags |= flagExtension;
7978 } else if (xmlStrEqual(item, BAD_CAST "restriction")) {
7979 if (flagRestriction != -1) {
7980 if ((*flags & flagRestriction) == 0)
7981 *flags |= flagRestriction;
7984 } else if (xmlStrEqual(item, BAD_CAST "substitution")) {
7985 if (flagSubstitution != -1) {
7986 if ((*flags & flagSubstitution) == 0)
7987 *flags |= flagSubstitution;
7990 } else if (xmlStrEqual(item, BAD_CAST "list")) {
7991 if (flagList != -1) {
7992 if ((*flags & flagList) == 0)
7996 } else if (xmlStrEqual(item, BAD_CAST "union")) {
7997 if (flagUnion != -1) {
7998 if ((*flags & flagUnion) == 0)
7999 *flags |= flagUnion;
8007 } while ((ret == 0) && (*cur != 0));
8014 xmlSchemaCheckCSelectorXPath(xmlSchemaParserCtxtPtr ctxt,
8015 xmlSchemaIDCPtr idc,
8016 xmlSchemaIDCSelectPtr selector,
8024 * Schema Component Constraint: Selector Value OK
8026 * TODO: 1 The {selector} must be a valid XPath expression, as defined
8029 if (selector == NULL) {
8030 xmlSchemaPErr(ctxt, idc->node,
8031 XML_SCHEMAP_INTERNAL,
8032 "Internal error: xmlSchemaCheckCSelectorXPath, "
8033 "the selector is not specified.\n", NULL, NULL);
8039 node = (xmlNodePtr) attr;
8040 if (selector->xpath == NULL) {
8041 xmlSchemaPCustomErr(ctxt,
8042 /* TODO: Adjust error code. */
8043 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
8045 "The XPath expression of the selector is not valid", NULL);
8046 return (XML_SCHEMAP_S4S_ATTR_INVALID_VALUE);
8048 const xmlChar **nsArray = NULL;
8049 xmlNsPtr *nsList = NULL;
8051 * Compile the XPath expression.
8054 * TODO: We need the array of in-scope namespaces for compilation.
8055 * TODO: Call xmlPatterncompile with different options for selector/
8061 nsList = xmlGetNsList(attr->doc, attr->parent);
8063 * Build an array of prefixes and namespaces.
8065 if (nsList != NULL) {
8068 for (i = 0; nsList[i] != NULL; i++)
8071 nsArray = (const xmlChar **) xmlMalloc(
8072 (count * 2 + 1) * sizeof(const xmlChar *));
8073 if (nsArray == NULL) {
8074 xmlSchemaPErrMemory(ctxt, "allocating a namespace array",
8079 for (i = 0; i < count; i++) {
8080 nsArray[2 * i] = nsList[i]->href;
8081 nsArray[2 * i + 1] = nsList[i]->prefix;
8083 nsArray[count * 2] = NULL;
8087 * TODO: Differentiate between "selector" and "field".
8090 selector->xpathComp = (void *) xmlPatterncompile(selector->xpath,
8091 NULL, XML_PATTERN_XSFIELD, nsArray);
8093 selector->xpathComp = (void *) xmlPatterncompile(selector->xpath,
8094 NULL, XML_PATTERN_XSSEL, nsArray);
8095 if (nsArray != NULL)
8096 xmlFree((xmlChar **) nsArray);
8098 if (selector->xpathComp == NULL) {
8099 xmlSchemaPCustomErr(ctxt,
8100 /* TODO: Adjust error code? */
8101 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
8103 "The XPath expression '%s' could not be "
8104 "compiled", selector->xpath);
8105 return (XML_SCHEMAP_S4S_ATTR_INVALID_VALUE);
8111 #define ADD_ANNOTATION(annot) \
8112 xmlSchemaAnnotPtr cur = item->annot; \
8113 if (item->annot == NULL) { \
8114 item->annot = annot; \
8117 cur = item->annot; \
8118 if (cur->next != NULL) { \
8124 * xmlSchemaAssignAnnotation:
8125 * @item: the schema component
8126 * @annot: the annotation
8128 * Adds the annotation to the given schema component.
8130 * Returns the given annotaion.
8132 static xmlSchemaAnnotPtr
8133 xmlSchemaAddAnnotation(xmlSchemaAnnotItemPtr annItem,
8134 xmlSchemaAnnotPtr annot)
8136 if ((annItem == NULL) || (annot == NULL))
8138 switch (annItem->type) {
8139 case XML_SCHEMA_TYPE_ELEMENT: {
8140 xmlSchemaElementPtr item = (xmlSchemaElementPtr) annItem;
8141 ADD_ANNOTATION(annot)
8144 case XML_SCHEMA_TYPE_ATTRIBUTE: {
8145 xmlSchemaAttributePtr item = (xmlSchemaAttributePtr) annItem;
8146 ADD_ANNOTATION(annot)
8149 case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
8150 case XML_SCHEMA_TYPE_ANY: {
8151 xmlSchemaWildcardPtr item = (xmlSchemaWildcardPtr) annItem;
8152 ADD_ANNOTATION(annot)
8155 case XML_SCHEMA_TYPE_PARTICLE:
8156 case XML_SCHEMA_TYPE_IDC_KEY:
8157 case XML_SCHEMA_TYPE_IDC_KEYREF:
8158 case XML_SCHEMA_TYPE_IDC_UNIQUE: {
8159 xmlSchemaAnnotItemPtr item = (xmlSchemaAnnotItemPtr) annItem;
8160 ADD_ANNOTATION(annot)
8163 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: {
8164 xmlSchemaAttributeGroupPtr item =
8165 (xmlSchemaAttributeGroupPtr) annItem;
8166 ADD_ANNOTATION(annot)
8169 case XML_SCHEMA_TYPE_NOTATION: {
8170 xmlSchemaNotationPtr item = (xmlSchemaNotationPtr) annItem;
8171 ADD_ANNOTATION(annot)
8174 case XML_SCHEMA_FACET_MININCLUSIVE:
8175 case XML_SCHEMA_FACET_MINEXCLUSIVE:
8176 case XML_SCHEMA_FACET_MAXINCLUSIVE:
8177 case XML_SCHEMA_FACET_MAXEXCLUSIVE:
8178 case XML_SCHEMA_FACET_TOTALDIGITS:
8179 case XML_SCHEMA_FACET_FRACTIONDIGITS:
8180 case XML_SCHEMA_FACET_PATTERN:
8181 case XML_SCHEMA_FACET_ENUMERATION:
8182 case XML_SCHEMA_FACET_WHITESPACE:
8183 case XML_SCHEMA_FACET_LENGTH:
8184 case XML_SCHEMA_FACET_MAXLENGTH:
8185 case XML_SCHEMA_FACET_MINLENGTH: {
8186 xmlSchemaFacetPtr item = (xmlSchemaFacetPtr) annItem;
8187 ADD_ANNOTATION(annot)
8190 case XML_SCHEMA_TYPE_SIMPLE:
8191 case XML_SCHEMA_TYPE_COMPLEX: {
8192 xmlSchemaTypePtr item = (xmlSchemaTypePtr) annItem;
8193 ADD_ANNOTATION(annot)
8196 case XML_SCHEMA_TYPE_GROUP: {
8197 xmlSchemaModelGroupDefPtr item = (xmlSchemaModelGroupDefPtr) annItem;
8198 ADD_ANNOTATION(annot)
8201 case XML_SCHEMA_TYPE_SEQUENCE:
8202 case XML_SCHEMA_TYPE_CHOICE:
8203 case XML_SCHEMA_TYPE_ALL: {
8204 xmlSchemaModelGroupPtr item = (xmlSchemaModelGroupPtr) annItem;
8205 ADD_ANNOTATION(annot)
8209 xmlSchemaPCustomErr(NULL,
8210 XML_SCHEMAP_INTERNAL,
8212 "Internal error: xmlSchemaAddAnnotation, "
8213 "The item is not a annotated schema component", NULL);
8220 * xmlSchemaParseIDCSelectorAndField:
8221 * @ctxt: a schema validation context
8222 * @schema: the schema being built
8223 * @node: a subtree containing XML Schema informations
8225 * Parses a XML Schema identity-contraint definition's
8226 * <selector> and <field> elements.
8228 * Returns the parsed identity-constraint definition.
8230 static xmlSchemaIDCSelectPtr
8231 xmlSchemaParseIDCSelectorAndField(xmlSchemaParserCtxtPtr ctxt,
8232 xmlSchemaIDCPtr idc,
8236 xmlSchemaIDCSelectPtr item;
8237 xmlNodePtr child = NULL;
8241 * Check for illegal attributes.
8243 attr = node->properties;
8244 while (attr != NULL) {
8245 if (attr->ns == NULL) {
8246 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
8247 (!xmlStrEqual(attr->name, BAD_CAST "xpath"))) {
8248 xmlSchemaPIllegalAttrErr(ctxt,
8249 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
8251 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
8252 xmlSchemaPIllegalAttrErr(ctxt,
8253 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
8260 item = (xmlSchemaIDCSelectPtr) xmlMalloc(sizeof(xmlSchemaIDCSelect));
8262 xmlSchemaPErrMemory(ctxt,
8263 "allocating a 'selector' of an identity-constraint definition",
8267 memset(item, 0, sizeof(xmlSchemaIDCSelect));
8269 * Attribute "xpath" (mandatory).
8271 attr = xmlSchemaGetPropNode(node, "xpath");
8273 xmlSchemaPMissingAttrErr(ctxt,
8274 XML_SCHEMAP_S4S_ATTR_MISSING,
8278 item->xpath = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
8280 * URGENT TODO: "field"s have an other syntax than "selector"s.
8283 if (xmlSchemaCheckCSelectorXPath(ctxt, idc, item, attr,
8287 XML_SCHEMAP_INTERNAL,
8288 "Internal error: xmlSchemaParseIDCSelectorAndField, "
8289 "validating the XPath expression of a IDC selector.\n",
8294 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
8296 * And now for the children...
8298 child = node->children;
8299 if (IS_SCHEMA(child, "annotation")) {
8301 * Add the annotation to the parent IDC.
8303 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) idc,
8304 xmlSchemaParseAnnotation(ctxt, child, 1));
8305 child = child->next;
8307 if (child != NULL) {
8308 xmlSchemaPContentErr(ctxt,
8309 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
8311 NULL, "(annotation?)");
8318 * xmlSchemaParseIDC:
8319 * @ctxt: a schema validation context
8320 * @schema: the schema being built
8321 * @node: a subtree containing XML Schema informations
8323 * Parses a XML Schema identity-contraint definition.
8325 * Returns the parsed identity-constraint definition.
8327 static xmlSchemaIDCPtr
8328 xmlSchemaParseIDC(xmlSchemaParserCtxtPtr ctxt,
8329 xmlSchemaPtr schema,
8331 xmlSchemaTypeType idcCategory,
8332 const xmlChar *targetNamespace)
8334 xmlSchemaIDCPtr item = NULL;
8335 xmlNodePtr child = NULL;
8337 const xmlChar *name = NULL;
8338 xmlSchemaIDCSelectPtr field = NULL, lastField = NULL;
8341 * Check for illegal attributes.
8343 attr = node->properties;
8344 while (attr != NULL) {
8345 if (attr->ns == NULL) {
8346 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
8347 (!xmlStrEqual(attr->name, BAD_CAST "name")) &&
8348 ((idcCategory != XML_SCHEMA_TYPE_IDC_KEYREF) ||
8349 (!xmlStrEqual(attr->name, BAD_CAST "refer")))) {
8350 xmlSchemaPIllegalAttrErr(ctxt,
8351 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
8353 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
8354 xmlSchemaPIllegalAttrErr(ctxt,
8355 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
8360 * Attribute "name" (mandatory).
8362 attr = xmlSchemaGetPropNode(node, "name");
8364 xmlSchemaPMissingAttrErr(ctxt,
8365 XML_SCHEMAP_S4S_ATTR_MISSING,
8369 } else if (xmlSchemaPValAttrNode(ctxt,
8371 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) {
8374 /* Create the component. */
8375 item = xmlSchemaAddIDC(ctxt, schema, name, targetNamespace,
8380 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
8381 if (idcCategory == XML_SCHEMA_TYPE_IDC_KEYREF) {
8383 * Attribute "refer" (mandatory).
8385 attr = xmlSchemaGetPropNode(node, "refer");
8387 xmlSchemaPMissingAttrErr(ctxt,
8388 XML_SCHEMAP_S4S_ATTR_MISSING,
8393 * Create a reference item.
8395 item->ref = xmlSchemaNewQNameRef(ctxt, XML_SCHEMA_TYPE_IDC_KEY,
8397 if (item->ref == NULL)
8399 xmlSchemaPValAttrNodeQName(ctxt, schema,
8401 &(item->ref->targetNamespace),
8402 &(item->ref->name));
8403 xmlSchemaCheckReference(ctxt, schema, node, attr,
8404 item->ref->targetNamespace);
8408 * And now for the children...
8410 child = node->children;
8411 if (IS_SCHEMA(child, "annotation")) {
8412 item->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
8413 child = child->next;
8415 if (child == NULL) {
8416 xmlSchemaPContentErr(ctxt,
8417 XML_SCHEMAP_S4S_ELEM_MISSING,
8419 "A child element is missing",
8420 "(annotation?, (selector, field+))");
8423 * Child element <selector>.
8425 if (IS_SCHEMA(child, "selector")) {
8426 item->selector = xmlSchemaParseIDCSelectorAndField(ctxt,
8428 child = child->next;
8430 * Child elements <field>.
8432 if (IS_SCHEMA(child, "field")) {
8434 field = xmlSchemaParseIDCSelectorAndField(ctxt,
8436 if (field != NULL) {
8437 field->index = item->nbFields;
8439 if (lastField != NULL)
8440 lastField->next = field;
8442 item->fields = field;
8445 child = child->next;
8446 } while (IS_SCHEMA(child, "field"));
8448 xmlSchemaPContentErr(ctxt,
8449 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
8451 NULL, "(annotation?, (selector, field+))");
8454 if (child != NULL) {
8455 xmlSchemaPContentErr(ctxt,
8456 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
8458 NULL, "(annotation?, (selector, field+))");
8465 * xmlSchemaParseElement:
8466 * @ctxt: a schema validation context
8467 * @schema: the schema being built
8468 * @node: a subtree containing XML Schema informations
8469 * @topLevel: indicates if this is global declaration
8471 * Parses a XML schema element declaration.
8472 * *WARNING* this interface is highly subject to change
8474 * Returns the element declaration or a particle; NULL in case
8475 * of an error or if the particle has minOccurs==maxOccurs==0.
8477 static xmlSchemaBasicItemPtr
8478 xmlSchemaParseElement(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
8479 xmlNodePtr node, int *isElemRef, int topLevel)
8481 xmlSchemaElementPtr decl = NULL;
8482 xmlSchemaParticlePtr particle = NULL;
8483 xmlSchemaAnnotPtr annot = NULL;
8484 xmlNodePtr child = NULL;
8485 xmlAttrPtr attr, nameAttr;
8486 int min, max, isRef = 0;
8487 xmlChar *des = NULL;
8489 /* 3.3.3 Constraints on XML Representations of Element Declarations */
8490 /* TODO: Complete implementation of 3.3.6 */
8492 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
8495 if (isElemRef != NULL)
8498 * If we get a "ref" attribute on a local <element> we will assume it's
8499 * a reference - even if there's a "name" attribute; this seems to be more
8502 nameAttr = xmlSchemaGetPropNode(node, "name");
8503 attr = xmlSchemaGetPropNode(node, "ref");
8504 if ((topLevel) || (attr == NULL)) {
8505 if (nameAttr == NULL) {
8506 xmlSchemaPMissingAttrErr(ctxt,
8507 XML_SCHEMAP_S4S_ATTR_MISSING,
8508 NULL, node, "name", NULL);
8514 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
8515 child = node->children;
8516 if (IS_SCHEMA(child, "annotation")) {
8517 annot = xmlSchemaParseAnnotation(ctxt, child, 1);
8518 child = child->next;
8521 * Skip particle part if a global declaration.
8524 goto declaration_part;
8526 * The particle part ==================================================
8528 min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "xs:nonNegativeInteger");
8529 max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, "(xs:nonNegativeInteger | unbounded)");
8530 xmlSchemaPCheckParticleCorrect_2(ctxt, NULL, node, min, max);
8531 particle = xmlSchemaAddParticle(ctxt, node, min, max);
8532 if (particle == NULL)
8535 /* ret->flags |= XML_SCHEMAS_ELEM_REF; */
8538 const xmlChar *refNs = NULL, *ref = NULL;
8539 xmlSchemaQNameRefPtr refer = NULL;
8541 * The reference part =============================================
8543 if (isElemRef != NULL)
8546 xmlSchemaPValAttrNodeQName(ctxt, schema,
8547 NULL, attr, &refNs, &ref);
8548 xmlSchemaCheckReference(ctxt, schema, node, attr, refNs);
8550 * SPEC (3.3.3 : 2.1) "One of ref or name must be present, but not both"
8552 if (nameAttr != NULL) {
8553 xmlSchemaPMutualExclAttrErr(ctxt,
8554 XML_SCHEMAP_SRC_ELEMENT_2_1, NULL, nameAttr, "ref", "name");
8557 * Check for illegal attributes.
8559 attr = node->properties;
8560 while (attr != NULL) {
8561 if (attr->ns == NULL) {
8562 if (xmlStrEqual(attr->name, BAD_CAST "ref") ||
8563 xmlStrEqual(attr->name, BAD_CAST "name") ||
8564 xmlStrEqual(attr->name, BAD_CAST "id") ||
8565 xmlStrEqual(attr->name, BAD_CAST "maxOccurs") ||
8566 xmlStrEqual(attr->name, BAD_CAST "minOccurs"))
8571 /* SPEC (3.3.3 : 2.2) */
8572 xmlSchemaPCustomAttrErr(ctxt,
8573 XML_SCHEMAP_SRC_ELEMENT_2_2,
8575 "Only the attributes 'minOccurs', 'maxOccurs' and "
8576 "'id' are allowed in addition to 'ref'");
8579 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
8580 xmlSchemaPIllegalAttrErr(ctxt,
8581 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
8586 * No children except <annotation> expected.
8588 if (child != NULL) {
8589 xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
8590 NULL, node, child, NULL, "(annotation?)");
8592 if ((min == 0) && (max == 0))
8595 * Create the reference item and attach it to the particle.
8597 refer = xmlSchemaNewQNameRef(ctxt, XML_SCHEMA_TYPE_ELEMENT,
8601 particle->children = (xmlSchemaTreeItemPtr) refer;
8602 particle->annot = annot;
8604 * Add the particle to pending components, since the reference
8605 * need to be resolved.
8607 WXS_ADD_PENDING(ctxt, particle);
8608 return ((xmlSchemaBasicItemPtr) particle);
8611 * The declaration part ===============================================
8615 const xmlChar *ns = NULL, *fixed, *name, *attrValue;
8616 xmlSchemaIDCPtr curIDC = NULL, lastIDC = NULL;
8618 if (xmlSchemaPValAttrNode(ctxt, NULL, nameAttr,
8619 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0)
8622 * Evaluate the target namespace.
8625 ns = ctxt->targetNamespace;
8627 attr = xmlSchemaGetPropNode(node, "form");
8629 attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
8630 if (xmlStrEqual(attrValue, BAD_CAST "qualified")) {
8631 ns = ctxt->targetNamespace;
8632 } else if (!xmlStrEqual(attrValue, BAD_CAST "unqualified")) {
8633 xmlSchemaPSimpleTypeErr(ctxt,
8634 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
8635 NULL, (xmlNodePtr) attr,
8636 NULL, "(qualified | unqualified)",
8637 attrValue, NULL, NULL, NULL);
8639 } else if (schema->flags & XML_SCHEMAS_QUALIF_ELEM)
8640 ns = ctxt->targetNamespace;
8642 decl = xmlSchemaAddElement(ctxt, name, ns, node, topLevel);
8647 * Check for illegal attributes.
8649 attr = node->properties;
8650 while (attr != NULL) {
8651 if (attr->ns == NULL) {
8652 if ((!xmlStrEqual(attr->name, BAD_CAST "name")) &&
8653 (!xmlStrEqual(attr->name, BAD_CAST "type")) &&
8654 (!xmlStrEqual(attr->name, BAD_CAST "id")) &&
8655 (!xmlStrEqual(attr->name, BAD_CAST "default")) &&
8656 (!xmlStrEqual(attr->name, BAD_CAST "fixed")) &&
8657 (!xmlStrEqual(attr->name, BAD_CAST "block")) &&
8658 (!xmlStrEqual(attr->name, BAD_CAST "nillable")))
8660 if (topLevel == 0) {
8661 if ((!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) &&
8662 (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) &&
8663 (!xmlStrEqual(attr->name, BAD_CAST "form")))
8665 xmlSchemaPIllegalAttrErr(ctxt,
8666 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
8668 } else if ((!xmlStrEqual(attr->name, BAD_CAST "final")) &&
8669 (!xmlStrEqual(attr->name, BAD_CAST "abstract")) &&
8670 (!xmlStrEqual(attr->name, BAD_CAST "substitutionGroup"))) {
8672 xmlSchemaPIllegalAttrErr(ctxt,
8673 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
8676 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
8678 xmlSchemaPIllegalAttrErr(ctxt,
8679 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
8684 * Extract/validate attributes.
8688 * Process top attributes of global element declarations here.
8690 decl->flags |= XML_SCHEMAS_ELEM_GLOBAL;
8691 decl->flags |= XML_SCHEMAS_ELEM_TOPLEVEL;
8692 xmlSchemaPValAttrQName(ctxt, schema,
8693 NULL, node, "substitutionGroup",
8694 &(decl->substGroupNs), &(decl->substGroup));
8695 if (xmlGetBooleanProp(ctxt, node, "abstract", 0))
8696 decl->flags |= XML_SCHEMAS_ELEM_ABSTRACT;
8698 * Attribute "final".
8700 attr = xmlSchemaGetPropNode(node, "final");
8702 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION)
8703 decl->flags |= XML_SCHEMAS_ELEM_FINAL_EXTENSION;
8704 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION)
8705 decl->flags |= XML_SCHEMAS_ELEM_FINAL_RESTRICTION;
8707 attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
8708 if (xmlSchemaPValAttrBlockFinal(attrValue, &(decl->flags),
8710 XML_SCHEMAS_ELEM_FINAL_EXTENSION,
8711 XML_SCHEMAS_ELEM_FINAL_RESTRICTION, -1, -1, -1) != 0) {
8712 xmlSchemaPSimpleTypeErr(ctxt,
8713 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
8714 NULL, (xmlNodePtr) attr,
8715 NULL, "(#all | List of (extension | restriction))",
8716 attrValue, NULL, NULL, NULL);
8721 * Attribute "block".
8723 attr = xmlSchemaGetPropNode(node, "block");
8726 * Apply default "block" values.
8728 if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION)
8729 decl->flags |= XML_SCHEMAS_ELEM_BLOCK_RESTRICTION;
8730 if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION)
8731 decl->flags |= XML_SCHEMAS_ELEM_BLOCK_EXTENSION;
8732 if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION)
8733 decl->flags |= XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION;
8735 attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
8736 if (xmlSchemaPValAttrBlockFinal(attrValue, &(decl->flags),
8738 XML_SCHEMAS_ELEM_BLOCK_EXTENSION,
8739 XML_SCHEMAS_ELEM_BLOCK_RESTRICTION,
8740 XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION, -1, -1) != 0) {
8741 xmlSchemaPSimpleTypeErr(ctxt,
8742 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
8743 NULL, (xmlNodePtr) attr,
8744 NULL, "(#all | List of (extension | "
8745 "restriction | substitution))", attrValue,
8749 if (xmlGetBooleanProp(ctxt, node, "nillable", 0))
8750 decl->flags |= XML_SCHEMAS_ELEM_NILLABLE;
8752 attr = xmlSchemaGetPropNode(node, "type");
8754 xmlSchemaPValAttrNodeQName(ctxt, schema,
8756 &(decl->namedTypeNs), &(decl->namedType));
8757 xmlSchemaCheckReference(ctxt, schema, node,
8758 attr, decl->namedTypeNs);
8760 decl->value = xmlSchemaGetProp(ctxt, node, "default");
8761 attr = xmlSchemaGetPropNode(node, "fixed");
8763 fixed = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
8764 if (decl->value != NULL) {
8767 * default and fixed must not both be present.
8769 xmlSchemaPMutualExclAttrErr(ctxt,
8770 XML_SCHEMAP_SRC_ELEMENT_1,
8771 NULL, attr, "default", "fixed");
8773 decl->flags |= XML_SCHEMAS_ELEM_FIXED;
8774 decl->value = fixed;
8778 * And now for the children...
8780 if (IS_SCHEMA(child, "complexType")) {
8783 * "type" and either <simpleType> or <complexType> are mutually
8786 if (decl->namedType != NULL) {
8787 xmlSchemaPContentErr(ctxt,
8788 XML_SCHEMAP_SRC_ELEMENT_3,
8790 "The attribute 'type' and the <complexType> child are "
8791 "mutually exclusive", NULL);
8793 WXS_ELEM_TYPEDEF(decl) = xmlSchemaParseComplexType(ctxt, schema, child, 0);
8794 child = child->next;
8795 } else if (IS_SCHEMA(child, "simpleType")) {
8798 * "type" and either <simpleType> or <complexType> are
8799 * mutually exclusive
8801 if (decl->namedType != NULL) {
8802 xmlSchemaPContentErr(ctxt,
8803 XML_SCHEMAP_SRC_ELEMENT_3,
8805 "The attribute 'type' and the <simpleType> child are "
8806 "mutually exclusive", NULL);
8808 WXS_ELEM_TYPEDEF(decl) = xmlSchemaParseSimpleType(ctxt, schema, child, 0);
8809 child = child->next;
8811 while ((IS_SCHEMA(child, "unique")) ||
8812 (IS_SCHEMA(child, "key")) || (IS_SCHEMA(child, "keyref"))) {
8813 if (IS_SCHEMA(child, "unique")) {
8814 curIDC = xmlSchemaParseIDC(ctxt, schema, child,
8815 XML_SCHEMA_TYPE_IDC_UNIQUE, decl->targetNamespace);
8816 } else if (IS_SCHEMA(child, "key")) {
8817 curIDC = xmlSchemaParseIDC(ctxt, schema, child,
8818 XML_SCHEMA_TYPE_IDC_KEY, decl->targetNamespace);
8819 } else if (IS_SCHEMA(child, "keyref")) {
8820 curIDC = xmlSchemaParseIDC(ctxt, schema, child,
8821 XML_SCHEMA_TYPE_IDC_KEYREF, decl->targetNamespace);
8823 if (lastIDC != NULL)
8824 lastIDC->next = curIDC;
8826 decl->idcs = (void *) curIDC;
8828 child = child->next;
8830 if (child != NULL) {
8831 xmlSchemaPContentErr(ctxt,
8832 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
8834 NULL, "(annotation?, ((simpleType | complexType)?, "
8835 "(unique | key | keyref)*))");
8837 decl->annot = annot;
8840 * NOTE: Element Declaration Representation OK 4. will be checked at a
8845 return ((xmlSchemaBasicItemPtr) decl);
8847 particle->children = (xmlSchemaTreeItemPtr) decl;
8848 return ((xmlSchemaBasicItemPtr) particle);
8853 if (annot != NULL) {
8854 if (particle != NULL)
8855 particle->annot = NULL;
8858 xmlSchemaFreeAnnot(annot);
8864 * xmlSchemaParseUnion:
8865 * @ctxt: a schema validation context
8866 * @schema: the schema being built
8867 * @node: a subtree containing XML Schema informations
8869 * parse a XML schema Union definition
8870 * *WARNING* this interface is highly subject to change
8872 * Returns -1 in case of internal error, 0 in case of success and a positive
8873 * error code otherwise.
8876 xmlSchemaParseUnion(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
8879 xmlSchemaTypePtr type;
8880 xmlNodePtr child = NULL;
8882 const xmlChar *cur = NULL;
8884 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
8886 /* Not a component, don't create it. */
8887 type = ctxt->ctxtType;
8889 * Mark the simple type as being of variety "union".
8891 type->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION;
8893 * SPEC (Base type) (2) "If the <list> or <union> alternative is chosen,
8894 * then the `simple ur-type definition`."
8896 type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE);
8898 * Check for illegal attributes.
8900 attr = node->properties;
8901 while (attr != NULL) {
8902 if (attr->ns == NULL) {
8903 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
8904 (!xmlStrEqual(attr->name, BAD_CAST "memberTypes"))) {
8905 xmlSchemaPIllegalAttrErr(ctxt,
8906 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
8908 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
8909 xmlSchemaPIllegalAttrErr(ctxt,
8910 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
8914 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
8916 * Attribute "memberTypes". This is a list of QNames.
8917 * TODO: Check the value to contain anything.
8919 attr = xmlSchemaGetPropNode(node, "memberTypes");
8923 const xmlChar *localName, *nsName;
8924 xmlSchemaTypeLinkPtr link, lastLink = NULL;
8925 xmlSchemaQNameRefPtr ref;
8927 cur = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
8930 while (IS_BLANK_CH(*cur))
8933 while ((*end != 0) && (!(IS_BLANK_CH(*end))))
8937 tmp = xmlStrndup(cur, end - cur);
8938 if (xmlSchemaPValAttrNodeQNameValue(ctxt, schema,
8939 NULL, attr, BAD_CAST tmp, &nsName, &localName) == 0) {
8941 * Create the member type link.
8943 link = (xmlSchemaTypeLinkPtr)
8944 xmlMalloc(sizeof(xmlSchemaTypeLink));
8946 xmlSchemaPErrMemory(ctxt, "xmlSchemaParseUnion, "
8947 "allocating a type link", NULL);
8952 if (lastLink == NULL)
8953 type->memberTypes = link;
8955 lastLink->next = link;
8958 * Create a reference item.
8960 ref = xmlSchemaNewQNameRef(ctxt, XML_SCHEMA_TYPE_SIMPLE,
8967 * Assign the reference to the link, it will be resolved
8968 * later during fixup of the union simple type.
8970 link->type = (xmlSchemaTypePtr) ref;
8974 } while (*cur != 0);
8978 * And now for the children...
8980 child = node->children;
8981 if (IS_SCHEMA(child, "annotation")) {
8983 * Add the annotation to the simple type ancestor.
8985 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
8986 xmlSchemaParseAnnotation(ctxt, child, 1));
8987 child = child->next;
8989 if (IS_SCHEMA(child, "simpleType")) {
8990 xmlSchemaTypePtr subtype, last = NULL;
8993 * Anchor the member types in the "subtypes" field of the
8996 while (IS_SCHEMA(child, "simpleType")) {
8997 subtype = (xmlSchemaTypePtr)
8998 xmlSchemaParseSimpleType(ctxt, schema, child, 0);
8999 if (subtype != NULL) {
9001 type->subtypes = subtype;
9004 last->next = subtype;
9009 child = child->next;
9012 if (child != NULL) {
9013 xmlSchemaPContentErr(ctxt,
9014 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
9015 NULL, node, child, NULL, "(annotation?, simpleType*)");
9017 if ((attr == NULL) && (type->subtypes == NULL)) {
9019 * src-union-memberTypes-or-simpleTypes
9020 * Either the memberTypes [attribute] of the <union> element must
9021 * be non-empty or there must be at least one simpleType [child].
9023 xmlSchemaPCustomErr(ctxt,
9024 XML_SCHEMAP_SRC_UNION_MEMBERTYPES_OR_SIMPLETYPES,
9026 "Either the attribute 'memberTypes' or "
9027 "at least one <simpleType> child must be present", NULL);
9033 * xmlSchemaParseList:
9034 * @ctxt: a schema validation context
9035 * @schema: the schema being built
9036 * @node: a subtree containing XML Schema informations
9038 * parse a XML schema List definition
9039 * *WARNING* this interface is highly subject to change
9041 * Returns -1 in case of error, 0 if the declaration is improper and
9042 * 1 in case of success.
9044 static xmlSchemaTypePtr
9045 xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
9048 xmlSchemaTypePtr type;
9049 xmlNodePtr child = NULL;
9052 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
9054 /* Not a component, don't create it. */
9055 type = ctxt->ctxtType;
9057 * Mark the type as being of variety "list".
9059 type->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST;
9061 * SPEC (Base type) (2) "If the <list> or <union> alternative is chosen,
9062 * then the `simple ur-type definition`."
9064 type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE);
9066 * Check for illegal attributes.
9068 attr = node->properties;
9069 while (attr != NULL) {
9070 if (attr->ns == NULL) {
9071 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
9072 (!xmlStrEqual(attr->name, BAD_CAST "itemType"))) {
9073 xmlSchemaPIllegalAttrErr(ctxt,
9074 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
9076 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
9077 xmlSchemaPIllegalAttrErr(ctxt,
9078 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
9083 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
9086 * Attribute "itemType". NOTE that we will use the "ref" and "refNs"
9087 * fields for holding the reference to the itemType.
9089 * REVAMP TODO: Use the "base" and "baseNs" fields, since we will remove
9092 xmlSchemaPValAttrQName(ctxt, schema, NULL,
9093 node, "itemType", &(type->baseNs), &(type->base));
9095 * And now for the children...
9097 child = node->children;
9098 if (IS_SCHEMA(child, "annotation")) {
9099 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
9100 xmlSchemaParseAnnotation(ctxt, child, 1));
9101 child = child->next;
9103 if (IS_SCHEMA(child, "simpleType")) {
9105 * src-list-itemType-or-simpleType
9106 * Either the itemType [attribute] or the <simpleType> [child] of
9107 * the <list> element must be present, but not both.
9109 if (type->base != NULL) {
9110 xmlSchemaPCustomErr(ctxt,
9111 XML_SCHEMAP_SRC_SIMPLE_TYPE_1,
9113 "The attribute 'itemType' and the <simpleType> child "
9114 "are mutually exclusive", NULL);
9116 type->subtypes = xmlSchemaParseSimpleType(ctxt, schema, child, 0);
9118 child = child->next;
9119 } else if (type->base == NULL) {
9120 xmlSchemaPCustomErr(ctxt,
9121 XML_SCHEMAP_SRC_SIMPLE_TYPE_1,
9123 "Either the attribute 'itemType' or the <simpleType> child "
9124 "must be present", NULL);
9126 if (child != NULL) {
9127 xmlSchemaPContentErr(ctxt,
9128 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
9129 NULL, node, child, NULL, "(annotation?, simpleType?)");
9131 if ((type->base == NULL) &&
9132 (type->subtypes == NULL) &&
9133 (xmlSchemaGetPropNode(node, "itemType") == NULL)) {
9134 xmlSchemaPCustomErr(ctxt,
9135 XML_SCHEMAP_SRC_SIMPLE_TYPE_1,
9137 "Either the attribute 'itemType' or the <simpleType> child "
9138 "must be present", NULL);
9144 * xmlSchemaParseSimpleType:
9145 * @ctxt: a schema validation context
9146 * @schema: the schema being built
9147 * @node: a subtree containing XML Schema informations
9149 * parse a XML schema Simple Type definition
9150 * *WARNING* this interface is highly subject to change
9152 * Returns -1 in case of error, 0 if the declaration is improper and
9153 * 1 in case of success.
9155 static xmlSchemaTypePtr
9156 xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
9157 xmlNodePtr node, int topLevel)
9159 xmlSchemaTypePtr type, oldCtxtType;
9160 xmlNodePtr child = NULL;
9161 const xmlChar *attrValue = NULL;
9163 int hasRestriction = 0;
9165 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
9169 attr = xmlSchemaGetPropNode(node, "name");
9171 xmlSchemaPMissingAttrErr(ctxt,
9172 XML_SCHEMAP_S4S_ATTR_MISSING,
9177 if (xmlSchemaPValAttrNode(ctxt,
9179 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &attrValue) != 0)
9182 * Skip built-in types.
9185 xmlSchemaTypePtr biType;
9187 if (ctxt->isRedefine) {
9189 * REDEFINE: Disallow redefinition of built-in-types.
9190 * TODO: It seems that the spec does not say anything
9193 xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_SRC_REDEFINE,
9195 "Redefinition of built-in simple types is not "
9199 biType = xmlSchemaGetPredefinedType(attrValue, xmlSchemaNs);
9207 * SPEC "The `actual value` of the targetNamespace [attribute]
9208 * of the <schema> ancestor element information item if present,
9209 * otherwise `absent`.
9211 if (topLevel == 0) {
9212 #ifdef ENABLE_NAMED_LOCALS
9216 * Parse as local simple type definition.
9218 #ifdef ENABLE_NAMED_LOCALS
9219 snprintf(buf, 39, "#ST%d", ctxt->counter++ + 1);
9220 type = xmlSchemaAddType(ctxt, schema,
9221 XML_SCHEMA_TYPE_SIMPLE,
9222 xmlDictLookup(ctxt->dict, (const xmlChar *)buf, -1),
9223 ctxt->targetNamespace, node, 0);
9225 type = xmlSchemaAddType(ctxt, schema,
9226 XML_SCHEMA_TYPE_SIMPLE,
9227 NULL, ctxt->targetNamespace, node, 0);
9231 type->type = XML_SCHEMA_TYPE_SIMPLE;
9232 type->contentType = XML_SCHEMA_CONTENT_SIMPLE;
9234 * Check for illegal attributes.
9236 attr = node->properties;
9237 while (attr != NULL) {
9238 if (attr->ns == NULL) {
9239 if (!xmlStrEqual(attr->name, BAD_CAST "id")) {
9240 xmlSchemaPIllegalAttrErr(ctxt,
9241 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
9243 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
9244 xmlSchemaPIllegalAttrErr(ctxt,
9245 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
9251 * Parse as global simple type definition.
9253 * Note that attrValue is the value of the attribute "name" here.
9255 type = xmlSchemaAddType(ctxt, schema, XML_SCHEMA_TYPE_SIMPLE,
9256 attrValue, ctxt->targetNamespace, node, 1);
9259 type->type = XML_SCHEMA_TYPE_SIMPLE;
9260 type->contentType = XML_SCHEMA_CONTENT_SIMPLE;
9261 type->flags |= XML_SCHEMAS_TYPE_GLOBAL;
9263 * Check for illegal attributes.
9265 attr = node->properties;
9266 while (attr != NULL) {
9267 if (attr->ns == NULL) {
9268 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
9269 (!xmlStrEqual(attr->name, BAD_CAST "name")) &&
9270 (!xmlStrEqual(attr->name, BAD_CAST "final"))) {
9271 xmlSchemaPIllegalAttrErr(ctxt,
9272 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
9274 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
9275 xmlSchemaPIllegalAttrErr(ctxt,
9276 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
9281 * Attribute "final".
9283 attr = xmlSchemaGetPropNode(node, "final");
9285 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION)
9286 type->flags |= XML_SCHEMAS_TYPE_FINAL_RESTRICTION;
9287 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_LIST)
9288 type->flags |= XML_SCHEMAS_TYPE_FINAL_LIST;
9289 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_UNION)
9290 type->flags |= XML_SCHEMAS_TYPE_FINAL_UNION;
9292 attrValue = xmlSchemaGetProp(ctxt, node, "final");
9293 if (xmlSchemaPValAttrBlockFinal(attrValue, &(type->flags),
9294 -1, -1, XML_SCHEMAS_TYPE_FINAL_RESTRICTION, -1,
9295 XML_SCHEMAS_TYPE_FINAL_LIST,
9296 XML_SCHEMAS_TYPE_FINAL_UNION) != 0) {
9298 xmlSchemaPSimpleTypeErr(ctxt,
9299 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
9300 WXS_BASIC_CAST type, (xmlNodePtr) attr,
9301 NULL, "(#all | List of (list | union | restriction)",
9302 attrValue, NULL, NULL, NULL);
9306 type->targetNamespace = ctxt->targetNamespace;
9307 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
9309 * And now for the children...
9311 oldCtxtType = ctxt->ctxtType;
9313 ctxt->ctxtType = type;
9315 child = node->children;
9316 if (IS_SCHEMA(child, "annotation")) {
9317 type->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
9318 child = child->next;
9320 if (child == NULL) {
9321 xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_MISSING,
9322 NULL, node, child, NULL,
9323 "(annotation?, (restriction | list | union))");
9324 } else if (IS_SCHEMA(child, "restriction")) {
9325 xmlSchemaParseRestriction(ctxt, schema, child,
9326 XML_SCHEMA_TYPE_SIMPLE);
9328 child = child->next;
9329 } else if (IS_SCHEMA(child, "list")) {
9330 xmlSchemaParseList(ctxt, schema, child);
9331 child = child->next;
9332 } else if (IS_SCHEMA(child, "union")) {
9333 xmlSchemaParseUnion(ctxt, schema, child);
9334 child = child->next;
9336 if (child != NULL) {
9337 xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
9338 NULL, node, child, NULL,
9339 "(annotation?, (restriction | list | union))");
9342 * REDEFINE: SPEC src-redefine (5)
9343 * "Within the [children], each <simpleType> must have a
9344 * <restriction> among its [children] ... the `actual value` of whose
9345 * base [attribute] must be the same as the `actual value` of its own
9346 * name attribute plus target namespace;"
9348 if (topLevel && ctxt->isRedefine && (! hasRestriction)) {
9349 xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_SRC_REDEFINE,
9350 NULL, node, "This is a redefinition, thus the "
9351 "<simpleType> must have a <restriction> child", NULL);
9354 ctxt->ctxtType = oldCtxtType;
9359 * xmlSchemaParseModelGroupDefRef:
9360 * @ctxt: the parser context
9361 * @schema: the schema being built
9364 * Parses a reference to a model group definition.
9366 * We will return a particle component with a qname-component or
9367 * NULL in case of an error.
9369 static xmlSchemaTreeItemPtr
9370 xmlSchemaParseModelGroupDefRef(xmlSchemaParserCtxtPtr ctxt,
9371 xmlSchemaPtr schema,
9374 xmlSchemaParticlePtr item;
9375 xmlNodePtr child = NULL;
9377 const xmlChar *ref = NULL, *refNs = NULL;
9380 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
9383 attr = xmlSchemaGetPropNode(node, "ref");
9385 xmlSchemaPMissingAttrErr(ctxt,
9386 XML_SCHEMAP_S4S_ATTR_MISSING,
9387 NULL, node, "ref", NULL);
9389 } else if (xmlSchemaPValAttrNodeQName(ctxt, schema, NULL,
9390 attr, &refNs, &ref) != 0) {
9393 xmlSchemaCheckReference(ctxt, schema, node, attr, refNs);
9394 min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "xs:nonNegativeInteger");
9395 max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1,
9396 "(xs:nonNegativeInteger | unbounded)");
9398 * Check for illegal attributes.
9400 attr = node->properties;
9401 while (attr != NULL) {
9402 if (attr->ns == NULL) {
9403 if ((!xmlStrEqual(attr->name, BAD_CAST "ref")) &&
9404 (!xmlStrEqual(attr->name, BAD_CAST "id")) &&
9405 (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) &&
9406 (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs"))) {
9407 xmlSchemaPIllegalAttrErr(ctxt,
9408 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
9410 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
9411 xmlSchemaPIllegalAttrErr(ctxt,
9412 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
9416 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
9417 item = xmlSchemaAddParticle(ctxt, node, min, max);
9421 * Create a qname-reference and set as the term; it will be substituted
9422 * for the model group after the reference has been resolved.
9424 item->children = (xmlSchemaTreeItemPtr)
9425 xmlSchemaNewQNameRef(ctxt, XML_SCHEMA_TYPE_GROUP, ref, refNs);
9426 xmlSchemaPCheckParticleCorrect_2(ctxt, item, node, min, max);
9428 * And now for the children...
9430 child = node->children;
9431 /* TODO: Is annotation even allowed for a model group reference? */
9432 if (IS_SCHEMA(child, "annotation")) {
9434 * TODO: What to do exactly with the annotation?
9436 item->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
9437 child = child->next;
9439 if (child != NULL) {
9440 xmlSchemaPContentErr(ctxt,
9441 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
9442 NULL, node, child, NULL,
9446 * Corresponds to no component at all if minOccurs==maxOccurs==0.
9448 if ((min == 0) && (max == 0))
9451 return ((xmlSchemaTreeItemPtr) item);
9455 * xmlSchemaParseModelGroupDefinition:
9456 * @ctxt: a schema validation context
9457 * @schema: the schema being built
9458 * @node: a subtree containing XML Schema informations
9460 * Parses a XML schema model group definition.
9462 * Note that the contraint src-redefine (6.2) can't be applied until
9463 * references have been resolved. So we will do this at the
9464 * component fixup level.
9466 * *WARNING* this interface is highly subject to change
9468 * Returns -1 in case of error, 0 if the declaration is improper and
9469 * 1 in case of success.
9471 static xmlSchemaModelGroupDefPtr
9472 xmlSchemaParseModelGroupDefinition(xmlSchemaParserCtxtPtr ctxt,
9473 xmlSchemaPtr schema,
9476 xmlSchemaModelGroupDefPtr item;
9477 xmlNodePtr child = NULL;
9479 const xmlChar *name;
9481 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
9484 attr = xmlSchemaGetPropNode(node, "name");
9486 xmlSchemaPMissingAttrErr(ctxt,
9487 XML_SCHEMAP_S4S_ATTR_MISSING,
9491 } else if (xmlSchemaPValAttrNode(ctxt, NULL, attr,
9492 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) {
9495 item = xmlSchemaAddModelGroupDefinition(ctxt, schema, name,
9496 ctxt->targetNamespace, node);
9500 * Check for illegal attributes.
9502 attr = node->properties;
9503 while (attr != NULL) {
9504 if (attr->ns == NULL) {
9505 if ((!xmlStrEqual(attr->name, BAD_CAST "name")) &&
9506 (!xmlStrEqual(attr->name, BAD_CAST "id"))) {
9507 xmlSchemaPIllegalAttrErr(ctxt,
9508 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
9510 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
9511 xmlSchemaPIllegalAttrErr(ctxt,
9512 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
9516 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
9518 * And now for the children...
9520 child = node->children;
9521 if (IS_SCHEMA(child, "annotation")) {
9522 item->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
9523 child = child->next;
9525 if (IS_SCHEMA(child, "all")) {
9526 item->children = xmlSchemaParseModelGroup(ctxt, schema, child,
9527 XML_SCHEMA_TYPE_ALL, 0);
9528 child = child->next;
9529 } else if (IS_SCHEMA(child, "choice")) {
9530 item->children = xmlSchemaParseModelGroup(ctxt, schema, child,
9531 XML_SCHEMA_TYPE_CHOICE, 0);
9532 child = child->next;
9533 } else if (IS_SCHEMA(child, "sequence")) {
9534 item->children = xmlSchemaParseModelGroup(ctxt, schema, child,
9535 XML_SCHEMA_TYPE_SEQUENCE, 0);
9536 child = child->next;
9541 if (child != NULL) {
9542 xmlSchemaPContentErr(ctxt,
9543 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
9544 NULL, node, child, NULL,
9545 "(annotation?, (all | choice | sequence)?)");
9551 * xmlSchemaCleanupDoc:
9552 * @ctxt: a schema validation context
9553 * @node: the root of the document.
9555 * removes unwanted nodes in a schemas document tree
9558 xmlSchemaCleanupDoc(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr root)
9560 xmlNodePtr delete, cur;
9562 if ((ctxt == NULL) || (root == NULL)) return;
9565 * Remove all the blank text nodes
9569 while (cur != NULL) {
9570 if (delete != NULL) {
9571 xmlUnlinkNode(delete);
9572 xmlFreeNode(delete);
9575 if (cur->type == XML_TEXT_NODE) {
9576 if (IS_BLANK_NODE(cur)) {
9577 if (xmlNodeGetSpacePreserve(cur) != 1) {
9581 } else if ((cur->type != XML_ELEMENT_NODE) &&
9582 (cur->type != XML_CDATA_SECTION_NODE)) {
9590 if (cur->children != NULL) {
9591 if ((cur->children->type != XML_ENTITY_DECL) &&
9592 (cur->children->type != XML_ENTITY_REF_NODE) &&
9593 (cur->children->type != XML_ENTITY_NODE)) {
9594 cur = cur->children;
9599 if (cur->next != NULL) {
9612 if (cur->next != NULL) {
9616 } while (cur != NULL);
9618 if (delete != NULL) {
9619 xmlUnlinkNode(delete);
9620 xmlFreeNode(delete);
9627 xmlSchemaClearSchemaDefaults(xmlSchemaPtr schema)
9629 if (schema->flags & XML_SCHEMAS_QUALIF_ELEM)
9630 schema->flags ^= XML_SCHEMAS_QUALIF_ELEM;
9632 if (schema->flags & XML_SCHEMAS_QUALIF_ATTR)
9633 schema->flags ^= XML_SCHEMAS_QUALIF_ATTR;
9635 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION)
9636 schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_EXTENSION;
9637 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION)
9638 schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION;
9639 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_LIST)
9640 schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_LIST;
9641 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_UNION)
9642 schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_UNION;
9644 if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION)
9645 schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION;
9646 if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION)
9647 schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION;
9648 if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION)
9649 schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION;
9653 xmlSchemaParseSchemaElement(xmlSchemaParserCtxtPtr ctxt,
9654 xmlSchemaPtr schema,
9659 int res = 0, oldErrs = ctxt->nberrors;
9662 * Those flags should be moved to the parser context flags,
9663 * since they are not visible at the component level. I.e.
9664 * they are used if processing schema *documents* only.
9666 res = xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
9670 * Since the version is of type xs:token, we won't bother to
9674 attr = xmlSchemaGetPropNode(node, "version");
9676 res = xmlSchemaPValAttrNode(ctxt, NULL, NULL, attr,
9677 xmlSchemaGetBuiltInType(XML_SCHEMAS_TOKEN), &val);
9681 attr = xmlSchemaGetPropNode(node, "targetNamespace");
9683 res = xmlSchemaPValAttrNode(ctxt, NULL, attr,
9684 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), NULL);
9687 ctxt->stop = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE;
9691 attr = xmlSchemaGetPropNode(node, "elementFormDefault");
9693 val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
9694 res = xmlSchemaPValAttrFormDefault(val, &schema->flags,
9695 XML_SCHEMAS_QUALIF_ELEM);
9698 xmlSchemaPSimpleTypeErr(ctxt,
9699 XML_SCHEMAP_ELEMFORMDEFAULT_VALUE,
9700 NULL, (xmlNodePtr) attr, NULL,
9701 "(qualified | unqualified)", val, NULL, NULL, NULL);
9704 attr = xmlSchemaGetPropNode(node, "attributeFormDefault");
9706 val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
9707 res = xmlSchemaPValAttrFormDefault(val, &schema->flags,
9708 XML_SCHEMAS_QUALIF_ATTR);
9711 xmlSchemaPSimpleTypeErr(ctxt,
9712 XML_SCHEMAP_ATTRFORMDEFAULT_VALUE,
9713 NULL, (xmlNodePtr) attr, NULL,
9714 "(qualified | unqualified)", val, NULL, NULL, NULL);
9717 attr = xmlSchemaGetPropNode(node, "finalDefault");
9719 val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
9720 res = xmlSchemaPValAttrBlockFinal(val, &(schema->flags), -1,
9721 XML_SCHEMAS_FINAL_DEFAULT_EXTENSION,
9722 XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION,
9724 XML_SCHEMAS_FINAL_DEFAULT_LIST,
9725 XML_SCHEMAS_FINAL_DEFAULT_UNION);
9728 xmlSchemaPSimpleTypeErr(ctxt,
9729 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
9730 NULL, (xmlNodePtr) attr, NULL,
9731 "(#all | List of (extension | restriction | list | union))",
9732 val, NULL, NULL, NULL);
9735 attr = xmlSchemaGetPropNode(node, "blockDefault");
9737 val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
9738 res = xmlSchemaPValAttrBlockFinal(val, &(schema->flags), -1,
9739 XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION,
9740 XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION,
9741 XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION, -1, -1);
9744 xmlSchemaPSimpleTypeErr(ctxt,
9745 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
9746 NULL, (xmlNodePtr) attr, NULL,
9747 "(#all | List of (extension | restriction | substitution))",
9748 val, NULL, NULL, NULL);
9753 if (oldErrs != ctxt->nberrors)
9761 * xmlSchemaParseSchemaTopLevel:
9762 * @ctxt: a schema validation context
9763 * @schema: the schemas
9764 * @nodes: the list of top level nodes
9766 * Returns the internal XML Schema structure built from the resource or
9767 * NULL in case of error
9770 xmlSchemaParseSchemaTopLevel(xmlSchemaParserCtxtPtr ctxt,
9771 xmlSchemaPtr schema, xmlNodePtr nodes)
9774 xmlSchemaAnnotPtr annot;
9775 int res = 0, oldErrs, tmpOldErrs;
9777 if ((ctxt == NULL) || (schema == NULL) || (nodes == NULL))
9780 oldErrs = ctxt->nberrors;
9782 while ((IS_SCHEMA(child, "include")) ||
9783 (IS_SCHEMA(child, "import")) ||
9784 (IS_SCHEMA(child, "redefine")) ||
9785 (IS_SCHEMA(child, "annotation"))) {
9786 if (IS_SCHEMA(child, "annotation")) {
9787 annot = xmlSchemaParseAnnotation(ctxt, child, 1);
9788 if (schema->annot == NULL)
9789 schema->annot = annot;
9791 xmlSchemaFreeAnnot(annot);
9792 } else if (IS_SCHEMA(child, "import")) {
9793 tmpOldErrs = ctxt->nberrors;
9794 res = xmlSchemaParseImport(ctxt, schema, child);
9797 if (tmpOldErrs != ctxt->nberrors)
9799 } else if (IS_SCHEMA(child, "include")) {
9800 tmpOldErrs = ctxt->nberrors;
9801 res = xmlSchemaParseInclude(ctxt, schema, child);
9804 if (tmpOldErrs != ctxt->nberrors)
9806 } else if (IS_SCHEMA(child, "redefine")) {
9807 tmpOldErrs = ctxt->nberrors;
9808 res = xmlSchemaParseRedefine(ctxt, schema, child);
9811 if (tmpOldErrs != ctxt->nberrors)
9814 child = child->next;
9817 * URGENT TODO: Change the functions to return int results.
9818 * We need especially to catch internal errors.
9820 while (child != NULL) {
9821 if (IS_SCHEMA(child, "complexType")) {
9822 xmlSchemaParseComplexType(ctxt, schema, child, 1);
9823 child = child->next;
9824 } else if (IS_SCHEMA(child, "simpleType")) {
9825 xmlSchemaParseSimpleType(ctxt, schema, child, 1);
9826 child = child->next;
9827 } else if (IS_SCHEMA(child, "element")) {
9828 xmlSchemaParseElement(ctxt, schema, child, NULL, 1);
9829 child = child->next;
9830 } else if (IS_SCHEMA(child, "attribute")) {
9831 xmlSchemaParseGlobalAttribute(ctxt, schema, child);
9832 child = child->next;
9833 } else if (IS_SCHEMA(child, "attributeGroup")) {
9834 xmlSchemaParseAttributeGroupDefinition(ctxt, schema, child);
9835 child = child->next;
9836 } else if (IS_SCHEMA(child, "group")) {
9837 xmlSchemaParseModelGroupDefinition(ctxt, schema, child);
9838 child = child->next;
9839 } else if (IS_SCHEMA(child, "notation")) {
9840 xmlSchemaParseNotation(ctxt, schema, child);
9841 child = child->next;
9843 xmlSchemaPContentErr(ctxt,
9844 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
9845 NULL, child->parent, child,
9846 NULL, "((include | import | redefine | annotation)*, "
9847 "(((simpleType | complexType | group | attributeGroup) "
9848 "| element | attribute | notation), annotation*)*)");
9849 child = child->next;
9851 while (IS_SCHEMA(child, "annotation")) {
9853 * TODO: We should add all annotations.
9855 annot = xmlSchemaParseAnnotation(ctxt, child, 1);
9856 if (schema->annot == NULL)
9857 schema->annot = annot;
9859 xmlSchemaFreeAnnot(annot);
9860 child = child->next;
9864 ctxt->ctxtType = NULL;
9865 if (oldErrs != ctxt->nberrors)
9872 static xmlSchemaSchemaRelationPtr
9873 xmlSchemaSchemaRelationCreate(void)
9875 xmlSchemaSchemaRelationPtr ret;
9877 ret = (xmlSchemaSchemaRelationPtr)
9878 xmlMalloc(sizeof(xmlSchemaSchemaRelation));
9880 xmlSchemaPErrMemory(NULL, "allocating schema relation", NULL);
9883 memset(ret, 0, sizeof(xmlSchemaSchemaRelation));
9889 xmlSchemaSchemaRelationFree(xmlSchemaSchemaRelationPtr rel)
9896 xmlSchemaRedefListFree(xmlSchemaRedefPtr redef)
9898 xmlSchemaRedefPtr prev;
9900 while (redef != NULL) {
9902 redef = redef->next;
9908 xmlSchemaConstructionCtxtFree(xmlSchemaConstructionCtxtPtr con)
9911 * After the construction context has been freed, there will be
9912 * no schema graph available any more. Only the schema buckets
9913 * will stay alive, which are put into the "schemasImports" and
9914 * "includes" slots of the xmlSchema.
9916 if (con->buckets != NULL)
9917 xmlSchemaItemListFree(con->buckets);
9918 if (con->pending != NULL)
9919 xmlSchemaItemListFree(con->pending);
9920 if (con->substGroups != NULL)
9921 xmlHashFree(con->substGroups,
9922 (xmlHashDeallocator) xmlSchemaSubstGroupFree);
9923 if (con->redefs != NULL)
9924 xmlSchemaRedefListFree(con->redefs);
9925 if (con->dict != NULL)
9926 xmlDictFree(con->dict);
9930 static xmlSchemaConstructionCtxtPtr
9931 xmlSchemaConstructionCtxtCreate(xmlDictPtr dict)
9933 xmlSchemaConstructionCtxtPtr ret;
9935 ret = (xmlSchemaConstructionCtxtPtr)
9936 xmlMalloc(sizeof(xmlSchemaConstructionCtxt));
9938 xmlSchemaPErrMemory(NULL,
9939 "allocating schema construction context", NULL);
9942 memset(ret, 0, sizeof(xmlSchemaConstructionCtxt));
9944 ret->buckets = xmlSchemaItemListCreate();
9945 if (ret->buckets == NULL) {
9946 xmlSchemaPErrMemory(NULL,
9947 "allocating list of schema buckets", NULL);
9951 ret->pending = xmlSchemaItemListCreate();
9952 if (ret->pending == NULL) {
9953 xmlSchemaPErrMemory(NULL,
9954 "allocating list of pending global components", NULL);
9955 xmlSchemaConstructionCtxtFree(ret);
9959 xmlDictReference(dict);
9963 static xmlSchemaParserCtxtPtr
9964 xmlSchemaParserCtxtCreate(void)
9966 xmlSchemaParserCtxtPtr ret;
9968 ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt));
9970 xmlSchemaPErrMemory(NULL, "allocating schema parser context",
9974 memset(ret, 0, sizeof(xmlSchemaParserCtxt));
9975 ret->type = XML_SCHEMA_CTXT_PARSER;
9976 ret->attrProhibs = xmlSchemaItemListCreate();
9977 if (ret->attrProhibs == NULL) {
9985 * xmlSchemaNewParserCtxtUseDict:
9986 * @URL: the location of the schema
9987 * @dict: the dictionary to be used
9989 * Create an XML Schemas parse context for that file/resource expected
9990 * to contain an XML Schemas file.
9992 * Returns the parser context or NULL in case of error
9994 static xmlSchemaParserCtxtPtr
9995 xmlSchemaNewParserCtxtUseDict(const char *URL, xmlDictPtr dict)
9997 xmlSchemaParserCtxtPtr ret;
9999 ret = xmlSchemaParserCtxtCreate();
10003 xmlDictReference(dict);
10005 ret->URL = xmlDictLookup(dict, (const xmlChar *) URL, -1);
10010 xmlSchemaCreatePCtxtOnVCtxt(xmlSchemaValidCtxtPtr vctxt)
10012 if (vctxt->pctxt == NULL) {
10013 if (vctxt->schema != NULL)
10015 xmlSchemaNewParserCtxtUseDict("*", vctxt->schema->dict);
10017 vctxt->pctxt = xmlSchemaNewParserCtxt("*");
10018 if (vctxt->pctxt == NULL) {
10019 VERROR_INT("xmlSchemaCreatePCtxtOnVCtxt",
10020 "failed to create a temp. parser context");
10023 /* TODO: Pass user data. */
10024 xmlSchemaSetParserErrors(vctxt->pctxt, vctxt->error,
10025 vctxt->warning, vctxt->errCtxt);
10026 xmlSchemaSetParserStructuredErrors(vctxt->pctxt, vctxt->serror,
10033 * xmlSchemaGetSchemaBucket:
10034 * @pctxt: the schema parser context
10035 * @schemaLocation: the URI of the schema document
10037 * Returns a schema bucket if it was already parsed.
10039 * Returns a schema bucket if it was already parsed from
10040 * @schemaLocation, NULL otherwise.
10042 static xmlSchemaBucketPtr
10043 xmlSchemaGetSchemaBucket(xmlSchemaParserCtxtPtr pctxt,
10044 const xmlChar *schemaLocation)
10046 xmlSchemaBucketPtr cur;
10047 xmlSchemaItemListPtr list;
10049 list = pctxt->constructor->buckets;
10050 if (list->nbItems == 0)
10054 for (i = 0; i < list->nbItems; i++) {
10055 cur = (xmlSchemaBucketPtr) list->items[i];
10056 /* Pointer comparison! */
10057 if (cur->schemaLocation == schemaLocation)
10064 static xmlSchemaBucketPtr
10065 xmlSchemaGetChameleonSchemaBucket(xmlSchemaParserCtxtPtr pctxt,
10066 const xmlChar *schemaLocation,
10067 const xmlChar *targetNamespace)
10069 xmlSchemaBucketPtr cur;
10070 xmlSchemaItemListPtr list;
10072 list = pctxt->constructor->buckets;
10073 if (list->nbItems == 0)
10077 for (i = 0; i < list->nbItems; i++) {
10078 cur = (xmlSchemaBucketPtr) list->items[i];
10079 /* Pointer comparison! */
10080 if ((cur->origTargetNamespace == NULL) &&
10081 (cur->schemaLocation == schemaLocation) &&
10082 (cur->targetNamespace == targetNamespace))
10090 #define IS_BAD_SCHEMA_DOC(b) \
10091 (((b)->doc == NULL) && ((b)->schemaLocation != NULL))
10093 static xmlSchemaBucketPtr
10094 xmlSchemaGetSchemaBucketByTNS(xmlSchemaParserCtxtPtr pctxt,
10095 const xmlChar *targetNamespace,
10098 xmlSchemaBucketPtr cur;
10099 xmlSchemaItemListPtr list;
10101 list = pctxt->constructor->buckets;
10102 if (list->nbItems == 0)
10106 for (i = 0; i < list->nbItems; i++) {
10107 cur = (xmlSchemaBucketPtr) list->items[i];
10108 if ((! IS_BAD_SCHEMA_DOC(cur)) &&
10109 (cur->origTargetNamespace == targetNamespace) &&
10110 ((imported && cur->imported) ||
10111 ((!imported) && (!cur->imported))))
10119 xmlSchemaParseNewDocWithContext(xmlSchemaParserCtxtPtr pctxt,
10120 xmlSchemaPtr schema,
10121 xmlSchemaBucketPtr bucket)
10127 xmlSchemaBucketPtr oldbucket = pctxt->constructor->bucket;
10130 * Save old values; reset the *main* schema.
10131 * URGENT TODO: This is not good; move the per-document information
10132 * to the parser. Get rid of passing the main schema to the
10133 * parsing functions.
10135 oldFlags = schema->flags;
10136 oldDoc = schema->doc;
10137 if (schema->flags != 0)
10138 xmlSchemaClearSchemaDefaults(schema);
10139 schema->doc = bucket->doc;
10140 pctxt->schema = schema;
10142 * Keep the current target namespace on the parser *not* on the
10145 pctxt->targetNamespace = bucket->targetNamespace;
10146 WXS_CONSTRUCTOR(pctxt)->bucket = bucket;
10148 if ((bucket->targetNamespace != NULL) &&
10149 xmlStrEqual(bucket->targetNamespace, xmlSchemaNs)) {
10151 * We are parsing the schema for schemas!
10155 /* Mark it as parsed, even if parsing fails. */
10157 /* Compile the schema doc. */
10158 node = xmlDocGetRootElement(bucket->doc);
10159 ret = xmlSchemaParseSchemaElement(pctxt, schema, node);
10162 /* An empty schema; just get out. */
10163 if (node->children == NULL)
10165 oldErrs = pctxt->nberrors;
10166 ret = xmlSchemaParseSchemaTopLevel(pctxt, schema, node->children);
10170 * TODO: Not nice, but I'm not 100% sure we will get always an error
10171 * as a result of the obove functions; so better rely on pctxt->err
10174 if ((ret == 0) && (oldErrs != pctxt->nberrors)) {
10180 WXS_CONSTRUCTOR(pctxt)->bucket = oldbucket;
10181 /* Restore schema values. */
10182 schema->doc = oldDoc;
10183 schema->flags = oldFlags;
10188 xmlSchemaParseNewDoc(xmlSchemaParserCtxtPtr pctxt,
10189 xmlSchemaPtr schema,
10190 xmlSchemaBucketPtr bucket)
10192 xmlSchemaParserCtxtPtr newpctxt;
10195 if (bucket == NULL)
10197 if (bucket->parsed) {
10198 PERROR_INT("xmlSchemaParseNewDoc",
10199 "reparsing a schema doc");
10202 if (bucket->doc == NULL) {
10203 PERROR_INT("xmlSchemaParseNewDoc",
10204 "parsing a schema doc, but there's no doc");
10207 if (pctxt->constructor == NULL) {
10208 PERROR_INT("xmlSchemaParseNewDoc",
10212 /* Create and init the temporary parser context. */
10213 newpctxt = xmlSchemaNewParserCtxtUseDict(
10214 (const char *) bucket->schemaLocation, pctxt->dict);
10215 if (newpctxt == NULL)
10217 newpctxt->constructor = pctxt->constructor;
10219 * TODO: Can we avoid that the parser knows about the main schema?
10220 * It would be better if he knows about the current schema bucket
10223 newpctxt->schema = schema;
10224 xmlSchemaSetParserErrors(newpctxt, pctxt->error, pctxt->warning,
10226 xmlSchemaSetParserStructuredErrors(newpctxt, pctxt->serror,
10228 newpctxt->counter = pctxt->counter;
10231 res = xmlSchemaParseNewDocWithContext(newpctxt, schema, bucket);
10233 /* Channel back errors and cleanup the temporary parser context. */
10236 pctxt->nberrors += newpctxt->nberrors;
10237 pctxt->counter = newpctxt->counter;
10238 newpctxt->constructor = NULL;
10239 /* Free the parser context. */
10240 xmlSchemaFreeParserCtxt(newpctxt);
10245 xmlSchemaSchemaRelationAddChild(xmlSchemaBucketPtr bucket,
10246 xmlSchemaSchemaRelationPtr rel)
10248 xmlSchemaSchemaRelationPtr cur = bucket->relations;
10251 bucket->relations = rel;
10254 while (cur->next != NULL)
10260 static const xmlChar *
10261 xmlSchemaBuildAbsoluteURI(xmlDictPtr dict, const xmlChar* location,
10262 xmlNodePtr ctxtNode)
10265 * Build an absolue location URI.
10267 if (location != NULL) {
10268 if (ctxtNode == NULL)
10271 xmlChar *base, *URI;
10272 const xmlChar *ret = NULL;
10274 base = xmlNodeGetBase(ctxtNode->doc, ctxtNode);
10275 if (base == NULL) {
10276 URI = xmlBuildURI(location, ctxtNode->doc->URL);
10278 URI = xmlBuildURI(location, base);
10282 ret = xmlDictLookup(dict, URI, -1);
10294 * xmlSchemaAddSchemaDoc:
10295 * @pctxt: a schema validation context
10296 * @schema: the schema being built
10297 * @node: a subtree containing XML Schema informations
10299 * Parse an included (and to-be-redefined) XML schema document.
10301 * Returns 0 on success, a positive error code on errors and
10302 * -1 in case of an internal or API error.
10306 xmlSchemaAddSchemaDoc(xmlSchemaParserCtxtPtr pctxt,
10307 int type, /* import or include or redefine */
10308 const xmlChar *schemaLocation,
10309 xmlDocPtr schemaDoc,
10310 const char *schemaBuffer,
10311 int schemaBufferLen,
10312 xmlNodePtr invokingNode,
10313 const xmlChar *sourceTargetNamespace,
10314 const xmlChar *importNamespace,
10315 xmlSchemaBucketPtr *bucket)
10317 const xmlChar *targetNamespace = NULL;
10318 xmlSchemaSchemaRelationPtr relation = NULL;
10319 xmlDocPtr doc = NULL;
10320 int res = 0, err = 0, located = 0, preserveDoc = 0;
10321 xmlSchemaBucketPtr bkt = NULL;
10323 if (bucket != NULL)
10327 case XML_SCHEMA_SCHEMA_IMPORT:
10328 case XML_SCHEMA_SCHEMA_MAIN:
10329 err = XML_SCHEMAP_SRC_IMPORT;
10331 case XML_SCHEMA_SCHEMA_INCLUDE:
10332 err = XML_SCHEMAP_SRC_INCLUDE;
10334 case XML_SCHEMA_SCHEMA_REDEFINE:
10335 err = XML_SCHEMAP_SRC_REDEFINE;
10340 /* Special handling for the main schema:
10341 * skip the location and relation logic and just parse the doc.
10342 * We need just a bucket to be returned in this case.
10344 if ((type == XML_SCHEMA_SCHEMA_MAIN) || (! WXS_HAS_BUCKETS(pctxt)))
10347 /* Note that we expect the location to be an absulute URI. */
10348 if (schemaLocation != NULL) {
10349 bkt = xmlSchemaGetSchemaBucket(pctxt, schemaLocation);
10350 if ((bkt != NULL) &&
10351 (pctxt->constructor->bucket == bkt)) {
10352 /* Report self-imports/inclusions/redefinitions. */
10354 xmlSchemaCustomErr(ACTXT_CAST pctxt, err,
10355 invokingNode, NULL,
10356 "The schema must not import/include/redefine itself",
10362 * Create a relation for the graph of schemas.
10364 relation = xmlSchemaSchemaRelationCreate();
10365 if (relation == NULL)
10367 xmlSchemaSchemaRelationAddChild(pctxt->constructor->bucket,
10369 relation->type = type;
10372 * Save the namespace import information.
10374 if (WXS_IS_BUCKET_IMPMAIN(type)) {
10375 relation->importNamespace = importNamespace;
10376 if (schemaLocation == NULL) {
10378 * No location; this is just an import of the namespace.
10379 * Note that we don't assign a bucket to the relation
10384 targetNamespace = importNamespace;
10387 /* Did we already fetch the doc? */
10389 if ((WXS_IS_BUCKET_IMPMAIN(type)) && (! bkt->imported)) {
10391 * We included/redefined and then try to import a schema,
10392 * but the new location provided for import was different.
10394 if (schemaLocation == NULL)
10395 schemaLocation = BAD_CAST "in_memory_buffer";
10396 if (!xmlStrEqual(schemaLocation,
10397 bkt->schemaLocation)) {
10398 xmlSchemaCustomErr(ACTXT_CAST pctxt, err,
10399 invokingNode, NULL,
10400 "The schema document '%s' cannot be imported, since "
10401 "it was already included or redefined",
10402 schemaLocation, NULL);
10405 } else if ((! WXS_IS_BUCKET_IMPMAIN(type)) && (bkt->imported)) {
10407 * We imported and then try to include/redefine a schema,
10408 * but the new location provided for the include/redefine
10411 if (schemaLocation == NULL)
10412 schemaLocation = BAD_CAST "in_memory_buffer";
10413 if (!xmlStrEqual(schemaLocation,
10414 bkt->schemaLocation)) {
10415 xmlSchemaCustomErr(ACTXT_CAST pctxt, err,
10416 invokingNode, NULL,
10417 "The schema document '%s' cannot be included or "
10418 "redefined, since it was already imported",
10419 schemaLocation, NULL);
10425 if (WXS_IS_BUCKET_IMPMAIN(type)) {
10427 * Given that the schemaLocation [attribute] is only a hint, it is open
10428 * to applications to ignore all but the first <import> for a given
10429 * namespace, regardless of the `actual value` of schemaLocation, but
10430 * such a strategy risks missing useful information when new
10431 * schemaLocations are offered.
10433 * We will use the first <import> that comes with a location.
10434 * Further <import>s *with* a location, will result in an error.
10435 * TODO: Better would be to just report a warning here, but
10436 * we'll try it this way until someone complains.
10438 * Schema Document Location Strategy:
10439 * 3 Based on the namespace name, identify an existing schema document,
10440 * either as a resource which is an XML document or a <schema> element
10441 * information item, in some local schema repository;
10442 * 5 Attempt to resolve the namespace name to locate such a resource.
10444 * NOTE: (3) and (5) are not supported.
10447 relation->bucket = bkt;
10450 bkt = xmlSchemaGetSchemaBucketByTNS(pctxt,
10451 importNamespace, 1);
10454 relation->bucket = bkt;
10455 if (bkt->schemaLocation == NULL) {
10456 /* First given location of the schema; load the doc. */
10457 bkt->schemaLocation = schemaLocation;
10459 if (!xmlStrEqual(schemaLocation,
10460 bkt->schemaLocation)) {
10462 * Additional location given; just skip it.
10463 * URGENT TODO: We should report a warning here.
10464 * res = XML_SCHEMAP_SRC_IMPORT;
10466 if (schemaLocation == NULL)
10467 schemaLocation = BAD_CAST "in_memory_buffer";
10469 xmlSchemaCustomWarning(ACTXT_CAST pctxt,
10470 XML_SCHEMAP_WARN_SKIP_SCHEMA,
10471 invokingNode, NULL,
10472 "Skipping import of schema located at '%s' for the "
10473 "namespace '%s', since this namespace was already "
10474 "imported with the schema located at '%s'",
10475 schemaLocation, importNamespace, bkt->schemaLocation);
10481 * No bucket + first location: load the doc and create a
10485 /* <include> and <redefine> */
10488 if ((bkt->origTargetNamespace == NULL) &&
10489 (bkt->targetNamespace != sourceTargetNamespace)) {
10490 xmlSchemaBucketPtr chamel;
10493 * Chameleon include/redefine: skip loading only if it was
10494 * aleady build for the targetNamespace of the including
10498 * URGENT TODO: If the schema is a chameleon-include then copy
10499 * the components into the including schema and modify the
10500 * targetNamespace of those components, do nothing otherwise.
10501 * NOTE: This is currently worked-around by compiling the
10502 * chameleon for every destinct including targetNamespace; thus
10503 * not performant at the moment.
10504 * TODO: Check when the namespace in wildcards for chameleons
10505 * needs to be converted: before we built wildcard intersections
10509 chamel = xmlSchemaGetChameleonSchemaBucket(pctxt,
10510 schemaLocation, sourceTargetNamespace);
10511 if (chamel != NULL) {
10512 /* A fitting chameleon was already parsed; NOP. */
10513 relation->bucket = chamel;
10517 * We need to parse the chameleon again for a different
10519 * CHAMELEON TODO: Optimize this by only parsing the
10520 * chameleon once, and then copying the components to
10521 * the new targetNamespace.
10525 relation->bucket = bkt;
10530 if ((bkt != NULL) && (bkt->doc != NULL)) {
10531 PERROR_INT("xmlSchemaAddSchemaDoc",
10532 "trying to load a schema doc, but a doc is already "
10533 "assigned to the schema bucket");
10539 * Load the document.
10541 if (schemaDoc != NULL) {
10543 /* Don' free this one, since it was provided by the caller. */
10545 /* TODO: Does the context or the doc hold the location? */
10546 if (schemaDoc->URL != NULL)
10547 schemaLocation = xmlDictLookup(pctxt->dict,
10548 schemaDoc->URL, -1);
10550 schemaLocation = BAD_CAST "in_memory_buffer";
10551 } else if ((schemaLocation != NULL) || (schemaBuffer != NULL)) {
10552 xmlParserCtxtPtr parserCtxt;
10554 parserCtxt = xmlNewParserCtxt();
10555 if (parserCtxt == NULL) {
10556 xmlSchemaPErrMemory(NULL, "xmlSchemaGetDoc, "
10557 "allocating a parser context", NULL);
10560 if ((pctxt->dict != NULL) && (parserCtxt->dict != NULL)) {
10562 * TODO: Do we have to burden the schema parser dict with all
10563 * the content of the schema doc?
10565 xmlDictFree(parserCtxt->dict);
10566 parserCtxt->dict = pctxt->dict;
10567 xmlDictReference(parserCtxt->dict);
10569 if (schemaLocation != NULL) {
10570 /* Parse from file. */
10571 doc = xmlCtxtReadFile(parserCtxt, (const char *) schemaLocation,
10572 NULL, SCHEMAS_PARSE_OPTIONS);
10573 } else if (schemaBuffer != NULL) {
10574 /* Parse from memory buffer. */
10575 doc = xmlCtxtReadMemory(parserCtxt, schemaBuffer, schemaBufferLen,
10576 NULL, NULL, SCHEMAS_PARSE_OPTIONS);
10577 schemaLocation = BAD_CAST "in_memory_buffer";
10579 doc->URL = xmlStrdup(schemaLocation);
10583 * 2.1 The referent is (a fragment of) a resource which is an
10584 * XML document (see clause 1.1), which in turn corresponds to
10585 * a <schema> element information item in a well-formed information
10586 * set, which in turn corresponds to a valid schema.
10587 * TODO: (2.1) fragments of XML documents are not supported.
10589 * 2.2 The referent is a <schema> element information item in
10590 * a well-formed information set, which in turn corresponds
10591 * to a valid schema.
10592 * TODO: (2.2) is not supported.
10596 lerr = xmlGetLastError();
10598 * Check if this a parser error, or if the document could
10599 * just not be located.
10600 * TODO: Try to find specific error codes to react only on
10601 * localisation failures.
10603 if ((lerr == NULL) || (lerr->domain != XML_FROM_IO)) {
10605 * We assume a parser error here.
10608 /* TODO: Error code ?? */
10609 res = XML_SCHEMAP_SRC_IMPORT_2_1;
10610 xmlSchemaCustomErr(ACTXT_CAST pctxt, res,
10611 invokingNode, NULL,
10612 "Failed to parse the XML resource '%s'",
10613 schemaLocation, NULL);
10616 xmlFreeParserCtxt(parserCtxt);
10617 if ((doc == NULL) && located)
10620 xmlSchemaPErr(pctxt, NULL,
10621 XML_SCHEMAP_NOTHING_TO_PARSE,
10622 "No information for parsing was provided with the "
10623 "given schema parser context.\n",
10628 * Preprocess the document.
10631 xmlNodePtr docElem = NULL;
10634 docElem = xmlDocGetRootElement(doc);
10635 if (docElem == NULL) {
10636 xmlSchemaCustomErr(ACTXT_CAST pctxt, XML_SCHEMAP_NOROOT,
10637 invokingNode, NULL,
10638 "The document '%s' has no document element",
10639 schemaLocation, NULL);
10643 * Remove all the blank text nodes.
10645 xmlSchemaCleanupDoc(pctxt, docElem);
10647 * Check the schema's top level element.
10649 if (!IS_SCHEMA(docElem, "schema")) {
10650 xmlSchemaCustomErr(ACTXT_CAST pctxt, XML_SCHEMAP_NOT_SCHEMA,
10651 invokingNode, NULL,
10652 "The XML document '%s' is not a schema document",
10653 schemaLocation, NULL);
10657 * Note that we don't apply a type check for the
10658 * targetNamespace value here.
10660 targetNamespace = xmlSchemaGetProp(pctxt, docElem,
10661 "targetNamespace");
10664 /* after_doc_loading: */
10665 if ((bkt == NULL) && located) {
10666 /* Only create a bucket if the schema was located. */
10667 bkt = xmlSchemaBucketCreate(pctxt, type,
10673 bkt->schemaLocation = schemaLocation;
10674 bkt->located = located;
10677 bkt->targetNamespace = targetNamespace;
10678 bkt->origTargetNamespace = targetNamespace;
10680 bkt->preserveDoc = 1;
10682 if (WXS_IS_BUCKET_IMPMAIN(type))
10685 * Add it to the graph of schemas.
10687 if (relation != NULL)
10688 relation->bucket = bkt;
10693 * Return the bucket explicitely; this is needed for the
10696 if (bucket != NULL)
10701 if ((doc != NULL) && (! preserveDoc)) {
10706 return(pctxt->err);
10709 if ((doc != NULL) && (! preserveDoc)) {
10718 * xmlSchemaParseImport:
10719 * @ctxt: a schema validation context
10720 * @schema: the schema being built
10721 * @node: a subtree containing XML Schema informations
10723 * parse a XML schema Import definition
10724 * *WARNING* this interface is highly subject to change
10726 * Returns 0 in case of success, a positive error code if
10727 * not valid and -1 in case of an internal error.
10730 xmlSchemaParseImport(xmlSchemaParserCtxtPtr pctxt, xmlSchemaPtr schema,
10734 const xmlChar *namespaceName = NULL, *schemaLocation = NULL;
10735 const xmlChar *thisTargetNamespace;
10738 xmlSchemaBucketPtr bucket = NULL;
10740 if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
10744 * Check for illegal attributes.
10746 attr = node->properties;
10747 while (attr != NULL) {
10748 if (attr->ns == NULL) {
10749 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
10750 (!xmlStrEqual(attr->name, BAD_CAST "namespace")) &&
10751 (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation"))) {
10752 xmlSchemaPIllegalAttrErr(pctxt,
10753 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
10755 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
10756 xmlSchemaPIllegalAttrErr(pctxt,
10757 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
10762 * Extract and validate attributes.
10764 if (xmlSchemaPValAttr(pctxt, NULL, node,
10765 "namespace", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI),
10766 &namespaceName) != 0) {
10767 xmlSchemaPSimpleTypeErr(pctxt,
10768 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
10770 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI),
10771 NULL, namespaceName, NULL, NULL, NULL);
10772 return (pctxt->err);
10775 if (xmlSchemaPValAttr(pctxt, NULL, node,
10776 "schemaLocation", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI),
10777 &schemaLocation) != 0) {
10778 xmlSchemaPSimpleTypeErr(pctxt,
10779 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
10781 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI),
10782 NULL, schemaLocation, NULL, NULL, NULL);
10783 return (pctxt->err);
10786 * And now for the children...
10788 child = node->children;
10789 if (IS_SCHEMA(child, "annotation")) {
10791 * the annotation here is simply discarded ...
10794 child = child->next;
10796 if (child != NULL) {
10797 xmlSchemaPContentErr(pctxt,
10798 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
10799 NULL, node, child, NULL,
10803 * Apply additional constraints.
10805 * Note that it is important to use the original @targetNamespace
10806 * (or none at all), to rule out imports of schemas _with_ a
10807 * @targetNamespace if the importing schema is a chameleon schema
10808 * (with no @targetNamespace).
10810 thisTargetNamespace = WXS_BUCKET(pctxt)->origTargetNamespace;
10811 if (namespaceName != NULL) {
10813 * 1.1 If the namespace [attribute] is present, then its `actual value`
10814 * must not match the `actual value` of the enclosing <schema>'s
10815 * targetNamespace [attribute].
10817 if (xmlStrEqual(thisTargetNamespace, namespaceName)) {
10818 xmlSchemaPCustomErr(pctxt,
10819 XML_SCHEMAP_SRC_IMPORT_1_1,
10821 "The value of the attribute 'namespace' must not match "
10822 "the target namespace '%s' of the importing schema",
10823 thisTargetNamespace);
10824 return (pctxt->err);
10828 * 1.2 If the namespace [attribute] is not present, then the enclosing
10829 * <schema> must have a targetNamespace [attribute].
10831 if (thisTargetNamespace == NULL) {
10832 xmlSchemaPCustomErr(pctxt,
10833 XML_SCHEMAP_SRC_IMPORT_1_2,
10835 "The attribute 'namespace' must be existent if "
10836 "the importing schema has no target namespace",
10838 return (pctxt->err);
10842 * Locate and acquire the schema document.
10844 if (schemaLocation != NULL)
10845 schemaLocation = xmlSchemaBuildAbsoluteURI(pctxt->dict,
10846 schemaLocation, node);
10847 ret = xmlSchemaAddSchemaDoc(pctxt, XML_SCHEMA_SCHEMA_IMPORT,
10848 schemaLocation, NULL, NULL, 0, node, thisTargetNamespace,
10849 namespaceName, &bucket);
10855 * For <import>: "It is *not* an error for the application
10856 * schema reference strategy to fail."
10857 * So just don't parse if no schema document was found.
10858 * Note that we will get no bucket if the schema could not be
10859 * located or if there was no schemaLocation.
10861 if ((bucket == NULL) && (schemaLocation != NULL)) {
10862 xmlSchemaCustomWarning(ACTXT_CAST pctxt,
10863 XML_SCHEMAP_WARN_UNLOCATED_SCHEMA,
10865 "Failed to locate a schema at location '%s'. "
10866 "Skipping the import", schemaLocation, NULL, NULL);
10869 if ((bucket != NULL) && CAN_PARSE_SCHEMA(bucket)) {
10870 ret = xmlSchemaParseNewDoc(pctxt, schema, bucket);
10877 xmlSchemaParseIncludeOrRedefineAttrs(xmlSchemaParserCtxtPtr pctxt,
10878 xmlSchemaPtr schema,
10880 xmlChar **schemaLocation,
10885 if ((pctxt == NULL) || (schema == NULL) || (node == NULL) ||
10886 (schemaLocation == NULL))
10889 *schemaLocation = NULL;
10891 * Check for illegal attributes.
10892 * Applies for both <include> and <redefine>.
10894 attr = node->properties;
10895 while (attr != NULL) {
10896 if (attr->ns == NULL) {
10897 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
10898 (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation"))) {
10899 xmlSchemaPIllegalAttrErr(pctxt,
10900 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
10902 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
10903 xmlSchemaPIllegalAttrErr(pctxt,
10904 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
10908 xmlSchemaPValAttrID(pctxt, node, BAD_CAST "id");
10910 * Preliminary step, extract the URI-Reference and make an URI
10914 * Attribute "schemaLocation" is mandatory.
10916 attr = xmlSchemaGetPropNode(node, "schemaLocation");
10917 if (attr != NULL) {
10918 xmlChar *base = NULL;
10919 xmlChar *uri = NULL;
10921 if (xmlSchemaPValAttrNode(pctxt, NULL, attr,
10922 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI),
10923 (const xmlChar **) schemaLocation) != 0)
10925 base = xmlNodeGetBase(node->doc, node);
10926 if (base == NULL) {
10927 uri = xmlBuildURI(*schemaLocation, node->doc->URL);
10929 uri = xmlBuildURI(*schemaLocation, base);
10933 PERROR_INT("xmlSchemaParseIncludeOrRedefine",
10934 "could not build an URI from the schemaLocation")
10937 (*schemaLocation) = (xmlChar *) xmlDictLookup(pctxt->dict, uri, -1);
10940 xmlSchemaPMissingAttrErr(pctxt,
10941 XML_SCHEMAP_S4S_ATTR_MISSING,
10942 NULL, node, "schemaLocation", NULL);
10946 * Report self-inclusion and self-redefinition.
10948 if (xmlStrEqual(*schemaLocation, pctxt->URL)) {
10949 if (type == XML_SCHEMA_SCHEMA_REDEFINE) {
10950 xmlSchemaPCustomErr(pctxt,
10951 XML_SCHEMAP_SRC_REDEFINE,
10953 "The schema document '%s' cannot redefine itself.",
10956 xmlSchemaPCustomErr(pctxt,
10957 XML_SCHEMAP_SRC_INCLUDE,
10959 "The schema document '%s' cannot include itself.",
10967 return(pctxt->err);
10973 xmlSchemaParseIncludeOrRedefine(xmlSchemaParserCtxtPtr pctxt,
10974 xmlSchemaPtr schema,
10978 xmlNodePtr child = NULL;
10979 const xmlChar *schemaLocation = NULL;
10980 int res = 0; /* hasRedefinitions = 0 */
10981 int isChameleon = 0, wasChameleon = 0;
10982 xmlSchemaBucketPtr bucket = NULL;
10984 if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
10988 * Parse attributes. Note that the returned schemaLocation will
10989 * be already converted to an absolute URI.
10991 res = xmlSchemaParseIncludeOrRedefineAttrs(pctxt, schema,
10992 node, (xmlChar **) (&schemaLocation), type);
10996 * Load and add the schema document.
10998 res = xmlSchemaAddSchemaDoc(pctxt, type, schemaLocation, NULL,
10999 NULL, 0, node, pctxt->targetNamespace, NULL, &bucket);
11003 * If we get no schema bucket back, then this means that the schema
11004 * document could not be located or was broken XML or was not
11005 * a schema document.
11007 if ((bucket == NULL) || (bucket->doc == NULL)) {
11008 if (type == XML_SCHEMA_SCHEMA_INCLUDE) {
11010 * WARNING for <include>:
11011 * We will raise an error if the schema cannot be located
11012 * for inclusions, since the that was the feedback from the
11013 * schema people. I.e. the following spec piece will *not* be
11015 * SPEC src-include: "It is not an error for the `actual value` of the
11016 * schemaLocation [attribute] to fail to resolve it all, in which
11017 * case no corresponding inclusion is performed.
11018 * So do we need a warning report here?"
11020 res = XML_SCHEMAP_SRC_INCLUDE;
11021 xmlSchemaCustomErr(ACTXT_CAST pctxt, res,
11023 "Failed to load the document '%s' for inclusion",
11024 schemaLocation, NULL);
11027 * NOTE: This was changed to raise an error even if no redefinitions
11030 * SPEC src-redefine (1)
11031 * "If there are any element information items among the [children]
11032 * other than <annotation> then the `actual value` of the
11033 * schemaLocation [attribute] must successfully resolve."
11034 * TODO: Ask the WG if a the location has always to resolve
11037 res = XML_SCHEMAP_SRC_REDEFINE;
11038 xmlSchemaCustomErr(ACTXT_CAST pctxt, res,
11040 "Failed to load the document '%s' for redefinition",
11041 schemaLocation, NULL);
11045 * Check targetNamespace sanity before parsing the new schema.
11046 * TODO: Note that we won't check further content if the
11047 * targetNamespace was bad.
11049 if (bucket->origTargetNamespace != NULL) {
11051 * SPEC src-include (2.1)
11052 * "SII has a targetNamespace [attribute], and its `actual
11053 * value` is identical to the `actual value` of the targetNamespace
11054 * [attribute] of SII' (which must have such an [attribute])."
11056 if (pctxt->targetNamespace == NULL) {
11057 xmlSchemaCustomErr(ACTXT_CAST pctxt,
11058 XML_SCHEMAP_SRC_INCLUDE,
11060 "The target namespace of the included/redefined schema "
11061 "'%s' has to be absent, since the including/redefining "
11062 "schema has no target namespace",
11063 schemaLocation, NULL);
11065 } else if (!xmlStrEqual(bucket->origTargetNamespace,
11066 pctxt->targetNamespace)) {
11067 /* TODO: Change error function. */
11068 xmlSchemaPCustomErrExt(pctxt,
11069 XML_SCHEMAP_SRC_INCLUDE,
11071 "The target namespace '%s' of the included/redefined "
11072 "schema '%s' differs from '%s' of the "
11073 "including/redefining schema",
11074 bucket->origTargetNamespace, schemaLocation,
11075 pctxt->targetNamespace);
11078 } else if (pctxt->targetNamespace != NULL) {
11080 * Chameleons: the original target namespace will
11081 * differ from the resulting namespace.
11084 if (bucket->parsed &&
11085 bucket->origTargetNamespace != NULL) {
11086 xmlSchemaCustomErr(ACTXT_CAST pctxt,
11087 XML_SCHEMAP_SRC_INCLUDE,
11089 "The target namespace of the included/redefined schema "
11090 "'%s' has to be absent or the same as the "
11091 "including/redefining schema's target namespace",
11092 schemaLocation, NULL);
11095 bucket->targetNamespace = pctxt->targetNamespace;
11099 * Parse the schema.
11101 if (bucket && (!bucket->parsed) && (bucket->doc != NULL)) {
11103 /* TODO: Get rid of this flag on the schema itself. */
11104 if ((schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) == 0) {
11105 schema->flags |= XML_SCHEMAS_INCLUDING_CONVERT_NS;
11109 xmlSchemaParseNewDoc(pctxt, schema, bucket);
11110 /* Restore chameleon flag. */
11111 if (isChameleon && (!wasChameleon))
11112 schema->flags ^= XML_SCHEMAS_INCLUDING_CONVERT_NS;
11115 * And now for the children...
11117 child = node->children;
11118 if (type == XML_SCHEMA_SCHEMA_REDEFINE) {
11120 * Parse (simpleType | complexType | group | attributeGroup))*
11122 pctxt->redefined = bucket;
11124 * How to proceed if the redefined schema was not located?
11126 pctxt->isRedefine = 1;
11127 while (IS_SCHEMA(child, "annotation") ||
11128 IS_SCHEMA(child, "simpleType") ||
11129 IS_SCHEMA(child, "complexType") ||
11130 IS_SCHEMA(child, "group") ||
11131 IS_SCHEMA(child, "attributeGroup")) {
11132 if (IS_SCHEMA(child, "annotation")) {
11134 * TODO: discard or not?
11136 } else if (IS_SCHEMA(child, "simpleType")) {
11137 xmlSchemaParseSimpleType(pctxt, schema, child, 1);
11138 } else if (IS_SCHEMA(child, "complexType")) {
11139 xmlSchemaParseComplexType(pctxt, schema, child, 1);
11140 /* hasRedefinitions = 1; */
11141 } else if (IS_SCHEMA(child, "group")) {
11142 /* hasRedefinitions = 1; */
11143 xmlSchemaParseModelGroupDefinition(pctxt,
11145 } else if (IS_SCHEMA(child, "attributeGroup")) {
11146 /* hasRedefinitions = 1; */
11147 xmlSchemaParseAttributeGroupDefinition(pctxt, schema,
11150 child = child->next;
11152 pctxt->redefined = NULL;
11153 pctxt->isRedefine = 0;
11155 if (IS_SCHEMA(child, "annotation")) {
11157 * TODO: discard or not?
11159 child = child->next;
11162 if (child != NULL) {
11163 res = XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED;
11164 if (type == XML_SCHEMA_SCHEMA_REDEFINE) {
11165 xmlSchemaPContentErr(pctxt, res,
11166 NULL, node, child, NULL,
11167 "(annotation | (simpleType | complexType | group | attributeGroup))*");
11169 xmlSchemaPContentErr(pctxt, res,
11170 NULL, node, child, NULL,
11177 return(pctxt->err);
11181 xmlSchemaParseRedefine(xmlSchemaParserCtxtPtr pctxt, xmlSchemaPtr schema,
11185 #ifndef ENABLE_REDEFINE
11189 res = xmlSchemaParseIncludeOrRedefine(pctxt, schema, node,
11190 XML_SCHEMA_SCHEMA_REDEFINE);
11197 xmlSchemaParseInclude(xmlSchemaParserCtxtPtr pctxt, xmlSchemaPtr schema,
11202 res = xmlSchemaParseIncludeOrRedefine(pctxt, schema, node,
11203 XML_SCHEMA_SCHEMA_INCLUDE);
11210 * xmlSchemaParseModelGroup:
11211 * @ctxt: a schema validation context
11212 * @schema: the schema being built
11213 * @node: a subtree containing XML Schema informations
11214 * @type: the "compositor" type
11215 * @particleNeeded: if a a model group with a particle
11217 * parse a XML schema Sequence definition.
11218 * Applies parts of:
11219 * Schema Representation Constraint:
11220 * Redefinition Constraints and Semantics (src-redefine)
11221 * (6.1), (6.1.1), (6.1.2)
11223 * Schema Component Constraint:
11224 * All Group Limited (cos-all-limited) (2)
11225 * TODO: Actually this should go to component-level checks,
11226 * but is done here due to performance. Move it to an other layer
11227 * is schema construction via an API is implemented.
11229 * *WARNING* this interface is highly subject to change
11231 * Returns -1 in case of error, 0 if the declaration is improper and
11232 * 1 in case of success.
11234 static xmlSchemaTreeItemPtr
11235 xmlSchemaParseModelGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
11236 xmlNodePtr node, xmlSchemaTypeType type,
11239 xmlSchemaModelGroupPtr item;
11240 xmlSchemaParticlePtr particle = NULL;
11241 xmlNodePtr child = NULL;
11243 int min = 1, max = 1, isElemRef, hasRefs = 0;
11245 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
11248 * Create a model group with the given compositor.
11250 item = xmlSchemaAddModelGroup(ctxt, schema, type, node);
11254 if (withParticle) {
11255 if (type == XML_SCHEMA_TYPE_ALL) {
11256 min = xmlGetMinOccurs(ctxt, node, 0, 1, 1, "(0 | 1)");
11257 max = xmlGetMaxOccurs(ctxt, node, 1, 1, 1, "1");
11259 /* choice + sequence */
11260 min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "xs:nonNegativeInteger");
11261 max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1,
11262 "(xs:nonNegativeInteger | unbounded)");
11264 xmlSchemaPCheckParticleCorrect_2(ctxt, NULL, node, min, max);
11266 * Create a particle
11268 particle = xmlSchemaAddParticle(ctxt, node, min, max);
11269 if (particle == NULL)
11271 particle->children = (xmlSchemaTreeItemPtr) item;
11273 * Check for illegal attributes.
11275 attr = node->properties;
11276 while (attr != NULL) {
11277 if (attr->ns == NULL) {
11278 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
11279 (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) &&
11280 (!xmlStrEqual(attr->name, BAD_CAST "minOccurs"))) {
11281 xmlSchemaPIllegalAttrErr(ctxt,
11282 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
11284 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
11285 xmlSchemaPIllegalAttrErr(ctxt,
11286 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
11292 * Check for illegal attributes.
11294 attr = node->properties;
11295 while (attr != NULL) {
11296 if (attr->ns == NULL) {
11297 if (!xmlStrEqual(attr->name, BAD_CAST "id")) {
11298 xmlSchemaPIllegalAttrErr(ctxt,
11299 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
11301 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
11302 xmlSchemaPIllegalAttrErr(ctxt,
11303 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
11310 * Extract and validate attributes.
11312 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
11314 * And now for the children...
11316 child = node->children;
11317 if (IS_SCHEMA(child, "annotation")) {
11318 item->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
11319 child = child->next;
11321 if (type == XML_SCHEMA_TYPE_ALL) {
11322 xmlSchemaParticlePtr part, last = NULL;
11324 while (IS_SCHEMA(child, "element")) {
11325 part = (xmlSchemaParticlePtr) xmlSchemaParseElement(ctxt,
11326 schema, child, &isElemRef, 0);
11328 * SPEC cos-all-limited (2)
11329 * "The {max occurs} of all the particles in the {particles}
11330 * of the ('all') group must be 0 or 1.
11332 if (part != NULL) {
11335 if (part->minOccurs > 1) {
11336 xmlSchemaPCustomErr(ctxt,
11337 XML_SCHEMAP_COS_ALL_LIMITED,
11339 "Invalid value for minOccurs (must be 0 or 1)",
11342 part->minOccurs = 1;
11344 if (part->maxOccurs > 1) {
11345 xmlSchemaPCustomErr(ctxt,
11346 XML_SCHEMAP_COS_ALL_LIMITED,
11348 "Invalid value for maxOccurs (must be 0 or 1)",
11351 part->maxOccurs = 1;
11354 item->children = (xmlSchemaTreeItemPtr) part;
11356 last->next = (xmlSchemaTreeItemPtr) part;
11359 child = child->next;
11361 if (child != NULL) {
11362 xmlSchemaPContentErr(ctxt,
11363 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
11364 NULL, node, child, NULL,
11365 "(annotation?, (annotation?, element*)");
11368 /* choice + sequence */
11369 xmlSchemaTreeItemPtr part = NULL, last = NULL;
11371 while ((IS_SCHEMA(child, "element")) ||
11372 (IS_SCHEMA(child, "group")) ||
11373 (IS_SCHEMA(child, "any")) ||
11374 (IS_SCHEMA(child, "choice")) ||
11375 (IS_SCHEMA(child, "sequence"))) {
11377 if (IS_SCHEMA(child, "element")) {
11378 part = (xmlSchemaTreeItemPtr)
11379 xmlSchemaParseElement(ctxt, schema, child, &isElemRef, 0);
11380 if (part && isElemRef)
11382 } else if (IS_SCHEMA(child, "group")) {
11384 xmlSchemaParseModelGroupDefRef(ctxt, schema, child);
11388 * Handle redefinitions.
11390 if (ctxt->isRedefine && ctxt->redef &&
11391 (ctxt->redef->item->type == XML_SCHEMA_TYPE_GROUP) &&
11392 part && part->children)
11394 if ((xmlSchemaGetQNameRefName(part->children) ==
11395 ctxt->redef->refName) &&
11396 (xmlSchemaGetQNameRefTargetNs(part->children) ==
11397 ctxt->redef->refTargetNs))
11400 * SPEC src-redefine:
11401 * (6.1) "If it has a <group> among its contents at
11402 * some level the `actual value` of whose ref
11403 * [attribute] is the same as the `actual value` of
11404 * its own name attribute plus target namespace, then
11405 * all of the following must be true:"
11406 * (6.1.1) "It must have exactly one such group."
11408 if (ctxt->redefCounter != 0) {
11409 xmlChar *str = NULL;
11411 xmlSchemaCustomErr(ACTXT_CAST ctxt,
11412 XML_SCHEMAP_SRC_REDEFINE, child, NULL,
11413 "The redefining model group definition "
11414 "'%s' must not contain more than one "
11415 "reference to the redefined definition",
11416 xmlSchemaFormatQName(&str,
11417 ctxt->redef->refTargetNs,
11418 ctxt->redef->refName),
11422 } else if (((WXS_PARTICLE(part))->minOccurs != 1) ||
11423 ((WXS_PARTICLE(part))->maxOccurs != 1))
11425 xmlChar *str = NULL;
11427 * SPEC src-redefine:
11428 * (6.1.2) "The `actual value` of both that
11429 * group's minOccurs and maxOccurs [attribute]
11430 * must be 1 (or `absent`).
11432 xmlSchemaCustomErr(ACTXT_CAST ctxt,
11433 XML_SCHEMAP_SRC_REDEFINE, child, NULL,
11434 "The redefining model group definition "
11435 "'%s' must not contain a reference to the "
11436 "redefined definition with a "
11437 "maxOccurs/minOccurs other than 1",
11438 xmlSchemaFormatQName(&str,
11439 ctxt->redef->refTargetNs,
11440 ctxt->redef->refName),
11445 ctxt->redef->reference = WXS_BASIC_CAST part;
11446 ctxt->redefCounter++;
11449 } else if (IS_SCHEMA(child, "any")) {
11450 part = (xmlSchemaTreeItemPtr)
11451 xmlSchemaParseAny(ctxt, schema, child);
11452 } else if (IS_SCHEMA(child, "choice")) {
11453 part = xmlSchemaParseModelGroup(ctxt, schema, child,
11454 XML_SCHEMA_TYPE_CHOICE, 1);
11455 } else if (IS_SCHEMA(child, "sequence")) {
11456 part = xmlSchemaParseModelGroup(ctxt, schema, child,
11457 XML_SCHEMA_TYPE_SEQUENCE, 1);
11459 if (part != NULL) {
11461 item->children = part;
11466 child = child->next;
11468 if (child != NULL) {
11469 xmlSchemaPContentErr(ctxt,
11470 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
11471 NULL, node, child, NULL,
11472 "(annotation?, (element | group | choice | sequence | any)*)");
11475 if ((max == 0) && (min == 0))
11479 * We need to resolve references.
11481 WXS_ADD_PENDING(ctxt, item);
11484 return ((xmlSchemaTreeItemPtr) particle);
11486 return ((xmlSchemaTreeItemPtr) item);
11490 * xmlSchemaParseRestriction:
11491 * @ctxt: a schema validation context
11492 * @schema: the schema being built
11493 * @node: a subtree containing XML Schema informations
11495 * parse a XML schema Restriction definition
11496 * *WARNING* this interface is highly subject to change
11498 * Returns the type definition or NULL in case of error
11500 static xmlSchemaTypePtr
11501 xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
11502 xmlNodePtr node, xmlSchemaTypeType parentType)
11504 xmlSchemaTypePtr type;
11505 xmlNodePtr child = NULL;
11508 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
11510 /* Not a component, don't create it. */
11511 type = ctxt->ctxtType;
11512 type->flags |= XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION;
11515 * Check for illegal attributes.
11517 attr = node->properties;
11518 while (attr != NULL) {
11519 if (attr->ns == NULL) {
11520 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
11521 (!xmlStrEqual(attr->name, BAD_CAST "base"))) {
11522 xmlSchemaPIllegalAttrErr(ctxt,
11523 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
11525 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
11526 xmlSchemaPIllegalAttrErr(ctxt,
11527 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
11532 * Extract and validate attributes.
11534 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
11539 * Extract the base type. The "base" attribute is mandatory if inside
11540 * a complex type or if redefining.
11542 * SPEC (1.2) "...otherwise (<restriction> has no <simpleType> "
11543 * among its [children]), the simple type definition which is
11544 * the {content type} of the type definition `resolved` to by
11545 * the `actual value` of the base [attribute]"
11547 if (xmlSchemaPValAttrQName(ctxt, schema, NULL, node, "base",
11548 &(type->baseNs), &(type->base)) == 0)
11550 if ((type->base == NULL) && (type->type == XML_SCHEMA_TYPE_COMPLEX)) {
11551 xmlSchemaPMissingAttrErr(ctxt,
11552 XML_SCHEMAP_S4S_ATTR_MISSING,
11553 NULL, node, "base", NULL);
11554 } else if ((ctxt->isRedefine) &&
11555 (type->flags & XML_SCHEMAS_TYPE_GLOBAL))
11557 if (type->base == NULL) {
11558 xmlSchemaPMissingAttrErr(ctxt,
11559 XML_SCHEMAP_S4S_ATTR_MISSING,
11560 NULL, node, "base", NULL);
11561 } else if ((! xmlStrEqual(type->base, type->name)) ||
11562 (! xmlStrEqual(type->baseNs, type->targetNamespace)))
11564 xmlChar *str1 = NULL, *str2 = NULL;
11566 * REDEFINE: SPEC src-redefine (5)
11567 * "Within the [children], each <simpleType> must have a
11568 * <restriction> among its [children] ... the `actual value` of
11569 * whose base [attribute] must be the same as the `actual value`
11570 * of its own name attribute plus target namespace;"
11572 xmlSchemaPCustomErrExt(ctxt, XML_SCHEMAP_SRC_REDEFINE,
11573 NULL, node, "This is a redefinition, but the QName "
11574 "value '%s' of the 'base' attribute does not match the "
11575 "type's designation '%s'",
11576 xmlSchemaFormatQName(&str1, type->baseNs, type->base),
11577 xmlSchemaFormatQName(&str2, type->targetNamespace,
11578 type->name), NULL);
11579 FREE_AND_NULL(str1);
11580 FREE_AND_NULL(str2);
11581 /* Avoid confusion and erase the values. */
11583 type->baseNs = NULL;
11588 * And now for the children...
11590 child = node->children;
11591 if (IS_SCHEMA(child, "annotation")) {
11593 * Add the annotation to the simple type ancestor.
11595 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
11596 xmlSchemaParseAnnotation(ctxt, child, 1));
11597 child = child->next;
11599 if (parentType == XML_SCHEMA_TYPE_SIMPLE) {
11601 * Corresponds to <simpleType><restriction><simpleType>.
11603 if (IS_SCHEMA(child, "simpleType")) {
11604 if (type->base != NULL) {
11606 * src-restriction-base-or-simpleType
11607 * Either the base [attribute] or the simpleType [child] of the
11608 * <restriction> element must be present, but not both.
11610 xmlSchemaPContentErr(ctxt,
11611 XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE,
11613 "The attribute 'base' and the <simpleType> child are "
11614 "mutually exclusive", NULL);
11616 type->baseType = (xmlSchemaTypePtr)
11617 xmlSchemaParseSimpleType(ctxt, schema, child, 0);
11619 child = child->next;
11620 } else if (type->base == NULL) {
11621 xmlSchemaPContentErr(ctxt,
11622 XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE,
11624 "Either the attribute 'base' or a <simpleType> child "
11625 "must be present", NULL);
11627 } else if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) {
11629 * Corresponds to <complexType><complexContent><restriction>...
11632 * Model groups <all>, <choice> and <sequence>.
11634 if (IS_SCHEMA(child, "all")) {
11635 type->subtypes = (xmlSchemaTypePtr)
11636 xmlSchemaParseModelGroup(ctxt, schema, child,
11637 XML_SCHEMA_TYPE_ALL, 1);
11638 child = child->next;
11639 } else if (IS_SCHEMA(child, "choice")) {
11640 type->subtypes = (xmlSchemaTypePtr)
11641 xmlSchemaParseModelGroup(ctxt,
11642 schema, child, XML_SCHEMA_TYPE_CHOICE, 1);
11643 child = child->next;
11644 } else if (IS_SCHEMA(child, "sequence")) {
11645 type->subtypes = (xmlSchemaTypePtr)
11646 xmlSchemaParseModelGroup(ctxt, schema, child,
11647 XML_SCHEMA_TYPE_SEQUENCE, 1);
11648 child = child->next;
11650 * Model group reference <group>.
11652 } else if (IS_SCHEMA(child, "group")) {
11653 type->subtypes = (xmlSchemaTypePtr)
11654 xmlSchemaParseModelGroupDefRef(ctxt, schema, child);
11656 * Note that the reference will be resolved in
11657 * xmlSchemaResolveTypeReferences();
11659 child = child->next;
11661 } else if (parentType == XML_SCHEMA_TYPE_SIMPLE_CONTENT) {
11663 * Corresponds to <complexType><simpleContent><restriction>...
11665 * "1.1 the simple type definition corresponding to the <simpleType>
11666 * among the [children] of <restriction> if there is one;"
11668 if (IS_SCHEMA(child, "simpleType")) {
11670 * We will store the to-be-restricted simple type in
11671 * type->contentTypeDef *temporarily*.
11673 type->contentTypeDef = (xmlSchemaTypePtr)
11674 xmlSchemaParseSimpleType(ctxt, schema, child, 0);
11675 if ( type->contentTypeDef == NULL)
11677 child = child->next;
11681 if ((parentType == XML_SCHEMA_TYPE_SIMPLE) ||
11682 (parentType == XML_SCHEMA_TYPE_SIMPLE_CONTENT)) {
11683 xmlSchemaFacetPtr facet, lastfacet = NULL;
11685 * Corresponds to <complexType><simpleContent><restriction>...
11686 * <simpleType><restriction>...
11690 * Add the facets to the simple type ancestor.
11693 * TODO: Datatypes: 4.1.3 Constraints on XML Representation of
11694 * Simple Type Definition Schema Representation Constraint:
11695 * *Single Facet Value*
11697 while ((IS_SCHEMA(child, "minInclusive")) ||
11698 (IS_SCHEMA(child, "minExclusive")) ||
11699 (IS_SCHEMA(child, "maxInclusive")) ||
11700 (IS_SCHEMA(child, "maxExclusive")) ||
11701 (IS_SCHEMA(child, "totalDigits")) ||
11702 (IS_SCHEMA(child, "fractionDigits")) ||
11703 (IS_SCHEMA(child, "pattern")) ||
11704 (IS_SCHEMA(child, "enumeration")) ||
11705 (IS_SCHEMA(child, "whiteSpace")) ||
11706 (IS_SCHEMA(child, "length")) ||
11707 (IS_SCHEMA(child, "maxLength")) ||
11708 (IS_SCHEMA(child, "minLength"))) {
11709 facet = xmlSchemaParseFacet(ctxt, schema, child);
11710 if (facet != NULL) {
11711 if (lastfacet == NULL)
11712 type->facets = facet;
11714 lastfacet->next = facet;
11716 lastfacet->next = NULL;
11718 child = child->next;
11721 * Create links for derivation and validation.
11723 if (type->facets != NULL) {
11724 xmlSchemaFacetLinkPtr facetLink, lastFacetLink = NULL;
11726 facet = type->facets;
11728 facetLink = (xmlSchemaFacetLinkPtr)
11729 xmlMalloc(sizeof(xmlSchemaFacetLink));
11730 if (facetLink == NULL) {
11731 xmlSchemaPErrMemory(ctxt, "allocating a facet link", NULL);
11732 xmlFree(facetLink);
11735 facetLink->facet = facet;
11736 facetLink->next = NULL;
11737 if (lastFacetLink == NULL)
11738 type->facetSet = facetLink;
11740 lastFacetLink->next = facetLink;
11741 lastFacetLink = facetLink;
11742 facet = facet->next;
11743 } while (facet != NULL);
11746 if (type->type == XML_SCHEMA_TYPE_COMPLEX) {
11748 * Attribute uses/declarations.
11750 if (xmlSchemaParseLocalAttributes(ctxt, schema, &child,
11751 (xmlSchemaItemListPtr *) &(type->attrUses),
11752 XML_SCHEMA_TYPE_RESTRICTION, NULL) == -1)
11755 * Attribute wildcard.
11757 if (IS_SCHEMA(child, "anyAttribute")) {
11758 type->attributeWildcard =
11759 xmlSchemaParseAnyAttribute(ctxt, schema, child);
11760 child = child->next;
11763 if (child != NULL) {
11764 if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) {
11765 xmlSchemaPContentErr(ctxt,
11766 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
11767 NULL, node, child, NULL,
11768 "annotation?, (group | all | choice | sequence)?, "
11769 "((attribute | attributeGroup)*, anyAttribute?))");
11770 } else if (parentType == XML_SCHEMA_TYPE_SIMPLE_CONTENT) {
11771 xmlSchemaPContentErr(ctxt,
11772 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
11773 NULL, node, child, NULL,
11774 "(annotation?, (simpleType?, (minExclusive | minInclusive | "
11775 "maxExclusive | maxInclusive | totalDigits | fractionDigits | "
11776 "length | minLength | maxLength | enumeration | whiteSpace | "
11777 "pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))");
11780 xmlSchemaPContentErr(ctxt,
11781 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
11782 NULL, node, child, NULL,
11783 "(annotation?, (simpleType?, (minExclusive | minInclusive | "
11784 "maxExclusive | maxInclusive | totalDigits | fractionDigits | "
11785 "length | minLength | maxLength | enumeration | whiteSpace | "
11793 * xmlSchemaParseExtension:
11794 * @ctxt: a schema validation context
11795 * @schema: the schema being built
11796 * @node: a subtree containing XML Schema informations
11798 * Parses an <extension>, which is found inside a
11799 * <simpleContent> or <complexContent>.
11800 * *WARNING* this interface is highly subject to change.
11802 * TODO: Returns the type definition or NULL in case of error
11804 static xmlSchemaTypePtr
11805 xmlSchemaParseExtension(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
11806 xmlNodePtr node, xmlSchemaTypeType parentType)
11808 xmlSchemaTypePtr type;
11809 xmlNodePtr child = NULL;
11812 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
11814 /* Not a component, don't create it. */
11815 type = ctxt->ctxtType;
11816 type->flags |= XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION;
11819 * Check for illegal attributes.
11821 attr = node->properties;
11822 while (attr != NULL) {
11823 if (attr->ns == NULL) {
11824 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
11825 (!xmlStrEqual(attr->name, BAD_CAST "base"))) {
11826 xmlSchemaPIllegalAttrErr(ctxt,
11827 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
11829 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
11830 xmlSchemaPIllegalAttrErr(ctxt,
11831 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
11836 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
11839 * Attribute "base" - mandatory.
11841 if ((xmlSchemaPValAttrQName(ctxt, schema, NULL, node,
11842 "base", &(type->baseNs), &(type->base)) == 0) &&
11843 (type->base == NULL)) {
11844 xmlSchemaPMissingAttrErr(ctxt,
11845 XML_SCHEMAP_S4S_ATTR_MISSING,
11846 NULL, node, "base", NULL);
11849 * And now for the children...
11851 child = node->children;
11852 if (IS_SCHEMA(child, "annotation")) {
11854 * Add the annotation to the type ancestor.
11856 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
11857 xmlSchemaParseAnnotation(ctxt, child, 1));
11858 child = child->next;
11860 if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) {
11862 * Corresponds to <complexType><complexContent><extension>... and:
11864 * Model groups <all>, <choice>, <sequence> and <group>.
11866 if (IS_SCHEMA(child, "all")) {
11867 type->subtypes = (xmlSchemaTypePtr)
11868 xmlSchemaParseModelGroup(ctxt, schema,
11869 child, XML_SCHEMA_TYPE_ALL, 1);
11870 child = child->next;
11871 } else if (IS_SCHEMA(child, "choice")) {
11872 type->subtypes = (xmlSchemaTypePtr)
11873 xmlSchemaParseModelGroup(ctxt, schema,
11874 child, XML_SCHEMA_TYPE_CHOICE, 1);
11875 child = child->next;
11876 } else if (IS_SCHEMA(child, "sequence")) {
11877 type->subtypes = (xmlSchemaTypePtr)
11878 xmlSchemaParseModelGroup(ctxt, schema,
11879 child, XML_SCHEMA_TYPE_SEQUENCE, 1);
11880 child = child->next;
11881 } else if (IS_SCHEMA(child, "group")) {
11882 type->subtypes = (xmlSchemaTypePtr)
11883 xmlSchemaParseModelGroupDefRef(ctxt, schema, child);
11885 * Note that the reference will be resolved in
11886 * xmlSchemaResolveTypeReferences();
11888 child = child->next;
11891 if (child != NULL) {
11893 * Attribute uses/declarations.
11895 if (xmlSchemaParseLocalAttributes(ctxt, schema, &child,
11896 (xmlSchemaItemListPtr *) &(type->attrUses),
11897 XML_SCHEMA_TYPE_EXTENSION, NULL) == -1)
11900 * Attribute wildcard.
11902 if (IS_SCHEMA(child, "anyAttribute")) {
11903 ctxt->ctxtType->attributeWildcard =
11904 xmlSchemaParseAnyAttribute(ctxt, schema, child);
11905 child = child->next;
11908 if (child != NULL) {
11909 if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) {
11910 /* Complex content extension. */
11911 xmlSchemaPContentErr(ctxt,
11912 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
11913 NULL, node, child, NULL,
11914 "(annotation?, ((group | all | choice | sequence)?, "
11915 "((attribute | attributeGroup)*, anyAttribute?)))");
11917 /* Simple content extension. */
11918 xmlSchemaPContentErr(ctxt,
11919 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
11920 NULL, node, child, NULL,
11921 "(annotation?, ((attribute | attributeGroup)*, "
11922 "anyAttribute?))");
11929 * xmlSchemaParseSimpleContent:
11930 * @ctxt: a schema validation context
11931 * @schema: the schema being built
11932 * @node: a subtree containing XML Schema informations
11934 * parse a XML schema SimpleContent definition
11935 * *WARNING* this interface is highly subject to change
11937 * Returns the type definition or NULL in case of error
11940 xmlSchemaParseSimpleContent(xmlSchemaParserCtxtPtr ctxt,
11941 xmlSchemaPtr schema, xmlNodePtr node,
11942 int *hasRestrictionOrExtension)
11944 xmlSchemaTypePtr type;
11945 xmlNodePtr child = NULL;
11948 if ((ctxt == NULL) || (schema == NULL) || (node == NULL) ||
11949 (hasRestrictionOrExtension == NULL))
11951 *hasRestrictionOrExtension = 0;
11952 /* Not a component, don't create it. */
11953 type = ctxt->ctxtType;
11954 type->contentType = XML_SCHEMA_CONTENT_SIMPLE;
11956 * Check for illegal attributes.
11958 attr = node->properties;
11959 while (attr != NULL) {
11960 if (attr->ns == NULL) {
11961 if ((!xmlStrEqual(attr->name, BAD_CAST "id"))) {
11962 xmlSchemaPIllegalAttrErr(ctxt,
11963 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
11965 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
11966 xmlSchemaPIllegalAttrErr(ctxt,
11967 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
11972 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
11975 * And now for the children...
11977 child = node->children;
11978 if (IS_SCHEMA(child, "annotation")) {
11980 * Add the annotation to the complex type ancestor.
11982 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
11983 xmlSchemaParseAnnotation(ctxt, child, 1));
11984 child = child->next;
11986 if (child == NULL) {
11987 xmlSchemaPContentErr(ctxt,
11988 XML_SCHEMAP_S4S_ELEM_MISSING,
11989 NULL, node, NULL, NULL,
11990 "(annotation?, (restriction | extension))");
11992 if (child == NULL) {
11993 xmlSchemaPContentErr(ctxt,
11994 XML_SCHEMAP_S4S_ELEM_MISSING,
11995 NULL, node, NULL, NULL,
11996 "(annotation?, (restriction | extension))");
11998 if (IS_SCHEMA(child, "restriction")) {
11999 xmlSchemaParseRestriction(ctxt, schema, child,
12000 XML_SCHEMA_TYPE_SIMPLE_CONTENT);
12001 (*hasRestrictionOrExtension) = 1;
12002 child = child->next;
12003 } else if (IS_SCHEMA(child, "extension")) {
12004 xmlSchemaParseExtension(ctxt, schema, child,
12005 XML_SCHEMA_TYPE_SIMPLE_CONTENT);
12006 (*hasRestrictionOrExtension) = 1;
12007 child = child->next;
12009 if (child != NULL) {
12010 xmlSchemaPContentErr(ctxt,
12011 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
12012 NULL, node, child, NULL,
12013 "(annotation?, (restriction | extension))");
12019 * xmlSchemaParseComplexContent:
12020 * @ctxt: a schema validation context
12021 * @schema: the schema being built
12022 * @node: a subtree containing XML Schema informations
12024 * parse a XML schema ComplexContent definition
12025 * *WARNING* this interface is highly subject to change
12027 * Returns the type definition or NULL in case of error
12030 xmlSchemaParseComplexContent(xmlSchemaParserCtxtPtr ctxt,
12031 xmlSchemaPtr schema, xmlNodePtr node,
12032 int *hasRestrictionOrExtension)
12034 xmlSchemaTypePtr type;
12035 xmlNodePtr child = NULL;
12038 if ((ctxt == NULL) || (schema == NULL) || (node == NULL) ||
12039 (hasRestrictionOrExtension == NULL))
12041 *hasRestrictionOrExtension = 0;
12042 /* Not a component, don't create it. */
12043 type = ctxt->ctxtType;
12045 * Check for illegal attributes.
12047 attr = node->properties;
12048 while (attr != NULL) {
12049 if (attr->ns == NULL) {
12050 if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
12051 (!xmlStrEqual(attr->name, BAD_CAST "mixed")))
12053 xmlSchemaPIllegalAttrErr(ctxt,
12054 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
12056 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
12057 xmlSchemaPIllegalAttrErr(ctxt,
12058 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
12063 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
12066 * Set the 'mixed' on the complex type ancestor.
12068 if (xmlGetBooleanProp(ctxt, node, "mixed", 0)) {
12069 if ((type->flags & XML_SCHEMAS_TYPE_MIXED) == 0)
12070 type->flags |= XML_SCHEMAS_TYPE_MIXED;
12072 child = node->children;
12073 if (IS_SCHEMA(child, "annotation")) {
12075 * Add the annotation to the complex type ancestor.
12077 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
12078 xmlSchemaParseAnnotation(ctxt, child, 1));
12079 child = child->next;
12081 if (child == NULL) {
12082 xmlSchemaPContentErr(ctxt,
12083 XML_SCHEMAP_S4S_ELEM_MISSING,
12085 NULL, "(annotation?, (restriction | extension))");
12087 if (child == NULL) {
12088 xmlSchemaPContentErr(ctxt,
12089 XML_SCHEMAP_S4S_ELEM_MISSING,
12091 NULL, "(annotation?, (restriction | extension))");
12093 if (IS_SCHEMA(child, "restriction")) {
12094 xmlSchemaParseRestriction(ctxt, schema, child,
12095 XML_SCHEMA_TYPE_COMPLEX_CONTENT);
12096 (*hasRestrictionOrExtension) = 1;
12097 child = child->next;
12098 } else if (IS_SCHEMA(child, "extension")) {
12099 xmlSchemaParseExtension(ctxt, schema, child,
12100 XML_SCHEMA_TYPE_COMPLEX_CONTENT);
12101 (*hasRestrictionOrExtension) = 1;
12102 child = child->next;
12104 if (child != NULL) {
12105 xmlSchemaPContentErr(ctxt,
12106 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
12108 NULL, "(annotation?, (restriction | extension))");
12114 * xmlSchemaParseComplexType:
12115 * @ctxt: a schema validation context
12116 * @schema: the schema being built
12117 * @node: a subtree containing XML Schema informations
12119 * parse a XML schema Complex Type definition
12120 * *WARNING* this interface is highly subject to change
12122 * Returns the type definition or NULL in case of error
12124 static xmlSchemaTypePtr
12125 xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
12126 xmlNodePtr node, int topLevel)
12128 xmlSchemaTypePtr type, ctxtType;
12129 xmlNodePtr child = NULL;
12130 const xmlChar *name = NULL;
12132 const xmlChar *attrValue;
12133 #ifdef ENABLE_NAMED_LOCALS
12136 int final = 0, block = 0, hasRestrictionOrExtension = 0;
12139 if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
12142 ctxtType = ctxt->ctxtType;
12145 attr = xmlSchemaGetPropNode(node, "name");
12146 if (attr == NULL) {
12147 xmlSchemaPMissingAttrErr(ctxt,
12148 XML_SCHEMAP_S4S_ATTR_MISSING, NULL, node, "name", NULL);
12150 } else if (xmlSchemaPValAttrNode(ctxt, NULL, attr,
12151 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) {
12156 if (topLevel == 0) {
12158 * Parse as local complex type definition.
12160 #ifdef ENABLE_NAMED_LOCALS
12161 snprintf(buf, 39, "#CT%d", ctxt->counter++ + 1);
12162 type = xmlSchemaAddType(ctxt, schema,
12163 XML_SCHEMA_TYPE_COMPLEX,
12164 xmlDictLookup(ctxt->dict, (const xmlChar *)buf, -1),
12165 ctxt->targetNamespace, node, 0);
12167 type = xmlSchemaAddType(ctxt, schema,
12168 XML_SCHEMA_TYPE_COMPLEX,
12169 NULL, ctxt->targetNamespace, node, 0);
12175 type->type = XML_SCHEMA_TYPE_COMPLEX;
12177 * TODO: We need the target namespace.
12181 * Parse as global complex type definition.
12183 type = xmlSchemaAddType(ctxt, schema,
12184 XML_SCHEMA_TYPE_COMPLEX,
12185 name, ctxt->targetNamespace, node, 1);
12189 type->type = XML_SCHEMA_TYPE_COMPLEX;
12190 type->flags |= XML_SCHEMAS_TYPE_GLOBAL;
12192 type->targetNamespace = ctxt->targetNamespace;
12194 * Handle attributes.
12196 attr = node->properties;
12197 while (attr != NULL) {
12198 if (attr->ns == NULL) {
12199 if (xmlStrEqual(attr->name, BAD_CAST "id")) {
12203 xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
12204 } else if (xmlStrEqual(attr->name, BAD_CAST "mixed")) {
12206 * Attribute "mixed".
12208 if (xmlSchemaPGetBoolNodeValue(ctxt,
12209 NULL, (xmlNodePtr) attr))
12210 type->flags |= XML_SCHEMAS_TYPE_MIXED;
12211 } else if (topLevel) {
12213 * Attributes of global complex type definitions.
12215 if (xmlStrEqual(attr->name, BAD_CAST "name")) {
12217 } else if (xmlStrEqual(attr->name, BAD_CAST "abstract")) {
12219 * Attribute "abstract".
12221 if (xmlSchemaPGetBoolNodeValue(ctxt,
12222 NULL, (xmlNodePtr) attr))
12223 type->flags |= XML_SCHEMAS_TYPE_ABSTRACT;
12224 } else if (xmlStrEqual(attr->name, BAD_CAST "final")) {
12226 * Attribute "final".
12228 attrValue = xmlSchemaGetNodeContent(ctxt,
12229 (xmlNodePtr) attr);
12230 if (xmlSchemaPValAttrBlockFinal(attrValue,
12233 XML_SCHEMAS_TYPE_FINAL_EXTENSION,
12234 XML_SCHEMAS_TYPE_FINAL_RESTRICTION,
12237 xmlSchemaPSimpleTypeErr(ctxt,
12238 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
12239 NULL, (xmlNodePtr) attr, NULL,
12240 "(#all | List of (extension | restriction))",
12241 attrValue, NULL, NULL, NULL);
12244 } else if (xmlStrEqual(attr->name, BAD_CAST "block")) {
12246 * Attribute "block".
12248 attrValue = xmlSchemaGetNodeContent(ctxt,
12249 (xmlNodePtr) attr);
12250 if (xmlSchemaPValAttrBlockFinal(attrValue, &(type->flags),
12252 XML_SCHEMAS_TYPE_BLOCK_EXTENSION,
12253 XML_SCHEMAS_TYPE_BLOCK_RESTRICTION,
12254 -1, -1, -1) != 0) {
12255 xmlSchemaPSimpleTypeErr(ctxt,
12256 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
12257 NULL, (xmlNodePtr) attr, NULL,
12258 "(#all | List of (extension | restriction)) ",
12259 attrValue, NULL, NULL, NULL);
12263 xmlSchemaPIllegalAttrErr(ctxt,
12264 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
12267 xmlSchemaPIllegalAttrErr(ctxt,
12268 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
12270 } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
12271 xmlSchemaPIllegalAttrErr(ctxt,
12272 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
12278 * Apply default "block" values.
12280 if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION)
12281 type->flags |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION;
12282 if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION)
12283 type->flags |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION;
12287 * Apply default "block" values.
12289 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION)
12290 type->flags |= XML_SCHEMAS_TYPE_FINAL_RESTRICTION;
12291 if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION)
12292 type->flags |= XML_SCHEMAS_TYPE_FINAL_EXTENSION;
12295 * And now for the children...
12297 child = node->children;
12298 if (IS_SCHEMA(child, "annotation")) {
12299 type->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
12300 child = child->next;
12302 ctxt->ctxtType = type;
12303 if (IS_SCHEMA(child, "simpleContent")) {
12305 * <complexType><simpleContent>...
12307 * Specifying mixed='true' when the <simpleContent>
12308 * alternative is chosen has no effect
12310 if (type->flags & XML_SCHEMAS_TYPE_MIXED)
12311 type->flags ^= XML_SCHEMAS_TYPE_MIXED;
12312 xmlSchemaParseSimpleContent(ctxt, schema, child,
12313 &hasRestrictionOrExtension);
12314 child = child->next;
12315 } else if (IS_SCHEMA(child, "complexContent")) {
12317 * <complexType><complexContent>...
12319 type->contentType = XML_SCHEMA_CONTENT_EMPTY;
12320 xmlSchemaParseComplexContent(ctxt, schema, child,
12321 &hasRestrictionOrExtension);
12322 child = child->next;
12325 * E.g <complexType><sequence>... or <complexType><attribute>... etc.
12328 * "...the third alternative (neither <simpleContent> nor
12329 * <complexContent>) is chosen. This case is understood as shorthand
12330 * for complex content restricting the `ur-type definition`, and the
12331 * details of the mappings should be modified as necessary.
12333 type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE);
12334 type->flags |= XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION;
12336 * Parse model groups.
12338 if (IS_SCHEMA(child, "all")) {
12339 type->subtypes = (xmlSchemaTypePtr)
12340 xmlSchemaParseModelGroup(ctxt, schema, child,
12341 XML_SCHEMA_TYPE_ALL, 1);
12342 child = child->next;
12343 } else if (IS_SCHEMA(child, "choice")) {
12344 type->subtypes = (xmlSchemaTypePtr)
12345 xmlSchemaParseModelGroup(ctxt, schema, child,
12346 XML_SCHEMA_TYPE_CHOICE, 1);
12347 child = child->next;
12348 } else if (IS_SCHEMA(child, "sequence")) {
12349 type->subtypes = (xmlSchemaTypePtr)
12350 xmlSchemaParseModelGroup(ctxt, schema, child,
12351 XML_SCHEMA_TYPE_SEQUENCE, 1);
12352 child = child->next;
12353 } else if (IS_SCHEMA(child, "group")) {
12354 type->subtypes = (xmlSchemaTypePtr)
12355 xmlSchemaParseModelGroupDefRef(ctxt, schema, child);
12357 * Note that the reference will be resolved in
12358 * xmlSchemaResolveTypeReferences();
12360 child = child->next;
12363 * Parse attribute decls/refs.
12365 if (xmlSchemaParseLocalAttributes(ctxt, schema, &child,
12366 (xmlSchemaItemListPtr *) &(type->attrUses),
12367 XML_SCHEMA_TYPE_RESTRICTION, NULL) == -1)
12370 * Parse attribute wildcard.
12372 if (IS_SCHEMA(child, "anyAttribute")) {
12373 type->attributeWildcard = xmlSchemaParseAnyAttribute(ctxt, schema, child);
12374 child = child->next;
12377 if (child != NULL) {
12378 xmlSchemaPContentErr(ctxt,
12379 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
12381 NULL, "(annotation?, (simpleContent | complexContent | "
12382 "((group | all | choice | sequence)?, ((attribute | "
12383 "attributeGroup)*, anyAttribute?))))");
12386 * REDEFINE: SPEC src-redefine (5)
12388 if (topLevel && ctxt->isRedefine && (! hasRestrictionOrExtension)) {
12389 xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_SRC_REDEFINE,
12390 NULL, node, "This is a redefinition, thus the "
12391 "<complexType> must have a <restriction> or <extension> "
12392 "grand-child", NULL);
12394 ctxt->ctxtType = ctxtType;
12398 /************************************************************************
12400 * Validating using Schemas *
12402 ************************************************************************/
12404 /************************************************************************
12406 * Reading/Writing Schemas *
12408 ************************************************************************/
12410 #if 0 /* Will be enabled if it is clear what options are needed. */
12412 * xmlSchemaParserCtxtSetOptions:
12413 * @ctxt: a schema parser context
12414 * @options: a combination of xmlSchemaParserOption
12416 * Sets the options to be used during the parse.
12418 * Returns 0 in case of success, -1 in case of an
12422 xmlSchemaParserCtxtSetOptions(xmlSchemaParserCtxtPtr ctxt,
12431 * WARNING: Change the start value if adding to the
12432 * xmlSchemaParseOption.
12434 for (i = 1; i < (int) sizeof(int) * 8; i++) {
12435 if (options & 1<<i) {
12439 ctxt->options = options;
12444 * xmlSchemaValidCtxtGetOptions:
12445 * @ctxt: a schema parser context
12447 * Returns the option combination of the parser context.
12450 xmlSchemaParserCtxtGetOptions(xmlSchemaParserCtxtPtr ctxt)
12456 return (ctxt->options);
12461 * xmlSchemaNewParserCtxt:
12462 * @URL: the location of the schema
12464 * Create an XML Schemas parse context for that file/resource expected
12465 * to contain an XML Schemas file.
12467 * Returns the parser context or NULL in case of error
12469 xmlSchemaParserCtxtPtr
12470 xmlSchemaNewParserCtxt(const char *URL)
12472 xmlSchemaParserCtxtPtr ret;
12477 ret = xmlSchemaParserCtxtCreate();
12480 ret->dict = xmlDictCreate();
12481 ret->URL = xmlDictLookup(ret->dict, (const xmlChar *) URL, -1);
12486 * xmlSchemaNewMemParserCtxt:
12487 * @buffer: a pointer to a char array containing the schemas
12488 * @size: the size of the array
12490 * Create an XML Schemas parse context for that memory buffer expected
12491 * to contain an XML Schemas file.
12493 * Returns the parser context or NULL in case of error
12495 xmlSchemaParserCtxtPtr
12496 xmlSchemaNewMemParserCtxt(const char *buffer, int size)
12498 xmlSchemaParserCtxtPtr ret;
12500 if ((buffer == NULL) || (size <= 0))
12502 ret = xmlSchemaParserCtxtCreate();
12505 ret->buffer = buffer;
12507 ret->dict = xmlDictCreate();
12512 * xmlSchemaNewDocParserCtxt:
12513 * @doc: a preparsed document tree
12515 * Create an XML Schemas parse context for that document.
12516 * NB. The document may be modified during the parsing process.
12518 * Returns the parser context or NULL in case of error
12520 xmlSchemaParserCtxtPtr
12521 xmlSchemaNewDocParserCtxt(xmlDocPtr doc)
12523 xmlSchemaParserCtxtPtr ret;
12527 ret = xmlSchemaParserCtxtCreate();
12531 ret->dict = xmlDictCreate();
12532 /* The application has responsibility for the document */
12539 * xmlSchemaFreeParserCtxt:
12540 * @ctxt: the schema parser context
12542 * Free the resources associated to the schema parser context
12545 xmlSchemaFreeParserCtxt(xmlSchemaParserCtxtPtr ctxt)
12549 if (ctxt->doc != NULL && !ctxt->preserve)
12550 xmlFreeDoc(ctxt->doc);
12551 if (ctxt->vctxt != NULL) {
12552 xmlSchemaFreeValidCtxt(ctxt->vctxt);
12554 if (ctxt->ownsConstructor && (ctxt->constructor != NULL)) {
12555 xmlSchemaConstructionCtxtFree(ctxt->constructor);
12556 ctxt->constructor = NULL;
12557 ctxt->ownsConstructor = 0;
12559 if (ctxt->attrProhibs != NULL)
12560 xmlSchemaItemListFree(ctxt->attrProhibs);
12561 xmlDictFree(ctxt->dict);
12565 /************************************************************************
12567 * Building the content models *
12569 ************************************************************************/
12572 * xmlSchemaBuildContentModelForSubstGroup:
12574 * Returns 1 if nillable, 0 otherwise
12577 xmlSchemaBuildContentModelForSubstGroup(xmlSchemaParserCtxtPtr pctxt,
12578 xmlSchemaParticlePtr particle, int counter, xmlAutomataStatePtr end)
12580 xmlAutomataStatePtr start, tmp;
12581 xmlSchemaElementPtr elemDecl, member;
12582 xmlSchemaSubstGroupPtr substGroup;
12586 elemDecl = (xmlSchemaElementPtr) particle->children;
12588 * Wrap the substitution group with a CHOICE.
12590 start = pctxt->state;
12592 end = xmlAutomataNewState(pctxt->am);
12593 substGroup = xmlSchemaSubstGroupGet(pctxt, elemDecl);
12594 if (substGroup == NULL) {
12595 xmlSchemaPErr(pctxt, WXS_ITEM_NODE(particle),
12596 XML_SCHEMAP_INTERNAL,
12597 "Internal error: xmlSchemaBuildContentModelForSubstGroup, "
12598 "declaration is marked having a subst. group but none "
12599 "available.\n", elemDecl->name, NULL);
12602 if (counter >= 0) {
12604 * NOTE that we put the declaration in, even if it's abstract.
12605 * However, an error will be raised during *validation* if an element
12606 * information item shall be validated against an abstract element
12609 tmp = xmlAutomataNewCountedTrans(pctxt->am, start, NULL, counter);
12610 xmlAutomataNewTransition2(pctxt->am, tmp, end,
12611 elemDecl->name, elemDecl->targetNamespace, elemDecl);
12613 * Add subst. group members.
12615 for (i = 0; i < substGroup->members->nbItems; i++) {
12616 member = (xmlSchemaElementPtr) substGroup->members->items[i];
12617 xmlAutomataNewTransition2(pctxt->am, tmp, end,
12618 member->name, member->targetNamespace, member);
12620 } else if (particle->maxOccurs == 1) {
12622 * NOTE that we put the declaration in, even if it's abstract,
12624 xmlAutomataNewEpsilon(pctxt->am,
12625 xmlAutomataNewTransition2(pctxt->am,
12627 elemDecl->name, elemDecl->targetNamespace, elemDecl), end);
12629 * Add subst. group members.
12631 for (i = 0; i < substGroup->members->nbItems; i++) {
12632 member = (xmlSchemaElementPtr) substGroup->members->items[i];
12634 * NOTE: This fixes bug #341150. xmlAutomataNewOnceTrans2()
12635 * was incorrectly used instead of xmlAutomataNewTransition2()
12636 * (seems like a copy&paste bug from the XML_SCHEMA_TYPE_ALL
12637 * section in xmlSchemaBuildAContentModel() ).
12638 * TODO: Check if xmlAutomataNewOnceTrans2() was instead
12639 * intended for the above "counter" section originally. I.e.,
12640 * check xs:all with subst-groups.
12642 * tmp = xmlAutomataNewOnceTrans2(pctxt->am, start, NULL,
12643 * member->name, member->targetNamespace,
12646 tmp = xmlAutomataNewTransition2(pctxt->am, start, NULL,
12647 member->name, member->targetNamespace, member);
12648 xmlAutomataNewEpsilon(pctxt->am, tmp, end);
12651 xmlAutomataStatePtr hop;
12652 int maxOccurs = particle->maxOccurs == UNBOUNDED ?
12653 UNBOUNDED : particle->maxOccurs - 1;
12654 int minOccurs = particle->minOccurs < 1 ? 0 : particle->minOccurs - 1;
12657 xmlAutomataNewCounter(pctxt->am, minOccurs,
12659 hop = xmlAutomataNewState(pctxt->am);
12661 xmlAutomataNewEpsilon(pctxt->am,
12662 xmlAutomataNewTransition2(pctxt->am,
12664 elemDecl->name, elemDecl->targetNamespace, elemDecl),
12667 * Add subst. group members.
12669 for (i = 0; i < substGroup->members->nbItems; i++) {
12670 member = (xmlSchemaElementPtr) substGroup->members->items[i];
12671 xmlAutomataNewEpsilon(pctxt->am,
12672 xmlAutomataNewTransition2(pctxt->am,
12674 member->name, member->targetNamespace, member),
12677 xmlAutomataNewCountedTrans(pctxt->am, hop, start, counter);
12678 xmlAutomataNewCounterTrans(pctxt->am, hop, end, counter);
12680 if (particle->minOccurs == 0) {
12681 xmlAutomataNewEpsilon(pctxt->am, start, end);
12684 pctxt->state = end;
12689 * xmlSchemaBuildContentModelForElement:
12691 * Returns 1 if nillable, 0 otherwise
12694 xmlSchemaBuildContentModelForElement(xmlSchemaParserCtxtPtr ctxt,
12695 xmlSchemaParticlePtr particle)
12699 if (((xmlSchemaElementPtr) particle->children)->flags &
12700 XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD) {
12702 * Substitution groups.
12704 ret = xmlSchemaBuildContentModelForSubstGroup(ctxt, particle, -1, NULL);
12706 xmlSchemaElementPtr elemDecl;
12707 xmlAutomataStatePtr start;
12709 elemDecl = (xmlSchemaElementPtr) particle->children;
12711 if (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT)
12713 if (particle->maxOccurs == 1) {
12714 start = ctxt->state;
12715 ctxt->state = xmlAutomataNewTransition2(ctxt->am, start, NULL,
12716 elemDecl->name, elemDecl->targetNamespace, elemDecl);
12717 } else if ((particle->maxOccurs >= UNBOUNDED) &&
12718 (particle->minOccurs < 2)) {
12719 /* Special case. */
12720 start = ctxt->state;
12721 ctxt->state = xmlAutomataNewTransition2(ctxt->am, start, NULL,
12722 elemDecl->name, elemDecl->targetNamespace, elemDecl);
12723 ctxt->state = xmlAutomataNewTransition2(ctxt->am, ctxt->state, ctxt->state,
12724 elemDecl->name, elemDecl->targetNamespace, elemDecl);
12727 int maxOccurs = particle->maxOccurs == UNBOUNDED ?
12728 UNBOUNDED : particle->maxOccurs - 1;
12729 int minOccurs = particle->minOccurs < 1 ?
12730 0 : particle->minOccurs - 1;
12732 start = xmlAutomataNewEpsilon(ctxt->am, ctxt->state, NULL);
12733 counter = xmlAutomataNewCounter(ctxt->am, minOccurs, maxOccurs);
12734 ctxt->state = xmlAutomataNewTransition2(ctxt->am, start, NULL,
12735 elemDecl->name, elemDecl->targetNamespace, elemDecl);
12736 xmlAutomataNewCountedTrans(ctxt->am, ctxt->state, start, counter);
12737 ctxt->state = xmlAutomataNewCounterTrans(ctxt->am, ctxt->state,
12740 if (particle->minOccurs == 0) {
12741 xmlAutomataNewEpsilon(ctxt->am, start, ctxt->state);
12749 * xmlSchemaBuildAContentModel:
12750 * @ctxt: the schema parser context
12751 * @particle: the particle component
12752 * @name: the complex type's name whose content is being built
12754 * Create the automaton for the {content type} of a complex type.
12756 * Returns 1 if the content is nillable, 0 otherwise
12759 xmlSchemaBuildAContentModel(xmlSchemaParserCtxtPtr pctxt,
12760 xmlSchemaParticlePtr particle)
12764 if (particle == NULL) {
12765 PERROR_INT("xmlSchemaBuildAContentModel", "particle is NULL");
12768 if (particle->children == NULL) {
12770 * Just return in this case. A missing "term" of the particle
12771 * might arise due to an invalid "term" component.
12776 switch (particle->children->type) {
12777 case XML_SCHEMA_TYPE_ANY: {
12778 xmlAutomataStatePtr start, end;
12779 xmlSchemaWildcardPtr wild;
12780 xmlSchemaWildcardNsPtr ns;
12782 wild = (xmlSchemaWildcardPtr) particle->children;
12784 start = pctxt->state;
12785 end = xmlAutomataNewState(pctxt->am);
12787 if (particle->maxOccurs == 1) {
12788 if (wild->any == 1) {
12790 * We need to add both transitions:
12792 * 1. the {"*", "*"} for elements in a namespace.
12795 xmlAutomataNewTransition2(pctxt->am,
12796 start, NULL, BAD_CAST "*", BAD_CAST "*", wild);
12797 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, end);
12799 * 2. the {"*"} for elements in no namespace.
12802 xmlAutomataNewTransition2(pctxt->am,
12803 start, NULL, BAD_CAST "*", NULL, wild);
12804 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, end);
12806 } else if (wild->nsSet != NULL) {
12809 pctxt->state = start;
12810 pctxt->state = xmlAutomataNewTransition2(pctxt->am,
12811 pctxt->state, NULL, BAD_CAST "*", ns->value, wild);
12812 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, end);
12814 } while (ns != NULL);
12816 } else if (wild->negNsSet != NULL) {
12817 pctxt->state = xmlAutomataNewNegTrans(pctxt->am,
12818 start, end, BAD_CAST "*", wild->negNsSet->value,
12823 xmlAutomataStatePtr hop;
12825 particle->maxOccurs == UNBOUNDED ? UNBOUNDED :
12826 particle->maxOccurs - 1;
12828 particle->minOccurs < 1 ? 0 : particle->minOccurs - 1;
12830 counter = xmlAutomataNewCounter(pctxt->am, minOccurs, maxOccurs);
12831 hop = xmlAutomataNewState(pctxt->am);
12832 if (wild->any == 1) {
12834 xmlAutomataNewTransition2(pctxt->am,
12835 start, NULL, BAD_CAST "*", BAD_CAST "*", wild);
12836 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, hop);
12838 xmlAutomataNewTransition2(pctxt->am,
12839 start, NULL, BAD_CAST "*", NULL, wild);
12840 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, hop);
12841 } else if (wild->nsSet != NULL) {
12845 xmlAutomataNewTransition2(pctxt->am,
12846 start, NULL, BAD_CAST "*", ns->value, wild);
12847 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, hop);
12849 } while (ns != NULL);
12851 } else if (wild->negNsSet != NULL) {
12852 pctxt->state = xmlAutomataNewNegTrans(pctxt->am,
12853 start, hop, BAD_CAST "*", wild->negNsSet->value,
12856 xmlAutomataNewCountedTrans(pctxt->am, hop, start, counter);
12857 xmlAutomataNewCounterTrans(pctxt->am, hop, end, counter);
12859 if (particle->minOccurs == 0) {
12860 xmlAutomataNewEpsilon(pctxt->am, start, end);
12863 pctxt->state = end;
12866 case XML_SCHEMA_TYPE_ELEMENT:
12867 ret = xmlSchemaBuildContentModelForElement(pctxt, particle);
12869 case XML_SCHEMA_TYPE_SEQUENCE:{
12870 xmlSchemaTreeItemPtr sub;
12874 * If max and min occurances are default (1) then
12875 * simply iterate over the particles of the <sequence>.
12877 if ((particle->minOccurs == 1) && (particle->maxOccurs == 1)) {
12878 sub = particle->children->children;
12880 while (sub != NULL) {
12881 tmp2 = xmlSchemaBuildAContentModel(pctxt,
12882 (xmlSchemaParticlePtr) sub);
12883 if (tmp2 != 1) ret = 0;
12887 xmlAutomataStatePtr oldstate = pctxt->state;
12889 if (particle->maxOccurs >= UNBOUNDED) {
12890 if (particle->minOccurs > 1) {
12891 xmlAutomataStatePtr tmp;
12894 pctxt->state = xmlAutomataNewEpsilon(pctxt->am,
12896 oldstate = pctxt->state;
12898 counter = xmlAutomataNewCounter(pctxt->am,
12899 particle->minOccurs - 1, UNBOUNDED);
12901 sub = particle->children->children;
12902 while (sub != NULL) {
12903 tmp2 = xmlSchemaBuildAContentModel(pctxt,
12904 (xmlSchemaParticlePtr) sub);
12905 if (tmp2 != 1) ret = 0;
12908 tmp = pctxt->state;
12909 xmlAutomataNewCountedTrans(pctxt->am, tmp,
12910 oldstate, counter);
12912 xmlAutomataNewCounterTrans(pctxt->am, tmp,
12915 xmlAutomataNewEpsilon(pctxt->am,
12916 oldstate, pctxt->state);
12919 pctxt->state = xmlAutomataNewEpsilon(pctxt->am,
12921 oldstate = pctxt->state;
12923 sub = particle->children->children;
12924 while (sub != NULL) {
12925 tmp2 = xmlSchemaBuildAContentModel(pctxt,
12926 (xmlSchemaParticlePtr) sub);
12927 if (tmp2 != 1) ret = 0;
12930 xmlAutomataNewEpsilon(pctxt->am, pctxt->state,
12933 * epsilon needed to block previous trans from
12934 * being allowed to enter back from another
12937 pctxt->state = xmlAutomataNewEpsilon(pctxt->am,
12938 pctxt->state, NULL);
12939 if (particle->minOccurs == 0) {
12940 xmlAutomataNewEpsilon(pctxt->am,
12941 oldstate, pctxt->state);
12945 } else if ((particle->maxOccurs > 1)
12946 || (particle->minOccurs > 1)) {
12947 xmlAutomataStatePtr tmp;
12950 pctxt->state = xmlAutomataNewEpsilon(pctxt->am,
12952 oldstate = pctxt->state;
12954 counter = xmlAutomataNewCounter(pctxt->am,
12955 particle->minOccurs - 1,
12956 particle->maxOccurs - 1);
12958 sub = particle->children->children;
12959 while (sub != NULL) {
12960 tmp2 = xmlSchemaBuildAContentModel(pctxt,
12961 (xmlSchemaParticlePtr) sub);
12962 if (tmp2 != 1) ret = 0;
12965 tmp = pctxt->state;
12966 xmlAutomataNewCountedTrans(pctxt->am,
12967 tmp, oldstate, counter);
12969 xmlAutomataNewCounterTrans(pctxt->am, tmp, NULL,
12971 if ((particle->minOccurs == 0) || (ret == 1)) {
12972 xmlAutomataNewEpsilon(pctxt->am,
12973 oldstate, pctxt->state);
12977 sub = particle->children->children;
12978 while (sub != NULL) {
12979 tmp2 = xmlSchemaBuildAContentModel(pctxt,
12980 (xmlSchemaParticlePtr) sub);
12981 if (tmp2 != 1) ret = 0;
12986 * epsilon needed to block previous trans from
12987 * being allowed to enter back from another
12990 pctxt->state = xmlAutomataNewEpsilon(pctxt->am,
12991 pctxt->state, NULL);
12993 if (particle->minOccurs == 0) {
12994 xmlAutomataNewEpsilon(pctxt->am, oldstate,
13002 case XML_SCHEMA_TYPE_CHOICE:{
13003 xmlSchemaTreeItemPtr sub;
13004 xmlAutomataStatePtr start, end;
13007 start = pctxt->state;
13008 end = xmlAutomataNewState(pctxt->am);
13011 * iterate over the subtypes and remerge the end with an
13012 * epsilon transition
13014 if (particle->maxOccurs == 1) {
13015 sub = particle->children->children;
13016 while (sub != NULL) {
13017 pctxt->state = start;
13018 tmp2 = xmlSchemaBuildAContentModel(pctxt,
13019 (xmlSchemaParticlePtr) sub);
13020 if (tmp2 == 1) ret = 1;
13021 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, end);
13026 xmlAutomataStatePtr hop, base;
13027 int maxOccurs = particle->maxOccurs == UNBOUNDED ?
13028 UNBOUNDED : particle->maxOccurs - 1;
13030 particle->minOccurs < 1 ? 0 : particle->minOccurs - 1;
13033 * use a counter to keep track of the number of transtions
13034 * which went through the choice.
13037 xmlAutomataNewCounter(pctxt->am, minOccurs, maxOccurs);
13038 hop = xmlAutomataNewState(pctxt->am);
13039 base = xmlAutomataNewState(pctxt->am);
13041 sub = particle->children->children;
13042 while (sub != NULL) {
13043 pctxt->state = base;
13044 tmp2 = xmlSchemaBuildAContentModel(pctxt,
13045 (xmlSchemaParticlePtr) sub);
13046 if (tmp2 == 1) ret = 1;
13047 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, hop);
13050 xmlAutomataNewEpsilon(pctxt->am, start, base);
13051 xmlAutomataNewCountedTrans(pctxt->am, hop, base, counter);
13052 xmlAutomataNewCounterTrans(pctxt->am, hop, end, counter);
13054 xmlAutomataNewEpsilon(pctxt->am, base, end);
13056 if (particle->minOccurs == 0) {
13057 xmlAutomataNewEpsilon(pctxt->am, start, end);
13060 pctxt->state = end;
13063 case XML_SCHEMA_TYPE_ALL:{
13064 xmlAutomataStatePtr start, tmp;
13065 xmlSchemaParticlePtr sub;
13066 xmlSchemaElementPtr elemDecl;
13070 sub = (xmlSchemaParticlePtr) particle->children->children;
13076 start = pctxt->state;
13077 tmp = xmlAutomataNewState(pctxt->am);
13078 xmlAutomataNewEpsilon(pctxt->am, pctxt->state, tmp);
13079 pctxt->state = tmp;
13080 while (sub != NULL) {
13081 pctxt->state = tmp;
13083 elemDecl = (xmlSchemaElementPtr) sub->children;
13084 if (elemDecl == NULL) {
13085 PERROR_INT("xmlSchemaBuildAContentModel",
13086 "<element> particle has no term");
13090 * NOTE: The {max occurs} of all the particles in the
13091 * {particles} of the group must be 0 or 1; this is
13092 * already ensured during the parse of the content of
13095 if (elemDecl->flags & XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD) {
13099 * This is an abstract group, we need to share
13100 * the same counter for all the element transitions
13101 * derived from the group
13103 counter = xmlAutomataNewCounter(pctxt->am,
13104 sub->minOccurs, sub->maxOccurs);
13105 xmlSchemaBuildContentModelForSubstGroup(pctxt,
13106 sub, counter, pctxt->state);
13108 if ((sub->minOccurs == 1) &&
13109 (sub->maxOccurs == 1)) {
13110 xmlAutomataNewOnceTrans2(pctxt->am, pctxt->state,
13113 elemDecl->targetNamespace,
13115 } else if ((sub->minOccurs == 0) &&
13116 (sub->maxOccurs == 1)) {
13118 xmlAutomataNewCountTrans2(pctxt->am, pctxt->state,
13121 elemDecl->targetNamespace,
13127 sub = (xmlSchemaParticlePtr) sub->next;
13130 xmlAutomataNewAllTrans(pctxt->am, pctxt->state, NULL, 0);
13131 if (particle->minOccurs == 0) {
13132 xmlAutomataNewEpsilon(pctxt->am, start, pctxt->state);
13137 case XML_SCHEMA_TYPE_GROUP:
13139 * If we hit a model group definition, then this means that
13140 * it was empty, thus was not substituted for the containing
13141 * model group. Just do nothing in this case.
13142 * TODO: But the group should be substituted and not occur at
13143 * all in the content model at this point. Fix this.
13148 xmlSchemaInternalErr2(ACTXT_CAST pctxt,
13149 "xmlSchemaBuildAContentModel",
13150 "found unexpected term of type '%s' in content model",
13151 WXS_ITEM_TYPE_NAME(particle->children), NULL);
13158 * xmlSchemaBuildContentModel:
13159 * @ctxt: the schema parser context
13160 * @type: the complex type definition
13161 * @name: the element name
13163 * Builds the content model of the complex type.
13166 xmlSchemaBuildContentModel(xmlSchemaTypePtr type,
13167 xmlSchemaParserCtxtPtr ctxt)
13169 if ((type->type != XML_SCHEMA_TYPE_COMPLEX) ||
13170 (type->contModel != NULL) ||
13171 ((type->contentType != XML_SCHEMA_CONTENT_ELEMENTS) &&
13172 (type->contentType != XML_SCHEMA_CONTENT_MIXED)))
13175 #ifdef DEBUG_CONTENT
13176 xmlGenericError(xmlGenericErrorContext,
13177 "Building content model for %s\n", name);
13180 ctxt->am = xmlNewAutomata();
13181 if (ctxt->am == NULL) {
13182 xmlGenericError(xmlGenericErrorContext,
13183 "Cannot create automata for complex type %s\n", type->name);
13186 ctxt->state = xmlAutomataGetInitState(ctxt->am);
13188 * Build the automaton.
13190 xmlSchemaBuildAContentModel(ctxt, WXS_TYPE_PARTICLE(type));
13191 xmlAutomataSetFinalState(ctxt->am, ctxt->state);
13192 type->contModel = xmlAutomataCompile(ctxt->am);
13193 if (type->contModel == NULL) {
13194 xmlSchemaPCustomErr(ctxt,
13195 XML_SCHEMAP_INTERNAL,
13196 WXS_BASIC_CAST type, type->node,
13197 "Failed to compile the content model", NULL);
13198 } else if (xmlRegexpIsDeterminist(type->contModel) != 1) {
13199 xmlSchemaPCustomErr(ctxt,
13200 XML_SCHEMAP_NOT_DETERMINISTIC,
13201 /* XML_SCHEMAS_ERR_NOTDETERMINIST, */
13202 WXS_BASIC_CAST type, type->node,
13203 "The content model is not determinist", NULL);
13205 #ifdef DEBUG_CONTENT_REGEXP
13206 xmlGenericError(xmlGenericErrorContext,
13207 "Content model of %s:\n", type->name);
13208 xmlRegexpPrint(stderr, type->contModel);
13211 ctxt->state = NULL;
13212 xmlFreeAutomata(ctxt->am);
13217 * xmlSchemaResolveElementReferences:
13218 * @elem: the schema element context
13219 * @ctxt: the schema parser context
13221 * Resolves the references of an element declaration
13222 * or particle, which has an element declaration as it's
13226 xmlSchemaResolveElementReferences(xmlSchemaElementPtr elemDecl,
13227 xmlSchemaParserCtxtPtr ctxt)
13229 if ((ctxt == NULL) || (elemDecl == NULL) ||
13230 ((elemDecl != NULL) &&
13231 (elemDecl->flags & XML_SCHEMAS_ELEM_INTERNAL_RESOLVED)))
13233 elemDecl->flags |= XML_SCHEMAS_ELEM_INTERNAL_RESOLVED;
13235 if ((elemDecl->subtypes == NULL) && (elemDecl->namedType != NULL)) {
13236 xmlSchemaTypePtr type;
13238 /* (type definition) ... otherwise the type definition `resolved`
13239 * to by the `actual value` of the type [attribute] ...
13241 type = xmlSchemaGetType(ctxt->schema, elemDecl->namedType,
13242 elemDecl->namedTypeNs);
13243 if (type == NULL) {
13244 xmlSchemaPResCompAttrErr(ctxt,
13245 XML_SCHEMAP_SRC_RESOLVE,
13246 WXS_BASIC_CAST elemDecl, elemDecl->node,
13247 "type", elemDecl->namedType, elemDecl->namedTypeNs,
13248 XML_SCHEMA_TYPE_BASIC, "type definition");
13250 elemDecl->subtypes = type;
13252 if (elemDecl->substGroup != NULL) {
13253 xmlSchemaElementPtr substHead;
13256 * FIXME TODO: Do we need a new field in _xmlSchemaElement for
13257 * substitutionGroup?
13259 substHead = xmlSchemaGetElem(ctxt->schema, elemDecl->substGroup,
13260 elemDecl->substGroupNs);
13261 if (substHead == NULL) {
13262 xmlSchemaPResCompAttrErr(ctxt,
13263 XML_SCHEMAP_SRC_RESOLVE,
13264 WXS_BASIC_CAST elemDecl, NULL,
13265 "substitutionGroup", elemDecl->substGroup,
13266 elemDecl->substGroupNs, XML_SCHEMA_TYPE_ELEMENT, NULL);
13268 xmlSchemaResolveElementReferences(substHead, ctxt);
13270 * Set the "substitution group affiliation".
13271 * NOTE that now we use the "refDecl" field for this.
13273 WXS_SUBST_HEAD(elemDecl) = substHead;
13275 * The type definitions is set to:
13276 * SPEC "...the {type definition} of the element
13277 * declaration `resolved` to by the `actual value`
13278 * of the substitutionGroup [attribute], if present"
13280 if (elemDecl->subtypes == NULL)
13281 elemDecl->subtypes = substHead->subtypes;
13285 * SPEC "The definition of anyType serves as the default type definition
13286 * for element declarations whose XML representation does not specify one."
13288 if ((elemDecl->subtypes == NULL) &&
13289 (elemDecl->namedType == NULL) &&
13290 (elemDecl->substGroup == NULL))
13291 elemDecl->subtypes = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE);
13295 * xmlSchemaResolveUnionMemberTypes:
13296 * @ctxt: the schema parser context
13297 * @type: the schema simple type definition
13299 * Checks and builds the "member type definitions" property of the union
13300 * simple type. This handles part (1), part (2) is done in
13301 * xmlSchemaFinishMemberTypeDefinitionsProperty()
13303 * Returns -1 in case of an internal error, 0 otherwise.
13306 xmlSchemaResolveUnionMemberTypes(xmlSchemaParserCtxtPtr ctxt,
13307 xmlSchemaTypePtr type)
13310 xmlSchemaTypeLinkPtr link, lastLink, newLink;
13311 xmlSchemaTypePtr memberType;
13314 * SPEC (1) "If the <union> alternative is chosen, then [Definition:]
13315 * define the explicit members as the type definitions `resolved`
13316 * to by the items in the `actual value` of the memberTypes [attribute],
13317 * if any, followed by the type definitions corresponding to the
13318 * <simpleType>s among the [children] of <union>, if any."
13321 * Resolve references.
13323 link = type->memberTypes;
13325 while (link != NULL) {
13326 const xmlChar *name, *nsName;
13328 name = ((xmlSchemaQNameRefPtr) link->type)->name;
13329 nsName = ((xmlSchemaQNameRefPtr) link->type)->targetNamespace;
13331 memberType = xmlSchemaGetType(ctxt->schema, name, nsName);
13332 if ((memberType == NULL) || (! WXS_IS_SIMPLE(memberType))) {
13333 xmlSchemaPResCompAttrErr(ctxt, XML_SCHEMAP_SRC_RESOLVE,
13334 WXS_BASIC_CAST type, type->node, "memberTypes",
13335 name, nsName, XML_SCHEMA_TYPE_SIMPLE, NULL);
13337 * Remove the member type link.
13339 if (lastLink == NULL)
13340 type->memberTypes = link->next;
13342 lastLink->next = link->next;
13347 link->type = memberType;
13353 * Add local simple types,
13355 memberType = type->subtypes;
13356 while (memberType != NULL) {
13357 link = (xmlSchemaTypeLinkPtr) xmlMalloc(sizeof(xmlSchemaTypeLink));
13358 if (link == NULL) {
13359 xmlSchemaPErrMemory(ctxt, "allocating a type link", NULL);
13362 link->type = memberType;
13364 if (lastLink == NULL)
13365 type->memberTypes = link;
13367 lastLink->next = link;
13369 memberType = memberType->next;
13375 * xmlSchemaIsDerivedFromBuiltInType:
13376 * @ctxt: the schema parser context
13377 * @type: the type definition
13378 * @valType: the value type
13381 * Returns 1 if the type has the given value type, or
13382 * is derived from such a type.
13385 xmlSchemaIsDerivedFromBuiltInType(xmlSchemaTypePtr type, int valType)
13389 if (WXS_IS_COMPLEX(type))
13391 if (type->type == XML_SCHEMA_TYPE_BASIC) {
13392 if (type->builtInType == valType)
13394 if ((type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) ||
13395 (type->builtInType == XML_SCHEMAS_ANYTYPE))
13397 return(xmlSchemaIsDerivedFromBuiltInType(type->subtypes, valType));
13399 return(xmlSchemaIsDerivedFromBuiltInType(type->subtypes, valType));
13404 * xmlSchemaIsDerivedFromBuiltInType:
13405 * @ctxt: the schema parser context
13406 * @type: the type definition
13407 * @valType: the value type
13410 * Returns 1 if the type has the given value type, or
13411 * is derived from such a type.
13414 xmlSchemaIsUserDerivedFromBuiltInType(xmlSchemaTypePtr type, int valType)
13418 if (WXS_IS_COMPLEX(type))
13420 if (type->type == XML_SCHEMA_TYPE_BASIC) {
13421 if (type->builtInType == valType)
13425 return(xmlSchemaIsDerivedFromBuiltInType(type->subtypes, valType));
13430 static xmlSchemaTypePtr
13431 xmlSchemaQueryBuiltInType(xmlSchemaTypePtr type)
13435 if (WXS_IS_COMPLEX(type))
13437 if (type->type == XML_SCHEMA_TYPE_BASIC)
13439 return(xmlSchemaQueryBuiltInType(type->subtypes));
13444 * xmlSchemaGetPrimitiveType:
13445 * @type: the simpleType definition
13447 * Returns the primitive type of the given type or
13448 * NULL in case of error.
13450 static xmlSchemaTypePtr
13451 xmlSchemaGetPrimitiveType(xmlSchemaTypePtr type)
13454 while (type != NULL) {
13456 * Note that anySimpleType is actually not a primitive type
13457 * but we need that here.
13459 if ((type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) ||
13460 (type->flags & XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE))
13462 type = type->baseType;
13470 * xmlSchemaGetBuiltInTypeAncestor:
13471 * @type: the simpleType definition
13473 * Returns the primitive type of the given type or
13474 * NULL in case of error.
13476 static xmlSchemaTypePtr
13477 xmlSchemaGetBuiltInTypeAncestor(xmlSchemaTypePtr type)
13479 if (WXS_IS_LIST(type) || WXS_IS_UNION(type))
13481 while (type != NULL) {
13482 if (type->type == XML_SCHEMA_TYPE_BASIC)
13484 type = type->baseType;
13492 * xmlSchemaCloneWildcardNsConstraints:
13493 * @ctxt: the schema parser context
13494 * @dest: the destination wildcard
13495 * @source: the source wildcard
13497 * Clones the namespace constraints of source
13498 * and assignes them to dest.
13499 * Returns -1 on internal error, 0 otherwise.
13502 xmlSchemaCloneWildcardNsConstraints(xmlSchemaParserCtxtPtr ctxt,
13503 xmlSchemaWildcardPtr dest,
13504 xmlSchemaWildcardPtr source)
13506 xmlSchemaWildcardNsPtr cur, tmp, last;
13508 if ((source == NULL) || (dest == NULL))
13510 dest->any = source->any;
13511 cur = source->nsSet;
13513 while (cur != NULL) {
13514 tmp = xmlSchemaNewWildcardNsConstraint(ctxt);
13517 tmp->value = cur->value;
13525 if (dest->negNsSet != NULL)
13526 xmlSchemaFreeWildcardNsSet(dest->negNsSet);
13527 if (source->negNsSet != NULL) {
13528 dest->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt);
13529 if (dest->negNsSet == NULL)
13531 dest->negNsSet->value = source->negNsSet->value;
13533 dest->negNsSet = NULL;
13538 * xmlSchemaUnionWildcards:
13539 * @ctxt: the schema parser context
13540 * @completeWild: the first wildcard
13541 * @curWild: the second wildcard
13543 * Unions the namespace constraints of the given wildcards.
13544 * @completeWild will hold the resulting union.
13545 * Returns a positive error code on failure, -1 in case of an
13546 * internal error, 0 otherwise.
13549 xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt,
13550 xmlSchemaWildcardPtr completeWild,
13551 xmlSchemaWildcardPtr curWild)
13553 xmlSchemaWildcardNsPtr cur, curB, tmp;
13556 * 1 If O1 and O2 are the same value, then that value must be the
13559 if ((completeWild->any == curWild->any) &&
13560 ((completeWild->nsSet == NULL) == (curWild->nsSet == NULL)) &&
13561 ((completeWild->negNsSet == NULL) == (curWild->negNsSet == NULL))) {
13563 if ((completeWild->negNsSet == NULL) ||
13564 (completeWild->negNsSet->value == curWild->negNsSet->value)) {
13566 if (completeWild->nsSet != NULL) {
13570 * Check equality of sets.
13572 cur = completeWild->nsSet;
13573 while (cur != NULL) {
13575 curB = curWild->nsSet;
13576 while (curB != NULL) {
13577 if (cur->value == curB->value) {
13594 * 2 If either O1 or O2 is any, then any must be the value
13596 if (completeWild->any != curWild->any) {
13597 if (completeWild->any == 0) {
13598 completeWild->any = 1;
13599 if (completeWild->nsSet != NULL) {
13600 xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
13601 completeWild->nsSet = NULL;
13603 if (completeWild->negNsSet != NULL) {
13604 xmlFree(completeWild->negNsSet);
13605 completeWild->negNsSet = NULL;
13611 * 3 If both O1 and O2 are sets of (namespace names or `absent`),
13612 * then the union of those sets must be the value.
13614 if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) {
13616 xmlSchemaWildcardNsPtr start;
13618 cur = curWild->nsSet;
13619 start = completeWild->nsSet;
13620 while (cur != NULL) {
13623 while (curB != NULL) {
13624 if (cur->value == curB->value) {
13631 tmp = xmlSchemaNewWildcardNsConstraint(ctxt);
13634 tmp->value = cur->value;
13635 tmp->next = completeWild->nsSet;
13636 completeWild->nsSet = tmp;
13644 * 4 If the two are negations of different values (namespace names
13645 * or `absent`), then a pair of not and `absent` must be the value.
13647 if ((completeWild->negNsSet != NULL) &&
13648 (curWild->negNsSet != NULL) &&
13649 (completeWild->negNsSet->value != curWild->negNsSet->value)) {
13650 completeWild->negNsSet->value = NULL;
13657 if (((completeWild->negNsSet != NULL) &&
13658 (completeWild->negNsSet->value != NULL) &&
13659 (curWild->nsSet != NULL)) ||
13660 ((curWild->negNsSet != NULL) &&
13661 (curWild->negNsSet->value != NULL) &&
13662 (completeWild->nsSet != NULL))) {
13664 int nsFound, absentFound = 0;
13666 if (completeWild->nsSet != NULL) {
13667 cur = completeWild->nsSet;
13668 curB = curWild->negNsSet;
13670 cur = curWild->nsSet;
13671 curB = completeWild->negNsSet;
13674 while (cur != NULL) {
13675 if (cur->value == NULL)
13677 else if (cur->value == curB->value)
13679 if (nsFound && absentFound)
13684 if (nsFound && absentFound) {
13686 * 5.1 If the set S includes both the negated namespace
13687 * name and `absent`, then any must be the value.
13689 completeWild->any = 1;
13690 if (completeWild->nsSet != NULL) {
13691 xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
13692 completeWild->nsSet = NULL;
13694 if (completeWild->negNsSet != NULL) {
13695 xmlFree(completeWild->negNsSet);
13696 completeWild->negNsSet = NULL;
13698 } else if (nsFound && (!absentFound)) {
13700 * 5.2 If the set S includes the negated namespace name
13701 * but not `absent`, then a pair of not and `absent` must
13704 if (completeWild->nsSet != NULL) {
13705 xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
13706 completeWild->nsSet = NULL;
13708 if (completeWild->negNsSet == NULL) {
13709 completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt);
13710 if (completeWild->negNsSet == NULL)
13713 completeWild->negNsSet->value = NULL;
13714 } else if ((!nsFound) && absentFound) {
13716 * 5.3 If the set S includes `absent` but not the negated
13717 * namespace name, then the union is not expressible.
13719 xmlSchemaPErr(ctxt, completeWild->node,
13720 XML_SCHEMAP_UNION_NOT_EXPRESSIBLE,
13721 "The union of the wilcard is not expressible.\n",
13723 return(XML_SCHEMAP_UNION_NOT_EXPRESSIBLE);
13724 } else if ((!nsFound) && (!absentFound)) {
13726 * 5.4 If the set S does not include either the negated namespace
13727 * name or `absent`, then whichever of O1 or O2 is a pair of not
13728 * and a namespace name must be the value.
13730 if (completeWild->negNsSet == NULL) {
13731 if (completeWild->nsSet != NULL) {
13732 xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
13733 completeWild->nsSet = NULL;
13735 completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt);
13736 if (completeWild->negNsSet == NULL)
13738 completeWild->negNsSet->value = curWild->negNsSet->value;
13746 if (((completeWild->negNsSet != NULL) &&
13747 (completeWild->negNsSet->value == NULL) &&
13748 (curWild->nsSet != NULL)) ||
13749 ((curWild->negNsSet != NULL) &&
13750 (curWild->negNsSet->value == NULL) &&
13751 (completeWild->nsSet != NULL))) {
13753 if (completeWild->nsSet != NULL) {
13754 cur = completeWild->nsSet;
13756 cur = curWild->nsSet;
13758 while (cur != NULL) {
13759 if (cur->value == NULL) {
13761 * 6.1 If the set S includes `absent`, then any must be the
13764 completeWild->any = 1;
13765 if (completeWild->nsSet != NULL) {
13766 xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
13767 completeWild->nsSet = NULL;
13769 if (completeWild->negNsSet != NULL) {
13770 xmlFree(completeWild->negNsSet);
13771 completeWild->negNsSet = NULL;
13777 if (completeWild->negNsSet == NULL) {
13779 * 6.2 If the set S does not include `absent`, then a pair of not
13780 * and `absent` must be the value.
13782 if (completeWild->nsSet != NULL) {
13783 xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
13784 completeWild->nsSet = NULL;
13786 completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt);
13787 if (completeWild->negNsSet == NULL)
13789 completeWild->negNsSet->value = NULL;
13798 * xmlSchemaIntersectWildcards:
13799 * @ctxt: the schema parser context
13800 * @completeWild: the first wildcard
13801 * @curWild: the second wildcard
13803 * Intersects the namespace constraints of the given wildcards.
13804 * @completeWild will hold the resulting intersection.
13805 * Returns a positive error code on failure, -1 in case of an
13806 * internal error, 0 otherwise.
13809 xmlSchemaIntersectWildcards(xmlSchemaParserCtxtPtr ctxt,
13810 xmlSchemaWildcardPtr completeWild,
13811 xmlSchemaWildcardPtr curWild)
13813 xmlSchemaWildcardNsPtr cur, curB, prev, tmp;
13816 * 1 If O1 and O2 are the same value, then that value must be the
13819 if ((completeWild->any == curWild->any) &&
13820 ((completeWild->nsSet == NULL) == (curWild->nsSet == NULL)) &&
13821 ((completeWild->negNsSet == NULL) == (curWild->negNsSet == NULL))) {
13823 if ((completeWild->negNsSet == NULL) ||
13824 (completeWild->negNsSet->value == curWild->negNsSet->value)) {
13826 if (completeWild->nsSet != NULL) {
13830 * Check equality of sets.
13832 cur = completeWild->nsSet;
13833 while (cur != NULL) {
13835 curB = curWild->nsSet;
13836 while (curB != NULL) {
13837 if (cur->value == curB->value) {
13854 * 2 If either O1 or O2 is any, then the other must be the value.
13856 if ((completeWild->any != curWild->any) && (completeWild->any)) {
13857 if (xmlSchemaCloneWildcardNsConstraints(ctxt, completeWild, curWild) == -1)
13862 * 3 If either O1 or O2 is a pair of not and a value (a namespace
13863 * name or `absent`) and the other is a set of (namespace names or
13864 * `absent`), then that set, minus the negated value if it was in
13865 * the set, minus `absent` if it was in the set, must be the value.
13867 if (((completeWild->negNsSet != NULL) && (curWild->nsSet != NULL)) ||
13868 ((curWild->negNsSet != NULL) && (completeWild->nsSet != NULL))) {
13869 const xmlChar *neg;
13871 if (completeWild->nsSet == NULL) {
13872 neg = completeWild->negNsSet->value;
13873 if (xmlSchemaCloneWildcardNsConstraints(ctxt, completeWild, curWild) == -1)
13876 neg = curWild->negNsSet->value;
13878 * Remove absent and negated.
13881 cur = completeWild->nsSet;
13882 while (cur != NULL) {
13883 if (cur->value == NULL) {
13885 completeWild->nsSet = cur->next;
13887 prev->next = cur->next;
13896 cur = completeWild->nsSet;
13897 while (cur != NULL) {
13898 if (cur->value == neg) {
13900 completeWild->nsSet = cur->next;
13902 prev->next = cur->next;
13914 * 4 If both O1 and O2 are sets of (namespace names or `absent`),
13915 * then the intersection of those sets must be the value.
13917 if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) {
13920 cur = completeWild->nsSet;
13922 while (cur != NULL) {
13924 curB = curWild->nsSet;
13925 while (curB != NULL) {
13926 if (cur->value == curB->value) {
13934 completeWild->nsSet = cur->next;
13936 prev->next = cur->next;
13948 /* 5 If the two are negations of different namespace names,
13949 * then the intersection is not expressible
13951 if ((completeWild->negNsSet != NULL) &&
13952 (curWild->negNsSet != NULL) &&
13953 (completeWild->negNsSet->value != curWild->negNsSet->value) &&
13954 (completeWild->negNsSet->value != NULL) &&
13955 (curWild->negNsSet->value != NULL)) {
13957 xmlSchemaPErr(ctxt, completeWild->node, XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE,
13958 "The intersection of the wilcard is not expressible.\n",
13960 return(XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE);
13963 * 6 If the one is a negation of a namespace name and the other
13964 * is a negation of `absent`, then the one which is the negation
13965 * of a namespace name must be the value.
13967 if ((completeWild->negNsSet != NULL) && (curWild->negNsSet != NULL) &&
13968 (completeWild->negNsSet->value != curWild->negNsSet->value) &&
13969 (completeWild->negNsSet->value == NULL)) {
13970 completeWild->negNsSet->value = curWild->negNsSet->value;
13976 * xmlSchemaIsWildcardNsConstraintSubset:
13977 * @ctxt: the schema parser context
13978 * @sub: the first wildcard
13979 * @super: the second wildcard
13981 * Schema Component Constraint: Wildcard Subset (cos-ns-subset)
13983 * Returns 0 if the namespace constraint of @sub is an intensional
13984 * subset of @super, 1 otherwise.
13987 xmlSchemaCheckCOSNSSubset(xmlSchemaWildcardPtr sub,
13988 xmlSchemaWildcardPtr super)
13991 * 1 super must be any.
13996 * 2.1 sub must be a pair of not and a namespace name or `absent`.
13997 * 2.2 super must be a pair of not and the same value.
13999 if ((sub->negNsSet != NULL) &&
14000 (super->negNsSet != NULL) &&
14001 (sub->negNsSet->value == super->negNsSet->value))
14004 * 3.1 sub must be a set whose members are either namespace names or `absent`.
14006 if (sub->nsSet != NULL) {
14008 * 3.2.1 super must be the same set or a superset thereof.
14010 if (super->nsSet != NULL) {
14011 xmlSchemaWildcardNsPtr cur, curB;
14015 while (cur != NULL) {
14017 curB = super->nsSet;
14018 while (curB != NULL) {
14019 if (cur->value == curB->value) {
14031 } else if (super->negNsSet != NULL) {
14032 xmlSchemaWildcardNsPtr cur;
14034 * 3.2.2 super must be a pair of not and a namespace name or
14035 * `absent` and that value must not be in sub's set.
14038 while (cur != NULL) {
14039 if (cur->value == super->negNsSet->value)
14050 xmlSchemaGetEffectiveValueConstraint(xmlSchemaAttributeUsePtr attruse,
14052 const xmlChar **value,
14053 xmlSchemaValPtr *val)
14060 if (attruse->defValue != NULL) {
14061 *value = attruse->defValue;
14063 *val = attruse->defVal;
14064 if (attruse->flags & XML_SCHEMA_ATTR_USE_FIXED)
14067 } else if ((attruse->attrDecl != NULL) &&
14068 (attruse->attrDecl->defValue != NULL)) {
14069 *value = attruse->attrDecl->defValue;
14071 *val = attruse->attrDecl->defVal;
14072 if (attruse->attrDecl->flags & XML_SCHEMAS_ATTR_FIXED)
14079 * xmlSchemaCheckCVCWildcardNamespace:
14080 * @wild: the wildcard
14081 * @ns: the namespace
14083 * Validation Rule: Wildcard allows Namespace Name
14084 * (cvc-wildcard-namespace)
14086 * Returns 0 if the given namespace matches the wildcard,
14087 * 1 otherwise and -1 on API errors.
14090 xmlSchemaCheckCVCWildcardNamespace(xmlSchemaWildcardPtr wild,
14098 else if (wild->nsSet != NULL) {
14099 xmlSchemaWildcardNsPtr cur;
14102 while (cur != NULL) {
14103 if (xmlStrEqual(cur->value, ns))
14107 } else if ((wild->negNsSet != NULL) && (ns != NULL) &&
14108 (!xmlStrEqual(wild->negNsSet->value, ns)))
14114 #define XML_SCHEMA_ACTION_DERIVE 0
14115 #define XML_SCHEMA_ACTION_REDEFINE 1
14117 #define WXS_ACTION_STR(a) \
14118 ((a) == XML_SCHEMA_ACTION_DERIVE) ? (const xmlChar *) "base" : (const xmlChar *) "redefined"
14121 * Schema Component Constraint:
14122 * Derivation Valid (Restriction, Complex)
14123 * derivation-ok-restriction (2) - (4)
14126 * In XML Schema 1.1 this will be:
14128 * Checking complex type subsumption (practicalSubsumption) (1, 2 and 3)
14132 xmlSchemaCheckDerivationOKRestriction2to4(xmlSchemaParserCtxtPtr pctxt,
14134 xmlSchemaBasicItemPtr item,
14135 xmlSchemaBasicItemPtr baseItem,
14136 xmlSchemaItemListPtr uses,
14137 xmlSchemaItemListPtr baseUses,
14138 xmlSchemaWildcardPtr wild,
14139 xmlSchemaWildcardPtr baseWild)
14141 xmlSchemaAttributeUsePtr cur = NULL, bcur;
14142 int i, j, found; /* err = 0; */
14143 const xmlChar *bEffValue;
14146 if (uses != NULL) {
14147 for (i = 0; i < uses->nbItems; i++) {
14148 cur = uses->items[i];
14150 if (baseUses == NULL)
14152 for (j = 0; j < baseUses->nbItems; j++) {
14153 bcur = baseUses->items[j];
14154 if ((WXS_ATTRUSE_DECL_NAME(cur) ==
14155 WXS_ATTRUSE_DECL_NAME(bcur)) &&
14156 (WXS_ATTRUSE_DECL_TNS(cur) ==
14157 WXS_ATTRUSE_DECL_TNS(bcur)))
14160 * (2.1) "If there is an attribute use in the {attribute
14161 * uses} of the {base type definition} (call this B) whose
14162 * {attribute declaration} has the same {name} and {target
14163 * namespace}, then all of the following must be true:"
14167 if ((cur->occurs == XML_SCHEMAS_ATTR_USE_OPTIONAL) &&
14168 (bcur->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED))
14170 xmlChar *str = NULL;
14172 * (2.1.1) "one of the following must be true:"
14173 * (2.1.1.1) "B's {required} is false."
14174 * (2.1.1.2) "R's {required} is true."
14176 xmlSchemaPAttrUseErr4(pctxt,
14177 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_1,
14178 WXS_ITEM_NODE(item), item, cur,
14179 "The 'optional' attribute use is inconsistent "
14180 "with the corresponding 'required' attribute use of "
14182 WXS_ACTION_STR(action),
14183 xmlSchemaGetComponentDesignation(&str, baseItem),
14185 FREE_AND_NULL(str);
14186 /* err = pctxt->err; */
14187 } else if (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt,
14188 WXS_ATTRUSE_TYPEDEF(cur),
14189 WXS_ATTRUSE_TYPEDEF(bcur), 0) != 0)
14191 xmlChar *strA = NULL, *strB = NULL, *strC = NULL;
14194 * SPEC (2.1.2) "R's {attribute declaration}'s
14195 * {type definition} must be validly derived from
14196 * B's {type definition} given the empty set as
14197 * defined in Type Derivation OK (Simple) ($3.14.6)."
14199 xmlSchemaPAttrUseErr4(pctxt,
14200 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_2,
14201 WXS_ITEM_NODE(item), item, cur,
14202 "The attribute declaration's %s "
14203 "is not validly derived from "
14204 "the corresponding %s of the "
14205 "attribute declaration in the %s %s",
14206 xmlSchemaGetComponentDesignation(&strA,
14207 WXS_ATTRUSE_TYPEDEF(cur)),
14208 xmlSchemaGetComponentDesignation(&strB,
14209 WXS_ATTRUSE_TYPEDEF(bcur)),
14210 WXS_ACTION_STR(action),
14211 xmlSchemaGetComponentDesignation(&strC, baseItem));
14212 /* xmlSchemaGetComponentDesignation(&str, baseItem), */
14213 FREE_AND_NULL(strA);
14214 FREE_AND_NULL(strB);
14215 FREE_AND_NULL(strC);
14216 /* err = pctxt->err; */
14219 * 2.1.3 [Definition:] Let the effective value
14220 * constraint of an attribute use be its {value
14221 * constraint}, if present, otherwise its {attribute
14222 * declaration}'s {value constraint} .
14224 xmlSchemaGetEffectiveValueConstraint(bcur,
14225 &effFixed, &bEffValue, NULL);
14227 * 2.1.3 ... one of the following must be true
14229 * 2.1.3.1 B's `effective value constraint` is
14230 * `absent` or default.
14232 if ((bEffValue != NULL) &&
14234 const xmlChar *rEffValue = NULL;
14236 xmlSchemaGetEffectiveValueConstraint(bcur,
14237 &effFixed, &rEffValue, NULL);
14239 * 2.1.3.2 R's `effective value constraint` is
14240 * fixed with the same string as B's.
14241 * MAYBE TODO: Compare the computed values.
14242 * Hmm, it says "same string" so
14243 * string-equality might really be sufficient.
14245 if ((effFixed == 0) ||
14246 (! WXS_ARE_DEFAULT_STR_EQUAL(rEffValue, bEffValue)))
14248 xmlChar *str = NULL;
14250 xmlSchemaPAttrUseErr4(pctxt,
14251 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_3,
14252 WXS_ITEM_NODE(item), item, cur,
14253 "The effective value constraint of the "
14254 "attribute use is inconsistent with "
14255 "its correspondent in the %s %s",
14256 WXS_ACTION_STR(action),
14257 xmlSchemaGetComponentDesignation(&str,
14260 FREE_AND_NULL(str);
14261 /* err = pctxt->err; */
14271 * (2.2) "otherwise the {base type definition} must have an
14272 * {attribute wildcard} and the {target namespace} of the
14273 * R's {attribute declaration} must be `valid` with respect
14274 * to that wildcard, as defined in Wildcard allows Namespace
14277 if ((baseWild == NULL) ||
14278 (xmlSchemaCheckCVCWildcardNamespace(baseWild,
14279 (WXS_ATTRUSE_DECL(cur))->targetNamespace) != 0))
14281 xmlChar *str = NULL;
14283 xmlSchemaPAttrUseErr4(pctxt,
14284 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_2,
14285 WXS_ITEM_NODE(item), item, cur,
14286 "Neither a matching attribute use, "
14287 "nor a matching wildcard exists in the %s %s",
14288 WXS_ACTION_STR(action),
14289 xmlSchemaGetComponentDesignation(&str, baseItem),
14291 FREE_AND_NULL(str);
14292 /* err = pctxt->err; */
14298 * SPEC derivation-ok-restriction (3):
14299 * (3) "For each attribute use in the {attribute uses} of the {base type
14300 * definition} whose {required} is true, there must be an attribute
14301 * use with an {attribute declaration} with the same {name} and
14302 * {target namespace} as its {attribute declaration} in the {attribute
14303 * uses} of the complex type definition itself whose {required} is true.
14305 if (baseUses != NULL) {
14306 for (j = 0; j < baseUses->nbItems; j++) {
14307 bcur = baseUses->items[j];
14308 if (bcur->occurs != XML_SCHEMAS_ATTR_USE_REQUIRED)
14311 if (uses != NULL) {
14312 for (i = 0; i < uses->nbItems; i++) {
14313 cur = uses->items[i];
14314 if ((WXS_ATTRUSE_DECL_NAME(cur) ==
14315 WXS_ATTRUSE_DECL_NAME(bcur)) &&
14316 (WXS_ATTRUSE_DECL_TNS(cur) ==
14317 WXS_ATTRUSE_DECL_TNS(bcur))) {
14324 xmlChar *strA = NULL, *strB = NULL;
14326 xmlSchemaCustomErr4(ACTXT_CAST pctxt,
14327 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_3,
14329 "A matching attribute use for the "
14330 "'required' %s of the %s %s is missing",
14331 xmlSchemaGetComponentDesignation(&strA, bcur),
14332 WXS_ACTION_STR(action),
14333 xmlSchemaGetComponentDesignation(&strB, baseItem),
14335 FREE_AND_NULL(strA);
14336 FREE_AND_NULL(strB);
14341 * derivation-ok-restriction (4)
14343 if (wild != NULL) {
14345 * (4) "If there is an {attribute wildcard}, all of the
14346 * following must be true:"
14348 if (baseWild == NULL) {
14349 xmlChar *str = NULL;
14352 * (4.1) "The {base type definition} must also have one."
14354 xmlSchemaCustomErr4(ACTXT_CAST pctxt,
14355 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_1,
14357 "The %s has an attribute wildcard, "
14358 "but the %s %s '%s' does not have one",
14359 WXS_ITEM_TYPE_NAME(item),
14360 WXS_ACTION_STR(action),
14361 WXS_ITEM_TYPE_NAME(baseItem),
14362 xmlSchemaGetComponentQName(&str, baseItem));
14363 FREE_AND_NULL(str);
14364 return(pctxt->err);
14365 } else if ((baseWild->any == 0) &&
14366 xmlSchemaCheckCOSNSSubset(wild, baseWild))
14368 xmlChar *str = NULL;
14370 * (4.2) "The complex type definition's {attribute wildcard}'s
14371 * {namespace constraint} must be a subset of the {base type
14372 * definition}'s {attribute wildcard}'s {namespace constraint},
14373 * as defined by Wildcard Subset ($3.10.6)."
14375 xmlSchemaCustomErr4(ACTXT_CAST pctxt,
14376 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_2,
14378 "The attribute wildcard is not a valid "
14379 "subset of the wildcard in the %s %s '%s'",
14380 WXS_ACTION_STR(action),
14381 WXS_ITEM_TYPE_NAME(baseItem),
14382 xmlSchemaGetComponentQName(&str, baseItem),
14384 FREE_AND_NULL(str);
14385 return(pctxt->err);
14387 /* 4.3 Unless the {base type definition} is the `ur-type
14388 * definition`, the complex type definition's {attribute
14389 * wildcard}'s {process contents} must be identical to or
14390 * stronger than the {base type definition}'s {attribute
14391 * wildcard}'s {process contents}, where strict is stronger
14392 * than lax is stronger than skip.
14394 if ((! WXS_IS_ANYTYPE(baseItem)) &&
14395 (wild->processContents < baseWild->processContents)) {
14396 xmlChar *str = NULL;
14397 xmlSchemaCustomErr4(ACTXT_CAST pctxt,
14398 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_3,
14400 "The {process contents} of the attribute wildcard is "
14401 "weaker than the one in the %s %s '%s'",
14402 WXS_ACTION_STR(action),
14403 WXS_ITEM_TYPE_NAME(baseItem),
14404 xmlSchemaGetComponentQName(&str, baseItem),
14407 return(pctxt->err);
14415 xmlSchemaExpandAttributeGroupRefs(xmlSchemaParserCtxtPtr pctxt,
14416 xmlSchemaBasicItemPtr item,
14417 xmlSchemaWildcardPtr *completeWild,
14418 xmlSchemaItemListPtr list,
14419 xmlSchemaItemListPtr prohibs);
14421 * xmlSchemaFixupTypeAttributeUses:
14422 * @ctxt: the schema parser context
14423 * @type: the complex type definition
14426 * Builds the wildcard and the attribute uses on the given complex type.
14427 * Returns -1 if an internal error occurs, 0 otherwise.
14429 * ATTENTION TODO: Experimantally this uses pointer comparisons for
14430 * strings, so recheck this if we start to hardcode some schemata, since
14431 * they might not be in the same dict.
14432 * NOTE: It is allowed to "extend" the xs:anyType type.
14435 xmlSchemaFixupTypeAttributeUses(xmlSchemaParserCtxtPtr pctxt,
14436 xmlSchemaTypePtr type)
14438 xmlSchemaTypePtr baseType = NULL;
14439 xmlSchemaAttributeUsePtr use;
14440 xmlSchemaItemListPtr uses, baseUses, prohibs = NULL;
14442 if (type->baseType == NULL) {
14443 PERROR_INT("xmlSchemaFixupTypeAttributeUses",
14447 baseType = type->baseType;
14448 if (WXS_IS_TYPE_NOT_FIXED(baseType))
14449 if (xmlSchemaTypeFixup(baseType, ACTXT_CAST pctxt) == -1)
14452 uses = type->attrUses;
14453 baseUses = baseType->attrUses;
14455 * Expand attribute group references. And build the 'complete'
14456 * wildcard, i.e. intersect multiple wildcards.
14457 * Move attribute prohibitions into a separate list.
14459 if (uses != NULL) {
14460 if (WXS_IS_RESTRICTION(type)) {
14462 * This one will transfer all attr. prohibitions
14463 * into pctxt->attrProhibs.
14465 if (xmlSchemaExpandAttributeGroupRefs(pctxt,
14466 WXS_BASIC_CAST type, &(type->attributeWildcard), uses,
14467 pctxt->attrProhibs) == -1)
14469 PERROR_INT("xmlSchemaFixupTypeAttributeUses",
14470 "failed to expand attributes");
14472 if (pctxt->attrProhibs->nbItems != 0)
14473 prohibs = pctxt->attrProhibs;
14475 if (xmlSchemaExpandAttributeGroupRefs(pctxt,
14476 WXS_BASIC_CAST type, &(type->attributeWildcard), uses,
14479 PERROR_INT("xmlSchemaFixupTypeAttributeUses",
14480 "failed to expand attributes");
14485 * Inherit the attribute uses of the base type.
14487 if (baseUses != NULL) {
14489 xmlSchemaAttributeUseProhibPtr pro;
14491 if (WXS_IS_RESTRICTION(type)) {
14493 xmlSchemaAttributeUsePtr tmp;
14496 usesCount = uses->nbItems;
14501 for (i = 0; i < baseUses->nbItems; i++) {
14502 use = baseUses->items[i];
14505 * Filter out prohibited uses.
14507 for (j = 0; j < prohibs->nbItems; j++) {
14508 pro = prohibs->items[j];
14509 if ((WXS_ATTRUSE_DECL_NAME(use) == pro->name) &&
14510 (WXS_ATTRUSE_DECL_TNS(use) ==
14511 pro->targetNamespace))
14519 * Filter out existing uses.
14521 for (j = 0; j < usesCount; j++) {
14522 tmp = uses->items[j];
14523 if ((WXS_ATTRUSE_DECL_NAME(use) ==
14524 WXS_ATTRUSE_DECL_NAME(tmp)) &&
14525 (WXS_ATTRUSE_DECL_TNS(use) ==
14526 WXS_ATTRUSE_DECL_TNS(tmp)))
14532 if (uses == NULL) {
14533 type->attrUses = xmlSchemaItemListCreate();
14534 if (type->attrUses == NULL)
14536 uses = type->attrUses;
14538 xmlSchemaItemListAddSize(uses, 2, use);
14543 for (i = 0; i < baseUses->nbItems; i++) {
14544 use = baseUses->items[i];
14545 if (uses == NULL) {
14546 type->attrUses = xmlSchemaItemListCreate();
14547 if (type->attrUses == NULL)
14549 uses = type->attrUses;
14551 xmlSchemaItemListAddSize(uses, baseUses->nbItems, use);
14556 * Shrink attr. uses.
14559 if (uses->nbItems == 0) {
14560 xmlSchemaItemListFree(uses);
14561 type->attrUses = NULL;
14564 * TODO: We could shrink the size of the array
14565 * to fit the actual number of items.
14569 * Compute the complete wildcard.
14571 if (WXS_IS_EXTENSION(type)) {
14572 if (baseType->attributeWildcard != NULL) {
14574 * (3.2.2.1) "If the `base wildcard` is non-`absent`, then
14575 * the appropriate case among the following:"
14577 if (type->attributeWildcard != NULL) {
14579 * Union the complete wildcard with the base wildcard.
14580 * SPEC {attribute wildcard}
14581 * (3.2.2.1.2) "otherwise a wildcard whose {process contents}
14582 * and {annotation} are those of the `complete wildcard`,
14583 * and whose {namespace constraint} is the intensional union
14584 * of the {namespace constraint} of the `complete wildcard`
14585 * and of the `base wildcard`, as defined in Attribute
14586 * Wildcard Union ($3.10.6)."
14588 if (xmlSchemaUnionWildcards(pctxt, type->attributeWildcard,
14589 baseType->attributeWildcard) == -1)
14593 * (3.2.2.1.1) "If the `complete wildcard` is `absent`,
14594 * then the `base wildcard`."
14596 type->attributeWildcard = baseType->attributeWildcard;
14600 * (3.2.2.2) "otherwise (the `base wildcard` is `absent`) the
14601 * `complete wildcard`"
14607 * SPEC {attribute wildcard}
14608 * (3.1) "If the <restriction> alternative is chosen, then the
14609 * `complete wildcard`;"
14621 * xmlSchemaTypeFinalContains:
14622 * @schema: the schema
14623 * @type: the type definition
14624 * @final: the final
14626 * Evaluates if a type definition contains the given "final".
14627 * This does take "finalDefault" into account as well.
14629 * Returns 1 if the type does containt the given "final",
14633 xmlSchemaTypeFinalContains(xmlSchemaTypePtr type, int final)
14637 if (type->flags & final)
14644 * xmlSchemaGetUnionSimpleTypeMemberTypes:
14645 * @type: the Union Simple Type
14647 * Returns a list of member types of @type if existing,
14648 * returns NULL otherwise.
14650 static xmlSchemaTypeLinkPtr
14651 xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type)
14653 while ((type != NULL) && (type->type == XML_SCHEMA_TYPE_SIMPLE)) {
14654 if (type->memberTypes != NULL)
14655 return (type->memberTypes);
14657 type = type->baseType;
14663 * xmlSchemaGetParticleTotalRangeMin:
14664 * @particle: the particle
14666 * Schema Component Constraint: Effective Total Range
14667 * (all and sequence) + (choice)
14669 * Returns the minimun Effective Total Range.
14672 xmlSchemaGetParticleTotalRangeMin(xmlSchemaParticlePtr particle)
14674 if ((particle->children == NULL) ||
14675 (particle->minOccurs == 0))
14677 if (particle->children->type == XML_SCHEMA_TYPE_CHOICE) {
14679 xmlSchemaParticlePtr part =
14680 (xmlSchemaParticlePtr) particle->children->children;
14684 while (part != NULL) {
14685 if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) ||
14686 (part->children->type == XML_SCHEMA_TYPE_ANY))
14687 cur = part->minOccurs;
14689 cur = xmlSchemaGetParticleTotalRangeMin(part);
14692 if ((min > cur) || (min == -1))
14694 part = (xmlSchemaParticlePtr) part->next;
14696 return (particle->minOccurs * min);
14698 /* <all> and <sequence> */
14700 xmlSchemaParticlePtr part =
14701 (xmlSchemaParticlePtr) particle->children->children;
14706 if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) ||
14707 (part->children->type == XML_SCHEMA_TYPE_ANY))
14708 sum += part->minOccurs;
14710 sum += xmlSchemaGetParticleTotalRangeMin(part);
14711 part = (xmlSchemaParticlePtr) part->next;
14712 } while (part != NULL);
14713 return (particle->minOccurs * sum);
14719 * xmlSchemaGetParticleTotalRangeMax:
14720 * @particle: the particle
14722 * Schema Component Constraint: Effective Total Range
14723 * (all and sequence) + (choice)
14725 * Returns the maximum Effective Total Range.
14728 xmlSchemaGetParticleTotalRangeMax(xmlSchemaParticlePtr particle)
14730 if ((particle->children == NULL) ||
14731 (particle->children->children == NULL))
14733 if (particle->children->type == XML_SCHEMA_TYPE_CHOICE) {
14735 xmlSchemaParticlePtr part =
14736 (xmlSchemaParticlePtr) particle->children->children;
14738 for (; part != NULL; part = (xmlSchemaParticlePtr) part->next) {
14739 if (part->children == NULL)
14741 if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) ||
14742 (part->children->type == XML_SCHEMA_TYPE_ANY))
14743 cur = part->maxOccurs;
14745 cur = xmlSchemaGetParticleTotalRangeMax(part);
14746 if (cur == UNBOUNDED)
14747 return (UNBOUNDED);
14748 if ((max < cur) || (max == -1))
14751 /* TODO: Handle overflows? */
14752 return (particle->maxOccurs * max);
14754 /* <all> and <sequence> */
14756 xmlSchemaParticlePtr part =
14757 (xmlSchemaParticlePtr) particle->children->children;
14759 for (; part != NULL; part = (xmlSchemaParticlePtr) part->next) {
14760 if (part->children == NULL)
14762 if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) ||
14763 (part->children->type == XML_SCHEMA_TYPE_ANY))
14764 cur = part->maxOccurs;
14766 cur = xmlSchemaGetParticleTotalRangeMax(part);
14767 if (cur == UNBOUNDED)
14768 return (UNBOUNDED);
14769 if ((cur > 0) && (particle->maxOccurs == UNBOUNDED))
14770 return (UNBOUNDED);
14773 /* TODO: Handle overflows? */
14774 return (particle->maxOccurs * sum);
14780 * xmlSchemaIsParticleEmptiable:
14781 * @particle: the particle
14783 * Schema Component Constraint: Particle Emptiable
14784 * Checks whether the given particle is emptiable.
14786 * Returns 1 if emptiable, 0 otherwise.
14789 xmlSchemaIsParticleEmptiable(xmlSchemaParticlePtr particle)
14792 * SPEC (1) "Its {min occurs} is 0."
14794 if ((particle == NULL) || (particle->minOccurs == 0) ||
14795 (particle->children == NULL))
14798 * SPEC (2) "Its {term} is a group and the minimum part of the
14799 * effective total range of that group, [...] is 0."
14801 if (WXS_IS_MODEL_GROUP(particle->children)) {
14802 if (xmlSchemaGetParticleTotalRangeMin(particle) == 0)
14809 * xmlSchemaCheckCOSSTDerivedOK:
14810 * @actxt: a context
14811 * @type: the derived simple type definition
14812 * @baseType: the base type definition
14813 * @subset: the subset of ('restriction', ect.)
14815 * Schema Component Constraint:
14816 * Type Derivation OK (Simple) (cos-st-derived-OK)
14818 * Checks wheter @type can be validly
14819 * derived from @baseType.
14821 * Returns 0 on success, an positive error code otherwise.
14824 xmlSchemaCheckCOSSTDerivedOK(xmlSchemaAbstractCtxtPtr actxt,
14825 xmlSchemaTypePtr type,
14826 xmlSchemaTypePtr baseType,
14830 * 1 They are the same type definition.
14831 * TODO: The identy check might have to be more complex than this.
14833 if (type == baseType)
14836 * 2.1 restriction is not in the subset, or in the {final}
14837 * of its own {base type definition};
14839 * NOTE that this will be used also via "xsi:type".
14841 * TODO: Revise this, it looks strange. How can the "type"
14842 * not be fixed or *in* fixing?
14844 if (WXS_IS_TYPE_NOT_FIXED(type))
14845 if (xmlSchemaTypeFixup(type, actxt) == -1)
14847 if (WXS_IS_TYPE_NOT_FIXED(baseType))
14848 if (xmlSchemaTypeFixup(baseType, actxt) == -1)
14850 if ((subset & SUBSET_RESTRICTION) ||
14851 (xmlSchemaTypeFinalContains(type->baseType,
14852 XML_SCHEMAS_TYPE_FINAL_RESTRICTION))) {
14853 return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_1);
14856 if (type->baseType == baseType) {
14858 * 2.2.1 D's `base type definition` is B.
14863 * 2.2.2 D's `base type definition` is not the `ur-type definition`
14864 * and is validly derived from B given the subset, as defined by this
14867 if ((! WXS_IS_ANYTYPE(type->baseType)) &&
14868 (xmlSchemaCheckCOSSTDerivedOK(actxt, type->baseType,
14869 baseType, subset) == 0)) {
14873 * 2.2.3 D's {variety} is list or union and B is the `simple ur-type
14876 if (WXS_IS_ANY_SIMPLE_TYPE(baseType) &&
14877 (WXS_IS_LIST(type) || WXS_IS_UNION(type))) {
14881 * 2.2.4 B's {variety} is union and D is validly derived from a type
14882 * definition in B's {member type definitions} given the subset, as
14883 * defined by this constraint.
14885 * NOTE: This seems not to involve built-in types, since there is no
14886 * built-in Union Simple Type.
14888 if (WXS_IS_UNION(baseType)) {
14889 xmlSchemaTypeLinkPtr cur;
14891 cur = baseType->memberTypes;
14892 while (cur != NULL) {
14893 if (WXS_IS_TYPE_NOT_FIXED(cur->type))
14894 if (xmlSchemaTypeFixup(cur->type, actxt) == -1)
14896 if (xmlSchemaCheckCOSSTDerivedOK(actxt,
14897 type, cur->type, subset) == 0)
14900 * It just has to be validly derived from at least one
14908 return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_2);
14912 * xmlSchemaCheckTypeDefCircularInternal:
14913 * @pctxt: the schema parser context
14914 * @ctxtType: the type definition
14915 * @ancestor: an ancestor of @ctxtType
14917 * Checks st-props-correct (2) + ct-props-correct (3).
14918 * Circular type definitions are not allowed.
14920 * Returns XML_SCHEMAP_ST_PROPS_CORRECT_2 if the given type is
14921 * circular, 0 otherwise.
14924 xmlSchemaCheckTypeDefCircularInternal(xmlSchemaParserCtxtPtr pctxt,
14925 xmlSchemaTypePtr ctxtType,
14926 xmlSchemaTypePtr ancestor)
14930 if ((ancestor == NULL) || (ancestor->type == XML_SCHEMA_TYPE_BASIC))
14933 if (ctxtType == ancestor) {
14934 xmlSchemaPCustomErr(pctxt,
14935 XML_SCHEMAP_ST_PROPS_CORRECT_2,
14936 WXS_BASIC_CAST ctxtType, WXS_ITEM_NODE(ctxtType),
14937 "The definition is circular", NULL);
14938 return (XML_SCHEMAP_ST_PROPS_CORRECT_2);
14940 if (ancestor->flags & XML_SCHEMAS_TYPE_MARKED) {
14942 * Avoid inifinite recursion on circular types not yet checked.
14946 ancestor->flags |= XML_SCHEMAS_TYPE_MARKED;
14947 ret = xmlSchemaCheckTypeDefCircularInternal(pctxt, ctxtType,
14948 ancestor->baseType);
14949 ancestor->flags ^= XML_SCHEMAS_TYPE_MARKED;
14954 * xmlSchemaCheckTypeDefCircular:
14955 * @item: the complex/simple type definition
14956 * @ctxt: the parser context
14959 * Checks for circular type definitions.
14962 xmlSchemaCheckTypeDefCircular(xmlSchemaTypePtr item,
14963 xmlSchemaParserCtxtPtr ctxt)
14965 if ((item == NULL) ||
14966 (item->type == XML_SCHEMA_TYPE_BASIC) ||
14967 (item->baseType == NULL))
14969 xmlSchemaCheckTypeDefCircularInternal(ctxt, item,
14974 * Simple Type Definition Representation OK (src-simple-type) 4
14976 * "4 Circular union type definition is disallowed. That is, if the
14977 * <union> alternative is chosen, there must not be any entries in the
14978 * memberTypes [attribute] at any depth which resolve to the component
14979 * corresponding to the <simpleType>."
14981 * Note that this should work on the *representation* of a component,
14982 * thus assumes any union types in the member types not being yet
14983 * substituted. At this stage we need the variety of the types
14984 * to be already computed.
14987 xmlSchemaCheckUnionTypeDefCircularRecur(xmlSchemaParserCtxtPtr pctxt,
14988 xmlSchemaTypePtr ctxType,
14989 xmlSchemaTypeLinkPtr members)
14991 xmlSchemaTypeLinkPtr member;
14992 xmlSchemaTypePtr memberType;
14995 while (member != NULL) {
14996 memberType = member->type;
14997 while ((memberType != NULL) &&
14998 (memberType->type != XML_SCHEMA_TYPE_BASIC)) {
14999 if (memberType == ctxType) {
15000 xmlSchemaPCustomErr(pctxt,
15001 XML_SCHEMAP_SRC_SIMPLE_TYPE_4,
15002 WXS_BASIC_CAST ctxType, NULL,
15003 "The union type definition is circular", NULL);
15004 return (XML_SCHEMAP_SRC_SIMPLE_TYPE_4);
15006 if ((WXS_IS_UNION(memberType)) &&
15007 ((memberType->flags & XML_SCHEMAS_TYPE_MARKED) == 0))
15010 memberType->flags |= XML_SCHEMAS_TYPE_MARKED;
15011 res = xmlSchemaCheckUnionTypeDefCircularRecur(pctxt,
15013 xmlSchemaGetUnionSimpleTypeMemberTypes(memberType));
15014 memberType->flags ^= XML_SCHEMAS_TYPE_MARKED;
15018 memberType = memberType->baseType;
15020 member = member->next;
15026 xmlSchemaCheckUnionTypeDefCircular(xmlSchemaParserCtxtPtr pctxt,
15027 xmlSchemaTypePtr type)
15029 if (! WXS_IS_UNION(type))
15031 return(xmlSchemaCheckUnionTypeDefCircularRecur(pctxt, type,
15032 type->memberTypes));
15036 * xmlSchemaResolveTypeReferences:
15037 * @item: the complex/simple type definition
15038 * @ctxt: the parser context
15041 * Resolvese type definition references
15044 xmlSchemaResolveTypeReferences(xmlSchemaTypePtr typeDef,
15045 xmlSchemaParserCtxtPtr ctxt)
15047 if (typeDef == NULL)
15051 * Resolve the base type.
15053 if (typeDef->baseType == NULL) {
15054 typeDef->baseType = xmlSchemaGetType(ctxt->schema,
15055 typeDef->base, typeDef->baseNs);
15056 if (typeDef->baseType == NULL) {
15057 xmlSchemaPResCompAttrErr(ctxt,
15058 XML_SCHEMAP_SRC_RESOLVE,
15059 WXS_BASIC_CAST typeDef, typeDef->node,
15060 "base", typeDef->base, typeDef->baseNs,
15061 XML_SCHEMA_TYPE_SIMPLE, NULL);
15065 if (WXS_IS_SIMPLE(typeDef)) {
15066 if (WXS_IS_UNION(typeDef)) {
15068 * Resolve the memberTypes.
15070 xmlSchemaResolveUnionMemberTypes(ctxt, typeDef);
15072 } else if (WXS_IS_LIST(typeDef)) {
15074 * Resolve the itemType.
15076 if ((typeDef->subtypes == NULL) && (typeDef->base != NULL)) {
15078 typeDef->subtypes = xmlSchemaGetType(ctxt->schema,
15079 typeDef->base, typeDef->baseNs);
15081 if ((typeDef->subtypes == NULL) ||
15082 (! WXS_IS_SIMPLE(typeDef->subtypes)))
15084 typeDef->subtypes = NULL;
15085 xmlSchemaPResCompAttrErr(ctxt,
15086 XML_SCHEMAP_SRC_RESOLVE,
15087 WXS_BASIC_CAST typeDef, typeDef->node,
15088 "itemType", typeDef->base, typeDef->baseNs,
15089 XML_SCHEMA_TYPE_SIMPLE, NULL);
15096 * The ball of letters below means, that if we have a particle
15097 * which has a QName-helper component as its {term}, we want
15100 else if ((WXS_TYPE_CONTENTTYPE(typeDef) != NULL) &&
15101 ((WXS_TYPE_CONTENTTYPE(typeDef))->type ==
15102 XML_SCHEMA_TYPE_PARTICLE) &&
15103 (WXS_TYPE_PARTICLE_TERM(typeDef) != NULL) &&
15104 ((WXS_TYPE_PARTICLE_TERM(typeDef))->type ==
15105 XML_SCHEMA_EXTRA_QNAMEREF))
15107 xmlSchemaQNameRefPtr ref =
15108 WXS_QNAME_CAST WXS_TYPE_PARTICLE_TERM(typeDef);
15109 xmlSchemaModelGroupDefPtr groupDef;
15112 * URGENT TODO: Test this.
15114 WXS_TYPE_PARTICLE_TERM(typeDef) = NULL;
15116 * Resolve the MG definition reference.
15119 WXS_MODEL_GROUPDEF_CAST xmlSchemaGetNamedComponent(ctxt->schema,
15120 ref->itemType, ref->name, ref->targetNamespace);
15121 if (groupDef == NULL) {
15122 xmlSchemaPResCompAttrErr(ctxt, XML_SCHEMAP_SRC_RESOLVE,
15123 NULL, WXS_ITEM_NODE(WXS_TYPE_PARTICLE(typeDef)),
15124 "ref", ref->name, ref->targetNamespace, ref->itemType,
15126 /* Remove the particle. */
15127 WXS_TYPE_CONTENTTYPE(typeDef) = NULL;
15128 } else if (WXS_MODELGROUPDEF_MODEL(groupDef) == NULL)
15129 /* Remove the particle. */
15130 WXS_TYPE_CONTENTTYPE(typeDef) = NULL;
15133 * Assign the MG definition's {model group} to the
15134 * particle's {term}.
15136 WXS_TYPE_PARTICLE_TERM(typeDef) = WXS_MODELGROUPDEF_MODEL(groupDef);
15138 if (WXS_MODELGROUPDEF_MODEL(groupDef)->type == XML_SCHEMA_TYPE_ALL) {
15140 * SPEC cos-all-limited (1.2)
15141 * "1.2 the {term} property of a particle with
15142 * {max occurs}=1 which is part of a pair which constitutes
15143 * the {content type} of a complex type definition."
15145 if ((WXS_TYPE_PARTICLE(typeDef))->maxOccurs != 1) {
15146 xmlSchemaCustomErr(ACTXT_CAST ctxt,
15147 /* TODO: error code */
15148 XML_SCHEMAP_COS_ALL_LIMITED,
15149 WXS_ITEM_NODE(WXS_TYPE_PARTICLE(typeDef)), NULL,
15150 "The particle's {max occurs} must be 1, since the "
15151 "reference resolves to an 'all' model group",
15162 * xmlSchemaCheckSTPropsCorrect:
15163 * @ctxt: the schema parser context
15164 * @type: the simple type definition
15166 * Checks st-props-correct.
15168 * Returns 0 if the properties are correct,
15169 * if not, a positive error code and -1 on internal
15173 xmlSchemaCheckSTPropsCorrect(xmlSchemaParserCtxtPtr ctxt,
15174 xmlSchemaTypePtr type)
15176 xmlSchemaTypePtr baseType = type->baseType;
15177 xmlChar *str = NULL;
15179 /* STATE: error funcs converted. */
15181 * Schema Component Constraint: Simple Type Definition Properties Correct
15183 * NOTE: This is somehow redundant, since we actually built a simple type
15184 * to have all the needed information; this acts as an self test.
15186 /* Base type: If the datatype has been `derived` by `restriction`
15187 * then the Simple Type Definition component from which it is `derived`,
15188 * otherwise the Simple Type Definition for anySimpleType ($4.1.6).
15190 if (baseType == NULL) {
15192 * TODO: Think about: "modulo the impact of Missing
15193 * Sub-components ($5.3)."
15195 xmlSchemaPCustomErr(ctxt,
15196 XML_SCHEMAP_ST_PROPS_CORRECT_1,
15197 WXS_BASIC_CAST type, NULL,
15198 "No base type existent", NULL);
15199 return (XML_SCHEMAP_ST_PROPS_CORRECT_1);
15202 if (! WXS_IS_SIMPLE(baseType)) {
15203 xmlSchemaPCustomErr(ctxt,
15204 XML_SCHEMAP_ST_PROPS_CORRECT_1,
15205 WXS_BASIC_CAST type, NULL,
15206 "The base type '%s' is not a simple type",
15207 xmlSchemaGetComponentQName(&str, baseType));
15209 return (XML_SCHEMAP_ST_PROPS_CORRECT_1);
15211 if ((WXS_IS_LIST(type) || WXS_IS_UNION(type)) &&
15212 (WXS_IS_RESTRICTION(type) == 0) &&
15213 ((! WXS_IS_ANY_SIMPLE_TYPE(baseType)) &&
15214 (baseType->type != XML_SCHEMA_TYPE_SIMPLE))) {
15215 xmlSchemaPCustomErr(ctxt,
15216 XML_SCHEMAP_ST_PROPS_CORRECT_1,
15217 WXS_BASIC_CAST type, NULL,
15218 "A type, derived by list or union, must have "
15219 "the simple ur-type definition as base type, not '%s'",
15220 xmlSchemaGetComponentQName(&str, baseType));
15222 return (XML_SCHEMAP_ST_PROPS_CORRECT_1);
15225 * Variety: One of {atomic, list, union}.
15227 if ((! WXS_IS_ATOMIC(type)) && (! WXS_IS_UNION(type)) &&
15228 (! WXS_IS_LIST(type))) {
15229 xmlSchemaPCustomErr(ctxt,
15230 XML_SCHEMAP_ST_PROPS_CORRECT_1,
15231 WXS_BASIC_CAST type, NULL,
15232 "The variety is absent", NULL);
15233 return (XML_SCHEMAP_ST_PROPS_CORRECT_1);
15235 /* TODO: Finish this. Hmm, is this finished? */
15238 * 3 The {final} of the {base type definition} must not contain restriction.
15240 if (xmlSchemaTypeFinalContains(baseType,
15241 XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) {
15242 xmlSchemaPCustomErr(ctxt,
15243 XML_SCHEMAP_ST_PROPS_CORRECT_3,
15244 WXS_BASIC_CAST type, NULL,
15245 "The 'final' of its base type '%s' must not contain "
15247 xmlSchemaGetComponentQName(&str, baseType));
15249 return (XML_SCHEMAP_ST_PROPS_CORRECT_3);
15253 * 2 All simple type definitions must be derived ultimately from the `simple
15254 * ur-type definition` (so circular definitions are disallowed). That is, it
15255 * must be possible to reach a built-in primitive datatype or the `simple
15256 * ur-type definition` by repeatedly following the {base type definition}.
15258 * NOTE: this is done in xmlSchemaCheckTypeDefCircular().
15264 * xmlSchemaCheckCOSSTRestricts:
15265 * @ctxt: the schema parser context
15266 * @type: the simple type definition
15268 * Schema Component Constraint:
15269 * Derivation Valid (Restriction, Simple) (cos-st-restricts)
15271 * Checks if the given @type (simpleType) is derived validly by restriction.
15274 * Returns -1 on internal errors, 0 if the type is validly derived,
15275 * a positive error code otherwise.
15278 xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr pctxt,
15279 xmlSchemaTypePtr type)
15281 xmlChar *str = NULL;
15283 if (type->type != XML_SCHEMA_TYPE_SIMPLE) {
15284 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15285 "given type is not a user-derived simpleType");
15289 if (WXS_IS_ATOMIC(type)) {
15290 xmlSchemaTypePtr primitive;
15292 * 1.1 The {base type definition} must be an atomic simple
15293 * type definition or a built-in primitive datatype.
15295 if (! WXS_IS_ATOMIC(type->baseType)) {
15296 xmlSchemaPCustomErr(pctxt,
15297 XML_SCHEMAP_COS_ST_RESTRICTS_1_1,
15298 WXS_BASIC_CAST type, NULL,
15299 "The base type '%s' is not an atomic simple type",
15300 xmlSchemaGetComponentQName(&str, type->baseType));
15302 return (XML_SCHEMAP_COS_ST_RESTRICTS_1_1);
15304 /* 1.2 The {final} of the {base type definition} must not contain
15307 /* OPTIMIZE TODO : This is already done in xmlSchemaCheckStPropsCorrect */
15308 if (xmlSchemaTypeFinalContains(type->baseType,
15309 XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) {
15310 xmlSchemaPCustomErr(pctxt,
15311 XML_SCHEMAP_COS_ST_RESTRICTS_1_2,
15312 WXS_BASIC_CAST type, NULL,
15313 "The final of its base type '%s' must not contain 'restriction'",
15314 xmlSchemaGetComponentQName(&str, type->baseType));
15316 return (XML_SCHEMAP_COS_ST_RESTRICTS_1_2);
15320 * 1.3.1 DF must be an allowed constraining facet for the {primitive
15321 * type definition}, as specified in the appropriate subsection of 3.2
15322 * Primitive datatypes.
15324 if (type->facets != NULL) {
15325 xmlSchemaFacetPtr facet;
15328 primitive = xmlSchemaGetPrimitiveType(type);
15329 if (primitive == NULL) {
15330 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15331 "failed to get primitive type");
15334 facet = type->facets;
15336 if (xmlSchemaIsBuiltInTypeFacet(primitive, facet->type) == 0) {
15338 xmlSchemaPIllegalFacetAtomicErr(pctxt,
15339 XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1,
15340 type, primitive, facet);
15342 facet = facet->next;
15343 } while (facet != NULL);
15345 return (XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1);
15348 * SPEC (1.3.2) "If there is a facet of the same kind in the {facets}
15349 * of the {base type definition} (call this BF),then the DF's {value}
15350 * must be a valid restriction of BF's {value} as defined in
15351 * [XML Schemas: Datatypes]."
15353 * NOTE (1.3.2) Facet derivation constraints are currently handled in
15354 * xmlSchemaDeriveAndValidateFacets()
15356 } else if (WXS_IS_LIST(type)) {
15357 xmlSchemaTypePtr itemType = NULL;
15359 itemType = type->subtypes;
15360 if ((itemType == NULL) || (! WXS_IS_SIMPLE(itemType))) {
15361 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15362 "failed to evaluate the item type");
15365 if (WXS_IS_TYPE_NOT_FIXED(itemType))
15366 xmlSchemaTypeFixup(itemType, ACTXT_CAST pctxt);
15368 * 2.1 The {item type definition} must have a {variety} of atomic or
15369 * union (in which case all the {member type definitions}
15372 if ((! WXS_IS_ATOMIC(itemType)) &&
15373 (! WXS_IS_UNION(itemType))) {
15374 xmlSchemaPCustomErr(pctxt,
15375 XML_SCHEMAP_COS_ST_RESTRICTS_2_1,
15376 WXS_BASIC_CAST type, NULL,
15377 "The item type '%s' does not have a variety of atomic or union",
15378 xmlSchemaGetComponentQName(&str, itemType));
15380 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1);
15381 } else if (WXS_IS_UNION(itemType)) {
15382 xmlSchemaTypeLinkPtr member;
15384 member = itemType->memberTypes;
15385 while (member != NULL) {
15386 if (! WXS_IS_ATOMIC(member->type)) {
15387 xmlSchemaPCustomErr(pctxt,
15388 XML_SCHEMAP_COS_ST_RESTRICTS_2_1,
15389 WXS_BASIC_CAST type, NULL,
15390 "The item type is a union type, but the "
15391 "member type '%s' of this item type is not atomic",
15392 xmlSchemaGetComponentQName(&str, member->type));
15394 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1);
15396 member = member->next;
15400 if (WXS_IS_ANY_SIMPLE_TYPE(type->baseType)) {
15401 xmlSchemaFacetPtr facet;
15403 * This is the case if we have: <simpleType><list ..
15407 * 2.3.1.1 The {final} of the {item type definition} must not
15410 if (xmlSchemaTypeFinalContains(itemType,
15411 XML_SCHEMAS_TYPE_FINAL_LIST)) {
15412 xmlSchemaPCustomErr(pctxt,
15413 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1,
15414 WXS_BASIC_CAST type, NULL,
15415 "The final of its item type '%s' must not contain 'list'",
15416 xmlSchemaGetComponentQName(&str, itemType));
15418 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1);
15421 * 2.3.1.2 The {facets} must only contain the whiteSpace
15423 * OPTIMIZE TODO: the S4S already disallows any facet
15426 if (type->facets != NULL) {
15427 facet = type->facets;
15429 if (facet->type != XML_SCHEMA_FACET_WHITESPACE) {
15430 xmlSchemaPIllegalFacetListUnionErr(pctxt,
15431 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2,
15433 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2);
15435 facet = facet->next;
15436 } while (facet != NULL);
15439 * MAYBE TODO: (Hmm, not really) Datatypes states:
15440 * A `list` datatype can be `derived` from an `atomic` datatype
15441 * whose `lexical space` allows space (such as string or anyURI)or
15442 * a `union` datatype any of whose {member type definitions}'s
15443 * `lexical space` allows space.
15447 * This is the case if we have: <simpleType><restriction ...
15448 * I.e. the variety of "list" is inherited.
15452 * 2.3.2.1 The {base type definition} must have a {variety} of list.
15454 if (! WXS_IS_LIST(type->baseType)) {
15455 xmlSchemaPCustomErr(pctxt,
15456 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1,
15457 WXS_BASIC_CAST type, NULL,
15458 "The base type '%s' must be a list type",
15459 xmlSchemaGetComponentQName(&str, type->baseType));
15461 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1);
15464 * 2.3.2.2 The {final} of the {base type definition} must not
15465 * contain restriction.
15467 if (xmlSchemaTypeFinalContains(type->baseType,
15468 XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) {
15469 xmlSchemaPCustomErr(pctxt,
15470 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2,
15471 WXS_BASIC_CAST type, NULL,
15472 "The 'final' of the base type '%s' must not contain 'restriction'",
15473 xmlSchemaGetComponentQName(&str, type->baseType));
15475 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2);
15478 * 2.3.2.3 The {item type definition} must be validly derived
15479 * from the {base type definition}'s {item type definition} given
15480 * the empty set, as defined in Type Derivation OK (Simple) ($3.14.6).
15483 xmlSchemaTypePtr baseItemType;
15485 baseItemType = type->baseType->subtypes;
15486 if ((baseItemType == NULL) || (! WXS_IS_SIMPLE(baseItemType))) {
15487 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15488 "failed to eval the item type of a base type");
15491 if ((itemType != baseItemType) &&
15492 (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt, itemType,
15493 baseItemType, 0) != 0)) {
15494 xmlChar *strBIT = NULL, *strBT = NULL;
15495 xmlSchemaPCustomErrExt(pctxt,
15496 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3,
15497 WXS_BASIC_CAST type, NULL,
15498 "The item type '%s' is not validly derived from "
15499 "the item type '%s' of the base type '%s'",
15500 xmlSchemaGetComponentQName(&str, itemType),
15501 xmlSchemaGetComponentQName(&strBIT, baseItemType),
15502 xmlSchemaGetComponentQName(&strBT, type->baseType));
15505 FREE_AND_NULL(strBIT)
15506 FREE_AND_NULL(strBT)
15507 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3);
15511 if (type->facets != NULL) {
15512 xmlSchemaFacetPtr facet;
15515 * 2.3.2.4 Only length, minLength, maxLength, whiteSpace, pattern
15516 * and enumeration facet components are allowed among the {facets}.
15518 facet = type->facets;
15520 switch (facet->type) {
15521 case XML_SCHEMA_FACET_LENGTH:
15522 case XML_SCHEMA_FACET_MINLENGTH:
15523 case XML_SCHEMA_FACET_MAXLENGTH:
15524 case XML_SCHEMA_FACET_WHITESPACE:
15526 * TODO: 2.5.1.2 List datatypes
15527 * The value of `whiteSpace` is fixed to the value collapse.
15529 case XML_SCHEMA_FACET_PATTERN:
15530 case XML_SCHEMA_FACET_ENUMERATION:
15533 xmlSchemaPIllegalFacetListUnionErr(pctxt,
15534 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4,
15537 * We could return, but it's nicer to report all
15543 facet = facet->next;
15544 } while (facet != NULL);
15546 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4);
15548 * SPEC (2.3.2.5) (same as 1.3.2)
15550 * NOTE (2.3.2.5) This is currently done in
15551 * xmlSchemaDeriveAndValidateFacets()
15555 } else if (WXS_IS_UNION(type)) {
15557 * 3.1 The {member type definitions} must all have {variety} of
15560 xmlSchemaTypeLinkPtr member;
15562 member = type->memberTypes;
15563 while (member != NULL) {
15564 if (WXS_IS_TYPE_NOT_FIXED(member->type))
15565 xmlSchemaTypeFixup(member->type, ACTXT_CAST pctxt);
15567 if ((! WXS_IS_ATOMIC(member->type)) &&
15568 (! WXS_IS_LIST(member->type))) {
15569 xmlSchemaPCustomErr(pctxt,
15570 XML_SCHEMAP_COS_ST_RESTRICTS_3_1,
15571 WXS_BASIC_CAST type, NULL,
15572 "The member type '%s' is neither an atomic, nor a list type",
15573 xmlSchemaGetComponentQName(&str, member->type));
15575 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_1);
15577 member = member->next;
15580 * 3.3.1 If the {base type definition} is the `simple ur-type
15583 if (type->baseType->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) {
15585 * 3.3.1.1 All of the {member type definitions} must have a
15586 * {final} which does not contain union.
15588 member = type->memberTypes;
15589 while (member != NULL) {
15590 if (xmlSchemaTypeFinalContains(member->type,
15591 XML_SCHEMAS_TYPE_FINAL_UNION)) {
15592 xmlSchemaPCustomErr(pctxt,
15593 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1,
15594 WXS_BASIC_CAST type, NULL,
15595 "The 'final' of member type '%s' contains 'union'",
15596 xmlSchemaGetComponentQName(&str, member->type));
15598 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1);
15600 member = member->next;
15603 * 3.3.1.2 The {facets} must be empty.
15605 if (type->facetSet != NULL) {
15606 xmlSchemaPCustomErr(pctxt,
15607 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2,
15608 WXS_BASIC_CAST type, NULL,
15609 "No facets allowed", NULL);
15610 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2);
15614 * 3.3.2.1 The {base type definition} must have a {variety} of union.
15615 * I.e. the variety of "list" is inherited.
15617 if (! WXS_IS_UNION(type->baseType)) {
15618 xmlSchemaPCustomErr(pctxt,
15619 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1,
15620 WXS_BASIC_CAST type, NULL,
15621 "The base type '%s' is not a union type",
15622 xmlSchemaGetComponentQName(&str, type->baseType));
15624 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1);
15627 * 3.3.2.2 The {final} of the {base type definition} must not contain restriction.
15629 if (xmlSchemaTypeFinalContains(type->baseType,
15630 XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) {
15631 xmlSchemaPCustomErr(pctxt,
15632 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2,
15633 WXS_BASIC_CAST type, NULL,
15634 "The 'final' of its base type '%s' must not contain 'restriction'",
15635 xmlSchemaGetComponentQName(&str, type->baseType));
15637 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2);
15640 * 3.3.2.3 The {member type definitions}, in order, must be validly
15641 * derived from the corresponding type definitions in the {base
15642 * type definition}'s {member type definitions} given the empty set,
15643 * as defined in Type Derivation OK (Simple) ($3.14.6).
15646 xmlSchemaTypeLinkPtr baseMember;
15649 * OPTIMIZE: if the type is restricting, it has no local defined
15650 * member types and inherits the member types of the base type;
15651 * thus a check for equality can be skipped.
15654 * Even worse: I cannot see a scenario where a restricting
15655 * union simple type can have other member types as the member
15656 * types of it's base type. This check seems not necessary with
15657 * respect to the derivation process in libxml2.
15658 * But necessary if constructing types with an API.
15660 if (type->memberTypes != NULL) {
15661 member = type->memberTypes;
15662 baseMember = xmlSchemaGetUnionSimpleTypeMemberTypes(type->baseType);
15663 if ((member == NULL) && (baseMember != NULL)) {
15664 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15665 "different number of member types in base");
15667 while (member != NULL) {
15668 if (baseMember == NULL) {
15669 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15670 "different number of member types in base");
15671 } else if ((member->type != baseMember->type) &&
15672 (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt,
15673 member->type, baseMember->type, 0) != 0)) {
15674 xmlChar *strBMT = NULL, *strBT = NULL;
15676 xmlSchemaPCustomErrExt(pctxt,
15677 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3,
15678 WXS_BASIC_CAST type, NULL,
15679 "The member type %s is not validly "
15680 "derived from its corresponding member "
15681 "type %s of the base type %s",
15682 xmlSchemaGetComponentQName(&str, member->type),
15683 xmlSchemaGetComponentQName(&strBMT, baseMember->type),
15684 xmlSchemaGetComponentQName(&strBT, type->baseType));
15686 FREE_AND_NULL(strBMT)
15687 FREE_AND_NULL(strBT)
15688 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3);
15690 member = member->next;
15691 if (baseMember != NULL)
15692 baseMember = baseMember->next;
15697 * 3.3.2.4 Only pattern and enumeration facet components are
15698 * allowed among the {facets}.
15700 if (type->facets != NULL) {
15701 xmlSchemaFacetPtr facet;
15704 facet = type->facets;
15706 if ((facet->type != XML_SCHEMA_FACET_PATTERN) &&
15707 (facet->type != XML_SCHEMA_FACET_ENUMERATION)) {
15708 xmlSchemaPIllegalFacetListUnionErr(pctxt,
15709 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4,
15713 facet = facet->next;
15714 } while (facet != NULL);
15716 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4);
15720 * SPEC (3.3.2.5) (same as 1.3.2)
15722 * NOTE (3.3.2.5) This is currently done in
15723 * xmlSchemaDeriveAndValidateFacets()
15732 * xmlSchemaCheckSRCSimpleType:
15733 * @ctxt: the schema parser context
15734 * @type: the simple type definition
15736 * Checks crc-simple-type constraints.
15738 * Returns 0 if the constraints are satisfied,
15739 * if not a positive error code and -1 on internal
15744 xmlSchemaCheckSRCSimpleType(xmlSchemaParserCtxtPtr ctxt,
15745 xmlSchemaTypePtr type)
15748 * src-simple-type.1 The corresponding simple type definition, if any,
15749 * must satisfy the conditions set out in Constraints on Simple Type
15750 * Definition Schema Components ($3.14.6).
15752 if (WXS_IS_RESTRICTION(type)) {
15754 * src-simple-type.2 "If the <restriction> alternative is chosen,
15755 * either it must have a base [attribute] or a <simpleType> among its
15756 * [children], but not both."
15757 * NOTE: This is checked in the parse function of <restriction>.
15762 } else if (WXS_IS_LIST(type)) {
15763 /* src-simple-type.3 "If the <list> alternative is chosen, either it must have
15764 * an itemType [attribute] or a <simpleType> among its [children],
15767 * NOTE: This is checked in the parse function of <list>.
15769 } else if (WXS_IS_UNION(type)) {
15771 * src-simple-type.4 is checked in xmlSchemaCheckUnionTypeDefCircular().
15779 xmlSchemaCreateVCtxtOnPCtxt(xmlSchemaParserCtxtPtr ctxt)
15781 if (ctxt->vctxt == NULL) {
15782 ctxt->vctxt = xmlSchemaNewValidCtxt(NULL);
15783 if (ctxt->vctxt == NULL) {
15784 xmlSchemaPErr(ctxt, NULL,
15785 XML_SCHEMAP_INTERNAL,
15786 "Internal error: xmlSchemaCreateVCtxtOnPCtxt, "
15787 "failed to create a temp. validation context.\n",
15791 /* TODO: Pass user data. */
15792 xmlSchemaSetValidErrors(ctxt->vctxt,
15793 ctxt->error, ctxt->warning, ctxt->errCtxt);
15794 xmlSchemaSetValidStructuredErrors(ctxt->vctxt,
15795 ctxt->serror, ctxt->errCtxt);
15801 xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt,
15803 xmlSchemaTypePtr type,
15804 const xmlChar *value,
15805 xmlSchemaValPtr *retVal,
15811 * xmlSchemaParseCheckCOSValidDefault:
15812 * @pctxt: the schema parser context
15813 * @type: the simple type definition
15814 * @value: the default value
15815 * @node: an optional node (the holder of the value)
15817 * Schema Component Constraint: Element Default Valid (Immediate)
15818 * (cos-valid-default)
15819 * This will be used by the parser only. For the validator there's
15820 * an other version.
15822 * Returns 0 if the constraints are satisfied,
15823 * if not, a positive error code and -1 on internal
15827 xmlSchemaParseCheckCOSValidDefault(xmlSchemaParserCtxtPtr pctxt,
15829 xmlSchemaTypePtr type,
15830 const xmlChar *value,
15831 xmlSchemaValPtr *val)
15836 * cos-valid-default:
15837 * Schema Component Constraint: Element Default Valid (Immediate)
15838 * For a string to be a valid default with respect to a type
15839 * definition the appropriate case among the following must be true:
15841 if WXS_IS_COMPLEX(type) {
15845 * SPEC (2.1) "its {content type} must be a simple type definition
15847 * SPEC (2.2.2) "If the {content type} is mixed, then the {content
15848 * type}'s particle must be `emptiable` as defined by
15849 * Particle Emptiable ($3.9.6)."
15851 if ((! WXS_HAS_SIMPLE_CONTENT(type)) &&
15852 ((! WXS_HAS_MIXED_CONTENT(type)) || (! WXS_EMPTIABLE(type)))) {
15853 /* NOTE that this covers (2.2.2) as well. */
15854 xmlSchemaPCustomErr(pctxt,
15855 XML_SCHEMAP_COS_VALID_DEFAULT_2_1,
15856 WXS_BASIC_CAST type, type->node,
15857 "For a string to be a valid default, the type definition "
15858 "must be a simple type or a complex type with mixed content "
15859 "and a particle emptiable", NULL);
15860 return(XML_SCHEMAP_COS_VALID_DEFAULT_2_1);
15864 * 1 If the type definition is a simple type definition, then the string
15865 * must be `valid` with respect to that definition as defined by String
15870 * 2.2.1 If the {content type} is a simple type definition, then the
15871 * string must be `valid` with respect to that simple type definition
15872 * as defined by String Valid ($3.14.4).
15874 if (WXS_IS_SIMPLE(type))
15875 ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt, node,
15876 type, value, val, 1, 1, 0);
15877 else if (WXS_HAS_SIMPLE_CONTENT(type))
15878 ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt, node,
15879 type->contentTypeDef, value, val, 1, 1, 0);
15884 PERROR_INT("xmlSchemaParseCheckCOSValidDefault",
15885 "calling xmlSchemaVCheckCVCSimpleType()");
15892 * xmlSchemaCheckCTPropsCorrect:
15893 * @ctxt: the schema parser context
15894 * @type: the complex type definition
15896 *.(4.6) Constraints on Complex Type Definition Schema Components
15897 * Schema Component Constraint:
15898 * Complex Type Definition Properties Correct (ct-props-correct)
15899 * STATUS: (seems) complete
15901 * Returns 0 if the constraints are satisfied, a positive
15902 * error code if not and -1 if an internal error occurred.
15905 xmlSchemaCheckCTPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
15906 xmlSchemaTypePtr type)
15909 * TODO: Correct the error code; XML_SCHEMAP_SRC_CT_1 is used temporarily.
15911 * SPEC (1) "The values of the properties of a complex type definition must
15912 * be as described in the property tableau in The Complex Type Definition
15913 * Schema Component ($3.4.1), modulo the impact of Missing
15914 * Sub-components ($5.3)."
15916 if ((type->baseType != NULL) &&
15917 (WXS_IS_SIMPLE(type->baseType)) &&
15918 (WXS_IS_EXTENSION(type) == 0)) {
15920 * SPEC (2) "If the {base type definition} is a simple type definition,
15921 * the {derivation method} must be extension."
15923 xmlSchemaCustomErr(ACTXT_CAST pctxt,
15924 XML_SCHEMAP_SRC_CT_1,
15925 NULL, WXS_BASIC_CAST type,
15926 "If the base type is a simple type, the derivation method must be "
15927 "'extension'", NULL, NULL);
15928 return (XML_SCHEMAP_SRC_CT_1);
15931 * SPEC (3) "Circular definitions are disallowed, except for the `ur-type
15932 * definition`. That is, it must be possible to reach the `ur-type
15933 * definition` by repeatedly following the {base type definition}."
15935 * NOTE (3) is done in xmlSchemaCheckTypeDefCircular().
15938 * NOTE that (4) and (5) need the following:
15939 * - attribute uses need to be already inherited (apply attr. prohibitions)
15940 * - attribute group references need to be expanded already
15941 * - simple types need to be typefixed already
15943 if (type->attrUses &&
15944 (((xmlSchemaItemListPtr) type->attrUses)->nbItems > 1))
15946 xmlSchemaItemListPtr uses = (xmlSchemaItemListPtr) type->attrUses;
15947 xmlSchemaAttributeUsePtr use, tmp;
15948 int i, j, hasId = 0;
15950 for (i = uses->nbItems -1; i >= 0; i--) {
15951 use = uses->items[i];
15954 * SPEC ct-props-correct
15955 * (4) "Two distinct attribute declarations in the
15956 * {attribute uses} must not have identical {name}s and
15957 * {target namespace}s."
15960 for (j = i -1; j >= 0; j--) {
15961 tmp = uses->items[j];
15962 if ((WXS_ATTRUSE_DECL_NAME(use) ==
15963 WXS_ATTRUSE_DECL_NAME(tmp)) &&
15964 (WXS_ATTRUSE_DECL_TNS(use) ==
15965 WXS_ATTRUSE_DECL_TNS(tmp)))
15967 xmlChar *str = NULL;
15969 xmlSchemaCustomErr(ACTXT_CAST pctxt,
15970 XML_SCHEMAP_AG_PROPS_CORRECT,
15971 NULL, WXS_BASIC_CAST type,
15973 xmlSchemaGetComponentDesignation(&str, use),
15975 FREE_AND_NULL(str);
15977 * Remove the duplicate.
15979 if (xmlSchemaItemListRemove(uses, i) == -1)
15986 * SPEC ct-props-correct
15987 * (5) "Two distinct attribute declarations in the
15988 * {attribute uses} must not have {type definition}s which
15989 * are or are derived from ID."
15991 if (WXS_ATTRUSE_TYPEDEF(use) != NULL) {
15992 if (xmlSchemaIsDerivedFromBuiltInType(
15993 WXS_ATTRUSE_TYPEDEF(use), XML_SCHEMAS_ID))
15996 xmlChar *str = NULL;
15998 xmlSchemaCustomErr(ACTXT_CAST pctxt,
15999 XML_SCHEMAP_AG_PROPS_CORRECT,
16000 NULL, WXS_BASIC_CAST type,
16001 "There must not exist more than one attribute "
16002 "declaration of type 'xs:ID' "
16003 "(or derived from 'xs:ID'). The %s violates this "
16005 xmlSchemaGetComponentDesignation(&str, use),
16007 FREE_AND_NULL(str);
16008 if (xmlSchemaItemListRemove(uses, i) == -1)
16024 xmlSchemaAreEqualTypes(xmlSchemaTypePtr typeA,
16025 xmlSchemaTypePtr typeB)
16028 * TODO: This should implement component-identity
16031 if ((typeA == NULL) || (typeB == NULL))
16033 return (typeA == typeB);
16037 * xmlSchemaCheckCOSCTDerivedOK:
16038 * @ctxt: the schema parser context
16039 * @type: the to-be derived complex type definition
16040 * @baseType: the base complex type definition
16041 * @set: the given set
16043 * Schema Component Constraint:
16044 * Type Derivation OK (Complex) (cos-ct-derived-ok)
16046 * STATUS: completed
16048 * Returns 0 if the constraints are satisfied, or 1
16052 xmlSchemaCheckCOSCTDerivedOK(xmlSchemaAbstractCtxtPtr actxt,
16053 xmlSchemaTypePtr type,
16054 xmlSchemaTypePtr baseType,
16057 int equal = xmlSchemaAreEqualTypes(type, baseType);
16058 /* TODO: Error codes. */
16060 * SPEC "For a complex type definition (call it D, for derived)
16061 * to be validly derived from a type definition (call this
16062 * B, for base) given a subset of {extension, restriction}
16063 * all of the following must be true:"
16067 * SPEC (1) "If B and D are not the same type definition, then the
16068 * {derivation method} of D must not be in the subset."
16070 if (((set & SUBSET_EXTENSION) && (WXS_IS_EXTENSION(type))) ||
16071 ((set & SUBSET_RESTRICTION) && (WXS_IS_RESTRICTION(type))))
16075 * SPEC (2.1) "B and D must be the same type definition."
16080 * SPEC (2.2) "B must be D's {base type definition}."
16082 if (type->baseType == baseType)
16085 * SPEC (2.3.1) "D's {base type definition} must not be the `ur-type
16088 if (WXS_IS_ANYTYPE(type->baseType))
16091 if (WXS_IS_COMPLEX(type->baseType)) {
16093 * SPEC (2.3.2.1) "If D's {base type definition} is complex, then it
16094 * must be validly derived from B given the subset as defined by this
16097 return (xmlSchemaCheckCOSCTDerivedOK(actxt, type->baseType,
16101 * SPEC (2.3.2.2) "If D's {base type definition} is simple, then it
16102 * must be validly derived from B given the subset as defined in Type
16103 * Derivation OK (Simple) ($3.14.6).
16105 return (xmlSchemaCheckCOSSTDerivedOK(actxt, type->baseType,
16111 * xmlSchemaCheckCOSDerivedOK:
16112 * @type: the derived simple type definition
16113 * @baseType: the base type definition
16116 * Type Derivation OK (Simple) AND Type Derivation OK (Complex)
16118 * Checks wheter @type can be validly derived from @baseType.
16120 * Returns 0 on success, an positive error code otherwise.
16123 xmlSchemaCheckCOSDerivedOK(xmlSchemaAbstractCtxtPtr actxt,
16124 xmlSchemaTypePtr type,
16125 xmlSchemaTypePtr baseType,
16128 if (WXS_IS_SIMPLE(type))
16129 return (xmlSchemaCheckCOSSTDerivedOK(actxt, type, baseType, set));
16131 return (xmlSchemaCheckCOSCTDerivedOK(actxt, type, baseType, set));
16135 * xmlSchemaCheckCOSCTExtends:
16136 * @ctxt: the schema parser context
16137 * @type: the complex type definition
16139 * (3.4.6) Constraints on Complex Type Definition Schema Components
16140 * Schema Component Constraint:
16141 * Derivation Valid (Extension) (cos-ct-extends)
16146 * (1.4.3.2.2.2) "Particle Valid (Extension)"
16148 * Returns 0 if the constraints are satisfied, a positive
16149 * error code if not and -1 if an internal error occurred.
16152 xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt,
16153 xmlSchemaTypePtr type)
16155 xmlSchemaTypePtr base = type->baseType;
16157 * TODO: Correct the error code; XML_SCHEMAP_COS_CT_EXTENDS_1_1 is used
16158 * temporarily only.
16161 * SPEC (1) "If the {base type definition} is a complex type definition,
16162 * then all of the following must be true:"
16164 if (WXS_IS_COMPLEX(base)) {
16166 * SPEC (1.1) "The {final} of the {base type definition} must not
16167 * contain extension."
16169 if (base->flags & XML_SCHEMAS_TYPE_FINAL_EXTENSION) {
16170 xmlSchemaPCustomErr(ctxt,
16171 XML_SCHEMAP_COS_CT_EXTENDS_1_1,
16172 WXS_BASIC_CAST type, NULL,
16173 "The 'final' of the base type definition "
16174 "contains 'extension'", NULL);
16175 return (XML_SCHEMAP_COS_CT_EXTENDS_1_1);
16179 * ATTENTION: The constrains (1.2) and (1.3) are not applied,
16180 * since they are automatically satisfied through the
16181 * inheriting mechanism.
16182 * Note that even if redefining components, the inheriting mechanism
16187 * SPEC (1.2) "Its {attribute uses} must be a subset of the {attribute
16189 * of the complex type definition itself, that is, for every attribute
16190 * use in the {attribute uses} of the {base type definition}, there
16191 * must be an attribute use in the {attribute uses} of the complex
16192 * type definition itself whose {attribute declaration} has the same
16193 * {name}, {target namespace} and {type definition} as its attribute
16196 if (base->attrUses != NULL) {
16198 xmlSchemaAttributeUsePtr use, buse;
16200 for (i = 0; i < (WXS_LIST_CAST base->attrUses)->nbItems; i ++) {
16201 buse = (WXS_LIST_CAST base->attrUses)->items[i];
16203 if (type->attrUses != NULL) {
16204 use = (WXS_LIST_CAST type->attrUses)->items[j];
16205 for (j = 0; j < (WXS_LIST_CAST type->attrUses)->nbItems; j ++)
16207 if ((WXS_ATTRUSE_DECL_NAME(use) ==
16208 WXS_ATTRUSE_DECL_NAME(buse)) &&
16209 (WXS_ATTRUSE_DECL_TNS(use) ==
16210 WXS_ATTRUSE_DECL_TNS(buse)) &&
16211 (WXS_ATTRUSE_TYPEDEF(use) ==
16212 WXS_ATTRUSE_TYPEDEF(buse))
16220 xmlChar *str = NULL;
16222 xmlSchemaCustomErr(ACTXT_CAST ctxt,
16223 XML_SCHEMAP_COS_CT_EXTENDS_1_2,
16224 NULL, WXS_BASIC_CAST type,
16226 * TODO: The report does not indicate that also the
16227 * type needs to be the same.
16229 "This type is missing a matching correspondent "
16230 "for its {base type}'s %s in its {attribute uses}",
16231 xmlSchemaGetComponentDesignation(&str,
16239 * SPEC (1.3) "If it has an {attribute wildcard}, the complex type
16240 * definition must also have one, and the base type definition's
16241 * {attribute wildcard}'s {namespace constraint} must be a subset
16242 * of the complex type definition's {attribute wildcard}'s {namespace
16243 * constraint}, as defined by Wildcard Subset ($3.10.6)."
16247 * MAYBE TODO: Enable if ever needed. But this will be needed only
16248 * if created the type via a schema construction API.
16250 if (base->attributeWildcard != NULL) {
16251 if (type->attributeWilcard == NULL) {
16252 xmlChar *str = NULL;
16254 xmlSchemaCustomErr(ACTXT_CAST pctxt,
16255 XML_SCHEMAP_COS_CT_EXTENDS_1_3,
16257 "The base %s has an attribute wildcard, "
16258 "but this type is missing an attribute wildcard",
16259 xmlSchemaGetComponentDesignation(&str, base));
16262 } else if (xmlSchemaCheckCOSNSSubset(
16263 base->attributeWildcard, type->attributeWildcard))
16265 xmlChar *str = NULL;
16267 xmlSchemaCustomErr(ACTXT_CAST pctxt,
16268 XML_SCHEMAP_COS_CT_EXTENDS_1_3,
16270 "The attribute wildcard is not a valid "
16271 "superset of the one in the base %s",
16272 xmlSchemaGetComponentDesignation(&str, base));
16278 * SPEC (1.4) "One of the following must be true:"
16280 if ((type->contentTypeDef != NULL) &&
16281 (type->contentTypeDef == base->contentTypeDef)) {
16283 * SPEC (1.4.1) "The {content type} of the {base type definition}
16284 * and the {content type} of the complex type definition itself
16285 * must be the same simple type definition"
16288 } else if ((type->contentType == XML_SCHEMA_CONTENT_EMPTY) &&
16289 (base->contentType == XML_SCHEMA_CONTENT_EMPTY) ) {
16291 * SPEC (1.4.2) "The {content type} of both the {base type
16292 * definition} and the complex type definition itself must
16298 * SPEC (1.4.3) "All of the following must be true:"
16300 if (type->subtypes == NULL) {
16302 * SPEC 1.4.3.1 The {content type} of the complex type
16303 * definition itself must specify a particle.
16305 xmlSchemaPCustomErr(ctxt,
16306 XML_SCHEMAP_COS_CT_EXTENDS_1_1,
16307 WXS_BASIC_CAST type, NULL,
16308 "The content type must specify a particle", NULL);
16309 return (XML_SCHEMAP_COS_CT_EXTENDS_1_1);
16312 * SPEC (1.4.3.2) "One of the following must be true:"
16314 if (base->contentType == XML_SCHEMA_CONTENT_EMPTY) {
16316 * SPEC (1.4.3.2.1) "The {content type} of the {base type
16317 * definition} must be empty.
16322 * SPEC (1.4.3.2.2) "All of the following must be true:"
16324 if ((type->contentType != base->contentType) ||
16325 ((type->contentType != XML_SCHEMA_CONTENT_MIXED) &&
16326 (type->contentType != XML_SCHEMA_CONTENT_ELEMENTS))) {
16328 * SPEC (1.4.3.2.2.1) "Both {content type}s must be mixed
16329 * or both must be element-only."
16331 xmlSchemaPCustomErr(ctxt,
16332 XML_SCHEMAP_COS_CT_EXTENDS_1_1,
16333 WXS_BASIC_CAST type, NULL,
16334 "The content type of both, the type and its base "
16335 "type, must either 'mixed' or 'element-only'", NULL);
16336 return (XML_SCHEMAP_COS_CT_EXTENDS_1_1);
16339 * URGENT TODO SPEC (1.4.3.2.2.2) "The particle of the
16340 * complex type definition must be a `valid extension`
16341 * of the {base type definition}'s particle, as defined
16342 * in Particle Valid (Extension) ($3.9.6)."
16344 * NOTE that we won't check "Particle Valid (Extension)",
16345 * since it is ensured by the derivation process in
16346 * xmlSchemaTypeFixup(). We need to implement this when heading
16347 * for a construction API
16348 * TODO: !! This is needed to be checked if redefining a type !!
16352 * URGENT TODO (1.5)
16357 * SPEC (2) "If the {base type definition} is a simple type definition,
16358 * then all of the following must be true:"
16360 if (type->contentTypeDef != base) {
16362 * SPEC (2.1) "The {content type} must be the same simple type
16365 xmlSchemaPCustomErr(ctxt,
16366 XML_SCHEMAP_COS_CT_EXTENDS_1_1,
16367 WXS_BASIC_CAST type, NULL,
16368 "The content type must be the simple base type", NULL);
16369 return (XML_SCHEMAP_COS_CT_EXTENDS_1_1);
16371 if (base->flags & XML_SCHEMAS_TYPE_FINAL_EXTENSION) {
16373 * SPEC (2.2) "The {final} of the {base type definition} must not
16374 * contain extension"
16375 * NOTE that this is the same as (1.1).
16377 xmlSchemaPCustomErr(ctxt,
16378 XML_SCHEMAP_COS_CT_EXTENDS_1_1,
16379 WXS_BASIC_CAST type, NULL,
16380 "The 'final' of the base type definition "
16381 "contains 'extension'", NULL);
16382 return (XML_SCHEMAP_COS_CT_EXTENDS_1_1);
16389 * xmlSchemaCheckDerivationOKRestriction:
16390 * @ctxt: the schema parser context
16391 * @type: the complex type definition
16393 * (3.4.6) Constraints on Complex Type Definition Schema Components
16394 * Schema Component Constraint:
16395 * Derivation Valid (Restriction, Complex) (derivation-ok-restriction)
16402 * In XML Schema 1.1 this will be:
16403 * Validation Rule: Checking complex type subsumption
16405 * Returns 0 if the constraints are satisfied, a positive
16406 * error code if not and -1 if an internal error occurred.
16409 xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt,
16410 xmlSchemaTypePtr type)
16412 xmlSchemaTypePtr base;
16415 * TODO: Correct the error code; XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1 is used
16416 * temporarily only.
16418 base = type->baseType;
16419 if (! WXS_IS_COMPLEX(base)) {
16420 xmlSchemaCustomErr(ACTXT_CAST ctxt,
16421 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
16422 type->node, WXS_BASIC_CAST type,
16423 "The base type must be a complex type", NULL, NULL);
16426 if (base->flags & XML_SCHEMAS_TYPE_FINAL_RESTRICTION) {
16428 * SPEC (1) "The {base type definition} must be a complex type
16429 * definition whose {final} does not contain restriction."
16431 xmlSchemaCustomErr(ACTXT_CAST ctxt,
16432 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
16433 type->node, WXS_BASIC_CAST type,
16434 "The 'final' of the base type definition "
16435 "contains 'restriction'", NULL, NULL);
16436 return (ctxt->err);
16439 * SPEC (2), (3) and (4)
16440 * Those are handled in a separate function, since the
16441 * same constraints are needed for redefinition of
16442 * attribute groups as well.
16444 if (xmlSchemaCheckDerivationOKRestriction2to4(ctxt,
16445 XML_SCHEMA_ACTION_DERIVE,
16446 WXS_BASIC_CAST type, WXS_BASIC_CAST base,
16447 type->attrUses, base->attrUses,
16448 type->attributeWildcard,
16449 base->attributeWildcard) == -1)
16454 * SPEC (5) "One of the following must be true:"
16456 if (base->builtInType == XML_SCHEMAS_ANYTYPE) {
16458 * SPEC (5.1) "The {base type definition} must be the
16459 * `ur-type definition`."
16462 } else if ((type->contentType == XML_SCHEMA_CONTENT_SIMPLE) ||
16463 (type->contentType == XML_SCHEMA_CONTENT_BASIC)) {
16465 * SPEC (5.2.1) "The {content type} of the complex type definition
16466 * must be a simple type definition"
16468 * SPEC (5.2.2) "One of the following must be true:"
16470 if ((base->contentType == XML_SCHEMA_CONTENT_SIMPLE) ||
16471 (base->contentType == XML_SCHEMA_CONTENT_BASIC))
16475 * SPEC (5.2.2.1) "The {content type} of the {base type
16476 * definition} must be a simple type definition from which
16477 * the {content type} is validly derived given the empty
16478 * set as defined in Type Derivation OK (Simple) ($3.14.6)."
16480 * ATTENTION TODO: This seems not needed if the type implicitely
16481 * derived from the base type.
16484 err = xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST ctxt,
16485 type->contentTypeDef, base->contentTypeDef, 0);
16487 xmlChar *strA = NULL, *strB = NULL;
16491 xmlSchemaCustomErr(ACTXT_CAST ctxt,
16492 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
16493 NULL, WXS_BASIC_CAST type,
16494 "The {content type} %s is not validly derived from the "
16495 "base type's {content type} %s",
16496 xmlSchemaGetComponentDesignation(&strA,
16497 type->contentTypeDef),
16498 xmlSchemaGetComponentDesignation(&strB,
16499 base->contentTypeDef));
16500 FREE_AND_NULL(strA);
16501 FREE_AND_NULL(strB);
16504 } else if ((base->contentType == XML_SCHEMA_CONTENT_MIXED) &&
16505 (xmlSchemaIsParticleEmptiable(
16506 (xmlSchemaParticlePtr) base->subtypes))) {
16508 * SPEC (5.2.2.2) "The {base type definition} must be mixed
16509 * and have a particle which is `emptiable` as defined in
16510 * Particle Emptiable ($3.9.6)."
16514 xmlSchemaPCustomErr(ctxt,
16515 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
16516 WXS_BASIC_CAST type, NULL,
16517 "The content type of the base type must be either "
16518 "a simple type or 'mixed' and an emptiable particle", NULL);
16519 return (ctxt->err);
16521 } else if (type->contentType == XML_SCHEMA_CONTENT_EMPTY) {
16523 * SPEC (5.3.1) "The {content type} of the complex type itself must
16526 if (base->contentType == XML_SCHEMA_CONTENT_EMPTY) {
16528 * SPEC (5.3.2.1) "The {content type} of the {base type
16529 * definition} must also be empty."
16532 } else if (((base->contentType == XML_SCHEMA_CONTENT_ELEMENTS) ||
16533 (base->contentType == XML_SCHEMA_CONTENT_MIXED)) &&
16534 xmlSchemaIsParticleEmptiable(
16535 (xmlSchemaParticlePtr) base->subtypes)) {
16537 * SPEC (5.3.2.2) "The {content type} of the {base type
16538 * definition} must be elementOnly or mixed and have a particle
16539 * which is `emptiable` as defined in Particle Emptiable ($3.9.6)."
16543 xmlSchemaPCustomErr(ctxt,
16544 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
16545 WXS_BASIC_CAST type, NULL,
16546 "The content type of the base type must be either "
16547 "empty or 'mixed' (or 'elements-only') and an emptiable "
16549 return (ctxt->err);
16551 } else if ((type->contentType == XML_SCHEMA_CONTENT_ELEMENTS) ||
16552 WXS_HAS_MIXED_CONTENT(type)) {
16554 * SPEC (5.4.1.1) "The {content type} of the complex type definition
16555 * itself must be element-only"
16557 if (WXS_HAS_MIXED_CONTENT(type) && (! WXS_HAS_MIXED_CONTENT(base))) {
16559 * SPEC (5.4.1.2) "The {content type} of the complex type
16560 * definition itself and of the {base type definition} must be
16563 xmlSchemaPCustomErr(ctxt,
16564 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
16565 WXS_BASIC_CAST type, NULL,
16566 "If the content type is 'mixed', then the content type of the "
16567 "base type must also be 'mixed'", NULL);
16568 return (ctxt->err);
16571 * SPEC (5.4.2) "The particle of the complex type definition itself
16572 * must be a `valid restriction` of the particle of the {content
16573 * type} of the {base type definition} as defined in Particle Valid
16574 * (Restriction) ($3.9.6).
16576 * URGENT TODO: (5.4.2)
16579 xmlSchemaPCustomErr(ctxt,
16580 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
16581 WXS_BASIC_CAST type, NULL,
16582 "The type is not a valid restriction of its base type", NULL);
16583 return (ctxt->err);
16589 * xmlSchemaCheckCTComponent:
16590 * @ctxt: the schema parser context
16591 * @type: the complex type definition
16593 * (3.4.6) Constraints on Complex Type Definition Schema Components
16595 * Returns 0 if the constraints are satisfied, a positive
16596 * error code if not and -1 if an internal error occurred.
16599 xmlSchemaCheckCTComponent(xmlSchemaParserCtxtPtr ctxt,
16600 xmlSchemaTypePtr type)
16604 * Complex Type Definition Properties Correct
16606 ret = xmlSchemaCheckCTPropsCorrect(ctxt, type);
16609 if (WXS_IS_EXTENSION(type))
16610 ret = xmlSchemaCheckCOSCTExtends(ctxt, type);
16612 ret = xmlSchemaCheckDerivationOKRestriction(ctxt, type);
16617 * xmlSchemaCheckSRCCT:
16618 * @ctxt: the schema parser context
16619 * @type: the complex type definition
16621 * (3.4.3) Constraints on XML Representations of Complex Type Definitions:
16622 * Schema Representation Constraint:
16623 * Complex Type Definition Representation OK (src-ct)
16625 * Returns 0 if the constraints are satisfied, a positive
16626 * error code if not and -1 if an internal error occurred.
16629 xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt,
16630 xmlSchemaTypePtr type)
16632 xmlSchemaTypePtr base;
16636 * TODO: Adjust the error codes here, as I used
16637 * XML_SCHEMAP_SRC_CT_1 only yet.
16639 base = type->baseType;
16640 if (! WXS_HAS_SIMPLE_CONTENT(type)) {
16642 * 1 If the <complexContent> alternative is chosen, the type definition
16643 * `resolved` to by the `actual value` of the base [attribute]
16644 * must be a complex type definition;
16646 if (! WXS_IS_COMPLEX(base)) {
16647 xmlChar *str = NULL;
16648 xmlSchemaPCustomErr(ctxt,
16649 XML_SCHEMAP_SRC_CT_1,
16650 WXS_BASIC_CAST type, type->node,
16651 "If using <complexContent>, the base type is expected to be "
16652 "a complex type. The base type '%s' is a simple type",
16653 xmlSchemaFormatQName(&str, base->targetNamespace,
16656 return (XML_SCHEMAP_SRC_CT_1);
16661 * 2 If the <simpleContent> alternative is chosen, all of the
16662 * following must be true:
16663 * 2.1 The type definition `resolved` to by the `actual value` of the
16664 * base [attribute] must be one of the following:
16666 if (WXS_IS_SIMPLE(base)) {
16667 if (WXS_IS_EXTENSION(type) == 0) {
16668 xmlChar *str = NULL;
16670 * 2.1.3 only if the <extension> alternative is also
16671 * chosen, a simple type definition.
16673 /* TODO: Change error code to ..._SRC_CT_2_1_3. */
16674 xmlSchemaPCustomErr(ctxt,
16675 XML_SCHEMAP_SRC_CT_1,
16676 WXS_BASIC_CAST type, NULL,
16677 "If using <simpleContent> and <restriction>, the base "
16678 "type must be a complex type. The base type '%s' is "
16680 xmlSchemaFormatQName(&str, base->targetNamespace,
16683 return (XML_SCHEMAP_SRC_CT_1);
16686 /* Base type is a complex type. */
16687 if ((base->contentType == XML_SCHEMA_CONTENT_SIMPLE) ||
16688 (base->contentType == XML_SCHEMA_CONTENT_BASIC)) {
16690 * 2.1.1 a complex type definition whose {content type} is a
16691 * simple type definition;
16694 if (base->contentTypeDef == NULL) {
16695 xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL,
16696 WXS_BASIC_CAST type, NULL,
16697 "Internal error: xmlSchemaCheckSRCCT, "
16698 "'%s', base type has no content type",
16702 } else if ((base->contentType == XML_SCHEMA_CONTENT_MIXED) &&
16703 (WXS_IS_RESTRICTION(type))) {
16706 * 2.1.2 only if the <restriction> alternative is also
16707 * chosen, a complex type definition whose {content type}
16708 * is mixed and a particle emptiable.
16710 if (! xmlSchemaIsParticleEmptiable(
16711 (xmlSchemaParticlePtr) base->subtypes)) {
16712 ret = XML_SCHEMAP_SRC_CT_1;
16715 * Attention: at this point the <simpleType> child is in
16716 * ->contentTypeDef (put there during parsing).
16718 if (type->contentTypeDef == NULL) {
16719 xmlChar *str = NULL;
16721 * 2.2 If clause 2.1.2 above is satisfied, then there
16722 * must be a <simpleType> among the [children] of
16725 /* TODO: Change error code to ..._SRC_CT_2_2. */
16726 xmlSchemaPCustomErr(ctxt,
16727 XML_SCHEMAP_SRC_CT_1,
16728 WXS_BASIC_CAST type, NULL,
16729 "A <simpleType> is expected among the children "
16730 "of <restriction>, if <simpleContent> is used and "
16731 "the base type '%s' is a complex type",
16732 xmlSchemaFormatQName(&str, base->targetNamespace,
16735 return (XML_SCHEMAP_SRC_CT_1);
16738 ret = XML_SCHEMAP_SRC_CT_1;
16742 xmlChar *str = NULL;
16743 if (WXS_IS_RESTRICTION(type)) {
16744 xmlSchemaPCustomErr(ctxt,
16745 XML_SCHEMAP_SRC_CT_1,
16746 WXS_BASIC_CAST type, NULL,
16747 "If <simpleContent> and <restriction> is used, the "
16748 "base type must be a simple type or a complex type with "
16749 "mixed content and particle emptiable. The base type "
16750 "'%s' is none of those",
16751 xmlSchemaFormatQName(&str, base->targetNamespace,
16754 xmlSchemaPCustomErr(ctxt,
16755 XML_SCHEMAP_SRC_CT_1,
16756 WXS_BASIC_CAST type, NULL,
16757 "If <simpleContent> and <extension> is used, the "
16758 "base type must be a simple type. The base type '%s' "
16759 "is a complex type",
16760 xmlSchemaFormatQName(&str, base->targetNamespace,
16767 * SPEC (3) "The corresponding complex type definition component must
16768 * satisfy the conditions set out in Constraints on Complex Type
16769 * Definition Schema Components ($3.4.6);"
16770 * NOTE (3) will be done in xmlSchemaTypeFixup().
16773 * SPEC (4) If clause 2.2.1 or clause 2.2.2 in the correspondence specification
16774 * above for {attribute wildcard} is satisfied, the intensional
16775 * intersection must be expressible, as defined in Attribute Wildcard
16776 * Intersection ($3.10.6).
16777 * NOTE (4) is done in xmlSchemaFixupTypeAttributeUses().
16782 #ifdef ENABLE_PARTICLE_RESTRICTION
16784 * xmlSchemaCheckParticleRangeOK:
16785 * @ctxt: the schema parser context
16786 * @type: the complex type definition
16788 * (3.9.6) Constraints on Particle Schema Components
16789 * Schema Component Constraint:
16790 * Occurrence Range OK (range-ok)
16794 * Returns 0 if the constraints are satisfied, a positive
16795 * error code if not and -1 if an internal error occurred.
16798 xmlSchemaCheckParticleRangeOK(int rmin, int rmax,
16799 int bmin, int bmax)
16803 if ((bmax != UNBOUNDED) &&
16810 * xmlSchemaCheckRCaseNameAndTypeOK:
16811 * @ctxt: the schema parser context
16812 * @r: the restricting element declaration particle
16813 * @b: the base element declaration particle
16815 * (3.9.6) Constraints on Particle Schema Components
16816 * Schema Component Constraint:
16817 * Particle Restriction OK (Elt:Elt -- NameAndTypeOK)
16818 * (rcase-NameAndTypeOK)
16824 * Returns 0 if the constraints are satisfied, a positive
16825 * error code if not and -1 if an internal error occurred.
16828 xmlSchemaCheckRCaseNameAndTypeOK(xmlSchemaParserCtxtPtr ctxt,
16829 xmlSchemaParticlePtr r,
16830 xmlSchemaParticlePtr b)
16832 xmlSchemaElementPtr elemR, elemB;
16834 /* TODO: Error codes (rcase-NameAndTypeOK). */
16835 elemR = (xmlSchemaElementPtr) r->children;
16836 elemB = (xmlSchemaElementPtr) b->children;
16838 * SPEC (1) "The declarations' {name}s and {target namespace}s are
16841 if ((elemR != elemB) &&
16842 ((! xmlStrEqual(elemR->name, elemB->name)) ||
16843 (! xmlStrEqual(elemR->targetNamespace, elemB->targetNamespace))))
16846 * SPEC (2) "R's occurrence range is a valid restriction of B's
16847 * occurrence range as defined by Occurrence Range OK ($3.9.6)."
16849 if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs,
16850 b->minOccurs, b->maxOccurs) != 0)
16853 * SPEC (3.1) "Both B's declaration's {scope} and R's declaration's
16854 * {scope} are global."
16856 if (elemR == elemB)
16859 * SPEC (3.2.1) "Either B's {nillable} is true or R's {nillable} is false."
16861 if (((elemB->flags & XML_SCHEMAS_ELEM_NILLABLE) == 0) &&
16862 (elemR->flags & XML_SCHEMAS_ELEM_NILLABLE))
16865 * SPEC (3.2.2) "either B's declaration's {value constraint} is absent,
16866 * or is not fixed, or R's declaration's {value constraint} is fixed
16867 * with the same value."
16869 if ((elemB->value != NULL) && (elemB->flags & XML_SCHEMAS_ELEM_FIXED) &&
16870 ((elemR->value == NULL) ||
16871 ((elemR->flags & XML_SCHEMAS_ELEM_FIXED) == 0) ||
16872 /* TODO: Equality of the initial value or normalized or canonical? */
16873 (! xmlStrEqual(elemR->value, elemB->value))))
16876 * TODO: SPEC (3.2.3) "R's declaration's {identity-constraint
16877 * definitions} is a subset of B's declaration's {identity-constraint
16878 * definitions}, if any."
16880 if (elemB->idcs != NULL) {
16884 * SPEC (3.2.4) "R's declaration's {disallowed substitutions} is a
16885 * superset of B's declaration's {disallowed substitutions}."
16887 if (((elemB->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) &&
16888 ((elemR->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) == 0)) ||
16889 ((elemB->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) &&
16890 ((elemR->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) == 0)) ||
16891 ((elemB->flags & XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION) &&
16892 ((elemR->flags & XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION) == 0)))
16895 * SPEC (3.2.5) "R's {type definition} is validly derived given
16896 * {extension, list, union} from B's {type definition}"
16898 * BADSPEC TODO: What's the point of adding "list" and "union" to the
16899 * set, if the corresponding constraints handle "restriction" and
16900 * "extension" only?
16906 set |= SUBSET_EXTENSION;
16907 set |= SUBSET_LIST;
16908 set |= SUBSET_UNION;
16909 if (xmlSchemaCheckCOSDerivedOK(ACTXT_CAST ctxt, elemR->subtypes,
16910 elemB->subtypes, set) != 0)
16917 * xmlSchemaCheckRCaseNSCompat:
16918 * @ctxt: the schema parser context
16919 * @r: the restricting element declaration particle
16920 * @b: the base wildcard particle
16922 * (3.9.6) Constraints on Particle Schema Components
16923 * Schema Component Constraint:
16924 * Particle Derivation OK (Elt:Any -- NSCompat)
16929 * Returns 0 if the constraints are satisfied, a positive
16930 * error code if not and -1 if an internal error occurred.
16933 xmlSchemaCheckRCaseNSCompat(xmlSchemaParserCtxtPtr ctxt,
16934 xmlSchemaParticlePtr r,
16935 xmlSchemaParticlePtr b)
16937 /* TODO:Error codes (rcase-NSCompat). */
16939 * SPEC "For an element declaration particle to be a `valid restriction`
16940 * of a wildcard particle all of the following must be true:"
16942 * SPEC (1) "The element declaration's {target namespace} is `valid`
16943 * with respect to the wildcard's {namespace constraint} as defined by
16944 * Wildcard allows Namespace Name ($3.10.4)."
16946 if (xmlSchemaCheckCVCWildcardNamespace((xmlSchemaWildcardPtr) b->children,
16947 ((xmlSchemaElementPtr) r->children)->targetNamespace) != 0)
16950 * SPEC (2) "R's occurrence range is a valid restriction of B's
16951 * occurrence range as defined by Occurrence Range OK ($3.9.6)."
16953 if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs,
16954 b->minOccurs, b->maxOccurs) != 0)
16961 * xmlSchemaCheckRCaseRecurseAsIfGroup:
16962 * @ctxt: the schema parser context
16963 * @r: the restricting element declaration particle
16964 * @b: the base model group particle
16966 * (3.9.6) Constraints on Particle Schema Components
16967 * Schema Component Constraint:
16968 * Particle Derivation OK (Elt:All/Choice/Sequence -- RecurseAsIfGroup)
16969 * (rcase-RecurseAsIfGroup)
16973 * Returns 0 if the constraints are satisfied, a positive
16974 * error code if not and -1 if an internal error occurred.
16977 xmlSchemaCheckRCaseRecurseAsIfGroup(xmlSchemaParserCtxtPtr ctxt,
16978 xmlSchemaParticlePtr r,
16979 xmlSchemaParticlePtr b)
16981 /* TODO: Error codes (rcase-RecurseAsIfGroup). */
16987 * xmlSchemaCheckRCaseNSSubset:
16988 * @ctxt: the schema parser context
16989 * @r: the restricting wildcard particle
16990 * @b: the base wildcard particle
16992 * (3.9.6) Constraints on Particle Schema Components
16993 * Schema Component Constraint:
16994 * Particle Derivation OK (Any:Any -- NSSubset)
16999 * Returns 0 if the constraints are satisfied, a positive
17000 * error code if not and -1 if an internal error occurred.
17003 xmlSchemaCheckRCaseNSSubset(xmlSchemaParserCtxtPtr ctxt,
17004 xmlSchemaParticlePtr r,
17005 xmlSchemaParticlePtr b,
17008 /* TODO: Error codes (rcase-NSSubset). */
17010 * SPEC (1) "R's occurrence range is a valid restriction of B's
17011 * occurrence range as defined by Occurrence Range OK ($3.9.6)."
17013 if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs,
17014 b->minOccurs, b->maxOccurs))
17017 * SPEC (2) "R's {namespace constraint} must be an intensional subset
17018 * of B's {namespace constraint} as defined by Wildcard Subset ($3.10.6)."
17020 if (xmlSchemaCheckCOSNSSubset((xmlSchemaWildcardPtr) r->children,
17021 (xmlSchemaWildcardPtr) b->children))
17024 * SPEC (3) "Unless B is the content model wildcard of the `ur-type
17025 * definition`, R's {process contents} must be identical to or stronger
17026 * than B's {process contents}, where strict is stronger than lax is
17027 * stronger than skip."
17029 if (! isAnyTypeBase) {
17030 if ( ((xmlSchemaWildcardPtr) r->children)->processContents <
17031 ((xmlSchemaWildcardPtr) b->children)->processContents)
17039 * xmlSchemaCheckCOSParticleRestrict:
17040 * @ctxt: the schema parser context
17041 * @type: the complex type definition
17043 * (3.9.6) Constraints on Particle Schema Components
17044 * Schema Component Constraint:
17045 * Particle Valid (Restriction) (cos-particle-restrict)
17049 * Returns 0 if the constraints are satisfied, a positive
17050 * error code if not and -1 if an internal error occurred.
17053 xmlSchemaCheckCOSParticleRestrict(xmlSchemaParserCtxtPtr ctxt,
17054 xmlSchemaParticlePtr r,
17055 xmlSchemaParticlePtr b)
17059 /*part = WXS_TYPE_PARTICLE(type);
17060 basePart = WXS_TYPE_PARTICLE(base);
17066 * SPEC (1) "They are the same particle."
17077 * xmlSchemaCheckRCaseNSRecurseCheckCardinality:
17078 * @ctxt: the schema parser context
17079 * @r: the model group particle
17080 * @b: the base wildcard particle
17082 * (3.9.6) Constraints on Particle Schema Components
17083 * Schema Component Constraint:
17084 * Particle Derivation OK (All/Choice/Sequence:Any --
17085 * NSRecurseCheckCardinality)
17086 * (rcase-NSRecurseCheckCardinality)
17088 * STATUS: TODO: subst-groups
17090 * Returns 0 if the constraints are satisfied, a positive
17091 * error code if not and -1 if an internal error occurred.
17094 xmlSchemaCheckRCaseNSRecurseCheckCardinality(xmlSchemaParserCtxtPtr ctxt,
17095 xmlSchemaParticlePtr r,
17096 xmlSchemaParticlePtr b)
17098 xmlSchemaParticlePtr part;
17099 /* TODO: Error codes (rcase-NSRecurseCheckCardinality). */
17100 if ((r->children == NULL) || (r->children->children == NULL))
17103 * SPEC "For a group particle to be a `valid restriction` of a
17104 * wildcard particle..."
17106 * SPEC (1) "Every member of the {particles} of the group is a `valid
17107 * restriction` of the wildcard as defined by
17108 * Particle Valid (Restriction) ($3.9.6)."
17110 part = (xmlSchemaParticlePtr) r->children->children;
17112 if (xmlSchemaCheckCOSParticleRestrict(ctxt, part, b))
17114 part = (xmlSchemaParticlePtr) part->next;
17115 } while (part != NULL);
17117 * SPEC (2) "The effective total range of the group [...] is a
17118 * valid restriction of B's occurrence range as defined by
17119 * Occurrence Range OK ($3.9.6)."
17121 if (xmlSchemaCheckParticleRangeOK(
17122 xmlSchemaGetParticleTotalRangeMin(r),
17123 xmlSchemaGetParticleTotalRangeMax(r),
17124 b->minOccurs, b->maxOccurs) != 0)
17131 * xmlSchemaCheckRCaseRecurse:
17132 * @ctxt: the schema parser context
17133 * @r: the <all> or <sequence> model group particle
17134 * @b: the base <all> or <sequence> model group particle
17136 * (3.9.6) Constraints on Particle Schema Components
17137 * Schema Component Constraint:
17138 * Particle Derivation OK (All:All,Sequence:Sequence --
17143 * TODO: subst-groups
17145 * Returns 0 if the constraints are satisfied, a positive
17146 * error code if not and -1 if an internal error occurred.
17149 xmlSchemaCheckRCaseRecurse(xmlSchemaParserCtxtPtr ctxt,
17150 xmlSchemaParticlePtr r,
17151 xmlSchemaParticlePtr b)
17153 /* xmlSchemaParticlePtr part; */
17154 /* TODO: Error codes (rcase-Recurse). */
17155 if ((r->children == NULL) || (b->children == NULL) ||
17156 (r->children->type != b->children->type))
17159 * SPEC "For an all or sequence group particle to be a `valid
17160 * restriction` of another group particle with the same {compositor}..."
17162 * SPEC (1) "R's occurrence range is a valid restriction of B's
17163 * occurrence range as defined by Occurrence Range OK ($3.9.6)."
17165 if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs,
17166 b->minOccurs, b->maxOccurs))
17175 #define FACET_RESTR_MUTUAL_ERR(fac1, fac2) \
17176 xmlSchemaPCustomErrExt(pctxt, \
17177 XML_SCHEMAP_INVALID_FACET_VALUE, \
17178 WXS_BASIC_CAST fac1, fac1->node, \
17179 "It is an error for both '%s' and '%s' to be specified on the "\
17180 "same type definition", \
17181 BAD_CAST xmlSchemaFacetTypeToString(fac1->type), \
17182 BAD_CAST xmlSchemaFacetTypeToString(fac2->type), NULL);
17184 #define FACET_RESTR_ERR(fac1, msg) \
17185 xmlSchemaPCustomErr(pctxt, \
17186 XML_SCHEMAP_INVALID_FACET_VALUE, \
17187 WXS_BASIC_CAST fac1, fac1->node, \
17190 #define FACET_RESTR_FIXED_ERR(fac) \
17191 xmlSchemaPCustomErr(pctxt, \
17192 XML_SCHEMAP_INVALID_FACET_VALUE, \
17193 WXS_BASIC_CAST fac, fac->node, \
17194 "The base type's facet is 'fixed', thus the value must not " \
17198 xmlSchemaDeriveFacetErr(xmlSchemaParserCtxtPtr pctxt,
17199 xmlSchemaFacetPtr facet1,
17200 xmlSchemaFacetPtr facet2,
17205 xmlChar *msg = NULL;
17207 msg = xmlStrdup(BAD_CAST "'");
17208 msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facet1->type));
17209 msg = xmlStrcat(msg, BAD_CAST "' has to be");
17210 if (lessGreater == 0)
17211 msg = xmlStrcat(msg, BAD_CAST " equal to");
17212 if (lessGreater == 1)
17213 msg = xmlStrcat(msg, BAD_CAST " greater than");
17215 msg = xmlStrcat(msg, BAD_CAST " less than");
17218 msg = xmlStrcat(msg, BAD_CAST " or equal to");
17219 msg = xmlStrcat(msg, BAD_CAST " '");
17220 msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facet2->type));
17222 msg = xmlStrcat(msg, BAD_CAST "' of the base type");
17224 msg = xmlStrcat(msg, BAD_CAST "'");
17226 xmlSchemaPCustomErr(pctxt,
17227 XML_SCHEMAP_INVALID_FACET_VALUE,
17228 WXS_BASIC_CAST facet1, NULL,
17229 (const char *) msg, NULL);
17236 * xmlSchemaDeriveAndValidateFacets:
17238 * Schema Component Constraint: Simple Type Restriction (Facets)
17239 * (st-restrict-facets)
17242 xmlSchemaDeriveAndValidateFacets(xmlSchemaParserCtxtPtr pctxt,
17243 xmlSchemaTypePtr type)
17245 xmlSchemaTypePtr base = type->baseType;
17246 xmlSchemaFacetLinkPtr link, cur, last = NULL;
17247 xmlSchemaFacetPtr facet, bfacet,
17248 flength = NULL, ftotdig = NULL, ffracdig = NULL,
17249 fmaxlen = NULL, fminlen = NULL, /* facets of the current type */
17250 fmininc = NULL, fmaxinc = NULL,
17251 fminexc = NULL, fmaxexc = NULL,
17252 bflength = NULL, bftotdig = NULL, bffracdig = NULL,
17253 bfmaxlen = NULL, bfminlen = NULL, /* facets of the base type */
17254 bfmininc = NULL, bfmaxinc = NULL,
17255 bfminexc = NULL, bfmaxexc = NULL;
17256 int res; /* err = 0, fixedErr; */
17259 * SPEC st-restrict-facets 1:
17260 * "The {variety} of R is the same as that of B."
17263 * SPEC st-restrict-facets 2:
17264 * "If {variety} is atomic, the {primitive type definition}
17265 * of R is the same as that of B."
17267 * NOTE: we leave 1 & 2 out for now, since this will be
17268 * satisfied by the derivation process.
17269 * CONSTRUCTION TODO: Maybe needed if using a construction API.
17272 * SPEC st-restrict-facets 3:
17273 * "The {facets} of R are the union of S and the {facets}
17274 * of B, eliminating duplicates. To eliminate duplicates,
17275 * when a facet of the same kind occurs in both S and the
17276 * {facets} of B, the one in the {facets} of B is not
17277 * included, with the exception of enumeration and pattern
17278 * facets, for which multiple occurrences with distinct values
17282 if ((type->facetSet == NULL) && (base->facetSet == NULL))
17285 last = type->facetSet;
17287 while (last->next != NULL)
17290 for (cur = type->facetSet; cur != NULL; cur = cur->next) {
17291 facet = cur->facet;
17292 switch (facet->type) {
17293 case XML_SCHEMA_FACET_LENGTH:
17294 flength = facet; break;
17295 case XML_SCHEMA_FACET_MINLENGTH:
17296 fminlen = facet; break;
17297 case XML_SCHEMA_FACET_MININCLUSIVE:
17298 fmininc = facet; break;
17299 case XML_SCHEMA_FACET_MINEXCLUSIVE:
17300 fminexc = facet; break;
17301 case XML_SCHEMA_FACET_MAXLENGTH:
17302 fmaxlen = facet; break;
17303 case XML_SCHEMA_FACET_MAXINCLUSIVE:
17304 fmaxinc = facet; break;
17305 case XML_SCHEMA_FACET_MAXEXCLUSIVE:
17306 fmaxexc = facet; break;
17307 case XML_SCHEMA_FACET_TOTALDIGITS:
17308 ftotdig = facet; break;
17309 case XML_SCHEMA_FACET_FRACTIONDIGITS:
17310 ffracdig = facet; break;
17315 for (cur = base->facetSet; cur != NULL; cur = cur->next) {
17316 facet = cur->facet;
17317 switch (facet->type) {
17318 case XML_SCHEMA_FACET_LENGTH:
17319 bflength = facet; break;
17320 case XML_SCHEMA_FACET_MINLENGTH:
17321 bfminlen = facet; break;
17322 case XML_SCHEMA_FACET_MININCLUSIVE:
17323 bfmininc = facet; break;
17324 case XML_SCHEMA_FACET_MINEXCLUSIVE:
17325 bfminexc = facet; break;
17326 case XML_SCHEMA_FACET_MAXLENGTH:
17327 bfmaxlen = facet; break;
17328 case XML_SCHEMA_FACET_MAXINCLUSIVE:
17329 bfmaxinc = facet; break;
17330 case XML_SCHEMA_FACET_MAXEXCLUSIVE:
17331 bfmaxexc = facet; break;
17332 case XML_SCHEMA_FACET_TOTALDIGITS:
17333 bftotdig = facet; break;
17334 case XML_SCHEMA_FACET_FRACTIONDIGITS:
17335 bffracdig = facet; break;
17341 * length and minLength or maxLength (2.2) + (3.2)
17343 if (flength && (fminlen || fmaxlen)) {
17344 FACET_RESTR_ERR(flength, "It is an error for both 'length' and "
17345 "either of 'minLength' or 'maxLength' to be specified on "
17346 "the same type definition")
17349 * Mutual exclusions in the same derivation step.
17351 if ((fmaxinc) && (fmaxexc)) {
17353 * SCC "maxInclusive and maxExclusive"
17355 FACET_RESTR_MUTUAL_ERR(fmaxinc, fmaxexc)
17357 if ((fmininc) && (fminexc)) {
17359 * SCC "minInclusive and minExclusive"
17361 FACET_RESTR_MUTUAL_ERR(fmininc, fminexc)
17364 if (flength && bflength) {
17366 * SCC "length valid restriction"
17367 * The values have to be equal.
17369 res = xmlSchemaCompareValues(flength->val, bflength->val);
17371 goto internal_error;
17373 xmlSchemaDeriveFacetErr(pctxt, flength, bflength, 0, 0, 1);
17374 if ((res != 0) && (bflength->fixed)) {
17375 FACET_RESTR_FIXED_ERR(flength)
17379 if (fminlen && bfminlen) {
17381 * SCC "minLength valid restriction"
17382 * minLength >= BASE minLength
17384 res = xmlSchemaCompareValues(fminlen->val, bfminlen->val);
17386 goto internal_error;
17388 xmlSchemaDeriveFacetErr(pctxt, fminlen, bfminlen, 1, 1, 1);
17389 if ((res != 0) && (bfminlen->fixed)) {
17390 FACET_RESTR_FIXED_ERR(fminlen)
17393 if (fmaxlen && bfmaxlen) {
17395 * SCC "maxLength valid restriction"
17396 * maxLength <= BASE minLength
17398 res = xmlSchemaCompareValues(fmaxlen->val, bfmaxlen->val);
17400 goto internal_error;
17402 xmlSchemaDeriveFacetErr(pctxt, fmaxlen, bfmaxlen, -1, 1, 1);
17403 if ((res != 0) && (bfmaxlen->fixed)) {
17404 FACET_RESTR_FIXED_ERR(fmaxlen)
17408 * SCC "length and minLength or maxLength"
17411 flength = bflength;
17414 fminlen = bfminlen;
17416 /* (1.1) length >= minLength */
17417 res = xmlSchemaCompareValues(flength->val, fminlen->val);
17419 goto internal_error;
17421 xmlSchemaDeriveFacetErr(pctxt, flength, fminlen, 1, 1, 0);
17424 fmaxlen = bfmaxlen;
17426 /* (2.1) length <= maxLength */
17427 res = xmlSchemaCompareValues(flength->val, fmaxlen->val);
17429 goto internal_error;
17431 xmlSchemaDeriveFacetErr(pctxt, flength, fmaxlen, -1, 1, 0);
17439 /* SCC "maxInclusive >= minInclusive" */
17440 res = xmlSchemaCompareValues(fmaxinc->val, fmininc->val);
17442 goto internal_error;
17444 xmlSchemaDeriveFacetErr(pctxt, fmaxinc, fmininc, 1, 1, 0);
17448 * SCC "maxInclusive valid restriction"
17451 /* maxInclusive <= BASE maxInclusive */
17452 res = xmlSchemaCompareValues(fmaxinc->val, bfmaxinc->val);
17454 goto internal_error;
17456 xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfmaxinc, -1, 1, 1);
17457 if ((res != 0) && (bfmaxinc->fixed)) {
17458 FACET_RESTR_FIXED_ERR(fmaxinc)
17462 /* maxInclusive < BASE maxExclusive */
17463 res = xmlSchemaCompareValues(fmaxinc->val, bfmaxexc->val);
17465 goto internal_error;
17467 xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfmaxexc, -1, 0, 1);
17471 /* maxInclusive >= BASE minInclusive */
17472 res = xmlSchemaCompareValues(fmaxinc->val, bfmininc->val);
17474 goto internal_error;
17476 xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfmininc, 1, 1, 1);
17480 /* maxInclusive > BASE minExclusive */
17481 res = xmlSchemaCompareValues(fmaxinc->val, bfminexc->val);
17483 goto internal_error;
17485 xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfminexc, 1, 0, 1);
17491 * "maxExclusive >= minExclusive"
17494 res = xmlSchemaCompareValues(fmaxexc->val, fminexc->val);
17496 goto internal_error;
17498 xmlSchemaDeriveFacetErr(pctxt, fmaxexc, fminexc, 1, 1, 0);
17502 * "maxExclusive valid restriction"
17505 /* maxExclusive <= BASE maxExclusive */
17506 res = xmlSchemaCompareValues(fmaxexc->val, bfmaxexc->val);
17508 goto internal_error;
17510 xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfmaxexc, -1, 1, 1);
17512 if ((res != 0) && (bfmaxexc->fixed)) {
17513 FACET_RESTR_FIXED_ERR(fmaxexc)
17517 /* maxExclusive <= BASE maxInclusive */
17518 res = xmlSchemaCompareValues(fmaxexc->val, bfmaxinc->val);
17520 goto internal_error;
17522 xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfmaxinc, -1, 1, 1);
17526 /* maxExclusive > BASE minInclusive */
17527 res = xmlSchemaCompareValues(fmaxexc->val, bfmininc->val);
17529 goto internal_error;
17531 xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfmininc, 1, 0, 1);
17535 /* maxExclusive > BASE minExclusive */
17536 res = xmlSchemaCompareValues(fmaxexc->val, bfminexc->val);
17538 goto internal_error;
17540 xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfminexc, 1, 0, 1);
17546 * "minExclusive < maxInclusive"
17549 res = xmlSchemaCompareValues(fminexc->val, fmaxinc->val);
17551 goto internal_error;
17553 xmlSchemaDeriveFacetErr(pctxt, fminexc, fmaxinc, -1, 0, 0);
17557 * "minExclusive valid restriction"
17560 /* minExclusive >= BASE minExclusive */
17561 res = xmlSchemaCompareValues(fminexc->val, bfminexc->val);
17563 goto internal_error;
17565 xmlSchemaDeriveFacetErr(pctxt, fminexc, bfminexc, 1, 1, 1);
17567 if ((res != 0) && (bfminexc->fixed)) {
17568 FACET_RESTR_FIXED_ERR(fminexc)
17572 /* minExclusive <= BASE maxInclusive */
17573 res = xmlSchemaCompareValues(fminexc->val, bfmaxinc->val);
17575 goto internal_error;
17577 xmlSchemaDeriveFacetErr(pctxt, fminexc, bfmaxinc, -1, 1, 1);
17581 /* minExclusive >= BASE minInclusive */
17582 res = xmlSchemaCompareValues(fminexc->val, bfmininc->val);
17584 goto internal_error;
17586 xmlSchemaDeriveFacetErr(pctxt, fminexc, bfmininc, 1, 1, 1);
17590 /* minExclusive < BASE maxExclusive */
17591 res = xmlSchemaCompareValues(fminexc->val, bfmaxexc->val);
17593 goto internal_error;
17595 xmlSchemaDeriveFacetErr(pctxt, fminexc, bfmaxexc, -1, 0, 1);
17601 * "minInclusive < maxExclusive"
17604 res = xmlSchemaCompareValues(fmininc->val, fmaxexc->val);
17606 goto internal_error;
17608 xmlSchemaDeriveFacetErr(pctxt, fmininc, fmaxexc, -1, 0, 0);
17612 * "minExclusive valid restriction"
17615 /* minInclusive >= BASE minInclusive */
17616 res = xmlSchemaCompareValues(fmininc->val, bfmininc->val);
17618 goto internal_error;
17620 xmlSchemaDeriveFacetErr(pctxt, fmininc, bfmininc, 1, 1, 1);
17622 if ((res != 0) && (bfmininc->fixed)) {
17623 FACET_RESTR_FIXED_ERR(fmininc)
17627 /* minInclusive <= BASE maxInclusive */
17628 res = xmlSchemaCompareValues(fmininc->val, bfmaxinc->val);
17630 goto internal_error;
17632 xmlSchemaDeriveFacetErr(pctxt, fmininc, bfmaxinc, -1, 1, 1);
17636 /* minInclusive > BASE minExclusive */
17637 res = xmlSchemaCompareValues(fmininc->val, bfminexc->val);
17639 goto internal_error;
17641 xmlSchemaDeriveFacetErr(pctxt, fmininc, bfminexc, 1, 0, 1);
17644 /* minInclusive < BASE maxExclusive */
17645 res = xmlSchemaCompareValues(fmininc->val, bfmaxexc->val);
17647 goto internal_error;
17649 xmlSchemaDeriveFacetErr(pctxt, fmininc, bfmaxexc, -1, 0, 1);
17652 if (ftotdig && bftotdig) {
17654 * SCC " totalDigits valid restriction"
17655 * totalDigits <= BASE totalDigits
17657 res = xmlSchemaCompareValues(ftotdig->val, bftotdig->val);
17659 goto internal_error;
17661 xmlSchemaDeriveFacetErr(pctxt, ftotdig, bftotdig,
17663 if ((res != 0) && (bftotdig->fixed)) {
17664 FACET_RESTR_FIXED_ERR(ftotdig)
17667 if (ffracdig && bffracdig) {
17669 * SCC "fractionDigits valid restriction"
17670 * fractionDigits <= BASE fractionDigits
17672 res = xmlSchemaCompareValues(ffracdig->val, bffracdig->val);
17674 goto internal_error;
17676 xmlSchemaDeriveFacetErr(pctxt, ffracdig, bffracdig,
17678 if ((res != 0) && (bffracdig->fixed)) {
17679 FACET_RESTR_FIXED_ERR(ffracdig)
17683 * SCC "fractionDigits less than or equal to totalDigits"
17686 ftotdig = bftotdig;
17688 ffracdig = bffracdig;
17689 if (ftotdig && ffracdig) {
17690 res = xmlSchemaCompareValues(ffracdig->val, ftotdig->val);
17692 goto internal_error;
17694 xmlSchemaDeriveFacetErr(pctxt, ffracdig, ftotdig,
17698 * *Enumerations* won' be added here, since only the first set
17699 * of enumerations in the ancestor-or-self axis is used
17700 * for validation, plus we need to use the base type of those
17701 * enumerations for whitespace.
17703 * *Patterns*: won't be add here, since they are ORed at
17704 * type level and ANDed at ancestor level. This will
17705 * happed during validation by walking the base axis
17708 for (cur = base->facetSet; cur != NULL; cur = cur->next) {
17709 bfacet = cur->facet;
17711 * Special handling of enumerations and patterns.
17712 * TODO: hmm, they should not appear in the set, so remove this.
17714 if ((bfacet->type == XML_SCHEMA_FACET_PATTERN) ||
17715 (bfacet->type == XML_SCHEMA_FACET_ENUMERATION))
17718 * Search for a duplicate facet in the current type.
17720 link = type->facetSet;
17722 /* fixedErr = 0; */
17723 while (link != NULL) {
17724 facet = link->facet;
17725 if (facet->type == bfacet->type) {
17726 switch (facet->type) {
17727 case XML_SCHEMA_FACET_WHITESPACE:
17729 * The whitespace must be stronger.
17731 if (facet->whitespace < bfacet->whitespace) {
17732 FACET_RESTR_ERR(facet,
17733 "The 'whitespace' value has to be equal to "
17734 "or stronger than the 'whitespace' value of "
17737 if ((bfacet->fixed) &&
17738 (facet->whitespace != bfacet->whitespace)) {
17739 FACET_RESTR_FIXED_ERR(facet)
17745 /* Duplicate found. */
17751 * If no duplicate was found: add the base types's facet
17754 if (link == NULL) {
17755 link = (xmlSchemaFacetLinkPtr)
17756 xmlMalloc(sizeof(xmlSchemaFacetLink));
17757 if (link == NULL) {
17758 xmlSchemaPErrMemory(pctxt,
17759 "deriving facets, creating a facet link", NULL);
17762 link->facet = cur->facet;
17765 type->facetSet = link;
17775 PERROR_INT("xmlSchemaDeriveAndValidateFacets",
17776 "an error occurred");
17781 xmlSchemaFinishMemberTypeDefinitionsProperty(xmlSchemaParserCtxtPtr pctxt,
17782 xmlSchemaTypePtr type)
17784 xmlSchemaTypeLinkPtr link, lastLink, prevLink, subLink, newLink;
17786 * The actual value is then formed by replacing any union type
17787 * definition in the `explicit members` with the members of their
17788 * {member type definitions}, in order.
17790 * TODO: There's a bug entry at
17791 * "http://lists.w3.org/Archives/Public/www-xml-schema-comments/2005JulSep/0287.html"
17792 * which indicates that we'll keep the union types the future.
17794 link = type->memberTypes;
17795 while (link != NULL) {
17797 if (WXS_IS_TYPE_NOT_FIXED(link->type))
17798 xmlSchemaTypeFixup(link->type, ACTXT_CAST pctxt);
17800 if (WXS_IS_UNION(link->type)) {
17801 subLink = xmlSchemaGetUnionSimpleTypeMemberTypes(link->type);
17802 if (subLink != NULL) {
17803 link->type = subLink->type;
17804 if (subLink->next != NULL) {
17805 lastLink = link->next;
17806 subLink = subLink->next;
17808 while (subLink != NULL) {
17809 newLink = (xmlSchemaTypeLinkPtr)
17810 xmlMalloc(sizeof(xmlSchemaTypeLink));
17811 if (newLink == NULL) {
17812 xmlSchemaPErrMemory(pctxt, "allocating a type link",
17816 newLink->type = subLink->type;
17817 prevLink->next = newLink;
17818 prevLink = newLink;
17819 newLink->next = lastLink;
17821 subLink = subLink->next;
17832 xmlSchemaTypeFixupOptimFacets(xmlSchemaTypePtr type)
17834 int has = 0, needVal = 0, normVal = 0;
17836 has = (type->baseType->flags & XML_SCHEMAS_TYPE_HAS_FACETS) ? 1 : 0;
17838 needVal = (type->baseType->flags &
17839 XML_SCHEMAS_TYPE_FACETSNEEDVALUE) ? 1 : 0;
17840 normVal = (type->baseType->flags &
17841 XML_SCHEMAS_TYPE_NORMVALUENEEDED) ? 1 : 0;
17843 if (type->facets != NULL) {
17844 xmlSchemaFacetPtr fac;
17846 for (fac = type->facets; fac != NULL; fac = fac->next) {
17847 switch (fac->type) {
17848 case XML_SCHEMA_FACET_WHITESPACE:
17850 case XML_SCHEMA_FACET_PATTERN:
17854 case XML_SCHEMA_FACET_ENUMERATION:
17866 type->flags |= XML_SCHEMAS_TYPE_NORMVALUENEEDED;
17868 type->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE;
17870 type->flags |= XML_SCHEMAS_TYPE_HAS_FACETS;
17872 if (has && (! needVal) && WXS_IS_ATOMIC(type)) {
17873 xmlSchemaTypePtr prim = xmlSchemaGetPrimitiveType(type);
17875 * OPTIMIZE VAL TODO: Some facets need a computed value.
17877 if ((prim->builtInType != XML_SCHEMAS_ANYSIMPLETYPE) &&
17878 (prim->builtInType != XML_SCHEMAS_STRING)) {
17879 type->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE;
17885 xmlSchemaTypeFixupWhitespace(xmlSchemaTypePtr type)
17890 * Evaluate the whitespace-facet value.
17892 if (WXS_IS_LIST(type)) {
17893 type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE;
17895 } else if (WXS_IS_UNION(type))
17898 if (type->facetSet != NULL) {
17899 xmlSchemaFacetLinkPtr lin;
17901 for (lin = type->facetSet; lin != NULL; lin = lin->next) {
17902 if (lin->facet->type == XML_SCHEMA_FACET_WHITESPACE) {
17903 switch (lin->facet->whitespace) {
17904 case XML_SCHEMAS_FACET_PRESERVE:
17905 type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE;
17907 case XML_SCHEMAS_FACET_REPLACE:
17908 type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_REPLACE;
17910 case XML_SCHEMAS_FACET_COLLAPSE:
17911 type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE;
17921 * For all `atomic` datatypes other than string (and types `derived`
17922 * by `restriction` from it) the value of whiteSpace is fixed to
17926 xmlSchemaTypePtr anc;
17928 for (anc = type->baseType; anc != NULL &&
17929 anc->builtInType != XML_SCHEMAS_ANYTYPE;
17930 anc = anc->baseType) {
17932 if (anc->type == XML_SCHEMA_TYPE_BASIC) {
17933 if (anc->builtInType == XML_SCHEMAS_NORMSTRING) {
17934 type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_REPLACE;
17936 } else if ((anc->builtInType == XML_SCHEMAS_STRING) ||
17937 (anc->builtInType == XML_SCHEMAS_ANYSIMPLETYPE)) {
17938 type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE;
17941 type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE;
17950 xmlSchemaFixupSimpleTypeStageOne(xmlSchemaParserCtxtPtr pctxt,
17951 xmlSchemaTypePtr type)
17953 if (type->type != XML_SCHEMA_TYPE_SIMPLE)
17955 if (! WXS_IS_TYPE_NOT_FIXED_1(type))
17957 type->flags |= XML_SCHEMAS_TYPE_FIXUP_1;
17959 if (WXS_IS_LIST(type)) {
17961 * Corresponds to <simpleType><list>...
17963 if (type->subtypes == NULL) {
17965 * This one is really needed, so get out.
17967 PERROR_INT("xmlSchemaFixupSimpleTypeStageOne",
17968 "list type has no item-type assigned");
17971 } else if (WXS_IS_UNION(type)) {
17973 * Corresponds to <simpleType><union>...
17975 if (type->memberTypes == NULL) {
17977 * This one is really needed, so get out.
17979 PERROR_INT("xmlSchemaFixupSimpleTypeStageOne",
17980 "union type has no member-types assigned");
17985 * Corresponds to <simpleType><restriction>...
17987 if (type->baseType == NULL) {
17988 PERROR_INT("xmlSchemaFixupSimpleTypeStageOne",
17989 "type has no base-type assigned");
17992 if (WXS_IS_TYPE_NOT_FIXED_1(type->baseType))
17993 if (xmlSchemaFixupSimpleTypeStageOne(pctxt, type->baseType) == -1)
17997 * If the <restriction> alternative is chosen, then the
17998 * {variety} of the {base type definition}.
18000 if (WXS_IS_ATOMIC(type->baseType))
18001 type->flags |= XML_SCHEMAS_TYPE_VARIETY_ATOMIC;
18002 else if (WXS_IS_LIST(type->baseType)) {
18003 type->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST;
18005 * Inherit the itemType.
18007 type->subtypes = type->baseType->subtypes;
18008 } else if (WXS_IS_UNION(type->baseType)) {
18009 type->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION;
18011 * NOTE that we won't assign the memberTypes of the base,
18012 * since this will make trouble when freeing them; we will
18013 * use a lookup function to access them instead.
18022 xmlSchemaDebugFixedType(xmlSchemaParserCtxtPtr pctxt,
18023 xmlSchemaTypePtr type)
18025 if (type->node != NULL) {
18026 xmlGenericError(xmlGenericErrorContext,
18027 "Type of %s : %s:%d :", name,
18028 type->node->doc->URL,
18029 xmlGetLineNo(type->node));
18031 xmlGenericError(xmlGenericErrorContext, "Type of %s :", name);
18033 if ((WXS_IS_SIMPLE(type)) || (WXS_IS_COMPLEX(type))) {
18034 switch (type->contentType) {
18035 case XML_SCHEMA_CONTENT_SIMPLE:
18036 xmlGenericError(xmlGenericErrorContext, "simple\n");
18038 case XML_SCHEMA_CONTENT_ELEMENTS:
18039 xmlGenericError(xmlGenericErrorContext, "elements\n");
18041 case XML_SCHEMA_CONTENT_UNKNOWN:
18042 xmlGenericError(xmlGenericErrorContext, "unknown !!!\n");
18044 case XML_SCHEMA_CONTENT_EMPTY:
18045 xmlGenericError(xmlGenericErrorContext, "empty\n");
18047 case XML_SCHEMA_CONTENT_MIXED:
18048 if (xmlSchemaIsParticleEmptiable((xmlSchemaParticlePtr)
18050 xmlGenericError(xmlGenericErrorContext,
18051 "mixed as emptiable particle\n");
18053 xmlGenericError(xmlGenericErrorContext, "mixed\n");
18055 /* Removed, since not used. */
18057 case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS:
18058 xmlGenericError(xmlGenericErrorContext, "mixed or elems\n");
18061 case XML_SCHEMA_CONTENT_BASIC:
18062 xmlGenericError(xmlGenericErrorContext, "basic\n");
18065 xmlGenericError(xmlGenericErrorContext,
18066 "not registered !!!\n");
18074 * 3.14.6 Constraints on Simple Type Definition Schema Components
18077 xmlSchemaFixupSimpleTypeStageTwo(xmlSchemaParserCtxtPtr pctxt,
18078 xmlSchemaTypePtr type)
18080 int res, olderrs = pctxt->nberrors;
18082 if (type->type != XML_SCHEMA_TYPE_SIMPLE)
18085 if (! WXS_IS_TYPE_NOT_FIXED(type))
18088 type->flags |= XML_SCHEMAS_TYPE_INTERNAL_RESOLVED;
18089 type->contentType = XML_SCHEMA_CONTENT_SIMPLE;
18091 if (type->baseType == NULL) {
18092 PERROR_INT("xmlSchemaFixupSimpleTypeStageTwo",
18093 "missing baseType");
18096 if (WXS_IS_TYPE_NOT_FIXED(type->baseType))
18097 xmlSchemaTypeFixup(type->baseType, ACTXT_CAST pctxt);
18099 * If a member type of a union is a union itself, we need to substitute
18100 * that member type for its member types.
18101 * NOTE that this might change in WXS 1.1; i.e. we will keep the union
18102 * types in WXS 1.1.
18104 if ((type->memberTypes != NULL) &&
18105 (xmlSchemaFinishMemberTypeDefinitionsProperty(pctxt, type) == -1))
18108 * SPEC src-simple-type 1
18109 * "The corresponding simple type definition, if any, must satisfy
18110 * the conditions set out in Constraints on Simple Type Definition
18111 * Schema Components ($3.14.6)."
18114 * Schema Component Constraint: Simple Type Definition Properties Correct
18115 * (st-props-correct)
18117 res = xmlSchemaCheckSTPropsCorrect(pctxt, type);
18120 * Schema Component Constraint: Derivation Valid (Restriction, Simple)
18121 * (cos-st-restricts)
18123 res = xmlSchemaCheckCOSSTRestricts(pctxt, type);
18126 * TODO: Removed the error report, since it got annoying to get an
18127 * extra error report, if anything failed until now.
18128 * Enable this if needed.
18130 * xmlSchemaPErr(ctxt, type->node,
18131 * XML_SCHEMAP_SRC_SIMPLE_TYPE_1,
18132 * "Simple type '%s' does not satisfy the constraints "
18133 * "on simple type definitions.\n",
18134 * type->name, NULL);
18137 * Schema Component Constraint: Simple Type Restriction (Facets)
18138 * (st-restrict-facets)
18140 res = xmlSchemaCheckFacetValues(type, pctxt);
18142 if ((type->facetSet != NULL) ||
18143 (type->baseType->facetSet != NULL)) {
18144 res = xmlSchemaDeriveAndValidateFacets(pctxt, type);
18148 * Whitespace value.
18150 res = xmlSchemaTypeFixupWhitespace(type);
18152 xmlSchemaTypeFixupOptimFacets(type);
18156 xmlSchemaDebugFixedType(pctxt, type);
18158 if (olderrs != pctxt->nberrors)
18159 return(pctxt->err);
18164 xmlSchemaDebugFixedType(pctxt, type);
18170 xmlSchemaFixupComplexType(xmlSchemaParserCtxtPtr pctxt,
18171 xmlSchemaTypePtr type)
18173 int res = 0, olderrs = pctxt->nberrors;
18174 xmlSchemaTypePtr baseType = type->baseType;
18176 if (! WXS_IS_TYPE_NOT_FIXED(type))
18178 type->flags |= XML_SCHEMAS_TYPE_INTERNAL_RESOLVED;
18179 if (baseType == NULL) {
18180 PERROR_INT("xmlSchemaFixupComplexType",
18181 "missing baseType");
18185 * Fixup the base type.
18187 if (WXS_IS_TYPE_NOT_FIXED(baseType))
18188 xmlSchemaTypeFixup(baseType, ACTXT_CAST pctxt);
18189 if (baseType->flags & XML_SCHEMAS_TYPE_INTERNAL_INVALID) {
18191 * Skip fixup if the base type is invalid.
18192 * TODO: Generate a warning!
18197 * This basically checks if the base type can be derived.
18199 res = xmlSchemaCheckSRCCT(pctxt, type);
18202 * Fixup the content type.
18204 if (type->contentType == XML_SCHEMA_CONTENT_SIMPLE) {
18206 * Corresponds to <complexType><simpleContent>...
18208 if ((WXS_IS_COMPLEX(baseType)) &&
18209 (baseType->contentTypeDef != NULL) &&
18210 (WXS_IS_RESTRICTION(type))) {
18211 xmlSchemaTypePtr contentBase, content;
18212 #ifdef ENABLE_NAMED_LOCALS
18214 const xmlChar *tmpname;
18217 * SPEC (1) If <restriction> + base type is <complexType>,
18218 * "whose own {content type} is a simple type..."
18220 if (type->contentTypeDef != NULL) {
18222 * SPEC (1.1) "the simple type definition corresponding to the
18223 * <simpleType> among the [children] of <restriction> if there
18225 * Note that this "<simpleType> among the [children]" was put
18226 * into ->contentTypeDef during parsing.
18228 contentBase = type->contentTypeDef;
18229 type->contentTypeDef = NULL;
18232 * (1.2) "...otherwise (<restriction> has no <simpleType>
18233 * among its [children]), the simple type definition which
18234 * is the {content type} of the ... base type."
18236 contentBase = baseType->contentTypeDef;
18240 * "... a simple type definition which restricts the simple
18241 * type definition identified in clause 1.1 or clause 1.2
18242 * with a set of facet components"
18244 * Create the anonymous simple type, which will be the content
18245 * type of the complex type.
18247 #ifdef ENABLE_NAMED_LOCALS
18248 snprintf(buf, 29, "#scST%d", ++(pctxt->counter));
18249 tmpname = xmlDictLookup(pctxt->dict, BAD_CAST buf, -1);
18250 content = xmlSchemaAddType(pctxt, pctxt->schema,
18251 XML_SCHEMA_TYPE_SIMPLE, tmpname, type->targetNamespace,
18254 content = xmlSchemaAddType(pctxt, pctxt->schema,
18255 XML_SCHEMA_TYPE_SIMPLE, NULL, type->targetNamespace,
18258 if (content == NULL)
18261 * We will use the same node as for the <complexType>
18262 * to have it somehow anchored in the schema doc.
18264 content->type = XML_SCHEMA_TYPE_SIMPLE;
18265 content->baseType = contentBase;
18267 * Move the facets, previously anchored on the
18268 * complexType during parsing.
18270 content->facets = type->facets;
18271 type->facets = NULL;
18272 content->facetSet = type->facetSet;
18273 type->facetSet = NULL;
18275 type->contentTypeDef = content;
18276 if (WXS_IS_TYPE_NOT_FIXED(contentBase))
18277 xmlSchemaTypeFixup(contentBase, ACTXT_CAST pctxt);
18279 * Fixup the newly created type. We don't need to check
18280 * for circularity here.
18282 res = xmlSchemaFixupSimpleTypeStageOne(pctxt, content);
18284 res = xmlSchemaFixupSimpleTypeStageTwo(pctxt, content);
18287 } else if ((WXS_IS_COMPLEX(baseType)) &&
18288 (baseType->contentType == XML_SCHEMA_CONTENT_MIXED) &&
18289 (WXS_IS_RESTRICTION(type))) {
18291 * SPEC (2) If <restriction> + base is a mixed <complexType> with
18292 * an emptiable particle, then a simple type definition which
18293 * restricts the <restriction>'s <simpleType> child.
18295 if ((type->contentTypeDef == NULL) ||
18296 (type->contentTypeDef->baseType == NULL)) {
18298 * TODO: Check if this ever happens.
18300 xmlSchemaPCustomErr(pctxt,
18301 XML_SCHEMAP_INTERNAL,
18302 WXS_BASIC_CAST type, NULL,
18303 "Internal error: xmlSchemaTypeFixup, "
18304 "complex type '%s': the <simpleContent><restriction> "
18305 "is missing a <simpleType> child, but was not catched "
18306 "by xmlSchemaCheckSRCCT()", type->name);
18309 } else if ((WXS_IS_COMPLEX(baseType)) && WXS_IS_EXTENSION(type)) {
18311 * SPEC (3) If <extension> + base is <complexType> with
18312 * <simpleType> content, "...then the {content type} of that
18313 * complex type definition"
18315 if (baseType->contentTypeDef == NULL) {
18317 * TODO: Check if this ever happens. xmlSchemaCheckSRCCT
18318 * should have catched this already.
18320 xmlSchemaPCustomErr(pctxt,
18321 XML_SCHEMAP_INTERNAL,
18322 WXS_BASIC_CAST type, NULL,
18323 "Internal error: xmlSchemaTypeFixup, "
18324 "complex type '%s': the <extension>ed base type is "
18325 "a complex type with no simple content type",
18329 type->contentTypeDef = baseType->contentTypeDef;
18330 } else if ((WXS_IS_SIMPLE(baseType)) && WXS_IS_EXTENSION(type)) {
18332 * SPEC (4) <extension> + base is <simpleType>
18333 * "... then that simple type definition"
18335 type->contentTypeDef = baseType;
18338 * TODO: Check if this ever happens.
18340 xmlSchemaPCustomErr(pctxt,
18341 XML_SCHEMAP_INTERNAL,
18342 WXS_BASIC_CAST type, NULL,
18343 "Internal error: xmlSchemaTypeFixup, "
18344 "complex type '%s' with <simpleContent>: unhandled "
18345 "derivation case", type->name);
18349 int dummySequence = 0;
18350 xmlSchemaParticlePtr particle =
18351 (xmlSchemaParticlePtr) type->subtypes;
18353 * Corresponds to <complexType><complexContent>...
18355 * NOTE that the effective mixed was already set during parsing of
18356 * <complexType> and <complexContent>; its flag value is
18357 * XML_SCHEMAS_TYPE_MIXED.
18359 * Compute the "effective content":
18360 * (2.1.1) + (2.1.2) + (2.1.3)
18362 if ((particle == NULL) ||
18363 ((particle->type == XML_SCHEMA_TYPE_PARTICLE) &&
18364 ((particle->children->type == XML_SCHEMA_TYPE_ALL) ||
18365 (particle->children->type == XML_SCHEMA_TYPE_SEQUENCE) ||
18366 ((particle->children->type == XML_SCHEMA_TYPE_CHOICE) &&
18367 (particle->minOccurs == 0))) &&
18368 ( ((xmlSchemaTreeItemPtr) particle->children)->children == NULL))) {
18369 if (type->flags & XML_SCHEMAS_TYPE_MIXED) {
18371 * SPEC (2.1.4) "If the `effective mixed` is true, then
18372 * a particle whose properties are as follows:..."
18374 * Empty sequence model group with
18375 * minOccurs/maxOccurs = 1 (i.e. a "particle emptiable").
18376 * NOTE that we sill assign it the <complexType> node to
18377 * somehow anchor it in the doc.
18379 if ((particle == NULL) ||
18380 (particle->children->type != XML_SCHEMA_TYPE_SEQUENCE)) {
18382 * Create the particle.
18384 particle = xmlSchemaAddParticle(pctxt,
18386 if (particle == NULL)
18389 * Create the model group.
18390 */ /* URGENT TODO: avoid adding to pending items. */
18391 particle->children = (xmlSchemaTreeItemPtr)
18392 xmlSchemaAddModelGroup(pctxt, pctxt->schema,
18393 XML_SCHEMA_TYPE_SEQUENCE, type->node);
18394 if (particle->children == NULL)
18397 type->subtypes = (xmlSchemaTypePtr) particle;
18400 type->contentType = XML_SCHEMA_CONTENT_ELEMENTS;
18403 * SPEC (2.1.5) "otherwise empty"
18405 type->contentType = XML_SCHEMA_CONTENT_EMPTY;
18409 * SPEC (2.2) "otherwise the particle corresponding to the
18410 * <all>, <choice>, <group> or <sequence> among the
18413 type->contentType = XML_SCHEMA_CONTENT_ELEMENTS;
18416 * Compute the "content type".
18418 if (WXS_IS_RESTRICTION(type)) {
18420 * SPEC (3.1) "If <restriction>..."
18421 * (3.1.1) + (3.1.2) */
18422 if (type->contentType != XML_SCHEMA_CONTENT_EMPTY) {
18423 if (type->flags & XML_SCHEMAS_TYPE_MIXED)
18424 type->contentType = XML_SCHEMA_CONTENT_MIXED;
18428 * SPEC (3.2) "If <extension>..."
18430 if (type->contentType == XML_SCHEMA_CONTENT_EMPTY) {
18433 * "If the `effective content` is empty, then the
18434 * {content type} of the [...] base ..."
18436 type->contentType = baseType->contentType;
18437 type->subtypes = baseType->subtypes;
18439 * Fixes bug #347316:
18440 * This is the case when the base type has a simple
18441 * type definition as content.
18443 type->contentTypeDef = baseType->contentTypeDef;
18445 * NOTE that the effective mixed is ignored here.
18447 } else if (baseType->contentType == XML_SCHEMA_CONTENT_EMPTY) {
18451 if (type->flags & XML_SCHEMAS_TYPE_MIXED)
18452 type->contentType = XML_SCHEMA_CONTENT_MIXED;
18457 if (type->flags & XML_SCHEMAS_TYPE_MIXED)
18458 type->contentType = XML_SCHEMA_CONTENT_MIXED;
18460 * "A model group whose {compositor} is sequence and whose
18461 * {particles} are..."
18463 if ((WXS_TYPE_PARTICLE(type) != NULL) &&
18464 (WXS_TYPE_PARTICLE_TERM(type) != NULL) &&
18465 ((WXS_TYPE_PARTICLE_TERM(type))->type ==
18466 XML_SCHEMA_TYPE_ALL))
18469 * SPEC cos-all-limited (1)
18471 xmlSchemaCustomErr(ACTXT_CAST pctxt,
18472 /* TODO: error code */
18473 XML_SCHEMAP_COS_ALL_LIMITED,
18474 WXS_ITEM_NODE(type), NULL,
18475 "The type has an 'all' model group in its "
18476 "{content type} and thus cannot be derived from "
18477 "a non-empty type, since this would produce a "
18478 "'sequence' model group containing the 'all' "
18479 "model group; 'all' model groups are not "
18480 "allowed to appear inside other model groups",
18483 } else if ((WXS_TYPE_PARTICLE(baseType) != NULL) &&
18484 (WXS_TYPE_PARTICLE_TERM(baseType) != NULL) &&
18485 ((WXS_TYPE_PARTICLE_TERM(baseType))->type ==
18486 XML_SCHEMA_TYPE_ALL))
18489 * SPEC cos-all-limited (1)
18491 xmlSchemaCustomErr(ACTXT_CAST pctxt,
18492 /* TODO: error code */
18493 XML_SCHEMAP_COS_ALL_LIMITED,
18494 WXS_ITEM_NODE(type), NULL,
18495 "A type cannot be derived by extension from a type "
18496 "which has an 'all' model group in its "
18497 "{content type}, since this would produce a "
18498 "'sequence' model group containing the 'all' "
18499 "model group; 'all' model groups are not "
18500 "allowed to appear inside other model groups",
18503 } else if (! dummySequence) {
18504 xmlSchemaTreeItemPtr effectiveContent =
18505 (xmlSchemaTreeItemPtr) type->subtypes;
18507 * Create the particle.
18509 particle = xmlSchemaAddParticle(pctxt,
18511 if (particle == NULL)
18514 * Create the "sequence" model group.
18516 particle->children = (xmlSchemaTreeItemPtr)
18517 xmlSchemaAddModelGroup(pctxt, pctxt->schema,
18518 XML_SCHEMA_TYPE_SEQUENCE, type->node);
18519 if (particle->children == NULL)
18521 WXS_TYPE_CONTENTTYPE(type) = (xmlSchemaTypePtr) particle;
18523 * SPEC "the particle of the {content type} of
18524 * the ... base ..."
18525 * Create a duplicate of the base type's particle
18526 * and assign its "term" to it.
18528 particle->children->children =
18529 (xmlSchemaTreeItemPtr) xmlSchemaAddParticle(pctxt,
18531 ((xmlSchemaParticlePtr) baseType->subtypes)->minOccurs,
18532 ((xmlSchemaParticlePtr) baseType->subtypes)->maxOccurs);
18533 if (particle->children->children == NULL)
18535 particle = (xmlSchemaParticlePtr)
18536 particle->children->children;
18537 particle->children =
18538 ((xmlSchemaParticlePtr) baseType->subtypes)->children;
18540 * SPEC "followed by the `effective content`."
18542 particle->next = effectiveContent;
18544 * This all will result in:
18546 * --> new-sequence(
18555 * This is the case when there is already an empty
18556 * <sequence> with minOccurs==maxOccurs==1.
18557 * Just add the base types's content type.
18558 * NOTE that, although we miss to add an intermediate
18559 * <sequence>, this should produce no difference to
18560 * neither the regex compilation of the content model,
18561 * nor to the complex type contraints.
18563 particle->children->children =
18564 (xmlSchemaTreeItemPtr) baseType->subtypes;
18570 * Now fixup attribute uses:
18571 * - expand attr. group references
18572 * - intersect attribute wildcards
18573 * - inherit attribute uses of the base type
18574 * - inherit or union attr. wildcards if extending
18575 * - apply attr. use prohibitions if restricting
18577 res = xmlSchemaFixupTypeAttributeUses(pctxt, type);
18580 * Apply the complex type component constraints; this will not
18581 * check attributes, since this is done in
18582 * xmlSchemaFixupTypeAttributeUses().
18584 res = xmlSchemaCheckCTComponent(pctxt, type);
18588 xmlSchemaDebugFixedType(pctxt, type);
18590 if (olderrs != pctxt->nberrors)
18591 return(pctxt->err);
18596 type->flags |= XML_SCHEMAS_TYPE_INTERNAL_INVALID;
18598 xmlSchemaDebugFixedType(pctxt, type);
18600 return(pctxt->err);
18603 type->flags |= XML_SCHEMAS_TYPE_INTERNAL_INVALID;
18605 xmlSchemaDebugFixedType(pctxt, type);
18612 * xmlSchemaTypeFixup:
18613 * @typeDecl: the schema type definition
18614 * @ctxt: the schema parser context
18616 * Fixes the content model of the type.
18617 * URGENT TODO: We need an int result!
18620 xmlSchemaTypeFixup(xmlSchemaTypePtr type,
18621 xmlSchemaAbstractCtxtPtr actxt)
18625 if (actxt->type != XML_SCHEMA_CTXT_PARSER) {
18626 AERROR_INT("xmlSchemaTypeFixup",
18627 "this function needs a parser context");
18630 if (! WXS_IS_TYPE_NOT_FIXED(type))
18632 if (type->type == XML_SCHEMA_TYPE_COMPLEX)
18633 return(xmlSchemaFixupComplexType(PCTXT_CAST actxt, type));
18634 else if (type->type == XML_SCHEMA_TYPE_SIMPLE)
18635 return(xmlSchemaFixupSimpleTypeStageTwo(PCTXT_CAST actxt, type));
18640 * xmlSchemaCheckFacet:
18641 * @facet: the facet
18642 * @typeDecl: the schema type definition
18643 * @pctxt: the schema parser context or NULL
18644 * @name: the optional name of the type
18646 * Checks and computes the values of facets.
18648 * Returns 0 if valid, a positive error code if not valid and
18649 * -1 in case of an internal or API error.
18652 xmlSchemaCheckFacet(xmlSchemaFacetPtr facet,
18653 xmlSchemaTypePtr typeDecl,
18654 xmlSchemaParserCtxtPtr pctxt,
18655 const xmlChar * name ATTRIBUTE_UNUSED)
18657 int ret = 0, ctxtGiven;
18659 if ((facet == NULL) || (typeDecl == NULL))
18662 * TODO: will the parser context be given if used from
18663 * the relaxNG module?
18670 switch (facet->type) {
18671 case XML_SCHEMA_FACET_MININCLUSIVE:
18672 case XML_SCHEMA_FACET_MINEXCLUSIVE:
18673 case XML_SCHEMA_FACET_MAXINCLUSIVE:
18674 case XML_SCHEMA_FACET_MAXEXCLUSIVE:
18675 case XML_SCHEMA_FACET_ENUMERATION: {
18677 * Okay we need to validate the value
18680 xmlSchemaTypePtr base;
18682 /* 4.3.5.5 Constraints on enumeration Schema Components
18683 * Schema Component Constraint: enumeration valid restriction
18684 * It is an `error` if any member of {value} is not in the
18685 * `value space` of {base type definition}.
18687 * minInclusive, maxInclusive, minExclusive, maxExclusive:
18688 * The value `must` be in the
18689 * `value space` of the `base type`.
18692 * This function is intended to deliver a compiled value
18693 * on the facet. In this implementation of XML Schemata the
18694 * type holding a facet, won't be a built-in type.
18695 * Thus to ensure that other API
18696 * calls (relaxng) do work, if the given type is a built-in
18697 * type, we will assume that the given built-in type *is
18698 * already* the base type.
18700 if (typeDecl->type != XML_SCHEMA_TYPE_BASIC) {
18701 base = typeDecl->baseType;
18702 if (base == NULL) {
18703 PERROR_INT("xmlSchemaCheckFacet",
18704 "a type user derived type has no base type");
18712 * A context is needed if called from RelaxNG.
18714 pctxt = xmlSchemaNewParserCtxt("*");
18719 * NOTE: This call does not check the content nodes,
18720 * since they are not available:
18721 * facet->node is just the node holding the facet
18722 * definition, *not* the attribute holding the *value*
18725 ret = xmlSchemaVCheckCVCSimpleType(
18726 ACTXT_CAST pctxt, facet->node, base,
18727 facet->value, &(facet->val), 1, 1, 0);
18730 /* No error message for RelaxNG. */
18732 xmlSchemaCustomErr(ACTXT_CAST pctxt,
18733 XML_SCHEMAP_INTERNAL, facet->node, NULL,
18734 "Internal error: xmlSchemaCheckFacet, "
18735 "failed to validate the value '%s' of the "
18736 "facet '%s' against the base type",
18737 facet->value, xmlSchemaFacetTypeToString(facet->type));
18739 goto internal_error;
18741 ret = XML_SCHEMAP_INVALID_FACET_VALUE;
18742 /* No error message for RelaxNG. */
18744 xmlChar *str = NULL;
18746 xmlSchemaCustomErr(ACTXT_CAST pctxt,
18747 ret, facet->node, WXS_BASIC_CAST facet,
18748 "The value '%s' of the facet does not validate "
18749 "against the base type '%s'",
18751 xmlSchemaFormatQName(&str,
18752 base->targetNamespace, base->name));
18753 FREE_AND_NULL(str);
18756 } else if (facet->val == NULL) {
18758 PERROR_INT("xmlSchemaCheckFacet",
18759 "value was not computed");
18765 case XML_SCHEMA_FACET_PATTERN:
18766 facet->regexp = xmlRegexpCompile(facet->value);
18767 if (facet->regexp == NULL) {
18768 ret = XML_SCHEMAP_REGEXP_INVALID;
18769 /* No error message for RelaxNG. */
18771 xmlSchemaCustomErr(ACTXT_CAST pctxt,
18772 ret, facet->node, WXS_BASIC_CAST typeDecl,
18773 "The value '%s' of the facet 'pattern' is not a "
18774 "valid regular expression",
18775 facet->value, NULL);
18779 case XML_SCHEMA_FACET_TOTALDIGITS:
18780 case XML_SCHEMA_FACET_FRACTIONDIGITS:
18781 case XML_SCHEMA_FACET_LENGTH:
18782 case XML_SCHEMA_FACET_MAXLENGTH:
18783 case XML_SCHEMA_FACET_MINLENGTH:
18785 if (facet->type == XML_SCHEMA_FACET_TOTALDIGITS) {
18786 ret = xmlSchemaValidatePredefinedType(
18787 xmlSchemaGetBuiltInType(XML_SCHEMAS_PINTEGER),
18788 facet->value, &(facet->val));
18790 ret = xmlSchemaValidatePredefinedType(
18791 xmlSchemaGetBuiltInType(XML_SCHEMAS_NNINTEGER),
18792 facet->value, &(facet->val));
18796 /* No error message for RelaxNG. */
18798 PERROR_INT("xmlSchemaCheckFacet",
18799 "validating facet value");
18801 goto internal_error;
18803 ret = XML_SCHEMAP_INVALID_FACET_VALUE;
18804 /* No error message for RelaxNG. */
18807 xmlSchemaCustomErr4(ACTXT_CAST pctxt,
18808 ret, facet->node, WXS_BASIC_CAST typeDecl,
18809 "The value '%s' of the facet '%s' is not a valid '%s'",
18811 xmlSchemaFacetTypeToString(facet->type),
18812 (facet->type != XML_SCHEMA_FACET_TOTALDIGITS) ?
18813 BAD_CAST "nonNegativeInteger" :
18814 BAD_CAST "positiveInteger",
18820 case XML_SCHEMA_FACET_WHITESPACE:{
18821 if (xmlStrEqual(facet->value, BAD_CAST "preserve")) {
18822 facet->whitespace = XML_SCHEMAS_FACET_PRESERVE;
18823 } else if (xmlStrEqual(facet->value, BAD_CAST "replace")) {
18824 facet->whitespace = XML_SCHEMAS_FACET_REPLACE;
18825 } else if (xmlStrEqual(facet->value, BAD_CAST "collapse")) {
18826 facet->whitespace = XML_SCHEMAS_FACET_COLLAPSE;
18828 ret = XML_SCHEMAP_INVALID_FACET_VALUE;
18829 /* No error message for RelaxNG. */
18831 /* error was previously: XML_SCHEMAP_INVALID_WHITE_SPACE */
18832 xmlSchemaCustomErr(ACTXT_CAST pctxt,
18833 ret, facet->node, WXS_BASIC_CAST typeDecl,
18834 "The value '%s' of the facet 'whitespace' is not "
18835 "valid", facet->value, NULL);
18843 if ((! ctxtGiven) && (pctxt != NULL))
18844 xmlSchemaFreeParserCtxt(pctxt);
18847 if ((! ctxtGiven) && (pctxt != NULL))
18848 xmlSchemaFreeParserCtxt(pctxt);
18853 * xmlSchemaCheckFacetValues:
18854 * @typeDecl: the schema type definition
18855 * @ctxt: the schema parser context
18857 * Checks the default values types, especially for facets
18860 xmlSchemaCheckFacetValues(xmlSchemaTypePtr typeDecl,
18861 xmlSchemaParserCtxtPtr pctxt)
18863 int res, olderrs = pctxt->nberrors;
18864 const xmlChar *name = typeDecl->name;
18866 * NOTE: It is intended to use the facets list, instead
18869 if (typeDecl->facets != NULL) {
18870 xmlSchemaFacetPtr facet = typeDecl->facets;
18873 * Temporarily assign the "schema" to the validation context
18874 * of the parser context. This is needed for NOTATION validation.
18876 if (pctxt->vctxt == NULL) {
18877 if (xmlSchemaCreateVCtxtOnPCtxt(pctxt) == -1)
18880 pctxt->vctxt->schema = pctxt->schema;
18881 while (facet != NULL) {
18882 res = xmlSchemaCheckFacet(facet, typeDecl, pctxt, name);
18884 facet = facet->next;
18886 pctxt->vctxt->schema = NULL;
18888 if (olderrs != pctxt->nberrors)
18889 return(pctxt->err);
18896 * xmlSchemaGetCircModelGrDefRef:
18897 * @ctxtMGroup: the searched model group
18898 * @selfMGroup: the second searched model group
18899 * @particle: the first particle
18901 * This one is intended to be used by
18902 * xmlSchemaCheckGroupDefCircular only.
18904 * Returns the particle with the circular model group definition reference,
18907 static xmlSchemaTreeItemPtr
18908 xmlSchemaGetCircModelGrDefRef(xmlSchemaModelGroupDefPtr groupDef,
18909 xmlSchemaTreeItemPtr particle)
18911 xmlSchemaTreeItemPtr circ = NULL;
18912 xmlSchemaTreeItemPtr term;
18913 xmlSchemaModelGroupDefPtr gdef;
18915 for (; particle != NULL; particle = particle->next) {
18916 term = particle->children;
18919 switch (term->type) {
18920 case XML_SCHEMA_TYPE_GROUP:
18921 gdef = (xmlSchemaModelGroupDefPtr) term;
18922 if (gdef == groupDef)
18925 * Mark this model group definition to avoid infinite
18926 * recursion on circular references not yet examined.
18928 if (gdef->flags & XML_SCHEMA_MODEL_GROUP_DEF_MARKED)
18930 if (gdef->children != NULL) {
18931 gdef->flags |= XML_SCHEMA_MODEL_GROUP_DEF_MARKED;
18932 circ = xmlSchemaGetCircModelGrDefRef(groupDef,
18933 gdef->children->children);
18934 gdef->flags ^= XML_SCHEMA_MODEL_GROUP_DEF_MARKED;
18939 case XML_SCHEMA_TYPE_SEQUENCE:
18940 case XML_SCHEMA_TYPE_CHOICE:
18941 case XML_SCHEMA_TYPE_ALL:
18942 circ = xmlSchemaGetCircModelGrDefRef(groupDef, term->children);
18954 * xmlSchemaCheckGroupDefCircular:
18955 * @item: the model group definition
18956 * @ctxt: the parser context
18959 * Checks for circular references to model group definitions.
18962 xmlSchemaCheckGroupDefCircular(xmlSchemaModelGroupDefPtr item,
18963 xmlSchemaParserCtxtPtr ctxt)
18966 * Schema Component Constraint: Model Group Correct
18967 * 2 Circular groups are disallowed. That is, within the {particles}
18968 * of a group there must not be at any depth a particle whose {term}
18969 * is the group itself.
18971 if ((item == NULL) ||
18972 (item->type != XML_SCHEMA_TYPE_GROUP) ||
18973 (item->children == NULL))
18976 xmlSchemaTreeItemPtr circ;
18978 circ = xmlSchemaGetCircModelGrDefRef(item, item->children->children);
18979 if (circ != NULL) {
18980 xmlChar *str = NULL;
18982 * TODO: The error report is not adequate: this constraint
18983 * is defined for model groups but not definitions, but since
18984 * there cannot be any circular model groups without a model group
18985 * definition (if not using a construction API), we check those
18988 xmlSchemaPCustomErr(ctxt,
18989 XML_SCHEMAP_MG_PROPS_CORRECT_2,
18990 NULL, WXS_ITEM_NODE(circ),
18991 "Circular reference to the model group definition '%s' "
18992 "defined", xmlSchemaFormatQName(&str,
18993 item->targetNamespace, item->name));
18996 * NOTE: We will cut the reference to avoid further
18997 * confusion of the processor. This is a fatal error.
18999 circ->children = NULL;
19005 * xmlSchemaModelGroupToModelGroupDefFixup:
19006 * @ctxt: the parser context
19007 * @mg: the model group
19009 * Assigns the model group of model group definitions to the "term"
19010 * of the referencing particle.
19011 * In xmlSchemaResolveModelGroupParticleReferences the model group
19012 * definitions were assigned to the "term", since needed for the
19013 * circularity check.
19015 * Schema Component Constraint:
19016 * All Group Limited (cos-all-limited) (1.2)
19019 xmlSchemaModelGroupToModelGroupDefFixup(
19020 xmlSchemaParserCtxtPtr ctxt ATTRIBUTE_UNUSED,
19021 xmlSchemaModelGroupPtr mg)
19023 xmlSchemaParticlePtr particle = WXS_MODELGROUP_PARTICLE(mg);
19025 while (particle != NULL) {
19026 if ((WXS_PARTICLE_TERM(particle) == NULL) ||
19027 ((WXS_PARTICLE_TERM(particle))->type !=
19028 XML_SCHEMA_TYPE_GROUP))
19030 particle = WXS_PTC_CAST particle->next;
19033 if (WXS_MODELGROUPDEF_MODEL(WXS_PARTICLE_TERM(particle)) == NULL) {
19035 * TODO: Remove the particle.
19037 WXS_PARTICLE_TERM(particle) = NULL;
19038 particle = WXS_PTC_CAST particle->next;
19042 * Assign the model group to the {term} of the particle.
19044 WXS_PARTICLE_TERM(particle) =
19045 WXS_TREE_CAST WXS_MODELGROUPDEF_MODEL(WXS_PARTICLE_TERM(particle));
19047 particle = WXS_PTC_CAST particle->next;
19052 * xmlSchemaCheckAttrGroupCircularRecur:
19053 * @ctxtGr: the searched attribute group
19054 * @attr: the current attribute list to be processed
19056 * This one is intended to be used by
19057 * xmlSchemaCheckAttrGroupCircular only.
19059 * Returns the circular attribute grou reference, otherwise NULL.
19061 static xmlSchemaQNameRefPtr
19062 xmlSchemaCheckAttrGroupCircularRecur(xmlSchemaAttributeGroupPtr ctxtGr,
19063 xmlSchemaItemListPtr list)
19065 xmlSchemaAttributeGroupPtr gr;
19066 xmlSchemaQNameRefPtr ref, circ;
19069 * We will search for an attribute group reference which
19070 * references the context attribute group.
19072 for (i = 0; i < list->nbItems; i++) {
19073 ref = list->items[i];
19074 if ((ref->type == XML_SCHEMA_EXTRA_QNAMEREF) &&
19075 (ref->itemType == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) &&
19076 (ref->item != NULL))
19078 gr = WXS_ATTR_GROUP_CAST ref->item;
19081 if (gr->flags & XML_SCHEMAS_ATTRGROUP_MARKED)
19084 * Mark as visited to avoid infinite recursion on
19085 * circular references not yet examined.
19087 if ((gr->attrUses) &&
19088 (gr->flags & XML_SCHEMAS_ATTRGROUP_HAS_REFS))
19090 gr->flags |= XML_SCHEMAS_ATTRGROUP_MARKED;
19091 circ = xmlSchemaCheckAttrGroupCircularRecur(ctxtGr,
19092 (xmlSchemaItemListPtr) gr->attrUses);
19093 gr->flags ^= XML_SCHEMAS_ATTRGROUP_MARKED;
19104 * xmlSchemaCheckAttrGroupCircular:
19105 * attrGr: the attribute group definition
19106 * @ctxt: the parser context
19109 * Checks for circular references of attribute groups.
19112 xmlSchemaCheckAttrGroupCircular(xmlSchemaAttributeGroupPtr attrGr,
19113 xmlSchemaParserCtxtPtr ctxt)
19116 * Schema Representation Constraint:
19117 * Attribute Group Definition Representation OK
19118 * 3 Circular group reference is disallowed outside <redefine>.
19119 * That is, unless this element information item's parent is
19120 * <redefine>, then among the [children], if any, there must
19121 * not be an <attributeGroup> with ref [attribute] which resolves
19122 * to the component corresponding to this <attributeGroup>. Indirect
19123 * circularity is also ruled out. That is, when QName resolution
19124 * (Schema Document) ($3.15.3) is applied to a `QName` arising from
19125 * any <attributeGroup>s with a ref [attribute] among the [children],
19126 * it must not be the case that a `QName` is encountered at any depth
19127 * which resolves to the component corresponding to this <attributeGroup>.
19129 if (attrGr->attrUses == NULL)
19131 else if ((attrGr->flags & XML_SCHEMAS_ATTRGROUP_HAS_REFS) == 0)
19134 xmlSchemaQNameRefPtr circ;
19136 circ = xmlSchemaCheckAttrGroupCircularRecur(attrGr,
19137 (xmlSchemaItemListPtr) attrGr->attrUses);
19138 if (circ != NULL) {
19139 xmlChar *str = NULL;
19141 * TODO: Report the referenced attr group as QName.
19143 xmlSchemaPCustomErr(ctxt,
19144 XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_3,
19145 NULL, WXS_ITEM_NODE(WXS_BASIC_CAST circ),
19146 "Circular reference to the attribute group '%s' "
19147 "defined", xmlSchemaGetComponentQName(&str, attrGr));
19148 FREE_AND_NULL(str);
19150 * NOTE: We will cut the reference to avoid further
19151 * confusion of the processor.
19152 * BADSPEC TODO: The spec should define how to process in this case.
19162 xmlSchemaAttributeGroupExpandRefs(xmlSchemaParserCtxtPtr pctxt,
19163 xmlSchemaAttributeGroupPtr attrGr);
19166 * xmlSchemaExpandAttributeGroupRefs:
19167 * @pctxt: the parser context
19168 * @node: the node of the component holding the attribute uses
19169 * @completeWild: the intersected wildcard to be returned
19170 * @list: the attribute uses
19172 * Substitutes contained attribute group references
19173 * for their attribute uses. Wilcards are intersected.
19174 * Attribute use prohibitions are removed from the list
19175 * and returned via the @prohibs list.
19176 * Pointlessness of attr. prohibs, if a matching attr. decl
19177 * is existent a well, are checked.
19180 xmlSchemaExpandAttributeGroupRefs(xmlSchemaParserCtxtPtr pctxt,
19181 xmlSchemaBasicItemPtr item,
19182 xmlSchemaWildcardPtr *completeWild,
19183 xmlSchemaItemListPtr list,
19184 xmlSchemaItemListPtr prohibs)
19186 xmlSchemaAttributeGroupPtr gr;
19187 xmlSchemaAttributeUsePtr use;
19188 xmlSchemaItemListPtr sublist;
19190 int created = (*completeWild == NULL) ? 0 : 1;
19193 prohibs->nbItems = 0;
19195 for (i = 0; i < list->nbItems; i++) {
19196 use = list->items[i];
19198 if (use->type == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB) {
19199 if (prohibs == NULL) {
19200 PERROR_INT("xmlSchemaExpandAttributeGroupRefs",
19201 "unexpected attr prohibition found");
19205 * Remove from attribute uses.
19207 if (xmlSchemaItemListRemove(list, i) == -1)
19211 * Note that duplicate prohibitions were already
19212 * handled at parsing time.
19215 * Add to list of prohibitions.
19217 xmlSchemaItemListAddSize(prohibs, 2, use);
19220 if ((use->type == XML_SCHEMA_EXTRA_QNAMEREF) &&
19221 ((WXS_QNAME_CAST use)->itemType == XML_SCHEMA_TYPE_ATTRIBUTEGROUP))
19223 if ((WXS_QNAME_CAST use)->item == NULL)
19225 gr = WXS_ATTR_GROUP_CAST (WXS_QNAME_CAST use)->item;
19227 * Expand the referenced attr. group.
19228 * TODO: remove this, this is done in a previous step, so
19229 * already done here.
19231 if ((gr->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED) == 0) {
19232 if (xmlSchemaAttributeGroupExpandRefs(pctxt, gr) == -1)
19236 * Build the 'complete' wildcard; i.e. intersect multiple
19239 if (gr->attributeWildcard != NULL) {
19240 if (*completeWild == NULL) {
19241 *completeWild = gr->attributeWildcard;
19244 xmlSchemaWildcardPtr tmpWild;
19247 * Copy the first encountered wildcard as context,
19248 * except for the annotation.
19250 * Although the complete wildcard might not correspond
19251 * to any node in the schema, we will anchor it on
19252 * the node of the owner component.
19254 tmpWild = xmlSchemaAddWildcard(pctxt, pctxt->schema,
19255 XML_SCHEMA_TYPE_ANY_ATTRIBUTE,
19256 WXS_ITEM_NODE(item));
19257 if (tmpWild == NULL)
19259 if (xmlSchemaCloneWildcardNsConstraints(pctxt,
19260 tmpWild, *completeWild) == -1)
19262 tmpWild->processContents = (*completeWild)->processContents;
19263 *completeWild = tmpWild;
19267 if (xmlSchemaIntersectWildcards(pctxt, *completeWild,
19268 gr->attributeWildcard) == -1)
19273 * Just remove the reference if the referenced group does not
19274 * contain any attribute uses.
19276 sublist = ((xmlSchemaItemListPtr) gr->attrUses);
19277 if ((sublist == NULL) || sublist->nbItems == 0) {
19278 if (xmlSchemaItemListRemove(list, i) == -1)
19284 * Add the attribute uses.
19286 list->items[i] = sublist->items[0];
19287 if (sublist->nbItems != 1) {
19288 for (j = 1; j < sublist->nbItems; j++) {
19290 if (xmlSchemaItemListInsert(list,
19291 sublist->items[j], i) == -1)
19299 * Handle pointless prohibitions of declared attributes.
19301 if (prohibs && (prohibs->nbItems != 0) && (list->nbItems != 0)) {
19302 xmlSchemaAttributeUseProhibPtr prohib;
19304 for (i = prohibs->nbItems -1; i >= 0; i--) {
19305 prohib = prohibs->items[i];
19306 for (j = 0; j < list->nbItems; j++) {
19307 use = list->items[j];
19309 if ((prohib->name == WXS_ATTRUSE_DECL_NAME(use)) &&
19310 (prohib->targetNamespace == WXS_ATTRUSE_DECL_TNS(use)))
19312 xmlChar *str = NULL;
19314 xmlSchemaCustomWarning(ACTXT_CAST pctxt,
19315 XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH,
19316 prohib->node, NULL,
19317 "Skipping pointless attribute use prohibition "
19318 "'%s', since a corresponding attribute use "
19319 "exists already in the type definition",
19320 xmlSchemaFormatQName(&str,
19321 prohib->targetNamespace, prohib->name),
19323 FREE_AND_NULL(str);
19325 * Remove the prohibition.
19327 if (xmlSchemaItemListRemove(prohibs, i) == -1)
19338 * xmlSchemaAttributeGroupExpandRefs:
19339 * @pctxt: the parser context
19340 * @attrGr: the attribute group definition
19343 * {attribute uses} property
19344 * {attribute wildcard} property
19346 * Substitutes contained attribute group references
19347 * for their attribute uses. Wilcards are intersected.
19350 xmlSchemaAttributeGroupExpandRefs(xmlSchemaParserCtxtPtr pctxt,
19351 xmlSchemaAttributeGroupPtr attrGr)
19353 if ((attrGr->attrUses == NULL) ||
19354 (attrGr->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED))
19357 attrGr->flags |= XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED;
19358 if (xmlSchemaExpandAttributeGroupRefs(pctxt, WXS_BASIC_CAST attrGr,
19359 &(attrGr->attributeWildcard), attrGr->attrUses, NULL) == -1)
19365 * xmlSchemaAttributeGroupExpandRefs:
19366 * @pctxt: the parser context
19367 * @attrGr: the attribute group definition
19369 * Substitutes contained attribute group references
19370 * for their attribute uses. Wilcards are intersected.
19372 * Schema Component Constraint:
19373 * Attribute Group Definition Properties Correct (ag-props-correct)
19376 xmlSchemaCheckAGPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
19377 xmlSchemaAttributeGroupPtr attrGr)
19380 * SPEC ag-props-correct
19381 * (1) "The values of the properties of an attribute group definition
19382 * must be as described in the property tableau in The Attribute
19383 * Group Definition Schema Component ($3.6.1), modulo the impact of
19384 * Missing Sub-components ($5.3);"
19387 if ((attrGr->attrUses != NULL) &&
19388 (WXS_LIST_CAST attrGr->attrUses)->nbItems > 1)
19390 xmlSchemaItemListPtr uses = WXS_LIST_CAST attrGr->attrUses;
19391 xmlSchemaAttributeUsePtr use, tmp;
19392 int i, j, hasId = 0;
19394 for (i = uses->nbItems -1; i >= 0; i--) {
19395 use = uses->items[i];
19397 * SPEC ag-props-correct
19398 * (2) "Two distinct members of the {attribute uses} must not have
19399 * {attribute declaration}s both of whose {name}s match and whose
19400 * {target namespace}s are identical."
19403 for (j = i -1; j >= 0; j--) {
19404 tmp = uses->items[j];
19405 if ((WXS_ATTRUSE_DECL_NAME(use) ==
19406 WXS_ATTRUSE_DECL_NAME(tmp)) &&
19407 (WXS_ATTRUSE_DECL_TNS(use) ==
19408 WXS_ATTRUSE_DECL_TNS(tmp)))
19410 xmlChar *str = NULL;
19412 xmlSchemaCustomErr(ACTXT_CAST pctxt,
19413 XML_SCHEMAP_AG_PROPS_CORRECT,
19414 attrGr->node, WXS_BASIC_CAST attrGr,
19416 xmlSchemaGetComponentDesignation(&str, use),
19418 FREE_AND_NULL(str);
19420 * Remove the duplicate.
19422 if (xmlSchemaItemListRemove(uses, i) == -1)
19429 * SPEC ag-props-correct
19430 * (3) "Two distinct members of the {attribute uses} must not have
19431 * {attribute declaration}s both of whose {type definition}s are or
19432 * are derived from ID."
19433 * TODO: Does 'derived' include member-types of unions?
19435 if (WXS_ATTRUSE_TYPEDEF(use) != NULL) {
19436 if (xmlSchemaIsDerivedFromBuiltInType(
19437 WXS_ATTRUSE_TYPEDEF(use), XML_SCHEMAS_ID))
19440 xmlChar *str = NULL;
19442 xmlSchemaCustomErr(ACTXT_CAST pctxt,
19443 XML_SCHEMAP_AG_PROPS_CORRECT,
19444 attrGr->node, WXS_BASIC_CAST attrGr,
19445 "There must not exist more than one attribute "
19446 "declaration of type 'xs:ID' "
19447 "(or derived from 'xs:ID'). The %s violates this "
19449 xmlSchemaGetComponentDesignation(&str, use),
19451 FREE_AND_NULL(str);
19452 if (xmlSchemaItemListRemove(uses, i) == -1)
19465 * xmlSchemaResolveAttrGroupReferences:
19466 * @attrgrpDecl: the schema attribute definition
19467 * @ctxt: the schema parser context
19468 * @name: the attribute name
19470 * Resolves references to attribute group definitions.
19473 xmlSchemaResolveAttrGroupReferences(xmlSchemaQNameRefPtr ref,
19474 xmlSchemaParserCtxtPtr ctxt)
19476 xmlSchemaAttributeGroupPtr group;
19478 if (ref->item != NULL)
19480 group = xmlSchemaGetAttributeGroup(ctxt->schema,
19482 ref->targetNamespace);
19483 if (group == NULL) {
19484 xmlSchemaPResCompAttrErr(ctxt,
19485 XML_SCHEMAP_SRC_RESOLVE,
19487 "ref", ref->name, ref->targetNamespace,
19488 ref->itemType, NULL);
19491 ref->item = WXS_BASIC_CAST group;
19496 * xmlSchemaCheckAttrPropsCorrect:
19497 * @item: an schema attribute declaration/use
19498 * @ctxt: a schema parser context
19499 * @name: the name of the attribute
19502 * Schema Component Constraint:
19503 * Attribute Declaration Properties Correct (a-props-correct)
19505 * Validates the value constraints of an attribute declaration/use.
19506 * NOTE that this needs the simle type definitions to be already
19507 * builded and checked.
19510 xmlSchemaCheckAttrPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
19511 xmlSchemaAttributePtr attr)
19515 * SPEC a-props-correct (1)
19516 * "The values of the properties of an attribute declaration must
19517 * be as described in the property tableau in The Attribute
19518 * Declaration Schema Component ($3.2.1), modulo the impact of
19519 * Missing Sub-components ($5.3)."
19522 if (WXS_ATTR_TYPEDEF(attr) == NULL)
19525 if (attr->defValue != NULL) {
19529 * SPEC a-props-correct (3)
19530 * "If the {type definition} is or is derived from ID then there
19531 * must not be a {value constraint}."
19533 if (xmlSchemaIsDerivedFromBuiltInType(
19534 WXS_ATTR_TYPEDEF(attr), XML_SCHEMAS_ID))
19536 xmlSchemaCustomErr(ACTXT_CAST pctxt,
19537 XML_SCHEMAP_A_PROPS_CORRECT_3,
19538 NULL, WXS_BASIC_CAST attr,
19539 "Value constraints are not allowed if the type definition "
19540 "is or is derived from xs:ID",
19542 return(pctxt->err);
19545 * SPEC a-props-correct (2)
19546 * "if there is a {value constraint}, the canonical lexical
19547 * representation of its value must be `valid` with respect
19548 * to the {type definition} as defined in String Valid ($3.14.4)."
19549 * TODO: Don't care about the *canonical* stuff here, this requirement
19550 * will be removed in WXS 1.1 anyway.
19552 ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt,
19553 attr->node, WXS_ATTR_TYPEDEF(attr),
19554 attr->defValue, &(attr->defVal),
19558 PERROR_INT("xmlSchemaCheckAttrPropsCorrect",
19559 "calling xmlSchemaVCheckCVCSimpleType()");
19562 xmlSchemaCustomErr(ACTXT_CAST pctxt,
19563 XML_SCHEMAP_A_PROPS_CORRECT_2,
19564 NULL, WXS_BASIC_CAST attr,
19565 "The value of the value constraint is not valid",
19567 return(pctxt->err);
19574 static xmlSchemaElementPtr
19575 xmlSchemaCheckSubstGroupCircular(xmlSchemaElementPtr elemDecl,
19576 xmlSchemaElementPtr ancestor)
19578 xmlSchemaElementPtr ret;
19580 if (WXS_SUBST_HEAD(ancestor) == NULL)
19582 if (WXS_SUBST_HEAD(ancestor) == elemDecl)
19585 if (WXS_SUBST_HEAD(ancestor)->flags & XML_SCHEMAS_ELEM_CIRCULAR)
19587 WXS_SUBST_HEAD(ancestor)->flags |= XML_SCHEMAS_ELEM_CIRCULAR;
19588 ret = xmlSchemaCheckSubstGroupCircular(elemDecl,
19589 WXS_SUBST_HEAD(ancestor));
19590 WXS_SUBST_HEAD(ancestor)->flags ^= XML_SCHEMAS_ELEM_CIRCULAR;
19596 * xmlSchemaCheckElemPropsCorrect:
19597 * @ctxt: a schema parser context
19598 * @decl: the element declaration
19599 * @name: the name of the attribute
19601 * Schema Component Constraint:
19602 * Element Declaration Properties Correct (e-props-correct)
19608 xmlSchemaCheckElemPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
19609 xmlSchemaElementPtr elemDecl)
19612 xmlSchemaTypePtr typeDef = WXS_ELEM_TYPEDEF(elemDecl);
19614 * SPEC (1) "The values of the properties of an element declaration
19615 * must be as described in the property tableau in The Element
19616 * Declaration Schema Component ($3.3.1), modulo the impact of Missing
19617 * Sub-components ($5.3)."
19619 if (WXS_SUBST_HEAD(elemDecl) != NULL) {
19620 xmlSchemaElementPtr head = WXS_SUBST_HEAD(elemDecl), circ;
19622 xmlSchemaCheckElementDeclComponent(head, pctxt);
19624 * SPEC (3) "If there is a non-`absent` {substitution group
19625 * affiliation}, then {scope} must be global."
19627 if ((elemDecl->flags & XML_SCHEMAS_ELEM_GLOBAL) == 0) {
19628 xmlSchemaPCustomErr(pctxt,
19629 XML_SCHEMAP_E_PROPS_CORRECT_3,
19630 WXS_BASIC_CAST elemDecl, NULL,
19631 "Only global element declarations can have a "
19632 "substitution group affiliation", NULL);
19633 ret = XML_SCHEMAP_E_PROPS_CORRECT_3;
19636 * TODO: SPEC (6) "Circular substitution groups are disallowed.
19637 * That is, it must not be possible to return to an element declaration
19638 * by repeatedly following the {substitution group affiliation}
19641 if (head == elemDecl)
19643 else if (WXS_SUBST_HEAD(head) != NULL)
19644 circ = xmlSchemaCheckSubstGroupCircular(head, head);
19647 if (circ != NULL) {
19648 xmlChar *strA = NULL, *strB = NULL;
19650 xmlSchemaPCustomErrExt(pctxt,
19651 XML_SCHEMAP_E_PROPS_CORRECT_6,
19652 WXS_BASIC_CAST circ, NULL,
19653 "The element declaration '%s' defines a circular "
19654 "substitution group to element declaration '%s'",
19655 xmlSchemaGetComponentQName(&strA, circ),
19656 xmlSchemaGetComponentQName(&strB, head),
19658 FREE_AND_NULL(strA)
19659 FREE_AND_NULL(strB)
19660 ret = XML_SCHEMAP_E_PROPS_CORRECT_6;
19663 * SPEC (4) "If there is a {substitution group affiliation},
19664 * the {type definition}
19665 * of the element declaration must be validly derived from the {type
19666 * definition} of the {substitution group affiliation}, given the value
19667 * of the {substitution group exclusions} of the {substitution group
19668 * affiliation}, as defined in Type Derivation OK (Complex) ($3.4.6)
19669 * (if the {type definition} is complex) or as defined in
19670 * Type Derivation OK (Simple) ($3.14.6) (if the {type definition} is
19673 * NOTE: {substitution group exclusions} means the values of the
19674 * attribute "final".
19677 if (typeDef != WXS_ELEM_TYPEDEF(WXS_SUBST_HEAD(elemDecl))) {
19680 if (head->flags & XML_SCHEMAS_ELEM_FINAL_EXTENSION)
19681 set |= SUBSET_EXTENSION;
19682 if (head->flags & XML_SCHEMAS_ELEM_FINAL_RESTRICTION)
19683 set |= SUBSET_RESTRICTION;
19685 if (xmlSchemaCheckCOSDerivedOK(ACTXT_CAST pctxt, typeDef,
19686 WXS_ELEM_TYPEDEF(head), set) != 0) {
19687 xmlChar *strA = NULL, *strB = NULL, *strC = NULL;
19689 ret = XML_SCHEMAP_E_PROPS_CORRECT_4;
19690 xmlSchemaPCustomErrExt(pctxt,
19691 XML_SCHEMAP_E_PROPS_CORRECT_4,
19692 WXS_BASIC_CAST elemDecl, NULL,
19693 "The type definition '%s' was "
19694 "either rejected by the substitution group "
19695 "affiliation '%s', or not validly derived from its type "
19697 xmlSchemaGetComponentQName(&strA, typeDef),
19698 xmlSchemaGetComponentQName(&strB, head),
19699 xmlSchemaGetComponentQName(&strC, WXS_ELEM_TYPEDEF(head)));
19700 FREE_AND_NULL(strA)
19701 FREE_AND_NULL(strB)
19702 FREE_AND_NULL(strC)
19707 * SPEC (5) "If the {type definition} or {type definition}'s
19709 * is or is derived from ID then there must not be a {value constraint}.
19710 * Note: The use of ID as a type definition for elements goes beyond
19711 * XML 1.0, and should be avoided if backwards compatibility is desired"
19713 if ((elemDecl->value != NULL) &&
19714 ((WXS_IS_SIMPLE(typeDef) &&
19715 xmlSchemaIsDerivedFromBuiltInType(typeDef, XML_SCHEMAS_ID)) ||
19716 (WXS_IS_COMPLEX(typeDef) &&
19717 WXS_HAS_SIMPLE_CONTENT(typeDef) &&
19718 xmlSchemaIsDerivedFromBuiltInType(typeDef->contentTypeDef,
19719 XML_SCHEMAS_ID)))) {
19721 ret = XML_SCHEMAP_E_PROPS_CORRECT_5;
19722 xmlSchemaPCustomErr(pctxt,
19723 XML_SCHEMAP_E_PROPS_CORRECT_5,
19724 WXS_BASIC_CAST elemDecl, NULL,
19725 "The type definition (or type definition's content type) is or "
19726 "is derived from ID; value constraints are not allowed in "
19727 "conjunction with such a type definition", NULL);
19728 } else if (elemDecl->value != NULL) {
19730 xmlNodePtr node = NULL;
19733 * SPEC (2) "If there is a {value constraint}, the canonical lexical
19734 * representation of its value must be `valid` with respect to the
19735 * {type definition} as defined in Element Default Valid (Immediate)
19738 if (typeDef == NULL) {
19739 xmlSchemaPErr(pctxt, elemDecl->node,
19740 XML_SCHEMAP_INTERNAL,
19741 "Internal error: xmlSchemaCheckElemPropsCorrect, "
19742 "type is missing... skipping validation of "
19743 "the value constraint", NULL, NULL);
19746 if (elemDecl->node != NULL) {
19747 if (elemDecl->flags & XML_SCHEMAS_ELEM_FIXED)
19748 node = (xmlNodePtr) xmlHasProp(elemDecl->node,
19751 node = (xmlNodePtr) xmlHasProp(elemDecl->node,
19752 BAD_CAST "default");
19754 vcret = xmlSchemaParseCheckCOSValidDefault(pctxt, node,
19755 typeDef, elemDecl->value, &(elemDecl->defVal));
19758 PERROR_INT("xmlSchemaElemCheckValConstr",
19759 "failed to validate the value constraint of an "
19760 "element declaration");
19771 * xmlSchemaCheckElemSubstGroup:
19772 * @ctxt: a schema parser context
19773 * @decl: the element declaration
19774 * @name: the name of the attribute
19776 * Schema Component Constraint:
19777 * Substitution Group (cos-equiv-class)
19779 * In Libxml2 the subst. groups will be precomputed, in terms of that
19780 * a list will be built for each subst. group head, holding all direct
19781 * referents to this head.
19782 * NOTE that this function needs:
19783 * 1. circular subst. groups to be checked beforehand
19784 * 2. the declaration's type to be derived from the head's type
19790 xmlSchemaCheckElemSubstGroup(xmlSchemaParserCtxtPtr ctxt,
19791 xmlSchemaElementPtr elemDecl)
19793 if ((WXS_SUBST_HEAD(elemDecl) == NULL) ||
19794 /* SPEC (1) "Its {abstract} is false." */
19795 (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT))
19798 xmlSchemaElementPtr head;
19799 xmlSchemaTypePtr headType, type;
19802 * SPEC (2) "It is validly substitutable for HEAD subject to HEAD's
19803 * {disallowed substitutions} as the blocking constraint, as defined in
19804 * Substitution Group OK (Transitive) ($3.3.6)."
19806 for (head = WXS_SUBST_HEAD(elemDecl); head != NULL;
19807 head = WXS_SUBST_HEAD(head)) {
19811 * The blocking constraints.
19813 if (head->flags & XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION)
19815 headType = head->subtypes;
19816 type = elemDecl->subtypes;
19817 if (headType == type)
19819 if (head->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION)
19820 set |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION;
19821 if (head->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION)
19822 set |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION;
19824 * SPEC: Substitution Group OK (Transitive) (2.3)
19825 * "The set of all {derivation method}s involved in the
19826 * derivation of D's {type definition} from C's {type definition}
19827 * does not intersect with the union of the blocking constraint,
19828 * C's {prohibited substitutions} (if C is complex, otherwise the
19829 * empty set) and the {prohibited substitutions} (respectively the
19830 * empty set) of any intermediate {type definition}s in the
19831 * derivation of D's {type definition} from C's {type definition}."
19834 * OPTIMIZE TODO: Optimize this a bit, since, if traversing the
19835 * subst.head axis, the methSet does not need to be computed for
19836 * the full depth over and over.
19839 * The set of all {derivation method}s involved in the derivation
19841 while ((type != NULL) && (type != headType)) {
19842 if ((WXS_IS_EXTENSION(type)) &&
19843 ((methSet & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) == 0))
19844 methSet |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION;
19846 if (WXS_IS_RESTRICTION(type) &&
19847 ((methSet & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) == 0))
19848 methSet |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION;
19850 type = type->baseType;
19853 * The {prohibited substitutions} of all intermediate types +
19856 type = elemDecl->subtypes->baseType;
19857 while (type != NULL) {
19858 if (WXS_IS_COMPLEX(type)) {
19860 XML_SCHEMAS_TYPE_BLOCK_EXTENSION) &&
19861 ((set & XML_SCHEMAS_TYPE_BLOCK_EXTENSION) == 0))
19862 set |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION;
19864 XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) &&
19865 ((set & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) == 0))
19866 set |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION;
19869 if (type == headType)
19871 type = type->baseType;
19874 (((set & XML_SCHEMAS_TYPE_BLOCK_EXTENSION) &&
19875 (methSet & XML_SCHEMAS_TYPE_BLOCK_EXTENSION)) ||
19876 ((set & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) &&
19877 (methSet & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION)))) {
19881 xmlSchemaAddElementSubstitutionMember(ctxt, head, elemDecl);
19882 if ((head->flags & XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD) == 0)
19883 head->flags |= XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD;
19888 #ifdef WXS_ELEM_DECL_CONS_ENABLED /* enable when finished */
19890 * xmlSchemaCheckElementDeclComponent
19891 * @pctxt: the schema parser context
19892 * @ctxtComponent: the context component (an element declaration)
19893 * @ctxtParticle: the first particle of the context component
19894 * @searchParticle: the element declaration particle to be analysed
19896 * Schema Component Constraint: Element Declarations Consistent
19899 xmlSchemaCheckElementDeclConsistent(xmlSchemaParserCtxtPtr pctxt,
19900 xmlSchemaBasicItemPtr ctxtComponent,
19901 xmlSchemaParticlePtr ctxtParticle,
19902 xmlSchemaParticlePtr searchParticle,
19903 xmlSchemaParticlePtr curParticle,
19909 xmlSchemaParticlePtr cur = curParticle;
19910 if (curParticle == NULL) {
19913 if (WXS_PARTICLE_TERM(curParticle) == NULL) {
19915 * Just return in this case. A missing "term" of the particle
19916 * might arise due to an invalid "term" component.
19920 while (cur != NULL) {
19921 switch (WXS_PARTICLE_TERM(cur)->type) {
19922 case XML_SCHEMA_TYPE_ANY:
19924 case XML_SCHEMA_TYPE_ELEMENT:
19926 ret = xmlSchemaCheckElementDeclConsistent(pctxt,
19927 ctxtComponent, ctxtParticle, cur, ctxtParticle, 1);
19931 xmlSchemaElementPtr elem =
19932 WXS_ELEM_CAST(WXS_PARTICLE_TERM(cur));
19934 * SPEC Element Declarations Consistent:
19935 * "If the {particles} contains, either directly,
19936 * indirectly (that is, within the {particles} of a
19937 * contained model group, recursively) or `implicitly`
19938 * two or more element declaration particles with
19939 * the same {name} and {target namespace}, then
19940 * all their type definitions must be the same
19941 * top-level definition [...]"
19943 if (xmlStrEqual(WXS_PARTICLE_TERM_AS_ELEM(cur)->name,
19944 WXS_PARTICLE_TERM_AS_ELEM(searchParticle)->name) &&
19945 xmlStrEqual(WXS_PARTICLE_TERM_AS_ELEM(cur)->targetNamespace,
19946 WXS_PARTICLE_TERM_AS_ELEM(searchParticle)->targetNamespace))
19948 xmlChar *strA = NULL, *strB = NULL;
19950 xmlSchemaCustomErr(ACTXT_CAST pctxt,
19951 /* TODO: error code */
19952 XML_SCHEMAP_COS_NONAMBIG,
19953 WXS_ITEM_NODE(cur), NULL,
19954 "In the content model of %s, there are multiple "
19955 "element declarations for '%s' with different "
19956 "type definitions",
19957 xmlSchemaGetComponentDesignation(&strA,
19959 xmlSchemaFormatQName(&strB,
19960 WXS_PARTICLE_TERM_AS_ELEM(cur)->targetNamespace,
19961 WXS_PARTICLE_TERM_AS_ELEM(cur)->name));
19962 FREE_AND_NULL(strA);
19963 FREE_AND_NULL(strB);
19964 return(XML_SCHEMAP_COS_NONAMBIG);
19968 case XML_SCHEMA_TYPE_SEQUENCE: {
19971 case XML_SCHEMA_TYPE_CHOICE:{
19973 xmlSchemaTreeItemPtr sub;
19975 sub = WXS_PARTICLE_TERM(particle)->children; (xmlSchemaParticlePtr)
19976 while (sub != NULL) {
19977 ret = xmlSchemaCheckElementDeclConsistent(pctxt, ctxtComponent,
19978 ctxtParticle, ctxtElem);
19986 case XML_SCHEMA_TYPE_ALL:
19988 case XML_SCHEMA_TYPE_GROUP:
19991 xmlSchemaInternalErr2(ACTXT_CAST pctxt,
19992 "xmlSchemaCheckElementDeclConsistent",
19993 "found unexpected term of type '%s' in content model",
19994 WXS_ITEM_TYPE_NAME(WXS_PARTICLE_TERM(cur)), NULL);
19997 cur = (xmlSchemaParticlePtr) cur->next;
20006 * xmlSchemaCheckElementDeclComponent
20007 * @item: an schema element declaration/particle
20008 * @ctxt: a schema parser context
20009 * @name: the name of the attribute
20011 * Validates the value constraints of an element declaration.
20012 * Adds substitution group members.
20015 xmlSchemaCheckElementDeclComponent(xmlSchemaElementPtr elemDecl,
20016 xmlSchemaParserCtxtPtr ctxt)
20018 if (elemDecl == NULL)
20020 if (elemDecl->flags & XML_SCHEMAS_ELEM_INTERNAL_CHECKED)
20022 elemDecl->flags |= XML_SCHEMAS_ELEM_INTERNAL_CHECKED;
20023 if (xmlSchemaCheckElemPropsCorrect(ctxt, elemDecl) == 0) {
20025 * Adds substitution group members.
20027 xmlSchemaCheckElemSubstGroup(ctxt, elemDecl);
20032 * xmlSchemaResolveModelGroupParticleReferences:
20033 * @particle: a particle component
20034 * @ctxt: a parser context
20036 * Resolves references of a model group's {particles} to
20037 * model group definitions and to element declarations.
20040 xmlSchemaResolveModelGroupParticleReferences(
20041 xmlSchemaParserCtxtPtr ctxt,
20042 xmlSchemaModelGroupPtr mg)
20044 xmlSchemaParticlePtr particle = WXS_MODELGROUP_PARTICLE(mg);
20045 xmlSchemaQNameRefPtr ref;
20046 xmlSchemaBasicItemPtr refItem;
20049 * URGENT TODO: Test this.
20051 while (particle != NULL) {
20052 if ((WXS_PARTICLE_TERM(particle) == NULL) ||
20053 ((WXS_PARTICLE_TERM(particle))->type !=
20054 XML_SCHEMA_EXTRA_QNAMEREF))
20056 goto next_particle;
20058 ref = WXS_QNAME_CAST WXS_PARTICLE_TERM(particle);
20060 * Resolve the reference.
20061 * NULL the {term} by default.
20063 particle->children = NULL;
20065 refItem = xmlSchemaGetNamedComponent(ctxt->schema,
20066 ref->itemType, ref->name, ref->targetNamespace);
20067 if (refItem == NULL) {
20068 xmlSchemaPResCompAttrErr(ctxt, XML_SCHEMAP_SRC_RESOLVE,
20069 NULL, WXS_ITEM_NODE(particle), "ref", ref->name,
20070 ref->targetNamespace, ref->itemType, NULL);
20071 /* TODO: remove the particle. */
20072 goto next_particle;
20074 if (refItem->type == XML_SCHEMA_TYPE_GROUP) {
20075 if (WXS_MODELGROUPDEF_MODEL(refItem) == NULL)
20076 /* TODO: remove the particle. */
20077 goto next_particle;
20079 * NOTE that we will assign the model group definition
20080 * itself to the "term" of the particle. This will ease
20081 * the check for circular model group definitions. After
20082 * that the "term" will be assigned the model group of the
20083 * model group definition.
20085 if ((WXS_MODELGROUPDEF_MODEL(refItem))->type ==
20086 XML_SCHEMA_TYPE_ALL) {
20088 * SPEC cos-all-limited (1)
20089 * SPEC cos-all-limited (1.2)
20090 * "It appears only as the value of one or both of the
20091 * following properties:"
20092 * (1.1) "the {model group} property of a model group
20094 * (1.2) "the {term} property of a particle [... of] the "
20095 * {content type} of a complex type definition."
20097 xmlSchemaCustomErr(ACTXT_CAST ctxt,
20098 /* TODO: error code */
20099 XML_SCHEMAP_COS_ALL_LIMITED,
20100 WXS_ITEM_NODE(particle), NULL,
20101 "A model group definition is referenced, but "
20102 "it contains an 'all' model group, which "
20103 "cannot be contained by model groups",
20105 /* TODO: remove the particle. */
20106 goto next_particle;
20108 particle->children = (xmlSchemaTreeItemPtr) refItem;
20111 * TODO: Are referenced element declarations the only
20112 * other components we expect here?
20114 particle->children = (xmlSchemaTreeItemPtr) refItem;
20117 particle = WXS_PTC_CAST particle->next;
20122 xmlSchemaAreValuesEqual(xmlSchemaValPtr x,
20125 xmlSchemaTypePtr tx, ty, ptx, pty;
20128 while (x != NULL) {
20130 tx = xmlSchemaGetBuiltInType(xmlSchemaGetValType(x));
20131 ty = xmlSchemaGetBuiltInType(xmlSchemaGetValType(y));
20132 ptx = xmlSchemaGetPrimitiveType(tx);
20133 pty = xmlSchemaGetPrimitiveType(ty);
20135 * (1) if a datatype T' is `derived` by `restriction` from an
20136 * atomic datatype T then the `value space` of T' is a subset of
20137 * the `value space` of T. */
20139 * (2) if datatypes T' and T'' are `derived` by `restriction`
20140 * from a common atomic ancestor T then the `value space`s of T'
20141 * and T'' may overlap.
20146 * We assume computed values to be normalized, so do a fast
20147 * string comparison for string based types.
20149 if ((ptx->builtInType == XML_SCHEMAS_STRING) ||
20150 WXS_IS_ANY_SIMPLE_TYPE(ptx)) {
20152 xmlSchemaValueGetAsString(x),
20153 xmlSchemaValueGetAsString(y)))
20156 ret = xmlSchemaCompareValuesWhtsp(
20157 x, XML_SCHEMA_WHITESPACE_PRESERVE,
20158 y, XML_SCHEMA_WHITESPACE_PRESERVE);
20167 x = xmlSchemaValueGetNext(x);
20169 y = xmlSchemaValueGetNext(y);
20172 } else if (xmlSchemaValueGetNext(y) != NULL)
20181 * xmlSchemaResolveAttrUseReferences:
20182 * @item: an attribute use
20183 * @ctxt: a parser context
20185 * Resolves the referenced attribute declaration.
20188 xmlSchemaResolveAttrUseReferences(xmlSchemaAttributeUsePtr ause,
20189 xmlSchemaParserCtxtPtr ctxt)
20191 if ((ctxt == NULL) || (ause == NULL))
20193 if ((ause->attrDecl == NULL) ||
20194 (ause->attrDecl->type != XML_SCHEMA_EXTRA_QNAMEREF))
20198 xmlSchemaQNameRefPtr ref = WXS_QNAME_CAST ause->attrDecl;
20201 * TODO: Evaluate, what errors could occur if the declaration is not
20204 ause->attrDecl = xmlSchemaGetAttributeDecl(ctxt->schema,
20205 ref->name, ref->targetNamespace);
20206 if (ause->attrDecl == NULL) {
20207 xmlSchemaPResCompAttrErr(ctxt,
20208 XML_SCHEMAP_SRC_RESOLVE,
20209 WXS_BASIC_CAST ause, ause->node,
20210 "ref", ref->name, ref->targetNamespace,
20211 XML_SCHEMA_TYPE_ATTRIBUTE, NULL);
20212 return(ctxt->err);;
20219 * xmlSchemaCheckAttrUsePropsCorrect:
20220 * @ctxt: a parser context
20221 * @use: an attribute use
20223 * Schema Component Constraint:
20224 * Attribute Use Correct (au-props-correct)
20228 xmlSchemaCheckAttrUsePropsCorrect(xmlSchemaParserCtxtPtr ctxt,
20229 xmlSchemaAttributeUsePtr use)
20231 if ((ctxt == NULL) || (use == NULL))
20233 if ((use->defValue == NULL) || (WXS_ATTRUSE_DECL(use) == NULL) ||
20234 ((WXS_ATTRUSE_DECL(use))->type != XML_SCHEMA_TYPE_ATTRIBUTE))
20238 * SPEC au-props-correct (1)
20239 * "The values of the properties of an attribute use must be as
20240 * described in the property tableau in The Attribute Use Schema
20241 * Component ($3.5.1), modulo the impact of Missing
20242 * Sub-components ($5.3)."
20245 if (((WXS_ATTRUSE_DECL(use))->defValue != NULL) &&
20246 ((WXS_ATTRUSE_DECL(use))->flags & XML_SCHEMAS_ATTR_FIXED) &&
20247 ((use->flags & XML_SCHEMA_ATTR_USE_FIXED) == 0))
20249 xmlSchemaPCustomErr(ctxt,
20250 XML_SCHEMAP_AU_PROPS_CORRECT_2,
20251 WXS_BASIC_CAST use, NULL,
20252 "The attribute declaration has a 'fixed' value constraint "
20253 ", thus the attribute use must also have a 'fixed' value "
20259 * Compute and check the value constraint's value.
20261 if ((use->defVal != NULL) && (WXS_ATTRUSE_TYPEDEF(use) != NULL)) {
20264 * TODO: The spec seems to be missing a check of the
20265 * value constraint of the attribute use. We will do it here.
20268 * SPEC a-props-correct (3)
20270 if (xmlSchemaIsDerivedFromBuiltInType(
20271 WXS_ATTRUSE_TYPEDEF(use), XML_SCHEMAS_ID))
20273 xmlSchemaCustomErr(ACTXT_CAST ctxt,
20274 XML_SCHEMAP_AU_PROPS_CORRECT,
20275 NULL, WXS_BASIC_CAST use,
20276 "Value constraints are not allowed if the type definition "
20277 "is or is derived from xs:ID",
20282 ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST ctxt,
20283 use->node, WXS_ATTRUSE_TYPEDEF(use),
20284 use->defValue, &(use->defVal),
20288 PERROR_INT2("xmlSchemaCheckAttrUsePropsCorrect",
20289 "calling xmlSchemaVCheckCVCSimpleType()");
20292 xmlSchemaCustomErr(ACTXT_CAST ctxt,
20293 XML_SCHEMAP_AU_PROPS_CORRECT,
20294 NULL, WXS_BASIC_CAST use,
20295 "The value of the value constraint is not valid",
20301 * SPEC au-props-correct (2)
20302 * "If the {attribute declaration} has a fixed
20303 * {value constraint}, then if the attribute use itself has a
20304 * {value constraint}, it must also be fixed and its value must match
20305 * that of the {attribute declaration}'s {value constraint}."
20307 if (((WXS_ATTRUSE_DECL(use))->defVal != NULL) &&
20308 (((WXS_ATTRUSE_DECL(use))->flags & XML_SCHEMA_ATTR_USE_FIXED) == 0))
20310 if (! xmlSchemaAreValuesEqual(use->defVal,
20311 (WXS_ATTRUSE_DECL(use))->defVal))
20313 xmlSchemaPCustomErr(ctxt,
20314 XML_SCHEMAP_AU_PROPS_CORRECT_2,
20315 WXS_BASIC_CAST use, NULL,
20316 "The 'fixed' value constraint of the attribute use "
20317 "must match the attribute declaration's value "
20319 (WXS_ATTRUSE_DECL(use))->defValue);
20330 * xmlSchemaResolveAttrTypeReferences:
20331 * @item: an attribute declaration
20332 * @ctxt: a parser context
20334 * Resolves the referenced type definition component.
20337 xmlSchemaResolveAttrTypeReferences(xmlSchemaAttributePtr item,
20338 xmlSchemaParserCtxtPtr ctxt)
20341 * The simple type definition corresponding to the <simpleType> element
20342 * information item in the [children], if present, otherwise the simple
20343 * type definition `resolved` to by the `actual value` of the type
20344 * [attribute], if present, otherwise the `simple ur-type definition`.
20346 if (item->flags & XML_SCHEMAS_ATTR_INTERNAL_RESOLVED)
20348 item->flags |= XML_SCHEMAS_ATTR_INTERNAL_RESOLVED;
20349 if (item->subtypes != NULL)
20351 if (item->typeName != NULL) {
20352 xmlSchemaTypePtr type;
20354 type = xmlSchemaGetType(ctxt->schema, item->typeName,
20356 if ((type == NULL) || (! WXS_IS_SIMPLE(type))) {
20357 xmlSchemaPResCompAttrErr(ctxt,
20358 XML_SCHEMAP_SRC_RESOLVE,
20359 WXS_BASIC_CAST item, item->node,
20360 "type", item->typeName, item->typeNs,
20361 XML_SCHEMA_TYPE_SIMPLE, NULL);
20364 item->subtypes = type;
20368 * The type defaults to the xs:anySimpleType.
20370 item->subtypes = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE);
20376 * xmlSchemaResolveIDCKeyReferences:
20377 * @idc: the identity-constraint definition
20378 * @ctxt: the schema parser context
20379 * @name: the attribute name
20381 * Resolve keyRef references to key/unique IDCs.
20382 * Schema Component Constraint:
20383 * Identity-constraint Definition Properties Correct (c-props-correct)
20386 xmlSchemaResolveIDCKeyReferences(xmlSchemaIDCPtr idc,
20387 xmlSchemaParserCtxtPtr pctxt)
20389 if (idc->type != XML_SCHEMA_TYPE_IDC_KEYREF)
20391 if (idc->ref->name != NULL) {
20392 idc->ref->item = (xmlSchemaBasicItemPtr)
20393 xmlSchemaGetIDC(pctxt->schema, idc->ref->name,
20394 idc->ref->targetNamespace);
20395 if (idc->ref->item == NULL) {
20397 * TODO: It is actually not an error to fail to resolve
20398 * at this stage. BUT we need to be that strict!
20400 xmlSchemaPResCompAttrErr(pctxt,
20401 XML_SCHEMAP_SRC_RESOLVE,
20402 WXS_BASIC_CAST idc, idc->node,
20403 "refer", idc->ref->name,
20404 idc->ref->targetNamespace,
20405 XML_SCHEMA_TYPE_IDC_KEY, NULL);
20406 return(pctxt->err);
20407 } else if (idc->ref->item->type == XML_SCHEMA_TYPE_IDC_KEYREF) {
20409 * SPEC c-props-correct (1)
20411 xmlSchemaCustomErr(ACTXT_CAST pctxt,
20412 XML_SCHEMAP_C_PROPS_CORRECT,
20413 NULL, WXS_BASIC_CAST idc,
20414 "The keyref references a keyref",
20416 idc->ref->item = NULL;
20417 return(pctxt->err);
20419 if (idc->nbFields !=
20420 ((xmlSchemaIDCPtr) idc->ref->item)->nbFields) {
20421 xmlChar *str = NULL;
20422 xmlSchemaIDCPtr refer;
20424 refer = (xmlSchemaIDCPtr) idc->ref->item;
20426 * SPEC c-props-correct(2)
20427 * "If the {identity-constraint category} is keyref,
20428 * the cardinality of the {fields} must equal that of
20429 * the {fields} of the {referenced key}.
20431 xmlSchemaCustomErr(ACTXT_CAST pctxt,
20432 XML_SCHEMAP_C_PROPS_CORRECT,
20433 NULL, WXS_BASIC_CAST idc,
20434 "The cardinality of the keyref differs from the "
20435 "cardinality of the referenced key/unique '%s'",
20436 xmlSchemaFormatQName(&str, refer->targetNamespace,
20440 return(pctxt->err);
20448 xmlSchemaResolveAttrUseProhibReferences(xmlSchemaAttributeUseProhibPtr prohib,
20449 xmlSchemaParserCtxtPtr pctxt)
20451 if (xmlSchemaGetAttributeDecl(pctxt->schema, prohib->name,
20452 prohib->targetNamespace) == NULL) {
20454 xmlSchemaPResCompAttrErr(pctxt,
20455 XML_SCHEMAP_SRC_RESOLVE,
20456 NULL, prohib->node,
20457 "ref", prohib->name, prohib->targetNamespace,
20458 XML_SCHEMA_TYPE_ATTRIBUTE, NULL);
20459 return(XML_SCHEMAP_SRC_RESOLVE);
20464 #define WXS_REDEFINED_TYPE(c) \
20465 (((xmlSchemaTypePtr) item)->flags & XML_SCHEMAS_TYPE_REDEFINED)
20467 #define WXS_REDEFINED_MODEL_GROUP_DEF(c) \
20468 (((xmlSchemaModelGroupDefPtr) item)->flags & XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED)
20470 #define WXS_REDEFINED_ATTR_GROUP(c) \
20471 (((xmlSchemaAttributeGroupPtr) item)->flags & XML_SCHEMAS_ATTRGROUP_REDEFINED)
20474 xmlSchemaCheckSRCRedefineFirst(xmlSchemaParserCtxtPtr pctxt)
20477 xmlSchemaRedefPtr redef = WXS_CONSTRUCTOR(pctxt)->redefs;
20478 xmlSchemaBasicItemPtr prev, item;
20485 item = redef->item;
20487 * First try to locate the redefined component in the
20488 * schema graph starting with the redefined schema.
20489 * NOTE: According to this schema bug entry:
20490 * http://lists.w3.org/Archives/Public/www-xml-schema-comments/2005OctDec/0019.html
20491 * it's not clear if the referenced component needs to originate
20492 * from the <redefine>d schema _document_ or the schema; the latter
20493 * would include all imported and included sub-schemas of the
20494 * <redefine>d schema. Currenlty we latter approach is used.
20495 * SUPPLEMENT: It seems that the WG moves towards the latter
20496 * approach, so we are doing it right.
20499 prev = xmlSchemaFindRedefCompInGraph(
20500 redef->targetBucket, item->type,
20501 redef->refName, redef->refTargetNs);
20502 if (prev == NULL) {
20503 xmlChar *str = NULL;
20507 * SPEC src-redefine:
20508 * (6.2.1) "The `actual value` of its own name attribute plus
20509 * target namespace must successfully `resolve` to a model
20510 * group definition in I."
20511 * (7.2.1) "The `actual value` of its own name attribute plus
20512 * target namespace must successfully `resolve` to an attribute
20513 * group definition in I."
20516 * Note that, if we are redefining with the use of references
20517 * to components, the spec assumes the src-resolve to be used;
20518 * but this won't assure that we search only *inside* the
20519 * redefined schema.
20521 if (redef->reference)
20522 node = WXS_ITEM_NODE(redef->reference);
20524 node = WXS_ITEM_NODE(item);
20525 xmlSchemaCustomErr(ACTXT_CAST pctxt,
20527 * TODO: error code.
20528 * Probably XML_SCHEMAP_SRC_RESOLVE, if this is using the
20531 XML_SCHEMAP_SRC_REDEFINE, node, NULL,
20532 "The %s '%s' to be redefined could not be found in "
20533 "the redefined schema",
20534 WXS_ITEM_TYPE_NAME(item),
20535 xmlSchemaFormatQName(&str, redef->refTargetNs,
20537 FREE_AND_NULL(str);
20539 redef = redef->next;
20543 * TODO: Obtaining and setting the redefinition state is really
20547 switch (item->type) {
20548 case XML_SCHEMA_TYPE_COMPLEX:
20549 case XML_SCHEMA_TYPE_SIMPLE:
20550 if ((WXS_TYPE_CAST prev)->flags &
20551 XML_SCHEMAS_TYPE_REDEFINED)
20556 /* Mark it as redefined. */
20557 (WXS_TYPE_CAST prev)->flags |= XML_SCHEMAS_TYPE_REDEFINED;
20559 * Assign the redefined type to the
20560 * base type of the redefining type.
20563 ((xmlSchemaTypePtr) item)->baseType =
20564 (xmlSchemaTypePtr) prev;
20566 case XML_SCHEMA_TYPE_GROUP:
20567 if ((WXS_MODEL_GROUPDEF_CAST prev)->flags &
20568 XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED)
20573 /* Mark it as redefined. */
20574 (WXS_MODEL_GROUPDEF_CAST prev)->flags |=
20575 XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED;
20576 if (redef->reference != NULL) {
20578 * Overwrite the QName-reference with the
20579 * referenced model group def.
20581 (WXS_PTC_CAST redef->reference)->children =
20582 WXS_TREE_CAST prev;
20584 redef->target = prev;
20586 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
20587 if ((WXS_ATTR_GROUP_CAST prev)->flags &
20588 XML_SCHEMAS_ATTRGROUP_REDEFINED)
20593 (WXS_ATTR_GROUP_CAST prev)->flags |=
20594 XML_SCHEMAS_ATTRGROUP_REDEFINED;
20595 if (redef->reference != NULL) {
20597 * Assign the redefined attribute group to the
20598 * QName-reference component.
20599 * This is the easy case, since we will just
20600 * expand the redefined group.
20602 (WXS_QNAME_CAST redef->reference)->item = prev;
20603 redef->target = NULL;
20606 * This is the complicated case: we need
20607 * to apply src-redefine (7.2.2) at a later
20608 * stage, i.e. when attribute group references
20609 * have beed expanded and simple types have
20612 redef->target = prev;
20616 PERROR_INT("xmlSchemaResolveRedefReferences",
20617 "Unexpected redefined component type");
20620 if (wasRedefined) {
20621 xmlChar *str = NULL;
20624 if (redef->reference)
20625 node = WXS_ITEM_NODE(redef->reference);
20627 node = WXS_ITEM_NODE(redef->item);
20629 xmlSchemaCustomErr(ACTXT_CAST pctxt,
20630 /* TODO: error code. */
20631 XML_SCHEMAP_SRC_REDEFINE,
20633 "The referenced %s was already redefined. Multiple "
20634 "redefinition of the same component is not supported",
20635 xmlSchemaGetComponentDesignation(&str, prev),
20639 redef = redef->next;
20642 redef = redef->next;
20643 } while (redef != NULL);
20649 xmlSchemaCheckSRCRedefineSecond(xmlSchemaParserCtxtPtr pctxt)
20652 xmlSchemaRedefPtr redef = WXS_CONSTRUCTOR(pctxt)->redefs;
20653 xmlSchemaBasicItemPtr item;
20659 if (redef->target == NULL) {
20660 redef = redef->next;
20663 item = redef->item;
20665 switch (item->type) {
20666 case XML_SCHEMA_TYPE_SIMPLE:
20667 case XML_SCHEMA_TYPE_COMPLEX:
20669 * Since the spec wants the {name} of the redefined
20670 * type to be 'absent', we'll NULL it.
20672 (WXS_TYPE_CAST redef->target)->name = NULL;
20675 * TODO: Seems like there's nothing more to do. The normal
20676 * inheritance mechanism is used. But not 100% sure.
20679 case XML_SCHEMA_TYPE_GROUP:
20682 * SPEC src-redefine:
20683 * (6.2.2) "The {model group} of the model group definition
20684 * which corresponds to it per XML Representation of Model
20685 * Group Definition Schema Components ($3.7.2) must be a
20686 * `valid restriction` of the {model group} of that model
20687 * group definition in I, as defined in Particle Valid
20688 * (Restriction) ($3.9.6)."
20691 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
20693 * SPEC src-redefine:
20694 * (7.2.2) "The {attribute uses} and {attribute wildcard} of
20695 * the attribute group definition which corresponds to it
20696 * per XML Representation of Attribute Group Definition Schema
20697 * Components ($3.6.2) must be `valid restrictions` of the
20698 * {attribute uses} and {attribute wildcard} of that attribute
20699 * group definition in I, as defined in clause 2, clause 3 and
20700 * clause 4 of Derivation Valid (Restriction, Complex)
20701 * ($3.4.6) (where references to the base type definition are
20702 * understood as references to the attribute group definition
20705 err = xmlSchemaCheckDerivationOKRestriction2to4(pctxt,
20706 XML_SCHEMA_ACTION_REDEFINE,
20707 item, redef->target,
20708 (WXS_ATTR_GROUP_CAST item)->attrUses,
20709 (WXS_ATTR_GROUP_CAST redef->target)->attrUses,
20710 (WXS_ATTR_GROUP_CAST item)->attributeWildcard,
20711 (WXS_ATTR_GROUP_CAST redef->target)->attributeWildcard);
20718 redef = redef->next;
20719 } while (redef != NULL);
20725 xmlSchemaAddComponents(xmlSchemaParserCtxtPtr pctxt,
20726 xmlSchemaBucketPtr bucket)
20728 xmlSchemaBasicItemPtr item;
20730 xmlHashTablePtr *table;
20731 const xmlChar *name;
20734 #define WXS_GET_GLOBAL_HASH(c, slot) { \
20735 if (WXS_IS_BUCKET_IMPMAIN((c)->type)) \
20736 table = &(WXS_IMPBUCKET((c))->schema->slot); \
20738 table = &(WXS_INCBUCKET((c))->ownerImport->schema->slot); }
20741 * Add global components to the schema's hash tables.
20742 * This is the place where duplicate components will be
20744 * TODO: I think normally we should support imports of the
20745 * same namespace from multiple locations. We don't do currently,
20746 * but if we do then according to:
20747 * http://www.w3.org/Bugs/Public/show_bug.cgi?id=2224
20748 * we would need, if imported directly, to import redefined
20749 * components as well to be able to catch clashing components.
20750 * (I hope I'll still know what this means after some months :-()
20752 if (bucket == NULL)
20754 if (bucket->flags & XML_SCHEMA_BUCKET_COMPS_ADDED)
20756 bucket->flags |= XML_SCHEMA_BUCKET_COMPS_ADDED;
20758 for (i = 0; i < bucket->globals->nbItems; i++) {
20759 item = bucket->globals->items[i];
20761 switch (item->type) {
20762 case XML_SCHEMA_TYPE_COMPLEX:
20763 case XML_SCHEMA_TYPE_SIMPLE:
20764 if (WXS_REDEFINED_TYPE(item))
20766 name = (WXS_TYPE_CAST item)->name;
20767 WXS_GET_GLOBAL_HASH(bucket, typeDecl)
20769 case XML_SCHEMA_TYPE_ELEMENT:
20770 name = (WXS_ELEM_CAST item)->name;
20771 WXS_GET_GLOBAL_HASH(bucket, elemDecl)
20773 case XML_SCHEMA_TYPE_ATTRIBUTE:
20774 name = (WXS_ATTR_CAST item)->name;
20775 WXS_GET_GLOBAL_HASH(bucket, attrDecl)
20777 case XML_SCHEMA_TYPE_GROUP:
20778 if (WXS_REDEFINED_MODEL_GROUP_DEF(item))
20780 name = (WXS_MODEL_GROUPDEF_CAST item)->name;
20781 WXS_GET_GLOBAL_HASH(bucket, groupDecl)
20783 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
20784 if (WXS_REDEFINED_ATTR_GROUP(item))
20786 name = (WXS_ATTR_GROUP_CAST item)->name;
20787 WXS_GET_GLOBAL_HASH(bucket, attrgrpDecl)
20789 case XML_SCHEMA_TYPE_IDC_KEY:
20790 case XML_SCHEMA_TYPE_IDC_UNIQUE:
20791 case XML_SCHEMA_TYPE_IDC_KEYREF:
20792 name = (WXS_IDC_CAST item)->name;
20793 WXS_GET_GLOBAL_HASH(bucket, idcDef)
20795 case XML_SCHEMA_TYPE_NOTATION:
20796 name = ((xmlSchemaNotationPtr) item)->name;
20797 WXS_GET_GLOBAL_HASH(bucket, notaDecl)
20800 PERROR_INT("xmlSchemaAddComponents",
20801 "Unexpected global component type");
20804 if (*table == NULL) {
20805 *table = xmlHashCreateDict(10, pctxt->dict);
20806 if (*table == NULL) {
20807 PERROR_INT("xmlSchemaAddComponents",
20808 "failed to create a component hash table");
20812 err = xmlHashAddEntry(*table, name, item);
20814 xmlChar *str = NULL;
20816 xmlSchemaCustomErr(ACTXT_CAST pctxt,
20817 XML_SCHEMAP_REDEFINED_TYPE,
20818 WXS_ITEM_NODE(item),
20819 WXS_BASIC_CAST item,
20820 "A global %s '%s' does already exist",
20821 WXS_ITEM_TYPE_NAME(item),
20822 xmlSchemaGetComponentQName(&str, item));
20823 FREE_AND_NULL(str);
20827 * Process imported/included schemas.
20829 if (bucket->relations != NULL) {
20830 xmlSchemaSchemaRelationPtr rel = bucket->relations;
20832 if ((rel->bucket != NULL) &&
20833 ((rel->bucket->flags & XML_SCHEMA_BUCKET_COMPS_ADDED) == 0)) {
20834 if (xmlSchemaAddComponents(pctxt, rel->bucket) == -1)
20838 } while (rel != NULL);
20844 xmlSchemaFixupComponents(xmlSchemaParserCtxtPtr pctxt,
20845 xmlSchemaBucketPtr rootBucket)
20847 xmlSchemaConstructionCtxtPtr con = pctxt->constructor;
20848 xmlSchemaTreeItemPtr item, *items;
20849 int nbItems, i, ret = 0;
20850 xmlSchemaBucketPtr oldbucket = con->bucket;
20851 xmlSchemaElementPtr elemDecl;
20853 #define FIXHFAILURE if (pctxt->err == XML_SCHEMAP_INTERNAL) goto exit_failure;
20855 if ((con->pending == NULL) ||
20856 (con->pending->nbItems == 0))
20860 * Since xmlSchemaFixupComplexType() will create new particles
20861 * (local components), and those particle components need a bucket
20862 * on the constructor, we'll assure here that the constructor has
20864 * TODO: Think about storing locals _only_ on the main bucket.
20866 if (con->bucket == NULL)
20867 con->bucket = rootBucket;
20870 * SPEC (src-redefine):
20871 * (6.2) "If it has no such self-reference, then all of the
20872 * following must be true:"
20874 * (6.2.2) The {model group} of the model group definition which
20875 * corresponds to it per XML Representation of Model Group
20876 * Definition Schema Components ($3.7.2) must be a `valid
20877 * restriction` of the {model group} of that model group definition
20878 * in I, as defined in Particle Valid (Restriction) ($3.9.6)."
20880 xmlSchemaCheckSRCRedefineFirst(pctxt);
20883 * Add global components to the schemata's hash tables.
20885 xmlSchemaAddComponents(pctxt, rootBucket);
20887 pctxt->ctxtType = NULL;
20888 items = (xmlSchemaTreeItemPtr *) con->pending->items;
20889 nbItems = con->pending->nbItems;
20891 * Now that we have parsed *all* the schema document(s) and converted
20892 * them to schema components, we can resolve references, apply component
20893 * constraints, create the FSA from the content model, etc.
20896 * Resolve references of..
20898 * 1. element declarations:
20899 * - the type definition
20900 * - the substitution group affiliation
20901 * 2. simple/complex types:
20902 * - the base type definition
20903 * - the memberTypes of union types
20904 * - the itemType of list types
20905 * 3. attributes declarations and attribute uses:
20906 * - the type definition
20907 * - if an attribute use, then the attribute declaration
20908 * 4. attribute group references:
20909 * - the attribute group definition
20911 * - the term of the particle (e.g. a model group)
20912 * 6. IDC key-references:
20913 * - the referenced IDC 'key' or 'unique' definition
20914 * 7. Attribute prohibitions which had a "ref" attribute.
20916 for (i = 0; i < nbItems; i++) {
20918 switch (item->type) {
20919 case XML_SCHEMA_TYPE_ELEMENT:
20920 xmlSchemaResolveElementReferences(
20921 (xmlSchemaElementPtr) item, pctxt);
20924 case XML_SCHEMA_TYPE_COMPLEX:
20925 case XML_SCHEMA_TYPE_SIMPLE:
20926 xmlSchemaResolveTypeReferences(
20927 (xmlSchemaTypePtr) item, pctxt);
20930 case XML_SCHEMA_TYPE_ATTRIBUTE:
20931 xmlSchemaResolveAttrTypeReferences(
20932 (xmlSchemaAttributePtr) item, pctxt);
20935 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
20936 xmlSchemaResolveAttrUseReferences(
20937 (xmlSchemaAttributeUsePtr) item, pctxt);
20940 case XML_SCHEMA_EXTRA_QNAMEREF:
20941 if ((WXS_QNAME_CAST item)->itemType ==
20942 XML_SCHEMA_TYPE_ATTRIBUTEGROUP)
20944 xmlSchemaResolveAttrGroupReferences(
20945 WXS_QNAME_CAST item, pctxt);
20949 case XML_SCHEMA_TYPE_SEQUENCE:
20950 case XML_SCHEMA_TYPE_CHOICE:
20951 case XML_SCHEMA_TYPE_ALL:
20952 xmlSchemaResolveModelGroupParticleReferences(pctxt,
20953 WXS_MODEL_GROUP_CAST item);
20956 case XML_SCHEMA_TYPE_IDC_KEY:
20957 case XML_SCHEMA_TYPE_IDC_UNIQUE:
20958 case XML_SCHEMA_TYPE_IDC_KEYREF:
20959 xmlSchemaResolveIDCKeyReferences(
20960 (xmlSchemaIDCPtr) item, pctxt);
20963 case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB:
20965 * Handle attribue prohibition which had a
20968 xmlSchemaResolveAttrUseProhibReferences(
20969 WXS_ATTR_PROHIB_CAST item, pctxt);
20976 if (pctxt->nberrors != 0)
20980 * Now that all references are resolved we
20981 * can check for circularity of...
20982 * 1. the base axis of type definitions
20983 * 2. nested model group definitions
20984 * 3. nested attribute group definitions
20985 * TODO: check for circual substitution groups.
20987 for (i = 0; i < nbItems; i++) {
20990 * Let's better stop on the first error here.
20992 switch (item->type) {
20993 case XML_SCHEMA_TYPE_COMPLEX:
20994 case XML_SCHEMA_TYPE_SIMPLE:
20995 xmlSchemaCheckTypeDefCircular(
20996 (xmlSchemaTypePtr) item, pctxt);
20998 if (pctxt->nberrors != 0)
21001 case XML_SCHEMA_TYPE_GROUP:
21002 xmlSchemaCheckGroupDefCircular(
21003 (xmlSchemaModelGroupDefPtr) item, pctxt);
21005 if (pctxt->nberrors != 0)
21008 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
21009 xmlSchemaCheckAttrGroupCircular(
21010 (xmlSchemaAttributeGroupPtr) item, pctxt);
21012 if (pctxt->nberrors != 0)
21019 if (pctxt->nberrors != 0)
21022 * Model group definition references:
21023 * Such a reference is reflected by a particle at the component
21024 * level. Until now the 'term' of such particles pointed
21025 * to the model group definition; this was done, in order to
21026 * ease circularity checks. Now we need to set the 'term' of
21027 * such particles to the model group of the model group definition.
21029 for (i = 0; i < nbItems; i++) {
21031 switch (item->type) {
21032 case XML_SCHEMA_TYPE_SEQUENCE:
21033 case XML_SCHEMA_TYPE_CHOICE:
21034 xmlSchemaModelGroupToModelGroupDefFixup(pctxt,
21035 WXS_MODEL_GROUP_CAST item);
21041 if (pctxt->nberrors != 0)
21044 * Expand attribute group references of attribute group definitions.
21046 for (i = 0; i < nbItems; i++) {
21048 switch (item->type) {
21049 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
21050 if ((! WXS_ATTR_GROUP_EXPANDED(item)) &&
21051 WXS_ATTR_GROUP_HAS_REFS(item))
21053 xmlSchemaAttributeGroupExpandRefs(pctxt,
21054 WXS_ATTR_GROUP_CAST item);
21062 if (pctxt->nberrors != 0)
21065 * First compute the variety of simple types. This is needed as
21066 * a seperate step, since otherwise we won't be able to detect
21067 * circular union types in all cases.
21069 for (i = 0; i < nbItems; i++) {
21071 switch (item->type) {
21072 case XML_SCHEMA_TYPE_SIMPLE:
21073 if (WXS_IS_TYPE_NOT_FIXED_1((xmlSchemaTypePtr) item)) {
21074 xmlSchemaFixupSimpleTypeStageOne(pctxt,
21075 (xmlSchemaTypePtr) item);
21083 if (pctxt->nberrors != 0)
21086 * Detect circular union types. Note that this needs the variety to
21087 * be already computed.
21089 for (i = 0; i < nbItems; i++) {
21091 switch (item->type) {
21092 case XML_SCHEMA_TYPE_SIMPLE:
21093 if (((xmlSchemaTypePtr) item)->memberTypes != NULL) {
21094 xmlSchemaCheckUnionTypeDefCircular(pctxt,
21095 (xmlSchemaTypePtr) item);
21103 if (pctxt->nberrors != 0)
21107 * Do the complete type fixup for simple types.
21109 for (i = 0; i < nbItems; i++) {
21111 switch (item->type) {
21112 case XML_SCHEMA_TYPE_SIMPLE:
21113 if (WXS_IS_TYPE_NOT_FIXED(WXS_TYPE_CAST item)) {
21114 xmlSchemaFixupSimpleTypeStageTwo(pctxt, WXS_TYPE_CAST item);
21122 if (pctxt->nberrors != 0)
21125 * At this point we need build and check all simple types.
21128 * Apply contraints for attribute declarations.
21130 for (i = 0; i < nbItems; i++) {
21132 switch (item->type) {
21133 case XML_SCHEMA_TYPE_ATTRIBUTE:
21134 xmlSchemaCheckAttrPropsCorrect(pctxt, WXS_ATTR_CAST item);
21141 if (pctxt->nberrors != 0)
21144 * Apply constraints for attribute uses.
21146 for (i = 0; i < nbItems; i++) {
21148 switch (item->type) {
21149 case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
21150 if (((xmlSchemaAttributeUsePtr)item)->defValue != NULL) {
21151 xmlSchemaCheckAttrUsePropsCorrect(pctxt,
21152 WXS_ATTR_USE_CAST item);
21160 if (pctxt->nberrors != 0)
21164 * Apply constraints for attribute group definitions.
21166 for (i = 0; i < nbItems; i++) {
21168 switch (item->type) {
21169 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
21170 if (( (WXS_ATTR_GROUP_CAST item)->attrUses != NULL) &&
21171 ( (WXS_LIST_CAST (WXS_ATTR_GROUP_CAST item)->attrUses)->nbItems > 1))
21173 xmlSchemaCheckAGPropsCorrect(pctxt, WXS_ATTR_GROUP_CAST item);
21181 if (pctxt->nberrors != 0)
21185 * Apply constraints for redefinitions.
21187 if (WXS_CONSTRUCTOR(pctxt)->redefs != NULL)
21188 xmlSchemaCheckSRCRedefineSecond(pctxt);
21189 if (pctxt->nberrors != 0)
21193 * Complex types are builded and checked.
21195 for (i = 0; i < nbItems; i++) {
21196 item = con->pending->items[i];
21197 switch (item->type) {
21198 case XML_SCHEMA_TYPE_COMPLEX:
21199 if (WXS_IS_TYPE_NOT_FIXED(WXS_TYPE_CAST item)) {
21200 xmlSchemaFixupComplexType(pctxt, WXS_TYPE_CAST item);
21208 if (pctxt->nberrors != 0)
21212 * The list could have changed, since xmlSchemaFixupComplexType()
21213 * will create particles and model groups in some cases.
21215 items = (xmlSchemaTreeItemPtr *) con->pending->items;
21216 nbItems = con->pending->nbItems;
21219 * Apply some constraints for element declarations.
21221 for (i = 0; i < nbItems; i++) {
21223 switch (item->type) {
21224 case XML_SCHEMA_TYPE_ELEMENT:
21225 elemDecl = (xmlSchemaElementPtr) item;
21227 if ((elemDecl->flags & XML_SCHEMAS_ELEM_INTERNAL_CHECKED) == 0)
21229 xmlSchemaCheckElementDeclComponent(
21230 (xmlSchemaElementPtr) elemDecl, pctxt);
21234 #ifdef WXS_ELEM_DECL_CONS_ENABLED
21236 * Schema Component Constraint: Element Declarations Consistent
21237 * Apply this constraint to local types of element declarations.
21239 if ((WXS_ELEM_TYPEDEF(elemDecl) != NULL) &&
21240 (WXS_IS_COMPLEX(WXS_ELEM_TYPEDEF(elemDecl))) &&
21241 (WXS_TYPE_IS_LOCAL(WXS_ELEM_TYPEDEF(elemDecl))))
21243 xmlSchemaCheckElementDeclConsistent(pctxt,
21244 WXS_BASIC_CAST elemDecl,
21245 WXS_TYPE_PARTICLE(WXS_ELEM_TYPEDEF(elemDecl)),
21254 if (pctxt->nberrors != 0)
21258 * Finally we can build the automaton from the content model of
21262 for (i = 0; i < nbItems; i++) {
21264 switch (item->type) {
21265 case XML_SCHEMA_TYPE_COMPLEX:
21266 xmlSchemaBuildContentModel((xmlSchemaTypePtr) item, pctxt);
21273 if (pctxt->nberrors != 0)
21276 * URGENT TODO: cos-element-consistent
21289 * Reset the constructor. This is needed for XSI acquisition, since
21290 * those items will be processed over and over again for every XSI
21291 * if not cleared here.
21293 con->bucket = oldbucket;
21294 con->pending->nbItems = 0;
21295 if (con->substGroups != NULL) {
21296 xmlHashFree(con->substGroups,
21297 (xmlHashDeallocator) xmlSchemaSubstGroupFree);
21298 con->substGroups = NULL;
21300 if (con->redefs != NULL) {
21301 xmlSchemaRedefListFree(con->redefs);
21302 con->redefs = NULL;
21308 * @ctxt: a schema validation context
21310 * parse a schema definition resource and build an internal
21311 * XML Shema struture which can be used to validate instances.
21313 * Returns the internal XML Schema structure built from the resource or
21314 * NULL in case of error
21317 xmlSchemaParse(xmlSchemaParserCtxtPtr ctxt)
21319 xmlSchemaPtr mainSchema = NULL;
21320 xmlSchemaBucketPtr bucket = NULL;
21324 * This one is used if the schema to be parsed was specified via
21325 * the API; i.e. not automatically by the validated instance document.
21328 xmlSchemaInitTypes();
21333 /* TODO: Init the context. Is this all we need?*/
21334 ctxt->nberrors = 0;
21338 /* Create the *main* schema. */
21339 mainSchema = xmlSchemaNewSchema(ctxt);
21340 if (mainSchema == NULL)
21343 * Create the schema constructor.
21345 if (ctxt->constructor == NULL) {
21346 ctxt->constructor = xmlSchemaConstructionCtxtCreate(ctxt->dict);
21347 if (ctxt->constructor == NULL)
21349 /* Take ownership of the constructor to be able to free it. */
21350 ctxt->ownsConstructor = 1;
21352 ctxt->constructor->mainSchema = mainSchema;
21354 * Locate and add the schema document.
21356 res = xmlSchemaAddSchemaDoc(ctxt, XML_SCHEMA_SCHEMA_MAIN,
21357 ctxt->URL, ctxt->doc, ctxt->buffer, ctxt->size, NULL,
21358 NULL, NULL, &bucket);
21364 if (bucket == NULL) {
21365 /* TODO: Error code, actually we failed to *locate* the schema. */
21367 xmlSchemaCustomErr(ACTXT_CAST ctxt, XML_SCHEMAP_FAILED_LOAD,
21369 "Failed to locate the main schema resource at '%s'",
21372 xmlSchemaCustomErr(ACTXT_CAST ctxt, XML_SCHEMAP_FAILED_LOAD,
21374 "Failed to locate the main schema resource",
21378 /* Then do the parsing for good. */
21379 if (xmlSchemaParseNewDocWithContext(ctxt, mainSchema, bucket) == -1)
21381 if (ctxt->nberrors != 0)
21384 mainSchema->doc = bucket->doc;
21385 mainSchema->preserve = ctxt->preserve;
21387 ctxt->schema = mainSchema;
21389 if (xmlSchemaFixupComponents(ctxt, WXS_CONSTRUCTOR(ctxt)->mainBucket) == -1)
21393 * TODO: This is not nice, since we cannot distinguish from the
21394 * result if there was an internal error or not.
21397 if (ctxt->nberrors != 0) {
21399 xmlSchemaFree(mainSchema);
21402 if (ctxt->constructor) {
21403 xmlSchemaConstructionCtxtFree(ctxt->constructor);
21404 ctxt->constructor = NULL;
21405 ctxt->ownsConstructor = 0;
21408 ctxt->schema = NULL;
21409 return(mainSchema);
21412 * Quite verbose, but should catch internal errors, which were
21413 * not communitated.
21416 xmlSchemaFree(mainSchema);
21419 if (ctxt->constructor) {
21420 xmlSchemaConstructionCtxtFree(ctxt->constructor);
21421 ctxt->constructor = NULL;
21422 ctxt->ownsConstructor = 0;
21424 PERROR_INT2("xmlSchemaParse",
21425 "An internal error occurred");
21426 ctxt->schema = NULL;
21431 * xmlSchemaSetParserErrors:
21432 * @ctxt: a schema validation context
21433 * @err: the error callback
21434 * @warn: the warning callback
21435 * @ctx: contextual data for the callbacks
21437 * Set the callback functions used to handle errors for a validation context
21440 xmlSchemaSetParserErrors(xmlSchemaParserCtxtPtr ctxt,
21441 xmlSchemaValidityErrorFunc err,
21442 xmlSchemaValidityWarningFunc warn, void *ctx)
21447 ctxt->warning = warn;
21448 ctxt->errCtxt = ctx;
21449 if (ctxt->vctxt != NULL)
21450 xmlSchemaSetValidErrors(ctxt->vctxt, err, warn, ctx);
21454 * xmlSchemaSetParserStructuredErrors:
21455 * @ctxt: a schema parser context
21456 * @serror: the structured error function
21457 * @ctx: the functions context
21459 * Set the structured error callback
21462 xmlSchemaSetParserStructuredErrors(xmlSchemaParserCtxtPtr ctxt,
21463 xmlStructuredErrorFunc serror,
21468 ctxt->serror = serror;
21469 ctxt->errCtxt = ctx;
21470 if (ctxt->vctxt != NULL)
21471 xmlSchemaSetValidStructuredErrors(ctxt->vctxt, serror, ctx);
21475 * xmlSchemaGetParserErrors:
21476 * @ctxt: a XMl-Schema parser context
21477 * @err: the error callback result
21478 * @warn: the warning callback result
21479 * @ctx: contextual data for the callbacks result
21481 * Get the callback information used to handle errors for a parser context
21483 * Returns -1 in case of failure, 0 otherwise
21486 xmlSchemaGetParserErrors(xmlSchemaParserCtxtPtr ctxt,
21487 xmlSchemaValidityErrorFunc * err,
21488 xmlSchemaValidityWarningFunc * warn, void **ctx)
21493 *err = ctxt->error;
21495 *warn = ctxt->warning;
21497 *ctx = ctxt->errCtxt;
21502 * xmlSchemaFacetTypeToString:
21503 * @type: the facet type
21505 * Convert the xmlSchemaTypeType to a char string.
21507 * Returns the char string representation of the facet type if the
21508 * type is a facet and an "Internal Error" string otherwise.
21510 static const xmlChar *
21511 xmlSchemaFacetTypeToString(xmlSchemaTypeType type)
21514 case XML_SCHEMA_FACET_PATTERN:
21515 return (BAD_CAST "pattern");
21516 case XML_SCHEMA_FACET_MAXEXCLUSIVE:
21517 return (BAD_CAST "maxExclusive");
21518 case XML_SCHEMA_FACET_MAXINCLUSIVE:
21519 return (BAD_CAST "maxInclusive");
21520 case XML_SCHEMA_FACET_MINEXCLUSIVE:
21521 return (BAD_CAST "minExclusive");
21522 case XML_SCHEMA_FACET_MININCLUSIVE:
21523 return (BAD_CAST "minInclusive");
21524 case XML_SCHEMA_FACET_WHITESPACE:
21525 return (BAD_CAST "whiteSpace");
21526 case XML_SCHEMA_FACET_ENUMERATION:
21527 return (BAD_CAST "enumeration");
21528 case XML_SCHEMA_FACET_LENGTH:
21529 return (BAD_CAST "length");
21530 case XML_SCHEMA_FACET_MAXLENGTH:
21531 return (BAD_CAST "maxLength");
21532 case XML_SCHEMA_FACET_MINLENGTH:
21533 return (BAD_CAST "minLength");
21534 case XML_SCHEMA_FACET_TOTALDIGITS:
21535 return (BAD_CAST "totalDigits");
21536 case XML_SCHEMA_FACET_FRACTIONDIGITS:
21537 return (BAD_CAST "fractionDigits");
21541 return (BAD_CAST "Internal Error");
21544 static xmlSchemaWhitespaceValueType
21545 xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type)
21548 * The normalization type can be changed only for types which are derived
21551 if (type->type == XML_SCHEMA_TYPE_BASIC) {
21553 * Note that we assume a whitespace of preserve for anySimpleType.
21555 if ((type->builtInType == XML_SCHEMAS_STRING) ||
21556 (type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE))
21557 return(XML_SCHEMA_WHITESPACE_PRESERVE);
21558 else if (type->builtInType == XML_SCHEMAS_NORMSTRING)
21559 return(XML_SCHEMA_WHITESPACE_REPLACE);
21562 * For all `atomic` datatypes other than string (and types `derived`
21563 * by `restriction` from it) the value of whiteSpace is fixed to
21565 * Note that this includes built-in list datatypes.
21567 return(XML_SCHEMA_WHITESPACE_COLLAPSE);
21569 } else if (WXS_IS_LIST(type)) {
21571 * For list types the facet "whiteSpace" is fixed to "collapse".
21573 return (XML_SCHEMA_WHITESPACE_COLLAPSE);
21574 } else if (WXS_IS_UNION(type)) {
21575 return (XML_SCHEMA_WHITESPACE_UNKNOWN);
21576 } else if (WXS_IS_ATOMIC(type)) {
21577 if (type->flags & XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE)
21578 return (XML_SCHEMA_WHITESPACE_PRESERVE);
21579 else if (type->flags & XML_SCHEMAS_TYPE_WHITESPACE_REPLACE)
21580 return (XML_SCHEMA_WHITESPACE_REPLACE);
21582 return (XML_SCHEMA_WHITESPACE_COLLAPSE);
21587 /************************************************************************
21589 * Simple type validation *
21591 ************************************************************************/
21594 /************************************************************************
21596 * DOM Validation code *
21598 ************************************************************************/
21601 * xmlSchemaAssembleByLocation:
21602 * @pctxt: a schema parser context
21603 * @vctxt: a schema validation context
21604 * @schema: the existing schema
21605 * @node: the node that fired the assembling
21606 * @nsName: the namespace name of the new schema
21607 * @location: the location of the schema
21609 * Expands an existing schema by an additional schema.
21611 * Returns 0 if the new schema is correct, a positive error code
21612 * number otherwise and -1 in case of an internal or API error.
21615 xmlSchemaAssembleByLocation(xmlSchemaValidCtxtPtr vctxt,
21616 xmlSchemaPtr schema,
21618 const xmlChar *nsName,
21619 const xmlChar *location)
21622 xmlSchemaParserCtxtPtr pctxt;
21623 xmlSchemaBucketPtr bucket = NULL;
21625 if ((vctxt == NULL) || (schema == NULL))
21628 if (vctxt->pctxt == NULL) {
21629 VERROR_INT("xmlSchemaAssembleByLocation",
21630 "no parser context available");
21633 pctxt = vctxt->pctxt;
21634 if (pctxt->constructor == NULL) {
21635 PERROR_INT("xmlSchemaAssembleByLocation",
21640 * Acquire the schema document.
21642 location = xmlSchemaBuildAbsoluteURI(pctxt->dict,
21645 * Note that we pass XML_SCHEMA_SCHEMA_IMPORT here;
21646 * the process will automatically change this to
21647 * XML_SCHEMA_SCHEMA_MAIN if it is the first schema document.
21649 ret = xmlSchemaAddSchemaDoc(pctxt, XML_SCHEMA_SCHEMA_IMPORT,
21650 location, NULL, NULL, 0, node, NULL, nsName,
21654 if (bucket == NULL) {
21656 * Generate a warning that the document could not be located.
21658 xmlSchemaCustomWarning(ACTXT_CAST vctxt, XML_SCHEMAV_MISC,
21660 "The document at location '%s' could not be acquired",
21661 location, NULL, NULL);
21665 * The first located schema will be handled as if all other
21666 * schemas imported by XSI were imported by this first schema.
21668 if ((bucket != NULL) &&
21669 (WXS_CONSTRUCTOR(pctxt)->bucket == NULL))
21670 WXS_CONSTRUCTOR(pctxt)->bucket = bucket;
21672 * TODO: Is this handled like an import? I.e. is it not an error
21673 * if the schema cannot be located?
21675 if ((bucket == NULL) || (! CAN_PARSE_SCHEMA(bucket)))
21678 * We will reuse the parser context for every schema imported
21679 * directly via XSI. So reset the context.
21681 pctxt->nberrors = 0;
21683 pctxt->doc = bucket->doc;
21685 ret = xmlSchemaParseNewDocWithContext(pctxt, schema, bucket);
21690 /* Paranoid error channelling. */
21691 if ((ret == 0) && (pctxt->nberrors != 0))
21693 if (pctxt->nberrors == 0) {
21695 * Only bother to fixup pending components, if there was
21697 * For every XSI acquired schema (and its sub-schemata) we will
21698 * fixup the components.
21700 xmlSchemaFixupComponents(pctxt, bucket);
21703 * Not nice, but we need somehow to channel the schema parser
21704 * error to the validation context.
21706 if ((ret != 0) && (vctxt->err == 0))
21708 vctxt->nberrors += pctxt->nberrors;
21710 /* Add to validation error sum. */
21711 vctxt->nberrors += pctxt->nberrors;
21720 static xmlSchemaAttrInfoPtr
21721 xmlSchemaGetMetaAttrInfo(xmlSchemaValidCtxtPtr vctxt,
21724 if (vctxt->nbAttrInfos == 0)
21728 xmlSchemaAttrInfoPtr iattr;
21730 for (i = 0; i < vctxt->nbAttrInfos; i++) {
21731 iattr = vctxt->attrInfos[i];
21732 if (iattr->metaType == metaType)
21741 * xmlSchemaAssembleByXSI:
21742 * @vctxt: a schema validation context
21744 * Expands an existing schema by an additional schema using
21745 * the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attribute
21746 * of an instance. If xsi:noNamespaceSchemaLocation is used, @noNamespace
21747 * must be set to 1.
21749 * Returns 0 if the new schema is correct, a positive error code
21750 * number otherwise and -1 in case of an internal or API error.
21753 xmlSchemaAssembleByXSI(xmlSchemaValidCtxtPtr vctxt)
21755 const xmlChar *cur, *end;
21756 const xmlChar *nsname = NULL, *location;
21759 xmlSchemaAttrInfoPtr iattr;
21762 * Parse the value; we will assume an even number of values
21763 * to be given (this is how Xerces and XSV work).
21765 * URGENT TODO: !! This needs to work for both
21766 * @noNamespaceSchemaLocation AND @schemaLocation on the same
21769 iattr = xmlSchemaGetMetaAttrInfo(vctxt,
21770 XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC);
21772 iattr = xmlSchemaGetMetaAttrInfo(vctxt,
21773 XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC);
21776 cur = iattr->value;
21779 * TODO: Move the string parsing mechanism away from here.
21781 if (iattr->metaType == XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC) {
21783 * Get the namespace name.
21785 while (IS_BLANK_CH(*cur))
21788 while ((*end != 0) && (!(IS_BLANK_CH(*end))))
21792 count++; /* TODO: Don't use the schema's dict. */
21793 nsname = xmlDictLookup(vctxt->schema->dict, cur, end - cur);
21799 while (IS_BLANK_CH(*cur))
21802 while ((*end != 0) && (!(IS_BLANK_CH(*end))))
21805 if (iattr->metaType ==
21806 XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC)
21809 * If using @schemaLocation then tuples are expected.
21810 * I.e. the namespace name *and* the document's URI.
21812 xmlSchemaCustomWarning(ACTXT_CAST vctxt, XML_SCHEMAV_MISC,
21814 "The value must consist of tuples: the target namespace "
21815 "name and the document's URI", NULL, NULL, NULL);
21819 count++; /* TODO: Don't use the schema's dict. */
21820 location = xmlDictLookup(vctxt->schema->dict, cur, end - cur);
21822 ret = xmlSchemaAssembleByLocation(vctxt, vctxt->schema,
21823 iattr->node, nsname, location);
21825 VERROR_INT("xmlSchemaAssembleByXSI",
21826 "assembling schemata");
21829 } while (*cur != 0);
21833 static const xmlChar *
21834 xmlSchemaLookupNamespace(xmlSchemaValidCtxtPtr vctxt,
21835 const xmlChar *prefix)
21837 if (vctxt->sax != NULL) {
21839 xmlSchemaNodeInfoPtr inode;
21841 for (i = vctxt->depth; i >= 0; i--) {
21842 if (vctxt->elemInfos[i]->nbNsBindings != 0) {
21843 inode = vctxt->elemInfos[i];
21844 for (j = 0; j < inode->nbNsBindings * 2; j += 2) {
21845 if (((prefix == NULL) &&
21846 (inode->nsBindings[j] == NULL)) ||
21847 ((prefix != NULL) && xmlStrEqual(prefix,
21848 inode->nsBindings[j]))) {
21851 * Note that the namespace bindings are already
21852 * in a string dict.
21854 return (inode->nsBindings[j+1]);
21860 #ifdef LIBXML_READER_ENABLED
21861 } else if (vctxt->reader != NULL) {
21864 nsName = xmlTextReaderLookupNamespace(vctxt->reader, prefix);
21865 if (nsName != NULL) {
21866 const xmlChar *ret;
21868 ret = xmlDictLookup(vctxt->dict, nsName, -1);
21877 if ((vctxt->inode->node == NULL) ||
21878 (vctxt->inode->node->doc == NULL)) {
21879 VERROR_INT("xmlSchemaLookupNamespace",
21880 "no node or node's doc avaliable");
21883 ns = xmlSearchNs(vctxt->inode->node->doc,
21884 vctxt->inode->node, prefix);
21892 * This one works on the schema of the validation context.
21895 xmlSchemaValidateNotation(xmlSchemaValidCtxtPtr vctxt,
21896 xmlSchemaPtr schema,
21898 const xmlChar *value,
21899 xmlSchemaValPtr *val,
21904 if (vctxt && (vctxt->schema == NULL)) {
21905 VERROR_INT("xmlSchemaValidateNotation",
21906 "a schema is needed on the validation context");
21909 ret = xmlValidateQName(value, 1);
21913 xmlChar *localName = NULL;
21914 xmlChar *prefix = NULL;
21916 localName = xmlSplitQName2(value, &prefix);
21917 if (prefix != NULL) {
21918 const xmlChar *nsName = NULL;
21921 nsName = xmlSchemaLookupNamespace(vctxt, BAD_CAST prefix);
21922 else if (node != NULL) {
21923 xmlNsPtr ns = xmlSearchNs(node->doc, node, prefix);
21928 xmlFree(localName);
21931 if (nsName == NULL) {
21933 xmlFree(localName);
21936 if (xmlSchemaGetNotation(schema, localName, nsName) != NULL) {
21937 if ((valNeeded) && (val != NULL)) {
21938 (*val) = xmlSchemaNewNOTATIONValue(xmlStrdup(localName),
21939 xmlStrdup(nsName));
21946 xmlFree(localName);
21948 if (xmlSchemaGetNotation(schema, value, NULL) != NULL) {
21949 if (valNeeded && (val != NULL)) {
21950 (*val) = xmlSchemaNewNOTATIONValue(
21951 BAD_CAST xmlStrdup(value), NULL);
21963 xmlSchemaVAddNodeQName(xmlSchemaValidCtxtPtr vctxt,
21964 const xmlChar* lname,
21965 const xmlChar* nsname)
21969 lname = xmlDictLookup(vctxt->dict, lname, -1);
21972 if (nsname != NULL) {
21973 nsname = xmlDictLookup(vctxt->dict, nsname, -1);
21974 if (nsname == NULL)
21977 for (i = 0; i < vctxt->nodeQNames->nbItems; i += 2) {
21978 if ((vctxt->nodeQNames->items [i] == lname) &&
21979 (vctxt->nodeQNames->items[i +1] == nsname))
21980 /* Already there */
21983 /* Add new entry. */
21984 i = vctxt->nodeQNames->nbItems;
21985 xmlSchemaItemListAdd(vctxt->nodeQNames, (void *) lname);
21986 xmlSchemaItemListAdd(vctxt->nodeQNames, (void *) nsname);
21990 /************************************************************************
21992 * Validation of identity-constraints (IDC) *
21994 ************************************************************************/
21997 * xmlSchemaAugmentIDC:
21998 * @idcDef: the IDC definition
22000 * Creates an augmented IDC definition item.
22002 * Returns the item, or NULL on internal errors.
22005 xmlSchemaAugmentIDC(xmlSchemaIDCPtr idcDef,
22006 xmlSchemaValidCtxtPtr vctxt)
22008 xmlSchemaIDCAugPtr aidc;
22010 aidc = (xmlSchemaIDCAugPtr) xmlMalloc(sizeof(xmlSchemaIDCAug));
22011 if (aidc == NULL) {
22012 xmlSchemaVErrMemory(vctxt,
22013 "xmlSchemaAugmentIDC: allocating an augmented IDC definition",
22017 aidc->keyrefDepth = -1;
22018 aidc->def = idcDef;
22020 if (vctxt->aidcs == NULL)
22021 vctxt->aidcs = aidc;
22023 aidc->next = vctxt->aidcs;
22024 vctxt->aidcs = aidc;
22027 * Save if we have keyrefs at all.
22029 if ((vctxt->hasKeyrefs == 0) &&
22030 (idcDef->type == XML_SCHEMA_TYPE_IDC_KEYREF))
22031 vctxt->hasKeyrefs = 1;
22035 * xmlSchemaAugmentImportedIDC:
22036 * @imported: the imported schema
22038 * Creates an augmented IDC definition for the imported schema.
22041 xmlSchemaAugmentImportedIDC(xmlSchemaImportPtr imported, xmlSchemaValidCtxtPtr vctxt, xmlChar *name ATTRIBUTE_UNUSED) {
22042 if (imported->schema->idcDef != NULL) {
22043 xmlHashScan(imported->schema->idcDef ,
22044 (xmlHashScanner) xmlSchemaAugmentIDC, vctxt);
22049 * xmlSchemaIDCNewBinding:
22050 * @idcDef: the IDC definition of this binding
22052 * Creates a new IDC binding.
22054 * Returns the new IDC binding, NULL on internal errors.
22056 static xmlSchemaPSVIIDCBindingPtr
22057 xmlSchemaIDCNewBinding(xmlSchemaIDCPtr idcDef)
22059 xmlSchemaPSVIIDCBindingPtr ret;
22061 ret = (xmlSchemaPSVIIDCBindingPtr) xmlMalloc(
22062 sizeof(xmlSchemaPSVIIDCBinding));
22064 xmlSchemaVErrMemory(NULL,
22065 "allocating a PSVI IDC binding item", NULL);
22068 memset(ret, 0, sizeof(xmlSchemaPSVIIDCBinding));
22069 ret->definition = idcDef;
22074 * xmlSchemaIDCStoreNodeTableItem:
22075 * @vctxt: the WXS validation context
22076 * @item: the IDC node table item
22078 * The validation context is used to store IDC node table items.
22079 * They are stored to avoid copying them if IDC node-tables are merged
22080 * with corresponding parent IDC node-tables (bubbling).
22082 * Returns 0 if succeeded, -1 on internal errors.
22085 xmlSchemaIDCStoreNodeTableItem(xmlSchemaValidCtxtPtr vctxt,
22086 xmlSchemaPSVIIDCNodePtr item)
22089 * Add to gobal list.
22091 if (vctxt->idcNodes == NULL) {
22092 vctxt->idcNodes = (xmlSchemaPSVIIDCNodePtr *)
22093 xmlMalloc(20 * sizeof(xmlSchemaPSVIIDCNodePtr));
22094 if (vctxt->idcNodes == NULL) {
22095 xmlSchemaVErrMemory(vctxt,
22096 "allocating the IDC node table item list", NULL);
22099 vctxt->sizeIdcNodes = 20;
22100 } else if (vctxt->sizeIdcNodes <= vctxt->nbIdcNodes) {
22101 vctxt->sizeIdcNodes *= 2;
22102 vctxt->idcNodes = (xmlSchemaPSVIIDCNodePtr *)
22103 xmlRealloc(vctxt->idcNodes, vctxt->sizeIdcNodes *
22104 sizeof(xmlSchemaPSVIIDCNodePtr));
22105 if (vctxt->idcNodes == NULL) {
22106 xmlSchemaVErrMemory(vctxt,
22107 "re-allocating the IDC node table item list", NULL);
22111 vctxt->idcNodes[vctxt->nbIdcNodes++] = item;
22117 * xmlSchemaIDCStoreKey:
22118 * @vctxt: the WXS validation context
22119 * @item: the IDC key
22121 * The validation context is used to store an IDC key.
22123 * Returns 0 if succeeded, -1 on internal errors.
22126 xmlSchemaIDCStoreKey(xmlSchemaValidCtxtPtr vctxt,
22127 xmlSchemaPSVIIDCKeyPtr key)
22130 * Add to gobal list.
22132 if (vctxt->idcKeys == NULL) {
22133 vctxt->idcKeys = (xmlSchemaPSVIIDCKeyPtr *)
22134 xmlMalloc(40 * sizeof(xmlSchemaPSVIIDCKeyPtr));
22135 if (vctxt->idcKeys == NULL) {
22136 xmlSchemaVErrMemory(vctxt,
22137 "allocating the IDC key storage list", NULL);
22140 vctxt->sizeIdcKeys = 40;
22141 } else if (vctxt->sizeIdcKeys <= vctxt->nbIdcKeys) {
22142 vctxt->sizeIdcKeys *= 2;
22143 vctxt->idcKeys = (xmlSchemaPSVIIDCKeyPtr *)
22144 xmlRealloc(vctxt->idcKeys, vctxt->sizeIdcKeys *
22145 sizeof(xmlSchemaPSVIIDCKeyPtr));
22146 if (vctxt->idcKeys == NULL) {
22147 xmlSchemaVErrMemory(vctxt,
22148 "re-allocating the IDC key storage list", NULL);
22152 vctxt->idcKeys[vctxt->nbIdcKeys++] = key;
22158 * xmlSchemaIDCAppendNodeTableItem:
22159 * @bind: the IDC binding
22160 * @ntItem: the node-table item
22162 * Appends the IDC node-table item to the binding.
22164 * Returns 0 on success and -1 on internal errors.
22167 xmlSchemaIDCAppendNodeTableItem(xmlSchemaPSVIIDCBindingPtr bind,
22168 xmlSchemaPSVIIDCNodePtr ntItem)
22170 if (bind->nodeTable == NULL) {
22171 bind->sizeNodes = 10;
22172 bind->nodeTable = (xmlSchemaPSVIIDCNodePtr *)
22173 xmlMalloc(10 * sizeof(xmlSchemaPSVIIDCNodePtr));
22174 if (bind->nodeTable == NULL) {
22175 xmlSchemaVErrMemory(NULL,
22176 "allocating an array of IDC node-table items", NULL);
22179 } else if (bind->sizeNodes <= bind->nbNodes) {
22180 bind->sizeNodes *= 2;
22181 bind->nodeTable = (xmlSchemaPSVIIDCNodePtr *)
22182 xmlRealloc(bind->nodeTable, bind->sizeNodes *
22183 sizeof(xmlSchemaPSVIIDCNodePtr));
22184 if (bind->nodeTable == NULL) {
22185 xmlSchemaVErrMemory(NULL,
22186 "re-allocating an array of IDC node-table items", NULL);
22190 bind->nodeTable[bind->nbNodes++] = ntItem;
22195 * xmlSchemaIDCAcquireBinding:
22196 * @vctxt: the WXS validation context
22197 * @matcher: the IDC matcher
22199 * Looks up an PSVI IDC binding, for the IDC definition and
22200 * of the given matcher. If none found, a new one is created
22201 * and added to the IDC table.
22203 * Returns an IDC binding or NULL on internal errors.
22205 static xmlSchemaPSVIIDCBindingPtr
22206 xmlSchemaIDCAcquireBinding(xmlSchemaValidCtxtPtr vctxt,
22207 xmlSchemaIDCMatcherPtr matcher)
22209 xmlSchemaNodeInfoPtr ielem;
22211 ielem = vctxt->elemInfos[matcher->depth];
22213 if (ielem->idcTable == NULL) {
22214 ielem->idcTable = xmlSchemaIDCNewBinding(matcher->aidc->def);
22215 if (ielem->idcTable == NULL)
22217 return(ielem->idcTable);
22219 xmlSchemaPSVIIDCBindingPtr bind = NULL;
22221 bind = ielem->idcTable;
22223 if (bind->definition == matcher->aidc->def)
22225 if (bind->next == NULL) {
22226 bind->next = xmlSchemaIDCNewBinding(matcher->aidc->def);
22227 if (bind->next == NULL)
22229 return(bind->next);
22232 } while (bind != NULL);
22237 static xmlSchemaItemListPtr
22238 xmlSchemaIDCAcquireTargetList(xmlSchemaValidCtxtPtr vctxt ATTRIBUTE_UNUSED,
22239 xmlSchemaIDCMatcherPtr matcher)
22241 if (matcher->targets == NULL)
22242 matcher->targets = xmlSchemaItemListCreate();
22243 return(matcher->targets);
22247 * xmlSchemaIDCFreeKey:
22248 * @key: the IDC key
22250 * Frees an IDC key together with its compiled value.
22253 xmlSchemaIDCFreeKey(xmlSchemaPSVIIDCKeyPtr key)
22255 if (key->val != NULL)
22256 xmlSchemaFreeValue(key->val);
22261 * xmlSchemaIDCFreeBinding:
22263 * Frees an IDC binding. Note that the node table-items
22267 xmlSchemaIDCFreeBinding(xmlSchemaPSVIIDCBindingPtr bind)
22269 if (bind->nodeTable != NULL)
22270 xmlFree(bind->nodeTable);
22271 if (bind->dupls != NULL)
22272 xmlSchemaItemListFree(bind->dupls);
22277 * xmlSchemaIDCFreeIDCTable:
22278 * @bind: the first IDC binding in the list
22280 * Frees an IDC table, i.e. all the IDC bindings in the list.
22283 xmlSchemaIDCFreeIDCTable(xmlSchemaPSVIIDCBindingPtr bind)
22285 xmlSchemaPSVIIDCBindingPtr prev;
22287 while (bind != NULL) {
22290 xmlSchemaIDCFreeBinding(prev);
22295 * xmlSchemaIDCFreeMatcherList:
22296 * @matcher: the first IDC matcher in the list
22298 * Frees a list of IDC matchers.
22301 xmlSchemaIDCFreeMatcherList(xmlSchemaIDCMatcherPtr matcher)
22303 xmlSchemaIDCMatcherPtr next;
22305 while (matcher != NULL) {
22306 next = matcher->next;
22307 if (matcher->keySeqs != NULL) {
22309 for (i = 0; i < matcher->sizeKeySeqs; i++)
22310 if (matcher->keySeqs[i] != NULL)
22311 xmlFree(matcher->keySeqs[i]);
22312 xmlFree(matcher->keySeqs);
22314 if (matcher->targets != NULL) {
22315 if (matcher->idcType == XML_SCHEMA_TYPE_IDC_KEYREF) {
22317 xmlSchemaPSVIIDCNodePtr idcNode;
22319 * Node-table items for keyrefs are not stored globally
22320 * to the validation context, since they are not bubbled.
22321 * We need to free them here.
22323 for (i = 0; i < matcher->targets->nbItems; i++) {
22325 (xmlSchemaPSVIIDCNodePtr) matcher->targets->items[i];
22326 xmlFree(idcNode->keys);
22330 xmlSchemaItemListFree(matcher->targets);
22338 * xmlSchemaIDCReleaseMatcherList:
22339 * @vctxt: the WXS validation context
22340 * @matcher: the first IDC matcher in the list
22342 * Caches a list of IDC matchers for reuse.
22345 xmlSchemaIDCReleaseMatcherList(xmlSchemaValidCtxtPtr vctxt,
22346 xmlSchemaIDCMatcherPtr matcher)
22348 xmlSchemaIDCMatcherPtr next;
22350 while (matcher != NULL) {
22351 next = matcher->next;
22352 if (matcher->keySeqs != NULL) {
22355 * Don't free the array, but only the content.
22357 for (i = 0; i < matcher->sizeKeySeqs; i++)
22358 if (matcher->keySeqs[i] != NULL) {
22359 xmlFree(matcher->keySeqs[i]);
22360 matcher->keySeqs[i] = NULL;
22363 if (matcher->targets) {
22364 if (matcher->idcType == XML_SCHEMA_TYPE_IDC_KEYREF) {
22366 xmlSchemaPSVIIDCNodePtr idcNode;
22368 * Node-table items for keyrefs are not stored globally
22369 * to the validation context, since they are not bubbled.
22370 * We need to free them here.
22372 for (i = 0; i < matcher->targets->nbItems; i++) {
22374 (xmlSchemaPSVIIDCNodePtr) matcher->targets->items[i];
22375 xmlFree(idcNode->keys);
22379 xmlSchemaItemListFree(matcher->targets);
22380 matcher->targets = NULL;
22382 matcher->next = NULL;
22384 * Cache the matcher.
22386 if (vctxt->idcMatcherCache != NULL)
22387 matcher->nextCached = vctxt->idcMatcherCache;
22388 vctxt->idcMatcherCache = matcher;
22395 * xmlSchemaIDCAddStateObject:
22396 * @vctxt: the WXS validation context
22397 * @matcher: the IDC matcher
22398 * @sel: the XPath information
22399 * @parent: the parent "selector" state object if any
22400 * @type: "selector" or "field"
22402 * Creates/reuses and activates state objects for the given
22403 * XPath information; if the XPath expression consists of unions,
22404 * multiple state objects are created for every unioned expression.
22406 * Returns 0 on success and -1 on internal errors.
22409 xmlSchemaIDCAddStateObject(xmlSchemaValidCtxtPtr vctxt,
22410 xmlSchemaIDCMatcherPtr matcher,
22411 xmlSchemaIDCSelectPtr sel,
22414 xmlSchemaIDCStateObjPtr sto;
22417 * Reuse the state objects from the pool.
22419 if (vctxt->xpathStatePool != NULL) {
22420 sto = vctxt->xpathStatePool;
22421 vctxt->xpathStatePool = sto->next;
22425 * Create a new state object.
22427 sto = (xmlSchemaIDCStateObjPtr) xmlMalloc(sizeof(xmlSchemaIDCStateObj));
22429 xmlSchemaVErrMemory(NULL,
22430 "allocating an IDC state object", NULL);
22433 memset(sto, 0, sizeof(xmlSchemaIDCStateObj));
22436 * Add to global list.
22438 if (vctxt->xpathStates != NULL)
22439 sto->next = vctxt->xpathStates;
22440 vctxt->xpathStates = sto;
22443 * Free the old xpath validation context.
22445 if (sto->xpathCtxt != NULL)
22446 xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt);
22449 * Create a new XPath (pattern) validation context.
22451 sto->xpathCtxt = (void *) xmlPatternGetStreamCtxt(
22452 (xmlPatternPtr) sel->xpathComp);
22453 if (sto->xpathCtxt == NULL) {
22454 VERROR_INT("xmlSchemaIDCAddStateObject",
22455 "failed to create an XPath validation context");
22459 sto->depth = vctxt->depth;
22460 sto->matcher = matcher;
22462 sto->nbHistory = 0;
22465 xmlGenericError(xmlGenericErrorContext, "IDC: STO push '%s'\n",
22472 * xmlSchemaXPathEvaluate:
22473 * @vctxt: the WXS validation context
22474 * @nodeType: the nodeType of the current node
22476 * Evaluates all active XPath state objects.
22478 * Returns the number of IC "field" state objects which resolved to
22479 * this node, 0 if none resolved and -1 on internal errors.
22482 xmlSchemaXPathEvaluate(xmlSchemaValidCtxtPtr vctxt,
22483 xmlElementType nodeType)
22485 xmlSchemaIDCStateObjPtr sto, head = NULL, first;
22486 int res, resolved = 0, depth = vctxt->depth;
22488 if (vctxt->xpathStates == NULL)
22491 if (nodeType == XML_ATTRIBUTE_NODE)
22495 xmlChar *str = NULL;
22496 xmlGenericError(xmlGenericErrorContext,
22497 "IDC: EVAL on %s, depth %d, type %d\n",
22498 xmlSchemaFormatQName(&str, vctxt->inode->nsName,
22499 vctxt->inode->localName), depth, nodeType);
22504 * Process all active XPath state objects.
22506 first = vctxt->xpathStates;
22508 while (sto != head) {
22510 if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR)
22511 xmlGenericError(xmlGenericErrorContext, "IDC: ['%s'] selector '%s'\n",
22512 sto->matcher->aidc->def->name, sto->sel->xpath);
22514 xmlGenericError(xmlGenericErrorContext, "IDC: ['%s'] field '%s'\n",
22515 sto->matcher->aidc->def->name, sto->sel->xpath);
22517 if (nodeType == XML_ELEMENT_NODE)
22518 res = xmlStreamPush((xmlStreamCtxtPtr) sto->xpathCtxt,
22519 vctxt->inode->localName, vctxt->inode->nsName);
22521 res = xmlStreamPushAttr((xmlStreamCtxtPtr) sto->xpathCtxt,
22522 vctxt->inode->localName, vctxt->inode->nsName);
22525 VERROR_INT("xmlSchemaXPathEvaluate",
22526 "calling xmlStreamPush()");
22535 xmlGenericError(xmlGenericErrorContext, "IDC: "
22539 * Register a match in the state object history.
22541 if (sto->history == NULL) {
22542 sto->history = (int *) xmlMalloc(5 * sizeof(int));
22543 if (sto->history == NULL) {
22544 xmlSchemaVErrMemory(NULL,
22545 "allocating the state object history", NULL);
22548 sto->sizeHistory = 5;
22549 } else if (sto->sizeHistory <= sto->nbHistory) {
22550 sto->sizeHistory *= 2;
22551 sto->history = (int *) xmlRealloc(sto->history,
22552 sto->sizeHistory * sizeof(int));
22553 if (sto->history == NULL) {
22554 xmlSchemaVErrMemory(NULL,
22555 "re-allocating the state object history", NULL);
22559 sto->history[sto->nbHistory++] = depth;
22562 xmlGenericError(xmlGenericErrorContext, "IDC: push match '%d'\n",
22566 if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) {
22567 xmlSchemaIDCSelectPtr sel;
22569 * Activate state objects for the IDC fields of
22570 * the IDC selector.
22573 xmlGenericError(xmlGenericErrorContext, "IDC: "
22574 "activating field states\n");
22576 sel = sto->matcher->aidc->def->fields;
22577 while (sel != NULL) {
22578 if (xmlSchemaIDCAddStateObject(vctxt, sto->matcher,
22579 sel, XPATH_STATE_OBJ_TYPE_IDC_FIELD) == -1)
22583 } else if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_FIELD) {
22585 * An IDC key node was found by the IDC field.
22588 xmlGenericError(xmlGenericErrorContext,
22589 "IDC: key found\n");
22592 * Notify that the character value of this node is
22595 if (resolved == 0) {
22596 if ((vctxt->inode->flags &
22597 XML_SCHEMA_NODE_INFO_VALUE_NEEDED) == 0)
22598 vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_VALUE_NEEDED;
22603 if (sto->next == NULL) {
22605 * Evaluate field state objects created on this node as well.
22608 sto = vctxt->xpathStates;
22615 static const xmlChar *
22616 xmlSchemaFormatIDCKeySequence(xmlSchemaValidCtxtPtr vctxt,
22618 xmlSchemaPSVIIDCKeyPtr *seq,
22622 xmlChar *value = NULL;
22624 *buf = xmlStrdup(BAD_CAST "[");
22625 for (i = 0; i < count; i++) {
22626 *buf = xmlStrcat(*buf, BAD_CAST "'");
22627 res = xmlSchemaGetCanonValueWhtspExt(seq[i]->val,
22628 xmlSchemaGetWhiteSpaceFacetValue(seq[i]->type),
22631 *buf = xmlStrcat(*buf, BAD_CAST value);
22633 VERROR_INT("xmlSchemaFormatIDCKeySequence",
22634 "failed to compute a canonical value");
22635 *buf = xmlStrcat(*buf, BAD_CAST "???");
22638 *buf = xmlStrcat(*buf, BAD_CAST "', ");
22640 *buf = xmlStrcat(*buf, BAD_CAST "'");
22641 if (value != NULL) {
22646 *buf = xmlStrcat(*buf, BAD_CAST "]");
22648 return (BAD_CAST *buf);
22652 * xmlSchemaXPathPop:
22653 * @vctxt: the WXS validation context
22655 * Pops all XPath states.
22657 * Returns 0 on success and -1 on internal errors.
22660 xmlSchemaXPathPop(xmlSchemaValidCtxtPtr vctxt)
22662 xmlSchemaIDCStateObjPtr sto;
22665 if (vctxt->xpathStates == NULL)
22667 sto = vctxt->xpathStates;
22669 res = xmlStreamPop((xmlStreamCtxtPtr) sto->xpathCtxt);
22673 } while (sto != NULL);
22678 * xmlSchemaXPathProcessHistory:
22679 * @vctxt: the WXS validation context
22680 * @type: the simple/complex type of the current node if any at all
22681 * @val: the precompiled value
22683 * Processes and pops the history items of the IDC state objects.
22684 * IDC key-sequences are validated/created on IDC bindings.
22686 * Returns 0 on success and -1 on internal errors.
22689 xmlSchemaXPathProcessHistory(xmlSchemaValidCtxtPtr vctxt,
22692 xmlSchemaIDCStateObjPtr sto, nextsto;
22693 int res, matchDepth;
22694 xmlSchemaPSVIIDCKeyPtr key = NULL;
22695 xmlSchemaTypePtr type = vctxt->inode->typeDef, simpleType = NULL;
22697 if (vctxt->xpathStates == NULL)
22699 sto = vctxt->xpathStates;
22703 xmlChar *str = NULL;
22704 xmlGenericError(xmlGenericErrorContext,
22705 "IDC: BACK on %s, depth %d\n",
22706 xmlSchemaFormatQName(&str, vctxt->inode->nsName,
22707 vctxt->inode->localName), vctxt->depth);
22712 * Evaluate the state objects.
22714 while (sto != NULL) {
22715 res = xmlStreamPop((xmlStreamCtxtPtr) sto->xpathCtxt);
22717 VERROR_INT("xmlSchemaXPathProcessHistory",
22718 "calling xmlStreamPop()");
22722 xmlGenericError(xmlGenericErrorContext, "IDC: stream pop '%s'\n",
22725 if (sto->nbHistory == 0)
22726 goto deregister_check;
22728 matchDepth = sto->history[sto->nbHistory -1];
22731 * Only matches at the current depth are of interest.
22733 if (matchDepth != depth) {
22737 if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_FIELD) {
22739 * NOTE: According to
22740 * http://www.w3.org/Bugs/Public/show_bug.cgi?id=2198
22741 * ... the simple-content of complex types is also allowed.
22744 if (WXS_IS_COMPLEX(type)) {
22745 if (WXS_HAS_SIMPLE_CONTENT(type)) {
22747 * Sanity check for complex types with simple content.
22749 simpleType = type->contentTypeDef;
22750 if (simpleType == NULL) {
22751 VERROR_INT("xmlSchemaXPathProcessHistory",
22752 "field resolves to a CT with simple content "
22753 "but the CT is missing the ST definition");
22760 if (simpleType == NULL) {
22761 xmlChar *str = NULL;
22764 * Not qualified if the field resolves to a node of non
22767 xmlSchemaCustomErr(ACTXT_CAST vctxt,
22768 XML_SCHEMAV_CVC_IDC, NULL,
22769 WXS_BASIC_CAST sto->matcher->aidc->def,
22770 "The XPath '%s' of a field of %s does evaluate to a node of "
22773 xmlSchemaGetIDCDesignation(&str, sto->matcher->aidc->def));
22774 FREE_AND_NULL(str);
22776 goto deregister_check;
22779 if ((key == NULL) && (vctxt->inode->val == NULL)) {
22781 * Failed to provide the normalized value; maybe
22782 * the value was invalid.
22784 VERROR(XML_SCHEMAV_CVC_IDC,
22785 WXS_BASIC_CAST sto->matcher->aidc->def,
22786 "Warning: No precomputed value available, the value "
22787 "was either invalid or something strange happend");
22789 goto deregister_check;
22791 xmlSchemaIDCMatcherPtr matcher = sto->matcher;
22792 xmlSchemaPSVIIDCKeyPtr *keySeq;
22796 * The key will be anchored on the matcher's list of
22797 * key-sequences. The position in this list is determined
22798 * by the target node's depth relative to the matcher's
22799 * depth of creation (i.e. the depth of the scope element).
22801 * Element Depth Pos List-entries
22804 * <target/> 2 2 target
22808 * The size of the list is only dependant on the depth of
22810 * An entry will be NULLed in selector_leave, i.e. when
22811 * we hit the target's
22813 pos = sto->depth - matcher->depth;
22814 idx = sto->sel->index;
22817 * Create/grow the array of key-sequences.
22819 if (matcher->keySeqs == NULL) {
22821 matcher->sizeKeySeqs = pos * 2;
22823 matcher->sizeKeySeqs = 10;
22824 matcher->keySeqs = (xmlSchemaPSVIIDCKeyPtr **)
22825 xmlMalloc(matcher->sizeKeySeqs *
22826 sizeof(xmlSchemaPSVIIDCKeyPtr *));
22827 if (matcher->keySeqs == NULL) {
22828 xmlSchemaVErrMemory(NULL,
22829 "allocating an array of key-sequences",
22833 memset(matcher->keySeqs, 0,
22834 matcher->sizeKeySeqs *
22835 sizeof(xmlSchemaPSVIIDCKeyPtr *));
22836 } else if (pos >= matcher->sizeKeySeqs) {
22837 int i = matcher->sizeKeySeqs;
22839 matcher->sizeKeySeqs *= 2;
22840 matcher->keySeqs = (xmlSchemaPSVIIDCKeyPtr **)
22841 xmlRealloc(matcher->keySeqs,
22842 matcher->sizeKeySeqs *
22843 sizeof(xmlSchemaPSVIIDCKeyPtr *));
22844 if (matcher->keySeqs == NULL) {
22845 xmlSchemaVErrMemory(NULL,
22846 "reallocating an array of key-sequences",
22851 * The array needs to be NULLed.
22852 * TODO: Use memset?
22854 for (; i < matcher->sizeKeySeqs; i++)
22855 matcher->keySeqs[i] = NULL;
22859 * Get/create the key-sequence.
22861 keySeq = matcher->keySeqs[pos];
22862 if (keySeq == NULL) {
22863 goto create_sequence;
22864 } else if (keySeq[idx] != NULL) {
22865 xmlChar *str = NULL;
22867 * cvc-identity-constraint:
22868 * 3 For each node in the `target node set` all
22869 * of the {fields}, with that node as the context
22870 * node, evaluate to either an empty node-set or
22871 * a node-set with exactly one member, which must
22872 * have a simple type.
22874 * The key was already set; report an error.
22876 xmlSchemaCustomErr(ACTXT_CAST vctxt,
22877 XML_SCHEMAV_CVC_IDC, NULL,
22878 WXS_BASIC_CAST matcher->aidc->def,
22879 "The XPath '%s' of a field of %s evaluates to a "
22880 "node-set with more than one member",
22882 xmlSchemaGetIDCDesignation(&str, matcher->aidc->def));
22883 FREE_AND_NULL(str);
22885 goto deregister_check;
22891 * Create a key-sequence.
22893 keySeq = (xmlSchemaPSVIIDCKeyPtr *) xmlMalloc(
22894 matcher->aidc->def->nbFields *
22895 sizeof(xmlSchemaPSVIIDCKeyPtr));
22896 if (keySeq == NULL) {
22897 xmlSchemaVErrMemory(NULL,
22898 "allocating an IDC key-sequence", NULL);
22901 memset(keySeq, 0, matcher->aidc->def->nbFields *
22902 sizeof(xmlSchemaPSVIIDCKeyPtr));
22903 matcher->keySeqs[pos] = keySeq;
22906 * Create a key once per node only.
22909 key = (xmlSchemaPSVIIDCKeyPtr) xmlMalloc(
22910 sizeof(xmlSchemaPSVIIDCKey));
22912 xmlSchemaVErrMemory(NULL,
22913 "allocating a IDC key", NULL);
22915 matcher->keySeqs[pos] = NULL;
22919 * Consume the compiled value.
22921 key->type = simpleType;
22922 key->val = vctxt->inode->val;
22923 vctxt->inode->val = NULL;
22925 * Store the key in a global list.
22927 if (xmlSchemaIDCStoreKey(vctxt, key) == -1) {
22928 xmlSchemaIDCFreeKey(key);
22934 } else if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) {
22936 xmlSchemaPSVIIDCKeyPtr **keySeq = NULL;
22937 /* xmlSchemaPSVIIDCBindingPtr bind; */
22938 xmlSchemaPSVIIDCNodePtr ntItem;
22939 xmlSchemaIDCMatcherPtr matcher;
22940 xmlSchemaIDCPtr idc;
22941 xmlSchemaItemListPtr targets;
22942 int pos, i, j, nbKeys;
22944 * Here we have the following scenario:
22945 * An IDC 'selector' state object resolved to a target node,
22946 * during the time this target node was in the
22947 * ancestor-or-self axis, the 'field' state object(s) looked
22948 * out for matching nodes to create a key-sequence for this
22949 * target node. Now we are back to this target node and need
22950 * to put the key-sequence, together with the target node
22951 * itself, into the node-table of the corresponding IDC
22954 matcher = sto->matcher;
22955 idc = matcher->aidc->def;
22956 nbKeys = idc->nbFields;
22957 pos = depth - matcher->depth;
22959 * Check if the matcher has any key-sequences at all, plus
22960 * if it has a key-sequence for the current target node.
22962 if ((matcher->keySeqs == NULL) ||
22963 (matcher->sizeKeySeqs <= pos)) {
22964 if (idc->type == XML_SCHEMA_TYPE_IDC_KEY)
22965 goto selector_key_error;
22967 goto selector_leave;
22970 keySeq = &(matcher->keySeqs[pos]);
22971 if (*keySeq == NULL) {
22972 if (idc->type == XML_SCHEMA_TYPE_IDC_KEY)
22973 goto selector_key_error;
22975 goto selector_leave;
22978 for (i = 0; i < nbKeys; i++) {
22979 if ((*keySeq)[i] == NULL) {
22981 * Not qualified, if not all fields did resolve.
22983 if (idc->type == XML_SCHEMA_TYPE_IDC_KEY) {
22985 * All fields of a "key" IDC must resolve.
22987 goto selector_key_error;
22989 goto selector_leave;
22993 * All fields did resolve.
22997 * 4.1 If the {identity-constraint category} is unique(/key),
22998 * then no two members of the `qualified node set` have
22999 * `key-sequences` whose members are pairwise equal, as
23000 * defined by Equal in [XML Schemas: Datatypes].
23002 * Get the IDC binding from the matcher and check for
23003 * duplicate key-sequences.
23006 bind = xmlSchemaIDCAcquireBinding(vctxt, matcher);
23008 targets = xmlSchemaIDCAcquireTargetList(vctxt, matcher);
23009 if ((idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) &&
23010 (targets->nbItems != 0)) {
23011 xmlSchemaPSVIIDCKeyPtr ckey, bkey, *bkeySeq;
23016 * Compare the key-sequences, key by key.
23020 ((xmlSchemaPSVIIDCNodePtr) targets->items[i])->keys;
23021 for (j = 0; j < nbKeys; j++) {
23022 ckey = (*keySeq)[j];
23024 res = xmlSchemaAreValuesEqual(ckey->val, bkey->val);
23027 } else if (res == 0) {
23029 * One of the keys differs, so the key-sequence
23030 * won't be equal; get out.
23037 * Duplicate key-sequence found.
23042 } while (i < targets->nbItems);
23043 if (i != targets->nbItems) {
23044 xmlChar *str = NULL, *strB = NULL;
23046 * TODO: Try to report the key-sequence.
23048 xmlSchemaCustomErr(ACTXT_CAST vctxt,
23049 XML_SCHEMAV_CVC_IDC, NULL,
23050 WXS_BASIC_CAST idc,
23051 "Duplicate key-sequence %s in %s",
23052 xmlSchemaFormatIDCKeySequence(vctxt, &str,
23053 (*keySeq), nbKeys),
23054 xmlSchemaGetIDCDesignation(&strB, idc));
23055 FREE_AND_NULL(str);
23056 FREE_AND_NULL(strB);
23057 goto selector_leave;
23061 * Add a node-table item to the IDC binding.
23063 ntItem = (xmlSchemaPSVIIDCNodePtr) xmlMalloc(
23064 sizeof(xmlSchemaPSVIIDCNode));
23065 if (ntItem == NULL) {
23066 xmlSchemaVErrMemory(NULL,
23067 "allocating an IDC node-table item", NULL);
23072 memset(ntItem, 0, sizeof(xmlSchemaPSVIIDCNode));
23075 * Store the node-table item in a global list.
23077 if (idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) {
23078 if (xmlSchemaIDCStoreNodeTableItem(vctxt, ntItem) == -1) {
23084 ntItem->nodeQNameID = -1;
23087 * Save a cached QName for this node on the IDC node, to be
23088 * able to report it, even if the node is not saved.
23090 ntItem->nodeQNameID = xmlSchemaVAddNodeQName(vctxt,
23091 vctxt->inode->localName, vctxt->inode->nsName);
23092 if (ntItem->nodeQNameID == -1) {
23100 * Init the node-table item: Save the node, position and
23101 * consume the key-sequence.
23103 ntItem->node = vctxt->node;
23104 ntItem->nodeLine = vctxt->inode->nodeLine;
23105 ntItem->keys = *keySeq;
23108 if (xmlSchemaIDCAppendNodeTableItem(bind, ntItem) == -1)
23110 if (xmlSchemaItemListAdd(targets, ntItem) == -1) {
23111 if (idc->type == XML_SCHEMA_TYPE_IDC_KEYREF) {
23113 * Free the item, since keyref items won't be
23114 * put on a global list.
23116 xmlFree(ntItem->keys);
23122 goto selector_leave;
23123 selector_key_error:
23125 xmlChar *str = NULL;
23127 * 4.2.1 (KEY) The `target node set` and the
23128 * `qualified node set` are equal, that is, every
23129 * member of the `target node set` is also a member
23130 * of the `qualified node set` and vice versa.
23132 xmlSchemaCustomErr(ACTXT_CAST vctxt,
23133 XML_SCHEMAV_CVC_IDC, NULL,
23134 WXS_BASIC_CAST idc,
23135 "Not all fields of %s evaluate to a node",
23136 xmlSchemaGetIDCDesignation(&str, idc), NULL);
23137 FREE_AND_NULL(str);
23141 * Free the key-sequence if not added to the IDC table.
23143 if ((keySeq != NULL) && (*keySeq != NULL)) {
23147 } /* if selector */
23153 * Deregister state objects if they reach the depth of creation.
23155 if ((sto->nbHistory == 0) && (sto->depth == depth)) {
23157 xmlGenericError(xmlGenericErrorContext, "IDC: STO pop '%s'\n",
23160 if (vctxt->xpathStates != sto) {
23161 VERROR_INT("xmlSchemaXPathProcessHistory",
23162 "The state object to be removed is not the first "
23165 nextsto = sto->next;
23167 * Unlink from the list of active XPath state objects.
23169 vctxt->xpathStates = sto->next;
23170 sto->next = vctxt->xpathStatePool;
23172 * Link it to the pool of reusable state objects.
23174 vctxt->xpathStatePool = sto;
23178 } /* while (sto != NULL) */
23183 * xmlSchemaIDCRegisterMatchers:
23184 * @vctxt: the WXS validation context
23185 * @elemDecl: the element declaration
23187 * Creates helper objects to evaluate IDC selectors/fields
23190 * Returns 0 if OK and -1 on internal errors.
23193 xmlSchemaIDCRegisterMatchers(xmlSchemaValidCtxtPtr vctxt,
23194 xmlSchemaElementPtr elemDecl)
23196 xmlSchemaIDCMatcherPtr matcher, last = NULL;
23197 xmlSchemaIDCPtr idc, refIdc;
23198 xmlSchemaIDCAugPtr aidc;
23200 idc = (xmlSchemaIDCPtr) elemDecl->idcs;
23206 xmlChar *str = NULL;
23207 xmlGenericError(xmlGenericErrorContext,
23208 "IDC: REGISTER on %s, depth %d\n",
23209 (char *) xmlSchemaFormatQName(&str, vctxt->inode->nsName,
23210 vctxt->inode->localName), vctxt->depth);
23214 if (vctxt->inode->idcMatchers != NULL) {
23215 VERROR_INT("xmlSchemaIDCRegisterMatchers",
23216 "The chain of IDC matchers is expected to be empty");
23220 if (idc->type == XML_SCHEMA_TYPE_IDC_KEYREF) {
23222 * Since IDCs bubbles are expensive we need to know the
23223 * depth at which the bubbles should stop; this will be
23224 * the depth of the top-most keyref IDC. If no keyref
23225 * references a key/unique IDC, the keyrefDepth will
23226 * be -1, indicating that no bubbles are needed.
23228 refIdc = (xmlSchemaIDCPtr) idc->ref->item;
23229 if (refIdc != NULL) {
23231 * Remember that we have keyrefs on this node.
23233 vctxt->inode->hasKeyrefs = 1;
23235 * Lookup the referenced augmented IDC info.
23237 aidc = vctxt->aidcs;
23238 while (aidc != NULL) {
23239 if (aidc->def == refIdc)
23243 if (aidc == NULL) {
23244 VERROR_INT("xmlSchemaIDCRegisterMatchers",
23245 "Could not find an augmented IDC item for an IDC "
23249 if ((aidc->keyrefDepth == -1) ||
23250 (vctxt->depth < aidc->keyrefDepth))
23251 aidc->keyrefDepth = vctxt->depth;
23255 * Lookup the augmented IDC item for the IDC definition.
23257 aidc = vctxt->aidcs;
23258 while (aidc != NULL) {
23259 if (aidc->def == idc)
23263 if (aidc == NULL) {
23264 VERROR_INT("xmlSchemaIDCRegisterMatchers",
23265 "Could not find an augmented IDC item for an IDC definition");
23269 * Create an IDC matcher for every IDC definition.
23271 if (vctxt->idcMatcherCache != NULL) {
23273 * Reuse a cached matcher.
23275 matcher = vctxt->idcMatcherCache;
23276 vctxt->idcMatcherCache = matcher->nextCached;
23277 matcher->nextCached = NULL;
23279 matcher = (xmlSchemaIDCMatcherPtr)
23280 xmlMalloc(sizeof(xmlSchemaIDCMatcher));
23281 if (matcher == NULL) {
23282 xmlSchemaVErrMemory(vctxt,
23283 "allocating an IDC matcher", NULL);
23286 memset(matcher, 0, sizeof(xmlSchemaIDCMatcher));
23289 vctxt->inode->idcMatchers = matcher;
23291 last->next = matcher;
23294 matcher->type = IDC_MATCHER;
23295 matcher->depth = vctxt->depth;
23296 matcher->aidc = aidc;
23297 matcher->idcType = aidc->def->type;
23299 xmlGenericError(xmlGenericErrorContext, "IDC: register matcher\n");
23302 * Init the automaton state object.
23304 if (xmlSchemaIDCAddStateObject(vctxt, matcher,
23305 idc->selector, XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) == -1)
23309 } while (idc != NULL);
23314 xmlSchemaIDCFillNodeTables(xmlSchemaValidCtxtPtr vctxt,
23315 xmlSchemaNodeInfoPtr ielem)
23317 xmlSchemaPSVIIDCBindingPtr bind;
23318 int res, i, j, k, nbTargets, nbFields, nbDupls, nbNodeTable;
23319 xmlSchemaPSVIIDCKeyPtr *keys, *ntkeys;
23320 xmlSchemaPSVIIDCNodePtr *targets, *dupls;
23322 xmlSchemaIDCMatcherPtr matcher = ielem->idcMatchers;
23323 /* vctxt->createIDCNodeTables */
23324 while (matcher != NULL) {
23326 * Skip keyref IDCs and empty IDC target-lists.
23328 if ((matcher->aidc->def->type == XML_SCHEMA_TYPE_IDC_KEYREF) ||
23329 WXS_ILIST_IS_EMPTY(matcher->targets))
23331 matcher = matcher->next;
23335 * If we _want_ the IDC node-table to be created in any case
23336 * then do so. Otherwise create them only if keyrefs need them.
23338 if ((! vctxt->createIDCNodeTables) &&
23339 ((matcher->aidc->keyrefDepth == -1) ||
23340 (matcher->aidc->keyrefDepth > vctxt->depth)))
23342 matcher = matcher->next;
23346 * Get/create the IDC binding on this element for the IDC definition.
23348 bind = xmlSchemaIDCAcquireBinding(vctxt, matcher);
23350 if (! WXS_ILIST_IS_EMPTY(bind->dupls)) {
23351 dupls = (xmlSchemaPSVIIDCNodePtr *) bind->dupls->items;
23352 nbDupls = bind->dupls->nbItems;
23357 if (bind->nodeTable != NULL) {
23358 nbNodeTable = bind->nbNodes;
23363 if ((nbNodeTable == 0) && (nbDupls == 0)) {
23365 * Transfer all IDC target-nodes to the IDC node-table.
23368 (xmlSchemaPSVIIDCNodePtr *) matcher->targets->items;
23369 bind->sizeNodes = matcher->targets->sizeItems;
23370 bind->nbNodes = matcher->targets->nbItems;
23372 matcher->targets->items = NULL;
23373 matcher->targets->sizeItems = 0;
23374 matcher->targets->nbItems = 0;
23377 * Compare the key-sequences and add to the IDC node-table.
23379 nbTargets = matcher->targets->nbItems;
23380 targets = (xmlSchemaPSVIIDCNodePtr *) matcher->targets->items;
23381 nbFields = matcher->aidc->def->nbFields;
23384 keys = targets[i]->keys;
23387 * Search in already found duplicates first.
23391 if (nbFields == 1) {
23392 res = xmlSchemaAreValuesEqual(keys[0]->val,
23393 dupls[j]->keys[0]->val);
23395 goto internal_error;
23398 * Equal key-sequence.
23404 ntkeys = dupls[j]->keys;
23405 for (k = 0; k < nbFields; k++) {
23406 res = xmlSchemaAreValuesEqual(keys[k]->val,
23409 goto internal_error;
23412 * One of the keys differs.
23419 * Equal key-sequence found.
23425 } while (j < nbDupls);
23430 if (nbFields == 1) {
23431 res = xmlSchemaAreValuesEqual(keys[0]->val,
23432 bind->nodeTable[j]->keys[0]->val);
23434 goto internal_error;
23437 * The key-sequence differs.
23439 goto next_node_table_entry;
23443 ntkeys = bind->nodeTable[j]->keys;
23444 for (k = 0; k < nbFields; k++) {
23445 res = xmlSchemaAreValuesEqual(keys[k]->val,
23448 goto internal_error;
23451 * One of the keys differs.
23453 goto next_node_table_entry;
23458 * Add the duplicate to the list of duplicates.
23460 if (bind->dupls == NULL) {
23461 bind->dupls = xmlSchemaItemListCreate();
23462 if (bind->dupls == NULL)
23463 goto internal_error;
23465 if (xmlSchemaItemListAdd(bind->dupls, bind->nodeTable[j]) == -1)
23466 goto internal_error;
23468 * Remove the duplicate entry from the IDC node-table.
23470 bind->nodeTable[j] = bind->nodeTable[bind->nbNodes -1];
23475 next_node_table_entry:
23477 } while (j < nbNodeTable);
23480 * If everything is fine, then add the IDC target-node to
23481 * the IDC node-table.
23483 if (xmlSchemaIDCAppendNodeTableItem(bind, targets[i]) == -1)
23484 goto internal_error;
23488 } while (i < nbTargets);
23490 matcher = matcher->next;
23499 * xmlSchemaBubbleIDCNodeTables:
23500 * @depth: the current tree depth
23502 * Merges IDC bindings of an element at @depth into the corresponding IDC
23503 * bindings of its parent element. If a duplicate note-table entry is found,
23504 * both, the parent node-table entry and child entry are discarded from the
23505 * node-table of the parent.
23507 * Returns 0 if OK and -1 on internal errors.
23510 xmlSchemaBubbleIDCNodeTables(xmlSchemaValidCtxtPtr vctxt)
23512 xmlSchemaPSVIIDCBindingPtr bind; /* IDC bindings of the current node. */
23513 xmlSchemaPSVIIDCBindingPtr *parTable, parBind = NULL; /* parent IDC bindings. */
23514 xmlSchemaPSVIIDCNodePtr node, parNode = NULL, *dupls, *parNodes; /* node-table entries. */
23515 xmlSchemaIDCAugPtr aidc;
23516 int i, j, k, ret = 0, nbFields, oldNum, oldDupls;
23518 bind = vctxt->inode->idcTable;
23519 if (bind == NULL) {
23520 /* Fine, no table, no bubbles. */
23524 parTable = &(vctxt->elemInfos[vctxt->depth -1]->idcTable);
23526 * Walk all bindings; create new or add to existing bindings.
23527 * Remove duplicate key-sequences.
23529 while (bind != NULL) {
23531 if ((bind->nbNodes == 0) && WXS_ILIST_IS_EMPTY(bind->dupls))
23534 * Check if the key/unique IDC table needs to be bubbled.
23536 if (! vctxt->createIDCNodeTables) {
23537 aidc = vctxt->aidcs;
23539 if (aidc->def == bind->definition) {
23540 if ((aidc->keyrefDepth == -1) ||
23541 (aidc->keyrefDepth >= vctxt->depth)) {
23547 } while (aidc != NULL);
23550 if (parTable != NULL)
23551 parBind = *parTable;
23553 * Search a matching parent binding for the
23556 while (parBind != NULL) {
23557 if (parBind->definition == bind->definition)
23559 parBind = parBind->next;
23562 if (parBind != NULL) {
23564 * Compare every node-table entry of the child node,
23565 * i.e. the key-sequence within, ...
23567 oldNum = parBind->nbNodes; /* Skip newly added items. */
23569 if (! WXS_ILIST_IS_EMPTY(parBind->dupls)) {
23570 oldDupls = parBind->dupls->nbItems;
23571 dupls = (xmlSchemaPSVIIDCNodePtr *) parBind->dupls->items;
23577 parNodes = parBind->nodeTable;
23578 nbFields = bind->definition->nbFields;
23580 for (i = 0; i < bind->nbNodes; i++) {
23581 node = bind->nodeTable[i];
23585 * ...with every key-sequence of the parent node, already
23586 * evaluated to be a duplicate key-sequence.
23590 while (j < oldDupls) {
23591 if (nbFields == 1) {
23592 ret = xmlSchemaAreValuesEqual(
23593 node->keys[0]->val,
23594 dupls[j]->keys[0]->val);
23596 goto internal_error;
23602 parNode = dupls[j];
23603 for (k = 0; k < nbFields; k++) {
23604 ret = xmlSchemaAreValuesEqual(
23605 node->keys[k]->val,
23606 parNode->keys[k]->val);
23608 goto internal_error;
23614 /* Duplicate found. */
23618 if (j != oldDupls) {
23619 /* Duplicate found. Skip this entry. */
23624 * ... and with every key-sequence of the parent node.
23628 while (j < oldNum) {
23629 parNode = parNodes[j];
23630 if (nbFields == 1) {
23631 ret = xmlSchemaAreValuesEqual(
23632 node->keys[0]->val,
23633 parNode->keys[0]->val);
23635 goto internal_error;
23641 for (k = 0; k < nbFields; k++) {
23642 ret = xmlSchemaAreValuesEqual(
23643 node->keys[k]->val,
23644 parNode->keys[k]->val);
23646 goto internal_error;
23652 /* Duplicate found. */
23658 * Handle duplicates. Move the duplicate in
23659 * the parent's node-table to the list of
23663 parBind->nbNodes--;
23665 * Move last old item to pos of duplicate.
23667 parNodes[j] = parNodes[oldNum];
23669 if (parBind->nbNodes != oldNum) {
23671 * If new items exist, move last new item to
23672 * last of old items.
23675 parNodes[parBind->nbNodes];
23677 if (parBind->dupls == NULL) {
23678 parBind->dupls = xmlSchemaItemListCreate();
23679 if (parBind->dupls == NULL)
23680 goto internal_error;
23682 xmlSchemaItemListAdd(parBind->dupls, parNode);
23685 * Add the node-table entry (node and key-sequence) of
23686 * the child node to the node table of the parent node.
23688 if (parBind->nodeTable == NULL) {
23689 parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *)
23690 xmlMalloc(10 * sizeof(xmlSchemaPSVIIDCNodePtr));
23691 if (parBind->nodeTable == NULL) {
23692 xmlSchemaVErrMemory(NULL,
23693 "allocating IDC list of node-table items", NULL);
23694 goto internal_error;
23696 parBind->sizeNodes = 1;
23697 } else if (parBind->nbNodes >= parBind->sizeNodes) {
23698 parBind->sizeNodes *= 2;
23699 parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *)
23700 xmlRealloc(parBind->nodeTable, parBind->sizeNodes *
23701 sizeof(xmlSchemaPSVIIDCNodePtr));
23702 if (parBind->nodeTable == NULL) {
23703 xmlSchemaVErrMemory(NULL,
23704 "re-allocating IDC list of node-table items", NULL);
23705 goto internal_error;
23708 parNodes = parBind->nodeTable;
23710 * Append the new node-table entry to the 'new node-table
23711 * entries' section.
23713 parNodes[parBind->nbNodes++] = node;
23721 * No binding for the IDC was found: create a new one and
23722 * copy all node-tables.
23724 parBind = xmlSchemaIDCNewBinding(bind->definition);
23725 if (parBind == NULL)
23726 goto internal_error;
23729 * TODO: Hmm, how to optimize the initial number of
23730 * allocated entries?
23732 if (bind->nbNodes != 0) {
23734 * Add all IDC node-table entries.
23736 if (! vctxt->psviExposeIDCNodeTables) {
23738 * Just move the entries.
23739 * NOTE: this is quite save here, since
23740 * all the keyref lookups have already been
23743 parBind->nodeTable = bind->nodeTable;
23744 bind->nodeTable = NULL;
23745 parBind->sizeNodes = bind->sizeNodes;
23746 bind->sizeNodes = 0;
23747 parBind->nbNodes = bind->nbNodes;
23751 * Copy the entries.
23753 parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *)
23754 xmlMalloc(bind->nbNodes *
23755 sizeof(xmlSchemaPSVIIDCNodePtr));
23756 if (parBind->nodeTable == NULL) {
23757 xmlSchemaVErrMemory(NULL,
23758 "allocating an array of IDC node-table "
23760 xmlSchemaIDCFreeBinding(parBind);
23761 goto internal_error;
23763 parBind->sizeNodes = bind->nbNodes;
23764 parBind->nbNodes = bind->nbNodes;
23765 memcpy(parBind->nodeTable, bind->nodeTable,
23766 bind->nbNodes * sizeof(xmlSchemaPSVIIDCNodePtr));
23771 * Move the duplicates.
23773 if (parBind->dupls != NULL)
23774 xmlSchemaItemListFree(parBind->dupls);
23775 parBind->dupls = bind->dupls;
23776 bind->dupls = NULL;
23778 if (parTable != NULL) {
23779 if (*parTable == NULL)
23780 *parTable = parBind;
23782 parBind->next = *parTable;
23783 *parTable = parBind;
23798 * xmlSchemaCheckCVCIDCKeyRef:
23799 * @vctxt: the WXS validation context
23800 * @elemDecl: the element declaration
23802 * Check the cvc-idc-keyref constraints.
23805 xmlSchemaCheckCVCIDCKeyRef(xmlSchemaValidCtxtPtr vctxt)
23807 xmlSchemaIDCMatcherPtr matcher;
23808 xmlSchemaPSVIIDCBindingPtr bind;
23810 matcher = vctxt->inode->idcMatchers;
23814 while (matcher != NULL) {
23815 if ((matcher->idcType == XML_SCHEMA_TYPE_IDC_KEYREF) &&
23816 matcher->targets &&
23817 matcher->targets->nbItems)
23819 int i, j, k, res, nbFields, hasDupls;
23820 xmlSchemaPSVIIDCKeyPtr *refKeys, *keys;
23821 xmlSchemaPSVIIDCNodePtr refNode = NULL;
23823 nbFields = matcher->aidc->def->nbFields;
23826 * Find the IDC node-table for the referenced IDC key/unique.
23828 bind = vctxt->inode->idcTable;
23829 while (bind != NULL) {
23830 if ((xmlSchemaIDCPtr) matcher->aidc->def->ref->item ==
23835 hasDupls = (bind && bind->dupls && bind->dupls->nbItems) ? 1 : 0;
23837 * Search for a matching key-sequences.
23839 for (i = 0; i < matcher->targets->nbItems; i++) {
23841 refNode = matcher->targets->items[i];
23842 if (bind != NULL) {
23843 refKeys = refNode->keys;
23844 for (j = 0; j < bind->nbNodes; j++) {
23845 keys = bind->nodeTable[j]->keys;
23846 for (k = 0; k < nbFields; k++) {
23847 res = xmlSchemaAreValuesEqual(keys[k]->val,
23851 else if (res == -1) {
23862 if ((res == 0) && hasDupls) {
23864 * Search in duplicates
23866 for (j = 0; j < bind->dupls->nbItems; j++) {
23867 keys = ((xmlSchemaPSVIIDCNodePtr)
23868 bind->dupls->items[j])->keys;
23869 for (k = 0; k < nbFields; k++) {
23870 res = xmlSchemaAreValuesEqual(keys[k]->val,
23874 else if (res == -1) {
23880 * Match in duplicates found.
23882 xmlChar *str = NULL, *strB = NULL;
23883 xmlSchemaKeyrefErr(vctxt,
23884 XML_SCHEMAV_CVC_IDC, refNode,
23885 (xmlSchemaTypePtr) matcher->aidc->def,
23886 "More than one match found for "
23887 "key-sequence %s of keyref '%s'",
23888 xmlSchemaFormatIDCKeySequence(vctxt, &str,
23889 refNode->keys, nbFields),
23890 xmlSchemaGetComponentQName(&strB,
23891 matcher->aidc->def));
23892 FREE_AND_NULL(str);
23893 FREE_AND_NULL(strB);
23901 xmlChar *str = NULL, *strB = NULL;
23902 xmlSchemaKeyrefErr(vctxt,
23903 XML_SCHEMAV_CVC_IDC, refNode,
23904 (xmlSchemaTypePtr) matcher->aidc->def,
23905 "No match found for key-sequence %s of keyref '%s'",
23906 xmlSchemaFormatIDCKeySequence(vctxt, &str,
23907 refNode->keys, nbFields),
23908 xmlSchemaGetComponentQName(&strB, matcher->aidc->def));
23909 FREE_AND_NULL(str);
23910 FREE_AND_NULL(strB);
23914 matcher = matcher->next;
23916 /* TODO: Return an error if any error encountered. */
23920 /************************************************************************
23922 * XML Reader validation code *
23924 ************************************************************************/
23926 static xmlSchemaAttrInfoPtr
23927 xmlSchemaGetFreshAttrInfo(xmlSchemaValidCtxtPtr vctxt)
23929 xmlSchemaAttrInfoPtr iattr;
23931 * Grow/create list of attribute infos.
23933 if (vctxt->attrInfos == NULL) {
23934 vctxt->attrInfos = (xmlSchemaAttrInfoPtr *)
23935 xmlMalloc(sizeof(xmlSchemaAttrInfoPtr));
23936 vctxt->sizeAttrInfos = 1;
23937 if (vctxt->attrInfos == NULL) {
23938 xmlSchemaVErrMemory(vctxt,
23939 "allocating attribute info list", NULL);
23942 } else if (vctxt->sizeAttrInfos <= vctxt->nbAttrInfos) {
23943 vctxt->sizeAttrInfos++;
23944 vctxt->attrInfos = (xmlSchemaAttrInfoPtr *)
23945 xmlRealloc(vctxt->attrInfos,
23946 vctxt->sizeAttrInfos * sizeof(xmlSchemaAttrInfoPtr));
23947 if (vctxt->attrInfos == NULL) {
23948 xmlSchemaVErrMemory(vctxt,
23949 "re-allocating attribute info list", NULL);
23953 iattr = vctxt->attrInfos[vctxt->nbAttrInfos++];
23954 if (iattr->localName != NULL) {
23955 VERROR_INT("xmlSchemaGetFreshAttrInfo",
23956 "attr info not cleared");
23959 iattr->nodeType = XML_ATTRIBUTE_NODE;
23963 * Create an attribute info.
23965 iattr = (xmlSchemaAttrInfoPtr)
23966 xmlMalloc(sizeof(xmlSchemaAttrInfo));
23967 if (iattr == NULL) {
23968 xmlSchemaVErrMemory(vctxt, "creating new attribute info", NULL);
23971 memset(iattr, 0, sizeof(xmlSchemaAttrInfo));
23972 iattr->nodeType = XML_ATTRIBUTE_NODE;
23973 vctxt->attrInfos[vctxt->nbAttrInfos++] = iattr;
23979 xmlSchemaValidatorPushAttribute(xmlSchemaValidCtxtPtr vctxt,
23980 xmlNodePtr attrNode,
23982 const xmlChar *localName,
23983 const xmlChar *nsName,
23988 xmlSchemaAttrInfoPtr attr;
23990 attr = xmlSchemaGetFreshAttrInfo(vctxt);
23991 if (attr == NULL) {
23992 VERROR_INT("xmlSchemaPushAttribute",
23993 "calling xmlSchemaGetFreshAttrInfo()");
23996 attr->node = attrNode;
23997 attr->nodeLine = nodeLine;
23998 attr->state = XML_SCHEMAS_ATTR_UNKNOWN;
23999 attr->localName = localName;
24000 attr->nsName = nsName;
24002 attr->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES;
24004 * Evaluate if it's an XSI attribute.
24006 if (nsName != NULL) {
24007 if (xmlStrEqual(localName, BAD_CAST "nil")) {
24008 if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) {
24009 attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_NIL;
24011 } else if (xmlStrEqual(localName, BAD_CAST "type")) {
24012 if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) {
24013 attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_TYPE;
24015 } else if (xmlStrEqual(localName, BAD_CAST "schemaLocation")) {
24016 if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) {
24017 attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC;
24019 } else if (xmlStrEqual(localName, BAD_CAST "noNamespaceSchemaLocation")) {
24020 if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) {
24021 attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC;
24023 } else if (xmlStrEqual(attr->nsName, xmlNamespaceNs)) {
24024 attr->metaType = XML_SCHEMA_ATTR_INFO_META_XMLNS;
24027 attr->value = value;
24029 attr->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES;
24030 if (attr->metaType != 0)
24031 attr->state = XML_SCHEMAS_ATTR_META;
24036 * xmlSchemaClearElemInfo:
24037 * @vctxt: the WXS validation context
24038 * @ielem: the element information item
24041 xmlSchemaClearElemInfo(xmlSchemaValidCtxtPtr vctxt,
24042 xmlSchemaNodeInfoPtr ielem)
24044 ielem->hasKeyrefs = 0;
24045 ielem->appliedXPath = 0;
24046 if (ielem->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES) {
24047 FREE_AND_NULL(ielem->localName);
24048 FREE_AND_NULL(ielem->nsName);
24050 ielem->localName = NULL;
24051 ielem->nsName = NULL;
24053 if (ielem->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) {
24054 FREE_AND_NULL(ielem->value);
24056 ielem->value = NULL;
24058 if (ielem->val != NULL) {
24060 * PSVI TODO: Be careful not to free it when the value is
24061 * exposed via PSVI.
24063 xmlSchemaFreeValue(ielem->val);
24066 if (ielem->idcMatchers != NULL) {
24068 * REVISIT OPTIMIZE TODO: Use a pool of IDC matchers.
24071 xmlSchemaIDCReleaseMatcherList(vctxt, ielem->idcMatchers);
24073 xmlSchemaIDCFreeMatcherList(ielem->idcMatchers);
24075 ielem->idcMatchers = NULL;
24077 if (ielem->idcTable != NULL) {
24079 * OPTIMIZE TODO: Use a pool of IDC tables??.
24081 xmlSchemaIDCFreeIDCTable(ielem->idcTable);
24082 ielem->idcTable = NULL;
24084 if (ielem->regexCtxt != NULL) {
24085 xmlRegFreeExecCtxt(ielem->regexCtxt);
24086 ielem->regexCtxt = NULL;
24088 if (ielem->nsBindings != NULL) {
24089 xmlFree((xmlChar **)ielem->nsBindings);
24090 ielem->nsBindings = NULL;
24091 ielem->nbNsBindings = 0;
24092 ielem->sizeNsBindings = 0;
24097 * xmlSchemaGetFreshElemInfo:
24098 * @vctxt: the schema validation context
24100 * Creates/reuses and initializes the element info item for
24101 * the currect tree depth.
24103 * Returns the element info item or NULL on API or internal errors.
24105 static xmlSchemaNodeInfoPtr
24106 xmlSchemaGetFreshElemInfo(xmlSchemaValidCtxtPtr vctxt)
24108 xmlSchemaNodeInfoPtr info = NULL;
24110 if (vctxt->depth > vctxt->sizeElemInfos) {
24111 VERROR_INT("xmlSchemaGetFreshElemInfo",
24112 "inconsistent depth encountered");
24115 if (vctxt->elemInfos == NULL) {
24116 vctxt->elemInfos = (xmlSchemaNodeInfoPtr *)
24117 xmlMalloc(10 * sizeof(xmlSchemaNodeInfoPtr));
24118 if (vctxt->elemInfos == NULL) {
24119 xmlSchemaVErrMemory(vctxt,
24120 "allocating the element info array", NULL);
24123 memset(vctxt->elemInfos, 0, 10 * sizeof(xmlSchemaNodeInfoPtr));
24124 vctxt->sizeElemInfos = 10;
24125 } else if (vctxt->sizeElemInfos <= vctxt->depth) {
24126 int i = vctxt->sizeElemInfos;
24128 vctxt->sizeElemInfos *= 2;
24129 vctxt->elemInfos = (xmlSchemaNodeInfoPtr *)
24130 xmlRealloc(vctxt->elemInfos, vctxt->sizeElemInfos *
24131 sizeof(xmlSchemaNodeInfoPtr));
24132 if (vctxt->elemInfos == NULL) {
24133 xmlSchemaVErrMemory(vctxt,
24134 "re-allocating the element info array", NULL);
24138 * We need the new memory to be NULLed.
24139 * TODO: Use memset instead?
24141 for (; i < vctxt->sizeElemInfos; i++)
24142 vctxt->elemInfos[i] = NULL;
24144 info = vctxt->elemInfos[vctxt->depth];
24146 if (info == NULL) {
24147 info = (xmlSchemaNodeInfoPtr)
24148 xmlMalloc(sizeof(xmlSchemaNodeInfo));
24149 if (info == NULL) {
24150 xmlSchemaVErrMemory(vctxt,
24151 "allocating an element info", NULL);
24154 vctxt->elemInfos[vctxt->depth] = info;
24156 if (info->localName != NULL) {
24157 VERROR_INT("xmlSchemaGetFreshElemInfo",
24158 "elem info has not been cleared");
24162 memset(info, 0, sizeof(xmlSchemaNodeInfo));
24163 info->nodeType = XML_ELEMENT_NODE;
24164 info->depth = vctxt->depth;
24169 #define ACTIVATE_ATTRIBUTE(item) vctxt->inode = (xmlSchemaNodeInfoPtr) item;
24170 #define ACTIVATE_ELEM vctxt->inode = vctxt->elemInfos[vctxt->depth];
24171 #define ACTIVATE_PARENT_ELEM vctxt->inode = vctxt->elemInfos[vctxt->depth -1];
24174 xmlSchemaValidateFacets(xmlSchemaAbstractCtxtPtr actxt,
24176 xmlSchemaTypePtr type,
24177 xmlSchemaValType valType,
24178 const xmlChar * value,
24179 xmlSchemaValPtr val,
24180 unsigned long length,
24183 int ret, error = 0;
24185 xmlSchemaTypePtr tmpType;
24186 xmlSchemaFacetLinkPtr facetLink;
24187 xmlSchemaFacetPtr facet;
24188 unsigned long len = 0;
24189 xmlSchemaWhitespaceValueType ws;
24192 * In Libxml2, derived built-in types have currently no explicit facets.
24194 if (type->type == XML_SCHEMA_TYPE_BASIC)
24198 * NOTE: Do not jump away, if the facetSet of the given type is
24199 * empty: until now, "pattern" and "enumeration" facets of the
24200 * *base types* need to be checked as well.
24202 if (type->facetSet == NULL)
24203 goto pattern_and_enum;
24205 if (! WXS_IS_ATOMIC(type)) {
24206 if (WXS_IS_LIST(type))
24209 goto pattern_and_enum;
24213 * Whitespace handling is only of importance for string-based
24216 tmpType = xmlSchemaGetPrimitiveType(type);
24217 if ((tmpType->builtInType == XML_SCHEMAS_STRING) ||
24218 WXS_IS_ANY_SIMPLE_TYPE(tmpType)) {
24219 ws = xmlSchemaGetWhiteSpaceFacetValue(type);
24221 ws = XML_SCHEMA_WHITESPACE_COLLAPSE;
24224 * If the value was not computed (for string or
24225 * anySimpleType based types), then use the provided
24229 valType = xmlSchemaGetValType(val);
24232 for (facetLink = type->facetSet; facetLink != NULL;
24233 facetLink = facetLink->next) {
24235 * Skip the pattern "whiteSpace": it is used to
24236 * format the character content beforehand.
24238 switch (facetLink->facet->type) {
24239 case XML_SCHEMA_FACET_WHITESPACE:
24240 case XML_SCHEMA_FACET_PATTERN:
24241 case XML_SCHEMA_FACET_ENUMERATION:
24243 case XML_SCHEMA_FACET_LENGTH:
24244 case XML_SCHEMA_FACET_MINLENGTH:
24245 case XML_SCHEMA_FACET_MAXLENGTH:
24246 ret = xmlSchemaValidateLengthFacetWhtsp(facetLink->facet,
24247 valType, value, val, &len, ws);
24250 ret = xmlSchemaValidateFacetWhtsp(facetLink->facet, ws,
24251 valType, value, val, ws);
24255 AERROR_INT("xmlSchemaValidateFacets",
24256 "validating against a atomic type facet");
24258 } else if (ret > 0) {
24260 xmlSchemaFacetErr(actxt, ret, node,
24261 value, len, type, facetLink->facet, NULL, NULL, NULL);
24271 if (! WXS_IS_LIST(type))
24272 goto pattern_and_enum;
24274 * "length", "minLength" and "maxLength" of list types.
24277 for (facetLink = type->facetSet; facetLink != NULL;
24278 facetLink = facetLink->next) {
24280 switch (facetLink->facet->type) {
24281 case XML_SCHEMA_FACET_LENGTH:
24282 case XML_SCHEMA_FACET_MINLENGTH:
24283 case XML_SCHEMA_FACET_MAXLENGTH:
24284 ret = xmlSchemaValidateListSimpleTypeFacet(facetLink->facet,
24285 value, length, NULL);
24291 AERROR_INT("xmlSchemaValidateFacets",
24292 "validating against a list type facet");
24294 } else if (ret > 0) {
24296 xmlSchemaFacetErr(actxt, ret, node,
24297 value, length, type, facetLink->facet, NULL, NULL, NULL);
24310 * Process enumerations. Facet values are in the value space
24311 * of the defining type's base type. This seems to be a bug in the
24312 * XML Schema 1.0 spec. Use the whitespace type of the base type.
24313 * Only the first set of enumerations in the ancestor-or-self axis
24314 * is used for validation.
24319 for (facet = tmpType->facets; facet != NULL; facet = facet->next) {
24320 if (facet->type != XML_SCHEMA_FACET_ENUMERATION)
24323 ret = xmlSchemaAreValuesEqual(facet->val, val);
24326 else if (ret < 0) {
24327 AERROR_INT("xmlSchemaValidateFacets",
24328 "validating against an enumeration facet");
24335 * Break on the first set of enumerations. Any additional
24336 * enumerations which might be existent on the ancestors
24337 * of the current type are restricted by this set; thus
24338 * *must* *not* be taken into account.
24342 tmpType = tmpType->baseType;
24343 } while ((tmpType != NULL) &&
24344 (tmpType->type != XML_SCHEMA_TYPE_BASIC));
24345 if (found && (ret == 0)) {
24346 ret = XML_SCHEMAV_CVC_ENUMERATION_VALID;
24348 xmlSchemaFacetErr(actxt, ret, node,
24349 value, 0, type, NULL, NULL, NULL, NULL);
24360 * Process patters. Pattern facets are ORed at type level
24361 * and ANDed if derived. Walk the base type axis.
24367 for (facetLink = tmpType->facetSet; facetLink != NULL;
24368 facetLink = facetLink->next) {
24369 if (facetLink->facet->type != XML_SCHEMA_FACET_PATTERN)
24373 * NOTE that for patterns, @value needs to be the
24374 * normalized vaule.
24376 ret = xmlRegexpExec(facetLink->facet->regexp, value);
24379 else if (ret < 0) {
24380 AERROR_INT("xmlSchemaValidateFacets",
24381 "validating against a pattern facet");
24385 * Save the last non-validating facet.
24387 facet = facetLink->facet;
24390 if (found && (ret != 1)) {
24391 ret = XML_SCHEMAV_CVC_PATTERN_VALID;
24393 xmlSchemaFacetErr(actxt, ret, node,
24394 value, 0, type, facet, NULL, NULL, NULL);
24401 tmpType = tmpType->baseType;
24402 } while ((tmpType != NULL) && (tmpType->type != XML_SCHEMA_TYPE_BASIC));
24409 xmlSchemaNormalizeValue(xmlSchemaTypePtr type,
24410 const xmlChar *value)
24412 switch (xmlSchemaGetWhiteSpaceFacetValue(type)) {
24413 case XML_SCHEMA_WHITESPACE_COLLAPSE:
24414 return (xmlSchemaCollapseString(value));
24415 case XML_SCHEMA_WHITESPACE_REPLACE:
24416 return (xmlSchemaWhiteSpaceReplace(value));
24423 xmlSchemaValidateQName(xmlSchemaValidCtxtPtr vctxt,
24424 const xmlChar *value,
24425 xmlSchemaValPtr *val,
24429 const xmlChar *nsName;
24430 xmlChar *local, *prefix = NULL;
24432 ret = xmlValidateQName(value, 1);
24435 VERROR_INT("xmlSchemaValidateQName",
24436 "calling xmlValidateQName()");
24439 return( XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1);
24442 * NOTE: xmlSplitQName2 will always return a duplicated
24445 local = xmlSplitQName2(value, &prefix);
24447 local = xmlStrdup(value);
24449 * OPTIMIZE TODO: Use flags for:
24450 * - is there any namespace binding?
24451 * - is there a default namespace?
24453 nsName = xmlSchemaLookupNamespace(vctxt, prefix);
24455 if (prefix != NULL) {
24458 * A namespace must be found if the prefix is
24461 if (nsName == NULL) {
24462 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1;
24463 xmlSchemaCustomErr(ACTXT_CAST vctxt, ret, NULL,
24464 WXS_BASIC_CAST xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME),
24465 "The QName value '%s' has no "
24466 "corresponding namespace declaration in "
24467 "scope", value, NULL);
24473 if (valNeeded && val) {
24474 if (nsName != NULL)
24475 *val = xmlSchemaNewQNameValue(
24476 BAD_CAST xmlStrdup(nsName), BAD_CAST local);
24478 *val = xmlSchemaNewQNameValue(NULL,
24489 xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt,
24491 xmlSchemaTypePtr type,
24492 const xmlChar *value,
24493 xmlSchemaValPtr *retVal,
24498 int ret = 0, valNeeded = (retVal) ? 1 : 0;
24499 xmlSchemaValPtr val = NULL;
24500 /* xmlSchemaWhitespaceValueType ws; */
24501 xmlChar *normValue = NULL;
24503 #define NORMALIZE(atype) \
24504 if ((! isNormalized) && \
24505 (normalize || (type->flags & XML_SCHEMAS_TYPE_NORMVALUENEEDED))) { \
24506 normValue = xmlSchemaNormalizeValue(atype, value); \
24507 if (normValue != NULL) \
24508 value = normValue; \
24509 isNormalized = 1; \
24512 if ((retVal != NULL) && (*retVal != NULL)) {
24513 xmlSchemaFreeValue(*retVal);
24517 * 3.14.4 Simple Type Definition Validation Rules
24518 * Validation Rule: String Valid
24521 * 1 It is schema-valid with respect to that definition as defined
24522 * by Datatype Valid in [XML Schemas: Datatypes].
24525 * 2.1 If The definition is ENTITY or is validly derived from ENTITY given
24526 * the empty set, as defined in Type Derivation OK (Simple) ($3.14.6), then
24527 * the string must be a `declared entity name`.
24530 * 2.2 If The definition is ENTITIES or is validly derived from ENTITIES
24531 * given the empty set, as defined in Type Derivation OK (Simple) ($3.14.6),
24532 * then every whitespace-delimited substring of the string must be a `declared
24536 * 2.3 otherwise no further condition applies.
24538 if ((! valNeeded) && (type->flags & XML_SCHEMAS_TYPE_FACETSNEEDVALUE))
24541 value = BAD_CAST "";
24542 if (WXS_IS_ANY_SIMPLE_TYPE(type) || WXS_IS_ATOMIC(type)) {
24543 xmlSchemaTypePtr biType; /* The built-in type. */
24545 * SPEC (1.2.1) "if {variety} is `atomic` then the string must `match`
24546 * a literal in the `lexical space` of {base type definition}"
24549 * Whitespace-normalize.
24552 if (type->type != XML_SCHEMA_TYPE_BASIC) {
24554 * Get the built-in type.
24556 biType = type->baseType;
24557 while ((biType != NULL) &&
24558 (biType->type != XML_SCHEMA_TYPE_BASIC))
24559 biType = biType->baseType;
24561 if (biType == NULL) {
24562 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24563 "could not get the built-in type");
24564 goto internal_error;
24569 * NOTATIONs need to be processed here, since they need
24570 * to lookup in the hashtable of NOTATION declarations of the schema.
24572 if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR) {
24573 switch (biType->builtInType) {
24574 case XML_SCHEMAS_NOTATION:
24575 ret = xmlSchemaValidateNotation(
24576 (xmlSchemaValidCtxtPtr) actxt,
24577 ((xmlSchemaValidCtxtPtr) actxt)->schema,
24578 NULL, value, &val, valNeeded);
24580 case XML_SCHEMAS_QNAME:
24581 ret = xmlSchemaValidateQName((xmlSchemaValidCtxtPtr) actxt,
24582 value, &val, valNeeded);
24585 /* ws = xmlSchemaGetWhiteSpaceFacetValue(type); */
24587 ret = xmlSchemaValPredefTypeNodeNoNorm(biType,
24588 value, &val, node);
24590 ret = xmlSchemaValPredefTypeNodeNoNorm(biType,
24591 value, NULL, node);
24594 } else if (actxt->type == XML_SCHEMA_CTXT_PARSER) {
24595 switch (biType->builtInType) {
24596 case XML_SCHEMAS_NOTATION:
24597 ret = xmlSchemaValidateNotation(NULL,
24598 ((xmlSchemaParserCtxtPtr) actxt)->schema, node,
24599 value, &val, valNeeded);
24602 /* ws = xmlSchemaGetWhiteSpaceFacetValue(type); */
24604 ret = xmlSchemaValPredefTypeNodeNoNorm(biType,
24605 value, &val, node);
24607 ret = xmlSchemaValPredefTypeNodeNoNorm(biType,
24608 value, NULL, node);
24613 * Validation via a public API is not implemented yet.
24616 goto internal_error;
24620 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24621 "validating against a built-in type");
24622 goto internal_error;
24624 if (WXS_IS_LIST(type))
24625 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2;
24627 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1;
24629 if ((ret == 0) && (type->flags & XML_SCHEMAS_TYPE_HAS_FACETS)) {
24633 ret = xmlSchemaValidateFacets(actxt, node, type,
24634 (xmlSchemaValType) biType->builtInType, value, val,
24638 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24639 "validating facets of atomic simple type");
24640 goto internal_error;
24642 if (WXS_IS_LIST(type))
24643 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2;
24645 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1;
24648 if (fireErrors && (ret > 0))
24649 xmlSchemaSimpleTypeErr(actxt, ret, node, value, type, 1);
24650 } else if (WXS_IS_LIST(type)) {
24652 xmlSchemaTypePtr itemType;
24653 const xmlChar *cur, *end;
24654 xmlChar *tmpValue = NULL;
24655 unsigned long len = 0;
24656 xmlSchemaValPtr prevVal = NULL, curVal = NULL;
24657 /* 1.2.2 if {variety} is `list` then the string must be a sequence
24658 * of white space separated tokens, each of which `match`es a literal
24659 * in the `lexical space` of {item type definition}
24662 * Note that XML_SCHEMAS_TYPE_NORMVALUENEEDED will be set if
24663 * the list type has an enum or pattern facet.
24667 * VAL TODO: Optimize validation of empty values.
24668 * VAL TODO: We do not have computed values for lists.
24670 itemType = WXS_LIST_ITEMTYPE(type);
24673 while (IS_BLANK_CH(*cur))
24676 while ((*end != 0) && (!(IS_BLANK_CH(*end))))
24680 tmpValue = xmlStrndup(cur, end - cur);
24684 ret = xmlSchemaVCheckCVCSimpleType(actxt, node, itemType,
24685 tmpValue, &curVal, fireErrors, 0, 1);
24687 ret = xmlSchemaVCheckCVCSimpleType(actxt, node, itemType,
24688 tmpValue, NULL, fireErrors, 0, 1);
24689 FREE_AND_NULL(tmpValue);
24690 if (curVal != NULL) {
24692 * Add to list of computed values.
24697 xmlSchemaValueAppend(prevVal, curVal);
24703 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24704 "validating an item of list simple type");
24705 goto internal_error;
24707 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2;
24711 } while (*cur != 0);
24712 FREE_AND_NULL(tmpValue);
24713 if ((ret == 0) && (type->flags & XML_SCHEMAS_TYPE_HAS_FACETS)) {
24715 * Apply facets (pattern, enumeration).
24717 ret = xmlSchemaValidateFacets(actxt, node, type,
24718 XML_SCHEMAS_UNKNOWN, value, val,
24722 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24723 "validating facets of list simple type");
24724 goto internal_error;
24726 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2;
24729 if (fireErrors && (ret > 0)) {
24731 * Report the normalized value.
24735 xmlSchemaSimpleTypeErr(actxt, ret, node, value, type, 1);
24737 } else if (WXS_IS_UNION(type)) {
24738 xmlSchemaTypeLinkPtr memberLink;
24740 * TODO: For all datatypes `derived` by `union` whiteSpace does
24741 * not apply directly; however, the normalization behavior of `union`
24742 * types is controlled by the value of whiteSpace on that one of the
24743 * `memberTypes` against which the `union` is successfully validated.
24745 * This means that the value is normalized by the first validating
24746 * member type, then the facets of the union type are applied. This
24747 * needs changing of the value!
24751 * 1.2.3 if {variety} is `union` then the string must `match` a
24752 * literal in the `lexical space` of at least one member of
24753 * {member type definitions}
24755 memberLink = xmlSchemaGetUnionSimpleTypeMemberTypes(type);
24756 if (memberLink == NULL) {
24757 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24758 "union simple type has no member types");
24759 goto internal_error;
24762 * Always normalize union type values, since we currently
24763 * cannot store the whitespace information with the value
24764 * itself; otherwise a later value-comparison would be
24767 while (memberLink != NULL) {
24769 ret = xmlSchemaVCheckCVCSimpleType(actxt, node,
24770 memberLink->type, value, &val, 0, 1, 0);
24772 ret = xmlSchemaVCheckCVCSimpleType(actxt, node,
24773 memberLink->type, value, NULL, 0, 1, 0);
24776 memberLink = memberLink->next;
24780 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24781 "validating members of union simple type");
24782 goto internal_error;
24784 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3;
24787 * Apply facets (pattern, enumeration).
24789 if ((ret == 0) && (type->flags & XML_SCHEMAS_TYPE_HAS_FACETS)) {
24791 * The normalization behavior of `union` types is controlled by
24792 * the value of whiteSpace on that one of the `memberTypes`
24793 * against which the `union` is successfully validated.
24795 NORMALIZE(memberLink->type);
24796 ret = xmlSchemaValidateFacets(actxt, node, type,
24797 XML_SCHEMAS_UNKNOWN, value, val,
24801 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24802 "validating facets of union simple type");
24803 goto internal_error;
24805 ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3;
24808 if (fireErrors && (ret > 0))
24809 xmlSchemaSimpleTypeErr(actxt, ret, node, value, type, 1);
24812 if (normValue != NULL)
24813 xmlFree(normValue);
24815 if (retVal != NULL)
24817 else if (val != NULL)
24818 xmlSchemaFreeValue(val);
24819 } else if (val != NULL)
24820 xmlSchemaFreeValue(val);
24823 if (normValue != NULL)
24824 xmlFree(normValue);
24826 xmlSchemaFreeValue(val);
24831 xmlSchemaVExpandQName(xmlSchemaValidCtxtPtr vctxt,
24832 const xmlChar *value,
24833 const xmlChar **nsName,
24834 const xmlChar **localName)
24838 if ((nsName == NULL) || (localName == NULL))
24843 ret = xmlValidateQName(value, 1);
24847 xmlSchemaSimpleTypeErr(ACTXT_CAST vctxt,
24848 XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, NULL,
24849 value, xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), 1);
24853 xmlChar *local = NULL;
24857 * NOTE: xmlSplitQName2 will return a duplicated
24860 local = xmlSplitQName2(value, &prefix);
24862 *localName = xmlDictLookup(vctxt->dict, value, -1);
24864 *localName = xmlDictLookup(vctxt->dict, local, -1);
24868 *nsName = xmlSchemaLookupNamespace(vctxt, prefix);
24870 if (prefix != NULL) {
24873 * A namespace must be found if the prefix is NOT NULL.
24875 if (*nsName == NULL) {
24876 xmlSchemaCustomErr(ACTXT_CAST vctxt,
24877 XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, NULL,
24878 WXS_BASIC_CAST xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME),
24879 "The QName value '%s' has no "
24880 "corresponding namespace declaration in scope",
24890 xmlSchemaProcessXSIType(xmlSchemaValidCtxtPtr vctxt,
24891 xmlSchemaAttrInfoPtr iattr,
24892 xmlSchemaTypePtr *localType,
24893 xmlSchemaElementPtr elemDecl)
24897 * cvc-elt (3.3.4) : (4)
24899 * Schema-Validity Assessment (Element) (cvc-assess-elt)
24900 * (1.2.1.2.1) - (1.2.1.2.4)
24901 * Handle 'xsi:type'.
24903 if (localType == NULL)
24909 const xmlChar *nsName = NULL, *local = NULL;
24911 * TODO: We should report a *warning* that the type was overriden
24914 ACTIVATE_ATTRIBUTE(iattr);
24916 * (cvc-elt) (3.3.4) : (4.1)
24917 * (cvc-assess-elt) (1.2.1.2.2)
24919 ret = xmlSchemaVExpandQName(vctxt, iattr->value,
24923 VERROR_INT("xmlSchemaValidateElementByDeclaration",
24924 "calling xmlSchemaQNameExpand() to validate the "
24925 "attribute 'xsi:type'");
24926 goto internal_error;
24931 * (cvc-elt) (3.3.4) : (4.2)
24932 * (cvc-assess-elt) (1.2.1.2.3)
24934 *localType = xmlSchemaGetType(vctxt->schema, local, nsName);
24935 if (*localType == NULL) {
24936 xmlChar *str = NULL;
24938 xmlSchemaCustomErr(ACTXT_CAST vctxt,
24939 XML_SCHEMAV_CVC_ELT_4_2, NULL,
24940 WXS_BASIC_CAST xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME),
24941 "The QName value '%s' of the xsi:type attribute does not "
24942 "resolve to a type definition",
24943 xmlSchemaFormatQName(&str, nsName, local), NULL);
24944 FREE_AND_NULL(str);
24948 if (elemDecl != NULL) {
24952 * SPEC cvc-elt (3.3.4) : (4.3) (Type Derivation OK)
24953 * "The `local type definition` must be validly
24954 * derived from the {type definition} given the union of
24955 * the {disallowed substitutions} and the {type definition}'s
24956 * {prohibited substitutions}, as defined in
24957 * Type Derivation OK (Complex) ($3.4.6)
24958 * (if it is a complex type definition),
24959 * or given {disallowed substitutions} as defined in Type
24960 * Derivation OK (Simple) ($3.14.6) (if it is a simple type
24963 * {disallowed substitutions}: the "block" on the element decl.
24964 * {prohibited substitutions}: the "block" on the type def.
24967 * OPTIMIZE TODO: We could map types already evaluated
24968 * to be validly derived from other types to avoid checking
24969 * this over and over for the same types.
24971 if ((elemDecl->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) ||
24972 (elemDecl->subtypes->flags &
24973 XML_SCHEMAS_TYPE_BLOCK_EXTENSION))
24974 set |= SUBSET_EXTENSION;
24976 if ((elemDecl->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) ||
24977 (elemDecl->subtypes->flags &
24978 XML_SCHEMAS_TYPE_BLOCK_RESTRICTION))
24979 set |= SUBSET_RESTRICTION;
24982 * REMOVED and CHANGED since this produced a parser context
24983 * which adds to the string dict of the schema. So this would
24984 * change the schema and we don't want this. We don't need
24985 * the parser context anymore.
24987 * if ((vctxt->pctxt == NULL) &&
24988 * (xmlSchemaCreatePCtxtOnVCtxt(vctxt) == -1))
24992 if (xmlSchemaCheckCOSDerivedOK(ACTXT_CAST vctxt, *localType,
24993 elemDecl->subtypes, set) != 0) {
24994 xmlChar *str = NULL;
24996 xmlSchemaCustomErr(ACTXT_CAST vctxt,
24997 XML_SCHEMAV_CVC_ELT_4_3, NULL, NULL,
24998 "The type definition '%s', specified by xsi:type, is "
24999 "blocked or not validly derived from the type definition "
25000 "of the element declaration",
25001 xmlSchemaFormatQName(&str,
25002 (*localType)->targetNamespace,
25003 (*localType)->name),
25005 FREE_AND_NULL(str);
25020 xmlSchemaValidateElemDecl(xmlSchemaValidCtxtPtr vctxt)
25022 xmlSchemaElementPtr elemDecl = vctxt->inode->decl;
25023 xmlSchemaTypePtr actualType;
25026 * cvc-elt (3.3.4) : 1
25028 if (elemDecl == NULL) {
25029 VERROR(XML_SCHEMAV_CVC_ELT_1, NULL,
25030 "No matching declaration available");
25031 return (vctxt->err);
25033 actualType = WXS_ELEM_TYPEDEF(elemDecl);
25035 * cvc-elt (3.3.4) : 2
25037 if (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT) {
25038 VERROR(XML_SCHEMAV_CVC_ELT_2, NULL,
25039 "The element declaration is abstract");
25040 return (vctxt->err);
25042 if (actualType == NULL) {
25043 VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL,
25044 "The type definition is absent");
25045 return (XML_SCHEMAV_CVC_TYPE_1);
25047 if (vctxt->nbAttrInfos != 0) {
25049 xmlSchemaAttrInfoPtr iattr;
25051 * cvc-elt (3.3.4) : 3
25052 * Handle 'xsi:nil'.
25054 iattr = xmlSchemaGetMetaAttrInfo(vctxt,
25055 XML_SCHEMA_ATTR_INFO_META_XSI_NIL);
25057 ACTIVATE_ATTRIBUTE(iattr);
25059 * Validate the value.
25061 ret = xmlSchemaVCheckCVCSimpleType(
25062 ACTXT_CAST vctxt, NULL,
25063 xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN),
25064 iattr->value, &(iattr->val), 1, 0, 0);
25067 VERROR_INT("xmlSchemaValidateElemDecl",
25068 "calling xmlSchemaVCheckCVCSimpleType() to "
25069 "validate the attribute 'xsi:nil'");
25073 if ((elemDecl->flags & XML_SCHEMAS_ELEM_NILLABLE) == 0) {
25075 * cvc-elt (3.3.4) : 3.1
25077 VERROR(XML_SCHEMAV_CVC_ELT_3_1, NULL,
25078 "The element is not 'nillable'");
25079 /* Does not return an error on purpose. */
25081 if (xmlSchemaValueGetAsBoolean(iattr->val)) {
25083 * cvc-elt (3.3.4) : 3.2.2
25085 if ((elemDecl->flags & XML_SCHEMAS_ELEM_FIXED) &&
25086 (elemDecl->value != NULL)) {
25087 VERROR(XML_SCHEMAV_CVC_ELT_3_2_2, NULL,
25088 "The element cannot be 'nilled' because "
25089 "there is a fixed value constraint defined "
25091 /* Does not return an error on purpose. */
25093 vctxt->inode->flags |=
25094 XML_SCHEMA_ELEM_INFO_NILLED;
25100 * cvc-elt (3.3.4) : 4
25101 * Handle 'xsi:type'.
25103 iattr = xmlSchemaGetMetaAttrInfo(vctxt,
25104 XML_SCHEMA_ATTR_INFO_META_XSI_TYPE);
25106 xmlSchemaTypePtr localType = NULL;
25108 ret = xmlSchemaProcessXSIType(vctxt, iattr, &localType,
25112 VERROR_INT("xmlSchemaValidateElemDecl",
25113 "calling xmlSchemaProcessXSIType() to "
25114 "process the attribute 'xsi:type'");
25117 /* Does not return an error on purpose. */
25119 if (localType != NULL) {
25120 vctxt->inode->flags |= XML_SCHEMA_ELEM_INFO_LOCAL_TYPE;
25121 actualType = localType;
25126 * IDC: Register identity-constraint XPath matchers.
25128 if ((elemDecl->idcs != NULL) &&
25129 (xmlSchemaIDCRegisterMatchers(vctxt, elemDecl) == -1))
25132 * No actual type definition.
25134 if (actualType == NULL) {
25135 VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL,
25136 "The type definition is absent");
25137 return (XML_SCHEMAV_CVC_TYPE_1);
25140 * Remember the actual type definition.
25142 vctxt->inode->typeDef = actualType;
25148 xmlSchemaVAttributesSimple(xmlSchemaValidCtxtPtr vctxt)
25150 xmlSchemaAttrInfoPtr iattr;
25154 * SPEC cvc-type (3.1.1)
25155 * "The attributes of must be empty, excepting those whose namespace
25156 * name is identical to http://www.w3.org/2001/XMLSchema-instance and
25157 * whose local name is one of type, nil, schemaLocation or
25158 * noNamespaceSchemaLocation."
25160 if (vctxt->nbAttrInfos == 0)
25162 for (i = 0; i < vctxt->nbAttrInfos; i++) {
25163 iattr = vctxt->attrInfos[i];
25164 if (! iattr->metaType) {
25165 ACTIVATE_ATTRIBUTE(iattr)
25166 xmlSchemaIllegalAttrErr(ACTXT_CAST vctxt,
25167 XML_SCHEMAV_CVC_TYPE_3_1_1, iattr, NULL);
25168 ret = XML_SCHEMAV_CVC_TYPE_3_1_1;
25176 * Cleanup currently used attribute infos.
25179 xmlSchemaClearAttrInfos(xmlSchemaValidCtxtPtr vctxt)
25182 xmlSchemaAttrInfoPtr attr;
25184 if (vctxt->nbAttrInfos == 0)
25186 for (i = 0; i < vctxt->nbAttrInfos; i++) {
25187 attr = vctxt->attrInfos[i];
25188 if (attr->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES) {
25189 if (attr->localName != NULL)
25190 xmlFree((xmlChar *) attr->localName);
25191 if (attr->nsName != NULL)
25192 xmlFree((xmlChar *) attr->nsName);
25194 if (attr->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) {
25195 if (attr->value != NULL)
25196 xmlFree((xmlChar *) attr->value);
25198 if (attr->val != NULL) {
25199 xmlSchemaFreeValue(attr->val);
25202 memset(attr, 0, sizeof(xmlSchemaAttrInfo));
25204 vctxt->nbAttrInfos = 0;
25208 * 3.4.4 Complex Type Definition Validation Rules
25209 * Element Locally Valid (Complex Type) (cvc-complex-type)
25210 * 3.2.4 Attribute Declaration Validation Rules
25211 * Validation Rule: Attribute Locally Valid (cvc-attribute)
25212 * Attribute Locally Valid (Use) (cvc-au)
25214 * Only "assessed" attribute information items will be visible to
25215 * IDCs. I.e. not "lax" (without declaration) and "skip" wild attributes.
25218 xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
25220 xmlSchemaTypePtr type = vctxt->inode->typeDef;
25221 xmlSchemaItemListPtr attrUseList;
25222 xmlSchemaAttributeUsePtr attrUse = NULL;
25223 xmlSchemaAttributePtr attrDecl = NULL;
25224 xmlSchemaAttrInfoPtr iattr, tmpiattr;
25225 int i, j, found, nbAttrs, nbUses;
25226 int xpathRes = 0, res, wildIDs = 0, fixed;
25227 xmlNodePtr defAttrOwnerElem = NULL;
25230 * SPEC (cvc-attribute)
25231 * (1) "The declaration must not be `absent` (see Missing
25232 * Sub-components ($5.3) for how this can fail to be
25234 * (2) "Its {type definition} must not be absent."
25236 * NOTE (1) + (2): This is not handled here, since we currently do not
25237 * allow validation against schemas which have missing sub-components.
25239 * SPEC (cvc-complex-type)
25240 * (3) "For each attribute information item in the element information
25241 * item's [attributes] excepting those whose [namespace name] is
25242 * identical to http://www.w3.org/2001/XMLSchema-instance and whose
25243 * [local name] is one of type, nil, schemaLocation or
25244 * noNamespaceSchemaLocation, the appropriate case among the following
25248 attrUseList = (xmlSchemaItemListPtr) type->attrUses;
25250 * @nbAttrs is the number of attributes present in the instance.
25252 nbAttrs = vctxt->nbAttrInfos;
25253 if (attrUseList != NULL)
25254 nbUses = attrUseList->nbItems;
25257 for (i = 0; i < nbUses; i++) {
25259 attrUse = attrUseList->items[i];
25260 attrDecl = WXS_ATTRUSE_DECL(attrUse);
25261 for (j = 0; j < nbAttrs; j++) {
25262 iattr = vctxt->attrInfos[j];
25264 * SPEC (cvc-complex-type) (3)
25265 * Skip meta attributes.
25267 if (iattr->metaType)
25269 if (iattr->localName[0] != attrDecl->name[0])
25271 if (!xmlStrEqual(iattr->localName, attrDecl->name))
25273 if (!xmlStrEqual(iattr->nsName, attrDecl->targetNamespace))
25277 * SPEC (cvc-complex-type)
25278 * (3.1) "If there is among the {attribute uses} an attribute
25279 * use with an {attribute declaration} whose {name} matches
25280 * the attribute information item's [local name] and whose
25281 * {target namespace} is identical to the attribute information
25282 * item's [namespace name] (where an `absent` {target namespace}
25283 * is taken to be identical to a [namespace name] with no value),
25284 * then the attribute information must be `valid` with respect
25285 * to that attribute use as per Attribute Locally Valid (Use)
25286 * ($3.5.4). In this case the {attribute declaration} of that
25287 * attribute use is the `context-determined declaration` for the
25288 * attribute information item with respect to Schema-Validity
25289 * Assessment (Attribute) ($3.2.4) and
25290 * Assessment Outcome (Attribute) ($3.2.5).
25292 iattr->state = XML_SCHEMAS_ATTR_ASSESSED;
25293 iattr->use = attrUse;
25295 * Context-determined declaration.
25297 iattr->decl = attrDecl;
25298 iattr->typeDef = attrDecl->subtypes;
25305 if (attrUse->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED) {
25307 * Handle non-existent, required attributes.
25309 * SPEC (cvc-complex-type)
25310 * (4) "The {attribute declaration} of each attribute use in
25311 * the {attribute uses} whose {required} is true matches one
25312 * of the attribute information items in the element information
25313 * item's [attributes] as per clause 3.1 above."
25315 tmpiattr = xmlSchemaGetFreshAttrInfo(vctxt);
25316 if (tmpiattr == NULL) {
25318 "xmlSchemaVAttributesComplex",
25319 "calling xmlSchemaGetFreshAttrInfo()");
25322 tmpiattr->state = XML_SCHEMAS_ATTR_ERR_MISSING;
25323 tmpiattr->use = attrUse;
25324 tmpiattr->decl = attrDecl;
25325 } else if ((attrUse->occurs == XML_SCHEMAS_ATTR_USE_OPTIONAL) &&
25326 ((attrUse->defValue != NULL) ||
25327 (attrDecl->defValue != NULL))) {
25329 * Handle non-existent, optional, default/fixed attributes.
25331 tmpiattr = xmlSchemaGetFreshAttrInfo(vctxt);
25332 if (tmpiattr == NULL) {
25334 "xmlSchemaVAttributesComplex",
25335 "calling xmlSchemaGetFreshAttrInfo()");
25338 tmpiattr->state = XML_SCHEMAS_ATTR_DEFAULT;
25339 tmpiattr->use = attrUse;
25340 tmpiattr->decl = attrDecl;
25341 tmpiattr->typeDef = attrDecl->subtypes;
25342 tmpiattr->localName = attrDecl->name;
25343 tmpiattr->nsName = attrDecl->targetNamespace;
25347 if (vctxt->nbAttrInfos == 0)
25350 * Validate against the wildcard.
25352 if (type->attributeWildcard != NULL) {
25354 * SPEC (cvc-complex-type)
25355 * (3.2.1) "There must be an {attribute wildcard}."
25357 for (i = 0; i < nbAttrs; i++) {
25358 iattr = vctxt->attrInfos[i];
25360 * SPEC (cvc-complex-type) (3)
25361 * Skip meta attributes.
25363 if (iattr->state != XML_SCHEMAS_ATTR_UNKNOWN)
25366 * SPEC (cvc-complex-type)
25367 * (3.2.2) "The attribute information item must be `valid` with
25368 * respect to it as defined in Item Valid (Wildcard) ($3.10.4)."
25370 * SPEC Item Valid (Wildcard) (cvc-wildcard)
25371 * "... its [namespace name] must be `valid` with respect to
25372 * the wildcard constraint, as defined in Wildcard allows
25373 * Namespace Name ($3.10.4)."
25375 if (xmlSchemaCheckCVCWildcardNamespace(type->attributeWildcard,
25376 iattr->nsName) == 0) {
25378 * Handle processContents.
25380 * SPEC (cvc-wildcard):
25381 * processContents | context-determined declaration:
25382 * "strict" "mustFind"
25386 if (type->attributeWildcard->processContents ==
25387 XML_SCHEMAS_ANY_SKIP) {
25389 * context-determined declaration = "skip"
25391 * SPEC PSVI Assessment Outcome (Attribute)
25392 * [validity] = "notKnown"
25393 * [validation attempted] = "none"
25395 iattr->state = XML_SCHEMAS_ATTR_WILD_SKIP;
25399 * Find an attribute declaration.
25401 iattr->decl = xmlSchemaGetAttributeDecl(vctxt->schema,
25402 iattr->localName, iattr->nsName);
25403 if (iattr->decl != NULL) {
25404 iattr->state = XML_SCHEMAS_ATTR_ASSESSED;
25406 * SPEC (cvc-complex-type)
25407 * (5) "Let [Definition:] the wild IDs be the set of
25408 * all attribute information item to which clause 3.2
25409 * applied and whose `validation` resulted in a
25410 * `context-determined declaration` of mustFind or no
25411 * `context-determined declaration` at all, and whose
25412 * [local name] and [namespace name] resolve (as
25413 * defined by QName resolution (Instance) ($3.15.4)) to
25414 * an attribute declaration whose {type definition} is
25415 * or is derived from ID. Then all of the following
25418 iattr->typeDef = WXS_ATTR_TYPEDEF(iattr->decl);
25419 if (xmlSchemaIsDerivedFromBuiltInType(
25420 iattr->typeDef, XML_SCHEMAS_ID)) {
25422 * SPEC (5.1) "There must be no more than one
25423 * item in `wild IDs`."
25425 if (wildIDs != 0) {
25427 iattr->state = XML_SCHEMAS_ATTR_ERR_WILD_DUPLICATE_ID;
25433 * SPEC (cvc-complex-type)
25434 * (5.2) "If `wild IDs` is non-empty, there must not
25435 * be any attribute uses among the {attribute uses}
25436 * whose {attribute declaration}'s {type definition}
25437 * is or is derived from ID."
25439 if (attrUseList != NULL) {
25440 for (j = 0; j < attrUseList->nbItems; j++) {
25441 if (xmlSchemaIsDerivedFromBuiltInType(
25442 WXS_ATTRUSE_TYPEDEF(attrUseList->items[j]),
25444 /* URGENT VAL TODO: implement */
25445 iattr->state = XML_SCHEMAS_ATTR_ERR_WILD_AND_USE_ID;
25452 } else if (type->attributeWildcard->processContents ==
25453 XML_SCHEMAS_ANY_LAX) {
25454 iattr->state = XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL;
25456 * SPEC PSVI Assessment Outcome (Attribute)
25457 * [validity] = "notKnown"
25458 * [validation attempted] = "none"
25461 iattr->state = XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL;
25467 if (vctxt->nbAttrInfos == 0)
25471 * Get the owner element; needed for creation of default attributes.
25472 * This fixes bug #341337, reported by David Grohmann.
25474 if (vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) {
25475 xmlSchemaNodeInfoPtr ielem = vctxt->elemInfos[vctxt->depth];
25476 if (ielem && ielem->node && ielem->node->doc)
25477 defAttrOwnerElem = ielem->node;
25480 * Validate values, create default attributes, evaluate IDCs.
25482 for (i = 0; i < vctxt->nbAttrInfos; i++) {
25483 iattr = vctxt->attrInfos[i];
25485 * VAL TODO: Note that we won't try to resolve IDCs to
25486 * "lax" and "skip" validated attributes. Check what to
25489 if ((iattr->state != XML_SCHEMAS_ATTR_ASSESSED) &&
25490 (iattr->state != XML_SCHEMAS_ATTR_DEFAULT))
25493 * VAL TODO: What to do if the type definition is missing?
25495 if (iattr->typeDef == NULL) {
25496 iattr->state = XML_SCHEMAS_ATTR_ERR_NO_TYPE;
25500 ACTIVATE_ATTRIBUTE(iattr);
25504 if (vctxt->xpathStates != NULL) {
25508 xpathRes = xmlSchemaXPathEvaluate(vctxt,
25509 XML_ATTRIBUTE_NODE);
25510 if (xpathRes == -1) {
25511 VERROR_INT("xmlSchemaVAttributesComplex",
25512 "calling xmlSchemaXPathEvaluate()");
25513 goto internal_error;
25517 if (iattr->state == XML_SCHEMAS_ATTR_DEFAULT) {
25519 * Default/fixed attributes.
25520 * We need the value only if we need to resolve IDCs or
25521 * will create default attributes.
25523 if ((xpathRes) || (defAttrOwnerElem)) {
25524 if (iattr->use->defValue != NULL) {
25525 iattr->value = (xmlChar *) iattr->use->defValue;
25526 iattr->val = iattr->use->defVal;
25528 iattr->value = (xmlChar *) iattr->decl->defValue;
25529 iattr->val = iattr->decl->defVal;
25532 * IDCs will consume the precomputed default value,
25533 * so we need to clone it.
25535 if (iattr->val == NULL) {
25536 VERROR_INT("xmlSchemaVAttributesComplex",
25537 "default/fixed value on an attribute use was "
25538 "not precomputed");
25539 goto internal_error;
25541 iattr->val = xmlSchemaCopyValue(iattr->val);
25542 if (iattr->val == NULL) {
25543 VERROR_INT("xmlSchemaVAttributesComplex",
25544 "calling xmlSchemaCopyValue()");
25545 goto internal_error;
25549 * PSVI: Add the default attribute to the current element.
25550 * VAL TODO: Should we use the *normalized* value? This currently
25551 * uses the *initial* value.
25554 if (defAttrOwnerElem) {
25555 xmlChar *normValue;
25556 const xmlChar *value;
25558 value = iattr->value;
25560 * Normalize the value.
25562 normValue = xmlSchemaNormalizeValue(iattr->typeDef,
25564 if (normValue != NULL)
25565 value = BAD_CAST normValue;
25567 if (iattr->nsName == NULL) {
25568 if (xmlNewProp(defAttrOwnerElem,
25569 iattr->localName, value) == NULL) {
25570 VERROR_INT("xmlSchemaVAttributesComplex",
25571 "calling xmlNewProp()");
25572 if (normValue != NULL)
25573 xmlFree(normValue);
25574 goto internal_error;
25579 ns = xmlSearchNsByHref(defAttrOwnerElem->doc,
25580 defAttrOwnerElem, iattr->nsName);
25582 xmlChar prefix[12];
25586 * Create a namespace declaration on the validation
25587 * root node if no namespace declaration is in scope.
25590 snprintf((char *) prefix, 12, "p%d", counter++);
25591 ns = xmlSearchNs(defAttrOwnerElem->doc,
25592 defAttrOwnerElem, BAD_CAST prefix);
25593 if (counter > 1000) {
25595 "xmlSchemaVAttributesComplex",
25596 "could not compute a ns prefix for a "
25597 "default/fixed attribute");
25598 if (normValue != NULL)
25599 xmlFree(normValue);
25600 goto internal_error;
25602 } while (ns != NULL);
25603 ns = xmlNewNs(vctxt->validationRoot,
25604 iattr->nsName, BAD_CAST prefix);
25608 * http://lists.w3.org/Archives/Public/www-xml-schema-comments/2005JulSep/0406.html
25609 * If we have QNames: do we need to ensure there's a
25610 * prefix defined for the QName?
25612 xmlNewNsProp(defAttrOwnerElem, ns, iattr->localName, value);
25614 if (normValue != NULL)
25615 xmlFree(normValue);
25618 * Go directly to IDC evaluation.
25623 * Validate the value.
25625 if (vctxt->value != NULL) {
25627 * Free last computed value; just for safety reasons.
25629 xmlSchemaFreeValue(vctxt->value);
25630 vctxt->value = NULL;
25633 * Note that the attribute *use* can be unavailable, if
25634 * the attribute was a wild attribute.
25636 if ((iattr->decl->flags & XML_SCHEMAS_ATTR_FIXED) ||
25637 ((iattr->use != NULL) &&
25638 (iattr->use->flags & XML_SCHEMAS_ATTR_FIXED)))
25643 * SPEC (cvc-attribute)
25644 * (3) "The item's `normalized value` must be locally `valid`
25645 * with respect to that {type definition} as per
25646 * String Valid ($3.14.4)."
25648 * VAL TODO: Do we already have the
25649 * "normalized attribute value" here?
25651 if (xpathRes || fixed) {
25652 iattr->flags |= XML_SCHEMA_NODE_INFO_VALUE_NEEDED;
25654 * Request a computed value.
25656 res = xmlSchemaVCheckCVCSimpleType(
25658 iattr->node, iattr->typeDef, iattr->value, &(iattr->val),
25661 res = xmlSchemaVCheckCVCSimpleType(
25663 iattr->node, iattr->typeDef, iattr->value, NULL,
25669 VERROR_INT("xmlSchemaVAttributesComplex",
25670 "calling xmlSchemaStreamValidateSimpleTypeValue()");
25671 goto internal_error;
25673 iattr->state = XML_SCHEMAS_ATTR_INVALID_VALUE;
25675 * SPEC PSVI Assessment Outcome (Attribute)
25676 * [validity] = "invalid"
25683 * SPEC Attribute Locally Valid (Use) (cvc-au)
25684 * "For an attribute information item to be `valid`
25685 * with respect to an attribute use its *normalized*
25686 * value must match the *canonical* lexical
25687 * representation of the attribute use's {value
25688 * constraint}value, if it is present and fixed."
25690 * VAL TODO: The requirement for the *canonical* value
25691 * will be removed in XML Schema 1.1.
25694 * SPEC Attribute Locally Valid (cvc-attribute)
25695 * (4) "The item's *actual* value must match the *value* of
25696 * the {value constraint}, if it is present and fixed."
25698 if (iattr->val == NULL) {
25699 /* VAL TODO: A value was not precomputed. */
25703 if ((iattr->use != NULL) &&
25704 (iattr->use->defValue != NULL)) {
25705 if (iattr->use->defVal == NULL) {
25706 /* VAL TODO: A default value was not precomputed. */
25710 iattr->vcValue = iattr->use->defValue;
25712 if (xmlSchemaCompareValuesWhtsp(attr->val,
25713 (xmlSchemaWhitespaceValueType) ws,
25715 (xmlSchemaWhitespaceValueType) ws) != 0) {
25717 if (! xmlSchemaAreValuesEqual(iattr->val, iattr->use->defVal))
25718 iattr->state = XML_SCHEMAS_ATTR_ERR_FIXED_VALUE;
25720 if (iattr->decl->defVal == NULL) {
25721 /* VAL TODO: A default value was not precomputed. */
25725 iattr->vcValue = iattr->decl->defValue;
25727 if (xmlSchemaCompareValuesWhtsp(attr->val,
25728 (xmlSchemaWhitespaceValueType) ws,
25730 (xmlSchemaWhitespaceValueType) ws) != 0) {
25732 if (! xmlSchemaAreValuesEqual(iattr->val, iattr->decl->defVal))
25733 iattr->state = XML_SCHEMAS_ATTR_ERR_FIXED_VALUE;
25736 * [validity] = "valid"
25744 if (xmlSchemaXPathProcessHistory(vctxt,
25745 vctxt->depth +1) == -1) {
25746 VERROR_INT("xmlSchemaVAttributesComplex",
25747 "calling xmlSchemaXPathEvaluate()");
25748 goto internal_error;
25750 } else if (vctxt->xpathStates != NULL)
25751 xmlSchemaXPathPop(vctxt);
25757 for (i = 0; i < vctxt->nbAttrInfos; i++) {
25758 iattr = vctxt->attrInfos[i];
25759 if ((iattr->state == XML_SCHEMAS_ATTR_META) ||
25760 (iattr->state == XML_SCHEMAS_ATTR_ASSESSED) ||
25761 (iattr->state == XML_SCHEMAS_ATTR_WILD_SKIP) ||
25762 (iattr->state == XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL))
25764 ACTIVATE_ATTRIBUTE(iattr);
25765 switch (iattr->state) {
25766 case XML_SCHEMAS_ATTR_ERR_MISSING: {
25767 xmlChar *str = NULL;
25769 xmlSchemaCustomErr(ACTXT_CAST vctxt,
25770 XML_SCHEMAV_CVC_COMPLEX_TYPE_4, NULL, NULL,
25771 "The attribute '%s' is required but missing",
25772 xmlSchemaFormatQName(&str,
25773 iattr->decl->targetNamespace,
25774 iattr->decl->name),
25779 case XML_SCHEMAS_ATTR_ERR_NO_TYPE:
25780 VERROR(XML_SCHEMAV_CVC_ATTRIBUTE_2, NULL,
25781 "The type definition is absent");
25783 case XML_SCHEMAS_ATTR_ERR_FIXED_VALUE:
25784 xmlSchemaCustomErr(ACTXT_CAST vctxt,
25785 XML_SCHEMAV_CVC_AU, NULL, NULL,
25786 "The value '%s' does not match the fixed "
25787 "value constraint '%s'",
25788 iattr->value, iattr->vcValue);
25790 case XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL:
25791 VERROR(XML_SCHEMAV_CVC_WILDCARD, NULL,
25792 "No matching global attribute declaration available, but "
25793 "demanded by the strict wildcard");
25795 case XML_SCHEMAS_ATTR_UNKNOWN:
25796 if (iattr->metaType)
25799 * MAYBE VAL TODO: One might report different error messages
25800 * for the following errors.
25802 if (type->attributeWildcard == NULL) {
25803 xmlSchemaIllegalAttrErr(ACTXT_CAST vctxt,
25804 XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_1, iattr, NULL);
25806 xmlSchemaIllegalAttrErr(ACTXT_CAST vctxt,
25807 XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_2, iattr, NULL);
25823 xmlSchemaValidateElemWildcard(xmlSchemaValidCtxtPtr vctxt,
25826 xmlSchemaWildcardPtr wild = (xmlSchemaWildcardPtr) vctxt->inode->decl;
25828 * The namespace of the element was already identified to be
25829 * matching the wildcard.
25831 if ((skip == NULL) || (wild == NULL) ||
25832 (wild->type != XML_SCHEMA_TYPE_ANY)) {
25833 VERROR_INT("xmlSchemaValidateElemWildcard",
25838 if (wild->processContents == XML_SCHEMAS_ANY_SKIP) {
25840 * URGENT VAL TODO: Either we need to position the stream to the
25841 * next sibling, or walk the whole subtree.
25847 xmlSchemaElementPtr decl = NULL;
25849 decl = xmlSchemaGetElem(vctxt->schema,
25850 vctxt->inode->localName, vctxt->inode->nsName);
25851 if (decl != NULL) {
25852 vctxt->inode->decl = decl;
25856 if (wild->processContents == XML_SCHEMAS_ANY_STRICT) {
25857 /* VAL TODO: Change to proper error code. */
25858 VERROR(XML_SCHEMAV_CVC_ELT_1, NULL, /* WXS_BASIC_CAST wild */
25859 "No matching global element declaration available, but "
25860 "demanded by the strict wildcard");
25861 return (vctxt->err);
25863 if (vctxt->nbAttrInfos != 0) {
25864 xmlSchemaAttrInfoPtr iattr;
25866 * SPEC Validation Rule: Schema-Validity Assessment (Element)
25867 * (1.2.1.2.1) - (1.2.1.2.3 )
25869 * Use the xsi:type attribute for the type definition.
25871 iattr = xmlSchemaGetMetaAttrInfo(vctxt,
25872 XML_SCHEMA_ATTR_INFO_META_XSI_TYPE);
25873 if (iattr != NULL) {
25874 if (xmlSchemaProcessXSIType(vctxt, iattr,
25875 &(vctxt->inode->typeDef), NULL) == -1) {
25876 VERROR_INT("xmlSchemaValidateElemWildcard",
25877 "calling xmlSchemaProcessXSIType() to "
25878 "process the attribute 'xsi:nil'");
25882 * Don't return an error on purpose.
25888 * SPEC Validation Rule: Schema-Validity Assessment (Element)
25890 * Fallback to "anyType".
25892 vctxt->inode->typeDef =
25893 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE);
25898 * xmlSchemaCheckCOSValidDefault:
25900 * This will be called if: not nilled, no content and a default/fixed
25901 * value is provided.
25905 xmlSchemaCheckCOSValidDefault(xmlSchemaValidCtxtPtr vctxt,
25906 const xmlChar *value,
25907 xmlSchemaValPtr *val)
25910 xmlSchemaNodeInfoPtr inode = vctxt->inode;
25913 * cos-valid-default:
25914 * Schema Component Constraint: Element Default Valid (Immediate)
25915 * For a string to be a valid default with respect to a type
25916 * definition the appropriate case among the following must be true:
25918 if WXS_IS_COMPLEX(inode->typeDef) {
25922 * SPEC (2.1) "its {content type} must be a simple type definition
25924 * SPEC (2.2.2) "If the {content type} is mixed, then the {content
25925 * type}'s particle must be `emptiable` as defined by
25926 * Particle Emptiable ($3.9.6)."
25928 if ((! WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) &&
25929 ((! WXS_HAS_MIXED_CONTENT(inode->typeDef)) ||
25930 (! WXS_EMPTIABLE(inode->typeDef)))) {
25931 ret = XML_SCHEMAP_COS_VALID_DEFAULT_2_1;
25932 /* NOTE that this covers (2.2.2) as well. */
25934 "For a string to be a valid default, the type definition "
25935 "must be a simple type or a complex type with simple content "
25936 "or mixed content and a particle emptiable");
25941 * 1 If the type definition is a simple type definition, then the string
25942 * must be `valid` with respect to that definition as defined by String
25947 * 2.2.1 If the {content type} is a simple type definition, then the
25948 * string must be `valid` with respect to that simple type definition
25949 * as defined by String Valid ($3.14.4).
25951 if (WXS_IS_SIMPLE(inode->typeDef)) {
25953 ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST vctxt,
25954 NULL, inode->typeDef, value, val, 1, 1, 0);
25956 } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) {
25958 ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST vctxt,
25959 NULL, inode->typeDef->contentTypeDef, value, val, 1, 1, 0);
25962 VERROR_INT("xmlSchemaCheckCOSValidDefault",
25963 "calling xmlSchemaVCheckCVCSimpleType()");
25969 xmlSchemaVContentModelCallback(xmlSchemaValidCtxtPtr vctxt ATTRIBUTE_UNUSED,
25970 const xmlChar * name ATTRIBUTE_UNUSED,
25971 xmlSchemaElementPtr item,
25972 xmlSchemaNodeInfoPtr inode)
25974 inode->decl = item;
25975 #ifdef DEBUG_CONTENT
25977 xmlChar *str = NULL;
25979 if (item->type == XML_SCHEMA_TYPE_ELEMENT) {
25980 xmlGenericError(xmlGenericErrorContext,
25981 "AUTOMATON callback for '%s' [declaration]\n",
25982 xmlSchemaFormatQName(&str,
25983 inode->localName, inode->nsName));
25985 xmlGenericError(xmlGenericErrorContext,
25986 "AUTOMATON callback for '%s' [wildcard]\n",
25987 xmlSchemaFormatQName(&str,
25988 inode->localName, inode->nsName));
25997 xmlSchemaValidatorPushElem(xmlSchemaValidCtxtPtr vctxt)
25999 vctxt->inode = xmlSchemaGetFreshElemInfo(vctxt);
26000 if (vctxt->inode == NULL) {
26001 VERROR_INT("xmlSchemaValidatorPushElem",
26002 "calling xmlSchemaGetFreshElemInfo()");
26005 vctxt->nbAttrInfos = 0;
26010 xmlSchemaVCheckINodeDataType(xmlSchemaValidCtxtPtr vctxt,
26011 xmlSchemaNodeInfoPtr inode,
26012 xmlSchemaTypePtr type,
26013 const xmlChar *value)
26015 if (inode->flags & XML_SCHEMA_NODE_INFO_VALUE_NEEDED)
26016 return (xmlSchemaVCheckCVCSimpleType(
26017 ACTXT_CAST vctxt, NULL,
26018 type, value, &(inode->val), 1, 1, 0));
26020 return (xmlSchemaVCheckCVCSimpleType(
26021 ACTXT_CAST vctxt, NULL,
26022 type, value, NULL, 1, 0, 0));
26028 * Process END of element.
26031 xmlSchemaValidatorPopElem(xmlSchemaValidCtxtPtr vctxt)
26034 xmlSchemaNodeInfoPtr inode = vctxt->inode;
26036 if (vctxt->nbAttrInfos != 0)
26037 xmlSchemaClearAttrInfos(vctxt);
26038 if (inode->flags & XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED) {
26040 * This element was not expected;
26041 * we will not validate child elements of broken parents.
26042 * Skip validation of all content of the parent.
26044 vctxt->skipDepth = vctxt->depth -1;
26047 if ((inode->typeDef == NULL) ||
26048 (inode->flags & XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE)) {
26050 * 1. the type definition might be missing if the element was
26052 * 2. it might be abstract.
26057 * Check the content model.
26059 if ((inode->typeDef->contentType == XML_SCHEMA_CONTENT_MIXED) ||
26060 (inode->typeDef->contentType == XML_SCHEMA_CONTENT_ELEMENTS)) {
26063 * Workaround for "anyType".
26065 if (inode->typeDef->builtInType == XML_SCHEMAS_ANYTYPE)
26066 goto character_content;
26068 if ((inode->flags & XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT) == 0) {
26069 xmlChar *values[10];
26070 int terminal, nbval = 10, nbneg;
26072 if (inode->regexCtxt == NULL) {
26074 * Create the regex context.
26077 xmlRegNewExecCtxt(inode->typeDef->contModel,
26078 (xmlRegExecCallbacks) xmlSchemaVContentModelCallback,
26080 if (inode->regexCtxt == NULL) {
26081 VERROR_INT("xmlSchemaValidatorPopElem",
26082 "failed to create a regex context");
26083 goto internal_error;
26085 #ifdef DEBUG_AUTOMATA
26086 xmlGenericError(xmlGenericErrorContext,
26087 "AUTOMATON create on '%s'\n", inode->localName);
26092 * Do not check further content if the node has been nilled
26094 if (INODE_NILLED(inode)) {
26096 #ifdef DEBUG_AUTOMATA
26097 xmlGenericError(xmlGenericErrorContext,
26098 "AUTOMATON succeeded on nilled '%s'\n",
26105 * Get hold of the still expected content, since a further
26106 * call to xmlRegExecPushString() will lose this information.
26108 xmlRegExecNextValues(inode->regexCtxt,
26109 &nbval, &nbneg, &values[0], &terminal);
26110 ret = xmlRegExecPushString(inode->regexCtxt, NULL, NULL);
26111 if ((ret<0) || ((ret==0) && (!INODE_NILLED(inode)))) {
26113 * Still missing something.
26117 XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT;
26118 xmlSchemaComplexTypeErr(ACTXT_CAST vctxt,
26119 XML_SCHEMAV_ELEMENT_CONTENT, NULL, NULL,
26120 "Missing child element(s)",
26121 nbval, nbneg, values);
26122 #ifdef DEBUG_AUTOMATA
26123 xmlGenericError(xmlGenericErrorContext,
26124 "AUTOMATON missing ERROR on '%s'\n",
26129 * Content model is satisfied.
26132 #ifdef DEBUG_AUTOMATA
26133 xmlGenericError(xmlGenericErrorContext,
26134 "AUTOMATON succeeded on '%s'\n",
26144 if (inode->typeDef->contentType == XML_SCHEMA_CONTENT_ELEMENTS)
26149 if (vctxt->value != NULL) {
26150 xmlSchemaFreeValue(vctxt->value);
26151 vctxt->value = NULL;
26154 * Check character content.
26156 if (inode->decl == NULL) {
26158 * Speedup if no declaration exists.
26160 if (WXS_IS_SIMPLE(inode->typeDef)) {
26161 ret = xmlSchemaVCheckINodeDataType(vctxt,
26162 inode, inode->typeDef, inode->value);
26163 } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) {
26164 ret = xmlSchemaVCheckINodeDataType(vctxt,
26165 inode, inode->typeDef->contentTypeDef,
26169 VERROR_INT("xmlSchemaValidatorPopElem",
26170 "calling xmlSchemaVCheckCVCSimpleType()");
26171 goto internal_error;
26176 * cvc-elt (3.3.4) : 5
26177 * The appropriate case among the following must be true:
26180 * cvc-elt (3.3.4) : 5.1
26181 * If the declaration has a {value constraint},
26182 * the item has neither element nor character [children] and
26183 * clause 3.2 has not applied, then all of the following must be true:
26185 if ((inode->decl->value != NULL) &&
26186 (inode->flags & XML_SCHEMA_ELEM_INFO_EMPTY) &&
26187 (! INODE_NILLED(inode))) {
26189 * cvc-elt (3.3.4) : 5.1.1
26190 * If the `actual type definition` is a `local type definition`
26191 * then the canonical lexical representation of the {value constraint}
26192 * value must be a valid default for the `actual type definition` as
26193 * defined in Element Default Valid (Immediate) ($3.3.6).
26196 * NOTE: 'local' above means types acquired by xsi:type.
26197 * NOTE: Although the *canonical* value is stated, it is not
26198 * relevant if canonical or not. Additionally XML Schema 1.1
26199 * will removed this requirement as well.
26201 if (inode->flags & XML_SCHEMA_ELEM_INFO_LOCAL_TYPE) {
26203 ret = xmlSchemaCheckCOSValidDefault(vctxt,
26204 inode->decl->value, &(inode->val));
26207 VERROR_INT("xmlSchemaValidatorPopElem",
26208 "calling xmlSchemaCheckCOSValidDefault()");
26209 goto internal_error;
26214 * Stop here, to avoid redundant validation of the value
26220 * cvc-elt (3.3.4) : 5.1.2
26221 * The element information item with the canonical lexical
26222 * representation of the {value constraint} value used as its
26223 * `normalized value` must be `valid` with respect to the
26224 * `actual type definition` as defined by Element Locally Valid (Type)
26227 if (WXS_IS_SIMPLE(inode->typeDef)) {
26228 ret = xmlSchemaVCheckINodeDataType(vctxt,
26229 inode, inode->typeDef, inode->decl->value);
26230 } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) {
26231 ret = xmlSchemaVCheckINodeDataType(vctxt,
26232 inode, inode->typeDef->contentTypeDef,
26233 inode->decl->value);
26237 VERROR_INT("xmlSchemaValidatorPopElem",
26238 "calling xmlSchemaVCheckCVCSimpleType()");
26239 goto internal_error;
26246 * PSVI: Create a text node on the instance element.
26248 if ((vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) &&
26249 (inode->node != NULL)) {
26250 xmlNodePtr textChild;
26251 xmlChar *normValue;
26253 * VAL TODO: Normalize the value.
26255 normValue = xmlSchemaNormalizeValue(inode->typeDef,
26256 inode->decl->value);
26257 if (normValue != NULL) {
26258 textChild = xmlNewText(BAD_CAST normValue);
26259 xmlFree(normValue);
26261 textChild = xmlNewText(inode->decl->value);
26262 if (textChild == NULL) {
26263 VERROR_INT("xmlSchemaValidatorPopElem",
26264 "calling xmlNewText()");
26265 goto internal_error;
26267 xmlAddChild(inode->node, textChild);
26270 } else if (! INODE_NILLED(inode)) {
26272 * 5.2.1 The element information item must be `valid` with respect
26273 * to the `actual type definition` as defined by Element Locally
26274 * Valid (Type) ($3.3.4).
26276 if (WXS_IS_SIMPLE(inode->typeDef)) {
26278 * SPEC (cvc-type) (3.1)
26279 * "If the type definition is a simple type definition, ..."
26280 * (3.1.3) "If clause 3.2 of Element Locally Valid
26281 * (Element) ($3.3.4) did not apply, then the `normalized value`
26282 * must be `valid` with respect to the type definition as defined
26283 * by String Valid ($3.14.4).
26285 ret = xmlSchemaVCheckINodeDataType(vctxt,
26286 inode, inode->typeDef, inode->value);
26287 } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) {
26289 * SPEC (cvc-type) (3.2) "If the type definition is a complex type
26290 * definition, then the element information item must be
26291 * `valid` with respect to the type definition as per
26292 * Element Locally Valid (Complex Type) ($3.4.4);"
26294 * SPEC (cvc-complex-type) (2.2)
26295 * "If the {content type} is a simple type definition, ...
26296 * the `normalized value` of the element information item is
26297 * `valid` with respect to that simple type definition as
26298 * defined by String Valid ($3.14.4)."
26300 ret = xmlSchemaVCheckINodeDataType(vctxt,
26301 inode, inode->typeDef->contentTypeDef, inode->value);
26305 VERROR_INT("xmlSchemaValidatorPopElem",
26306 "calling xmlSchemaVCheckCVCSimpleType()");
26307 goto internal_error;
26312 * 5.2.2 If there is a fixed {value constraint} and clause 3.2 has
26313 * not applied, all of the following must be true:
26315 if ((inode->decl->value != NULL) &&
26316 (inode->decl->flags & XML_SCHEMAS_ELEM_FIXED)) {
26319 * TODO: We will need a computed value, when comparison is
26320 * done on computed values.
26323 * 5.2.2.1 The element information item must have no element
26324 * information item [children].
26327 XML_SCHEMA_ELEM_INFO_HAS_ELEM_CONTENT) {
26328 ret = XML_SCHEMAV_CVC_ELT_5_2_2_1;
26330 "The content must not containt element nodes since "
26331 "there is a fixed value constraint");
26335 * 5.2.2.2 The appropriate case among the following must
26338 if (WXS_HAS_MIXED_CONTENT(inode->typeDef)) {
26340 * 5.2.2.2.1 If the {content type} of the `actual type
26341 * definition` is mixed, then the *initial value* of the
26342 * item must match the canonical lexical representation
26343 * of the {value constraint} value.
26345 * ... the *initial value* of an element information
26346 * item is the string composed of, in order, the
26347 * [character code] of each character information item in
26348 * the [children] of that element information item.
26350 if (! xmlStrEqual(inode->value, inode->decl->value)){
26352 * VAL TODO: Report invalid & expected values as well.
26353 * VAL TODO: Implement the canonical stuff.
26355 ret = XML_SCHEMAV_CVC_ELT_5_2_2_2_1;
26356 xmlSchemaCustomErr(ACTXT_CAST vctxt,
26358 "The initial value '%s' does not match the fixed "
26359 "value constraint '%s'",
26360 inode->value, inode->decl->value);
26363 } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) {
26365 * 5.2.2.2.2 If the {content type} of the `actual type
26366 * definition` is a simple type definition, then the
26367 * *actual value* of the item must match the canonical
26368 * lexical representation of the {value constraint} value.
26371 * VAL TODO: *actual value* is the normalized value, impl.
26373 * VAL TODO: Report invalid & expected values as well.
26374 * VAL TODO: Implement a comparison with the computed values.
26376 if (! xmlStrEqual(inode->value,
26377 inode->decl->value)) {
26378 ret = XML_SCHEMAV_CVC_ELT_5_2_2_2_2;
26379 xmlSchemaCustomErr(ACTXT_CAST vctxt,
26381 "The actual value '%s' does not match the fixed "
26382 "value constraint '%s'",
26384 inode->decl->value);
26393 if (vctxt->depth < 0) {
26394 /* TODO: raise error? */
26397 if (vctxt->depth == vctxt->skipDepth)
26398 vctxt->skipDepth = -1;
26400 * Evaluate the history of XPath state objects.
26402 if (inode->appliedXPath &&
26403 (xmlSchemaXPathProcessHistory(vctxt, vctxt->depth) == -1))
26404 goto internal_error;
26407 * SPEC (6) "The element information item must be `valid` with
26408 * respect to each of the {identity-constraint definitions} as per
26409 * Identity-constraint Satisfied ($3.11.4)."
26412 * PSVI TODO: If we expose IDC node-tables via PSVI then the tables
26413 * need to be built in any case.
26414 * We will currently build IDC node-tables and bubble them only if
26415 * keyrefs do exist.
26419 * Add the current IDC target-nodes to the IDC node-tables.
26421 if ((inode->idcMatchers != NULL) &&
26422 (vctxt->hasKeyrefs || vctxt->createIDCNodeTables))
26424 if (xmlSchemaIDCFillNodeTables(vctxt, inode) == -1)
26425 goto internal_error;
26428 * Validate IDC keyrefs.
26430 if (vctxt->inode->hasKeyrefs)
26431 if (xmlSchemaCheckCVCIDCKeyRef(vctxt) == -1)
26432 goto internal_error;
26434 * Merge/free the IDC table.
26436 if (inode->idcTable != NULL) {
26437 #ifdef DEBUG_IDC_NODE_TABLE
26438 xmlSchemaDebugDumpIDCTable(stdout,
26443 if ((vctxt->depth > 0) &&
26444 (vctxt->hasKeyrefs || vctxt->createIDCNodeTables))
26447 * Merge the IDC node table with the table of the parent node.
26449 if (xmlSchemaBubbleIDCNodeTables(vctxt) == -1)
26450 goto internal_error;
26454 * Clear the current ielem.
26455 * VAL TODO: Don't free the PSVI IDC tables if they are
26456 * requested for the PSVI.
26458 xmlSchemaClearElemInfo(vctxt, inode);
26460 * Skip further processing if we are on the validation root.
26462 if (vctxt->depth == 0) {
26464 vctxt->inode = NULL;
26468 * Reset the keyrefDepth if needed.
26470 if (vctxt->aidcs != NULL) {
26471 xmlSchemaIDCAugPtr aidc = vctxt->aidcs;
26473 if (aidc->keyrefDepth == vctxt->depth) {
26475 * A 'keyrefDepth' of a key/unique IDC matches the current
26476 * depth, this means that we are leaving the scope of the
26477 * top-most keyref IDC which refers to this IDC.
26479 aidc->keyrefDepth = -1;
26482 } while (aidc != NULL);
26485 vctxt->inode = vctxt->elemInfos[vctxt->depth];
26487 * VAL TODO: 7 If the element information item is the `validation root`, it must be
26488 * `valid` per Validation Root Valid (ID/IDREF) ($3.3.4).
26498 * 3.4.4 Complex Type Definition Validation Rules
26499 * Validation Rule: Element Locally Valid (Complex Type) (cvc-complex-type)
26502 xmlSchemaValidateChildElem(xmlSchemaValidCtxtPtr vctxt)
26504 xmlSchemaNodeInfoPtr pielem;
26505 xmlSchemaTypePtr ptype;
26508 if (vctxt->depth <= 0) {
26509 VERROR_INT("xmlSchemaValidateChildElem",
26510 "not intended for the validation root");
26513 pielem = vctxt->elemInfos[vctxt->depth -1];
26514 if (pielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY)
26515 pielem->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY;
26517 * Handle 'nilled' elements.
26519 if (INODE_NILLED(pielem)) {
26521 * SPEC (cvc-elt) (3.3.4) : (3.2.1)
26523 ACTIVATE_PARENT_ELEM;
26524 ret = XML_SCHEMAV_CVC_ELT_3_2_1;
26526 "Neither character nor element content is allowed, "
26527 "because the element was 'nilled'");
26529 goto unexpected_elem;
26532 ptype = pielem->typeDef;
26534 if (ptype->builtInType == XML_SCHEMAS_ANYTYPE) {
26536 * Workaround for "anyType": we have currently no content model
26537 * assigned for "anyType", so handle it explicitely.
26538 * "anyType" has an unbounded, lax "any" wildcard.
26540 vctxt->inode->decl = xmlSchemaGetElem(vctxt->schema,
26541 vctxt->inode->localName,
26542 vctxt->inode->nsName);
26544 if (vctxt->inode->decl == NULL) {
26545 xmlSchemaAttrInfoPtr iattr;
26547 * Process "xsi:type".
26548 * SPEC (cvc-assess-elt) (1.2.1.2.1) - (1.2.1.2.3)
26550 iattr = xmlSchemaGetMetaAttrInfo(vctxt,
26551 XML_SCHEMA_ATTR_INFO_META_XSI_TYPE);
26552 if (iattr != NULL) {
26553 ret = xmlSchemaProcessXSIType(vctxt, iattr,
26554 &(vctxt->inode->typeDef), NULL);
26557 VERROR_INT("xmlSchemaValidateChildElem",
26558 "calling xmlSchemaProcessXSIType() to "
26559 "process the attribute 'xsi:nil'");
26566 * Fallback to "anyType".
26568 * SPEC (cvc-assess-elt)
26569 * "If the item cannot be `strictly assessed`, [...]
26570 * an element information item's schema validity may be laxly
26571 * assessed if its `context-determined declaration` is not
26572 * skip by `validating` with respect to the `ur-type
26573 * definition` as per Element Locally Valid (Type) ($3.3.4)."
26575 vctxt->inode->typeDef =
26576 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE);
26582 switch (ptype->contentType) {
26583 case XML_SCHEMA_CONTENT_EMPTY:
26585 * SPEC (2.1) "If the {content type} is empty, then the
26586 * element information item has no character or element
26587 * information item [children]."
26589 ACTIVATE_PARENT_ELEM
26590 ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1;
26592 "Element content is not allowed, "
26593 "because the content type is empty");
26595 goto unexpected_elem;
26598 case XML_SCHEMA_CONTENT_MIXED:
26599 case XML_SCHEMA_CONTENT_ELEMENTS: {
26600 xmlRegExecCtxtPtr regexCtxt;
26601 xmlChar *values[10];
26602 int terminal, nbval = 10, nbneg;
26604 /* VAL TODO: Optimized "anyType" validation.*/
26606 if (ptype->contModel == NULL) {
26607 VERROR_INT("xmlSchemaValidateChildElem",
26608 "type has elem content but no content model");
26612 * Safety belf for evaluation if the cont. model was already
26613 * examined to be invalid.
26615 if (pielem->flags & XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT) {
26616 VERROR_INT("xmlSchemaValidateChildElem",
26617 "validating elem, but elem content is already invalid");
26621 regexCtxt = pielem->regexCtxt;
26622 if (regexCtxt == NULL) {
26624 * Create the regex context.
26626 regexCtxt = xmlRegNewExecCtxt(ptype->contModel,
26627 (xmlRegExecCallbacks) xmlSchemaVContentModelCallback,
26629 if (regexCtxt == NULL) {
26630 VERROR_INT("xmlSchemaValidateChildElem",
26631 "failed to create a regex context");
26634 pielem->regexCtxt = regexCtxt;
26635 #ifdef DEBUG_AUTOMATA
26636 xmlGenericError(xmlGenericErrorContext, "AUTOMATA create on '%s'\n",
26637 pielem->localName);
26642 * SPEC (2.4) "If the {content type} is element-only or mixed,
26643 * then the sequence of the element information item's
26644 * element information item [children], if any, taken in
26645 * order, is `valid` with respect to the {content type}'s
26646 * particle, as defined in Element Sequence Locally Valid
26647 * (Particle) ($3.9.4)."
26649 ret = xmlRegExecPushString2(regexCtxt,
26650 vctxt->inode->localName,
26651 vctxt->inode->nsName,
26653 #ifdef DEBUG_AUTOMATA
26655 xmlGenericError(xmlGenericErrorContext,
26656 "AUTOMATON push ERROR for '%s' on '%s'\n",
26657 vctxt->inode->localName, pielem->localName);
26659 xmlGenericError(xmlGenericErrorContext,
26660 "AUTOMATON push OK for '%s' on '%s'\n",
26661 vctxt->inode->localName, pielem->localName);
26663 if (vctxt->err == XML_SCHEMAV_INTERNAL) {
26664 VERROR_INT("xmlSchemaValidateChildElem",
26665 "calling xmlRegExecPushString2()");
26669 xmlRegExecErrInfo(regexCtxt, NULL, &nbval, &nbneg,
26670 &values[0], &terminal);
26671 xmlSchemaComplexTypeErr(ACTXT_CAST vctxt,
26672 XML_SCHEMAV_ELEMENT_CONTENT, NULL,NULL,
26673 "This element is not expected",
26674 nbval, nbneg, values);
26676 goto unexpected_elem;
26681 case XML_SCHEMA_CONTENT_SIMPLE:
26682 case XML_SCHEMA_CONTENT_BASIC:
26683 ACTIVATE_PARENT_ELEM
26684 if (WXS_IS_COMPLEX(ptype)) {
26686 * SPEC (cvc-complex-type) (2.2)
26687 * "If the {content type} is a simple type definition, then
26688 * the element information item has no element information
26689 * item [children], ..."
26691 ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2;
26692 VERROR(ret, NULL, "Element content is not allowed, "
26693 "because the content type is a simple type definition");
26696 * SPEC (cvc-type) (3.1.2) "The element information item must
26697 * have no element information item [children]."
26699 ret = XML_SCHEMAV_CVC_TYPE_3_1_2;
26700 VERROR(ret, NULL, "Element content is not allowed, "
26701 "because the type definition is simple");
26705 goto unexpected_elem;
26714 * Pop this element and set the skipDepth to skip
26715 * all further content of the parent element.
26717 vctxt->skipDepth = vctxt->depth;
26718 vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED;
26719 pielem->flags |= XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT;
26723 #define XML_SCHEMA_PUSH_TEXT_PERSIST 1
26724 #define XML_SCHEMA_PUSH_TEXT_CREATED 2
26725 #define XML_SCHEMA_PUSH_TEXT_VOLATILE 3
26728 xmlSchemaVPushText(xmlSchemaValidCtxtPtr vctxt,
26729 int nodeType, const xmlChar *value, int len,
26730 int mode, int *consumed)
26733 * Unfortunately we have to duplicate the text sometimes.
26734 * OPTIMIZE: Maybe we could skip it, if:
26735 * 1. content type is simple
26736 * 2. whitespace is "collapse"
26737 * 3. it consists of whitespace only
26739 * Process character content.
26741 if (consumed != NULL)
26743 if (INODE_NILLED(vctxt->inode)) {
26745 * SPEC cvc-elt (3.3.4 - 3.2.1)
26746 * "The element information item must have no character or
26747 * element information item [children]."
26749 VERROR(XML_SCHEMAV_CVC_ELT_3_2_1, NULL,
26750 "Neither character nor element content is allowed "
26751 "because the element is 'nilled'");
26752 return (vctxt->err);
26755 * SPEC (2.1) "If the {content type} is empty, then the
26756 * element information item has no character or element
26757 * information item [children]."
26759 if (vctxt->inode->typeDef->contentType ==
26760 XML_SCHEMA_CONTENT_EMPTY) {
26761 VERROR(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1, NULL,
26762 "Character content is not allowed, "
26763 "because the content type is empty");
26764 return (vctxt->err);
26767 if (vctxt->inode->typeDef->contentType ==
26768 XML_SCHEMA_CONTENT_ELEMENTS) {
26769 if ((nodeType != XML_TEXT_NODE) ||
26770 (! xmlSchemaIsBlank((xmlChar *) value, len))) {
26772 * SPEC cvc-complex-type (2.3)
26773 * "If the {content type} is element-only, then the
26774 * element information item has no character information
26775 * item [children] other than those whose [character
26776 * code] is defined as a white space in [XML 1.0 (Second
26779 VERROR(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_3, NULL,
26780 "Character content other than whitespace is not allowed "
26781 "because the content type is 'element-only'");
26782 return (vctxt->err);
26787 if ((value == NULL) || (value[0] == 0))
26791 * NOTE that even if the content type is *mixed*, we need the
26792 * *initial value* for default/fixed value constraints.
26794 if ((vctxt->inode->typeDef->contentType == XML_SCHEMA_CONTENT_MIXED) &&
26795 ((vctxt->inode->decl == NULL) ||
26796 (vctxt->inode->decl->value == NULL)))
26799 if (vctxt->inode->value == NULL) {
26804 case XML_SCHEMA_PUSH_TEXT_PERSIST:
26806 * When working on a tree.
26808 vctxt->inode->value = value;
26810 case XML_SCHEMA_PUSH_TEXT_CREATED:
26812 * When working with the reader.
26813 * The value will be freed by the element info.
26815 vctxt->inode->value = value;
26816 if (consumed != NULL)
26818 vctxt->inode->flags |=
26819 XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES;
26821 case XML_SCHEMA_PUSH_TEXT_VOLATILE:
26823 * When working with SAX.
26824 * The value will be freed by the element info.
26827 vctxt->inode->value = BAD_CAST xmlStrndup(value, len);
26829 vctxt->inode->value = BAD_CAST xmlStrdup(value);
26830 vctxt->inode->flags |=
26831 XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES;
26838 len = xmlStrlen(value);
26840 * Concat the value.
26842 if (vctxt->inode->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) {
26843 vctxt->inode->value = BAD_CAST xmlStrncat(
26844 (xmlChar *) vctxt->inode->value, value, len);
26846 vctxt->inode->value =
26847 BAD_CAST xmlStrncatNew(vctxt->inode->value, value, len);
26848 vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES;
26856 xmlSchemaValidateElem(xmlSchemaValidCtxtPtr vctxt)
26860 if ((vctxt->skipDepth != -1) &&
26861 (vctxt->depth >= vctxt->skipDepth)) {
26862 VERROR_INT("xmlSchemaValidateElem",
26864 goto internal_error;
26866 if (vctxt->xsiAssemble) {
26868 * We will stop validation if there was an error during
26869 * dynamic schema construction.
26870 * Note that we simply set @skipDepth to 0, this could
26871 * mean that a streaming document via SAX would be
26872 * still read to the end but it won't be validated any more.
26873 * TODO: If we are sure how to stop the validation at once
26874 * for all input scenarios, then this should be changed to
26875 * instantly stop the validation.
26877 ret = xmlSchemaAssembleByXSI(vctxt);
26880 goto internal_error;
26881 vctxt->skipDepth = 0;
26885 * Augment the IDC definitions for the main schema and all imported ones
26886 * NOTE: main schema is the first in the imported list
26888 xmlHashScan(vctxt->schema->schemasImports,(xmlHashScanner)xmlSchemaAugmentImportedIDC, vctxt);
26890 if (vctxt->depth > 0) {
26892 * Validate this element against the content model
26895 ret = xmlSchemaValidateChildElem(vctxt);
26898 VERROR_INT("xmlSchemaValidateElem",
26899 "calling xmlSchemaStreamValidateChildElement()");
26900 goto internal_error;
26904 if (vctxt->depth == vctxt->skipDepth)
26906 if ((vctxt->inode->decl == NULL) &&
26907 (vctxt->inode->typeDef == NULL)) {
26908 VERROR_INT("xmlSchemaValidateElem",
26909 "the child element was valid but neither the "
26910 "declaration nor the type was set");
26911 goto internal_error;
26915 * Get the declaration of the validation root.
26917 vctxt->inode->decl = xmlSchemaGetElem(vctxt->schema,
26918 vctxt->inode->localName,
26919 vctxt->inode->nsName);
26920 if (vctxt->inode->decl == NULL) {
26921 ret = XML_SCHEMAV_CVC_ELT_1;
26923 "No matching global declaration available "
26924 "for the validation root");
26929 if (vctxt->inode->decl == NULL)
26930 goto type_validation;
26932 if (vctxt->inode->decl->type == XML_SCHEMA_TYPE_ANY) {
26937 ret = xmlSchemaValidateElemWildcard(vctxt, &skip);
26940 VERROR_INT("xmlSchemaValidateElem",
26941 "calling xmlSchemaValidateElemWildcard()");
26942 goto internal_error;
26947 vctxt->skipDepth = vctxt->depth;
26951 * The declaration might be set by the wildcard validation,
26952 * when the processContents is "lax" or "strict".
26954 if (vctxt->inode->decl->type != XML_SCHEMA_TYPE_ELEMENT) {
26956 * Clear the "decl" field to not confuse further processing.
26958 vctxt->inode->decl = NULL;
26959 goto type_validation;
26963 * Validate against the declaration.
26965 ret = xmlSchemaValidateElemDecl(vctxt);
26968 VERROR_INT("xmlSchemaValidateElem",
26969 "calling xmlSchemaValidateElemDecl()");
26970 goto internal_error;
26975 * Validate against the type definition.
26979 if (vctxt->inode->typeDef == NULL) {
26980 vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE;
26981 ret = XML_SCHEMAV_CVC_TYPE_1;
26983 "The type definition is absent");
26986 if (vctxt->inode->typeDef->flags & XML_SCHEMAS_TYPE_ABSTRACT) {
26987 vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE;
26988 ret = XML_SCHEMAV_CVC_TYPE_2;
26990 "The type definition is abstract");
26994 * Evaluate IDCs. Do it here, since new IDC matchers are registered
26995 * during validation against the declaration. This must be done
26996 * _before_ attribute validation.
26998 if (vctxt->xpathStates != NULL) {
26999 ret = xmlSchemaXPathEvaluate(vctxt, XML_ELEMENT_NODE);
27000 vctxt->inode->appliedXPath = 1;
27002 VERROR_INT("xmlSchemaValidateElem",
27003 "calling xmlSchemaXPathEvaluate()");
27004 goto internal_error;
27008 * Validate attributes.
27010 if (WXS_IS_COMPLEX(vctxt->inode->typeDef)) {
27011 if ((vctxt->nbAttrInfos != 0) ||
27012 (vctxt->inode->typeDef->attrUses != NULL)) {
27014 ret = xmlSchemaVAttributesComplex(vctxt);
27016 } else if (vctxt->nbAttrInfos != 0) {
27018 ret = xmlSchemaVAttributesSimple(vctxt);
27021 * Clear registered attributes.
27023 if (vctxt->nbAttrInfos != 0)
27024 xmlSchemaClearAttrInfos(vctxt);
27026 VERROR_INT("xmlSchemaValidateElem",
27027 "calling attributes validation");
27028 goto internal_error;
27031 * Don't return an error if attributes are invalid on purpose.
27037 vctxt->skipDepth = vctxt->depth;
27043 #ifdef XML_SCHEMA_READER_ENABLED
27045 xmlSchemaVReaderWalk(xmlSchemaValidCtxtPtr vctxt)
27047 const int WHTSP = 13, SIGN_WHTSP = 14, END_ELEM = 15;
27048 int depth, nodeType, ret = 0, consumed;
27049 xmlSchemaNodeInfoPtr ielem;
27052 ret = xmlTextReaderRead(vctxt->reader);
27054 * Move to the document element.
27057 nodeType = xmlTextReaderNodeType(vctxt->reader);
27058 if (nodeType == XML_ELEMENT_NODE)
27060 ret = xmlTextReaderRead(vctxt->reader);
27067 depth = xmlTextReaderDepth(vctxt->reader);
27068 nodeType = xmlTextReaderNodeType(vctxt->reader);
27070 if (nodeType == XML_ELEMENT_NODE) {
27073 if (xmlSchemaValidatorPushElem(vctxt) == -1) {
27074 VERROR_INT("xmlSchemaVReaderWalk",
27075 "calling xmlSchemaValidatorPushElem()");
27076 goto internal_error;
27078 ielem = vctxt->inode;
27079 ielem->localName = xmlTextReaderLocalName(vctxt->reader);
27080 ielem->nsName = xmlTextReaderNamespaceUri(vctxt->reader);
27081 ielem->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES;
27083 * Is the element empty?
27085 ret = xmlTextReaderIsEmptyElement(vctxt->reader);
27087 VERROR_INT("xmlSchemaVReaderWalk",
27088 "calling xmlTextReaderIsEmptyElement()");
27089 goto internal_error;
27092 ielem->flags |= XML_SCHEMA_ELEM_INFO_EMPTY;
27095 * Register attributes.
27097 vctxt->nbAttrInfos = 0;
27098 ret = xmlTextReaderMoveToFirstAttribute(vctxt->reader);
27100 VERROR_INT("xmlSchemaVReaderWalk",
27101 "calling xmlTextReaderMoveToFirstAttribute()");
27102 goto internal_error;
27107 * VAL TODO: How do we know that the reader works on a
27108 * node tree, to be able to pass a node here?
27110 if (xmlSchemaValidatorPushAttribute(vctxt, NULL,
27111 (const xmlChar *) xmlTextReaderLocalName(vctxt->reader),
27112 xmlTextReaderNamespaceUri(vctxt->reader), 1,
27113 xmlTextReaderValue(vctxt->reader), 1) == -1) {
27115 VERROR_INT("xmlSchemaVReaderWalk",
27116 "calling xmlSchemaValidatorPushAttribute()");
27117 goto internal_error;
27119 ret = xmlTextReaderMoveToNextAttribute(vctxt->reader);
27121 VERROR_INT("xmlSchemaVReaderWalk",
27122 "calling xmlTextReaderMoveToFirstAttribute()");
27123 goto internal_error;
27125 } while (ret == 1);
27127 * Back to element position.
27129 ret = xmlTextReaderMoveToElement(vctxt->reader);
27131 VERROR_INT("xmlSchemaVReaderWalk",
27132 "calling xmlTextReaderMoveToElement()");
27133 goto internal_error;
27137 * Validate the element.
27139 ret= xmlSchemaValidateElem(vctxt);
27142 VERROR_INT("xmlSchemaVReaderWalk",
27143 "calling xmlSchemaValidateElem()");
27144 goto internal_error;
27148 if (vctxt->depth == vctxt->skipDepth) {
27151 * Skip all content.
27153 if ((ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY) == 0) {
27154 ret = xmlTextReaderRead(vctxt->reader);
27155 curDepth = xmlTextReaderDepth(vctxt->reader);
27156 while ((ret == 1) && (curDepth != depth)) {
27157 ret = xmlTextReaderRead(vctxt->reader);
27158 curDepth = xmlTextReaderDepth(vctxt->reader);
27162 * VAL TODO: A reader error occurred; what to do here?
27171 * READER VAL TODO: Is an END_ELEM really never called
27172 * if the elem is empty?
27174 if (ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY)
27176 } else if (nodeType == END_ELEM) {
27178 * Process END of element.
27181 ret = xmlSchemaValidatorPopElem(vctxt);
27184 VERROR_INT("xmlSchemaVReaderWalk",
27185 "calling xmlSchemaValidatorPopElem()");
27186 goto internal_error;
27190 if (vctxt->depth >= 0)
27191 ielem = vctxt->inode;
27194 } else if ((nodeType == XML_TEXT_NODE) ||
27195 (nodeType == XML_CDATA_SECTION_NODE) ||
27196 (nodeType == WHTSP) ||
27197 (nodeType == SIGN_WHTSP)) {
27199 * Process character content.
27203 if ((nodeType == WHTSP) || (nodeType == SIGN_WHTSP))
27204 nodeType = XML_TEXT_NODE;
27206 value = xmlTextReaderValue(vctxt->reader);
27207 ret = xmlSchemaVPushText(vctxt, nodeType, BAD_CAST value,
27208 -1, XML_SCHEMA_PUSH_TEXT_CREATED, &consumed);
27212 VERROR_INT("xmlSchemaVReaderWalk",
27213 "calling xmlSchemaVPushText()");
27214 goto internal_error;
27216 } else if ((nodeType == XML_ENTITY_NODE) ||
27217 (nodeType == XML_ENTITY_REF_NODE)) {
27219 * VAL TODO: What to do with entities?
27226 ret = xmlTextReaderRead(vctxt->reader);
27227 } while (ret == 1);
27236 /************************************************************************
27238 * SAX validation handlers *
27240 ************************************************************************/
27243 * Process text content.
27246 xmlSchemaSAXHandleText(void *ctx,
27247 const xmlChar * ch,
27250 xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx;
27252 if (vctxt->depth < 0)
27254 if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth))
27256 if (vctxt->inode->flags & XML_SCHEMA_ELEM_INFO_EMPTY)
27257 vctxt->inode->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY;
27258 if (xmlSchemaVPushText(vctxt, XML_TEXT_NODE, ch, len,
27259 XML_SCHEMA_PUSH_TEXT_VOLATILE, NULL) == -1) {
27260 VERROR_INT("xmlSchemaSAXHandleCDataSection",
27261 "calling xmlSchemaVPushText()");
27263 xmlStopParser(vctxt->parserCtxt);
27268 * Process CDATA content.
27271 xmlSchemaSAXHandleCDataSection(void *ctx,
27272 const xmlChar * ch,
27275 xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx;
27277 if (vctxt->depth < 0)
27279 if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth))
27281 if (vctxt->inode->flags & XML_SCHEMA_ELEM_INFO_EMPTY)
27282 vctxt->inode->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY;
27283 if (xmlSchemaVPushText(vctxt, XML_CDATA_SECTION_NODE, ch, len,
27284 XML_SCHEMA_PUSH_TEXT_VOLATILE, NULL) == -1) {
27285 VERROR_INT("xmlSchemaSAXHandleCDataSection",
27286 "calling xmlSchemaVPushText()");
27288 xmlStopParser(vctxt->parserCtxt);
27293 xmlSchemaSAXHandleReference(void *ctx ATTRIBUTE_UNUSED,
27294 const xmlChar * name ATTRIBUTE_UNUSED)
27296 xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx;
27298 if (vctxt->depth < 0)
27300 if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth))
27302 /* SAX VAL TODO: What to do here? */
27307 xmlSchemaSAXHandleStartElementNs(void *ctx,
27308 const xmlChar * localname,
27309 const xmlChar * prefix ATTRIBUTE_UNUSED,
27310 const xmlChar * URI,
27312 const xmlChar ** namespaces,
27314 int nb_defaulted ATTRIBUTE_UNUSED,
27315 const xmlChar ** attributes)
27317 xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx;
27319 xmlSchemaNodeInfoPtr ielem;
27323 * SAX VAL TODO: What to do with nb_defaulted?
27326 * Skip elements if inside a "skip" wildcard or invalid.
27329 if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth))
27332 * Push the element.
27334 if (xmlSchemaValidatorPushElem(vctxt) == -1) {
27335 VERROR_INT("xmlSchemaSAXHandleStartElementNs",
27336 "calling xmlSchemaValidatorPushElem()");
27337 goto internal_error;
27339 ielem = vctxt->inode;
27341 * TODO: Is this OK?
27343 ielem->nodeLine = xmlSAX2GetLineNumber(vctxt->parserCtxt);
27344 ielem->localName = localname;
27345 ielem->nsName = URI;
27346 ielem->flags |= XML_SCHEMA_ELEM_INFO_EMPTY;
27348 * Register namespaces on the elem info.
27350 if (nb_namespaces != 0) {
27352 * Although the parser builds its own namespace list,
27353 * we have no access to it, so we'll use an own one.
27355 for (i = 0, j = 0; i < nb_namespaces; i++, j += 2) {
27357 * Store prefix and namespace name.
27359 if (ielem->nsBindings == NULL) {
27360 ielem->nsBindings =
27361 (const xmlChar **) xmlMalloc(10 *
27362 sizeof(const xmlChar *));
27363 if (ielem->nsBindings == NULL) {
27364 xmlSchemaVErrMemory(vctxt,
27365 "allocating namespace bindings for SAX validation",
27367 goto internal_error;
27369 ielem->nbNsBindings = 0;
27370 ielem->sizeNsBindings = 5;
27371 } else if (ielem->sizeNsBindings <= ielem->nbNsBindings) {
27372 ielem->sizeNsBindings *= 2;
27373 ielem->nsBindings =
27374 (const xmlChar **) xmlRealloc(
27375 (void *) ielem->nsBindings,
27376 ielem->sizeNsBindings * 2 * sizeof(const xmlChar *));
27377 if (ielem->nsBindings == NULL) {
27378 xmlSchemaVErrMemory(vctxt,
27379 "re-allocating namespace bindings for SAX validation",
27381 goto internal_error;
27385 ielem->nsBindings[ielem->nbNsBindings * 2] = namespaces[j];
27386 if (namespaces[j+1][0] == 0) {
27390 ielem->nsBindings[ielem->nbNsBindings * 2 + 1] = NULL;
27392 ielem->nsBindings[ielem->nbNsBindings * 2 + 1] =
27394 ielem->nbNsBindings++;
27398 * Register attributes.
27399 * SAX VAL TODO: We are not adding namespace declaration
27402 if (nb_attributes != 0) {
27403 int valueLen, k, l;
27406 for (j = 0, i = 0; i < nb_attributes; i++, j += 5) {
27408 * Duplicate the value, changing any & to a literal ampersand.
27410 * libxml2 differs from normal SAX here in that it escapes all ampersands
27411 * as & instead of delivering the raw converted string. Changing the
27412 * behavior at this point would break applications that use this API, so
27413 * we are forced to work around it.
27415 valueLen = attributes[j+4] - attributes[j+3];
27416 value = xmlMallocAtomic(valueLen + 1);
27417 if (value == NULL) {
27418 xmlSchemaVErrMemory(vctxt,
27419 "allocating string for decoded attribute",
27421 goto internal_error;
27423 for (k = 0, l = 0; k < valueLen; l++) {
27424 if (k < valueLen - 4 &&
27425 attributes[j+3][k+0] == '&' &&
27426 attributes[j+3][k+1] == '#' &&
27427 attributes[j+3][k+2] == '3' &&
27428 attributes[j+3][k+3] == '8' &&
27429 attributes[j+3][k+4] == ';') {
27433 value[l] = attributes[j+3][k];
27439 * TODO: Set the node line.
27441 ret = xmlSchemaValidatorPushAttribute(vctxt,
27442 NULL, ielem->nodeLine, attributes[j], attributes[j+2], 0,
27445 VERROR_INT("xmlSchemaSAXHandleStartElementNs",
27446 "calling xmlSchemaValidatorPushAttribute()");
27447 goto internal_error;
27452 * Validate the element.
27454 ret = xmlSchemaValidateElem(vctxt);
27457 VERROR_INT("xmlSchemaSAXHandleStartElementNs",
27458 "calling xmlSchemaValidateElem()");
27459 goto internal_error;
27468 xmlStopParser(vctxt->parserCtxt);
27473 xmlSchemaSAXHandleEndElementNs(void *ctx,
27474 const xmlChar * localname ATTRIBUTE_UNUSED,
27475 const xmlChar * prefix ATTRIBUTE_UNUSED,
27476 const xmlChar * URI ATTRIBUTE_UNUSED)
27478 xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx;
27482 * Skip elements if inside a "skip" wildcard or if invalid.
27484 if (vctxt->skipDepth != -1) {
27485 if (vctxt->depth > vctxt->skipDepth) {
27489 vctxt->skipDepth = -1;
27492 * SAX VAL TODO: Just a temporary check.
27494 if ((!xmlStrEqual(vctxt->inode->localName, localname)) ||
27495 (!xmlStrEqual(vctxt->inode->nsName, URI))) {
27496 VERROR_INT("xmlSchemaSAXHandleEndElementNs",
27497 "elem pop mismatch");
27499 res = xmlSchemaValidatorPopElem(vctxt);
27502 VERROR_INT("xmlSchemaSAXHandleEndElementNs",
27503 "calling xmlSchemaValidatorPopElem()");
27504 goto internal_error;
27512 xmlStopParser(vctxt->parserCtxt);
27516 /************************************************************************
27518 * Validation interfaces *
27520 ************************************************************************/
27523 * xmlSchemaNewValidCtxt:
27524 * @schema: a precompiled XML Schemas
27526 * Create an XML Schemas validation context based on the given schema.
27528 * Returns the validation context or NULL in case of error
27530 xmlSchemaValidCtxtPtr
27531 xmlSchemaNewValidCtxt(xmlSchemaPtr schema)
27533 xmlSchemaValidCtxtPtr ret;
27535 ret = (xmlSchemaValidCtxtPtr) xmlMalloc(sizeof(xmlSchemaValidCtxt));
27537 xmlSchemaVErrMemory(NULL, "allocating validation context", NULL);
27540 memset(ret, 0, sizeof(xmlSchemaValidCtxt));
27541 ret->type = XML_SCHEMA_CTXT_VALIDATOR;
27542 ret->dict = xmlDictCreate();
27543 ret->nodeQNames = xmlSchemaItemListCreate();
27544 ret->schema = schema;
27549 * xmlSchemaValidateSetFilename:
27550 * @vctxt: the schema validation context
27551 * @filename: the file name
27553 * Workaround to provide file error reporting information when this is
27554 * not provided by current APIs
27557 xmlSchemaValidateSetFilename(xmlSchemaValidCtxtPtr vctxt, const char *filename) {
27560 if (vctxt->filename != NULL)
27561 xmlFree(vctxt->filename);
27562 if (filename != NULL)
27563 vctxt->filename = (char *) xmlStrdup((const xmlChar *) filename);
27565 vctxt->filename = NULL;
27569 * xmlSchemaClearValidCtxt:
27570 * @vctxt: the schema validation context
27572 * Free the resources associated to the schema validation context;
27573 * leaves some fields alive intended for reuse of the context.
27576 xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt)
27582 * TODO: Should we clear the flags?
27583 * Might be problematic if one reuses the context
27584 * and assumes that the options remain the same.
27587 vctxt->validationRoot = NULL;
27589 #ifdef LIBXML_READER_ENABLED
27590 vctxt->reader = NULL;
27592 vctxt->hasKeyrefs = 0;
27594 if (vctxt->value != NULL) {
27595 xmlSchemaFreeValue(vctxt->value);
27596 vctxt->value = NULL;
27599 * Augmented IDC information.
27601 if (vctxt->aidcs != NULL) {
27602 xmlSchemaIDCAugPtr cur = vctxt->aidcs, next;
27607 } while (cur != NULL);
27608 vctxt->aidcs = NULL;
27610 if (vctxt->idcMatcherCache != NULL) {
27611 xmlSchemaIDCMatcherPtr matcher = vctxt->idcMatcherCache, tmp;
27615 matcher = matcher->nextCached;
27616 xmlSchemaIDCFreeMatcherList(tmp);
27618 vctxt->idcMatcherCache = NULL;
27622 if (vctxt->idcNodes != NULL) {
27624 xmlSchemaPSVIIDCNodePtr item;
27626 for (i = 0; i < vctxt->nbIdcNodes; i++) {
27627 item = vctxt->idcNodes[i];
27628 xmlFree(item->keys);
27631 xmlFree(vctxt->idcNodes);
27632 vctxt->idcNodes = NULL;
27633 vctxt->nbIdcNodes = 0;
27634 vctxt->sizeIdcNodes = 0;
27637 * Note that we won't delete the XPath state pool here.
27639 if (vctxt->xpathStates != NULL) {
27640 xmlSchemaFreeIDCStateObjList(vctxt->xpathStates);
27641 vctxt->xpathStates = NULL;
27646 if (vctxt->nbAttrInfos != 0) {
27647 xmlSchemaClearAttrInfos(vctxt);
27652 if (vctxt->elemInfos != NULL) {
27654 xmlSchemaNodeInfoPtr ei;
27656 for (i = 0; i < vctxt->sizeElemInfos; i++) {
27657 ei = vctxt->elemInfos[i];
27660 xmlSchemaClearElemInfo(vctxt, ei);
27663 xmlSchemaItemListClear(vctxt->nodeQNames);
27664 /* Recreate the dict. */
27665 xmlDictFree(vctxt->dict);
27667 * TODO: Is is save to recreate it? Do we have a scenario
27668 * where the user provides the dict?
27670 vctxt->dict = xmlDictCreate();
27672 if (vctxt->filename != NULL) {
27673 xmlFree(vctxt->filename);
27674 vctxt->filename = NULL;
27679 * xmlSchemaFreeValidCtxt:
27680 * @ctxt: the schema validation context
27682 * Free the resources associated to the schema validation context
27685 xmlSchemaFreeValidCtxt(xmlSchemaValidCtxtPtr ctxt)
27689 if (ctxt->value != NULL)
27690 xmlSchemaFreeValue(ctxt->value);
27691 if (ctxt->pctxt != NULL)
27692 xmlSchemaFreeParserCtxt(ctxt->pctxt);
27693 if (ctxt->idcNodes != NULL) {
27695 xmlSchemaPSVIIDCNodePtr item;
27697 for (i = 0; i < ctxt->nbIdcNodes; i++) {
27698 item = ctxt->idcNodes[i];
27699 xmlFree(item->keys);
27702 xmlFree(ctxt->idcNodes);
27704 if (ctxt->idcKeys != NULL) {
27706 for (i = 0; i < ctxt->nbIdcKeys; i++)
27707 xmlSchemaIDCFreeKey(ctxt->idcKeys[i]);
27708 xmlFree(ctxt->idcKeys);
27711 if (ctxt->xpathStates != NULL) {
27712 xmlSchemaFreeIDCStateObjList(ctxt->xpathStates);
27713 ctxt->xpathStates = NULL;
27715 if (ctxt->xpathStatePool != NULL) {
27716 xmlSchemaFreeIDCStateObjList(ctxt->xpathStatePool);
27717 ctxt->xpathStatePool = NULL;
27721 * Augmented IDC information.
27723 if (ctxt->aidcs != NULL) {
27724 xmlSchemaIDCAugPtr cur = ctxt->aidcs, next;
27729 } while (cur != NULL);
27731 if (ctxt->attrInfos != NULL) {
27733 xmlSchemaAttrInfoPtr attr;
27735 /* Just a paranoid call to the cleanup. */
27736 if (ctxt->nbAttrInfos != 0)
27737 xmlSchemaClearAttrInfos(ctxt);
27738 for (i = 0; i < ctxt->sizeAttrInfos; i++) {
27739 attr = ctxt->attrInfos[i];
27742 xmlFree(ctxt->attrInfos);
27744 if (ctxt->elemInfos != NULL) {
27746 xmlSchemaNodeInfoPtr ei;
27748 for (i = 0; i < ctxt->sizeElemInfos; i++) {
27749 ei = ctxt->elemInfos[i];
27752 xmlSchemaClearElemInfo(ctxt, ei);
27755 xmlFree(ctxt->elemInfos);
27757 if (ctxt->nodeQNames != NULL)
27758 xmlSchemaItemListFree(ctxt->nodeQNames);
27759 if (ctxt->dict != NULL)
27760 xmlDictFree(ctxt->dict);
27761 if (ctxt->filename != NULL)
27762 xmlFree(ctxt->filename);
27767 * xmlSchemaIsValid:
27768 * @ctxt: the schema validation context
27770 * Check if any error was detected during validation.
27772 * Returns 1 if valid so far, 0 if errors were detected, and -1 in case
27773 * of internal error.
27776 xmlSchemaIsValid(xmlSchemaValidCtxtPtr ctxt)
27780 return(ctxt->err == 0);
27784 * xmlSchemaSetValidErrors:
27785 * @ctxt: a schema validation context
27786 * @err: the error function
27787 * @warn: the warning function
27788 * @ctx: the functions context
27790 * Set the error and warning callback informations
27793 xmlSchemaSetValidErrors(xmlSchemaValidCtxtPtr ctxt,
27794 xmlSchemaValidityErrorFunc err,
27795 xmlSchemaValidityWarningFunc warn, void *ctx)
27800 ctxt->warning = warn;
27801 ctxt->errCtxt = ctx;
27802 if (ctxt->pctxt != NULL)
27803 xmlSchemaSetParserErrors(ctxt->pctxt, err, warn, ctx);
27807 * xmlSchemaSetValidStructuredErrors:
27808 * @ctxt: a schema validation context
27809 * @serror: the structured error function
27810 * @ctx: the functions context
27812 * Set the structured error callback
27815 xmlSchemaSetValidStructuredErrors(xmlSchemaValidCtxtPtr ctxt,
27816 xmlStructuredErrorFunc serror, void *ctx)
27820 ctxt->serror = serror;
27821 ctxt->error = NULL;
27822 ctxt->warning = NULL;
27823 ctxt->errCtxt = ctx;
27824 if (ctxt->pctxt != NULL)
27825 xmlSchemaSetParserStructuredErrors(ctxt->pctxt, serror, ctx);
27829 * xmlSchemaGetValidErrors:
27830 * @ctxt: a XML-Schema validation context
27831 * @err: the error function result
27832 * @warn: the warning function result
27833 * @ctx: the functions context result
27835 * Get the error and warning callback informations
27837 * Returns -1 in case of error and 0 otherwise
27840 xmlSchemaGetValidErrors(xmlSchemaValidCtxtPtr ctxt,
27841 xmlSchemaValidityErrorFunc * err,
27842 xmlSchemaValidityWarningFunc * warn, void **ctx)
27847 *err = ctxt->error;
27849 *warn = ctxt->warning;
27851 *ctx = ctxt->errCtxt;
27857 * xmlSchemaSetValidOptions:
27858 * @ctxt: a schema validation context
27859 * @options: a combination of xmlSchemaValidOption
27861 * Sets the options to be used during the validation.
27863 * Returns 0 in case of success, -1 in case of an
27867 xmlSchemaSetValidOptions(xmlSchemaValidCtxtPtr ctxt,
27876 * WARNING: Change the start value if adding to the
27877 * xmlSchemaValidOption.
27878 * TODO: Is there an other, more easy to maintain,
27881 for (i = 1; i < (int) sizeof(int) * 8; i++) {
27882 if (options & 1<<i)
27885 ctxt->options = options;
27890 * xmlSchemaValidCtxtGetOptions:
27891 * @ctxt: a schema validation context
27893 * Get the validation context options.
27895 * Returns the option combination or -1 on error.
27898 xmlSchemaValidCtxtGetOptions(xmlSchemaValidCtxtPtr ctxt)
27904 return (ctxt->options);
27908 xmlSchemaVDocWalk(xmlSchemaValidCtxtPtr vctxt)
27912 xmlSchemaNodeInfoPtr ielem = NULL;
27913 xmlNodePtr node, valRoot;
27914 const xmlChar *nsName;
27916 /* DOC VAL TODO: Move this to the start function. */
27917 if (vctxt->validationRoot != NULL)
27918 valRoot = vctxt->validationRoot;
27920 valRoot = xmlDocGetRootElement(vctxt->doc);
27921 if (valRoot == NULL) {
27922 /* VAL TODO: Error code? */
27923 VERROR(1, NULL, "The document has no document element");
27927 vctxt->validationRoot = valRoot;
27929 while (node != NULL) {
27930 if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth))
27932 if (node->type == XML_ELEMENT_NODE) {
27935 * Init the node-info.
27938 if (xmlSchemaValidatorPushElem(vctxt) == -1)
27939 goto internal_error;
27940 ielem = vctxt->inode;
27941 ielem->node = node;
27942 ielem->nodeLine = node->line;
27943 ielem->localName = node->name;
27944 if (node->ns != NULL)
27945 ielem->nsName = node->ns->href;
27946 ielem->flags |= XML_SCHEMA_ELEM_INFO_EMPTY;
27948 * Register attributes.
27949 * DOC VAL TODO: We do not register namespace declaration
27952 vctxt->nbAttrInfos = 0;
27953 if (node->properties != NULL) {
27954 attr = node->properties;
27956 if (attr->ns != NULL)
27957 nsName = attr->ns->href;
27960 ret = xmlSchemaValidatorPushAttribute(vctxt,
27963 * Note that we give it the line number of the
27967 attr->name, nsName, 0,
27968 xmlNodeListGetString(attr->doc, attr->children, 1), 1);
27970 VERROR_INT("xmlSchemaDocWalk",
27971 "calling xmlSchemaValidatorPushAttribute()");
27972 goto internal_error;
27978 * Validate the element.
27980 ret = xmlSchemaValidateElem(vctxt);
27983 VERROR_INT("xmlSchemaDocWalk",
27984 "calling xmlSchemaValidateElem()");
27985 goto internal_error;
27988 * Don't stop validation; just skip the content
27993 if ((vctxt->skipDepth != -1) &&
27994 (vctxt->depth >= vctxt->skipDepth))
27996 } else if ((node->type == XML_TEXT_NODE) ||
27997 (node->type == XML_CDATA_SECTION_NODE)) {
27999 * Process character content.
28001 if ((ielem != NULL) && (ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY))
28002 ielem->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY;
28003 ret = xmlSchemaVPushText(vctxt, node->type, node->content,
28004 -1, XML_SCHEMA_PUSH_TEXT_PERSIST, NULL);
28006 VERROR_INT("xmlSchemaVDocWalk",
28007 "calling xmlSchemaVPushText()");
28008 goto internal_error;
28011 * DOC VAL TODO: Should we skip further validation of the
28012 * element content here?
28014 } else if ((node->type == XML_ENTITY_NODE) ||
28015 (node->type == XML_ENTITY_REF_NODE)) {
28017 * DOC VAL TODO: What to do with entities?
28019 VERROR_INT("xmlSchemaVDocWalk",
28020 "there is at least one entity reference in the node-tree "
28021 "currently being validated. Processing of entities with "
28022 "this XML Schema processor is not supported (yet). Please "
28023 "substitute entities before validation.");
28024 goto internal_error;
28028 * DOC VAL TODO: XInclude nodes, etc.
28034 if (node->children != NULL) {
28035 node = node->children;
28039 if (node->type == XML_ELEMENT_NODE) {
28041 * Leaving the scope of an element.
28043 if (node != vctxt->inode->node) {
28044 VERROR_INT("xmlSchemaVDocWalk",
28045 "element position mismatch");
28046 goto internal_error;
28048 ret = xmlSchemaValidatorPopElem(vctxt);
28051 VERROR_INT("xmlSchemaVDocWalk",
28052 "calling xmlSchemaValidatorPopElem()");
28053 goto internal_error;
28056 if (node == valRoot)
28060 if (node->next != NULL)
28063 node = node->parent;
28075 xmlSchemaPreRun(xmlSchemaValidCtxtPtr vctxt) {
28077 * Some initialization.
28080 vctxt->nberrors = 0;
28082 vctxt->skipDepth = -1;
28083 vctxt->xsiAssemble = 0;
28084 vctxt->hasKeyrefs = 0;
28085 #ifdef ENABLE_IDC_NODE_TABLES_TEST
28086 vctxt->createIDCNodeTables = 1;
28088 vctxt->createIDCNodeTables = 0;
28091 * Create a schema + parser if necessary.
28093 if (vctxt->schema == NULL) {
28094 xmlSchemaParserCtxtPtr pctxt;
28096 vctxt->xsiAssemble = 1;
28098 * If not schema was given then we will create a schema
28099 * dynamically using XSI schema locations.
28101 * Create the schema parser context.
28103 if ((vctxt->pctxt == NULL) &&
28104 (xmlSchemaCreatePCtxtOnVCtxt(vctxt) == -1))
28106 pctxt = vctxt->pctxt;
28107 pctxt->xsiAssemble = 1;
28109 * Create the schema.
28111 vctxt->schema = xmlSchemaNewSchema(pctxt);
28112 if (vctxt->schema == NULL)
28115 * Create the schema construction context.
28117 pctxt->constructor = xmlSchemaConstructionCtxtCreate(pctxt->dict);
28118 if (pctxt->constructor == NULL)
28120 pctxt->constructor->mainSchema = vctxt->schema;
28122 * Take ownership of the constructor to be able to free it.
28124 pctxt->ownsConstructor = 1;
28127 * Augment the IDC definitions for the main schema and all imported ones
28128 * NOTE: main schema if the first in the imported list
28130 xmlHashScan(vctxt->schema->schemasImports,(xmlHashScanner)xmlSchemaAugmentImportedIDC, vctxt);
28136 xmlSchemaPostRun(xmlSchemaValidCtxtPtr vctxt) {
28137 if (vctxt->xsiAssemble) {
28138 if (vctxt->schema != NULL) {
28139 xmlSchemaFree(vctxt->schema);
28140 vctxt->schema = NULL;
28143 xmlSchemaClearValidCtxt(vctxt);
28147 xmlSchemaVStart(xmlSchemaValidCtxtPtr vctxt)
28151 if (xmlSchemaPreRun(vctxt) < 0)
28154 if (vctxt->doc != NULL) {
28158 ret = xmlSchemaVDocWalk(vctxt);
28159 #ifdef LIBXML_READER_ENABLED
28160 } else if (vctxt->reader != NULL) {
28162 * XML Reader validation.
28164 #ifdef XML_SCHEMA_READER_ENABLED
28165 ret = xmlSchemaVReaderWalk(vctxt);
28168 } else if ((vctxt->sax != NULL) && (vctxt->parserCtxt != NULL)) {
28172 ret = xmlParseDocument(vctxt->parserCtxt);
28174 VERROR_INT("xmlSchemaVStart",
28175 "no instance to validate");
28179 xmlSchemaPostRun(vctxt);
28186 * xmlSchemaValidateOneElement:
28187 * @ctxt: a schema validation context
28188 * @elem: an element node
28190 * Validate a branch of a tree, starting with the given @elem.
28192 * Returns 0 if the element and its subtree is valid, a positive error
28193 * code number otherwise and -1 in case of an internal or API error.
28196 xmlSchemaValidateOneElement(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem)
28198 if ((ctxt == NULL) || (elem == NULL) || (elem->type != XML_ELEMENT_NODE))
28201 if (ctxt->schema == NULL)
28204 ctxt->doc = elem->doc;
28206 ctxt->validationRoot = elem;
28207 return(xmlSchemaVStart(ctxt));
28211 * xmlSchemaValidateDoc:
28212 * @ctxt: a schema validation context
28213 * @doc: a parsed document tree
28215 * Validate a document tree in memory.
28217 * Returns 0 if the document is schemas valid, a positive error code
28218 * number otherwise and -1 in case of internal or API error.
28221 xmlSchemaValidateDoc(xmlSchemaValidCtxtPtr ctxt, xmlDocPtr doc)
28223 if ((ctxt == NULL) || (doc == NULL))
28227 ctxt->node = xmlDocGetRootElement(doc);
28228 if (ctxt->node == NULL) {
28229 xmlSchemaCustomErr(ACTXT_CAST ctxt,
28230 XML_SCHEMAV_DOCUMENT_ELEMENT_MISSING,
28231 (xmlNodePtr) doc, NULL,
28232 "The document has no document element", NULL, NULL);
28233 return (ctxt->err);
28235 ctxt->validationRoot = ctxt->node;
28236 return (xmlSchemaVStart(ctxt));
28240 /************************************************************************
28242 * Function and data for SAX streaming API *
28244 ************************************************************************/
28245 typedef struct _xmlSchemaSplitSAXData xmlSchemaSplitSAXData;
28246 typedef xmlSchemaSplitSAXData *xmlSchemaSplitSAXDataPtr;
28248 struct _xmlSchemaSplitSAXData {
28249 xmlSAXHandlerPtr user_sax;
28251 xmlSchemaValidCtxtPtr ctxt;
28252 xmlSAXHandlerPtr schemas_sax;
28255 #define XML_SAX_PLUG_MAGIC 0xdc43ba21
28257 struct _xmlSchemaSAXPlug {
28258 unsigned int magic;
28260 /* the original callbacks informations */
28261 xmlSAXHandlerPtr *user_sax_ptr;
28262 xmlSAXHandlerPtr user_sax;
28263 void **user_data_ptr;
28266 /* the block plugged back and validation informations */
28267 xmlSAXHandler schemas_sax;
28268 xmlSchemaValidCtxtPtr ctxt;
28271 /* All those functions just bounces to the user provided SAX handlers */
28273 internalSubsetSplit(void *ctx, const xmlChar *name,
28274 const xmlChar *ExternalID, const xmlChar *SystemID)
28276 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28277 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28278 (ctxt->user_sax->internalSubset != NULL))
28279 ctxt->user_sax->internalSubset(ctxt->user_data, name, ExternalID,
28284 isStandaloneSplit(void *ctx)
28286 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28287 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28288 (ctxt->user_sax->isStandalone != NULL))
28289 return(ctxt->user_sax->isStandalone(ctxt->user_data));
28294 hasInternalSubsetSplit(void *ctx)
28296 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28297 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28298 (ctxt->user_sax->hasInternalSubset != NULL))
28299 return(ctxt->user_sax->hasInternalSubset(ctxt->user_data));
28304 hasExternalSubsetSplit(void *ctx)
28306 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28307 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28308 (ctxt->user_sax->hasExternalSubset != NULL))
28309 return(ctxt->user_sax->hasExternalSubset(ctxt->user_data));
28314 externalSubsetSplit(void *ctx, const xmlChar *name,
28315 const xmlChar *ExternalID, const xmlChar *SystemID)
28317 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28318 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28319 (ctxt->user_sax->externalSubset != NULL))
28320 ctxt->user_sax->externalSubset(ctxt->user_data, name, ExternalID,
28324 static xmlParserInputPtr
28325 resolveEntitySplit(void *ctx, const xmlChar *publicId, const xmlChar *systemId)
28327 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28328 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28329 (ctxt->user_sax->resolveEntity != NULL))
28330 return(ctxt->user_sax->resolveEntity(ctxt->user_data, publicId,
28335 static xmlEntityPtr
28336 getEntitySplit(void *ctx, const xmlChar *name)
28338 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28339 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28340 (ctxt->user_sax->getEntity != NULL))
28341 return(ctxt->user_sax->getEntity(ctxt->user_data, name));
28345 static xmlEntityPtr
28346 getParameterEntitySplit(void *ctx, const xmlChar *name)
28348 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28349 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28350 (ctxt->user_sax->getParameterEntity != NULL))
28351 return(ctxt->user_sax->getParameterEntity(ctxt->user_data, name));
28357 entityDeclSplit(void *ctx, const xmlChar *name, int type,
28358 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
28360 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28361 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28362 (ctxt->user_sax->entityDecl != NULL))
28363 ctxt->user_sax->entityDecl(ctxt->user_data, name, type, publicId,
28364 systemId, content);
28368 attributeDeclSplit(void *ctx, const xmlChar * elem,
28369 const xmlChar * name, int type, int def,
28370 const xmlChar * defaultValue, xmlEnumerationPtr tree)
28372 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28373 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28374 (ctxt->user_sax->attributeDecl != NULL)) {
28375 ctxt->user_sax->attributeDecl(ctxt->user_data, elem, name, type,
28376 def, defaultValue, tree);
28378 xmlFreeEnumeration(tree);
28383 elementDeclSplit(void *ctx, const xmlChar *name, int type,
28384 xmlElementContentPtr content)
28386 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28387 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28388 (ctxt->user_sax->elementDecl != NULL))
28389 ctxt->user_sax->elementDecl(ctxt->user_data, name, type, content);
28393 notationDeclSplit(void *ctx, const xmlChar *name,
28394 const xmlChar *publicId, const xmlChar *systemId)
28396 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28397 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28398 (ctxt->user_sax->notationDecl != NULL))
28399 ctxt->user_sax->notationDecl(ctxt->user_data, name, publicId,
28404 unparsedEntityDeclSplit(void *ctx, const xmlChar *name,
28405 const xmlChar *publicId, const xmlChar *systemId,
28406 const xmlChar *notationName)
28408 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28409 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28410 (ctxt->user_sax->unparsedEntityDecl != NULL))
28411 ctxt->user_sax->unparsedEntityDecl(ctxt->user_data, name, publicId,
28412 systemId, notationName);
28416 setDocumentLocatorSplit(void *ctx, xmlSAXLocatorPtr loc)
28418 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28419 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28420 (ctxt->user_sax->setDocumentLocator != NULL))
28421 ctxt->user_sax->setDocumentLocator(ctxt->user_data, loc);
28425 startDocumentSplit(void *ctx)
28427 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28428 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28429 (ctxt->user_sax->startDocument != NULL))
28430 ctxt->user_sax->startDocument(ctxt->user_data);
28434 endDocumentSplit(void *ctx)
28436 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28437 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28438 (ctxt->user_sax->endDocument != NULL))
28439 ctxt->user_sax->endDocument(ctxt->user_data);
28443 processingInstructionSplit(void *ctx, const xmlChar *target,
28444 const xmlChar *data)
28446 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28447 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28448 (ctxt->user_sax->processingInstruction != NULL))
28449 ctxt->user_sax->processingInstruction(ctxt->user_data, target, data);
28453 commentSplit(void *ctx, const xmlChar *value)
28455 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28456 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28457 (ctxt->user_sax->comment != NULL))
28458 ctxt->user_sax->comment(ctxt->user_data, value);
28462 * Varargs error callbacks to the user application, harder ...
28465 static void XMLCDECL
28466 warningSplit(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) {
28467 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28468 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28469 (ctxt->user_sax->warning != NULL)) {
28473 static void XMLCDECL
28474 errorSplit(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) {
28475 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28476 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28477 (ctxt->user_sax->error != NULL)) {
28481 static void XMLCDECL
28482 fatalErrorSplit(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) {
28483 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28484 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28485 (ctxt->user_sax->fatalError != NULL)) {
28491 * Those are function where both the user handler and the schemas handler
28492 * need to be called.
28495 charactersSplit(void *ctx, const xmlChar *ch, int len)
28497 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28500 if ((ctxt->user_sax != NULL) && (ctxt->user_sax->characters != NULL))
28501 ctxt->user_sax->characters(ctxt->user_data, ch, len);
28502 if (ctxt->ctxt != NULL)
28503 xmlSchemaSAXHandleText(ctxt->ctxt, ch, len);
28507 ignorableWhitespaceSplit(void *ctx, const xmlChar *ch, int len)
28509 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28512 if ((ctxt->user_sax != NULL) &&
28513 (ctxt->user_sax->ignorableWhitespace != NULL))
28514 ctxt->user_sax->ignorableWhitespace(ctxt->user_data, ch, len);
28515 if (ctxt->ctxt != NULL)
28516 xmlSchemaSAXHandleText(ctxt->ctxt, ch, len);
28520 cdataBlockSplit(void *ctx, const xmlChar *value, int len)
28522 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28525 if ((ctxt->user_sax != NULL) &&
28526 (ctxt->user_sax->cdataBlock != NULL))
28527 ctxt->user_sax->cdataBlock(ctxt->user_data, value, len);
28528 if (ctxt->ctxt != NULL)
28529 xmlSchemaSAXHandleCDataSection(ctxt->ctxt, value, len);
28533 referenceSplit(void *ctx, const xmlChar *name)
28535 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28538 if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
28539 (ctxt->user_sax->reference != NULL))
28540 ctxt->user_sax->reference(ctxt->user_data, name);
28541 if (ctxt->ctxt != NULL)
28542 xmlSchemaSAXHandleReference(ctxt->user_data, name);
28546 startElementNsSplit(void *ctx, const xmlChar * localname,
28547 const xmlChar * prefix, const xmlChar * URI,
28548 int nb_namespaces, const xmlChar ** namespaces,
28549 int nb_attributes, int nb_defaulted,
28550 const xmlChar ** attributes) {
28551 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28554 if ((ctxt->user_sax != NULL) &&
28555 (ctxt->user_sax->startElementNs != NULL))
28556 ctxt->user_sax->startElementNs(ctxt->user_data, localname, prefix,
28557 URI, nb_namespaces, namespaces,
28558 nb_attributes, nb_defaulted,
28560 if (ctxt->ctxt != NULL)
28561 xmlSchemaSAXHandleStartElementNs(ctxt->ctxt, localname, prefix,
28562 URI, nb_namespaces, namespaces,
28563 nb_attributes, nb_defaulted,
28568 endElementNsSplit(void *ctx, const xmlChar * localname,
28569 const xmlChar * prefix, const xmlChar * URI) {
28570 xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
28573 if ((ctxt->user_sax != NULL) &&
28574 (ctxt->user_sax->endElementNs != NULL))
28575 ctxt->user_sax->endElementNs(ctxt->user_data, localname, prefix, URI);
28576 if (ctxt->ctxt != NULL)
28577 xmlSchemaSAXHandleEndElementNs(ctxt->ctxt, localname, prefix, URI);
28581 * xmlSchemaSAXPlug:
28582 * @ctxt: a schema validation context
28583 * @sax: a pointer to the original xmlSAXHandlerPtr
28584 * @user_data: a pointer to the original SAX user data pointer
28586 * Plug a SAX based validation layer in a SAX parsing event flow.
28587 * The original @saxptr and @dataptr data are replaced by new pointers
28588 * but the calls to the original will be maintained.
28590 * Returns a pointer to a data structure needed to unplug the validation layer
28591 * or NULL in case of errors.
28593 xmlSchemaSAXPlugPtr
28594 xmlSchemaSAXPlug(xmlSchemaValidCtxtPtr ctxt,
28595 xmlSAXHandlerPtr *sax, void **user_data)
28597 xmlSchemaSAXPlugPtr ret;
28598 xmlSAXHandlerPtr old_sax;
28600 if ((ctxt == NULL) || (sax == NULL) || (user_data == NULL))
28604 * We only allow to plug into SAX2 event streams
28607 if ((old_sax != NULL) && (old_sax->initialized != XML_SAX2_MAGIC))
28609 if ((old_sax != NULL) &&
28610 (old_sax->startElementNs == NULL) && (old_sax->endElementNs == NULL) &&
28611 ((old_sax->startElement != NULL) || (old_sax->endElement != NULL)))
28615 * everything seems right allocate the local data needed for that layer
28617 ret = (xmlSchemaSAXPlugPtr) xmlMalloc(sizeof(xmlSchemaSAXPlugStruct));
28621 memset(ret, 0, sizeof(xmlSchemaSAXPlugStruct));
28622 ret->magic = XML_SAX_PLUG_MAGIC;
28623 ret->schemas_sax.initialized = XML_SAX2_MAGIC;
28625 ret->user_sax_ptr = sax;
28626 ret->user_sax = old_sax;
28627 if (old_sax == NULL) {
28629 * go direct, no need for the split block and functions.
28631 ret->schemas_sax.startElementNs = xmlSchemaSAXHandleStartElementNs;
28632 ret->schemas_sax.endElementNs = xmlSchemaSAXHandleEndElementNs;
28634 * Note that we use the same text-function for both, to prevent
28635 * the parser from testing for ignorable whitespace.
28637 ret->schemas_sax.ignorableWhitespace = xmlSchemaSAXHandleText;
28638 ret->schemas_sax.characters = xmlSchemaSAXHandleText;
28640 ret->schemas_sax.cdataBlock = xmlSchemaSAXHandleCDataSection;
28641 ret->schemas_sax.reference = xmlSchemaSAXHandleReference;
28643 ret->user_data = ctxt;
28647 * for each callback unused by Schemas initialize it to the Split
28648 * routine only if non NULL in the user block, this can speed up
28649 * things at the SAX level.
28651 if (old_sax->internalSubset != NULL)
28652 ret->schemas_sax.internalSubset = internalSubsetSplit;
28653 if (old_sax->isStandalone != NULL)
28654 ret->schemas_sax.isStandalone = isStandaloneSplit;
28655 if (old_sax->hasInternalSubset != NULL)
28656 ret->schemas_sax.hasInternalSubset = hasInternalSubsetSplit;
28657 if (old_sax->hasExternalSubset != NULL)
28658 ret->schemas_sax.hasExternalSubset = hasExternalSubsetSplit;
28659 if (old_sax->resolveEntity != NULL)
28660 ret->schemas_sax.resolveEntity = resolveEntitySplit;
28661 if (old_sax->getEntity != NULL)
28662 ret->schemas_sax.getEntity = getEntitySplit;
28663 if (old_sax->entityDecl != NULL)
28664 ret->schemas_sax.entityDecl = entityDeclSplit;
28665 if (old_sax->notationDecl != NULL)
28666 ret->schemas_sax.notationDecl = notationDeclSplit;
28667 if (old_sax->attributeDecl != NULL)
28668 ret->schemas_sax.attributeDecl = attributeDeclSplit;
28669 if (old_sax->elementDecl != NULL)
28670 ret->schemas_sax.elementDecl = elementDeclSplit;
28671 if (old_sax->unparsedEntityDecl != NULL)
28672 ret->schemas_sax.unparsedEntityDecl = unparsedEntityDeclSplit;
28673 if (old_sax->setDocumentLocator != NULL)
28674 ret->schemas_sax.setDocumentLocator = setDocumentLocatorSplit;
28675 if (old_sax->startDocument != NULL)
28676 ret->schemas_sax.startDocument = startDocumentSplit;
28677 if (old_sax->endDocument != NULL)
28678 ret->schemas_sax.endDocument = endDocumentSplit;
28679 if (old_sax->processingInstruction != NULL)
28680 ret->schemas_sax.processingInstruction = processingInstructionSplit;
28681 if (old_sax->comment != NULL)
28682 ret->schemas_sax.comment = commentSplit;
28683 if (old_sax->warning != NULL)
28684 ret->schemas_sax.warning = warningSplit;
28685 if (old_sax->error != NULL)
28686 ret->schemas_sax.error = errorSplit;
28687 if (old_sax->fatalError != NULL)
28688 ret->schemas_sax.fatalError = fatalErrorSplit;
28689 if (old_sax->getParameterEntity != NULL)
28690 ret->schemas_sax.getParameterEntity = getParameterEntitySplit;
28691 if (old_sax->externalSubset != NULL)
28692 ret->schemas_sax.externalSubset = externalSubsetSplit;
28695 * the 6 schemas callback have to go to the splitter functions
28696 * Note that we use the same text-function for ignorableWhitespace
28697 * if possible, to prevent the parser from testing for ignorable
28700 ret->schemas_sax.characters = charactersSplit;
28701 if ((old_sax->ignorableWhitespace != NULL) &&
28702 (old_sax->ignorableWhitespace != old_sax->characters))
28703 ret->schemas_sax.ignorableWhitespace = ignorableWhitespaceSplit;
28705 ret->schemas_sax.ignorableWhitespace = charactersSplit;
28706 ret->schemas_sax.cdataBlock = cdataBlockSplit;
28707 ret->schemas_sax.reference = referenceSplit;
28708 ret->schemas_sax.startElementNs = startElementNsSplit;
28709 ret->schemas_sax.endElementNs = endElementNsSplit;
28711 ret->user_data_ptr = user_data;
28712 ret->user_data = *user_data;
28717 * plug the pointers back.
28719 *sax = &(ret->schemas_sax);
28721 ctxt->flags |= XML_SCHEMA_VALID_CTXT_FLAG_STREAM;
28722 xmlSchemaPreRun(ctxt);
28727 * xmlSchemaSAXUnplug:
28728 * @plug: a data structure returned by xmlSchemaSAXPlug
28730 * Unplug a SAX based validation layer in a SAX parsing event flow.
28731 * The original pointers used in the call are restored.
28733 * Returns 0 in case of success and -1 in case of failure.
28736 xmlSchemaSAXUnplug(xmlSchemaSAXPlugPtr plug)
28738 xmlSAXHandlerPtr *sax;
28741 if ((plug == NULL) || (plug->magic != XML_SAX_PLUG_MAGIC))
28745 xmlSchemaPostRun(plug->ctxt);
28746 /* restore the data */
28747 sax = plug->user_sax_ptr;
28748 *sax = plug->user_sax;
28749 if (plug->user_sax != NULL) {
28750 user_data = plug->user_data_ptr;
28751 *user_data = plug->user_data;
28754 /* free and return */
28760 * xmlSchemaValidateSetLocator:
28761 * @vctxt: a schema validation context
28762 * @f: the locator function pointer
28763 * @ctxt: the locator context
28765 * Allows to set a locator function to the validation context,
28766 * which will be used to provide file and line information since
28767 * those are not provided as part of the SAX validation flow
28768 * Setting @f to NULL disable the locator.
28772 xmlSchemaValidateSetLocator(xmlSchemaValidCtxtPtr vctxt,
28773 xmlSchemaValidityLocatorFunc f,
28776 if (vctxt == NULL) return;
28777 vctxt->locFunc = f;
28778 vctxt->locCtxt = ctxt;
28782 * xmlSchemaValidateStreamLocator:
28783 * @ctx: the xmlTextReaderPtr used
28784 * @file: returned file information
28785 * @line: returned line information
28787 * Internal locator function for the readers
28789 * Returns 0 in case the Schema validation could be (des)activated and
28790 * -1 in case of error.
28793 xmlSchemaValidateStreamLocator(void *ctx, const char **file,
28794 unsigned long *line) {
28795 xmlParserCtxtPtr ctxt;
28797 if ((ctx == NULL) || ((file == NULL) && (line == NULL)))
28805 ctxt = (xmlParserCtxtPtr) ctx;
28806 if (ctxt->input != NULL) {
28808 *file = ctxt->input->filename;
28810 *line = ctxt->input->line;
28817 * xmlSchemaValidateStream:
28818 * @ctxt: a schema validation context
28819 * @input: the input to use for reading the data
28820 * @enc: an optional encoding information
28821 * @sax: a SAX handler for the resulting events
28822 * @user_data: the context to provide to the SAX handler.
28824 * Validate an input based on a flow of SAX event from the parser
28825 * and forward the events to the @sax handler with the provided @user_data
28826 * the user provided @sax handler must be a SAX2 one.
28828 * Returns 0 if the document is schemas valid, a positive error code
28829 * number otherwise and -1 in case of internal or API error.
28832 xmlSchemaValidateStream(xmlSchemaValidCtxtPtr ctxt,
28833 xmlParserInputBufferPtr input, xmlCharEncoding enc,
28834 xmlSAXHandlerPtr sax, void *user_data)
28836 xmlSchemaSAXPlugPtr plug = NULL;
28837 xmlSAXHandlerPtr old_sax = NULL;
28838 xmlParserCtxtPtr pctxt = NULL;
28839 xmlParserInputPtr inputStream = NULL;
28842 if ((ctxt == NULL) || (input == NULL))
28846 * prepare the parser
28848 pctxt = xmlNewParserCtxt();
28851 old_sax = pctxt->sax;
28853 pctxt->userData = user_data;
28856 xmlCtxtUseOptions(pctxt, options);
28858 pctxt->linenumbers = 1;
28859 xmlSchemaValidateSetLocator(ctxt, xmlSchemaValidateStreamLocator, pctxt);
28861 inputStream = xmlNewIOInputStream(pctxt, input, enc);;
28862 if (inputStream == NULL) {
28866 inputPush(pctxt, inputStream);
28867 ctxt->parserCtxt = pctxt;
28868 ctxt->input = input;
28871 * Plug the validation and launch the parsing
28873 plug = xmlSchemaSAXPlug(ctxt, &(pctxt->sax), &(pctxt->userData));
28874 if (plug == NULL) {
28878 ctxt->input = input;
28880 ctxt->sax = pctxt->sax;
28881 ctxt->flags |= XML_SCHEMA_VALID_CTXT_FLAG_STREAM;
28882 ret = xmlSchemaVStart(ctxt);
28884 if ((ret == 0) && (! ctxt->parserCtxt->wellFormed)) {
28885 ret = ctxt->parserCtxt->errNo;
28891 ctxt->parserCtxt = NULL;
28893 ctxt->input = NULL;
28894 if (plug != NULL) {
28895 xmlSchemaSAXUnplug(plug);
28898 if (pctxt != NULL) {
28899 pctxt->sax = old_sax;
28900 xmlFreeParserCtxt(pctxt);
28906 * xmlSchemaValidateFile:
28907 * @ctxt: a schema validation context
28908 * @filename: the URI of the instance
28909 * @options: a future set of options, currently unused
28911 * Do a schemas validation of the given resource, it will use the
28912 * SAX streamable validation internally.
28914 * Returns 0 if the document is valid, a positive error code
28915 * number otherwise and -1 in case of an internal or API error.
28918 xmlSchemaValidateFile(xmlSchemaValidCtxtPtr ctxt,
28919 const char * filename,
28920 int options ATTRIBUTE_UNUSED)
28923 xmlParserInputBufferPtr input;
28925 if ((ctxt == NULL) || (filename == NULL))
28928 input = xmlParserInputBufferCreateFilename(filename,
28929 XML_CHAR_ENCODING_NONE);
28932 ret = xmlSchemaValidateStream(ctxt, input, XML_CHAR_ENCODING_NONE,
28938 * xmlSchemaValidCtxtGetParserCtxt:
28939 * @ctxt: a schema validation context
28941 * allow access to the parser context of the schema validation context
28943 * Returns the parser context of the schema validation context or NULL
28944 * in case of error.
28947 xmlSchemaValidCtxtGetParserCtxt(xmlSchemaValidCtxtPtr ctxt)
28951 return (ctxt->parserCtxt);
28954 #define bottom_xmlschemas
28955 #include "elfgcchack.h"
28956 #endif /* LIBXML_SCHEMAS_ENABLED */