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
);
3569 xmlSchemaBucketFreeEntry(void *bucket
, const xmlChar
*name ATTRIBUTE_UNUSED
)
3571 xmlSchemaBucketFree((xmlSchemaBucketPtr
) bucket
);
3574 static xmlSchemaBucketPtr
3575 xmlSchemaBucketCreate(xmlSchemaParserCtxtPtr pctxt
,
3576 int type
, const xmlChar
*targetNamespace
)
3578 xmlSchemaBucketPtr ret
;
3580 xmlSchemaPtr mainSchema
;
3582 if (WXS_CONSTRUCTOR(pctxt
)->mainSchema
== NULL
) {
3583 PERROR_INT("xmlSchemaBucketCreate",
3584 "no main schema on constructor");
3587 mainSchema
= WXS_CONSTRUCTOR(pctxt
)->mainSchema
;
3588 /* Create the schema bucket. */
3589 if (WXS_IS_BUCKET_INCREDEF(type
))
3590 size
= sizeof(xmlSchemaInclude
);
3592 size
= sizeof(xmlSchemaImport
);
3593 ret
= (xmlSchemaBucketPtr
) xmlMalloc(size
);
3595 xmlSchemaPErrMemory(NULL
, "allocating schema bucket", NULL
);
3598 memset(ret
, 0, size
);
3599 ret
->targetNamespace
= targetNamespace
;
3601 ret
->globals
= xmlSchemaItemListCreate();
3602 if (ret
->globals
== NULL
) {
3606 ret
->locals
= xmlSchemaItemListCreate();
3607 if (ret
->locals
== NULL
) {
3612 * The following will assure that only the first bucket is marked as
3613 * XML_SCHEMA_SCHEMA_MAIN and it points to the *main* schema.
3614 * For each following import buckets an xmlSchema will be created.
3615 * An xmlSchema will be created for every distinct targetNamespace.
3616 * We assign the targetNamespace to the schemata here.
3618 if (! WXS_HAS_BUCKETS(pctxt
)) {
3619 if (WXS_IS_BUCKET_INCREDEF(type
)) {
3620 PERROR_INT("xmlSchemaBucketCreate",
3621 "first bucket but it's an include or redefine");
3622 xmlSchemaBucketFree(ret
);
3625 /* Force the type to be XML_SCHEMA_SCHEMA_MAIN. */
3626 ret
->type
= XML_SCHEMA_SCHEMA_MAIN
;
3627 /* Point to the *main* schema. */
3628 WXS_CONSTRUCTOR(pctxt
)->mainBucket
= ret
;
3629 WXS_IMPBUCKET(ret
)->schema
= mainSchema
;
3631 * Ensure that the main schema gets a targetNamespace.
3633 mainSchema
->targetNamespace
= targetNamespace
;
3635 if (type
== XML_SCHEMA_SCHEMA_MAIN
) {
3636 PERROR_INT("xmlSchemaBucketCreate",
3637 "main bucket but it's not the first one");
3638 xmlSchemaBucketFree(ret
);
3640 } else if (type
== XML_SCHEMA_SCHEMA_IMPORT
) {
3642 * Create a schema for imports and assign the
3645 WXS_IMPBUCKET(ret
)->schema
= xmlSchemaNewSchema(pctxt
);
3646 if (WXS_IMPBUCKET(ret
)->schema
== NULL
) {
3647 xmlSchemaBucketFree(ret
);
3650 WXS_IMPBUCKET(ret
)->schema
->targetNamespace
= targetNamespace
;
3653 if (WXS_IS_BUCKET_IMPMAIN(type
)) {
3656 * Imports go into the "schemasImports" slot of the main *schema*.
3657 * Note that we create an import entry for the main schema as well; i.e.,
3658 * even if there's only one schema, we'll get an import.
3660 if (mainSchema
->schemasImports
== NULL
) {
3661 mainSchema
->schemasImports
= xmlHashCreateDict(5,
3662 WXS_CONSTRUCTOR(pctxt
)->dict
);
3663 if (mainSchema
->schemasImports
== NULL
) {
3664 xmlSchemaBucketFree(ret
);
3668 if (targetNamespace
== NULL
)
3669 res
= xmlHashAddEntry(mainSchema
->schemasImports
,
3670 XML_SCHEMAS_NO_NAMESPACE
, ret
);
3672 res
= xmlHashAddEntry(mainSchema
->schemasImports
,
3673 targetNamespace
, ret
);
3675 PERROR_INT("xmlSchemaBucketCreate",
3676 "failed to add the schema bucket to the hash");
3677 xmlSchemaBucketFree(ret
);
3681 /* Set the @ownerImport of an include bucket. */
3682 if (WXS_IS_BUCKET_IMPMAIN(WXS_CONSTRUCTOR(pctxt
)->bucket
->type
))
3683 WXS_INCBUCKET(ret
)->ownerImport
=
3684 WXS_IMPBUCKET(WXS_CONSTRUCTOR(pctxt
)->bucket
);
3686 WXS_INCBUCKET(ret
)->ownerImport
=
3687 WXS_INCBUCKET(WXS_CONSTRUCTOR(pctxt
)->bucket
)->ownerImport
;
3689 /* Includes got into the "includes" slot of the *main* schema. */
3690 if (mainSchema
->includes
== NULL
) {
3691 mainSchema
->includes
= xmlSchemaItemListCreate();
3692 if (mainSchema
->includes
== NULL
) {
3693 xmlSchemaBucketFree(ret
);
3697 xmlSchemaItemListAdd(mainSchema
->includes
, ret
);
3700 * Add to list of all buckets; this is used for lookup
3701 * during schema construction time only.
3703 if (xmlSchemaItemListAdd(WXS_CONSTRUCTOR(pctxt
)->buckets
, ret
) == -1)
3709 xmlSchemaAddItemSize(xmlSchemaItemListPtr
*list
, int initialSize
, void *item
)
3711 if (*list
== NULL
) {
3712 *list
= xmlSchemaItemListCreate();
3716 xmlSchemaItemListAddSize(*list
, initialSize
, item
);
3721 * xmlSchemaFreeAnnot:
3722 * @annot: a schema type structure
3724 * Deallocate a annotation structure
3727 xmlSchemaFreeAnnot(xmlSchemaAnnotPtr annot
)
3731 if (annot
->next
== NULL
) {
3734 xmlSchemaAnnotPtr prev
;
3738 annot
= annot
->next
;
3740 } while (annot
!= NULL
);
3745 * xmlSchemaFreeNotation:
3746 * @schema: a schema notation structure
3748 * Deallocate a Schema Notation structure.
3751 xmlSchemaFreeNotation(xmlSchemaNotationPtr nota
)
3759 * xmlSchemaFreeAttribute:
3760 * @attr: an attribute declaration
3762 * Deallocates an attribute declaration structure.
3765 xmlSchemaFreeAttribute(xmlSchemaAttributePtr attr
)
3769 if (attr
->annot
!= NULL
)
3770 xmlSchemaFreeAnnot(attr
->annot
);
3771 if (attr
->defVal
!= NULL
)
3772 xmlSchemaFreeValue(attr
->defVal
);
3777 * xmlSchemaFreeAttributeUse:
3778 * @use: an attribute use
3780 * Deallocates an attribute use structure.
3783 xmlSchemaFreeAttributeUse(xmlSchemaAttributeUsePtr use
)
3787 if (use
->annot
!= NULL
)
3788 xmlSchemaFreeAnnot(use
->annot
);
3789 if (use
->defVal
!= NULL
)
3790 xmlSchemaFreeValue(use
->defVal
);
3795 * xmlSchemaFreeAttributeUseProhib:
3796 * @prohib: an attribute use prohibition
3798 * Deallocates an attribute use structure.
3801 xmlSchemaFreeAttributeUseProhib(xmlSchemaAttributeUseProhibPtr prohib
)
3809 * xmlSchemaFreeWildcardNsSet:
3810 * set: a schema wildcard namespace
3812 * Deallocates a list of wildcard constraint structures.
3815 xmlSchemaFreeWildcardNsSet(xmlSchemaWildcardNsPtr set
)
3817 xmlSchemaWildcardNsPtr next
;
3819 while (set
!= NULL
) {
3827 * xmlSchemaFreeWildcard:
3828 * @wildcard: a wildcard structure
3830 * Deallocates a wildcard structure.
3833 xmlSchemaFreeWildcard(xmlSchemaWildcardPtr wildcard
)
3835 if (wildcard
== NULL
)
3837 if (wildcard
->annot
!= NULL
)
3838 xmlSchemaFreeAnnot(wildcard
->annot
);
3839 if (wildcard
->nsSet
!= NULL
)
3840 xmlSchemaFreeWildcardNsSet(wildcard
->nsSet
);
3841 if (wildcard
->negNsSet
!= NULL
)
3842 xmlFree(wildcard
->negNsSet
);
3847 * xmlSchemaFreeAttributeGroup:
3848 * @schema: a schema attribute group structure
3850 * Deallocate a Schema Attribute Group structure.
3853 xmlSchemaFreeAttributeGroup(xmlSchemaAttributeGroupPtr attrGr
)
3857 if (attrGr
->annot
!= NULL
)
3858 xmlSchemaFreeAnnot(attrGr
->annot
);
3859 if (attrGr
->attrUses
!= NULL
)
3860 xmlSchemaItemListFree(WXS_LIST_CAST attrGr
->attrUses
);
3865 * xmlSchemaFreeQNameRef:
3866 * @item: a QName reference structure
3868 * Deallocatea a QName reference structure.
3871 xmlSchemaFreeQNameRef(xmlSchemaQNameRefPtr item
)
3877 * xmlSchemaFreeTypeLinkList:
3878 * @alink: a type link
3880 * Deallocate a list of types.
3883 xmlSchemaFreeTypeLinkList(xmlSchemaTypeLinkPtr link
)
3885 xmlSchemaTypeLinkPtr next
;
3887 while (link
!= NULL
) {
3895 xmlSchemaFreeIDCStateObjList(xmlSchemaIDCStateObjPtr sto
)
3897 xmlSchemaIDCStateObjPtr next
;
3898 while (sto
!= NULL
) {
3900 if (sto
->history
!= NULL
)
3901 xmlFree(sto
->history
);
3902 if (sto
->xpathCtxt
!= NULL
)
3903 xmlFreeStreamCtxt((xmlStreamCtxtPtr
) sto
->xpathCtxt
);
3911 * @idc: a identity-constraint definition
3913 * Deallocates an identity-constraint definition.
3916 xmlSchemaFreeIDC(xmlSchemaIDCPtr idcDef
)
3918 xmlSchemaIDCSelectPtr cur
, prev
;
3922 if (idcDef
->annot
!= NULL
)
3923 xmlSchemaFreeAnnot(idcDef
->annot
);
3925 if (idcDef
->selector
!= NULL
) {
3926 if (idcDef
->selector
->xpathComp
!= NULL
)
3927 xmlFreePattern((xmlPatternPtr
) idcDef
->selector
->xpathComp
);
3928 xmlFree(idcDef
->selector
);
3931 if (idcDef
->fields
!= NULL
) {
3932 cur
= idcDef
->fields
;
3936 if (prev
->xpathComp
!= NULL
)
3937 xmlFreePattern((xmlPatternPtr
) prev
->xpathComp
);
3939 } while (cur
!= NULL
);
3945 * xmlSchemaFreeElement:
3946 * @schema: a schema element structure
3948 * Deallocate a Schema Element structure.
3951 xmlSchemaFreeElement(xmlSchemaElementPtr elem
)
3955 if (elem
->annot
!= NULL
)
3956 xmlSchemaFreeAnnot(elem
->annot
);
3957 if (elem
->contModel
!= NULL
)
3958 xmlRegFreeRegexp(elem
->contModel
);
3959 if (elem
->defVal
!= NULL
)
3960 xmlSchemaFreeValue(elem
->defVal
);
3965 * xmlSchemaFreeFacet:
3966 * @facet: a schema facet structure
3968 * Deallocate a Schema Facet structure.
3971 xmlSchemaFreeFacet(xmlSchemaFacetPtr facet
)
3975 if (facet
->val
!= NULL
)
3976 xmlSchemaFreeValue(facet
->val
);
3977 if (facet
->regexp
!= NULL
)
3978 xmlRegFreeRegexp(facet
->regexp
);
3979 if (facet
->annot
!= NULL
)
3980 xmlSchemaFreeAnnot(facet
->annot
);
3985 * xmlSchemaFreeType:
3986 * @type: a schema type structure
3988 * Deallocate a Schema Type structure.
3991 xmlSchemaFreeType(xmlSchemaTypePtr type
)
3995 if (type
->annot
!= NULL
)
3996 xmlSchemaFreeAnnot(type
->annot
);
3997 if (type
->facets
!= NULL
) {
3998 xmlSchemaFacetPtr facet
, next
;
4000 facet
= type
->facets
;
4001 while (facet
!= NULL
) {
4003 xmlSchemaFreeFacet(facet
);
4007 if (type
->attrUses
!= NULL
)
4008 xmlSchemaItemListFree((xmlSchemaItemListPtr
) type
->attrUses
);
4009 if (type
->memberTypes
!= NULL
)
4010 xmlSchemaFreeTypeLinkList(type
->memberTypes
);
4011 if (type
->facetSet
!= NULL
) {
4012 xmlSchemaFacetLinkPtr next
, link
;
4014 link
= type
->facetSet
;
4019 } while (link
!= NULL
);
4021 if (type
->contModel
!= NULL
)
4022 xmlRegFreeRegexp(type
->contModel
);
4027 * xmlSchemaFreeModelGroupDef:
4028 * @item: a schema model group definition
4030 * Deallocates a schema model group definition.
4033 xmlSchemaFreeModelGroupDef(xmlSchemaModelGroupDefPtr item
)
4035 if (item
->annot
!= NULL
)
4036 xmlSchemaFreeAnnot(item
->annot
);
4041 * xmlSchemaFreeModelGroup:
4042 * @item: a schema model group
4044 * Deallocates a schema model group structure.
4047 xmlSchemaFreeModelGroup(xmlSchemaModelGroupPtr item
)
4049 if (item
->annot
!= NULL
)
4050 xmlSchemaFreeAnnot(item
->annot
);
4055 xmlSchemaComponentListFree(xmlSchemaItemListPtr list
)
4057 if ((list
== NULL
) || (list
->nbItems
== 0))
4060 xmlSchemaTreeItemPtr item
;
4061 xmlSchemaTreeItemPtr
*items
= (xmlSchemaTreeItemPtr
*) list
->items
;
4064 for (i
= 0; i
< list
->nbItems
; i
++) {
4068 switch (item
->type
) {
4069 case XML_SCHEMA_TYPE_SIMPLE
:
4070 case XML_SCHEMA_TYPE_COMPLEX
:
4071 xmlSchemaFreeType((xmlSchemaTypePtr
) item
);
4073 case XML_SCHEMA_TYPE_ATTRIBUTE
:
4074 xmlSchemaFreeAttribute((xmlSchemaAttributePtr
) item
);
4076 case XML_SCHEMA_TYPE_ATTRIBUTE_USE
:
4077 xmlSchemaFreeAttributeUse((xmlSchemaAttributeUsePtr
) item
);
4079 case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB
:
4080 xmlSchemaFreeAttributeUseProhib(
4081 (xmlSchemaAttributeUseProhibPtr
) item
);
4083 case XML_SCHEMA_TYPE_ELEMENT
:
4084 xmlSchemaFreeElement((xmlSchemaElementPtr
) item
);
4086 case XML_SCHEMA_TYPE_PARTICLE
:
4087 if (item
->annot
!= NULL
)
4088 xmlSchemaFreeAnnot(item
->annot
);
4091 case XML_SCHEMA_TYPE_SEQUENCE
:
4092 case XML_SCHEMA_TYPE_CHOICE
:
4093 case XML_SCHEMA_TYPE_ALL
:
4094 xmlSchemaFreeModelGroup((xmlSchemaModelGroupPtr
) item
);
4096 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP
:
4097 xmlSchemaFreeAttributeGroup(
4098 (xmlSchemaAttributeGroupPtr
) item
);
4100 case XML_SCHEMA_TYPE_GROUP
:
4101 xmlSchemaFreeModelGroupDef(
4102 (xmlSchemaModelGroupDefPtr
) item
);
4104 case XML_SCHEMA_TYPE_ANY
:
4105 case XML_SCHEMA_TYPE_ANY_ATTRIBUTE
:
4106 xmlSchemaFreeWildcard((xmlSchemaWildcardPtr
) item
);
4108 case XML_SCHEMA_TYPE_IDC_KEY
:
4109 case XML_SCHEMA_TYPE_IDC_UNIQUE
:
4110 case XML_SCHEMA_TYPE_IDC_KEYREF
:
4111 xmlSchemaFreeIDC((xmlSchemaIDCPtr
) item
);
4113 case XML_SCHEMA_TYPE_NOTATION
:
4114 xmlSchemaFreeNotation((xmlSchemaNotationPtr
) item
);
4116 case XML_SCHEMA_EXTRA_QNAMEREF
:
4117 xmlSchemaFreeQNameRef((xmlSchemaQNameRefPtr
) item
);
4120 /* TODO: This should never be hit. */
4121 xmlSchemaPSimpleInternalErr(NULL
,
4122 "Internal error: xmlSchemaComponentListFree, "
4123 "unexpected component type '%s'\n",
4124 (const xmlChar
*) WXS_ITEM_TYPE_NAME(item
));
4135 * @schema: a schema structure
4137 * Deallocate a Schema structure.
4140 xmlSchemaFree(xmlSchemaPtr schema
)
4144 /* @volatiles is not used anymore :-/ */
4145 if (schema
->volatiles
!= NULL
)
4148 * Note that those slots are not responsible for freeing
4149 * schema components anymore; this will now be done by
4150 * the schema buckets.
4152 if (schema
->notaDecl
!= NULL
)
4153 xmlHashFree(schema
->notaDecl
, NULL
);
4154 if (schema
->attrDecl
!= NULL
)
4155 xmlHashFree(schema
->attrDecl
, NULL
);
4156 if (schema
->attrgrpDecl
!= NULL
)
4157 xmlHashFree(schema
->attrgrpDecl
, NULL
);
4158 if (schema
->elemDecl
!= NULL
)
4159 xmlHashFree(schema
->elemDecl
, NULL
);
4160 if (schema
->typeDecl
!= NULL
)
4161 xmlHashFree(schema
->typeDecl
, NULL
);
4162 if (schema
->groupDecl
!= NULL
)
4163 xmlHashFree(schema
->groupDecl
, NULL
);
4164 if (schema
->idcDef
!= NULL
)
4165 xmlHashFree(schema
->idcDef
, NULL
);
4167 if (schema
->schemasImports
!= NULL
)
4168 xmlHashFree(schema
->schemasImports
, xmlSchemaBucketFreeEntry
);
4169 if (schema
->includes
!= NULL
) {
4170 xmlSchemaItemListPtr list
= (xmlSchemaItemListPtr
) schema
->includes
;
4172 for (i
= 0; i
< list
->nbItems
; i
++) {
4173 xmlSchemaBucketFree((xmlSchemaBucketPtr
) list
->items
[i
]);
4175 xmlSchemaItemListFree(list
);
4177 if (schema
->annot
!= NULL
)
4178 xmlSchemaFreeAnnot(schema
->annot
);
4179 /* Never free the doc here, since this will be done by the buckets. */
4181 xmlDictFree(schema
->dict
);
4185 /************************************************************************
4189 ************************************************************************/
4191 #ifdef LIBXML_OUTPUT_ENABLED
4194 xmlSchemaTypeDump(xmlSchemaTypePtr type
, FILE * output
); /* forward */
4197 * xmlSchemaElementDump:
4199 * @output: the file output
4204 xmlSchemaElementDump(void *payload
, void *data
,
4205 const xmlChar
* name ATTRIBUTE_UNUSED
,
4206 const xmlChar
* namespace ATTRIBUTE_UNUSED
,
4207 const xmlChar
* context ATTRIBUTE_UNUSED
)
4209 xmlSchemaElementPtr elem
= (xmlSchemaElementPtr
) payload
;
4210 FILE *output
= (FILE *) data
;
4215 fprintf(output
, "Element");
4216 if (elem
->flags
& XML_SCHEMAS_ELEM_GLOBAL
)
4217 fprintf(output
, " (global)");
4218 fprintf(output
, ": '%s' ", elem
->name
);
4219 if (namespace != NULL
)
4220 fprintf(output
, "ns '%s'", namespace);
4221 fprintf(output
, "\n");
4223 if ((elem
->minOccurs
!= 1) || (elem
->maxOccurs
!= 1)) {
4224 fprintf(output
, " min %d ", elem
->minOccurs
);
4225 if (elem
->maxOccurs
>= UNBOUNDED
)
4226 fprintf(output
, "max: unbounded\n");
4227 else if (elem
->maxOccurs
!= 1)
4228 fprintf(output
, "max: %d\n", elem
->maxOccurs
);
4230 fprintf(output
, "\n");
4234 * Misc other properties.
4236 if ((elem
->flags
& XML_SCHEMAS_ELEM_NILLABLE
) ||
4237 (elem
->flags
& XML_SCHEMAS_ELEM_ABSTRACT
) ||
4238 (elem
->flags
& XML_SCHEMAS_ELEM_FIXED
) ||
4239 (elem
->flags
& XML_SCHEMAS_ELEM_DEFAULT
)) {
4240 fprintf(output
, " props: ");
4241 if (elem
->flags
& XML_SCHEMAS_ELEM_FIXED
)
4242 fprintf(output
, "[fixed] ");
4243 if (elem
->flags
& XML_SCHEMAS_ELEM_DEFAULT
)
4244 fprintf(output
, "[default] ");
4245 if (elem
->flags
& XML_SCHEMAS_ELEM_ABSTRACT
)
4246 fprintf(output
, "[abstract] ");
4247 if (elem
->flags
& XML_SCHEMAS_ELEM_NILLABLE
)
4248 fprintf(output
, "[nillable] ");
4249 fprintf(output
, "\n");
4252 * Default/fixed value.
4254 if (elem
->value
!= NULL
)
4255 fprintf(output
, " value: '%s'\n", elem
->value
);
4259 if (elem
->namedType
!= NULL
) {
4260 fprintf(output
, " type: '%s' ", elem
->namedType
);
4261 if (elem
->namedTypeNs
!= NULL
)
4262 fprintf(output
, "ns '%s'\n", elem
->namedTypeNs
);
4264 fprintf(output
, "\n");
4265 } else if (elem
->subtypes
!= NULL
) {
4269 xmlSchemaTypeDump(elem
->subtypes
, output
);
4272 * Substitution group.
4274 if (elem
->substGroup
!= NULL
) {
4275 fprintf(output
, " substitutionGroup: '%s' ", elem
->substGroup
);
4276 if (elem
->substGroupNs
!= NULL
)
4277 fprintf(output
, "ns '%s'\n", elem
->substGroupNs
);
4279 fprintf(output
, "\n");
4284 * xmlSchemaAnnotDump:
4285 * @output: the file output
4286 * @annot: a annotation
4288 * Dump the annotation
4291 xmlSchemaAnnotDump(FILE * output
, xmlSchemaAnnotPtr annot
)
4298 content
= xmlNodeGetContent(annot
->content
);
4299 if (content
!= NULL
) {
4300 fprintf(output
, " Annot: %s\n", content
);
4303 fprintf(output
, " Annot: empty\n");
4307 * xmlSchemaContentModelDump:
4308 * @particle: the schema particle
4309 * @output: the file output
4310 * @depth: the depth used for intentation
4312 * Dump a SchemaType structure
4315 xmlSchemaContentModelDump(xmlSchemaParticlePtr particle
, FILE * output
, int depth
)
4317 xmlChar
*str
= NULL
;
4318 xmlSchemaTreeItemPtr term
;
4322 if (particle
== NULL
)
4324 for (i
= 0;((i
< depth
) && (i
< 25));i
++)
4325 shift
[2 * i
] = shift
[2 * i
+ 1] = ' ';
4326 shift
[2 * i
] = shift
[2 * i
+ 1] = 0;
4327 fprintf(output
, "%s", shift
);
4328 if (particle
->children
== NULL
) {
4329 fprintf(output
, "MISSING particle term\n");
4332 term
= particle
->children
;
4334 fprintf(output
, "(NULL)");
4336 switch (term
->type
) {
4337 case XML_SCHEMA_TYPE_ELEMENT
:
4338 fprintf(output
, "ELEM '%s'", xmlSchemaFormatQName(&str
,
4339 ((xmlSchemaElementPtr
)term
)->targetNamespace
,
4340 ((xmlSchemaElementPtr
)term
)->name
));
4343 case XML_SCHEMA_TYPE_SEQUENCE
:
4344 fprintf(output
, "SEQUENCE");
4346 case XML_SCHEMA_TYPE_CHOICE
:
4347 fprintf(output
, "CHOICE");
4349 case XML_SCHEMA_TYPE_ALL
:
4350 fprintf(output
, "ALL");
4352 case XML_SCHEMA_TYPE_ANY
:
4353 fprintf(output
, "ANY");
4356 fprintf(output
, "UNKNOWN\n");
4360 if (particle
->minOccurs
!= 1)
4361 fprintf(output
, " min: %d", particle
->minOccurs
);
4362 if (particle
->maxOccurs
>= UNBOUNDED
)
4363 fprintf(output
, " max: unbounded");
4364 else if (particle
->maxOccurs
!= 1)
4365 fprintf(output
, " max: %d", particle
->maxOccurs
);
4366 fprintf(output
, "\n");
4368 ((term
->type
== XML_SCHEMA_TYPE_SEQUENCE
) ||
4369 (term
->type
== XML_SCHEMA_TYPE_CHOICE
) ||
4370 (term
->type
== XML_SCHEMA_TYPE_ALL
)) &&
4371 (term
->children
!= NULL
)) {
4372 xmlSchemaContentModelDump((xmlSchemaParticlePtr
) term
->children
,
4375 if (particle
->next
!= NULL
)
4376 xmlSchemaContentModelDump((xmlSchemaParticlePtr
) particle
->next
,
4381 * xmlSchemaAttrUsesDump:
4382 * @uses: attribute uses list
4383 * @output: the file output
4385 * Dumps a list of attribute use components.
4388 xmlSchemaAttrUsesDump(xmlSchemaItemListPtr uses
, FILE * output
)
4390 xmlSchemaAttributeUsePtr use
;
4391 xmlSchemaAttributeUseProhibPtr prohib
;
4392 xmlSchemaQNameRefPtr ref
;
4393 const xmlChar
*name
, *tns
;
4394 xmlChar
*str
= NULL
;
4397 if ((uses
== NULL
) || (uses
->nbItems
== 0))
4400 fprintf(output
, " attributes:\n");
4401 for (i
= 0; i
< uses
->nbItems
; i
++) {
4402 use
= uses
->items
[i
];
4403 if (use
->type
== XML_SCHEMA_EXTRA_ATTR_USE_PROHIB
) {
4404 fprintf(output
, " [prohibition] ");
4405 prohib
= (xmlSchemaAttributeUseProhibPtr
) use
;
4406 name
= prohib
->name
;
4407 tns
= prohib
->targetNamespace
;
4408 } else if (use
->type
== XML_SCHEMA_EXTRA_QNAMEREF
) {
4409 fprintf(output
, " [reference] ");
4410 ref
= (xmlSchemaQNameRefPtr
) use
;
4412 tns
= ref
->targetNamespace
;
4414 fprintf(output
, " [use] ");
4415 name
= WXS_ATTRUSE_DECL_NAME(use
);
4416 tns
= WXS_ATTRUSE_DECL_TNS(use
);
4418 fprintf(output
, "'%s'\n",
4419 (const char *) xmlSchemaFormatQName(&str
, tns
, name
));
4425 * xmlSchemaTypeDump:
4426 * @output: the file output
4427 * @type: a type structure
4429 * Dump a SchemaType structure
4432 xmlSchemaTypeDump(xmlSchemaTypePtr type
, FILE * output
)
4435 fprintf(output
, "Type: NULL\n");
4438 fprintf(output
, "Type: ");
4439 if (type
->name
!= NULL
)
4440 fprintf(output
, "'%s' ", type
->name
);
4442 fprintf(output
, "(no name) ");
4443 if (type
->targetNamespace
!= NULL
)
4444 fprintf(output
, "ns '%s' ", type
->targetNamespace
);
4445 switch (type
->type
) {
4446 case XML_SCHEMA_TYPE_BASIC
:
4447 fprintf(output
, "[basic] ");
4449 case XML_SCHEMA_TYPE_SIMPLE
:
4450 fprintf(output
, "[simple] ");
4452 case XML_SCHEMA_TYPE_COMPLEX
:
4453 fprintf(output
, "[complex] ");
4455 case XML_SCHEMA_TYPE_SEQUENCE
:
4456 fprintf(output
, "[sequence] ");
4458 case XML_SCHEMA_TYPE_CHOICE
:
4459 fprintf(output
, "[choice] ");
4461 case XML_SCHEMA_TYPE_ALL
:
4462 fprintf(output
, "[all] ");
4464 case XML_SCHEMA_TYPE_UR
:
4465 fprintf(output
, "[ur] ");
4467 case XML_SCHEMA_TYPE_RESTRICTION
:
4468 fprintf(output
, "[restriction] ");
4470 case XML_SCHEMA_TYPE_EXTENSION
:
4471 fprintf(output
, "[extension] ");
4474 fprintf(output
, "[unknown type %d] ", type
->type
);
4477 fprintf(output
, "content: ");
4478 switch (type
->contentType
) {
4479 case XML_SCHEMA_CONTENT_UNKNOWN
:
4480 fprintf(output
, "[unknown] ");
4482 case XML_SCHEMA_CONTENT_EMPTY
:
4483 fprintf(output
, "[empty] ");
4485 case XML_SCHEMA_CONTENT_ELEMENTS
:
4486 fprintf(output
, "[element] ");
4488 case XML_SCHEMA_CONTENT_MIXED
:
4489 fprintf(output
, "[mixed] ");
4491 case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS
:
4494 case XML_SCHEMA_CONTENT_BASIC
:
4495 fprintf(output
, "[basic] ");
4497 case XML_SCHEMA_CONTENT_SIMPLE
:
4498 fprintf(output
, "[simple] ");
4500 case XML_SCHEMA_CONTENT_ANY
:
4501 fprintf(output
, "[any] ");
4504 fprintf(output
, "\n");
4505 if (type
->base
!= NULL
) {
4506 fprintf(output
, " base type: '%s'", type
->base
);
4507 if (type
->baseNs
!= NULL
)
4508 fprintf(output
, " ns '%s'\n", type
->baseNs
);
4510 fprintf(output
, "\n");
4512 if (type
->attrUses
!= NULL
)
4513 xmlSchemaAttrUsesDump(type
->attrUses
, output
);
4514 if (type
->annot
!= NULL
)
4515 xmlSchemaAnnotDump(output
, type
->annot
);
4516 #ifdef DUMP_CONTENT_MODEL
4517 if ((type
->type
== XML_SCHEMA_TYPE_COMPLEX
) &&
4518 (type
->subtypes
!= NULL
)) {
4519 xmlSchemaContentModelDump((xmlSchemaParticlePtr
) type
->subtypes
,
4526 xmlSchemaTypeDumpEntry(void *type
, void *output
,
4527 const xmlChar
*name ATTRIBUTE_UNUSED
)
4529 xmlSchemaTypeDump((xmlSchemaTypePtr
) type
, (FILE *) output
);
4534 * @output: the file output
4535 * @schema: a schema structure
4537 * Dump a Schema structure.
4540 xmlSchemaDump(FILE * output
, xmlSchemaPtr schema
)
4544 if (schema
== NULL
) {
4545 fprintf(output
, "Schemas: NULL\n");
4548 fprintf(output
, "Schemas: ");
4549 if (schema
->name
!= NULL
)
4550 fprintf(output
, "%s, ", schema
->name
);
4552 fprintf(output
, "no name, ");
4553 if (schema
->targetNamespace
!= NULL
)
4554 fprintf(output
, "%s", (const char *) schema
->targetNamespace
);
4556 fprintf(output
, "no target namespace");
4557 fprintf(output
, "\n");
4558 if (schema
->annot
!= NULL
)
4559 xmlSchemaAnnotDump(output
, schema
->annot
);
4560 xmlHashScan(schema
->typeDecl
, xmlSchemaTypeDumpEntry
, output
);
4561 xmlHashScanFull(schema
->elemDecl
, xmlSchemaElementDump
, output
);
4564 #ifdef DEBUG_IDC_NODE_TABLE
4566 * xmlSchemaDebugDumpIDCTable:
4567 * @vctxt: the WXS validation context
4569 * Displays the current IDC table for debug purposes.
4572 xmlSchemaDebugDumpIDCTable(FILE * output
,
4573 const xmlChar
*namespaceName
,
4574 const xmlChar
*localName
,
4575 xmlSchemaPSVIIDCBindingPtr bind
)
4577 xmlChar
*str
= NULL
;
4578 const xmlChar
*value
;
4579 xmlSchemaPSVIIDCNodePtr tab
;
4580 xmlSchemaPSVIIDCKeyPtr key
;
4583 fprintf(output
, "IDC: TABLES on '%s'\n",
4584 xmlSchemaFormatQName(&str
, namespaceName
, localName
));
4590 fprintf(output
, "IDC: BINDING '%s' (%d)\n",
4591 xmlSchemaGetComponentQName(&str
,
4592 bind
->definition
), bind
->nbNodes
);
4594 for (i
= 0; i
< bind
->nbNodes
; i
++) {
4595 tab
= bind
->nodeTable
[i
];
4596 fprintf(output
, " ( ");
4597 for (j
= 0; j
< bind
->definition
->nbFields
; j
++) {
4599 if ((key
!= NULL
) && (key
->val
!= NULL
)) {
4600 res
= xmlSchemaGetCanonValue(key
->val
, &value
);
4602 fprintf(output
, "'%s' ", value
);
4604 fprintf(output
, "CANON-VALUE-FAILED ");
4606 FREE_AND_NULL(value
)
4607 } else if (key
!= NULL
)
4608 fprintf(output
, "(no val), ");
4610 fprintf(output
, "(key missing), ");
4612 fprintf(output
, ")\n");
4614 if (bind
->dupls
&& bind
->dupls
->nbItems
) {
4615 fprintf(output
, "IDC: dupls (%d):\n", bind
->dupls
->nbItems
);
4616 for (i
= 0; i
< bind
->dupls
->nbItems
; i
++) {
4617 tab
= bind
->dupls
->items
[i
];
4618 fprintf(output
, " ( ");
4619 for (j
= 0; j
< bind
->definition
->nbFields
; j
++) {
4621 if ((key
!= NULL
) && (key
->val
!= NULL
)) {
4622 res
= xmlSchemaGetCanonValue(key
->val
, &value
);
4624 fprintf(output
, "'%s' ", value
);
4626 fprintf(output
, "CANON-VALUE-FAILED ");
4628 FREE_AND_NULL(value
)
4629 } else if (key
!= NULL
)
4630 fprintf(output
, "(no val), ");
4632 fprintf(output
, "(key missing), ");
4634 fprintf(output
, ")\n");
4638 } while (bind
!= NULL
);
4640 #endif /* DEBUG_IDC */
4641 #endif /* LIBXML_OUTPUT_ENABLED */
4643 /************************************************************************
4647 ************************************************************************/
4650 * xmlSchemaGetPropNode:
4651 * @node: the element node
4652 * @name: the name of the attribute
4654 * Seeks an attribute with a name of @name in
4657 * Returns the attribute or NULL if not present.
4660 xmlSchemaGetPropNode(xmlNodePtr node
, const char *name
)
4664 if ((node
== NULL
) || (name
== NULL
))
4666 prop
= node
->properties
;
4667 while (prop
!= NULL
) {
4668 if ((prop
->ns
== NULL
) && xmlStrEqual(prop
->name
, BAD_CAST name
))
4676 * xmlSchemaGetPropNodeNs:
4677 * @node: the element node
4679 * @name: the name of the attribute
4681 * Seeks an attribute with a local name of @name and
4682 * a namespace URI of @uri.
4684 * Returns the attribute or NULL if not present.
4687 xmlSchemaGetPropNodeNs(xmlNodePtr node
, const char *uri
, const char *name
)
4691 if ((node
== NULL
) || (name
== NULL
))
4693 prop
= node
->properties
;
4694 while (prop
!= NULL
) {
4695 if ((prop
->ns
!= NULL
) &&
4696 xmlStrEqual(prop
->name
, BAD_CAST name
) &&
4697 xmlStrEqual(prop
->ns
->href
, BAD_CAST uri
))
4704 static const xmlChar
*
4705 xmlSchemaGetNodeContent(xmlSchemaParserCtxtPtr ctxt
, xmlNodePtr node
)
4710 val
= xmlNodeGetContent(node
);
4712 val
= xmlStrdup((xmlChar
*)"");
4713 ret
= xmlDictLookup(ctxt
->dict
, val
, -1);
4718 static const xmlChar
*
4719 xmlSchemaGetNodeContentNoDict(xmlNodePtr node
)
4721 return((const xmlChar
*) xmlNodeGetContent(node
));
4726 * @ctxt: the parser context
4728 * @name: the property name
4730 * Read a attribute value and internalize the string
4732 * Returns the string or NULL if not present.
4734 static const xmlChar
*
4735 xmlSchemaGetProp(xmlSchemaParserCtxtPtr ctxt
, xmlNodePtr node
,
4741 val
= xmlGetNoNsProp(node
, BAD_CAST name
);
4744 ret
= xmlDictLookup(ctxt
->dict
, val
, -1);
4749 /************************************************************************
4751 * Parsing functions *
4753 ************************************************************************/
4755 #define WXS_FIND_GLOBAL_ITEM(slot) \
4756 if (xmlStrEqual(nsName, schema->targetNamespace)) { \
4757 ret = xmlHashLookup(schema->slot, name); \
4758 if (ret != NULL) goto exit; \
4760 if (xmlHashSize(schema->schemasImports) > 1) { \
4761 xmlSchemaImportPtr import; \
4762 if (nsName == NULL) \
4763 import = xmlHashLookup(schema->schemasImports, \
4764 XML_SCHEMAS_NO_NAMESPACE); \
4766 import = xmlHashLookup(schema->schemasImports, nsName); \
4767 if (import == NULL) \
4769 ret = xmlHashLookup(import->schema->slot, name); \
4774 * @schema: the schema context
4775 * @name: the element name
4776 * @ns: the element namespace
4778 * Lookup a global element declaration in the schema.
4780 * Returns the element declaration or NULL if not found.
4782 static xmlSchemaElementPtr
4783 xmlSchemaGetElem(xmlSchemaPtr schema
, const xmlChar
* name
,
4784 const xmlChar
* nsName
)
4786 xmlSchemaElementPtr ret
= NULL
;
4788 if ((name
== NULL
) || (schema
== NULL
))
4790 if (schema
!= NULL
) {
4791 WXS_FIND_GLOBAL_ITEM(elemDecl
)
4797 fprintf(stderr
, "Unable to lookup element decl. %s", name
);
4799 fprintf(stderr
, "Unable to lookup element decl. %s:%s", name
,
4808 * @schema: the main schema
4809 * @name: the type's name
4810 * nsName: the type's namespace
4812 * Lookup a type in the schemas or the predefined types
4814 * Returns the group definition or NULL if not found.
4816 static xmlSchemaTypePtr
4817 xmlSchemaGetType(xmlSchemaPtr schema
, const xmlChar
* name
,
4818 const xmlChar
* nsName
)
4820 xmlSchemaTypePtr ret
= NULL
;
4824 /* First try the built-in types. */
4825 if ((nsName
!= NULL
) && xmlStrEqual(nsName
, xmlSchemaNs
)) {
4826 ret
= xmlSchemaGetPredefinedType(name
, nsName
);
4830 * Note that we try the parsed schemas as well here
4831 * since one might have parsed the S4S, which contain more
4832 * than the built-in types.
4833 * TODO: Can we optimize this?
4836 if (schema
!= NULL
) {
4837 WXS_FIND_GLOBAL_ITEM(typeDecl
)
4844 fprintf(stderr
, "Unable to lookup type %s", name
);
4846 fprintf(stderr
, "Unable to lookup type %s:%s", name
,
4854 * xmlSchemaGetAttributeDecl:
4855 * @schema: the context of the schema
4856 * @name: the name of the attribute
4857 * @ns: the target namespace of the attribute
4859 * Lookup a an attribute in the schema or imported schemas
4861 * Returns the attribute declaration or NULL if not found.
4863 static xmlSchemaAttributePtr
4864 xmlSchemaGetAttributeDecl(xmlSchemaPtr schema
, const xmlChar
* name
,
4865 const xmlChar
* nsName
)
4867 xmlSchemaAttributePtr ret
= NULL
;
4869 if ((name
== NULL
) || (schema
== NULL
))
4871 if (schema
!= NULL
) {
4872 WXS_FIND_GLOBAL_ITEM(attrDecl
)
4878 fprintf(stderr
, "Unable to lookup attribute %s", name
);
4880 fprintf(stderr
, "Unable to lookup attribute %s:%s", name
,
4888 * xmlSchemaGetAttributeGroup:
4889 * @schema: the context of the schema
4890 * @name: the name of the attribute group
4891 * @ns: the target namespace of the attribute group
4893 * Lookup a an attribute group in the schema or imported schemas
4895 * Returns the attribute group definition or NULL if not found.
4897 static xmlSchemaAttributeGroupPtr
4898 xmlSchemaGetAttributeGroup(xmlSchemaPtr schema
, const xmlChar
* name
,
4899 const xmlChar
* nsName
)
4901 xmlSchemaAttributeGroupPtr ret
= NULL
;
4903 if ((name
== NULL
) || (schema
== NULL
))
4905 if (schema
!= NULL
) {
4906 WXS_FIND_GLOBAL_ITEM(attrgrpDecl
)
4910 if ((ret != NULL) && (ret->redef != NULL)) {
4911 * Return the last redefinition. *
4918 fprintf(stderr
, "Unable to lookup attribute group %s", name
);
4920 fprintf(stderr
, "Unable to lookup attribute group %s:%s", name
,
4928 * xmlSchemaGetGroup:
4929 * @schema: the context of the schema
4930 * @name: the name of the group
4931 * @ns: the target namespace of the group
4933 * Lookup a group in the schema or imported schemas
4935 * Returns the group definition or NULL if not found.
4937 static xmlSchemaModelGroupDefPtr
4938 xmlSchemaGetGroup(xmlSchemaPtr schema
, const xmlChar
* name
,
4939 const xmlChar
* nsName
)
4941 xmlSchemaModelGroupDefPtr ret
= NULL
;
4943 if ((name
== NULL
) || (schema
== NULL
))
4945 if (schema
!= NULL
) {
4946 WXS_FIND_GLOBAL_ITEM(groupDecl
)
4953 fprintf(stderr
, "Unable to lookup group %s", name
);
4955 fprintf(stderr
, "Unable to lookup group %s:%s", name
,
4962 static xmlSchemaNotationPtr
4963 xmlSchemaGetNotation(xmlSchemaPtr schema
,
4964 const xmlChar
*name
,
4965 const xmlChar
*nsName
)
4967 xmlSchemaNotationPtr ret
= NULL
;
4969 if ((name
== NULL
) || (schema
== NULL
))
4971 if (schema
!= NULL
) {
4972 WXS_FIND_GLOBAL_ITEM(notaDecl
)
4978 static xmlSchemaIDCPtr
4979 xmlSchemaGetIDC(xmlSchemaPtr schema
,
4980 const xmlChar
*name
,
4981 const xmlChar
*nsName
)
4983 xmlSchemaIDCPtr ret
= NULL
;
4985 if ((name
== NULL
) || (schema
== NULL
))
4987 if (schema
!= NULL
) {
4988 WXS_FIND_GLOBAL_ITEM(idcDef
)
4995 * xmlSchemaGetNamedComponent:
4996 * @schema: the schema
4997 * @name: the name of the group
4998 * @ns: the target namespace of the group
5000 * Lookup a group in the schema or imported schemas
5002 * Returns the group definition or NULL if not found.
5004 static xmlSchemaBasicItemPtr
5005 xmlSchemaGetNamedComponent(xmlSchemaPtr schema
,
5006 xmlSchemaTypeType itemType
,
5007 const xmlChar
*name
,
5008 const xmlChar
*targetNs
)
5011 case XML_SCHEMA_TYPE_GROUP
:
5012 return ((xmlSchemaBasicItemPtr
) xmlSchemaGetGroup(schema
,
5014 case XML_SCHEMA_TYPE_ELEMENT
:
5015 return ((xmlSchemaBasicItemPtr
) xmlSchemaGetElem(schema
,
5023 /************************************************************************
5025 * Parsing functions *
5027 ************************************************************************/
5029 #define IS_BLANK_NODE(n) \
5030 (((n)->type == XML_TEXT_NODE) && (xmlSchemaIsBlank((n)->content, -1)))
5035 * @len: the length of the string or -1
5037 * Check if a string is ignorable
5039 * Returns 1 if the string is NULL or made of blanks chars, 0 otherwise
5042 xmlSchemaIsBlank(xmlChar
* str
, int len
)
5048 if (!(IS_BLANK_CH(*str
)))
5052 } else while ((*str
!= 0) && (len
!= 0)) {
5053 if (!(IS_BLANK_CH(*str
)))
5062 #define WXS_COMP_NAME(c, t) ((t) (c))->name
5063 #define WXS_COMP_TNS(c, t) ((t) (c))->targetNamespace
5065 * xmlSchemaFindRedefCompInGraph:
5066 * ATTENTION TODO: This uses pointer comp. for strings.
5068 static xmlSchemaBasicItemPtr
5069 xmlSchemaFindRedefCompInGraph(xmlSchemaBucketPtr bucket
,
5070 xmlSchemaTypeType type
,
5071 const xmlChar
*name
,
5072 const xmlChar
*nsName
)
5074 xmlSchemaBasicItemPtr ret
;
5077 if ((bucket
== NULL
) || (name
== NULL
))
5079 if ((bucket
->globals
== NULL
) ||
5080 (bucket
->globals
->nbItems
== 0))
5083 * Search in global components.
5085 for (i
= 0; i
< bucket
->globals
->nbItems
; i
++) {
5086 ret
= bucket
->globals
->items
[i
];
5087 if (ret
->type
== type
) {
5089 case XML_SCHEMA_TYPE_COMPLEX
:
5090 case XML_SCHEMA_TYPE_SIMPLE
:
5091 if ((WXS_COMP_NAME(ret
, xmlSchemaTypePtr
) == name
) &&
5092 (WXS_COMP_TNS(ret
, xmlSchemaTypePtr
) ==
5098 case XML_SCHEMA_TYPE_GROUP
:
5099 if ((WXS_COMP_NAME(ret
,
5100 xmlSchemaModelGroupDefPtr
) == name
) &&
5102 xmlSchemaModelGroupDefPtr
) == nsName
))
5107 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP
:
5108 if ((WXS_COMP_NAME(ret
,
5109 xmlSchemaAttributeGroupPtr
) == name
) &&
5111 xmlSchemaAttributeGroupPtr
) == nsName
))
5117 /* Should not be hit. */
5124 * Process imported/included schemas.
5126 if (bucket
->relations
!= NULL
) {
5127 xmlSchemaSchemaRelationPtr rel
= bucket
->relations
;
5130 * TODO: Marking the bucket will not avoid multiple searches
5131 * in the same schema, but avoids at least circularity.
5133 bucket
->flags
|= XML_SCHEMA_BUCKET_MARKED
;
5135 if ((rel
->bucket
!= NULL
) &&
5136 ((rel
->bucket
->flags
& XML_SCHEMA_BUCKET_MARKED
) == 0)) {
5137 ret
= xmlSchemaFindRedefCompInGraph(rel
->bucket
,
5138 type
, name
, nsName
);
5143 } while (rel
!= NULL
);
5144 bucket
->flags
^= XML_SCHEMA_BUCKET_MARKED
;
5150 * xmlSchemaAddNotation:
5151 * @ctxt: a schema parser context
5152 * @schema: the schema being built
5153 * @name: the item name
5155 * Add an XML schema annotation declaration
5156 * *WARNING* this interface is highly subject to change
5158 * Returns the new struture or NULL in case of error
5160 static xmlSchemaNotationPtr
5161 xmlSchemaAddNotation(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
5162 const xmlChar
*name
, const xmlChar
*nsName
,
5163 xmlNodePtr node ATTRIBUTE_UNUSED
)
5165 xmlSchemaNotationPtr ret
= NULL
;
5167 if ((ctxt
== NULL
) || (schema
== NULL
) || (name
== NULL
))
5170 ret
= (xmlSchemaNotationPtr
) xmlMalloc(sizeof(xmlSchemaNotation
));
5172 xmlSchemaPErrMemory(ctxt
, "add annotation", NULL
);
5175 memset(ret
, 0, sizeof(xmlSchemaNotation
));
5176 ret
->type
= XML_SCHEMA_TYPE_NOTATION
;
5178 ret
->targetNamespace
= nsName
;
5179 /* TODO: do we need the node to be set?
5180 * ret->node = node;*/
5181 WXS_ADD_GLOBAL(ctxt
, ret
);
5186 * xmlSchemaAddAttribute:
5187 * @ctxt: a schema parser context
5188 * @schema: the schema being built
5189 * @name: the item name
5190 * @namespace: the namespace
5192 * Add an XML schema Attrribute declaration
5193 * *WARNING* this interface is highly subject to change
5195 * Returns the new struture or NULL in case of error
5197 static xmlSchemaAttributePtr
5198 xmlSchemaAddAttribute(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
5199 const xmlChar
* name
, const xmlChar
* nsName
,
5200 xmlNodePtr node
, int topLevel
)
5202 xmlSchemaAttributePtr ret
= NULL
;
5204 if ((ctxt
== NULL
) || (schema
== NULL
))
5207 ret
= (xmlSchemaAttributePtr
) xmlMalloc(sizeof(xmlSchemaAttribute
));
5209 xmlSchemaPErrMemory(ctxt
, "allocating attribute", NULL
);
5212 memset(ret
, 0, sizeof(xmlSchemaAttribute
));
5213 ret
->type
= XML_SCHEMA_TYPE_ATTRIBUTE
;
5216 ret
->targetNamespace
= nsName
;
5219 WXS_ADD_GLOBAL(ctxt
, ret
);
5221 WXS_ADD_LOCAL(ctxt
, ret
);
5222 WXS_ADD_PENDING(ctxt
, ret
);
5227 * xmlSchemaAddAttributeUse:
5228 * @ctxt: a schema parser context
5229 * @schema: the schema being built
5230 * @name: the item name
5231 * @namespace: the namespace
5233 * Add an XML schema Attrribute declaration
5234 * *WARNING* this interface is highly subject to change
5236 * Returns the new struture or NULL in case of error
5238 static xmlSchemaAttributeUsePtr
5239 xmlSchemaAddAttributeUse(xmlSchemaParserCtxtPtr pctxt
,
5242 xmlSchemaAttributeUsePtr ret
= NULL
;
5247 ret
= (xmlSchemaAttributeUsePtr
) xmlMalloc(sizeof(xmlSchemaAttributeUse
));
5249 xmlSchemaPErrMemory(pctxt
, "allocating attribute", NULL
);
5252 memset(ret
, 0, sizeof(xmlSchemaAttributeUse
));
5253 ret
->type
= XML_SCHEMA_TYPE_ATTRIBUTE_USE
;
5256 WXS_ADD_LOCAL(pctxt
, ret
);
5261 * xmlSchemaAddRedef:
5263 * Adds a redefinition information. This is used at a later stage to:
5264 * resolve references to the redefined components and to check constraints.
5266 static xmlSchemaRedefPtr
5267 xmlSchemaAddRedef(xmlSchemaParserCtxtPtr pctxt
,
5268 xmlSchemaBucketPtr targetBucket
,
5270 const xmlChar
*refName
,
5271 const xmlChar
*refTargetNs
)
5273 xmlSchemaRedefPtr ret
;
5275 ret
= (xmlSchemaRedefPtr
)
5276 xmlMalloc(sizeof(xmlSchemaRedef
));
5278 xmlSchemaPErrMemory(pctxt
,
5279 "allocating redefinition info", NULL
);
5282 memset(ret
, 0, sizeof(xmlSchemaRedef
));
5284 ret
->targetBucket
= targetBucket
;
5285 ret
->refName
= refName
;
5286 ret
->refTargetNs
= refTargetNs
;
5287 if (WXS_CONSTRUCTOR(pctxt
)->redefs
== NULL
)
5288 WXS_CONSTRUCTOR(pctxt
)->redefs
= ret
;
5290 WXS_CONSTRUCTOR(pctxt
)->lastRedef
->next
= ret
;
5291 WXS_CONSTRUCTOR(pctxt
)->lastRedef
= ret
;
5297 * xmlSchemaAddAttributeGroupDefinition:
5298 * @ctxt: a schema parser context
5299 * @schema: the schema being built
5300 * @name: the item name
5301 * @nsName: the target namespace
5302 * @node: the corresponding node
5304 * Add an XML schema Attrribute Group definition.
5306 * Returns the new struture or NULL in case of error
5308 static xmlSchemaAttributeGroupPtr
5309 xmlSchemaAddAttributeGroupDefinition(xmlSchemaParserCtxtPtr pctxt
,
5310 xmlSchemaPtr schema ATTRIBUTE_UNUSED
,
5311 const xmlChar
*name
,
5312 const xmlChar
*nsName
,
5315 xmlSchemaAttributeGroupPtr ret
= NULL
;
5317 if ((pctxt
== NULL
) || (name
== NULL
))
5320 ret
= (xmlSchemaAttributeGroupPtr
)
5321 xmlMalloc(sizeof(xmlSchemaAttributeGroup
));
5323 xmlSchemaPErrMemory(pctxt
, "allocating attribute group", NULL
);
5326 memset(ret
, 0, sizeof(xmlSchemaAttributeGroup
));
5327 ret
->type
= XML_SCHEMA_TYPE_ATTRIBUTEGROUP
;
5329 ret
->targetNamespace
= nsName
;
5332 /* TODO: Remove the flag. */
5333 ret
->flags
|= XML_SCHEMAS_ATTRGROUP_GLOBAL
;
5334 if (pctxt
->isRedefine
) {
5335 pctxt
->redef
= xmlSchemaAddRedef(pctxt
, pctxt
->redefined
,
5337 if (pctxt
->redef
== NULL
) {
5341 pctxt
->redefCounter
= 0;
5343 WXS_ADD_GLOBAL(pctxt
, ret
);
5344 WXS_ADD_PENDING(pctxt
, ret
);
5349 * xmlSchemaAddElement:
5350 * @ctxt: a schema parser context
5351 * @schema: the schema being built
5352 * @name: the type name
5353 * @namespace: the type namespace
5355 * Add an XML schema Element declaration
5356 * *WARNING* this interface is highly subject to change
5358 * Returns the new struture or NULL in case of error
5360 static xmlSchemaElementPtr
5361 xmlSchemaAddElement(xmlSchemaParserCtxtPtr ctxt
,
5362 const xmlChar
* name
, const xmlChar
* nsName
,
5363 xmlNodePtr node
, int topLevel
)
5365 xmlSchemaElementPtr ret
= NULL
;
5367 if ((ctxt
== NULL
) || (name
== NULL
))
5370 ret
= (xmlSchemaElementPtr
) xmlMalloc(sizeof(xmlSchemaElement
));
5372 xmlSchemaPErrMemory(ctxt
, "allocating element", NULL
);
5375 memset(ret
, 0, sizeof(xmlSchemaElement
));
5376 ret
->type
= XML_SCHEMA_TYPE_ELEMENT
;
5378 ret
->targetNamespace
= nsName
;
5382 WXS_ADD_GLOBAL(ctxt
, ret
);
5384 WXS_ADD_LOCAL(ctxt
, ret
);
5385 WXS_ADD_PENDING(ctxt
, ret
);
5391 * @ctxt: a schema parser context
5392 * @schema: the schema being built
5393 * @name: the item name
5394 * @namespace: the namespace
5396 * Add an XML schema item
5397 * *WARNING* this interface is highly subject to change
5399 * Returns the new struture or NULL in case of error
5401 static xmlSchemaTypePtr
5402 xmlSchemaAddType(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
5403 xmlSchemaTypeType type
,
5404 const xmlChar
* name
, const xmlChar
* nsName
,
5405 xmlNodePtr node
, int topLevel
)
5407 xmlSchemaTypePtr ret
= NULL
;
5409 if ((ctxt
== NULL
) || (schema
== NULL
))
5412 ret
= (xmlSchemaTypePtr
) xmlMalloc(sizeof(xmlSchemaType
));
5414 xmlSchemaPErrMemory(ctxt
, "allocating type", NULL
);
5417 memset(ret
, 0, sizeof(xmlSchemaType
));
5420 ret
->targetNamespace
= nsName
;
5423 if (ctxt
->isRedefine
) {
5424 ctxt
->redef
= xmlSchemaAddRedef(ctxt
, ctxt
->redefined
,
5426 if (ctxt
->redef
== NULL
) {
5430 ctxt
->redefCounter
= 0;
5432 WXS_ADD_GLOBAL(ctxt
, ret
);
5434 WXS_ADD_LOCAL(ctxt
, ret
);
5435 WXS_ADD_PENDING(ctxt
, ret
);
5439 static xmlSchemaQNameRefPtr
5440 xmlSchemaNewQNameRef(xmlSchemaParserCtxtPtr pctxt
,
5441 xmlSchemaTypeType refType
,
5442 const xmlChar
*refName
,
5443 const xmlChar
*refNs
)
5445 xmlSchemaQNameRefPtr ret
;
5447 ret
= (xmlSchemaQNameRefPtr
)
5448 xmlMalloc(sizeof(xmlSchemaQNameRef
));
5450 xmlSchemaPErrMemory(pctxt
,
5451 "allocating QName reference item", NULL
);
5455 ret
->type
= XML_SCHEMA_EXTRA_QNAMEREF
;
5456 ret
->name
= refName
;
5457 ret
->targetNamespace
= refNs
;
5459 ret
->itemType
= refType
;
5461 * Store the reference item in the schema.
5463 WXS_ADD_LOCAL(pctxt
, ret
);
5467 static xmlSchemaAttributeUseProhibPtr
5468 xmlSchemaAddAttributeUseProhib(xmlSchemaParserCtxtPtr pctxt
)
5470 xmlSchemaAttributeUseProhibPtr ret
;
5472 ret
= (xmlSchemaAttributeUseProhibPtr
)
5473 xmlMalloc(sizeof(xmlSchemaAttributeUseProhib
));
5475 xmlSchemaPErrMemory(pctxt
,
5476 "allocating attribute use prohibition", NULL
);
5479 memset(ret
, 0, sizeof(xmlSchemaAttributeUseProhib
));
5480 ret
->type
= XML_SCHEMA_EXTRA_ATTR_USE_PROHIB
;
5481 WXS_ADD_LOCAL(pctxt
, ret
);
5487 * xmlSchemaAddModelGroup:
5488 * @ctxt: a schema parser context
5489 * @schema: the schema being built
5490 * @type: the "compositor" type of the model group
5491 * @node: the node in the schema doc
5493 * Adds a schema model group
5494 * *WARNING* this interface is highly subject to change
5496 * Returns the new struture or NULL in case of error
5498 static xmlSchemaModelGroupPtr
5499 xmlSchemaAddModelGroup(xmlSchemaParserCtxtPtr ctxt
,
5500 xmlSchemaPtr schema
,
5501 xmlSchemaTypeType type
,
5504 xmlSchemaModelGroupPtr ret
= NULL
;
5506 if ((ctxt
== NULL
) || (schema
== NULL
))
5509 ret
= (xmlSchemaModelGroupPtr
)
5510 xmlMalloc(sizeof(xmlSchemaModelGroup
));
5512 xmlSchemaPErrMemory(ctxt
, "allocating model group component",
5516 memset(ret
, 0, sizeof(xmlSchemaModelGroup
));
5519 WXS_ADD_LOCAL(ctxt
, ret
);
5520 if ((type
== XML_SCHEMA_TYPE_SEQUENCE
) ||
5521 (type
== XML_SCHEMA_TYPE_CHOICE
))
5522 WXS_ADD_PENDING(ctxt
, ret
);
5528 * xmlSchemaAddParticle:
5529 * @ctxt: a schema parser context
5530 * @schema: the schema being built
5531 * @node: the corresponding node in the schema doc
5532 * @min: the minOccurs
5533 * @max: the maxOccurs
5535 * Adds an XML schema particle component.
5536 * *WARNING* this interface is highly subject to change
5538 * Returns the new struture or NULL in case of error
5540 static xmlSchemaParticlePtr
5541 xmlSchemaAddParticle(xmlSchemaParserCtxtPtr ctxt
,
5542 xmlNodePtr node
, int min
, int max
)
5544 xmlSchemaParticlePtr ret
= NULL
;
5549 fprintf(stderr
, "Adding particle component\n");
5551 ret
= (xmlSchemaParticlePtr
)
5552 xmlMalloc(sizeof(xmlSchemaParticle
));
5554 xmlSchemaPErrMemory(ctxt
, "allocating particle component",
5558 ret
->type
= XML_SCHEMA_TYPE_PARTICLE
;
5561 ret
->minOccurs
= min
;
5562 ret
->maxOccurs
= max
;
5564 ret
->children
= NULL
;
5566 WXS_ADD_LOCAL(ctxt
, ret
);
5568 * Note that addition to pending components will be done locally
5569 * to the specific parsing function, since the most particles
5570 * need not to be fixed up (i.e. the reference to be resolved).
5571 * REMOVED: WXS_ADD_PENDING(ctxt, ret);
5577 * xmlSchemaAddModelGroupDefinition:
5578 * @ctxt: a schema validation context
5579 * @schema: the schema being built
5580 * @name: the group name
5582 * Add an XML schema Group definition
5584 * Returns the new struture or NULL in case of error
5586 static xmlSchemaModelGroupDefPtr
5587 xmlSchemaAddModelGroupDefinition(xmlSchemaParserCtxtPtr ctxt
,
5588 xmlSchemaPtr schema
,
5589 const xmlChar
*name
,
5590 const xmlChar
*nsName
,
5593 xmlSchemaModelGroupDefPtr ret
= NULL
;
5595 if ((ctxt
== NULL
) || (schema
== NULL
) || (name
== NULL
))
5598 ret
= (xmlSchemaModelGroupDefPtr
)
5599 xmlMalloc(sizeof(xmlSchemaModelGroupDef
));
5601 xmlSchemaPErrMemory(ctxt
, "adding group", NULL
);
5604 memset(ret
, 0, sizeof(xmlSchemaModelGroupDef
));
5606 ret
->type
= XML_SCHEMA_TYPE_GROUP
;
5608 ret
->targetNamespace
= nsName
;
5610 if (ctxt
->isRedefine
) {
5611 ctxt
->redef
= xmlSchemaAddRedef(ctxt
, ctxt
->redefined
,
5613 if (ctxt
->redef
== NULL
) {
5617 ctxt
->redefCounter
= 0;
5619 WXS_ADD_GLOBAL(ctxt
, ret
);
5620 WXS_ADD_PENDING(ctxt
, ret
);
5625 * xmlSchemaNewWildcardNs:
5626 * @ctxt: a schema validation context
5628 * Creates a new wildcard namespace constraint.
5630 * Returns the new struture or NULL in case of error
5632 static xmlSchemaWildcardNsPtr
5633 xmlSchemaNewWildcardNsConstraint(xmlSchemaParserCtxtPtr ctxt
)
5635 xmlSchemaWildcardNsPtr ret
;
5637 ret
= (xmlSchemaWildcardNsPtr
)
5638 xmlMalloc(sizeof(xmlSchemaWildcardNs
));
5640 xmlSchemaPErrMemory(ctxt
, "creating wildcard namespace constraint", NULL
);
5648 static xmlSchemaIDCPtr
5649 xmlSchemaAddIDC(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
5650 const xmlChar
*name
, const xmlChar
*nsName
,
5651 int category
, xmlNodePtr node
)
5653 xmlSchemaIDCPtr ret
= NULL
;
5655 if ((ctxt
== NULL
) || (schema
== NULL
) || (name
== NULL
))
5658 ret
= (xmlSchemaIDCPtr
) xmlMalloc(sizeof(xmlSchemaIDC
));
5660 xmlSchemaPErrMemory(ctxt
,
5661 "allocating an identity-constraint definition", NULL
);
5664 memset(ret
, 0, sizeof(xmlSchemaIDC
));
5665 /* The target namespace of the parent element declaration. */
5666 ret
->targetNamespace
= nsName
;
5668 ret
->type
= category
;
5671 WXS_ADD_GLOBAL(ctxt
, ret
);
5673 * Only keyrefs need to be fixup up.
5675 if (category
== XML_SCHEMA_TYPE_IDC_KEYREF
)
5676 WXS_ADD_PENDING(ctxt
, ret
);
5681 * xmlSchemaAddWildcard:
5682 * @ctxt: a schema validation context
5686 * It corresponds to a xsd:anyAttribute and xsd:any.
5688 * Returns the new struture or NULL in case of error
5690 static xmlSchemaWildcardPtr
5691 xmlSchemaAddWildcard(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
5692 xmlSchemaTypeType type
, xmlNodePtr node
)
5694 xmlSchemaWildcardPtr ret
= NULL
;
5696 if ((ctxt
== NULL
) || (schema
== NULL
))
5699 ret
= (xmlSchemaWildcardPtr
) xmlMalloc(sizeof(xmlSchemaWildcard
));
5701 xmlSchemaPErrMemory(ctxt
, "adding wildcard", NULL
);
5704 memset(ret
, 0, sizeof(xmlSchemaWildcard
));
5707 WXS_ADD_LOCAL(ctxt
, ret
);
5712 xmlSchemaSubstGroupFree(xmlSchemaSubstGroupPtr group
)
5716 if (group
->members
!= NULL
)
5717 xmlSchemaItemListFree(group
->members
);
5722 xmlSchemaSubstGroupFreeEntry(void *group
, const xmlChar
*name ATTRIBUTE_UNUSED
)
5724 xmlSchemaSubstGroupFree((xmlSchemaSubstGroupPtr
) group
);
5727 static xmlSchemaSubstGroupPtr
5728 xmlSchemaSubstGroupAdd(xmlSchemaParserCtxtPtr pctxt
,
5729 xmlSchemaElementPtr head
)
5731 xmlSchemaSubstGroupPtr ret
;
5733 /* Init subst group hash. */
5734 if (WXS_SUBST_GROUPS(pctxt
) == NULL
) {
5735 WXS_SUBST_GROUPS(pctxt
) = xmlHashCreateDict(10, pctxt
->dict
);
5736 if (WXS_SUBST_GROUPS(pctxt
) == NULL
)
5739 /* Create a new substitution group. */
5740 ret
= (xmlSchemaSubstGroupPtr
) xmlMalloc(sizeof(xmlSchemaSubstGroup
));
5742 xmlSchemaPErrMemory(NULL
,
5743 "allocating a substitution group container", NULL
);
5746 memset(ret
, 0, sizeof(xmlSchemaSubstGroup
));
5748 /* Create list of members. */
5749 ret
->members
= xmlSchemaItemListCreate();
5750 if (ret
->members
== NULL
) {
5751 xmlSchemaSubstGroupFree(ret
);
5754 /* Add subst group to hash. */
5755 if (xmlHashAddEntry2(WXS_SUBST_GROUPS(pctxt
),
5756 head
->name
, head
->targetNamespace
, ret
) != 0) {
5757 PERROR_INT("xmlSchemaSubstGroupAdd",
5758 "failed to add a new substitution container");
5759 xmlSchemaSubstGroupFree(ret
);
5765 static xmlSchemaSubstGroupPtr
5766 xmlSchemaSubstGroupGet(xmlSchemaParserCtxtPtr pctxt
,
5767 xmlSchemaElementPtr head
)
5769 if (WXS_SUBST_GROUPS(pctxt
) == NULL
)
5771 return(xmlHashLookup2(WXS_SUBST_GROUPS(pctxt
),
5772 head
->name
, head
->targetNamespace
));
5777 * xmlSchemaAddElementSubstitutionMember:
5778 * @pctxt: a schema parser context
5779 * @head: the head of the substitution group
5780 * @member: the new member of the substitution group
5782 * Allocate a new annotation structure.
5784 * Returns the newly allocated structure or NULL in case or error
5787 xmlSchemaAddElementSubstitutionMember(xmlSchemaParserCtxtPtr pctxt
,
5788 xmlSchemaElementPtr head
,
5789 xmlSchemaElementPtr member
)
5791 xmlSchemaSubstGroupPtr substGroup
= NULL
;
5793 if ((pctxt
== NULL
) || (head
== NULL
) || (member
== NULL
))
5796 substGroup
= xmlSchemaSubstGroupGet(pctxt
, head
);
5797 if (substGroup
== NULL
)
5798 substGroup
= xmlSchemaSubstGroupAdd(pctxt
, head
);
5799 if (substGroup
== NULL
)
5801 if (xmlSchemaItemListAdd(substGroup
->members
, member
) == -1)
5806 /************************************************************************
5808 * Utilities for parsing *
5810 ************************************************************************/
5813 * xmlSchemaPValAttrNodeQNameValue:
5814 * @ctxt: a schema parser context
5815 * @schema: the schema context
5816 * @ownerDes: the designation of the parent element
5817 * @ownerItem: the parent as a schema object
5818 * @value: the QName value
5819 * @local: the resulting local part if found, the attribute value otherwise
5820 * @uri: the resulting namespace URI if found
5822 * Extracts the local name and the URI of a QName value and validates it.
5823 * This one is intended to be used on attribute values that
5824 * should resolve to schema components.
5826 * Returns 0, in case the QName is valid, a positive error code
5827 * if not valid and -1 if an internal error occurs.
5830 xmlSchemaPValAttrNodeQNameValue(xmlSchemaParserCtxtPtr ctxt
,
5831 xmlSchemaPtr schema
,
5832 xmlSchemaBasicItemPtr ownerItem
,
5834 const xmlChar
*value
,
5835 const xmlChar
**uri
,
5836 const xmlChar
**local
)
5838 const xmlChar
*pref
;
5844 ret
= xmlValidateQName(value
, 1);
5846 xmlSchemaPSimpleTypeErr(ctxt
,
5847 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
5848 ownerItem
, (xmlNodePtr
) attr
,
5849 xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME
),
5850 NULL
, value
, NULL
, NULL
, NULL
);
5856 if (!strchr((char *) value
, ':')) {
5857 ns
= xmlSearchNs(attr
->doc
, attr
->parent
, NULL
);
5859 *uri
= xmlDictLookup(ctxt
->dict
, ns
->href
, -1);
5860 else if (schema
->flags
& XML_SCHEMAS_INCLUDING_CONVERT_NS
) {
5861 /* TODO: move XML_SCHEMAS_INCLUDING_CONVERT_NS to the
5862 * parser context. */
5864 * This one takes care of included schemas with no
5867 *uri
= ctxt
->targetNamespace
;
5869 *local
= xmlDictLookup(ctxt
->dict
, value
, -1);
5873 * At this point xmlSplitQName3 has to return a local name.
5875 *local
= xmlSplitQName3(value
, &len
);
5876 *local
= xmlDictLookup(ctxt
->dict
, *local
, -1);
5877 pref
= xmlDictLookup(ctxt
->dict
, value
, len
);
5878 ns
= xmlSearchNs(attr
->doc
, attr
->parent
, pref
);
5880 xmlSchemaPSimpleTypeErr(ctxt
,
5881 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
5882 ownerItem
, (xmlNodePtr
) attr
,
5883 xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME
), NULL
, value
,
5884 "The value '%s' of simple type 'xs:QName' has no "
5885 "corresponding namespace declaration in scope", value
, NULL
);
5888 *uri
= xmlDictLookup(ctxt
->dict
, ns
->href
, -1);
5894 * xmlSchemaPValAttrNodeQName:
5895 * @ctxt: a schema parser context
5896 * @schema: the schema context
5897 * @ownerDes: the designation of the owner element
5898 * @ownerItem: the owner as a schema object
5899 * @attr: the attribute node
5900 * @local: the resulting local part if found, the attribute value otherwise
5901 * @uri: the resulting namespace URI if found
5903 * Extracts and validates the QName of an attribute value.
5904 * This one is intended to be used on attribute values that
5905 * should resolve to schema components.
5907 * Returns 0, in case the QName is valid, a positive error code
5908 * if not valid and -1 if an internal error occurs.
5911 xmlSchemaPValAttrNodeQName(xmlSchemaParserCtxtPtr ctxt
,
5912 xmlSchemaPtr schema
,
5913 xmlSchemaBasicItemPtr ownerItem
,
5915 const xmlChar
**uri
,
5916 const xmlChar
**local
)
5918 const xmlChar
*value
;
5920 value
= xmlSchemaGetNodeContent(ctxt
, (xmlNodePtr
) attr
);
5921 return (xmlSchemaPValAttrNodeQNameValue(ctxt
, schema
,
5922 ownerItem
, attr
, value
, uri
, local
));
5926 * xmlSchemaPValAttrQName:
5927 * @ctxt: a schema parser context
5928 * @schema: the schema context
5929 * @ownerDes: the designation of the parent element
5930 * @ownerItem: the owner as a schema object
5931 * @ownerElem: the parent node of the attribute
5932 * @name: the name of the attribute
5933 * @local: the resulting local part if found, the attribute value otherwise
5934 * @uri: the resulting namespace URI if found
5936 * Extracts and validates the QName of an attribute value.
5938 * Returns 0, in case the QName is valid, a positive error code
5939 * if not valid and -1 if an internal error occurs.
5942 xmlSchemaPValAttrQName(xmlSchemaParserCtxtPtr ctxt
,
5943 xmlSchemaPtr schema
,
5944 xmlSchemaBasicItemPtr ownerItem
,
5945 xmlNodePtr ownerElem
,
5947 const xmlChar
**uri
,
5948 const xmlChar
**local
)
5952 attr
= xmlSchemaGetPropNode(ownerElem
, name
);
5958 return (xmlSchemaPValAttrNodeQName(ctxt
, schema
,
5959 ownerItem
, attr
, uri
, local
));
5963 * xmlSchemaPValAttrID:
5964 * @ctxt: a schema parser context
5965 * @schema: the schema context
5966 * @ownerDes: the designation of the parent element
5967 * @ownerItem: the owner as a schema object
5968 * @ownerElem: the parent node of the attribute
5969 * @name: the name of the attribute
5971 * Extracts and validates the ID of an attribute value.
5973 * Returns 0, in case the ID is valid, a positive error code
5974 * if not valid and -1 if an internal error occurs.
5977 xmlSchemaPValAttrNodeID(xmlSchemaParserCtxtPtr ctxt
, xmlAttrPtr attr
)
5980 const xmlChar
*value
;
5984 value
= xmlSchemaGetNodeContentNoDict((xmlNodePtr
) attr
);
5985 ret
= xmlValidateNCName(value
, 1);
5988 * NOTE: the IDness might have already be declared in the DTD
5990 if (attr
->atype
!= XML_ATTRIBUTE_ID
) {
5995 * TODO: Use xmlSchemaStrip here; it's not exported at this
5998 strip
= xmlSchemaCollapseString(value
);
5999 if (strip
!= NULL
) {
6000 xmlFree((xmlChar
*) value
);
6003 res
= xmlAddID(NULL
, attr
->doc
, value
, attr
);
6005 ret
= XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
;
6006 xmlSchemaPSimpleTypeErr(ctxt
,
6007 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
6008 NULL
, (xmlNodePtr
) attr
,
6009 xmlSchemaGetBuiltInType(XML_SCHEMAS_ID
),
6010 NULL
, NULL
, "Duplicate value '%s' of simple "
6011 "type 'xs:ID'", value
, NULL
);
6013 attr
->atype
= XML_ATTRIBUTE_ID
;
6015 } else if (ret
> 0) {
6016 ret
= XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
;
6017 xmlSchemaPSimpleTypeErr(ctxt
,
6018 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
6019 NULL
, (xmlNodePtr
) attr
,
6020 xmlSchemaGetBuiltInType(XML_SCHEMAS_ID
),
6021 NULL
, NULL
, "The value '%s' of simple type 'xs:ID' is "
6022 "not a valid 'xs:NCName'",
6026 xmlFree((xmlChar
*)value
);
6032 xmlSchemaPValAttrID(xmlSchemaParserCtxtPtr ctxt
,
6033 xmlNodePtr ownerElem
,
6034 const xmlChar
*name
)
6038 attr
= xmlSchemaGetPropNode(ownerElem
, (const char *) name
);
6041 return(xmlSchemaPValAttrNodeID(ctxt
, attr
));
6047 * @ctxt: a schema validation context
6048 * @node: a subtree containing XML Schema informations
6050 * Get the maxOccurs property
6052 * Returns the default if not found, or the value
6055 xmlGetMaxOccurs(xmlSchemaParserCtxtPtr ctxt
, xmlNodePtr node
,
6056 int min
, int max
, int def
, const char *expected
)
6058 const xmlChar
*val
, *cur
;
6062 attr
= xmlSchemaGetPropNode(node
, "maxOccurs");
6065 val
= xmlSchemaGetNodeContent(ctxt
, (xmlNodePtr
) attr
);
6067 if (xmlStrEqual(val
, (const xmlChar
*) "unbounded")) {
6068 if (max
!= UNBOUNDED
) {
6069 xmlSchemaPSimpleTypeErr(ctxt
,
6070 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
6071 /* XML_SCHEMAP_INVALID_MINOCCURS, */
6072 NULL
, (xmlNodePtr
) attr
, NULL
, expected
,
6073 val
, NULL
, NULL
, NULL
);
6076 return (UNBOUNDED
); /* encoding it with -1 might be another option */
6080 while (IS_BLANK_CH(*cur
))
6083 xmlSchemaPSimpleTypeErr(ctxt
,
6084 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
6085 /* XML_SCHEMAP_INVALID_MINOCCURS, */
6086 NULL
, (xmlNodePtr
) attr
, NULL
, expected
,
6087 val
, NULL
, NULL
, NULL
);
6090 while ((*cur
>= '0') && (*cur
<= '9')) {
6091 ret
= ret
* 10 + (*cur
- '0');
6094 while (IS_BLANK_CH(*cur
))
6097 * TODO: Restrict the maximal value to Integer.
6099 if ((*cur
!= 0) || (ret
< min
) || ((max
!= -1) && (ret
> max
))) {
6100 xmlSchemaPSimpleTypeErr(ctxt
,
6101 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
6102 /* XML_SCHEMAP_INVALID_MINOCCURS, */
6103 NULL
, (xmlNodePtr
) attr
, NULL
, expected
,
6104 val
, NULL
, NULL
, NULL
);
6112 * @ctxt: a schema validation context
6113 * @node: a subtree containing XML Schema informations
6115 * Get the minOccurs property
6117 * Returns the default if not found, or the value
6120 xmlGetMinOccurs(xmlSchemaParserCtxtPtr ctxt
, xmlNodePtr node
,
6121 int min
, int max
, int def
, const char *expected
)
6123 const xmlChar
*val
, *cur
;
6127 attr
= xmlSchemaGetPropNode(node
, "minOccurs");
6130 val
= xmlSchemaGetNodeContent(ctxt
, (xmlNodePtr
) attr
);
6132 while (IS_BLANK_CH(*cur
))
6135 xmlSchemaPSimpleTypeErr(ctxt
,
6136 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
6137 /* XML_SCHEMAP_INVALID_MINOCCURS, */
6138 NULL
, (xmlNodePtr
) attr
, NULL
, expected
,
6139 val
, NULL
, NULL
, NULL
);
6142 while ((*cur
>= '0') && (*cur
<= '9')) {
6143 ret
= ret
* 10 + (*cur
- '0');
6146 while (IS_BLANK_CH(*cur
))
6149 * TODO: Restrict the maximal value to Integer.
6151 if ((*cur
!= 0) || (ret
< min
) || ((max
!= -1) && (ret
> max
))) {
6152 xmlSchemaPSimpleTypeErr(ctxt
,
6153 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
6154 /* XML_SCHEMAP_INVALID_MINOCCURS, */
6155 NULL
, (xmlNodePtr
) attr
, NULL
, expected
,
6156 val
, NULL
, NULL
, NULL
);
6163 * xmlSchemaPGetBoolNodeValue:
6164 * @ctxt: a schema validation context
6165 * @ownerDes: owner designation
6166 * @ownerItem: the owner as a schema item
6167 * @node: the node holding the value
6169 * Converts a boolean string value into 1 or 0.
6174 xmlSchemaPGetBoolNodeValue(xmlSchemaParserCtxtPtr ctxt
,
6175 xmlSchemaBasicItemPtr ownerItem
,
6178 xmlChar
*value
= NULL
;
6181 value
= xmlNodeGetContent(node
);
6183 * 3.2.2.1 Lexical representation
6184 * An instance of a datatype that is defined as `boolean`
6185 * can have the following legal literals {true, false, 1, 0}.
6187 if (xmlStrEqual(BAD_CAST value
, BAD_CAST
"true"))
6189 else if (xmlStrEqual(BAD_CAST value
, BAD_CAST
"false"))
6191 else if (xmlStrEqual(BAD_CAST value
, BAD_CAST
"1"))
6193 else if (xmlStrEqual(BAD_CAST value
, BAD_CAST
"0"))
6196 xmlSchemaPSimpleTypeErr(ctxt
,
6197 XML_SCHEMAP_INVALID_BOOLEAN
,
6199 xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN
),
6200 NULL
, BAD_CAST value
,
6209 * xmlGetBooleanProp:
6210 * @ctxt: a schema validation context
6211 * @node: a subtree containing XML Schema informations
6212 * @name: the attribute name
6213 * @def: the default value
6215 * Evaluate if a boolean property is set
6217 * Returns the default if not found, 0 if found to be false,
6218 * 1 if found to be true
6221 xmlGetBooleanProp(xmlSchemaParserCtxtPtr ctxt
,
6223 const char *name
, int def
)
6227 val
= xmlSchemaGetProp(ctxt
, node
, name
);
6231 * 3.2.2.1 Lexical representation
6232 * An instance of a datatype that is defined as `boolean`
6233 * can have the following legal literals {true, false, 1, 0}.
6235 if (xmlStrEqual(val
, BAD_CAST
"true"))
6237 else if (xmlStrEqual(val
, BAD_CAST
"false"))
6239 else if (xmlStrEqual(val
, BAD_CAST
"1"))
6241 else if (xmlStrEqual(val
, BAD_CAST
"0"))
6244 xmlSchemaPSimpleTypeErr(ctxt
,
6245 XML_SCHEMAP_INVALID_BOOLEAN
,
6247 (xmlNodePtr
) xmlSchemaGetPropNode(node
, name
),
6248 xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN
),
6249 NULL
, val
, NULL
, NULL
, NULL
);
6254 /************************************************************************
6256 * Shema extraction from an Infoset *
6258 ************************************************************************/
6259 static xmlSchemaTypePtr
xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr
6260 ctxt
, xmlSchemaPtr schema
,
6263 static xmlSchemaTypePtr
xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr
6265 xmlSchemaPtr schema
,
6268 static xmlSchemaTypePtr
xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr
6270 xmlSchemaPtr schema
,
6272 xmlSchemaTypeType parentType
);
6273 static xmlSchemaBasicItemPtr
6274 xmlSchemaParseLocalAttribute(xmlSchemaParserCtxtPtr pctxt
,
6275 xmlSchemaPtr schema
,
6277 xmlSchemaItemListPtr uses
,
6279 static xmlSchemaTypePtr
xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt
,
6280 xmlSchemaPtr schema
,
6282 static xmlSchemaWildcardPtr
6283 xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt
,
6284 xmlSchemaPtr schema
, xmlNodePtr node
);
6287 * xmlSchemaPValAttrNodeValue:
6289 * @ctxt: a schema parser context
6290 * @ownerDes: the designation of the parent element
6291 * @ownerItem: the schema object owner if existent
6292 * @attr: the schema attribute node being validated
6294 * @type: the built-in type to be validated against
6296 * Validates a value against the given built-in type.
6297 * This one is intended to be used internally for validation
6298 * of schema attribute values during parsing of the schema.
6300 * Returns 0 if the value is valid, a positive error code
6301 * number otherwise and -1 in case of an internal or API error.
6304 xmlSchemaPValAttrNodeValue(xmlSchemaParserCtxtPtr pctxt
,
6305 xmlSchemaBasicItemPtr ownerItem
,
6307 const xmlChar
*value
,
6308 xmlSchemaTypePtr type
)
6314 * NOTE: Should we move this to xmlschematypes.c? Hmm, but this
6315 * one is really meant to be used internally, so better not.
6317 if ((pctxt
== NULL
) || (type
== NULL
) || (attr
== NULL
))
6319 if (type
->type
!= XML_SCHEMA_TYPE_BASIC
) {
6320 PERROR_INT("xmlSchemaPValAttrNodeValue",
6321 "the given type is not a built-in type");
6324 switch (type
->builtInType
) {
6325 case XML_SCHEMAS_NCNAME
:
6326 case XML_SCHEMAS_QNAME
:
6327 case XML_SCHEMAS_ANYURI
:
6328 case XML_SCHEMAS_TOKEN
:
6329 case XML_SCHEMAS_LANGUAGE
:
6330 ret
= xmlSchemaValPredefTypeNode(type
, value
, NULL
,
6334 PERROR_INT("xmlSchemaPValAttrNodeValue",
6335 "validation using the given type is not supported while "
6336 "parsing a schema");
6341 * TODO: Should we use the S4S error codes instead?
6344 PERROR_INT("xmlSchemaPValAttrNodeValue",
6345 "failed to validate a schema attribute value");
6347 } else if (ret
> 0) {
6348 if (WXS_IS_LIST(type
))
6349 ret
= XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2
;
6351 ret
= XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1
;
6352 xmlSchemaPSimpleTypeErr(pctxt
,
6353 ret
, ownerItem
, (xmlNodePtr
) attr
,
6354 type
, NULL
, value
, NULL
, NULL
, NULL
);
6360 * xmlSchemaPValAttrNode:
6362 * @ctxt: a schema parser context
6363 * @ownerDes: the designation of the parent element
6364 * @ownerItem: the schema object owner if existent
6365 * @attr: the schema attribute node being validated
6366 * @type: the built-in type to be validated against
6367 * @value: the resulting value if any
6369 * Extracts and validates a value against the given built-in type.
6370 * This one is intended to be used internally for validation
6371 * of schema attribute values during parsing of the schema.
6373 * Returns 0 if the value is valid, a positive error code
6374 * number otherwise and -1 in case of an internal or API error.
6377 xmlSchemaPValAttrNode(xmlSchemaParserCtxtPtr ctxt
,
6378 xmlSchemaBasicItemPtr ownerItem
,
6380 xmlSchemaTypePtr type
,
6381 const xmlChar
**value
)
6385 if ((ctxt
== NULL
) || (type
== NULL
) || (attr
== NULL
))
6388 val
= xmlSchemaGetNodeContent(ctxt
, (xmlNodePtr
) attr
);
6392 return (xmlSchemaPValAttrNodeValue(ctxt
, ownerItem
, attr
,
6397 * xmlSchemaPValAttr:
6399 * @ctxt: a schema parser context
6400 * @node: the element node of the attribute
6401 * @ownerDes: the designation of the parent element
6402 * @ownerItem: the schema object owner if existent
6403 * @ownerElem: the owner element node
6404 * @name: the name of the schema attribute node
6405 * @type: the built-in type to be validated against
6406 * @value: the resulting value if any
6408 * Extracts and validates a value against the given built-in type.
6409 * This one is intended to be used internally for validation
6410 * of schema attribute values during parsing of the schema.
6412 * Returns 0 if the value is valid, a positive error code
6413 * number otherwise and -1 in case of an internal or API error.
6416 xmlSchemaPValAttr(xmlSchemaParserCtxtPtr ctxt
,
6417 xmlSchemaBasicItemPtr ownerItem
,
6418 xmlNodePtr ownerElem
,
6420 xmlSchemaTypePtr type
,
6421 const xmlChar
**value
)
6425 if ((ctxt
== NULL
) || (type
== NULL
)) {
6430 if (type
->type
!= XML_SCHEMA_TYPE_BASIC
) {
6433 xmlSchemaPErr(ctxt
, ownerElem
,
6434 XML_SCHEMAP_INTERNAL
,
6435 "Internal error: xmlSchemaPValAttr, the given "
6436 "type '%s' is not a built-in type.\n",
6440 attr
= xmlSchemaGetPropNode(ownerElem
, name
);
6446 return (xmlSchemaPValAttrNode(ctxt
, ownerItem
, attr
,
6451 xmlSchemaCheckReference(xmlSchemaParserCtxtPtr pctxt
,
6452 xmlSchemaPtr schema ATTRIBUTE_UNUSED
,
6455 const xmlChar
*namespaceName
)
6457 /* TODO: Pointer comparison instead? */
6458 if (xmlStrEqual(pctxt
->targetNamespace
, namespaceName
))
6460 if (xmlStrEqual(xmlSchemaNs
, namespaceName
))
6463 * Check if the referenced namespace was <import>ed.
6465 if (WXS_BUCKET(pctxt
)->relations
!= NULL
) {
6466 xmlSchemaSchemaRelationPtr rel
;
6468 rel
= WXS_BUCKET(pctxt
)->relations
;
6470 if (WXS_IS_BUCKET_IMPMAIN(rel
->type
) &&
6471 xmlStrEqual(namespaceName
, rel
->importNamespace
))
6474 } while (rel
!= NULL
);
6477 * No matching <import>ed namespace found.
6480 xmlNodePtr n
= (attr
!= NULL
) ? (xmlNodePtr
) attr
: node
;
6482 if (namespaceName
== NULL
)
6483 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
6484 XML_SCHEMAP_SRC_RESOLVE
, n
, NULL
,
6485 "References from this schema to components in no "
6486 "namespace are not allowed, since not indicated by an "
6487 "import statement", NULL
, NULL
);
6489 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
6490 XML_SCHEMAP_SRC_RESOLVE
, n
, NULL
,
6491 "References from this schema to components in the "
6492 "namespace '%s' are not allowed, since not indicated by an "
6493 "import statement", namespaceName
, NULL
);
6495 return (XML_SCHEMAP_SRC_RESOLVE
);
6499 * xmlSchemaParseLocalAttributes:
6500 * @ctxt: a schema validation context
6501 * @schema: the schema being built
6502 * @node: a subtree containing XML Schema informations
6503 * @type: the hosting type where the attributes will be anchored
6505 * Parses attribute uses and attribute declarations and
6506 * attribute group references.
6509 xmlSchemaParseLocalAttributes(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
6510 xmlNodePtr
*child
, xmlSchemaItemListPtr
*list
,
6511 int parentType
, int *hasRefs
)
6515 while ((IS_SCHEMA((*child
), "attribute")) ||
6516 (IS_SCHEMA((*child
), "attributeGroup"))) {
6517 if (IS_SCHEMA((*child
), "attribute")) {
6518 item
= xmlSchemaParseLocalAttribute(ctxt
, schema
, *child
,
6521 item
= xmlSchemaParseAttributeGroupRef(ctxt
, schema
, *child
);
6522 if ((item
!= NULL
) && (hasRefs
!= NULL
))
6526 if (*list
== NULL
) {
6527 /* TODO: Customize grow factor. */
6528 *list
= xmlSchemaItemListCreate();
6532 if (xmlSchemaItemListAddSize(*list
, 2, item
) == -1)
6535 *child
= (*child
)->next
;
6541 * xmlSchemaParseAnnotation:
6542 * @ctxt: a schema validation context
6543 * @schema: the schema being built
6544 * @node: a subtree containing XML Schema informations
6546 * parse a XML schema Attrribute declaration
6547 * *WARNING* this interface is highly subject to change
6549 * Returns -1 in case of error, 0 if the declaration is improper and
6550 * 1 in case of success.
6552 static xmlSchemaAnnotPtr
6553 xmlSchemaParseAnnotation(xmlSchemaParserCtxtPtr ctxt
, xmlNodePtr node
, int needed
)
6555 xmlSchemaAnnotPtr ret
;
6556 xmlNodePtr child
= NULL
;
6561 * INFO: S4S completed.
6565 * {any attributes with non-schema namespace . . .}>
6566 * Content: (appinfo | documentation)*
6568 if ((ctxt
== NULL
) || (node
== NULL
))
6571 ret
= xmlSchemaNewAnnot(ctxt
, node
);
6574 attr
= node
->properties
;
6575 while (attr
!= NULL
) {
6576 if (((attr
->ns
== NULL
) &&
6577 (!xmlStrEqual(attr
->name
, BAD_CAST
"id"))) ||
6578 ((attr
->ns
!= NULL
) &&
6579 xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
))) {
6581 xmlSchemaPIllegalAttrErr(ctxt
,
6582 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
6586 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
6588 * And now for the children...
6590 child
= node
->children
;
6591 while (child
!= NULL
) {
6592 if (IS_SCHEMA(child
, "appinfo")) {
6593 /* TODO: make available the content of "appinfo". */
6596 * {any attributes with non-schema namespace . . .}>
6599 attr
= child
->properties
;
6600 while (attr
!= NULL
) {
6601 if (((attr
->ns
== NULL
) &&
6602 (!xmlStrEqual(attr
->name
, BAD_CAST
"source"))) ||
6603 ((attr
->ns
!= NULL
) &&
6604 xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
))) {
6606 xmlSchemaPIllegalAttrErr(ctxt
,
6607 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
6611 xmlSchemaPValAttr(ctxt
, NULL
, child
, "source",
6612 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI
), NULL
);
6613 child
= child
->next
;
6614 } else if (IS_SCHEMA(child
, "documentation")) {
6615 /* TODO: make available the content of "documentation". */
6618 * {any attributes with non-schema namespace . . .}>
6621 attr
= child
->properties
;
6622 while (attr
!= NULL
) {
6623 if (attr
->ns
== NULL
) {
6624 if (!xmlStrEqual(attr
->name
, BAD_CAST
"source")) {
6625 xmlSchemaPIllegalAttrErr(ctxt
,
6626 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
6629 if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
) ||
6630 (xmlStrEqual(attr
->name
, BAD_CAST
"lang") &&
6631 (!xmlStrEqual(attr
->ns
->href
, XML_XML_NAMESPACE
)))) {
6633 xmlSchemaPIllegalAttrErr(ctxt
,
6634 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
6640 * Attribute "xml:lang".
6642 attr
= xmlSchemaGetPropNodeNs(child
, (const char *) XML_XML_NAMESPACE
, "lang");
6644 xmlSchemaPValAttrNode(ctxt
, NULL
, attr
,
6645 xmlSchemaGetBuiltInType(XML_SCHEMAS_LANGUAGE
), NULL
);
6646 child
= child
->next
;
6649 xmlSchemaPContentErr(ctxt
,
6650 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
6651 NULL
, node
, child
, NULL
, "(appinfo | documentation)*");
6653 child
= child
->next
;
6661 * xmlSchemaParseFacet:
6662 * @ctxt: a schema validation context
6663 * @schema: the schema being built
6664 * @node: a subtree containing XML Schema informations
6666 * parse a XML schema Facet declaration
6667 * *WARNING* this interface is highly subject to change
6669 * Returns the new type structure or NULL in case of error
6671 static xmlSchemaFacetPtr
6672 xmlSchemaParseFacet(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
6675 xmlSchemaFacetPtr facet
;
6676 xmlNodePtr child
= NULL
;
6677 const xmlChar
*value
;
6679 if ((ctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
6682 facet
= xmlSchemaNewFacet();
6683 if (facet
== NULL
) {
6684 xmlSchemaPErrMemory(ctxt
, "allocating facet", node
);
6688 value
= xmlSchemaGetProp(ctxt
, node
, "value");
6689 if (value
== NULL
) {
6690 xmlSchemaPErr2(ctxt
, node
, child
, XML_SCHEMAP_FACET_NO_VALUE
,
6691 "Facet %s has no value\n", node
->name
, NULL
);
6692 xmlSchemaFreeFacet(facet
);
6695 if (IS_SCHEMA(node
, "minInclusive")) {
6696 facet
->type
= XML_SCHEMA_FACET_MININCLUSIVE
;
6697 } else if (IS_SCHEMA(node
, "minExclusive")) {
6698 facet
->type
= XML_SCHEMA_FACET_MINEXCLUSIVE
;
6699 } else if (IS_SCHEMA(node
, "maxInclusive")) {
6700 facet
->type
= XML_SCHEMA_FACET_MAXINCLUSIVE
;
6701 } else if (IS_SCHEMA(node
, "maxExclusive")) {
6702 facet
->type
= XML_SCHEMA_FACET_MAXEXCLUSIVE
;
6703 } else if (IS_SCHEMA(node
, "totalDigits")) {
6704 facet
->type
= XML_SCHEMA_FACET_TOTALDIGITS
;
6705 } else if (IS_SCHEMA(node
, "fractionDigits")) {
6706 facet
->type
= XML_SCHEMA_FACET_FRACTIONDIGITS
;
6707 } else if (IS_SCHEMA(node
, "pattern")) {
6708 facet
->type
= XML_SCHEMA_FACET_PATTERN
;
6709 } else if (IS_SCHEMA(node
, "enumeration")) {
6710 facet
->type
= XML_SCHEMA_FACET_ENUMERATION
;
6711 } else if (IS_SCHEMA(node
, "whiteSpace")) {
6712 facet
->type
= XML_SCHEMA_FACET_WHITESPACE
;
6713 } else if (IS_SCHEMA(node
, "length")) {
6714 facet
->type
= XML_SCHEMA_FACET_LENGTH
;
6715 } else if (IS_SCHEMA(node
, "maxLength")) {
6716 facet
->type
= XML_SCHEMA_FACET_MAXLENGTH
;
6717 } else if (IS_SCHEMA(node
, "minLength")) {
6718 facet
->type
= XML_SCHEMA_FACET_MINLENGTH
;
6720 xmlSchemaPErr2(ctxt
, node
, child
, XML_SCHEMAP_UNKNOWN_FACET_TYPE
,
6721 "Unknown facet type %s\n", node
->name
, NULL
);
6722 xmlSchemaFreeFacet(facet
);
6725 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
6726 facet
->value
= value
;
6727 if ((facet
->type
!= XML_SCHEMA_FACET_PATTERN
) &&
6728 (facet
->type
!= XML_SCHEMA_FACET_ENUMERATION
)) {
6729 const xmlChar
*fixed
;
6731 fixed
= xmlSchemaGetProp(ctxt
, node
, "fixed");
6732 if (fixed
!= NULL
) {
6733 if (xmlStrEqual(fixed
, BAD_CAST
"true"))
6737 child
= node
->children
;
6739 if (IS_SCHEMA(child
, "annotation")) {
6740 facet
->annot
= xmlSchemaParseAnnotation(ctxt
, child
, 1);
6741 child
= child
->next
;
6743 if (child
!= NULL
) {
6744 xmlSchemaPErr2(ctxt
, node
, child
, XML_SCHEMAP_UNKNOWN_FACET_CHILD
,
6745 "Facet %s has unexpected child content\n",
6752 * xmlSchemaParseWildcardNs:
6753 * @ctxt: a schema parser context
6754 * @wildc: the wildcard, already created
6755 * @node: a subtree containing XML Schema informations
6757 * Parses the attribute "processContents" and "namespace"
6758 * of a xsd:anyAttribute and xsd:any.
6759 * *WARNING* this interface is highly subject to change
6761 * Returns 0 if everything goes fine, a positive error code
6762 * if something is not valid and -1 if an internal error occurs.
6765 xmlSchemaParseWildcardNs(xmlSchemaParserCtxtPtr ctxt
,
6766 xmlSchemaPtr schema ATTRIBUTE_UNUSED
,
6767 xmlSchemaWildcardPtr wildc
,
6770 const xmlChar
*pc
, *ns
, *dictnsItem
;
6773 xmlSchemaWildcardNsPtr tmp
, lastNs
= NULL
;
6776 pc
= xmlSchemaGetProp(ctxt
, node
, "processContents");
6778 || (xmlStrEqual(pc
, (const xmlChar
*) "strict"))) {
6779 wildc
->processContents
= XML_SCHEMAS_ANY_STRICT
;
6780 } else if (xmlStrEqual(pc
, (const xmlChar
*) "skip")) {
6781 wildc
->processContents
= XML_SCHEMAS_ANY_SKIP
;
6782 } else if (xmlStrEqual(pc
, (const xmlChar
*) "lax")) {
6783 wildc
->processContents
= XML_SCHEMAS_ANY_LAX
;
6785 xmlSchemaPSimpleTypeErr(ctxt
,
6786 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
6788 NULL
, "(strict | skip | lax)", pc
,
6790 wildc
->processContents
= XML_SCHEMAS_ANY_STRICT
;
6791 ret
= XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
;
6794 * Build the namespace constraints.
6796 attr
= xmlSchemaGetPropNode(node
, "namespace");
6797 ns
= xmlSchemaGetNodeContent(ctxt
, (xmlNodePtr
) attr
);
6798 if ((attr
== NULL
) || (xmlStrEqual(ns
, BAD_CAST
"##any")))
6800 else if (xmlStrEqual(ns
, BAD_CAST
"##other")) {
6801 wildc
->negNsSet
= xmlSchemaNewWildcardNsConstraint(ctxt
);
6802 if (wildc
->negNsSet
== NULL
) {
6805 wildc
->negNsSet
->value
= ctxt
->targetNamespace
;
6807 const xmlChar
*end
, *cur
;
6811 while (IS_BLANK_CH(*cur
))
6814 while ((*end
!= 0) && (!(IS_BLANK_CH(*end
))))
6818 nsItem
= xmlStrndup(cur
, end
- cur
);
6819 if ((xmlStrEqual(nsItem
, BAD_CAST
"##other")) ||
6820 (xmlStrEqual(nsItem
, BAD_CAST
"##any"))) {
6821 xmlSchemaPSimpleTypeErr(ctxt
,
6822 XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER
,
6823 NULL
, (xmlNodePtr
) attr
,
6825 "((##any | ##other) | List of (xs:anyURI | "
6826 "(##targetNamespace | ##local)))",
6827 nsItem
, NULL
, NULL
, NULL
);
6828 ret
= XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER
;
6830 if (xmlStrEqual(nsItem
, BAD_CAST
"##targetNamespace")) {
6831 dictnsItem
= ctxt
->targetNamespace
;
6832 } else if (xmlStrEqual(nsItem
, BAD_CAST
"##local")) {
6836 * Validate the item (anyURI).
6838 xmlSchemaPValAttrNodeValue(ctxt
, NULL
, attr
,
6839 nsItem
, xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI
));
6840 dictnsItem
= xmlDictLookup(ctxt
->dict
, nsItem
, -1);
6843 * Avoid dublicate namespaces.
6846 while (tmp
!= NULL
) {
6847 if (dictnsItem
== tmp
->value
)
6852 tmp
= xmlSchemaNewWildcardNsConstraint(ctxt
);
6857 tmp
->value
= dictnsItem
;
6859 if (wildc
->nsSet
== NULL
)
6861 else if (lastNs
!= NULL
)
6869 } while (*cur
!= 0);
6875 xmlSchemaPCheckParticleCorrect_2(xmlSchemaParserCtxtPtr ctxt
,
6876 xmlSchemaParticlePtr item ATTRIBUTE_UNUSED
,
6881 if ((maxOccurs
== 0) && ( minOccurs
== 0))
6883 if (maxOccurs
!= UNBOUNDED
) {
6885 * TODO: Maybe we should better not create the particle,
6886 * if min/max is invalid, since it could confuse the build of the
6890 * 3.9.6 Schema Component Constraint: Particle Correct
6893 if (maxOccurs
< 1) {
6895 * 2.2 {max occurs} must be greater than or equal to 1.
6897 xmlSchemaPCustomAttrErr(ctxt
,
6898 XML_SCHEMAP_P_PROPS_CORRECT_2_2
,
6900 xmlSchemaGetPropNode(node
, "maxOccurs"),
6901 "The value must be greater than or equal to 1");
6902 return (XML_SCHEMAP_P_PROPS_CORRECT_2_2
);
6903 } else if (minOccurs
> maxOccurs
) {
6905 * 2.1 {min occurs} must not be greater than {max occurs}.
6907 xmlSchemaPCustomAttrErr(ctxt
,
6908 XML_SCHEMAP_P_PROPS_CORRECT_2_1
,
6910 xmlSchemaGetPropNode(node
, "minOccurs"),
6911 "The value must not be greater than the value of 'maxOccurs'");
6912 return (XML_SCHEMAP_P_PROPS_CORRECT_2_1
);
6919 * xmlSchemaParseAny:
6920 * @ctxt: a schema validation context
6921 * @schema: the schema being built
6922 * @node: a subtree containing XML Schema informations
6924 * Parsea a XML schema <any> element. A particle and wildcard
6925 * will be created (except if minOccurs==maxOccurs==0, in this case
6926 * nothing will be created).
6927 * *WARNING* this interface is highly subject to change
6929 * Returns the particle or NULL in case of error or if minOccurs==maxOccurs==0
6931 static xmlSchemaParticlePtr
6932 xmlSchemaParseAny(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
6935 xmlSchemaParticlePtr particle
;
6936 xmlNodePtr child
= NULL
;
6937 xmlSchemaWildcardPtr wild
;
6940 xmlSchemaAnnotPtr annot
= NULL
;
6942 if ((ctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
6945 * Check for illegal attributes.
6947 attr
= node
->properties
;
6948 while (attr
!= NULL
) {
6949 if (attr
->ns
== NULL
) {
6950 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"id")) &&
6951 (!xmlStrEqual(attr
->name
, BAD_CAST
"minOccurs")) &&
6952 (!xmlStrEqual(attr
->name
, BAD_CAST
"maxOccurs")) &&
6953 (!xmlStrEqual(attr
->name
, BAD_CAST
"namespace")) &&
6954 (!xmlStrEqual(attr
->name
, BAD_CAST
"processContents"))) {
6955 xmlSchemaPIllegalAttrErr(ctxt
,
6956 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
6958 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
6959 xmlSchemaPIllegalAttrErr(ctxt
,
6960 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
6964 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
6966 * minOccurs/maxOccurs.
6968 max
= xmlGetMaxOccurs(ctxt
, node
, 0, UNBOUNDED
, 1,
6969 "(xs:nonNegativeInteger | unbounded)");
6970 min
= xmlGetMinOccurs(ctxt
, node
, 0, -1, 1,
6971 "xs:nonNegativeInteger");
6972 xmlSchemaPCheckParticleCorrect_2(ctxt
, NULL
, node
, min
, max
);
6974 * Create & parse the wildcard.
6976 wild
= xmlSchemaAddWildcard(ctxt
, schema
, XML_SCHEMA_TYPE_ANY
, node
);
6979 xmlSchemaParseWildcardNs(ctxt
, schema
, wild
, node
);
6981 * And now for the children...
6983 child
= node
->children
;
6984 if (IS_SCHEMA(child
, "annotation")) {
6985 annot
= xmlSchemaParseAnnotation(ctxt
, child
, 1);
6986 child
= child
->next
;
6988 if (child
!= NULL
) {
6989 xmlSchemaPContentErr(ctxt
,
6990 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
6992 NULL
, "(annotation?)");
6995 * No component if minOccurs==maxOccurs==0.
6997 if ((min
== 0) && (max
== 0)) {
6998 /* Don't free the wildcard, since it's already on the list. */
7002 * Create the particle.
7004 particle
= xmlSchemaAddParticle(ctxt
, node
, min
, max
);
7005 if (particle
== NULL
)
7007 particle
->annot
= annot
;
7008 particle
->children
= (xmlSchemaTreeItemPtr
) wild
;
7014 * xmlSchemaParseNotation:
7015 * @ctxt: a schema validation context
7016 * @schema: the schema being built
7017 * @node: a subtree containing XML Schema informations
7019 * parse a XML schema Notation declaration
7021 * Returns the new structure or NULL in case of error
7023 static xmlSchemaNotationPtr
7024 xmlSchemaParseNotation(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
7027 const xmlChar
*name
;
7028 xmlSchemaNotationPtr ret
;
7029 xmlNodePtr child
= NULL
;
7031 if ((ctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
7033 name
= xmlSchemaGetProp(ctxt
, node
, "name");
7035 xmlSchemaPErr2(ctxt
, node
, child
, XML_SCHEMAP_NOTATION_NO_NAME
,
7036 "Notation has no name\n", NULL
, NULL
);
7039 ret
= xmlSchemaAddNotation(ctxt
, schema
, name
,
7040 ctxt
->targetNamespace
, node
);
7043 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
7045 child
= node
->children
;
7046 if (IS_SCHEMA(child
, "annotation")) {
7047 ret
->annot
= xmlSchemaParseAnnotation(ctxt
, child
, 1);
7048 child
= child
->next
;
7050 if (child
!= NULL
) {
7051 xmlSchemaPContentErr(ctxt
,
7052 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
7054 NULL
, "(annotation?)");
7061 * xmlSchemaParseAnyAttribute:
7062 * @ctxt: a schema validation context
7063 * @schema: the schema being built
7064 * @node: a subtree containing XML Schema informations
7066 * parse a XML schema AnyAttrribute declaration
7067 * *WARNING* this interface is highly subject to change
7069 * Returns a wildcard or NULL.
7071 static xmlSchemaWildcardPtr
7072 xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt
,
7073 xmlSchemaPtr schema
, xmlNodePtr node
)
7075 xmlSchemaWildcardPtr ret
;
7076 xmlNodePtr child
= NULL
;
7079 if ((ctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
7082 ret
= xmlSchemaAddWildcard(ctxt
, schema
, XML_SCHEMA_TYPE_ANY_ATTRIBUTE
,
7088 * Check for illegal attributes.
7090 attr
= node
->properties
;
7091 while (attr
!= NULL
) {
7092 if (attr
->ns
== NULL
) {
7093 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"id")) &&
7094 (!xmlStrEqual(attr
->name
, BAD_CAST
"namespace")) &&
7095 (!xmlStrEqual(attr
->name
, BAD_CAST
"processContents"))) {
7096 xmlSchemaPIllegalAttrErr(ctxt
,
7097 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
7099 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
7100 xmlSchemaPIllegalAttrErr(ctxt
,
7101 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
7105 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
7107 * Parse the namespace list.
7109 if (xmlSchemaParseWildcardNs(ctxt
, schema
, ret
, node
) != 0)
7112 * And now for the children...
7114 child
= node
->children
;
7115 if (IS_SCHEMA(child
, "annotation")) {
7116 ret
->annot
= xmlSchemaParseAnnotation(ctxt
, child
, 1);
7117 child
= child
->next
;
7119 if (child
!= NULL
) {
7120 xmlSchemaPContentErr(ctxt
,
7121 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
7123 NULL
, "(annotation?)");
7131 * xmlSchemaParseAttribute:
7132 * @ctxt: a schema validation context
7133 * @schema: the schema being built
7134 * @node: a subtree containing XML Schema informations
7136 * parse a XML schema Attrribute declaration
7137 * *WARNING* this interface is highly subject to change
7139 * Returns the attribute declaration.
7141 static xmlSchemaBasicItemPtr
7142 xmlSchemaParseLocalAttribute(xmlSchemaParserCtxtPtr pctxt
,
7143 xmlSchemaPtr schema
,
7145 xmlSchemaItemListPtr uses
,
7148 const xmlChar
*attrValue
, *name
= NULL
, *ns
= NULL
;
7149 xmlSchemaAttributeUsePtr use
= NULL
;
7150 xmlNodePtr child
= NULL
;
7152 const xmlChar
*tmpNs
= NULL
, *tmpName
= NULL
, *defValue
= NULL
;
7153 int isRef
= 0, occurs
= XML_SCHEMAS_ATTR_USE_OPTIONAL
;
7154 int nberrors
, hasForm
= 0, defValueType
= 0;
7156 #define WXS_ATTR_DEF_VAL_DEFAULT 1
7157 #define WXS_ATTR_DEF_VAL_FIXED 2
7160 * 3.2.3 Constraints on XML Representations of Attribute Declarations
7163 if ((pctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
7165 attr
= xmlSchemaGetPropNode(node
, "ref");
7167 if (xmlSchemaPValAttrNodeQName(pctxt
, schema
,
7168 NULL
, attr
, &tmpNs
, &tmpName
) != 0) {
7171 if (xmlSchemaCheckReference(pctxt
, schema
, node
, attr
, tmpNs
) != 0)
7175 nberrors
= pctxt
->nberrors
;
7177 * Check for illegal attributes.
7179 attr
= node
->properties
;
7180 while (attr
!= NULL
) {
7181 if (attr
->ns
== NULL
) {
7183 if (xmlStrEqual(attr
->name
, BAD_CAST
"id")) {
7184 xmlSchemaPValAttrNodeID(pctxt
, attr
);
7186 } else if (xmlStrEqual(attr
->name
, BAD_CAST
"ref")) {
7190 if (xmlStrEqual(attr
->name
, BAD_CAST
"name")) {
7192 } else if (xmlStrEqual(attr
->name
, BAD_CAST
"id")) {
7193 xmlSchemaPValAttrNodeID(pctxt
, attr
);
7195 } else if (xmlStrEqual(attr
->name
, BAD_CAST
"type")) {
7196 xmlSchemaPValAttrNodeQName(pctxt
, schema
, NULL
,
7197 attr
, &tmpNs
, &tmpName
);
7199 } else if (xmlStrEqual(attr
->name
, BAD_CAST
"form")) {
7201 * Evaluate the target namespace
7204 attrValue
= xmlSchemaGetNodeContent(pctxt
,
7206 if (xmlStrEqual(attrValue
, BAD_CAST
"qualified")) {
7207 ns
= pctxt
->targetNamespace
;
7208 } else if (!xmlStrEqual(attrValue
, BAD_CAST
"unqualified"))
7210 xmlSchemaPSimpleTypeErr(pctxt
,
7211 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
7212 NULL
, (xmlNodePtr
) attr
,
7213 NULL
, "(qualified | unqualified)",
7214 attrValue
, NULL
, NULL
, NULL
);
7219 if (xmlStrEqual(attr
->name
, BAD_CAST
"use")) {
7221 attrValue
= xmlSchemaGetNodeContent(pctxt
, (xmlNodePtr
) attr
);
7222 /* TODO: Maybe we need to normalize the value beforehand. */
7223 if (xmlStrEqual(attrValue
, BAD_CAST
"optional"))
7224 occurs
= XML_SCHEMAS_ATTR_USE_OPTIONAL
;
7225 else if (xmlStrEqual(attrValue
, BAD_CAST
"prohibited"))
7226 occurs
= XML_SCHEMAS_ATTR_USE_PROHIBITED
;
7227 else if (xmlStrEqual(attrValue
, BAD_CAST
"required"))
7228 occurs
= XML_SCHEMAS_ATTR_USE_REQUIRED
;
7230 xmlSchemaPSimpleTypeErr(pctxt
,
7231 XML_SCHEMAP_INVALID_ATTR_USE
,
7232 NULL
, (xmlNodePtr
) attr
,
7233 NULL
, "(optional | prohibited | required)",
7234 attrValue
, NULL
, NULL
, NULL
);
7237 } else if (xmlStrEqual(attr
->name
, BAD_CAST
"default")) {
7240 * default and fixed must not both be present.
7243 xmlSchemaPMutualExclAttrErr(pctxt
,
7244 XML_SCHEMAP_SRC_ATTRIBUTE_1
,
7245 NULL
, attr
, "default", "fixed");
7247 defValue
= xmlSchemaGetNodeContent(pctxt
, (xmlNodePtr
) attr
);
7248 defValueType
= WXS_ATTR_DEF_VAL_DEFAULT
;
7251 } else if (xmlStrEqual(attr
->name
, BAD_CAST
"fixed")) {
7254 * default and fixed must not both be present.
7257 xmlSchemaPMutualExclAttrErr(pctxt
,
7258 XML_SCHEMAP_SRC_ATTRIBUTE_1
,
7259 NULL
, attr
, "default", "fixed");
7261 defValue
= xmlSchemaGetNodeContent(pctxt
, (xmlNodePtr
) attr
);
7262 defValueType
= WXS_ATTR_DEF_VAL_FIXED
;
7266 } else if (! xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
))
7269 xmlSchemaPIllegalAttrErr(pctxt
,
7270 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
7277 * If default and use are both present, use must have
7278 * the actual value optional.
7280 if ((defValueType
== WXS_ATTR_DEF_VAL_DEFAULT
) &&
7281 (occurs
!= XML_SCHEMAS_ATTR_USE_OPTIONAL
)) {
7282 xmlSchemaPSimpleTypeErr(pctxt
,
7283 XML_SCHEMAP_SRC_ATTRIBUTE_2
,
7285 "(optional | prohibited | required)", NULL
,
7286 "The value of the attribute 'use' must be 'optional' "
7287 "if the attribute 'default' is present",
7291 * We want correct attributes.
7293 if (nberrors
!= pctxt
->nberrors
)
7296 xmlSchemaAttributePtr attrDecl
;
7298 /* TODO: move XML_SCHEMAS_QUALIF_ATTR to the parser. */
7299 if ((! hasForm
) && (schema
->flags
& XML_SCHEMAS_QUALIF_ATTR
))
7300 ns
= pctxt
->targetNamespace
;
7302 * 3.2.6 Schema Component Constraint: xsi: Not Allowed
7303 * TODO: Move this to the component layer.
7305 if (xmlStrEqual(ns
, xmlSchemaInstanceNs
)) {
7306 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
7309 "The target namespace must not match '%s'",
7310 xmlSchemaInstanceNs
, NULL
);
7312 attr
= xmlSchemaGetPropNode(node
, "name");
7314 xmlSchemaPMissingAttrErr(pctxt
, XML_SCHEMAP_S4S_ATTR_MISSING
,
7315 NULL
, node
, "name", NULL
);
7318 if (xmlSchemaPValAttrNode(pctxt
, NULL
, attr
,
7319 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME
), &name
) != 0) {
7323 * 3.2.6 Schema Component Constraint: xmlns Not Allowed
7324 * TODO: Move this to the component layer.
7326 if (xmlStrEqual(name
, BAD_CAST
"xmlns")) {
7327 xmlSchemaPSimpleTypeErr(pctxt
,
7328 XML_SCHEMAP_NO_XMLNS
,
7329 NULL
, (xmlNodePtr
) attr
,
7330 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME
), NULL
, NULL
,
7331 "The value of the attribute must not match 'xmlns'",
7335 if (occurs
== XML_SCHEMAS_ATTR_USE_PROHIBITED
)
7336 goto check_children
;
7338 * Create the attribute use component.
7340 use
= xmlSchemaAddAttributeUse(pctxt
, node
);
7343 use
->occurs
= occurs
;
7345 * Create the attribute declaration.
7347 attrDecl
= xmlSchemaAddAttribute(pctxt
, schema
, name
, ns
, node
, 0);
7348 if (attrDecl
== NULL
)
7350 if (tmpName
!= NULL
) {
7351 attrDecl
->typeName
= tmpName
;
7352 attrDecl
->typeNs
= tmpNs
;
7354 use
->attrDecl
= attrDecl
;
7358 if (defValue
!= NULL
) {
7359 attrDecl
->defValue
= defValue
;
7360 if (defValueType
== WXS_ATTR_DEF_VAL_FIXED
)
7361 attrDecl
->flags
|= XML_SCHEMAS_ATTR_FIXED
;
7363 } else if (occurs
!= XML_SCHEMAS_ATTR_USE_PROHIBITED
) {
7364 xmlSchemaQNameRefPtr ref
;
7367 * Create the attribute use component.
7369 use
= xmlSchemaAddAttributeUse(pctxt
, node
);
7373 * We need to resolve the reference at later stage.
7375 WXS_ADD_PENDING(pctxt
, use
);
7376 use
->occurs
= occurs
;
7378 * Create a QName reference to the attribute declaration.
7380 ref
= xmlSchemaNewQNameRef(pctxt
, XML_SCHEMA_TYPE_ATTRIBUTE
,
7385 * Assign the reference. This will be substituted for the
7386 * referenced attribute declaration when the QName is resolved.
7388 use
->attrDecl
= WXS_ATTR_CAST ref
;
7392 if (defValue
!= NULL
)
7393 use
->defValue
= defValue
;
7394 if (defValueType
== WXS_ATTR_DEF_VAL_FIXED
)
7395 use
->flags
|= XML_SCHEMA_ATTR_USE_FIXED
;
7400 * And now for the children...
7402 child
= node
->children
;
7403 if (occurs
== XML_SCHEMAS_ATTR_USE_PROHIBITED
) {
7404 xmlSchemaAttributeUseProhibPtr prohib
;
7406 if (IS_SCHEMA(child
, "annotation")) {
7407 xmlSchemaParseAnnotation(pctxt
, child
, 0);
7408 child
= child
->next
;
7410 if (child
!= NULL
) {
7411 xmlSchemaPContentErr(pctxt
,
7412 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
7413 NULL
, node
, child
, NULL
,
7417 * Check for pointlessness of attribute prohibitions.
7419 if (parentType
== XML_SCHEMA_TYPE_ATTRIBUTEGROUP
) {
7420 xmlSchemaCustomWarning(ACTXT_CAST pctxt
,
7421 XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH
,
7423 "Skipping attribute use prohibition, since it is "
7424 "pointless inside an <attributeGroup>",
7427 } else if (parentType
== XML_SCHEMA_TYPE_EXTENSION
) {
7428 xmlSchemaCustomWarning(ACTXT_CAST pctxt
,
7429 XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH
,
7431 "Skipping attribute use prohibition, since it is "
7432 "pointless when extending a type",
7441 * Check for duplicate attribute prohibitions.
7446 for (i
= 0; i
< uses
->nbItems
; i
++) {
7447 use
= uses
->items
[i
];
7448 if ((use
->type
== XML_SCHEMA_EXTRA_ATTR_USE_PROHIB
) &&
7449 (tmpName
== (WXS_ATTR_PROHIB_CAST use
)->name
) &&
7450 (tmpNs
== (WXS_ATTR_PROHIB_CAST use
)->targetNamespace
))
7452 xmlChar
*str
= NULL
;
7454 xmlSchemaCustomWarning(ACTXT_CAST pctxt
,
7455 XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH
,
7457 "Skipping duplicate attribute use prohibition '%s'",
7458 xmlSchemaFormatQName(&str
, tmpNs
, tmpName
),
7466 * Create the attribute prohibition helper component.
7468 prohib
= xmlSchemaAddAttributeUseProhib(pctxt
);
7471 prohib
->node
= node
;
7472 prohib
->name
= tmpName
;
7473 prohib
->targetNamespace
= tmpNs
;
7476 * We need at least to resolve to the attribute declaration.
7478 WXS_ADD_PENDING(pctxt
, prohib
);
7480 return(WXS_BASIC_CAST prohib
);
7482 if (IS_SCHEMA(child
, "annotation")) {
7484 * TODO: Should this go into the attr decl?
7486 use
->annot
= xmlSchemaParseAnnotation(pctxt
, child
, 1);
7487 child
= child
->next
;
7490 if (child
!= NULL
) {
7491 if (IS_SCHEMA(child
, "simpleType"))
7494 * If ref is present, then all of <simpleType>,
7495 * form and type must be absent.
7497 xmlSchemaPContentErr(pctxt
,
7498 XML_SCHEMAP_SRC_ATTRIBUTE_3_2
,
7499 NULL
, node
, child
, NULL
,
7502 xmlSchemaPContentErr(pctxt
,
7503 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
7504 NULL
, node
, child
, NULL
,
7508 if (IS_SCHEMA(child
, "simpleType")) {
7509 if (WXS_ATTRUSE_DECL(use
)->typeName
!= NULL
) {
7512 * type and <simpleType> must not both be present.
7514 xmlSchemaPContentErr(pctxt
, XML_SCHEMAP_SRC_ATTRIBUTE_4
,
7516 "The attribute 'type' and the <simpleType> child "
7517 "are mutually exclusive", NULL
);
7519 WXS_ATTRUSE_TYPEDEF(use
) =
7520 xmlSchemaParseSimpleType(pctxt
, schema
, child
, 0);
7521 child
= child
->next
;
7524 xmlSchemaPContentErr(pctxt
, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
7525 NULL
, node
, child
, NULL
,
7526 "(annotation?, simpleType?)");
7529 return (WXS_BASIC_CAST use
);
7533 static xmlSchemaAttributePtr
7534 xmlSchemaParseGlobalAttribute(xmlSchemaParserCtxtPtr pctxt
,
7535 xmlSchemaPtr schema
,
7538 const xmlChar
*attrValue
;
7539 xmlSchemaAttributePtr ret
;
7540 xmlNodePtr child
= NULL
;
7544 * Note that the w3c spec assumes the schema to be validated with schema
7545 * for schemas beforehand.
7547 * 3.2.3 Constraints on XML Representations of Attribute Declarations
7549 if ((pctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
7553 * One of ref or name must be present, but not both
7555 attr
= xmlSchemaGetPropNode(node
, "name");
7557 xmlSchemaPMissingAttrErr(pctxt
, XML_SCHEMAP_S4S_ATTR_MISSING
,
7558 NULL
, node
, "name", NULL
);
7561 if (xmlSchemaPValAttrNode(pctxt
, NULL
, attr
,
7562 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME
), &attrValue
) != 0) {
7566 * 3.2.6 Schema Component Constraint: xmlns Not Allowed
7567 * TODO: Move this to the component layer.
7569 if (xmlStrEqual(attrValue
, BAD_CAST
"xmlns")) {
7570 xmlSchemaPSimpleTypeErr(pctxt
,
7571 XML_SCHEMAP_NO_XMLNS
,
7572 NULL
, (xmlNodePtr
) attr
,
7573 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME
), NULL
, NULL
,
7574 "The value of the attribute must not match 'xmlns'",
7579 * 3.2.6 Schema Component Constraint: xsi: Not Allowed
7580 * TODO: Move this to the component layer.
7581 * Or better leave it here and add it to the component layer
7582 * if we have a schema construction API.
7584 if (xmlStrEqual(pctxt
->targetNamespace
, xmlSchemaInstanceNs
)) {
7585 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
7586 XML_SCHEMAP_NO_XSI
, node
, NULL
,
7587 "The target namespace must not match '%s'",
7588 xmlSchemaInstanceNs
, NULL
);
7591 ret
= xmlSchemaAddAttribute(pctxt
, schema
, attrValue
,
7592 pctxt
->targetNamespace
, node
, 1);
7595 ret
->flags
|= XML_SCHEMAS_ATTR_GLOBAL
;
7598 * Check for illegal attributes.
7600 attr
= node
->properties
;
7601 while (attr
!= NULL
) {
7602 if (attr
->ns
== NULL
) {
7603 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"id")) &&
7604 (!xmlStrEqual(attr
->name
, BAD_CAST
"default")) &&
7605 (!xmlStrEqual(attr
->name
, BAD_CAST
"fixed")) &&
7606 (!xmlStrEqual(attr
->name
, BAD_CAST
"name")) &&
7607 (!xmlStrEqual(attr
->name
, BAD_CAST
"type")))
7609 xmlSchemaPIllegalAttrErr(pctxt
,
7610 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
7612 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
7613 xmlSchemaPIllegalAttrErr(pctxt
,
7614 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
7618 xmlSchemaPValAttrQName(pctxt
, schema
, NULL
,
7619 node
, "type", &ret
->typeNs
, &ret
->typeName
);
7621 xmlSchemaPValAttrID(pctxt
, node
, BAD_CAST
"id");
7623 * Attribute "fixed".
7625 ret
->defValue
= xmlSchemaGetProp(pctxt
, node
, "fixed");
7626 if (ret
->defValue
!= NULL
)
7627 ret
->flags
|= XML_SCHEMAS_ATTR_FIXED
;
7629 * Attribute "default".
7631 attr
= xmlSchemaGetPropNode(node
, "default");
7635 * default and fixed must not both be present.
7637 if (ret
->flags
& XML_SCHEMAS_ATTR_FIXED
) {
7638 xmlSchemaPMutualExclAttrErr(pctxt
, XML_SCHEMAP_SRC_ATTRIBUTE_1
,
7639 WXS_BASIC_CAST ret
, attr
, "default", "fixed");
7641 ret
->defValue
= xmlSchemaGetNodeContent(pctxt
, (xmlNodePtr
) attr
);
7644 * And now for the children...
7646 child
= node
->children
;
7647 if (IS_SCHEMA(child
, "annotation")) {
7648 ret
->annot
= xmlSchemaParseAnnotation(pctxt
, child
, 1);
7649 child
= child
->next
;
7651 if (IS_SCHEMA(child
, "simpleType")) {
7652 if (ret
->typeName
!= NULL
) {
7655 * type and <simpleType> must not both be present.
7657 xmlSchemaPContentErr(pctxt
, XML_SCHEMAP_SRC_ATTRIBUTE_4
,
7659 "The attribute 'type' and the <simpleType> child "
7660 "are mutually exclusive", NULL
);
7662 ret
->subtypes
= xmlSchemaParseSimpleType(pctxt
, schema
, child
, 0);
7663 child
= child
->next
;
7666 xmlSchemaPContentErr(pctxt
, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
7667 NULL
, node
, child
, NULL
,
7668 "(annotation?, simpleType?)");
7674 * xmlSchemaParseAttributeGroupRef:
7675 * @ctxt: a schema validation context
7676 * @schema: the schema being built
7677 * @node: a subtree containing XML Schema informations
7679 * Parse an attribute group definition reference.
7680 * Note that a reference to an attribute group does not
7681 * correspond to any component at all.
7682 * *WARNING* this interface is highly subject to change
7684 * Returns the attribute group or NULL in case of error.
7686 static xmlSchemaQNameRefPtr
7687 xmlSchemaParseAttributeGroupRef(xmlSchemaParserCtxtPtr pctxt
,
7688 xmlSchemaPtr schema
,
7691 xmlSchemaQNameRefPtr ret
;
7692 xmlNodePtr child
= NULL
;
7694 const xmlChar
*refNs
= NULL
, *ref
= NULL
;
7696 if ((pctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
7699 attr
= xmlSchemaGetPropNode(node
, "ref");
7701 xmlSchemaPMissingAttrErr(pctxt
,
7702 XML_SCHEMAP_S4S_ATTR_MISSING
,
7703 NULL
, node
, "ref", NULL
);
7706 xmlSchemaPValAttrNodeQName(pctxt
, schema
,
7707 NULL
, attr
, &refNs
, &ref
);
7708 if (xmlSchemaCheckReference(pctxt
, schema
, node
, attr
, refNs
) != 0)
7712 * Check for illegal attributes.
7714 attr
= node
->properties
;
7715 while (attr
!= NULL
) {
7716 if (attr
->ns
== NULL
) {
7717 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"ref")) &&
7718 (!xmlStrEqual(attr
->name
, BAD_CAST
"id")))
7720 xmlSchemaPIllegalAttrErr(pctxt
,
7721 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
7723 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
7724 xmlSchemaPIllegalAttrErr(pctxt
,
7725 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
7730 xmlSchemaPValAttrID(pctxt
, node
, BAD_CAST
"id");
7733 * And now for the children...
7735 child
= node
->children
;
7736 if (IS_SCHEMA(child
, "annotation")) {
7738 * TODO: We do not have a place to store the annotation, do we?
7740 xmlSchemaParseAnnotation(pctxt
, child
, 0);
7741 child
= child
->next
;
7743 if (child
!= NULL
) {
7744 xmlSchemaPContentErr(pctxt
,
7745 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
7746 NULL
, node
, child
, NULL
,
7751 * Handle attribute group redefinitions.
7753 if (pctxt
->isRedefine
&& pctxt
->redef
&&
7754 (pctxt
->redef
->item
->type
==
7755 XML_SCHEMA_TYPE_ATTRIBUTEGROUP
) &&
7756 (ref
== pctxt
->redef
->refName
) &&
7757 (refNs
== pctxt
->redef
->refTargetNs
))
7760 * SPEC src-redefine:
7761 * (7.1) "If it has an <attributeGroup> among its contents
7762 * the `actual value` of whose ref [attribute] is the same
7763 * as the `actual value` of its own name attribute plus
7764 * target namespace, then it must have exactly one such group."
7766 if (pctxt
->redefCounter
!= 0) {
7767 xmlChar
*str
= NULL
;
7769 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
7770 XML_SCHEMAP_SRC_REDEFINE
, node
, NULL
,
7771 "The redefining attribute group definition "
7772 "'%s' must not contain more than one "
7773 "reference to the redefined definition",
7774 xmlSchemaFormatQName(&str
, refNs
, ref
), NULL
);
7778 pctxt
->redefCounter
++;
7780 * URGENT TODO: How to ensure that the reference will not be
7781 * handled by the normal component resolution mechanism?
7783 ret
= xmlSchemaNewQNameRef(pctxt
,
7784 XML_SCHEMA_TYPE_ATTRIBUTEGROUP
, ref
, refNs
);
7788 pctxt
->redef
->reference
= WXS_BASIC_CAST ret
;
7791 * Create a QName-reference helper component. We will substitute this
7792 * component for the attribute uses of the referenced attribute group
7795 ret
= xmlSchemaNewQNameRef(pctxt
,
7796 XML_SCHEMA_TYPE_ATTRIBUTEGROUP
, ref
, refNs
);
7800 /* Add to pending items, to be able to resolve the reference. */
7801 WXS_ADD_PENDING(pctxt
, ret
);
7807 * xmlSchemaParseAttributeGroupDefinition:
7808 * @pctxt: a schema validation context
7809 * @schema: the schema being built
7810 * @node: a subtree containing XML Schema informations
7812 * parse a XML schema Attribute Group declaration
7813 * *WARNING* this interface is highly subject to change
7815 * Returns the attribute group definition or NULL in case of error.
7817 static xmlSchemaAttributeGroupPtr
7818 xmlSchemaParseAttributeGroupDefinition(xmlSchemaParserCtxtPtr pctxt
,
7819 xmlSchemaPtr schema
,
7822 const xmlChar
*name
;
7823 xmlSchemaAttributeGroupPtr ret
;
7824 xmlNodePtr child
= NULL
;
7828 if ((pctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
7831 attr
= xmlSchemaGetPropNode(node
, "name");
7833 xmlSchemaPMissingAttrErr(pctxt
,
7834 XML_SCHEMAP_S4S_ATTR_MISSING
,
7835 NULL
, node
, "name", NULL
);
7839 * The name is crucial, exit if invalid.
7841 if (xmlSchemaPValAttrNode(pctxt
,
7843 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME
), &name
) != 0) {
7846 ret
= xmlSchemaAddAttributeGroupDefinition(pctxt
, schema
,
7847 name
, pctxt
->targetNamespace
, node
);
7851 * Check for illegal attributes.
7853 attr
= node
->properties
;
7854 while (attr
!= NULL
) {
7855 if (attr
->ns
== NULL
) {
7856 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"name")) &&
7857 (!xmlStrEqual(attr
->name
, BAD_CAST
"id")))
7859 xmlSchemaPIllegalAttrErr(pctxt
,
7860 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
7862 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
7863 xmlSchemaPIllegalAttrErr(pctxt
,
7864 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
7869 xmlSchemaPValAttrID(pctxt
, node
, BAD_CAST
"id");
7871 * And now for the children...
7873 child
= node
->children
;
7874 if (IS_SCHEMA(child
, "annotation")) {
7875 ret
->annot
= xmlSchemaParseAnnotation(pctxt
, child
, 1);
7876 child
= child
->next
;
7879 * Parse contained attribute decls/refs.
7881 if (xmlSchemaParseLocalAttributes(pctxt
, schema
, &child
,
7882 (xmlSchemaItemListPtr
*) &(ret
->attrUses
),
7883 XML_SCHEMA_TYPE_ATTRIBUTEGROUP
, &hasRefs
) == -1)
7886 ret
->flags
|= XML_SCHEMAS_ATTRGROUP_HAS_REFS
;
7888 * Parse the attribute wildcard.
7890 if (IS_SCHEMA(child
, "anyAttribute")) {
7891 ret
->attributeWildcard
= xmlSchemaParseAnyAttribute(pctxt
,
7893 child
= child
->next
;
7895 if (child
!= NULL
) {
7896 xmlSchemaPContentErr(pctxt
,
7897 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
7898 NULL
, node
, child
, NULL
,
7899 "(annotation?, ((attribute | attributeGroup)*, anyAttribute?))");
7905 * xmlSchemaPValAttrFormDefault:
7907 * @flags: the flags to be modified
7908 * @flagQualified: the specific flag for "qualified"
7910 * Returns 0 if the value is valid, 1 otherwise.
7913 xmlSchemaPValAttrFormDefault(const xmlChar
*value
,
7917 if (xmlStrEqual(value
, BAD_CAST
"qualified")) {
7918 if ((*flags
& flagQualified
) == 0)
7919 *flags
|= flagQualified
;
7920 } else if (!xmlStrEqual(value
, BAD_CAST
"unqualified"))
7927 * xmlSchemaPValAttrBlockFinal:
7929 * @flags: the flags to be modified
7930 * @flagAll: the specific flag for "#all"
7931 * @flagExtension: the specific flag for "extension"
7932 * @flagRestriction: the specific flag for "restriction"
7933 * @flagSubstitution: the specific flag for "substitution"
7934 * @flagList: the specific flag for "list"
7935 * @flagUnion: the specific flag for "union"
7937 * Validates the value of the attribute "final" and "block". The value
7938 * is converted into the specified flag values and returned in @flags.
7940 * Returns 0 if the value is valid, 1 otherwise.
7944 xmlSchemaPValAttrBlockFinal(const xmlChar
*value
,
7948 int flagRestriction
,
7949 int flagSubstitution
,
7956 * TODO: This does not check for dublicate entries.
7958 if ((flags
== NULL
) || (value
== NULL
))
7962 if (xmlStrEqual(value
, BAD_CAST
"#all")) {
7966 if (flagExtension
!= -1)
7967 *flags
|= flagExtension
;
7968 if (flagRestriction
!= -1)
7969 *flags
|= flagRestriction
;
7970 if (flagSubstitution
!= -1)
7971 *flags
|= flagSubstitution
;
7974 if (flagUnion
!= -1)
7975 *flags
|= flagUnion
;
7978 const xmlChar
*end
, *cur
= value
;
7982 while (IS_BLANK_CH(*cur
))
7985 while ((*end
!= 0) && (!(IS_BLANK_CH(*end
))))
7989 item
= xmlStrndup(cur
, end
- cur
);
7990 if (xmlStrEqual(item
, BAD_CAST
"extension")) {
7991 if (flagExtension
!= -1) {
7992 if ((*flags
& flagExtension
) == 0)
7993 *flags
|= flagExtension
;
7996 } else if (xmlStrEqual(item
, BAD_CAST
"restriction")) {
7997 if (flagRestriction
!= -1) {
7998 if ((*flags
& flagRestriction
) == 0)
7999 *flags
|= flagRestriction
;
8002 } else if (xmlStrEqual(item
, BAD_CAST
"substitution")) {
8003 if (flagSubstitution
!= -1) {
8004 if ((*flags
& flagSubstitution
) == 0)
8005 *flags
|= flagSubstitution
;
8008 } else if (xmlStrEqual(item
, BAD_CAST
"list")) {
8009 if (flagList
!= -1) {
8010 if ((*flags
& flagList
) == 0)
8014 } else if (xmlStrEqual(item
, BAD_CAST
"union")) {
8015 if (flagUnion
!= -1) {
8016 if ((*flags
& flagUnion
) == 0)
8017 *flags
|= flagUnion
;
8025 } while ((ret
== 0) && (*cur
!= 0));
8032 xmlSchemaCheckCSelectorXPath(xmlSchemaParserCtxtPtr ctxt
,
8033 xmlSchemaIDCPtr idc
,
8034 xmlSchemaIDCSelectPtr selector
,
8042 * Schema Component Constraint: Selector Value OK
8044 * TODO: 1 The {selector} must be a valid XPath expression, as defined
8047 if (selector
== NULL
) {
8048 xmlSchemaPErr(ctxt
, idc
->node
,
8049 XML_SCHEMAP_INTERNAL
,
8050 "Internal error: xmlSchemaCheckCSelectorXPath, "
8051 "the selector is not specified.\n", NULL
, NULL
);
8057 node
= (xmlNodePtr
) attr
;
8058 if (selector
->xpath
== NULL
) {
8059 xmlSchemaPCustomErr(ctxt
,
8060 /* TODO: Adjust error code. */
8061 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
8063 "The XPath expression of the selector is not valid", NULL
);
8064 return (XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
);
8066 const xmlChar
**nsArray
= NULL
;
8067 xmlNsPtr
*nsList
= NULL
;
8069 * Compile the XPath expression.
8072 * TODO: We need the array of in-scope namespaces for compilation.
8073 * TODO: Call xmlPatterncompile with different options for selector/
8079 nsList
= xmlGetNsList(attr
->doc
, attr
->parent
);
8081 * Build an array of prefixes and namespaces.
8083 if (nsList
!= NULL
) {
8086 for (i
= 0; nsList
[i
] != NULL
; i
++)
8089 nsArray
= (const xmlChar
**) xmlMalloc(
8090 (count
* 2 + 1) * sizeof(const xmlChar
*));
8091 if (nsArray
== NULL
) {
8092 xmlSchemaPErrMemory(ctxt
, "allocating a namespace array",
8097 for (i
= 0; i
< count
; i
++) {
8098 nsArray
[2 * i
] = nsList
[i
]->href
;
8099 nsArray
[2 * i
+ 1] = nsList
[i
]->prefix
;
8101 nsArray
[count
* 2] = NULL
;
8105 * TODO: Differentiate between "selector" and "field".
8108 selector
->xpathComp
= (void *) xmlPatterncompile(selector
->xpath
,
8109 NULL
, XML_PATTERN_XSFIELD
, nsArray
);
8111 selector
->xpathComp
= (void *) xmlPatterncompile(selector
->xpath
,
8112 NULL
, XML_PATTERN_XSSEL
, nsArray
);
8113 if (nsArray
!= NULL
)
8114 xmlFree((xmlChar
**) nsArray
);
8116 if (selector
->xpathComp
== NULL
) {
8117 xmlSchemaPCustomErr(ctxt
,
8118 /* TODO: Adjust error code? */
8119 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
8121 "The XPath expression '%s' could not be "
8122 "compiled", selector
->xpath
);
8123 return (XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
);
8129 #define ADD_ANNOTATION(annot) \
8130 xmlSchemaAnnotPtr cur = item->annot; \
8131 if (item->annot == NULL) { \
8132 item->annot = annot; \
8135 cur = item->annot; \
8136 if (cur->next != NULL) { \
8142 * xmlSchemaAssignAnnotation:
8143 * @item: the schema component
8144 * @annot: the annotation
8146 * Adds the annotation to the given schema component.
8148 * Returns the given annotaion.
8150 static xmlSchemaAnnotPtr
8151 xmlSchemaAddAnnotation(xmlSchemaAnnotItemPtr annItem
,
8152 xmlSchemaAnnotPtr annot
)
8154 if ((annItem
== NULL
) || (annot
== NULL
))
8156 switch (annItem
->type
) {
8157 case XML_SCHEMA_TYPE_ELEMENT
: {
8158 xmlSchemaElementPtr item
= (xmlSchemaElementPtr
) annItem
;
8159 ADD_ANNOTATION(annot
)
8162 case XML_SCHEMA_TYPE_ATTRIBUTE
: {
8163 xmlSchemaAttributePtr item
= (xmlSchemaAttributePtr
) annItem
;
8164 ADD_ANNOTATION(annot
)
8167 case XML_SCHEMA_TYPE_ANY_ATTRIBUTE
:
8168 case XML_SCHEMA_TYPE_ANY
: {
8169 xmlSchemaWildcardPtr item
= (xmlSchemaWildcardPtr
) annItem
;
8170 ADD_ANNOTATION(annot
)
8173 case XML_SCHEMA_TYPE_PARTICLE
:
8174 case XML_SCHEMA_TYPE_IDC_KEY
:
8175 case XML_SCHEMA_TYPE_IDC_KEYREF
:
8176 case XML_SCHEMA_TYPE_IDC_UNIQUE
: {
8177 xmlSchemaAnnotItemPtr item
= (xmlSchemaAnnotItemPtr
) annItem
;
8178 ADD_ANNOTATION(annot
)
8181 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP
: {
8182 xmlSchemaAttributeGroupPtr item
=
8183 (xmlSchemaAttributeGroupPtr
) annItem
;
8184 ADD_ANNOTATION(annot
)
8187 case XML_SCHEMA_TYPE_NOTATION
: {
8188 xmlSchemaNotationPtr item
= (xmlSchemaNotationPtr
) annItem
;
8189 ADD_ANNOTATION(annot
)
8192 case XML_SCHEMA_FACET_MININCLUSIVE
:
8193 case XML_SCHEMA_FACET_MINEXCLUSIVE
:
8194 case XML_SCHEMA_FACET_MAXINCLUSIVE
:
8195 case XML_SCHEMA_FACET_MAXEXCLUSIVE
:
8196 case XML_SCHEMA_FACET_TOTALDIGITS
:
8197 case XML_SCHEMA_FACET_FRACTIONDIGITS
:
8198 case XML_SCHEMA_FACET_PATTERN
:
8199 case XML_SCHEMA_FACET_ENUMERATION
:
8200 case XML_SCHEMA_FACET_WHITESPACE
:
8201 case XML_SCHEMA_FACET_LENGTH
:
8202 case XML_SCHEMA_FACET_MAXLENGTH
:
8203 case XML_SCHEMA_FACET_MINLENGTH
: {
8204 xmlSchemaFacetPtr item
= (xmlSchemaFacetPtr
) annItem
;
8205 ADD_ANNOTATION(annot
)
8208 case XML_SCHEMA_TYPE_SIMPLE
:
8209 case XML_SCHEMA_TYPE_COMPLEX
: {
8210 xmlSchemaTypePtr item
= (xmlSchemaTypePtr
) annItem
;
8211 ADD_ANNOTATION(annot
)
8214 case XML_SCHEMA_TYPE_GROUP
: {
8215 xmlSchemaModelGroupDefPtr item
= (xmlSchemaModelGroupDefPtr
) annItem
;
8216 ADD_ANNOTATION(annot
)
8219 case XML_SCHEMA_TYPE_SEQUENCE
:
8220 case XML_SCHEMA_TYPE_CHOICE
:
8221 case XML_SCHEMA_TYPE_ALL
: {
8222 xmlSchemaModelGroupPtr item
= (xmlSchemaModelGroupPtr
) annItem
;
8223 ADD_ANNOTATION(annot
)
8227 xmlSchemaPCustomErr(NULL
,
8228 XML_SCHEMAP_INTERNAL
,
8230 "Internal error: xmlSchemaAddAnnotation, "
8231 "The item is not a annotated schema component", NULL
);
8238 * xmlSchemaParseIDCSelectorAndField:
8239 * @ctxt: a schema validation context
8240 * @schema: the schema being built
8241 * @node: a subtree containing XML Schema informations
8243 * Parses a XML Schema identity-contraint definition's
8244 * <selector> and <field> elements.
8246 * Returns the parsed identity-constraint definition.
8248 static xmlSchemaIDCSelectPtr
8249 xmlSchemaParseIDCSelectorAndField(xmlSchemaParserCtxtPtr ctxt
,
8250 xmlSchemaIDCPtr idc
,
8254 xmlSchemaIDCSelectPtr item
;
8255 xmlNodePtr child
= NULL
;
8259 * Check for illegal attributes.
8261 attr
= node
->properties
;
8262 while (attr
!= NULL
) {
8263 if (attr
->ns
== NULL
) {
8264 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"id")) &&
8265 (!xmlStrEqual(attr
->name
, BAD_CAST
"xpath"))) {
8266 xmlSchemaPIllegalAttrErr(ctxt
,
8267 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
8269 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
8270 xmlSchemaPIllegalAttrErr(ctxt
,
8271 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
8278 item
= (xmlSchemaIDCSelectPtr
) xmlMalloc(sizeof(xmlSchemaIDCSelect
));
8280 xmlSchemaPErrMemory(ctxt
,
8281 "allocating a 'selector' of an identity-constraint definition",
8285 memset(item
, 0, sizeof(xmlSchemaIDCSelect
));
8287 * Attribute "xpath" (mandatory).
8289 attr
= xmlSchemaGetPropNode(node
, "xpath");
8291 xmlSchemaPMissingAttrErr(ctxt
,
8292 XML_SCHEMAP_S4S_ATTR_MISSING
,
8296 item
->xpath
= xmlSchemaGetNodeContent(ctxt
, (xmlNodePtr
) attr
);
8298 * URGENT TODO: "field"s have an other syntax than "selector"s.
8301 if (xmlSchemaCheckCSelectorXPath(ctxt
, idc
, item
, attr
,
8305 XML_SCHEMAP_INTERNAL
,
8306 "Internal error: xmlSchemaParseIDCSelectorAndField, "
8307 "validating the XPath expression of a IDC selector.\n",
8312 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
8314 * And now for the children...
8316 child
= node
->children
;
8317 if (IS_SCHEMA(child
, "annotation")) {
8319 * Add the annotation to the parent IDC.
8321 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr
) idc
,
8322 xmlSchemaParseAnnotation(ctxt
, child
, 1));
8323 child
= child
->next
;
8325 if (child
!= NULL
) {
8326 xmlSchemaPContentErr(ctxt
,
8327 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
8329 NULL
, "(annotation?)");
8336 * xmlSchemaParseIDC:
8337 * @ctxt: a schema validation context
8338 * @schema: the schema being built
8339 * @node: a subtree containing XML Schema informations
8341 * Parses a XML Schema identity-contraint definition.
8343 * Returns the parsed identity-constraint definition.
8345 static xmlSchemaIDCPtr
8346 xmlSchemaParseIDC(xmlSchemaParserCtxtPtr ctxt
,
8347 xmlSchemaPtr schema
,
8349 xmlSchemaTypeType idcCategory
,
8350 const xmlChar
*targetNamespace
)
8352 xmlSchemaIDCPtr item
= NULL
;
8353 xmlNodePtr child
= NULL
;
8355 const xmlChar
*name
= NULL
;
8356 xmlSchemaIDCSelectPtr field
= NULL
, lastField
= NULL
;
8359 * Check for illegal attributes.
8361 attr
= node
->properties
;
8362 while (attr
!= NULL
) {
8363 if (attr
->ns
== NULL
) {
8364 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"id")) &&
8365 (!xmlStrEqual(attr
->name
, BAD_CAST
"name")) &&
8366 ((idcCategory
!= XML_SCHEMA_TYPE_IDC_KEYREF
) ||
8367 (!xmlStrEqual(attr
->name
, BAD_CAST
"refer")))) {
8368 xmlSchemaPIllegalAttrErr(ctxt
,
8369 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
8371 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
8372 xmlSchemaPIllegalAttrErr(ctxt
,
8373 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
8378 * Attribute "name" (mandatory).
8380 attr
= xmlSchemaGetPropNode(node
, "name");
8382 xmlSchemaPMissingAttrErr(ctxt
,
8383 XML_SCHEMAP_S4S_ATTR_MISSING
,
8387 } else if (xmlSchemaPValAttrNode(ctxt
,
8389 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME
), &name
) != 0) {
8392 /* Create the component. */
8393 item
= xmlSchemaAddIDC(ctxt
, schema
, name
, targetNamespace
,
8398 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
8399 if (idcCategory
== XML_SCHEMA_TYPE_IDC_KEYREF
) {
8401 * Attribute "refer" (mandatory).
8403 attr
= xmlSchemaGetPropNode(node
, "refer");
8405 xmlSchemaPMissingAttrErr(ctxt
,
8406 XML_SCHEMAP_S4S_ATTR_MISSING
,
8411 * Create a reference item.
8413 item
->ref
= xmlSchemaNewQNameRef(ctxt
, XML_SCHEMA_TYPE_IDC_KEY
,
8415 if (item
->ref
== NULL
)
8417 xmlSchemaPValAttrNodeQName(ctxt
, schema
,
8419 &(item
->ref
->targetNamespace
),
8420 &(item
->ref
->name
));
8421 xmlSchemaCheckReference(ctxt
, schema
, node
, attr
,
8422 item
->ref
->targetNamespace
);
8426 * And now for the children...
8428 child
= node
->children
;
8429 if (IS_SCHEMA(child
, "annotation")) {
8430 item
->annot
= xmlSchemaParseAnnotation(ctxt
, child
, 1);
8431 child
= child
->next
;
8433 if (child
== NULL
) {
8434 xmlSchemaPContentErr(ctxt
,
8435 XML_SCHEMAP_S4S_ELEM_MISSING
,
8437 "A child element is missing",
8438 "(annotation?, (selector, field+))");
8441 * Child element <selector>.
8443 if (IS_SCHEMA(child
, "selector")) {
8444 item
->selector
= xmlSchemaParseIDCSelectorAndField(ctxt
,
8446 child
= child
->next
;
8448 * Child elements <field>.
8450 if (IS_SCHEMA(child
, "field")) {
8452 field
= xmlSchemaParseIDCSelectorAndField(ctxt
,
8454 if (field
!= NULL
) {
8455 field
->index
= item
->nbFields
;
8457 if (lastField
!= NULL
)
8458 lastField
->next
= field
;
8460 item
->fields
= field
;
8463 child
= child
->next
;
8464 } while (IS_SCHEMA(child
, "field"));
8466 xmlSchemaPContentErr(ctxt
,
8467 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
8469 NULL
, "(annotation?, (selector, field+))");
8472 if (child
!= NULL
) {
8473 xmlSchemaPContentErr(ctxt
,
8474 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
8476 NULL
, "(annotation?, (selector, field+))");
8483 * xmlSchemaParseElement:
8484 * @ctxt: a schema validation context
8485 * @schema: the schema being built
8486 * @node: a subtree containing XML Schema informations
8487 * @topLevel: indicates if this is global declaration
8489 * Parses a XML schema element declaration.
8490 * *WARNING* this interface is highly subject to change
8492 * Returns the element declaration or a particle; NULL in case
8493 * of an error or if the particle has minOccurs==maxOccurs==0.
8495 static xmlSchemaBasicItemPtr
8496 xmlSchemaParseElement(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
8497 xmlNodePtr node
, int *isElemRef
, int topLevel
)
8499 xmlSchemaElementPtr decl
= NULL
;
8500 xmlSchemaParticlePtr particle
= NULL
;
8501 xmlSchemaAnnotPtr annot
= NULL
;
8502 xmlNodePtr child
= NULL
;
8503 xmlAttrPtr attr
, nameAttr
;
8504 int min
, max
, isRef
= 0;
8505 xmlChar
*des
= NULL
;
8507 /* 3.3.3 Constraints on XML Representations of Element Declarations */
8508 /* TODO: Complete implementation of 3.3.6 */
8510 if ((ctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
8513 if (isElemRef
!= NULL
)
8516 * If we get a "ref" attribute on a local <element> we will assume it's
8517 * a reference - even if there's a "name" attribute; this seems to be more
8520 nameAttr
= xmlSchemaGetPropNode(node
, "name");
8521 attr
= xmlSchemaGetPropNode(node
, "ref");
8522 if ((topLevel
) || (attr
== NULL
)) {
8523 if (nameAttr
== NULL
) {
8524 xmlSchemaPMissingAttrErr(ctxt
,
8525 XML_SCHEMAP_S4S_ATTR_MISSING
,
8526 NULL
, node
, "name", NULL
);
8532 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
8533 child
= node
->children
;
8534 if (IS_SCHEMA(child
, "annotation")) {
8535 annot
= xmlSchemaParseAnnotation(ctxt
, child
, 1);
8536 child
= child
->next
;
8539 * Skip particle part if a global declaration.
8542 goto declaration_part
;
8544 * The particle part ==================================================
8546 min
= xmlGetMinOccurs(ctxt
, node
, 0, -1, 1, "xs:nonNegativeInteger");
8547 max
= xmlGetMaxOccurs(ctxt
, node
, 0, UNBOUNDED
, 1, "(xs:nonNegativeInteger | unbounded)");
8548 xmlSchemaPCheckParticleCorrect_2(ctxt
, NULL
, node
, min
, max
);
8549 particle
= xmlSchemaAddParticle(ctxt
, node
, min
, max
);
8550 if (particle
== NULL
)
8553 /* ret->flags |= XML_SCHEMAS_ELEM_REF; */
8556 const xmlChar
*refNs
= NULL
, *ref
= NULL
;
8557 xmlSchemaQNameRefPtr refer
= NULL
;
8559 * The reference part =============================================
8561 if (isElemRef
!= NULL
)
8564 xmlSchemaPValAttrNodeQName(ctxt
, schema
,
8565 NULL
, attr
, &refNs
, &ref
);
8566 xmlSchemaCheckReference(ctxt
, schema
, node
, attr
, refNs
);
8568 * SPEC (3.3.3 : 2.1) "One of ref or name must be present, but not both"
8570 if (nameAttr
!= NULL
) {
8571 xmlSchemaPMutualExclAttrErr(ctxt
,
8572 XML_SCHEMAP_SRC_ELEMENT_2_1
, NULL
, nameAttr
, "ref", "name");
8575 * Check for illegal attributes.
8577 attr
= node
->properties
;
8578 while (attr
!= NULL
) {
8579 if (attr
->ns
== NULL
) {
8580 if (xmlStrEqual(attr
->name
, BAD_CAST
"ref") ||
8581 xmlStrEqual(attr
->name
, BAD_CAST
"name") ||
8582 xmlStrEqual(attr
->name
, BAD_CAST
"id") ||
8583 xmlStrEqual(attr
->name
, BAD_CAST
"maxOccurs") ||
8584 xmlStrEqual(attr
->name
, BAD_CAST
"minOccurs"))
8589 /* SPEC (3.3.3 : 2.2) */
8590 xmlSchemaPCustomAttrErr(ctxt
,
8591 XML_SCHEMAP_SRC_ELEMENT_2_2
,
8593 "Only the attributes 'minOccurs', 'maxOccurs' and "
8594 "'id' are allowed in addition to 'ref'");
8597 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
8598 xmlSchemaPIllegalAttrErr(ctxt
,
8599 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
8604 * No children except <annotation> expected.
8606 if (child
!= NULL
) {
8607 xmlSchemaPContentErr(ctxt
, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
8608 NULL
, node
, child
, NULL
, "(annotation?)");
8610 if ((min
== 0) && (max
== 0))
8613 * Create the reference item and attach it to the particle.
8615 refer
= xmlSchemaNewQNameRef(ctxt
, XML_SCHEMA_TYPE_ELEMENT
,
8619 particle
->children
= (xmlSchemaTreeItemPtr
) refer
;
8620 particle
->annot
= annot
;
8622 * Add the particle to pending components, since the reference
8623 * need to be resolved.
8625 WXS_ADD_PENDING(ctxt
, particle
);
8626 return ((xmlSchemaBasicItemPtr
) particle
);
8629 * The declaration part ===============================================
8633 const xmlChar
*ns
= NULL
, *fixed
, *name
, *attrValue
;
8634 xmlSchemaIDCPtr curIDC
= NULL
, lastIDC
= NULL
;
8636 if (xmlSchemaPValAttrNode(ctxt
, NULL
, nameAttr
,
8637 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME
), &name
) != 0)
8640 * Evaluate the target namespace.
8643 ns
= ctxt
->targetNamespace
;
8645 attr
= xmlSchemaGetPropNode(node
, "form");
8647 attrValue
= xmlSchemaGetNodeContent(ctxt
, (xmlNodePtr
) attr
);
8648 if (xmlStrEqual(attrValue
, BAD_CAST
"qualified")) {
8649 ns
= ctxt
->targetNamespace
;
8650 } else if (!xmlStrEqual(attrValue
, BAD_CAST
"unqualified")) {
8651 xmlSchemaPSimpleTypeErr(ctxt
,
8652 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
8653 NULL
, (xmlNodePtr
) attr
,
8654 NULL
, "(qualified | unqualified)",
8655 attrValue
, NULL
, NULL
, NULL
);
8657 } else if (schema
->flags
& XML_SCHEMAS_QUALIF_ELEM
)
8658 ns
= ctxt
->targetNamespace
;
8660 decl
= xmlSchemaAddElement(ctxt
, name
, ns
, node
, topLevel
);
8665 * Check for illegal attributes.
8667 attr
= node
->properties
;
8668 while (attr
!= NULL
) {
8669 if (attr
->ns
== NULL
) {
8670 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"name")) &&
8671 (!xmlStrEqual(attr
->name
, BAD_CAST
"type")) &&
8672 (!xmlStrEqual(attr
->name
, BAD_CAST
"id")) &&
8673 (!xmlStrEqual(attr
->name
, BAD_CAST
"default")) &&
8674 (!xmlStrEqual(attr
->name
, BAD_CAST
"fixed")) &&
8675 (!xmlStrEqual(attr
->name
, BAD_CAST
"block")) &&
8676 (!xmlStrEqual(attr
->name
, BAD_CAST
"nillable")))
8678 if (topLevel
== 0) {
8679 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"maxOccurs")) &&
8680 (!xmlStrEqual(attr
->name
, BAD_CAST
"minOccurs")) &&
8681 (!xmlStrEqual(attr
->name
, BAD_CAST
"form")))
8683 xmlSchemaPIllegalAttrErr(ctxt
,
8684 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
8686 } else if ((!xmlStrEqual(attr
->name
, BAD_CAST
"final")) &&
8687 (!xmlStrEqual(attr
->name
, BAD_CAST
"abstract")) &&
8688 (!xmlStrEqual(attr
->name
, BAD_CAST
"substitutionGroup"))) {
8690 xmlSchemaPIllegalAttrErr(ctxt
,
8691 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
8694 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
8696 xmlSchemaPIllegalAttrErr(ctxt
,
8697 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
8702 * Extract/validate attributes.
8706 * Process top attributes of global element declarations here.
8708 decl
->flags
|= XML_SCHEMAS_ELEM_GLOBAL
;
8709 decl
->flags
|= XML_SCHEMAS_ELEM_TOPLEVEL
;
8710 xmlSchemaPValAttrQName(ctxt
, schema
,
8711 NULL
, node
, "substitutionGroup",
8712 &(decl
->substGroupNs
), &(decl
->substGroup
));
8713 if (xmlGetBooleanProp(ctxt
, node
, "abstract", 0))
8714 decl
->flags
|= XML_SCHEMAS_ELEM_ABSTRACT
;
8716 * Attribute "final".
8718 attr
= xmlSchemaGetPropNode(node
, "final");
8720 if (schema
->flags
& XML_SCHEMAS_FINAL_DEFAULT_EXTENSION
)
8721 decl
->flags
|= XML_SCHEMAS_ELEM_FINAL_EXTENSION
;
8722 if (schema
->flags
& XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION
)
8723 decl
->flags
|= XML_SCHEMAS_ELEM_FINAL_RESTRICTION
;
8725 attrValue
= xmlSchemaGetNodeContent(ctxt
, (xmlNodePtr
) attr
);
8726 if (xmlSchemaPValAttrBlockFinal(attrValue
, &(decl
->flags
),
8728 XML_SCHEMAS_ELEM_FINAL_EXTENSION
,
8729 XML_SCHEMAS_ELEM_FINAL_RESTRICTION
, -1, -1, -1) != 0) {
8730 xmlSchemaPSimpleTypeErr(ctxt
,
8731 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
8732 NULL
, (xmlNodePtr
) attr
,
8733 NULL
, "(#all | List of (extension | restriction))",
8734 attrValue
, NULL
, NULL
, NULL
);
8739 * Attribute "block".
8741 attr
= xmlSchemaGetPropNode(node
, "block");
8744 * Apply default "block" values.
8746 if (schema
->flags
& XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION
)
8747 decl
->flags
|= XML_SCHEMAS_ELEM_BLOCK_RESTRICTION
;
8748 if (schema
->flags
& XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION
)
8749 decl
->flags
|= XML_SCHEMAS_ELEM_BLOCK_EXTENSION
;
8750 if (schema
->flags
& XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION
)
8751 decl
->flags
|= XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION
;
8753 attrValue
= xmlSchemaGetNodeContent(ctxt
, (xmlNodePtr
) attr
);
8754 if (xmlSchemaPValAttrBlockFinal(attrValue
, &(decl
->flags
),
8756 XML_SCHEMAS_ELEM_BLOCK_EXTENSION
,
8757 XML_SCHEMAS_ELEM_BLOCK_RESTRICTION
,
8758 XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION
, -1, -1) != 0) {
8759 xmlSchemaPSimpleTypeErr(ctxt
,
8760 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
8761 NULL
, (xmlNodePtr
) attr
,
8762 NULL
, "(#all | List of (extension | "
8763 "restriction | substitution))", attrValue
,
8767 if (xmlGetBooleanProp(ctxt
, node
, "nillable", 0))
8768 decl
->flags
|= XML_SCHEMAS_ELEM_NILLABLE
;
8770 attr
= xmlSchemaGetPropNode(node
, "type");
8772 xmlSchemaPValAttrNodeQName(ctxt
, schema
,
8774 &(decl
->namedTypeNs
), &(decl
->namedType
));
8775 xmlSchemaCheckReference(ctxt
, schema
, node
,
8776 attr
, decl
->namedTypeNs
);
8778 decl
->value
= xmlSchemaGetProp(ctxt
, node
, "default");
8779 attr
= xmlSchemaGetPropNode(node
, "fixed");
8781 fixed
= xmlSchemaGetNodeContent(ctxt
, (xmlNodePtr
) attr
);
8782 if (decl
->value
!= NULL
) {
8785 * default and fixed must not both be present.
8787 xmlSchemaPMutualExclAttrErr(ctxt
,
8788 XML_SCHEMAP_SRC_ELEMENT_1
,
8789 NULL
, attr
, "default", "fixed");
8791 decl
->flags
|= XML_SCHEMAS_ELEM_FIXED
;
8792 decl
->value
= fixed
;
8796 * And now for the children...
8798 if (IS_SCHEMA(child
, "complexType")) {
8801 * "type" and either <simpleType> or <complexType> are mutually
8804 if (decl
->namedType
!= NULL
) {
8805 xmlSchemaPContentErr(ctxt
,
8806 XML_SCHEMAP_SRC_ELEMENT_3
,
8808 "The attribute 'type' and the <complexType> child are "
8809 "mutually exclusive", NULL
);
8811 WXS_ELEM_TYPEDEF(decl
) = xmlSchemaParseComplexType(ctxt
, schema
, child
, 0);
8812 child
= child
->next
;
8813 } else if (IS_SCHEMA(child
, "simpleType")) {
8816 * "type" and either <simpleType> or <complexType> are
8817 * mutually exclusive
8819 if (decl
->namedType
!= NULL
) {
8820 xmlSchemaPContentErr(ctxt
,
8821 XML_SCHEMAP_SRC_ELEMENT_3
,
8823 "The attribute 'type' and the <simpleType> child are "
8824 "mutually exclusive", NULL
);
8826 WXS_ELEM_TYPEDEF(decl
) = xmlSchemaParseSimpleType(ctxt
, schema
, child
, 0);
8827 child
= child
->next
;
8829 while ((IS_SCHEMA(child
, "unique")) ||
8830 (IS_SCHEMA(child
, "key")) || (IS_SCHEMA(child
, "keyref"))) {
8831 if (IS_SCHEMA(child
, "unique")) {
8832 curIDC
= xmlSchemaParseIDC(ctxt
, schema
, child
,
8833 XML_SCHEMA_TYPE_IDC_UNIQUE
, decl
->targetNamespace
);
8834 } else if (IS_SCHEMA(child
, "key")) {
8835 curIDC
= xmlSchemaParseIDC(ctxt
, schema
, child
,
8836 XML_SCHEMA_TYPE_IDC_KEY
, decl
->targetNamespace
);
8837 } else if (IS_SCHEMA(child
, "keyref")) {
8838 curIDC
= xmlSchemaParseIDC(ctxt
, schema
, child
,
8839 XML_SCHEMA_TYPE_IDC_KEYREF
, decl
->targetNamespace
);
8841 if (lastIDC
!= NULL
)
8842 lastIDC
->next
= curIDC
;
8844 decl
->idcs
= (void *) curIDC
;
8846 child
= child
->next
;
8848 if (child
!= NULL
) {
8849 xmlSchemaPContentErr(ctxt
,
8850 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
8852 NULL
, "(annotation?, ((simpleType | complexType)?, "
8853 "(unique | key | keyref)*))");
8855 decl
->annot
= annot
;
8858 * NOTE: Element Declaration Representation OK 4. will be checked at a
8863 return ((xmlSchemaBasicItemPtr
) decl
);
8865 particle
->children
= (xmlSchemaTreeItemPtr
) decl
;
8866 return ((xmlSchemaBasicItemPtr
) particle
);
8871 if (annot
!= NULL
) {
8872 if (particle
!= NULL
)
8873 particle
->annot
= NULL
;
8876 xmlSchemaFreeAnnot(annot
);
8882 * xmlSchemaParseUnion:
8883 * @ctxt: a schema validation context
8884 * @schema: the schema being built
8885 * @node: a subtree containing XML Schema informations
8887 * parse a XML schema Union definition
8888 * *WARNING* this interface is highly subject to change
8890 * Returns -1 in case of internal error, 0 in case of success and a positive
8891 * error code otherwise.
8894 xmlSchemaParseUnion(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
8897 xmlSchemaTypePtr type
;
8898 xmlNodePtr child
= NULL
;
8900 const xmlChar
*cur
= NULL
;
8902 if ((ctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
8904 /* Not a component, don't create it. */
8905 type
= ctxt
->ctxtType
;
8907 * Mark the simple type as being of variety "union".
8909 type
->flags
|= XML_SCHEMAS_TYPE_VARIETY_UNION
;
8911 * SPEC (Base type) (2) "If the <list> or <union> alternative is chosen,
8912 * then the `simple ur-type definition`."
8914 type
->baseType
= xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE
);
8916 * Check for illegal attributes.
8918 attr
= node
->properties
;
8919 while (attr
!= NULL
) {
8920 if (attr
->ns
== NULL
) {
8921 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"id")) &&
8922 (!xmlStrEqual(attr
->name
, BAD_CAST
"memberTypes"))) {
8923 xmlSchemaPIllegalAttrErr(ctxt
,
8924 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
8926 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
8927 xmlSchemaPIllegalAttrErr(ctxt
,
8928 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
8932 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
8934 * Attribute "memberTypes". This is a list of QNames.
8935 * TODO: Check the value to contain anything.
8937 attr
= xmlSchemaGetPropNode(node
, "memberTypes");
8941 const xmlChar
*localName
, *nsName
;
8942 xmlSchemaTypeLinkPtr link
, lastLink
= NULL
;
8943 xmlSchemaQNameRefPtr ref
;
8945 cur
= xmlSchemaGetNodeContent(ctxt
, (xmlNodePtr
) attr
);
8948 while (IS_BLANK_CH(*cur
))
8951 while ((*end
!= 0) && (!(IS_BLANK_CH(*end
))))
8955 tmp
= xmlStrndup(cur
, end
- cur
);
8956 if (xmlSchemaPValAttrNodeQNameValue(ctxt
, schema
,
8957 NULL
, attr
, BAD_CAST tmp
, &nsName
, &localName
) == 0) {
8959 * Create the member type link.
8961 link
= (xmlSchemaTypeLinkPtr
)
8962 xmlMalloc(sizeof(xmlSchemaTypeLink
));
8964 xmlSchemaPErrMemory(ctxt
, "xmlSchemaParseUnion, "
8965 "allocating a type link", NULL
);
8970 if (lastLink
== NULL
)
8971 type
->memberTypes
= link
;
8973 lastLink
->next
= link
;
8976 * Create a reference item.
8978 ref
= xmlSchemaNewQNameRef(ctxt
, XML_SCHEMA_TYPE_SIMPLE
,
8985 * Assign the reference to the link, it will be resolved
8986 * later during fixup of the union simple type.
8988 link
->type
= (xmlSchemaTypePtr
) ref
;
8992 } while (*cur
!= 0);
8996 * And now for the children...
8998 child
= node
->children
;
8999 if (IS_SCHEMA(child
, "annotation")) {
9001 * Add the annotation to the simple type ancestor.
9003 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr
) type
,
9004 xmlSchemaParseAnnotation(ctxt
, child
, 1));
9005 child
= child
->next
;
9007 if (IS_SCHEMA(child
, "simpleType")) {
9008 xmlSchemaTypePtr subtype
, last
= NULL
;
9011 * Anchor the member types in the "subtypes" field of the
9014 while (IS_SCHEMA(child
, "simpleType")) {
9015 subtype
= (xmlSchemaTypePtr
)
9016 xmlSchemaParseSimpleType(ctxt
, schema
, child
, 0);
9017 if (subtype
!= NULL
) {
9019 type
->subtypes
= subtype
;
9022 last
->next
= subtype
;
9027 child
= child
->next
;
9030 if (child
!= NULL
) {
9031 xmlSchemaPContentErr(ctxt
,
9032 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
9033 NULL
, node
, child
, NULL
, "(annotation?, simpleType*)");
9035 if ((attr
== NULL
) && (type
->subtypes
== NULL
)) {
9037 * src-union-memberTypes-or-simpleTypes
9038 * Either the memberTypes [attribute] of the <union> element must
9039 * be non-empty or there must be at least one simpleType [child].
9041 xmlSchemaPCustomErr(ctxt
,
9042 XML_SCHEMAP_SRC_UNION_MEMBERTYPES_OR_SIMPLETYPES
,
9044 "Either the attribute 'memberTypes' or "
9045 "at least one <simpleType> child must be present", NULL
);
9051 * xmlSchemaParseList:
9052 * @ctxt: a schema validation context
9053 * @schema: the schema being built
9054 * @node: a subtree containing XML Schema informations
9056 * parse a XML schema List definition
9057 * *WARNING* this interface is highly subject to change
9059 * Returns -1 in case of error, 0 if the declaration is improper and
9060 * 1 in case of success.
9062 static xmlSchemaTypePtr
9063 xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
9066 xmlSchemaTypePtr type
;
9067 xmlNodePtr child
= NULL
;
9070 if ((ctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
9072 /* Not a component, don't create it. */
9073 type
= ctxt
->ctxtType
;
9075 * Mark the type as being of variety "list".
9077 type
->flags
|= XML_SCHEMAS_TYPE_VARIETY_LIST
;
9079 * SPEC (Base type) (2) "If the <list> or <union> alternative is chosen,
9080 * then the `simple ur-type definition`."
9082 type
->baseType
= xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE
);
9084 * Check for illegal attributes.
9086 attr
= node
->properties
;
9087 while (attr
!= NULL
) {
9088 if (attr
->ns
== NULL
) {
9089 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"id")) &&
9090 (!xmlStrEqual(attr
->name
, BAD_CAST
"itemType"))) {
9091 xmlSchemaPIllegalAttrErr(ctxt
,
9092 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
9094 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
9095 xmlSchemaPIllegalAttrErr(ctxt
,
9096 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
9101 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
9104 * Attribute "itemType". NOTE that we will use the "ref" and "refNs"
9105 * fields for holding the reference to the itemType.
9107 * REVAMP TODO: Use the "base" and "baseNs" fields, since we will remove
9110 xmlSchemaPValAttrQName(ctxt
, schema
, NULL
,
9111 node
, "itemType", &(type
->baseNs
), &(type
->base
));
9113 * And now for the children...
9115 child
= node
->children
;
9116 if (IS_SCHEMA(child
, "annotation")) {
9117 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr
) type
,
9118 xmlSchemaParseAnnotation(ctxt
, child
, 1));
9119 child
= child
->next
;
9121 if (IS_SCHEMA(child
, "simpleType")) {
9123 * src-list-itemType-or-simpleType
9124 * Either the itemType [attribute] or the <simpleType> [child] of
9125 * the <list> element must be present, but not both.
9127 if (type
->base
!= NULL
) {
9128 xmlSchemaPCustomErr(ctxt
,
9129 XML_SCHEMAP_SRC_SIMPLE_TYPE_1
,
9131 "The attribute 'itemType' and the <simpleType> child "
9132 "are mutually exclusive", NULL
);
9134 type
->subtypes
= xmlSchemaParseSimpleType(ctxt
, schema
, child
, 0);
9136 child
= child
->next
;
9137 } else if (type
->base
== NULL
) {
9138 xmlSchemaPCustomErr(ctxt
,
9139 XML_SCHEMAP_SRC_SIMPLE_TYPE_1
,
9141 "Either the attribute 'itemType' or the <simpleType> child "
9142 "must be present", NULL
);
9144 if (child
!= NULL
) {
9145 xmlSchemaPContentErr(ctxt
,
9146 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
9147 NULL
, node
, child
, NULL
, "(annotation?, simpleType?)");
9149 if ((type
->base
== NULL
) &&
9150 (type
->subtypes
== NULL
) &&
9151 (xmlSchemaGetPropNode(node
, "itemType") == NULL
)) {
9152 xmlSchemaPCustomErr(ctxt
,
9153 XML_SCHEMAP_SRC_SIMPLE_TYPE_1
,
9155 "Either the attribute 'itemType' or the <simpleType> child "
9156 "must be present", NULL
);
9162 * xmlSchemaParseSimpleType:
9163 * @ctxt: a schema validation context
9164 * @schema: the schema being built
9165 * @node: a subtree containing XML Schema informations
9167 * parse a XML schema Simple Type definition
9168 * *WARNING* this interface is highly subject to change
9170 * Returns -1 in case of error, 0 if the declaration is improper and
9171 * 1 in case of success.
9173 static xmlSchemaTypePtr
9174 xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
9175 xmlNodePtr node
, int topLevel
)
9177 xmlSchemaTypePtr type
, oldCtxtType
;
9178 xmlNodePtr child
= NULL
;
9179 const xmlChar
*attrValue
= NULL
;
9181 int hasRestriction
= 0;
9183 if ((ctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
9187 attr
= xmlSchemaGetPropNode(node
, "name");
9189 xmlSchemaPMissingAttrErr(ctxt
,
9190 XML_SCHEMAP_S4S_ATTR_MISSING
,
9195 if (xmlSchemaPValAttrNode(ctxt
,
9197 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME
), &attrValue
) != 0)
9200 * Skip built-in types.
9203 xmlSchemaTypePtr biType
;
9205 if (ctxt
->isRedefine
) {
9207 * REDEFINE: Disallow redefinition of built-in-types.
9208 * TODO: It seems that the spec does not say anything
9211 xmlSchemaPCustomErr(ctxt
, XML_SCHEMAP_SRC_REDEFINE
,
9213 "Redefinition of built-in simple types is not "
9217 biType
= xmlSchemaGetPredefinedType(attrValue
, xmlSchemaNs
);
9225 * SPEC "The `actual value` of the targetNamespace [attribute]
9226 * of the <schema> ancestor element information item if present,
9227 * otherwise `absent`.
9229 if (topLevel
== 0) {
9230 #ifdef ENABLE_NAMED_LOCALS
9234 * Parse as local simple type definition.
9236 #ifdef ENABLE_NAMED_LOCALS
9237 snprintf(buf
, 39, "#ST%d", ctxt
->counter
++ + 1);
9238 type
= xmlSchemaAddType(ctxt
, schema
,
9239 XML_SCHEMA_TYPE_SIMPLE
,
9240 xmlDictLookup(ctxt
->dict
, (const xmlChar
*)buf
, -1),
9241 ctxt
->targetNamespace
, node
, 0);
9243 type
= xmlSchemaAddType(ctxt
, schema
,
9244 XML_SCHEMA_TYPE_SIMPLE
,
9245 NULL
, ctxt
->targetNamespace
, node
, 0);
9249 type
->type
= XML_SCHEMA_TYPE_SIMPLE
;
9250 type
->contentType
= XML_SCHEMA_CONTENT_SIMPLE
;
9252 * Check for illegal attributes.
9254 attr
= node
->properties
;
9255 while (attr
!= NULL
) {
9256 if (attr
->ns
== NULL
) {
9257 if (!xmlStrEqual(attr
->name
, BAD_CAST
"id")) {
9258 xmlSchemaPIllegalAttrErr(ctxt
,
9259 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
9261 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
9262 xmlSchemaPIllegalAttrErr(ctxt
,
9263 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
9269 * Parse as global simple type definition.
9271 * Note that attrValue is the value of the attribute "name" here.
9273 type
= xmlSchemaAddType(ctxt
, schema
, XML_SCHEMA_TYPE_SIMPLE
,
9274 attrValue
, ctxt
->targetNamespace
, node
, 1);
9277 type
->type
= XML_SCHEMA_TYPE_SIMPLE
;
9278 type
->contentType
= XML_SCHEMA_CONTENT_SIMPLE
;
9279 type
->flags
|= XML_SCHEMAS_TYPE_GLOBAL
;
9281 * Check for illegal attributes.
9283 attr
= node
->properties
;
9284 while (attr
!= NULL
) {
9285 if (attr
->ns
== NULL
) {
9286 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"id")) &&
9287 (!xmlStrEqual(attr
->name
, BAD_CAST
"name")) &&
9288 (!xmlStrEqual(attr
->name
, BAD_CAST
"final"))) {
9289 xmlSchemaPIllegalAttrErr(ctxt
,
9290 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
9292 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
9293 xmlSchemaPIllegalAttrErr(ctxt
,
9294 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
9299 * Attribute "final".
9301 attr
= xmlSchemaGetPropNode(node
, "final");
9303 if (schema
->flags
& XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION
)
9304 type
->flags
|= XML_SCHEMAS_TYPE_FINAL_RESTRICTION
;
9305 if (schema
->flags
& XML_SCHEMAS_FINAL_DEFAULT_LIST
)
9306 type
->flags
|= XML_SCHEMAS_TYPE_FINAL_LIST
;
9307 if (schema
->flags
& XML_SCHEMAS_FINAL_DEFAULT_UNION
)
9308 type
->flags
|= XML_SCHEMAS_TYPE_FINAL_UNION
;
9310 attrValue
= xmlSchemaGetProp(ctxt
, node
, "final");
9311 if (xmlSchemaPValAttrBlockFinal(attrValue
, &(type
->flags
),
9312 -1, -1, XML_SCHEMAS_TYPE_FINAL_RESTRICTION
, -1,
9313 XML_SCHEMAS_TYPE_FINAL_LIST
,
9314 XML_SCHEMAS_TYPE_FINAL_UNION
) != 0) {
9316 xmlSchemaPSimpleTypeErr(ctxt
,
9317 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
9318 WXS_BASIC_CAST type
, (xmlNodePtr
) attr
,
9319 NULL
, "(#all | List of (list | union | restriction)",
9320 attrValue
, NULL
, NULL
, NULL
);
9324 type
->targetNamespace
= ctxt
->targetNamespace
;
9325 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
9327 * And now for the children...
9329 oldCtxtType
= ctxt
->ctxtType
;
9331 ctxt
->ctxtType
= type
;
9333 child
= node
->children
;
9334 if (IS_SCHEMA(child
, "annotation")) {
9335 type
->annot
= xmlSchemaParseAnnotation(ctxt
, child
, 1);
9336 child
= child
->next
;
9338 if (child
== NULL
) {
9339 xmlSchemaPContentErr(ctxt
, XML_SCHEMAP_S4S_ELEM_MISSING
,
9340 NULL
, node
, child
, NULL
,
9341 "(annotation?, (restriction | list | union))");
9342 } else if (IS_SCHEMA(child
, "restriction")) {
9343 xmlSchemaParseRestriction(ctxt
, schema
, child
,
9344 XML_SCHEMA_TYPE_SIMPLE
);
9346 child
= child
->next
;
9347 } else if (IS_SCHEMA(child
, "list")) {
9348 xmlSchemaParseList(ctxt
, schema
, child
);
9349 child
= child
->next
;
9350 } else if (IS_SCHEMA(child
, "union")) {
9351 xmlSchemaParseUnion(ctxt
, schema
, child
);
9352 child
= child
->next
;
9354 if (child
!= NULL
) {
9355 xmlSchemaPContentErr(ctxt
, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
9356 NULL
, node
, child
, NULL
,
9357 "(annotation?, (restriction | list | union))");
9360 * REDEFINE: SPEC src-redefine (5)
9361 * "Within the [children], each <simpleType> must have a
9362 * <restriction> among its [children] ... the `actual value` of whose
9363 * base [attribute] must be the same as the `actual value` of its own
9364 * name attribute plus target namespace;"
9366 if (topLevel
&& ctxt
->isRedefine
&& (! hasRestriction
)) {
9367 xmlSchemaPCustomErr(ctxt
, XML_SCHEMAP_SRC_REDEFINE
,
9368 NULL
, node
, "This is a redefinition, thus the "
9369 "<simpleType> must have a <restriction> child", NULL
);
9372 ctxt
->ctxtType
= oldCtxtType
;
9377 * xmlSchemaParseModelGroupDefRef:
9378 * @ctxt: the parser context
9379 * @schema: the schema being built
9382 * Parses a reference to a model group definition.
9384 * We will return a particle component with a qname-component or
9385 * NULL in case of an error.
9387 static xmlSchemaTreeItemPtr
9388 xmlSchemaParseModelGroupDefRef(xmlSchemaParserCtxtPtr ctxt
,
9389 xmlSchemaPtr schema
,
9392 xmlSchemaParticlePtr item
;
9393 xmlNodePtr child
= NULL
;
9395 const xmlChar
*ref
= NULL
, *refNs
= NULL
;
9398 if ((ctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
9401 attr
= xmlSchemaGetPropNode(node
, "ref");
9403 xmlSchemaPMissingAttrErr(ctxt
,
9404 XML_SCHEMAP_S4S_ATTR_MISSING
,
9405 NULL
, node
, "ref", NULL
);
9407 } else if (xmlSchemaPValAttrNodeQName(ctxt
, schema
, NULL
,
9408 attr
, &refNs
, &ref
) != 0) {
9411 xmlSchemaCheckReference(ctxt
, schema
, node
, attr
, refNs
);
9412 min
= xmlGetMinOccurs(ctxt
, node
, 0, -1, 1, "xs:nonNegativeInteger");
9413 max
= xmlGetMaxOccurs(ctxt
, node
, 0, UNBOUNDED
, 1,
9414 "(xs:nonNegativeInteger | unbounded)");
9416 * Check for illegal attributes.
9418 attr
= node
->properties
;
9419 while (attr
!= NULL
) {
9420 if (attr
->ns
== NULL
) {
9421 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"ref")) &&
9422 (!xmlStrEqual(attr
->name
, BAD_CAST
"id")) &&
9423 (!xmlStrEqual(attr
->name
, BAD_CAST
"minOccurs")) &&
9424 (!xmlStrEqual(attr
->name
, BAD_CAST
"maxOccurs"))) {
9425 xmlSchemaPIllegalAttrErr(ctxt
,
9426 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
9428 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
9429 xmlSchemaPIllegalAttrErr(ctxt
,
9430 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
9434 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
9435 item
= xmlSchemaAddParticle(ctxt
, node
, min
, max
);
9439 * Create a qname-reference and set as the term; it will be substituted
9440 * for the model group after the reference has been resolved.
9442 item
->children
= (xmlSchemaTreeItemPtr
)
9443 xmlSchemaNewQNameRef(ctxt
, XML_SCHEMA_TYPE_GROUP
, ref
, refNs
);
9444 xmlSchemaPCheckParticleCorrect_2(ctxt
, item
, node
, min
, max
);
9446 * And now for the children...
9448 child
= node
->children
;
9449 /* TODO: Is annotation even allowed for a model group reference? */
9450 if (IS_SCHEMA(child
, "annotation")) {
9452 * TODO: What to do exactly with the annotation?
9454 item
->annot
= xmlSchemaParseAnnotation(ctxt
, child
, 1);
9455 child
= child
->next
;
9457 if (child
!= NULL
) {
9458 xmlSchemaPContentErr(ctxt
,
9459 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
9460 NULL
, node
, child
, NULL
,
9464 * Corresponds to no component at all if minOccurs==maxOccurs==0.
9466 if ((min
== 0) && (max
== 0))
9469 return ((xmlSchemaTreeItemPtr
) item
);
9473 * xmlSchemaParseModelGroupDefinition:
9474 * @ctxt: a schema validation context
9475 * @schema: the schema being built
9476 * @node: a subtree containing XML Schema informations
9478 * Parses a XML schema model group definition.
9480 * Note that the contraint src-redefine (6.2) can't be applied until
9481 * references have been resolved. So we will do this at the
9482 * component fixup level.
9484 * *WARNING* this interface is highly subject to change
9486 * Returns -1 in case of error, 0 if the declaration is improper and
9487 * 1 in case of success.
9489 static xmlSchemaModelGroupDefPtr
9490 xmlSchemaParseModelGroupDefinition(xmlSchemaParserCtxtPtr ctxt
,
9491 xmlSchemaPtr schema
,
9494 xmlSchemaModelGroupDefPtr item
;
9495 xmlNodePtr child
= NULL
;
9497 const xmlChar
*name
;
9499 if ((ctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
9502 attr
= xmlSchemaGetPropNode(node
, "name");
9504 xmlSchemaPMissingAttrErr(ctxt
,
9505 XML_SCHEMAP_S4S_ATTR_MISSING
,
9509 } else if (xmlSchemaPValAttrNode(ctxt
, NULL
, attr
,
9510 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME
), &name
) != 0) {
9513 item
= xmlSchemaAddModelGroupDefinition(ctxt
, schema
, name
,
9514 ctxt
->targetNamespace
, node
);
9518 * Check for illegal attributes.
9520 attr
= node
->properties
;
9521 while (attr
!= NULL
) {
9522 if (attr
->ns
== NULL
) {
9523 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"name")) &&
9524 (!xmlStrEqual(attr
->name
, BAD_CAST
"id"))) {
9525 xmlSchemaPIllegalAttrErr(ctxt
,
9526 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
9528 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
9529 xmlSchemaPIllegalAttrErr(ctxt
,
9530 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
9534 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
9536 * And now for the children...
9538 child
= node
->children
;
9539 if (IS_SCHEMA(child
, "annotation")) {
9540 item
->annot
= xmlSchemaParseAnnotation(ctxt
, child
, 1);
9541 child
= child
->next
;
9543 if (IS_SCHEMA(child
, "all")) {
9544 item
->children
= xmlSchemaParseModelGroup(ctxt
, schema
, child
,
9545 XML_SCHEMA_TYPE_ALL
, 0);
9546 child
= child
->next
;
9547 } else if (IS_SCHEMA(child
, "choice")) {
9548 item
->children
= xmlSchemaParseModelGroup(ctxt
, schema
, child
,
9549 XML_SCHEMA_TYPE_CHOICE
, 0);
9550 child
= child
->next
;
9551 } else if (IS_SCHEMA(child
, "sequence")) {
9552 item
->children
= xmlSchemaParseModelGroup(ctxt
, schema
, child
,
9553 XML_SCHEMA_TYPE_SEQUENCE
, 0);
9554 child
= child
->next
;
9559 if (child
!= NULL
) {
9560 xmlSchemaPContentErr(ctxt
,
9561 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
9562 NULL
, node
, child
, NULL
,
9563 "(annotation?, (all | choice | sequence)?)");
9569 * xmlSchemaCleanupDoc:
9570 * @ctxt: a schema validation context
9571 * @node: the root of the document.
9573 * removes unwanted nodes in a schemas document tree
9576 xmlSchemaCleanupDoc(xmlSchemaParserCtxtPtr ctxt
, xmlNodePtr root
)
9578 xmlNodePtr
delete, cur
;
9580 if ((ctxt
== NULL
) || (root
== NULL
)) return;
9583 * Remove all the blank text nodes
9587 while (cur
!= NULL
) {
9588 if (delete != NULL
) {
9589 xmlUnlinkNode(delete);
9590 xmlFreeNode(delete);
9593 if (cur
->type
== XML_TEXT_NODE
) {
9594 if (IS_BLANK_NODE(cur
)) {
9595 if (xmlNodeGetSpacePreserve(cur
) != 1) {
9599 } else if ((cur
->type
!= XML_ELEMENT_NODE
) &&
9600 (cur
->type
!= XML_CDATA_SECTION_NODE
)) {
9608 if (cur
->children
!= NULL
) {
9609 if ((cur
->children
->type
!= XML_ENTITY_DECL
) &&
9610 (cur
->children
->type
!= XML_ENTITY_REF_NODE
) &&
9611 (cur
->children
->type
!= XML_ENTITY_NODE
)) {
9612 cur
= cur
->children
;
9617 if (cur
->next
!= NULL
) {
9630 if (cur
->next
!= NULL
) {
9634 } while (cur
!= NULL
);
9636 if (delete != NULL
) {
9637 xmlUnlinkNode(delete);
9638 xmlFreeNode(delete);
9645 xmlSchemaClearSchemaDefaults(xmlSchemaPtr schema
)
9647 if (schema
->flags
& XML_SCHEMAS_QUALIF_ELEM
)
9648 schema
->flags
^= XML_SCHEMAS_QUALIF_ELEM
;
9650 if (schema
->flags
& XML_SCHEMAS_QUALIF_ATTR
)
9651 schema
->flags
^= XML_SCHEMAS_QUALIF_ATTR
;
9653 if (schema
->flags
& XML_SCHEMAS_FINAL_DEFAULT_EXTENSION
)
9654 schema
->flags
^= XML_SCHEMAS_FINAL_DEFAULT_EXTENSION
;
9655 if (schema
->flags
& XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION
)
9656 schema
->flags
^= XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION
;
9657 if (schema
->flags
& XML_SCHEMAS_FINAL_DEFAULT_LIST
)
9658 schema
->flags
^= XML_SCHEMAS_FINAL_DEFAULT_LIST
;
9659 if (schema
->flags
& XML_SCHEMAS_FINAL_DEFAULT_UNION
)
9660 schema
->flags
^= XML_SCHEMAS_FINAL_DEFAULT_UNION
;
9662 if (schema
->flags
& XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION
)
9663 schema
->flags
^= XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION
;
9664 if (schema
->flags
& XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION
)
9665 schema
->flags
^= XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION
;
9666 if (schema
->flags
& XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION
)
9667 schema
->flags
^= XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION
;
9671 xmlSchemaParseSchemaElement(xmlSchemaParserCtxtPtr ctxt
,
9672 xmlSchemaPtr schema
,
9677 int res
= 0, oldErrs
= ctxt
->nberrors
;
9680 * Those flags should be moved to the parser context flags,
9681 * since they are not visible at the component level. I.e.
9682 * they are used if processing schema *documents* only.
9684 res
= xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
9688 * Since the version is of type xs:token, we won't bother to
9692 attr = xmlSchemaGetPropNode(node, "version");
9694 res = xmlSchemaPValAttrNode(ctxt, NULL, NULL, attr,
9695 xmlSchemaGetBuiltInType(XML_SCHEMAS_TOKEN), &val);
9699 attr
= xmlSchemaGetPropNode(node
, "targetNamespace");
9701 res
= xmlSchemaPValAttrNode(ctxt
, NULL
, attr
,
9702 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI
), NULL
);
9705 ctxt
->stop
= XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
;
9709 attr
= xmlSchemaGetPropNode(node
, "elementFormDefault");
9711 val
= xmlSchemaGetNodeContent(ctxt
, (xmlNodePtr
) attr
);
9712 res
= xmlSchemaPValAttrFormDefault(val
, &schema
->flags
,
9713 XML_SCHEMAS_QUALIF_ELEM
);
9716 xmlSchemaPSimpleTypeErr(ctxt
,
9717 XML_SCHEMAP_ELEMFORMDEFAULT_VALUE
,
9718 NULL
, (xmlNodePtr
) attr
, NULL
,
9719 "(qualified | unqualified)", val
, NULL
, NULL
, NULL
);
9722 attr
= xmlSchemaGetPropNode(node
, "attributeFormDefault");
9724 val
= xmlSchemaGetNodeContent(ctxt
, (xmlNodePtr
) attr
);
9725 res
= xmlSchemaPValAttrFormDefault(val
, &schema
->flags
,
9726 XML_SCHEMAS_QUALIF_ATTR
);
9729 xmlSchemaPSimpleTypeErr(ctxt
,
9730 XML_SCHEMAP_ATTRFORMDEFAULT_VALUE
,
9731 NULL
, (xmlNodePtr
) attr
, NULL
,
9732 "(qualified | unqualified)", val
, NULL
, NULL
, NULL
);
9735 attr
= xmlSchemaGetPropNode(node
, "finalDefault");
9737 val
= xmlSchemaGetNodeContent(ctxt
, (xmlNodePtr
) attr
);
9738 res
= xmlSchemaPValAttrBlockFinal(val
, &(schema
->flags
), -1,
9739 XML_SCHEMAS_FINAL_DEFAULT_EXTENSION
,
9740 XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION
,
9742 XML_SCHEMAS_FINAL_DEFAULT_LIST
,
9743 XML_SCHEMAS_FINAL_DEFAULT_UNION
);
9746 xmlSchemaPSimpleTypeErr(ctxt
,
9747 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
9748 NULL
, (xmlNodePtr
) attr
, NULL
,
9749 "(#all | List of (extension | restriction | list | union))",
9750 val
, NULL
, NULL
, NULL
);
9753 attr
= xmlSchemaGetPropNode(node
, "blockDefault");
9755 val
= xmlSchemaGetNodeContent(ctxt
, (xmlNodePtr
) attr
);
9756 res
= xmlSchemaPValAttrBlockFinal(val
, &(schema
->flags
), -1,
9757 XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION
,
9758 XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION
,
9759 XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION
, -1, -1);
9762 xmlSchemaPSimpleTypeErr(ctxt
,
9763 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
9764 NULL
, (xmlNodePtr
) attr
, NULL
,
9765 "(#all | List of (extension | restriction | substitution))",
9766 val
, NULL
, NULL
, NULL
);
9771 if (oldErrs
!= ctxt
->nberrors
)
9779 * xmlSchemaParseSchemaTopLevel:
9780 * @ctxt: a schema validation context
9781 * @schema: the schemas
9782 * @nodes: the list of top level nodes
9784 * Returns the internal XML Schema structure built from the resource or
9785 * NULL in case of error
9788 xmlSchemaParseSchemaTopLevel(xmlSchemaParserCtxtPtr ctxt
,
9789 xmlSchemaPtr schema
, xmlNodePtr nodes
)
9792 xmlSchemaAnnotPtr annot
;
9793 int res
= 0, oldErrs
, tmpOldErrs
;
9795 if ((ctxt
== NULL
) || (schema
== NULL
) || (nodes
== NULL
))
9798 oldErrs
= ctxt
->nberrors
;
9800 while ((IS_SCHEMA(child
, "include")) ||
9801 (IS_SCHEMA(child
, "import")) ||
9802 (IS_SCHEMA(child
, "redefine")) ||
9803 (IS_SCHEMA(child
, "annotation"))) {
9804 if (IS_SCHEMA(child
, "annotation")) {
9805 annot
= xmlSchemaParseAnnotation(ctxt
, child
, 1);
9806 if (schema
->annot
== NULL
)
9807 schema
->annot
= annot
;
9809 xmlSchemaFreeAnnot(annot
);
9810 } else if (IS_SCHEMA(child
, "import")) {
9811 tmpOldErrs
= ctxt
->nberrors
;
9812 res
= xmlSchemaParseImport(ctxt
, schema
, child
);
9815 if (tmpOldErrs
!= ctxt
->nberrors
)
9817 } else if (IS_SCHEMA(child
, "include")) {
9818 tmpOldErrs
= ctxt
->nberrors
;
9819 res
= xmlSchemaParseInclude(ctxt
, schema
, child
);
9822 if (tmpOldErrs
!= ctxt
->nberrors
)
9824 } else if (IS_SCHEMA(child
, "redefine")) {
9825 tmpOldErrs
= ctxt
->nberrors
;
9826 res
= xmlSchemaParseRedefine(ctxt
, schema
, child
);
9829 if (tmpOldErrs
!= ctxt
->nberrors
)
9832 child
= child
->next
;
9835 * URGENT TODO: Change the functions to return int results.
9836 * We need especially to catch internal errors.
9838 while (child
!= NULL
) {
9839 if (IS_SCHEMA(child
, "complexType")) {
9840 xmlSchemaParseComplexType(ctxt
, schema
, child
, 1);
9841 child
= child
->next
;
9842 } else if (IS_SCHEMA(child
, "simpleType")) {
9843 xmlSchemaParseSimpleType(ctxt
, schema
, child
, 1);
9844 child
= child
->next
;
9845 } else if (IS_SCHEMA(child
, "element")) {
9846 xmlSchemaParseElement(ctxt
, schema
, child
, NULL
, 1);
9847 child
= child
->next
;
9848 } else if (IS_SCHEMA(child
, "attribute")) {
9849 xmlSchemaParseGlobalAttribute(ctxt
, schema
, child
);
9850 child
= child
->next
;
9851 } else if (IS_SCHEMA(child
, "attributeGroup")) {
9852 xmlSchemaParseAttributeGroupDefinition(ctxt
, schema
, child
);
9853 child
= child
->next
;
9854 } else if (IS_SCHEMA(child
, "group")) {
9855 xmlSchemaParseModelGroupDefinition(ctxt
, schema
, child
);
9856 child
= child
->next
;
9857 } else if (IS_SCHEMA(child
, "notation")) {
9858 xmlSchemaParseNotation(ctxt
, schema
, child
);
9859 child
= child
->next
;
9861 xmlSchemaPContentErr(ctxt
,
9862 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
9863 NULL
, child
->parent
, child
,
9864 NULL
, "((include | import | redefine | annotation)*, "
9865 "(((simpleType | complexType | group | attributeGroup) "
9866 "| element | attribute | notation), annotation*)*)");
9867 child
= child
->next
;
9869 while (IS_SCHEMA(child
, "annotation")) {
9871 * TODO: We should add all annotations.
9873 annot
= xmlSchemaParseAnnotation(ctxt
, child
, 1);
9874 if (schema
->annot
== NULL
)
9875 schema
->annot
= annot
;
9877 xmlSchemaFreeAnnot(annot
);
9878 child
= child
->next
;
9882 ctxt
->ctxtType
= NULL
;
9883 if (oldErrs
!= ctxt
->nberrors
)
9890 static xmlSchemaSchemaRelationPtr
9891 xmlSchemaSchemaRelationCreate(void)
9893 xmlSchemaSchemaRelationPtr ret
;
9895 ret
= (xmlSchemaSchemaRelationPtr
)
9896 xmlMalloc(sizeof(xmlSchemaSchemaRelation
));
9898 xmlSchemaPErrMemory(NULL
, "allocating schema relation", NULL
);
9901 memset(ret
, 0, sizeof(xmlSchemaSchemaRelation
));
9907 xmlSchemaSchemaRelationFree(xmlSchemaSchemaRelationPtr rel
)
9914 xmlSchemaRedefListFree(xmlSchemaRedefPtr redef
)
9916 xmlSchemaRedefPtr prev
;
9918 while (redef
!= NULL
) {
9920 redef
= redef
->next
;
9926 xmlSchemaConstructionCtxtFree(xmlSchemaConstructionCtxtPtr con
)
9929 * After the construction context has been freed, there will be
9930 * no schema graph available any more. Only the schema buckets
9931 * will stay alive, which are put into the "schemasImports" and
9932 * "includes" slots of the xmlSchema.
9934 if (con
->buckets
!= NULL
)
9935 xmlSchemaItemListFree(con
->buckets
);
9936 if (con
->pending
!= NULL
)
9937 xmlSchemaItemListFree(con
->pending
);
9938 if (con
->substGroups
!= NULL
)
9939 xmlHashFree(con
->substGroups
, xmlSchemaSubstGroupFreeEntry
);
9940 if (con
->redefs
!= NULL
)
9941 xmlSchemaRedefListFree(con
->redefs
);
9942 if (con
->dict
!= NULL
)
9943 xmlDictFree(con
->dict
);
9947 static xmlSchemaConstructionCtxtPtr
9948 xmlSchemaConstructionCtxtCreate(xmlDictPtr dict
)
9950 xmlSchemaConstructionCtxtPtr ret
;
9952 ret
= (xmlSchemaConstructionCtxtPtr
)
9953 xmlMalloc(sizeof(xmlSchemaConstructionCtxt
));
9955 xmlSchemaPErrMemory(NULL
,
9956 "allocating schema construction context", NULL
);
9959 memset(ret
, 0, sizeof(xmlSchemaConstructionCtxt
));
9961 ret
->buckets
= xmlSchemaItemListCreate();
9962 if (ret
->buckets
== NULL
) {
9963 xmlSchemaPErrMemory(NULL
,
9964 "allocating list of schema buckets", NULL
);
9968 ret
->pending
= xmlSchemaItemListCreate();
9969 if (ret
->pending
== NULL
) {
9970 xmlSchemaPErrMemory(NULL
,
9971 "allocating list of pending global components", NULL
);
9972 xmlSchemaConstructionCtxtFree(ret
);
9976 xmlDictReference(dict
);
9980 static xmlSchemaParserCtxtPtr
9981 xmlSchemaParserCtxtCreate(void)
9983 xmlSchemaParserCtxtPtr ret
;
9985 ret
= (xmlSchemaParserCtxtPtr
) xmlMalloc(sizeof(xmlSchemaParserCtxt
));
9987 xmlSchemaPErrMemory(NULL
, "allocating schema parser context",
9991 memset(ret
, 0, sizeof(xmlSchemaParserCtxt
));
9992 ret
->type
= XML_SCHEMA_CTXT_PARSER
;
9993 ret
->attrProhibs
= xmlSchemaItemListCreate();
9994 if (ret
->attrProhibs
== NULL
) {
10002 * xmlSchemaNewParserCtxtUseDict:
10003 * @URL: the location of the schema
10004 * @dict: the dictionary to be used
10006 * Create an XML Schemas parse context for that file/resource expected
10007 * to contain an XML Schemas file.
10009 * Returns the parser context or NULL in case of error
10011 static xmlSchemaParserCtxtPtr
10012 xmlSchemaNewParserCtxtUseDict(const char *URL
, xmlDictPtr dict
)
10014 xmlSchemaParserCtxtPtr ret
;
10016 ret
= xmlSchemaParserCtxtCreate();
10020 xmlDictReference(dict
);
10022 ret
->URL
= xmlDictLookup(dict
, (const xmlChar
*) URL
, -1);
10027 xmlSchemaCreatePCtxtOnVCtxt(xmlSchemaValidCtxtPtr vctxt
)
10029 if (vctxt
->pctxt
== NULL
) {
10030 if (vctxt
->schema
!= NULL
)
10032 xmlSchemaNewParserCtxtUseDict("*", vctxt
->schema
->dict
);
10034 vctxt
->pctxt
= xmlSchemaNewParserCtxt("*");
10035 if (vctxt
->pctxt
== NULL
) {
10036 VERROR_INT("xmlSchemaCreatePCtxtOnVCtxt",
10037 "failed to create a temp. parser context");
10040 /* TODO: Pass user data. */
10041 xmlSchemaSetParserErrors(vctxt
->pctxt
, vctxt
->error
,
10042 vctxt
->warning
, vctxt
->errCtxt
);
10043 xmlSchemaSetParserStructuredErrors(vctxt
->pctxt
, vctxt
->serror
,
10050 * xmlSchemaGetSchemaBucket:
10051 * @pctxt: the schema parser context
10052 * @schemaLocation: the URI of the schema document
10054 * Returns a schema bucket if it was already parsed.
10056 * Returns a schema bucket if it was already parsed from
10057 * @schemaLocation, NULL otherwise.
10059 static xmlSchemaBucketPtr
10060 xmlSchemaGetSchemaBucket(xmlSchemaParserCtxtPtr pctxt
,
10061 const xmlChar
*schemaLocation
)
10063 xmlSchemaBucketPtr cur
;
10064 xmlSchemaItemListPtr list
;
10066 list
= pctxt
->constructor
->buckets
;
10067 if (list
->nbItems
== 0)
10071 for (i
= 0; i
< list
->nbItems
; i
++) {
10072 cur
= (xmlSchemaBucketPtr
) list
->items
[i
];
10073 /* Pointer comparison! */
10074 if (cur
->schemaLocation
== schemaLocation
)
10081 static xmlSchemaBucketPtr
10082 xmlSchemaGetChameleonSchemaBucket(xmlSchemaParserCtxtPtr pctxt
,
10083 const xmlChar
*schemaLocation
,
10084 const xmlChar
*targetNamespace
)
10086 xmlSchemaBucketPtr cur
;
10087 xmlSchemaItemListPtr list
;
10089 list
= pctxt
->constructor
->buckets
;
10090 if (list
->nbItems
== 0)
10094 for (i
= 0; i
< list
->nbItems
; i
++) {
10095 cur
= (xmlSchemaBucketPtr
) list
->items
[i
];
10096 /* Pointer comparison! */
10097 if ((cur
->origTargetNamespace
== NULL
) &&
10098 (cur
->schemaLocation
== schemaLocation
) &&
10099 (cur
->targetNamespace
== targetNamespace
))
10107 #define IS_BAD_SCHEMA_DOC(b) \
10108 (((b)->doc == NULL) && ((b)->schemaLocation != NULL))
10110 static xmlSchemaBucketPtr
10111 xmlSchemaGetSchemaBucketByTNS(xmlSchemaParserCtxtPtr pctxt
,
10112 const xmlChar
*targetNamespace
,
10115 xmlSchemaBucketPtr cur
;
10116 xmlSchemaItemListPtr list
;
10118 list
= pctxt
->constructor
->buckets
;
10119 if (list
->nbItems
== 0)
10123 for (i
= 0; i
< list
->nbItems
; i
++) {
10124 cur
= (xmlSchemaBucketPtr
) list
->items
[i
];
10125 if ((! IS_BAD_SCHEMA_DOC(cur
)) &&
10126 (cur
->origTargetNamespace
== targetNamespace
) &&
10127 ((imported
&& cur
->imported
) ||
10128 ((!imported
) && (!cur
->imported
))))
10136 xmlSchemaParseNewDocWithContext(xmlSchemaParserCtxtPtr pctxt
,
10137 xmlSchemaPtr schema
,
10138 xmlSchemaBucketPtr bucket
)
10144 xmlSchemaBucketPtr oldbucket
= pctxt
->constructor
->bucket
;
10147 * Save old values; reset the *main* schema.
10148 * URGENT TODO: This is not good; move the per-document information
10149 * to the parser. Get rid of passing the main schema to the
10150 * parsing functions.
10152 oldFlags
= schema
->flags
;
10153 oldDoc
= schema
->doc
;
10154 if (schema
->flags
!= 0)
10155 xmlSchemaClearSchemaDefaults(schema
);
10156 schema
->doc
= bucket
->doc
;
10157 pctxt
->schema
= schema
;
10159 * Keep the current target namespace on the parser *not* on the
10162 pctxt
->targetNamespace
= bucket
->targetNamespace
;
10163 WXS_CONSTRUCTOR(pctxt
)->bucket
= bucket
;
10165 if ((bucket
->targetNamespace
!= NULL
) &&
10166 xmlStrEqual(bucket
->targetNamespace
, xmlSchemaNs
)) {
10168 * We are parsing the schema for schemas!
10172 /* Mark it as parsed, even if parsing fails. */
10174 /* Compile the schema doc. */
10175 node
= xmlDocGetRootElement(bucket
->doc
);
10176 ret
= xmlSchemaParseSchemaElement(pctxt
, schema
, node
);
10179 /* An empty schema; just get out. */
10180 if (node
->children
== NULL
)
10182 oldErrs
= pctxt
->nberrors
;
10183 ret
= xmlSchemaParseSchemaTopLevel(pctxt
, schema
, node
->children
);
10187 * TODO: Not nice, but I'm not 100% sure we will get always an error
10188 * as a result of the obove functions; so better rely on pctxt->err
10191 if ((ret
== 0) && (oldErrs
!= pctxt
->nberrors
)) {
10197 WXS_CONSTRUCTOR(pctxt
)->bucket
= oldbucket
;
10198 /* Restore schema values. */
10199 schema
->doc
= oldDoc
;
10200 schema
->flags
= oldFlags
;
10205 xmlSchemaParseNewDoc(xmlSchemaParserCtxtPtr pctxt
,
10206 xmlSchemaPtr schema
,
10207 xmlSchemaBucketPtr bucket
)
10209 xmlSchemaParserCtxtPtr newpctxt
;
10212 if (bucket
== NULL
)
10214 if (bucket
->parsed
) {
10215 PERROR_INT("xmlSchemaParseNewDoc",
10216 "reparsing a schema doc");
10219 if (bucket
->doc
== NULL
) {
10220 PERROR_INT("xmlSchemaParseNewDoc",
10221 "parsing a schema doc, but there's no doc");
10224 if (pctxt
->constructor
== NULL
) {
10225 PERROR_INT("xmlSchemaParseNewDoc",
10229 /* Create and init the temporary parser context. */
10230 newpctxt
= xmlSchemaNewParserCtxtUseDict(
10231 (const char *) bucket
->schemaLocation
, pctxt
->dict
);
10232 if (newpctxt
== NULL
)
10234 newpctxt
->constructor
= pctxt
->constructor
;
10236 * TODO: Can we avoid that the parser knows about the main schema?
10237 * It would be better if he knows about the current schema bucket
10240 newpctxt
->schema
= schema
;
10241 xmlSchemaSetParserErrors(newpctxt
, pctxt
->error
, pctxt
->warning
,
10243 xmlSchemaSetParserStructuredErrors(newpctxt
, pctxt
->serror
,
10245 newpctxt
->counter
= pctxt
->counter
;
10248 res
= xmlSchemaParseNewDocWithContext(newpctxt
, schema
, bucket
);
10250 /* Channel back errors and cleanup the temporary parser context. */
10253 pctxt
->nberrors
+= newpctxt
->nberrors
;
10254 pctxt
->counter
= newpctxt
->counter
;
10255 newpctxt
->constructor
= NULL
;
10256 /* Free the parser context. */
10257 xmlSchemaFreeParserCtxt(newpctxt
);
10262 xmlSchemaSchemaRelationAddChild(xmlSchemaBucketPtr bucket
,
10263 xmlSchemaSchemaRelationPtr rel
)
10265 xmlSchemaSchemaRelationPtr cur
= bucket
->relations
;
10268 bucket
->relations
= rel
;
10271 while (cur
->next
!= NULL
)
10277 static const xmlChar
*
10278 xmlSchemaBuildAbsoluteURI(xmlDictPtr dict
, const xmlChar
* location
,
10279 xmlNodePtr ctxtNode
)
10282 * Build an absolue location URI.
10284 if (location
!= NULL
) {
10285 if (ctxtNode
== NULL
)
10288 xmlChar
*base
, *URI
;
10289 const xmlChar
*ret
= NULL
;
10291 base
= xmlNodeGetBase(ctxtNode
->doc
, ctxtNode
);
10292 if (base
== NULL
) {
10293 URI
= xmlBuildURI(location
, ctxtNode
->doc
->URL
);
10295 URI
= xmlBuildURI(location
, base
);
10299 ret
= xmlDictLookup(dict
, URI
, -1);
10311 * xmlSchemaAddSchemaDoc:
10312 * @pctxt: a schema validation context
10313 * @schema: the schema being built
10314 * @node: a subtree containing XML Schema informations
10316 * Parse an included (and to-be-redefined) XML schema document.
10318 * Returns 0 on success, a positive error code on errors and
10319 * -1 in case of an internal or API error.
10323 xmlSchemaAddSchemaDoc(xmlSchemaParserCtxtPtr pctxt
,
10324 int type
, /* import or include or redefine */
10325 const xmlChar
*schemaLocation
,
10326 xmlDocPtr schemaDoc
,
10327 const char *schemaBuffer
,
10328 int schemaBufferLen
,
10329 xmlNodePtr invokingNode
,
10330 const xmlChar
*sourceTargetNamespace
,
10331 const xmlChar
*importNamespace
,
10332 xmlSchemaBucketPtr
*bucket
)
10334 const xmlChar
*targetNamespace
= NULL
;
10335 xmlSchemaSchemaRelationPtr relation
= NULL
;
10336 xmlDocPtr doc
= NULL
;
10337 int res
= 0, err
= 0, located
= 0, preserveDoc
= 0;
10338 xmlSchemaBucketPtr bkt
= NULL
;
10340 if (bucket
!= NULL
)
10344 case XML_SCHEMA_SCHEMA_IMPORT
:
10345 case XML_SCHEMA_SCHEMA_MAIN
:
10346 err
= XML_SCHEMAP_SRC_IMPORT
;
10348 case XML_SCHEMA_SCHEMA_INCLUDE
:
10349 err
= XML_SCHEMAP_SRC_INCLUDE
;
10351 case XML_SCHEMA_SCHEMA_REDEFINE
:
10352 err
= XML_SCHEMAP_SRC_REDEFINE
;
10357 /* Special handling for the main schema:
10358 * skip the location and relation logic and just parse the doc.
10359 * We need just a bucket to be returned in this case.
10361 if ((type
== XML_SCHEMA_SCHEMA_MAIN
) || (! WXS_HAS_BUCKETS(pctxt
)))
10364 /* Note that we expect the location to be an absulute URI. */
10365 if (schemaLocation
!= NULL
) {
10366 bkt
= xmlSchemaGetSchemaBucket(pctxt
, schemaLocation
);
10367 if ((bkt
!= NULL
) &&
10368 (pctxt
->constructor
->bucket
== bkt
)) {
10369 /* Report self-imports/inclusions/redefinitions. */
10371 xmlSchemaCustomErr(ACTXT_CAST pctxt
, err
,
10372 invokingNode
, NULL
,
10373 "The schema must not import/include/redefine itself",
10379 * Create a relation for the graph of schemas.
10381 relation
= xmlSchemaSchemaRelationCreate();
10382 if (relation
== NULL
)
10384 xmlSchemaSchemaRelationAddChild(pctxt
->constructor
->bucket
,
10386 relation
->type
= type
;
10389 * Save the namespace import information.
10391 if (WXS_IS_BUCKET_IMPMAIN(type
)) {
10392 relation
->importNamespace
= importNamespace
;
10393 if (schemaLocation
== NULL
) {
10395 * No location; this is just an import of the namespace.
10396 * Note that we don't assign a bucket to the relation
10401 targetNamespace
= importNamespace
;
10404 /* Did we already fetch the doc? */
10406 if ((WXS_IS_BUCKET_IMPMAIN(type
)) && (! bkt
->imported
)) {
10408 * We included/redefined and then try to import a schema,
10409 * but the new location provided for import was different.
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 imported, since "
10418 "it was already included or redefined",
10419 schemaLocation
, NULL
);
10422 } else if ((! WXS_IS_BUCKET_IMPMAIN(type
)) && (bkt
->imported
)) {
10424 * We imported and then try to include/redefine a schema,
10425 * but the new location provided for the include/redefine
10428 if (schemaLocation
== NULL
)
10429 schemaLocation
= BAD_CAST
"in_memory_buffer";
10430 if (!xmlStrEqual(schemaLocation
,
10431 bkt
->schemaLocation
)) {
10432 xmlSchemaCustomErr(ACTXT_CAST pctxt
, err
,
10433 invokingNode
, NULL
,
10434 "The schema document '%s' cannot be included or "
10435 "redefined, since it was already imported",
10436 schemaLocation
, NULL
);
10442 if (WXS_IS_BUCKET_IMPMAIN(type
)) {
10444 * Given that the schemaLocation [attribute] is only a hint, it is open
10445 * to applications to ignore all but the first <import> for a given
10446 * namespace, regardless of the `actual value` of schemaLocation, but
10447 * such a strategy risks missing useful information when new
10448 * schemaLocations are offered.
10450 * We will use the first <import> that comes with a location.
10451 * Further <import>s *with* a location, will result in an error.
10452 * TODO: Better would be to just report a warning here, but
10453 * we'll try it this way until someone complains.
10455 * Schema Document Location Strategy:
10456 * 3 Based on the namespace name, identify an existing schema document,
10457 * either as a resource which is an XML document or a <schema> element
10458 * information item, in some local schema repository;
10459 * 5 Attempt to resolve the namespace name to locate such a resource.
10461 * NOTE: (3) and (5) are not supported.
10464 relation
->bucket
= bkt
;
10467 bkt
= xmlSchemaGetSchemaBucketByTNS(pctxt
,
10468 importNamespace
, 1);
10471 relation
->bucket
= bkt
;
10472 if (bkt
->schemaLocation
== NULL
) {
10473 /* First given location of the schema; load the doc. */
10474 bkt
->schemaLocation
= schemaLocation
;
10476 if (!xmlStrEqual(schemaLocation
,
10477 bkt
->schemaLocation
)) {
10479 * Additional location given; just skip it.
10480 * URGENT TODO: We should report a warning here.
10481 * res = XML_SCHEMAP_SRC_IMPORT;
10483 if (schemaLocation
== NULL
)
10484 schemaLocation
= BAD_CAST
"in_memory_buffer";
10486 xmlSchemaCustomWarning(ACTXT_CAST pctxt
,
10487 XML_SCHEMAP_WARN_SKIP_SCHEMA
,
10488 invokingNode
, NULL
,
10489 "Skipping import of schema located at '%s' for the "
10490 "namespace '%s', since this namespace was already "
10491 "imported with the schema located at '%s'",
10492 schemaLocation
, importNamespace
, bkt
->schemaLocation
);
10498 * No bucket + first location: load the doc and create a
10502 /* <include> and <redefine> */
10505 if ((bkt
->origTargetNamespace
== NULL
) &&
10506 (bkt
->targetNamespace
!= sourceTargetNamespace
)) {
10507 xmlSchemaBucketPtr chamel
;
10510 * Chameleon include/redefine: skip loading only if it was
10511 * aleady build for the targetNamespace of the including
10515 * URGENT TODO: If the schema is a chameleon-include then copy
10516 * the components into the including schema and modify the
10517 * targetNamespace of those components, do nothing otherwise.
10518 * NOTE: This is currently worked-around by compiling the
10519 * chameleon for every destinct including targetNamespace; thus
10520 * not performant at the moment.
10521 * TODO: Check when the namespace in wildcards for chameleons
10522 * needs to be converted: before we built wildcard intersections
10526 chamel
= xmlSchemaGetChameleonSchemaBucket(pctxt
,
10527 schemaLocation
, sourceTargetNamespace
);
10528 if (chamel
!= NULL
) {
10529 /* A fitting chameleon was already parsed; NOP. */
10530 relation
->bucket
= chamel
;
10534 * We need to parse the chameleon again for a different
10536 * CHAMELEON TODO: Optimize this by only parsing the
10537 * chameleon once, and then copying the components to
10538 * the new targetNamespace.
10542 relation
->bucket
= bkt
;
10547 if ((bkt
!= NULL
) && (bkt
->doc
!= NULL
)) {
10548 PERROR_INT("xmlSchemaAddSchemaDoc",
10549 "trying to load a schema doc, but a doc is already "
10550 "assigned to the schema bucket");
10556 * Load the document.
10558 if (schemaDoc
!= NULL
) {
10560 /* Don' free this one, since it was provided by the caller. */
10562 /* TODO: Does the context or the doc hold the location? */
10563 if (schemaDoc
->URL
!= NULL
)
10564 schemaLocation
= xmlDictLookup(pctxt
->dict
,
10565 schemaDoc
->URL
, -1);
10567 schemaLocation
= BAD_CAST
"in_memory_buffer";
10568 } else if ((schemaLocation
!= NULL
) || (schemaBuffer
!= NULL
)) {
10569 xmlParserCtxtPtr parserCtxt
;
10571 parserCtxt
= xmlNewParserCtxt();
10572 if (parserCtxt
== NULL
) {
10573 xmlSchemaPErrMemory(NULL
, "xmlSchemaGetDoc, "
10574 "allocating a parser context", NULL
);
10577 if ((pctxt
->dict
!= NULL
) && (parserCtxt
->dict
!= NULL
)) {
10579 * TODO: Do we have to burden the schema parser dict with all
10580 * the content of the schema doc?
10582 xmlDictFree(parserCtxt
->dict
);
10583 parserCtxt
->dict
= pctxt
->dict
;
10584 xmlDictReference(parserCtxt
->dict
);
10586 if (schemaLocation
!= NULL
) {
10587 /* Parse from file. */
10588 doc
= xmlCtxtReadFile(parserCtxt
, (const char *) schemaLocation
,
10589 NULL
, SCHEMAS_PARSE_OPTIONS
);
10590 } else if (schemaBuffer
!= NULL
) {
10591 /* Parse from memory buffer. */
10592 doc
= xmlCtxtReadMemory(parserCtxt
, schemaBuffer
, schemaBufferLen
,
10593 NULL
, NULL
, SCHEMAS_PARSE_OPTIONS
);
10594 schemaLocation
= BAD_CAST
"in_memory_buffer";
10596 doc
->URL
= xmlStrdup(schemaLocation
);
10600 * 2.1 The referent is (a fragment of) a resource which is an
10601 * XML document (see clause 1.1), which in turn corresponds to
10602 * a <schema> element information item in a well-formed information
10603 * set, which in turn corresponds to a valid schema.
10604 * TODO: (2.1) fragments of XML documents are not supported.
10606 * 2.2 The referent is a <schema> element information item in
10607 * a well-formed information set, which in turn corresponds
10608 * to a valid schema.
10609 * TODO: (2.2) is not supported.
10613 lerr
= xmlGetLastError();
10615 * Check if this a parser error, or if the document could
10616 * just not be located.
10617 * TODO: Try to find specific error codes to react only on
10618 * localisation failures.
10620 if ((lerr
== NULL
) || (lerr
->domain
!= XML_FROM_IO
)) {
10622 * We assume a parser error here.
10625 /* TODO: Error code ?? */
10626 res
= XML_SCHEMAP_SRC_IMPORT_2_1
;
10627 xmlSchemaCustomErr(ACTXT_CAST pctxt
, res
,
10628 invokingNode
, NULL
,
10629 "Failed to parse the XML resource '%s'",
10630 schemaLocation
, NULL
);
10633 xmlFreeParserCtxt(parserCtxt
);
10634 if ((doc
== NULL
) && located
)
10637 xmlSchemaPErr(pctxt
, NULL
,
10638 XML_SCHEMAP_NOTHING_TO_PARSE
,
10639 "No information for parsing was provided with the "
10640 "given schema parser context.\n",
10645 * Preprocess the document.
10648 xmlNodePtr docElem
= NULL
;
10651 docElem
= xmlDocGetRootElement(doc
);
10652 if (docElem
== NULL
) {
10653 xmlSchemaCustomErr(ACTXT_CAST pctxt
, XML_SCHEMAP_NOROOT
,
10654 invokingNode
, NULL
,
10655 "The document '%s' has no document element",
10656 schemaLocation
, NULL
);
10660 * Remove all the blank text nodes.
10662 xmlSchemaCleanupDoc(pctxt
, docElem
);
10664 * Check the schema's top level element.
10666 if (!IS_SCHEMA(docElem
, "schema")) {
10667 xmlSchemaCustomErr(ACTXT_CAST pctxt
, XML_SCHEMAP_NOT_SCHEMA
,
10668 invokingNode
, NULL
,
10669 "The XML document '%s' is not a schema document",
10670 schemaLocation
, NULL
);
10674 * Note that we don't apply a type check for the
10675 * targetNamespace value here.
10677 targetNamespace
= xmlSchemaGetProp(pctxt
, docElem
,
10678 "targetNamespace");
10681 /* after_doc_loading: */
10682 if ((bkt
== NULL
) && located
) {
10683 /* Only create a bucket if the schema was located. */
10684 bkt
= xmlSchemaBucketCreate(pctxt
, type
,
10690 bkt
->schemaLocation
= schemaLocation
;
10691 bkt
->located
= located
;
10694 bkt
->targetNamespace
= targetNamespace
;
10695 bkt
->origTargetNamespace
= targetNamespace
;
10697 bkt
->preserveDoc
= 1;
10699 if (WXS_IS_BUCKET_IMPMAIN(type
))
10702 * Add it to the graph of schemas.
10704 if (relation
!= NULL
)
10705 relation
->bucket
= bkt
;
10710 * Return the bucket explicitely; this is needed for the
10713 if (bucket
!= NULL
)
10718 if ((doc
!= NULL
) && (! preserveDoc
)) {
10723 return(pctxt
->err
);
10726 if ((doc
!= NULL
) && (! preserveDoc
)) {
10735 * xmlSchemaParseImport:
10736 * @ctxt: a schema validation context
10737 * @schema: the schema being built
10738 * @node: a subtree containing XML Schema informations
10740 * parse a XML schema Import definition
10741 * *WARNING* this interface is highly subject to change
10743 * Returns 0 in case of success, a positive error code if
10744 * not valid and -1 in case of an internal error.
10747 xmlSchemaParseImport(xmlSchemaParserCtxtPtr pctxt
, xmlSchemaPtr schema
,
10751 const xmlChar
*namespaceName
= NULL
, *schemaLocation
= NULL
;
10752 const xmlChar
*thisTargetNamespace
;
10755 xmlSchemaBucketPtr bucket
= NULL
;
10757 if ((pctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
10761 * Check for illegal attributes.
10763 attr
= node
->properties
;
10764 while (attr
!= NULL
) {
10765 if (attr
->ns
== NULL
) {
10766 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"id")) &&
10767 (!xmlStrEqual(attr
->name
, BAD_CAST
"namespace")) &&
10768 (!xmlStrEqual(attr
->name
, BAD_CAST
"schemaLocation"))) {
10769 xmlSchemaPIllegalAttrErr(pctxt
,
10770 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
10772 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
10773 xmlSchemaPIllegalAttrErr(pctxt
,
10774 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
10779 * Extract and validate attributes.
10781 if (xmlSchemaPValAttr(pctxt
, NULL
, node
,
10782 "namespace", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI
),
10783 &namespaceName
) != 0) {
10784 xmlSchemaPSimpleTypeErr(pctxt
,
10785 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
10787 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI
),
10788 NULL
, namespaceName
, NULL
, NULL
, NULL
);
10789 return (pctxt
->err
);
10792 if (xmlSchemaPValAttr(pctxt
, NULL
, node
,
10793 "schemaLocation", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI
),
10794 &schemaLocation
) != 0) {
10795 xmlSchemaPSimpleTypeErr(pctxt
,
10796 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
10798 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI
),
10799 NULL
, schemaLocation
, NULL
, NULL
, NULL
);
10800 return (pctxt
->err
);
10803 * And now for the children...
10805 child
= node
->children
;
10806 if (IS_SCHEMA(child
, "annotation")) {
10808 * the annotation here is simply discarded ...
10811 child
= child
->next
;
10813 if (child
!= NULL
) {
10814 xmlSchemaPContentErr(pctxt
,
10815 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
10816 NULL
, node
, child
, NULL
,
10820 * Apply additional constraints.
10822 * Note that it is important to use the original @targetNamespace
10823 * (or none at all), to rule out imports of schemas _with_ a
10824 * @targetNamespace if the importing schema is a chameleon schema
10825 * (with no @targetNamespace).
10827 thisTargetNamespace
= WXS_BUCKET(pctxt
)->origTargetNamespace
;
10828 if (namespaceName
!= NULL
) {
10830 * 1.1 If the namespace [attribute] is present, then its `actual value`
10831 * must not match the `actual value` of the enclosing <schema>'s
10832 * targetNamespace [attribute].
10834 if (xmlStrEqual(thisTargetNamespace
, namespaceName
)) {
10835 xmlSchemaPCustomErr(pctxt
,
10836 XML_SCHEMAP_SRC_IMPORT_1_1
,
10838 "The value of the attribute 'namespace' must not match "
10839 "the target namespace '%s' of the importing schema",
10840 thisTargetNamespace
);
10841 return (pctxt
->err
);
10845 * 1.2 If the namespace [attribute] is not present, then the enclosing
10846 * <schema> must have a targetNamespace [attribute].
10848 if (thisTargetNamespace
== NULL
) {
10849 xmlSchemaPCustomErr(pctxt
,
10850 XML_SCHEMAP_SRC_IMPORT_1_2
,
10852 "The attribute 'namespace' must be existent if "
10853 "the importing schema has no target namespace",
10855 return (pctxt
->err
);
10859 * Locate and acquire the schema document.
10861 if (schemaLocation
!= NULL
)
10862 schemaLocation
= xmlSchemaBuildAbsoluteURI(pctxt
->dict
,
10863 schemaLocation
, node
);
10864 ret
= xmlSchemaAddSchemaDoc(pctxt
, XML_SCHEMA_SCHEMA_IMPORT
,
10865 schemaLocation
, NULL
, NULL
, 0, node
, thisTargetNamespace
,
10866 namespaceName
, &bucket
);
10872 * For <import>: "It is *not* an error for the application
10873 * schema reference strategy to fail."
10874 * So just don't parse if no schema document was found.
10875 * Note that we will get no bucket if the schema could not be
10876 * located or if there was no schemaLocation.
10878 if ((bucket
== NULL
) && (schemaLocation
!= NULL
)) {
10879 xmlSchemaCustomWarning(ACTXT_CAST pctxt
,
10880 XML_SCHEMAP_WARN_UNLOCATED_SCHEMA
,
10882 "Failed to locate a schema at location '%s'. "
10883 "Skipping the import", schemaLocation
, NULL
, NULL
);
10886 if ((bucket
!= NULL
) && CAN_PARSE_SCHEMA(bucket
)) {
10887 ret
= xmlSchemaParseNewDoc(pctxt
, schema
, bucket
);
10894 xmlSchemaParseIncludeOrRedefineAttrs(xmlSchemaParserCtxtPtr pctxt
,
10895 xmlSchemaPtr schema
,
10897 xmlChar
**schemaLocation
,
10902 if ((pctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
) ||
10903 (schemaLocation
== NULL
))
10906 *schemaLocation
= NULL
;
10908 * Check for illegal attributes.
10909 * Applies for both <include> and <redefine>.
10911 attr
= node
->properties
;
10912 while (attr
!= NULL
) {
10913 if (attr
->ns
== NULL
) {
10914 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"id")) &&
10915 (!xmlStrEqual(attr
->name
, BAD_CAST
"schemaLocation"))) {
10916 xmlSchemaPIllegalAttrErr(pctxt
,
10917 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
10919 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
10920 xmlSchemaPIllegalAttrErr(pctxt
,
10921 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
10925 xmlSchemaPValAttrID(pctxt
, node
, BAD_CAST
"id");
10927 * Preliminary step, extract the URI-Reference and make an URI
10931 * Attribute "schemaLocation" is mandatory.
10933 attr
= xmlSchemaGetPropNode(node
, "schemaLocation");
10934 if (attr
!= NULL
) {
10935 xmlChar
*base
= NULL
;
10936 xmlChar
*uri
= NULL
;
10938 if (xmlSchemaPValAttrNode(pctxt
, NULL
, attr
,
10939 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI
),
10940 (const xmlChar
**) schemaLocation
) != 0)
10942 base
= xmlNodeGetBase(node
->doc
, node
);
10943 if (base
== NULL
) {
10944 uri
= xmlBuildURI(*schemaLocation
, node
->doc
->URL
);
10946 uri
= xmlBuildURI(*schemaLocation
, base
);
10950 PERROR_INT("xmlSchemaParseIncludeOrRedefine",
10951 "could not build an URI from the schemaLocation")
10954 (*schemaLocation
) = (xmlChar
*) xmlDictLookup(pctxt
->dict
, uri
, -1);
10957 xmlSchemaPMissingAttrErr(pctxt
,
10958 XML_SCHEMAP_S4S_ATTR_MISSING
,
10959 NULL
, node
, "schemaLocation", NULL
);
10963 * Report self-inclusion and self-redefinition.
10965 if (xmlStrEqual(*schemaLocation
, pctxt
->URL
)) {
10966 if (type
== XML_SCHEMA_SCHEMA_REDEFINE
) {
10967 xmlSchemaPCustomErr(pctxt
,
10968 XML_SCHEMAP_SRC_REDEFINE
,
10970 "The schema document '%s' cannot redefine itself.",
10973 xmlSchemaPCustomErr(pctxt
,
10974 XML_SCHEMAP_SRC_INCLUDE
,
10976 "The schema document '%s' cannot include itself.",
10984 return(pctxt
->err
);
10990 xmlSchemaParseIncludeOrRedefine(xmlSchemaParserCtxtPtr pctxt
,
10991 xmlSchemaPtr schema
,
10995 xmlNodePtr child
= NULL
;
10996 const xmlChar
*schemaLocation
= NULL
;
10997 int res
= 0; /* hasRedefinitions = 0 */
10998 int isChameleon
= 0, wasChameleon
= 0;
10999 xmlSchemaBucketPtr bucket
= NULL
;
11001 if ((pctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
11005 * Parse attributes. Note that the returned schemaLocation will
11006 * be already converted to an absolute URI.
11008 res
= xmlSchemaParseIncludeOrRedefineAttrs(pctxt
, schema
,
11009 node
, (xmlChar
**) (&schemaLocation
), type
);
11013 * Load and add the schema document.
11015 res
= xmlSchemaAddSchemaDoc(pctxt
, type
, schemaLocation
, NULL
,
11016 NULL
, 0, node
, pctxt
->targetNamespace
, NULL
, &bucket
);
11020 * If we get no schema bucket back, then this means that the schema
11021 * document could not be located or was broken XML or was not
11022 * a schema document.
11024 if ((bucket
== NULL
) || (bucket
->doc
== NULL
)) {
11025 if (type
== XML_SCHEMA_SCHEMA_INCLUDE
) {
11027 * WARNING for <include>:
11028 * We will raise an error if the schema cannot be located
11029 * for inclusions, since the that was the feedback from the
11030 * schema people. I.e. the following spec piece will *not* be
11032 * SPEC src-include: "It is not an error for the `actual value` of the
11033 * schemaLocation [attribute] to fail to resolve it all, in which
11034 * case no corresponding inclusion is performed.
11035 * So do we need a warning report here?"
11037 res
= XML_SCHEMAP_SRC_INCLUDE
;
11038 xmlSchemaCustomErr(ACTXT_CAST pctxt
, res
,
11040 "Failed to load the document '%s' for inclusion",
11041 schemaLocation
, NULL
);
11044 * NOTE: This was changed to raise an error even if no redefinitions
11047 * SPEC src-redefine (1)
11048 * "If there are any element information items among the [children]
11049 * other than <annotation> then the `actual value` of the
11050 * schemaLocation [attribute] must successfully resolve."
11051 * TODO: Ask the WG if a the location has always to resolve
11054 res
= XML_SCHEMAP_SRC_REDEFINE
;
11055 xmlSchemaCustomErr(ACTXT_CAST pctxt
, res
,
11057 "Failed to load the document '%s' for redefinition",
11058 schemaLocation
, NULL
);
11062 * Check targetNamespace sanity before parsing the new schema.
11063 * TODO: Note that we won't check further content if the
11064 * targetNamespace was bad.
11066 if (bucket
->origTargetNamespace
!= NULL
) {
11068 * SPEC src-include (2.1)
11069 * "SII has a targetNamespace [attribute], and its `actual
11070 * value` is identical to the `actual value` of the targetNamespace
11071 * [attribute] of SII' (which must have such an [attribute])."
11073 if (pctxt
->targetNamespace
== NULL
) {
11074 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
11075 XML_SCHEMAP_SRC_INCLUDE
,
11077 "The target namespace of the included/redefined schema "
11078 "'%s' has to be absent, since the including/redefining "
11079 "schema has no target namespace",
11080 schemaLocation
, NULL
);
11082 } else if (!xmlStrEqual(bucket
->origTargetNamespace
,
11083 pctxt
->targetNamespace
)) {
11084 /* TODO: Change error function. */
11085 xmlSchemaPCustomErrExt(pctxt
,
11086 XML_SCHEMAP_SRC_INCLUDE
,
11088 "The target namespace '%s' of the included/redefined "
11089 "schema '%s' differs from '%s' of the "
11090 "including/redefining schema",
11091 bucket
->origTargetNamespace
, schemaLocation
,
11092 pctxt
->targetNamespace
);
11095 } else if (pctxt
->targetNamespace
!= NULL
) {
11097 * Chameleons: the original target namespace will
11098 * differ from the resulting namespace.
11101 if (bucket
->parsed
&&
11102 bucket
->origTargetNamespace
!= NULL
) {
11103 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
11104 XML_SCHEMAP_SRC_INCLUDE
,
11106 "The target namespace of the included/redefined schema "
11107 "'%s' has to be absent or the same as the "
11108 "including/redefining schema's target namespace",
11109 schemaLocation
, NULL
);
11112 bucket
->targetNamespace
= pctxt
->targetNamespace
;
11116 * Parse the schema.
11118 if (bucket
&& (!bucket
->parsed
) && (bucket
->doc
!= NULL
)) {
11120 /* TODO: Get rid of this flag on the schema itself. */
11121 if ((schema
->flags
& XML_SCHEMAS_INCLUDING_CONVERT_NS
) == 0) {
11122 schema
->flags
|= XML_SCHEMAS_INCLUDING_CONVERT_NS
;
11126 xmlSchemaParseNewDoc(pctxt
, schema
, bucket
);
11127 /* Restore chameleon flag. */
11128 if (isChameleon
&& (!wasChameleon
))
11129 schema
->flags
^= XML_SCHEMAS_INCLUDING_CONVERT_NS
;
11132 * And now for the children...
11134 child
= node
->children
;
11135 if (type
== XML_SCHEMA_SCHEMA_REDEFINE
) {
11137 * Parse (simpleType | complexType | group | attributeGroup))*
11139 pctxt
->redefined
= bucket
;
11141 * How to proceed if the redefined schema was not located?
11143 pctxt
->isRedefine
= 1;
11144 while (IS_SCHEMA(child
, "annotation") ||
11145 IS_SCHEMA(child
, "simpleType") ||
11146 IS_SCHEMA(child
, "complexType") ||
11147 IS_SCHEMA(child
, "group") ||
11148 IS_SCHEMA(child
, "attributeGroup")) {
11149 if (IS_SCHEMA(child
, "annotation")) {
11151 * TODO: discard or not?
11153 } else if (IS_SCHEMA(child
, "simpleType")) {
11154 xmlSchemaParseSimpleType(pctxt
, schema
, child
, 1);
11155 } else if (IS_SCHEMA(child
, "complexType")) {
11156 xmlSchemaParseComplexType(pctxt
, schema
, child
, 1);
11157 /* hasRedefinitions = 1; */
11158 } else if (IS_SCHEMA(child
, "group")) {
11159 /* hasRedefinitions = 1; */
11160 xmlSchemaParseModelGroupDefinition(pctxt
,
11162 } else if (IS_SCHEMA(child
, "attributeGroup")) {
11163 /* hasRedefinitions = 1; */
11164 xmlSchemaParseAttributeGroupDefinition(pctxt
, schema
,
11167 child
= child
->next
;
11169 pctxt
->redefined
= NULL
;
11170 pctxt
->isRedefine
= 0;
11172 if (IS_SCHEMA(child
, "annotation")) {
11174 * TODO: discard or not?
11176 child
= child
->next
;
11179 if (child
!= NULL
) {
11180 res
= XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
;
11181 if (type
== XML_SCHEMA_SCHEMA_REDEFINE
) {
11182 xmlSchemaPContentErr(pctxt
, res
,
11183 NULL
, node
, child
, NULL
,
11184 "(annotation | (simpleType | complexType | group | attributeGroup))*");
11186 xmlSchemaPContentErr(pctxt
, res
,
11187 NULL
, node
, child
, NULL
,
11194 return(pctxt
->err
);
11198 xmlSchemaParseRedefine(xmlSchemaParserCtxtPtr pctxt
, xmlSchemaPtr schema
,
11202 #ifndef ENABLE_REDEFINE
11206 res
= xmlSchemaParseIncludeOrRedefine(pctxt
, schema
, node
,
11207 XML_SCHEMA_SCHEMA_REDEFINE
);
11214 xmlSchemaParseInclude(xmlSchemaParserCtxtPtr pctxt
, xmlSchemaPtr schema
,
11219 res
= xmlSchemaParseIncludeOrRedefine(pctxt
, schema
, node
,
11220 XML_SCHEMA_SCHEMA_INCLUDE
);
11227 * xmlSchemaParseModelGroup:
11228 * @ctxt: a schema validation context
11229 * @schema: the schema being built
11230 * @node: a subtree containing XML Schema informations
11231 * @type: the "compositor" type
11232 * @particleNeeded: if a a model group with a particle
11234 * parse a XML schema Sequence definition.
11235 * Applies parts of:
11236 * Schema Representation Constraint:
11237 * Redefinition Constraints and Semantics (src-redefine)
11238 * (6.1), (6.1.1), (6.1.2)
11240 * Schema Component Constraint:
11241 * All Group Limited (cos-all-limited) (2)
11242 * TODO: Actually this should go to component-level checks,
11243 * but is done here due to performance. Move it to an other layer
11244 * is schema construction via an API is implemented.
11246 * *WARNING* this interface is highly subject to change
11248 * Returns -1 in case of error, 0 if the declaration is improper and
11249 * 1 in case of success.
11251 static xmlSchemaTreeItemPtr
11252 xmlSchemaParseModelGroup(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
11253 xmlNodePtr node
, xmlSchemaTypeType type
,
11256 xmlSchemaModelGroupPtr item
;
11257 xmlSchemaParticlePtr particle
= NULL
;
11258 xmlNodePtr child
= NULL
;
11260 int min
= 1, max
= 1, isElemRef
, hasRefs
= 0;
11262 if ((ctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
11265 * Create a model group with the given compositor.
11267 item
= xmlSchemaAddModelGroup(ctxt
, schema
, type
, node
);
11271 if (withParticle
) {
11272 if (type
== XML_SCHEMA_TYPE_ALL
) {
11273 min
= xmlGetMinOccurs(ctxt
, node
, 0, 1, 1, "(0 | 1)");
11274 max
= xmlGetMaxOccurs(ctxt
, node
, 1, 1, 1, "1");
11276 /* choice + sequence */
11277 min
= xmlGetMinOccurs(ctxt
, node
, 0, -1, 1, "xs:nonNegativeInteger");
11278 max
= xmlGetMaxOccurs(ctxt
, node
, 0, UNBOUNDED
, 1,
11279 "(xs:nonNegativeInteger | unbounded)");
11281 xmlSchemaPCheckParticleCorrect_2(ctxt
, NULL
, node
, min
, max
);
11283 * Create a particle
11285 particle
= xmlSchemaAddParticle(ctxt
, node
, min
, max
);
11286 if (particle
== NULL
)
11288 particle
->children
= (xmlSchemaTreeItemPtr
) item
;
11290 * Check for illegal attributes.
11292 attr
= node
->properties
;
11293 while (attr
!= NULL
) {
11294 if (attr
->ns
== NULL
) {
11295 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"id")) &&
11296 (!xmlStrEqual(attr
->name
, BAD_CAST
"maxOccurs")) &&
11297 (!xmlStrEqual(attr
->name
, BAD_CAST
"minOccurs"))) {
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
);
11309 * Check for illegal attributes.
11311 attr
= node
->properties
;
11312 while (attr
!= NULL
) {
11313 if (attr
->ns
== NULL
) {
11314 if (!xmlStrEqual(attr
->name
, BAD_CAST
"id")) {
11315 xmlSchemaPIllegalAttrErr(ctxt
,
11316 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
11318 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
11319 xmlSchemaPIllegalAttrErr(ctxt
,
11320 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
11327 * Extract and validate attributes.
11329 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
11331 * And now for the children...
11333 child
= node
->children
;
11334 if (IS_SCHEMA(child
, "annotation")) {
11335 item
->annot
= xmlSchemaParseAnnotation(ctxt
, child
, 1);
11336 child
= child
->next
;
11338 if (type
== XML_SCHEMA_TYPE_ALL
) {
11339 xmlSchemaParticlePtr part
, last
= NULL
;
11341 while (IS_SCHEMA(child
, "element")) {
11342 part
= (xmlSchemaParticlePtr
) xmlSchemaParseElement(ctxt
,
11343 schema
, child
, &isElemRef
, 0);
11345 * SPEC cos-all-limited (2)
11346 * "The {max occurs} of all the particles in the {particles}
11347 * of the ('all') group must be 0 or 1.
11349 if (part
!= NULL
) {
11352 if (part
->minOccurs
> 1) {
11353 xmlSchemaPCustomErr(ctxt
,
11354 XML_SCHEMAP_COS_ALL_LIMITED
,
11356 "Invalid value for minOccurs (must be 0 or 1)",
11359 part
->minOccurs
= 1;
11361 if (part
->maxOccurs
> 1) {
11362 xmlSchemaPCustomErr(ctxt
,
11363 XML_SCHEMAP_COS_ALL_LIMITED
,
11365 "Invalid value for maxOccurs (must be 0 or 1)",
11368 part
->maxOccurs
= 1;
11371 item
->children
= (xmlSchemaTreeItemPtr
) part
;
11373 last
->next
= (xmlSchemaTreeItemPtr
) part
;
11376 child
= child
->next
;
11378 if (child
!= NULL
) {
11379 xmlSchemaPContentErr(ctxt
,
11380 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
11381 NULL
, node
, child
, NULL
,
11382 "(annotation?, (annotation?, element*)");
11385 /* choice + sequence */
11386 xmlSchemaTreeItemPtr part
= NULL
, last
= NULL
;
11388 while ((IS_SCHEMA(child
, "element")) ||
11389 (IS_SCHEMA(child
, "group")) ||
11390 (IS_SCHEMA(child
, "any")) ||
11391 (IS_SCHEMA(child
, "choice")) ||
11392 (IS_SCHEMA(child
, "sequence"))) {
11394 if (IS_SCHEMA(child
, "element")) {
11395 part
= (xmlSchemaTreeItemPtr
)
11396 xmlSchemaParseElement(ctxt
, schema
, child
, &isElemRef
, 0);
11397 if (part
&& isElemRef
)
11399 } else if (IS_SCHEMA(child
, "group")) {
11401 xmlSchemaParseModelGroupDefRef(ctxt
, schema
, child
);
11405 * Handle redefinitions.
11407 if (ctxt
->isRedefine
&& ctxt
->redef
&&
11408 (ctxt
->redef
->item
->type
== XML_SCHEMA_TYPE_GROUP
) &&
11409 part
&& part
->children
)
11411 if ((xmlSchemaGetQNameRefName(part
->children
) ==
11412 ctxt
->redef
->refName
) &&
11413 (xmlSchemaGetQNameRefTargetNs(part
->children
) ==
11414 ctxt
->redef
->refTargetNs
))
11417 * SPEC src-redefine:
11418 * (6.1) "If it has a <group> among its contents at
11419 * some level the `actual value` of whose ref
11420 * [attribute] is the same as the `actual value` of
11421 * its own name attribute plus target namespace, then
11422 * all of the following must be true:"
11423 * (6.1.1) "It must have exactly one such group."
11425 if (ctxt
->redefCounter
!= 0) {
11426 xmlChar
*str
= NULL
;
11428 xmlSchemaCustomErr(ACTXT_CAST ctxt
,
11429 XML_SCHEMAP_SRC_REDEFINE
, child
, NULL
,
11430 "The redefining model group definition "
11431 "'%s' must not contain more than one "
11432 "reference to the redefined definition",
11433 xmlSchemaFormatQName(&str
,
11434 ctxt
->redef
->refTargetNs
,
11435 ctxt
->redef
->refName
),
11439 } else if (((WXS_PARTICLE(part
))->minOccurs
!= 1) ||
11440 ((WXS_PARTICLE(part
))->maxOccurs
!= 1))
11442 xmlChar
*str
= NULL
;
11444 * SPEC src-redefine:
11445 * (6.1.2) "The `actual value` of both that
11446 * group's minOccurs and maxOccurs [attribute]
11447 * must be 1 (or `absent`).
11449 xmlSchemaCustomErr(ACTXT_CAST ctxt
,
11450 XML_SCHEMAP_SRC_REDEFINE
, child
, NULL
,
11451 "The redefining model group definition "
11452 "'%s' must not contain a reference to the "
11453 "redefined definition with a "
11454 "maxOccurs/minOccurs other than 1",
11455 xmlSchemaFormatQName(&str
,
11456 ctxt
->redef
->refTargetNs
,
11457 ctxt
->redef
->refName
),
11462 ctxt
->redef
->reference
= WXS_BASIC_CAST part
;
11463 ctxt
->redefCounter
++;
11466 } else if (IS_SCHEMA(child
, "any")) {
11467 part
= (xmlSchemaTreeItemPtr
)
11468 xmlSchemaParseAny(ctxt
, schema
, child
);
11469 } else if (IS_SCHEMA(child
, "choice")) {
11470 part
= xmlSchemaParseModelGroup(ctxt
, schema
, child
,
11471 XML_SCHEMA_TYPE_CHOICE
, 1);
11472 } else if (IS_SCHEMA(child
, "sequence")) {
11473 part
= xmlSchemaParseModelGroup(ctxt
, schema
, child
,
11474 XML_SCHEMA_TYPE_SEQUENCE
, 1);
11476 if (part
!= NULL
) {
11478 item
->children
= part
;
11483 child
= child
->next
;
11485 if (child
!= NULL
) {
11486 xmlSchemaPContentErr(ctxt
,
11487 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
11488 NULL
, node
, child
, NULL
,
11489 "(annotation?, (element | group | choice | sequence | any)*)");
11492 if ((max
== 0) && (min
== 0))
11496 * We need to resolve references.
11498 WXS_ADD_PENDING(ctxt
, item
);
11501 return ((xmlSchemaTreeItemPtr
) particle
);
11503 return ((xmlSchemaTreeItemPtr
) item
);
11507 * xmlSchemaParseRestriction:
11508 * @ctxt: a schema validation context
11509 * @schema: the schema being built
11510 * @node: a subtree containing XML Schema informations
11512 * parse a XML schema Restriction definition
11513 * *WARNING* this interface is highly subject to change
11515 * Returns the type definition or NULL in case of error
11517 static xmlSchemaTypePtr
11518 xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
11519 xmlNodePtr node
, xmlSchemaTypeType parentType
)
11521 xmlSchemaTypePtr type
;
11522 xmlNodePtr child
= NULL
;
11525 if ((ctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
11527 /* Not a component, don't create it. */
11528 type
= ctxt
->ctxtType
;
11529 type
->flags
|= XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION
;
11532 * Check for illegal attributes.
11534 attr
= node
->properties
;
11535 while (attr
!= NULL
) {
11536 if (attr
->ns
== NULL
) {
11537 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"id")) &&
11538 (!xmlStrEqual(attr
->name
, BAD_CAST
"base"))) {
11539 xmlSchemaPIllegalAttrErr(ctxt
,
11540 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
11542 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
11543 xmlSchemaPIllegalAttrErr(ctxt
,
11544 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
11549 * Extract and validate attributes.
11551 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
11556 * Extract the base type. The "base" attribute is mandatory if inside
11557 * a complex type or if redefining.
11559 * SPEC (1.2) "...otherwise (<restriction> has no <simpleType> "
11560 * among its [children]), the simple type definition which is
11561 * the {content type} of the type definition `resolved` to by
11562 * the `actual value` of the base [attribute]"
11564 if (xmlSchemaPValAttrQName(ctxt
, schema
, NULL
, node
, "base",
11565 &(type
->baseNs
), &(type
->base
)) == 0)
11567 if ((type
->base
== NULL
) && (type
->type
== XML_SCHEMA_TYPE_COMPLEX
)) {
11568 xmlSchemaPMissingAttrErr(ctxt
,
11569 XML_SCHEMAP_S4S_ATTR_MISSING
,
11570 NULL
, node
, "base", NULL
);
11571 } else if ((ctxt
->isRedefine
) &&
11572 (type
->flags
& XML_SCHEMAS_TYPE_GLOBAL
))
11574 if (type
->base
== NULL
) {
11575 xmlSchemaPMissingAttrErr(ctxt
,
11576 XML_SCHEMAP_S4S_ATTR_MISSING
,
11577 NULL
, node
, "base", NULL
);
11578 } else if ((! xmlStrEqual(type
->base
, type
->name
)) ||
11579 (! xmlStrEqual(type
->baseNs
, type
->targetNamespace
)))
11581 xmlChar
*str1
= NULL
, *str2
= NULL
;
11583 * REDEFINE: SPEC src-redefine (5)
11584 * "Within the [children], each <simpleType> must have a
11585 * <restriction> among its [children] ... the `actual value` of
11586 * whose base [attribute] must be the same as the `actual value`
11587 * of its own name attribute plus target namespace;"
11589 xmlSchemaPCustomErrExt(ctxt
, XML_SCHEMAP_SRC_REDEFINE
,
11590 NULL
, node
, "This is a redefinition, but the QName "
11591 "value '%s' of the 'base' attribute does not match the "
11592 "type's designation '%s'",
11593 xmlSchemaFormatQName(&str1
, type
->baseNs
, type
->base
),
11594 xmlSchemaFormatQName(&str2
, type
->targetNamespace
,
11595 type
->name
), NULL
);
11596 FREE_AND_NULL(str1
);
11597 FREE_AND_NULL(str2
);
11598 /* Avoid confusion and erase the values. */
11600 type
->baseNs
= NULL
;
11605 * And now for the children...
11607 child
= node
->children
;
11608 if (IS_SCHEMA(child
, "annotation")) {
11610 * Add the annotation to the simple type ancestor.
11612 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr
) type
,
11613 xmlSchemaParseAnnotation(ctxt
, child
, 1));
11614 child
= child
->next
;
11616 if (parentType
== XML_SCHEMA_TYPE_SIMPLE
) {
11618 * Corresponds to <simpleType><restriction><simpleType>.
11620 if (IS_SCHEMA(child
, "simpleType")) {
11621 if (type
->base
!= NULL
) {
11623 * src-restriction-base-or-simpleType
11624 * Either the base [attribute] or the simpleType [child] of the
11625 * <restriction> element must be present, but not both.
11627 xmlSchemaPContentErr(ctxt
,
11628 XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE
,
11630 "The attribute 'base' and the <simpleType> child are "
11631 "mutually exclusive", NULL
);
11633 type
->baseType
= (xmlSchemaTypePtr
)
11634 xmlSchemaParseSimpleType(ctxt
, schema
, child
, 0);
11636 child
= child
->next
;
11637 } else if (type
->base
== NULL
) {
11638 xmlSchemaPContentErr(ctxt
,
11639 XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE
,
11641 "Either the attribute 'base' or a <simpleType> child "
11642 "must be present", NULL
);
11644 } else if (parentType
== XML_SCHEMA_TYPE_COMPLEX_CONTENT
) {
11646 * Corresponds to <complexType><complexContent><restriction>...
11649 * Model groups <all>, <choice> and <sequence>.
11651 if (IS_SCHEMA(child
, "all")) {
11652 type
->subtypes
= (xmlSchemaTypePtr
)
11653 xmlSchemaParseModelGroup(ctxt
, schema
, child
,
11654 XML_SCHEMA_TYPE_ALL
, 1);
11655 child
= child
->next
;
11656 } else if (IS_SCHEMA(child
, "choice")) {
11657 type
->subtypes
= (xmlSchemaTypePtr
)
11658 xmlSchemaParseModelGroup(ctxt
,
11659 schema
, child
, XML_SCHEMA_TYPE_CHOICE
, 1);
11660 child
= child
->next
;
11661 } else if (IS_SCHEMA(child
, "sequence")) {
11662 type
->subtypes
= (xmlSchemaTypePtr
)
11663 xmlSchemaParseModelGroup(ctxt
, schema
, child
,
11664 XML_SCHEMA_TYPE_SEQUENCE
, 1);
11665 child
= child
->next
;
11667 * Model group reference <group>.
11669 } else if (IS_SCHEMA(child
, "group")) {
11670 type
->subtypes
= (xmlSchemaTypePtr
)
11671 xmlSchemaParseModelGroupDefRef(ctxt
, schema
, child
);
11673 * Note that the reference will be resolved in
11674 * xmlSchemaResolveTypeReferences();
11676 child
= child
->next
;
11678 } else if (parentType
== XML_SCHEMA_TYPE_SIMPLE_CONTENT
) {
11680 * Corresponds to <complexType><simpleContent><restriction>...
11682 * "1.1 the simple type definition corresponding to the <simpleType>
11683 * among the [children] of <restriction> if there is one;"
11685 if (IS_SCHEMA(child
, "simpleType")) {
11687 * We will store the to-be-restricted simple type in
11688 * type->contentTypeDef *temporarily*.
11690 type
->contentTypeDef
= (xmlSchemaTypePtr
)
11691 xmlSchemaParseSimpleType(ctxt
, schema
, child
, 0);
11692 if ( type
->contentTypeDef
== NULL
)
11694 child
= child
->next
;
11698 if ((parentType
== XML_SCHEMA_TYPE_SIMPLE
) ||
11699 (parentType
== XML_SCHEMA_TYPE_SIMPLE_CONTENT
)) {
11700 xmlSchemaFacetPtr facet
, lastfacet
= NULL
;
11702 * Corresponds to <complexType><simpleContent><restriction>...
11703 * <simpleType><restriction>...
11707 * Add the facets to the simple type ancestor.
11710 * TODO: Datatypes: 4.1.3 Constraints on XML Representation of
11711 * Simple Type Definition Schema Representation Constraint:
11712 * *Single Facet Value*
11714 while ((IS_SCHEMA(child
, "minInclusive")) ||
11715 (IS_SCHEMA(child
, "minExclusive")) ||
11716 (IS_SCHEMA(child
, "maxInclusive")) ||
11717 (IS_SCHEMA(child
, "maxExclusive")) ||
11718 (IS_SCHEMA(child
, "totalDigits")) ||
11719 (IS_SCHEMA(child
, "fractionDigits")) ||
11720 (IS_SCHEMA(child
, "pattern")) ||
11721 (IS_SCHEMA(child
, "enumeration")) ||
11722 (IS_SCHEMA(child
, "whiteSpace")) ||
11723 (IS_SCHEMA(child
, "length")) ||
11724 (IS_SCHEMA(child
, "maxLength")) ||
11725 (IS_SCHEMA(child
, "minLength"))) {
11726 facet
= xmlSchemaParseFacet(ctxt
, schema
, child
);
11727 if (facet
!= NULL
) {
11728 if (lastfacet
== NULL
)
11729 type
->facets
= facet
;
11731 lastfacet
->next
= facet
;
11733 lastfacet
->next
= NULL
;
11735 child
= child
->next
;
11738 * Create links for derivation and validation.
11740 if (type
->facets
!= NULL
) {
11741 xmlSchemaFacetLinkPtr facetLink
, lastFacetLink
= NULL
;
11743 facet
= type
->facets
;
11745 facetLink
= (xmlSchemaFacetLinkPtr
)
11746 xmlMalloc(sizeof(xmlSchemaFacetLink
));
11747 if (facetLink
== NULL
) {
11748 xmlSchemaPErrMemory(ctxt
, "allocating a facet link", NULL
);
11749 xmlFree(facetLink
);
11752 facetLink
->facet
= facet
;
11753 facetLink
->next
= NULL
;
11754 if (lastFacetLink
== NULL
)
11755 type
->facetSet
= facetLink
;
11757 lastFacetLink
->next
= facetLink
;
11758 lastFacetLink
= facetLink
;
11759 facet
= facet
->next
;
11760 } while (facet
!= NULL
);
11763 if (type
->type
== XML_SCHEMA_TYPE_COMPLEX
) {
11765 * Attribute uses/declarations.
11767 if (xmlSchemaParseLocalAttributes(ctxt
, schema
, &child
,
11768 (xmlSchemaItemListPtr
*) &(type
->attrUses
),
11769 XML_SCHEMA_TYPE_RESTRICTION
, NULL
) == -1)
11772 * Attribute wildcard.
11774 if (IS_SCHEMA(child
, "anyAttribute")) {
11775 type
->attributeWildcard
=
11776 xmlSchemaParseAnyAttribute(ctxt
, schema
, child
);
11777 child
= child
->next
;
11780 if (child
!= NULL
) {
11781 if (parentType
== XML_SCHEMA_TYPE_COMPLEX_CONTENT
) {
11782 xmlSchemaPContentErr(ctxt
,
11783 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
11784 NULL
, node
, child
, NULL
,
11785 "annotation?, (group | all | choice | sequence)?, "
11786 "((attribute | attributeGroup)*, anyAttribute?))");
11787 } else if (parentType
== XML_SCHEMA_TYPE_SIMPLE_CONTENT
) {
11788 xmlSchemaPContentErr(ctxt
,
11789 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
11790 NULL
, node
, child
, NULL
,
11791 "(annotation?, (simpleType?, (minExclusive | minInclusive | "
11792 "maxExclusive | maxInclusive | totalDigits | fractionDigits | "
11793 "length | minLength | maxLength | enumeration | whiteSpace | "
11794 "pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))");
11797 xmlSchemaPContentErr(ctxt
,
11798 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
11799 NULL
, node
, child
, NULL
,
11800 "(annotation?, (simpleType?, (minExclusive | minInclusive | "
11801 "maxExclusive | maxInclusive | totalDigits | fractionDigits | "
11802 "length | minLength | maxLength | enumeration | whiteSpace | "
11810 * xmlSchemaParseExtension:
11811 * @ctxt: a schema validation context
11812 * @schema: the schema being built
11813 * @node: a subtree containing XML Schema informations
11815 * Parses an <extension>, which is found inside a
11816 * <simpleContent> or <complexContent>.
11817 * *WARNING* this interface is highly subject to change.
11819 * TODO: Returns the type definition or NULL in case of error
11821 static xmlSchemaTypePtr
11822 xmlSchemaParseExtension(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
11823 xmlNodePtr node
, xmlSchemaTypeType parentType
)
11825 xmlSchemaTypePtr type
;
11826 xmlNodePtr child
= NULL
;
11829 if ((ctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
11831 /* Not a component, don't create it. */
11832 type
= ctxt
->ctxtType
;
11833 type
->flags
|= XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION
;
11836 * Check for illegal attributes.
11838 attr
= node
->properties
;
11839 while (attr
!= NULL
) {
11840 if (attr
->ns
== NULL
) {
11841 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"id")) &&
11842 (!xmlStrEqual(attr
->name
, BAD_CAST
"base"))) {
11843 xmlSchemaPIllegalAttrErr(ctxt
,
11844 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
11846 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
11847 xmlSchemaPIllegalAttrErr(ctxt
,
11848 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
11853 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
11856 * Attribute "base" - mandatory.
11858 if ((xmlSchemaPValAttrQName(ctxt
, schema
, NULL
, node
,
11859 "base", &(type
->baseNs
), &(type
->base
)) == 0) &&
11860 (type
->base
== NULL
)) {
11861 xmlSchemaPMissingAttrErr(ctxt
,
11862 XML_SCHEMAP_S4S_ATTR_MISSING
,
11863 NULL
, node
, "base", NULL
);
11866 * And now for the children...
11868 child
= node
->children
;
11869 if (IS_SCHEMA(child
, "annotation")) {
11871 * Add the annotation to the type ancestor.
11873 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr
) type
,
11874 xmlSchemaParseAnnotation(ctxt
, child
, 1));
11875 child
= child
->next
;
11877 if (parentType
== XML_SCHEMA_TYPE_COMPLEX_CONTENT
) {
11879 * Corresponds to <complexType><complexContent><extension>... and:
11881 * Model groups <all>, <choice>, <sequence> and <group>.
11883 if (IS_SCHEMA(child
, "all")) {
11884 type
->subtypes
= (xmlSchemaTypePtr
)
11885 xmlSchemaParseModelGroup(ctxt
, schema
,
11886 child
, XML_SCHEMA_TYPE_ALL
, 1);
11887 child
= child
->next
;
11888 } else if (IS_SCHEMA(child
, "choice")) {
11889 type
->subtypes
= (xmlSchemaTypePtr
)
11890 xmlSchemaParseModelGroup(ctxt
, schema
,
11891 child
, XML_SCHEMA_TYPE_CHOICE
, 1);
11892 child
= child
->next
;
11893 } else if (IS_SCHEMA(child
, "sequence")) {
11894 type
->subtypes
= (xmlSchemaTypePtr
)
11895 xmlSchemaParseModelGroup(ctxt
, schema
,
11896 child
, XML_SCHEMA_TYPE_SEQUENCE
, 1);
11897 child
= child
->next
;
11898 } else if (IS_SCHEMA(child
, "group")) {
11899 type
->subtypes
= (xmlSchemaTypePtr
)
11900 xmlSchemaParseModelGroupDefRef(ctxt
, schema
, child
);
11902 * Note that the reference will be resolved in
11903 * xmlSchemaResolveTypeReferences();
11905 child
= child
->next
;
11908 if (child
!= NULL
) {
11910 * Attribute uses/declarations.
11912 if (xmlSchemaParseLocalAttributes(ctxt
, schema
, &child
,
11913 (xmlSchemaItemListPtr
*) &(type
->attrUses
),
11914 XML_SCHEMA_TYPE_EXTENSION
, NULL
) == -1)
11917 * Attribute wildcard.
11919 if (IS_SCHEMA(child
, "anyAttribute")) {
11920 ctxt
->ctxtType
->attributeWildcard
=
11921 xmlSchemaParseAnyAttribute(ctxt
, schema
, child
);
11922 child
= child
->next
;
11925 if (child
!= NULL
) {
11926 if (parentType
== XML_SCHEMA_TYPE_COMPLEX_CONTENT
) {
11927 /* Complex content extension. */
11928 xmlSchemaPContentErr(ctxt
,
11929 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
11930 NULL
, node
, child
, NULL
,
11931 "(annotation?, ((group | all | choice | sequence)?, "
11932 "((attribute | attributeGroup)*, anyAttribute?)))");
11934 /* Simple content extension. */
11935 xmlSchemaPContentErr(ctxt
,
11936 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
11937 NULL
, node
, child
, NULL
,
11938 "(annotation?, ((attribute | attributeGroup)*, "
11939 "anyAttribute?))");
11946 * xmlSchemaParseSimpleContent:
11947 * @ctxt: a schema validation context
11948 * @schema: the schema being built
11949 * @node: a subtree containing XML Schema informations
11951 * parse a XML schema SimpleContent definition
11952 * *WARNING* this interface is highly subject to change
11954 * Returns the type definition or NULL in case of error
11957 xmlSchemaParseSimpleContent(xmlSchemaParserCtxtPtr ctxt
,
11958 xmlSchemaPtr schema
, xmlNodePtr node
,
11959 int *hasRestrictionOrExtension
)
11961 xmlSchemaTypePtr type
;
11962 xmlNodePtr child
= NULL
;
11965 if ((ctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
) ||
11966 (hasRestrictionOrExtension
== NULL
))
11968 *hasRestrictionOrExtension
= 0;
11969 /* Not a component, don't create it. */
11970 type
= ctxt
->ctxtType
;
11971 type
->contentType
= XML_SCHEMA_CONTENT_SIMPLE
;
11973 * Check for illegal attributes.
11975 attr
= node
->properties
;
11976 while (attr
!= NULL
) {
11977 if (attr
->ns
== NULL
) {
11978 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"id"))) {
11979 xmlSchemaPIllegalAttrErr(ctxt
,
11980 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
11982 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
11983 xmlSchemaPIllegalAttrErr(ctxt
,
11984 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
11989 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
11992 * And now for the children...
11994 child
= node
->children
;
11995 if (IS_SCHEMA(child
, "annotation")) {
11997 * Add the annotation to the complex type ancestor.
11999 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr
) type
,
12000 xmlSchemaParseAnnotation(ctxt
, child
, 1));
12001 child
= child
->next
;
12003 if (child
== NULL
) {
12004 xmlSchemaPContentErr(ctxt
,
12005 XML_SCHEMAP_S4S_ELEM_MISSING
,
12006 NULL
, node
, NULL
, NULL
,
12007 "(annotation?, (restriction | extension))");
12009 if (child
== NULL
) {
12010 xmlSchemaPContentErr(ctxt
,
12011 XML_SCHEMAP_S4S_ELEM_MISSING
,
12012 NULL
, node
, NULL
, NULL
,
12013 "(annotation?, (restriction | extension))");
12015 if (IS_SCHEMA(child
, "restriction")) {
12016 xmlSchemaParseRestriction(ctxt
, schema
, child
,
12017 XML_SCHEMA_TYPE_SIMPLE_CONTENT
);
12018 (*hasRestrictionOrExtension
) = 1;
12019 child
= child
->next
;
12020 } else if (IS_SCHEMA(child
, "extension")) {
12021 xmlSchemaParseExtension(ctxt
, schema
, child
,
12022 XML_SCHEMA_TYPE_SIMPLE_CONTENT
);
12023 (*hasRestrictionOrExtension
) = 1;
12024 child
= child
->next
;
12026 if (child
!= NULL
) {
12027 xmlSchemaPContentErr(ctxt
,
12028 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
12029 NULL
, node
, child
, NULL
,
12030 "(annotation?, (restriction | extension))");
12036 * xmlSchemaParseComplexContent:
12037 * @ctxt: a schema validation context
12038 * @schema: the schema being built
12039 * @node: a subtree containing XML Schema informations
12041 * parse a XML schema ComplexContent definition
12042 * *WARNING* this interface is highly subject to change
12044 * Returns the type definition or NULL in case of error
12047 xmlSchemaParseComplexContent(xmlSchemaParserCtxtPtr ctxt
,
12048 xmlSchemaPtr schema
, xmlNodePtr node
,
12049 int *hasRestrictionOrExtension
)
12051 xmlSchemaTypePtr type
;
12052 xmlNodePtr child
= NULL
;
12055 if ((ctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
) ||
12056 (hasRestrictionOrExtension
== NULL
))
12058 *hasRestrictionOrExtension
= 0;
12059 /* Not a component, don't create it. */
12060 type
= ctxt
->ctxtType
;
12062 * Check for illegal attributes.
12064 attr
= node
->properties
;
12065 while (attr
!= NULL
) {
12066 if (attr
->ns
== NULL
) {
12067 if ((!xmlStrEqual(attr
->name
, BAD_CAST
"id")) &&
12068 (!xmlStrEqual(attr
->name
, BAD_CAST
"mixed")))
12070 xmlSchemaPIllegalAttrErr(ctxt
,
12071 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
12073 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
12074 xmlSchemaPIllegalAttrErr(ctxt
,
12075 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
12080 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
12083 * Set the 'mixed' on the complex type ancestor.
12085 if (xmlGetBooleanProp(ctxt
, node
, "mixed", 0)) {
12086 if ((type
->flags
& XML_SCHEMAS_TYPE_MIXED
) == 0)
12087 type
->flags
|= XML_SCHEMAS_TYPE_MIXED
;
12089 child
= node
->children
;
12090 if (IS_SCHEMA(child
, "annotation")) {
12092 * Add the annotation to the complex type ancestor.
12094 xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr
) type
,
12095 xmlSchemaParseAnnotation(ctxt
, child
, 1));
12096 child
= child
->next
;
12098 if (child
== NULL
) {
12099 xmlSchemaPContentErr(ctxt
,
12100 XML_SCHEMAP_S4S_ELEM_MISSING
,
12102 NULL
, "(annotation?, (restriction | extension))");
12104 if (child
== NULL
) {
12105 xmlSchemaPContentErr(ctxt
,
12106 XML_SCHEMAP_S4S_ELEM_MISSING
,
12108 NULL
, "(annotation?, (restriction | extension))");
12110 if (IS_SCHEMA(child
, "restriction")) {
12111 xmlSchemaParseRestriction(ctxt
, schema
, child
,
12112 XML_SCHEMA_TYPE_COMPLEX_CONTENT
);
12113 (*hasRestrictionOrExtension
) = 1;
12114 child
= child
->next
;
12115 } else if (IS_SCHEMA(child
, "extension")) {
12116 xmlSchemaParseExtension(ctxt
, schema
, child
,
12117 XML_SCHEMA_TYPE_COMPLEX_CONTENT
);
12118 (*hasRestrictionOrExtension
) = 1;
12119 child
= child
->next
;
12121 if (child
!= NULL
) {
12122 xmlSchemaPContentErr(ctxt
,
12123 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
12125 NULL
, "(annotation?, (restriction | extension))");
12131 * xmlSchemaParseComplexType:
12132 * @ctxt: a schema validation context
12133 * @schema: the schema being built
12134 * @node: a subtree containing XML Schema informations
12136 * parse a XML schema Complex Type definition
12137 * *WARNING* this interface is highly subject to change
12139 * Returns the type definition or NULL in case of error
12141 static xmlSchemaTypePtr
12142 xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr ctxt
, xmlSchemaPtr schema
,
12143 xmlNodePtr node
, int topLevel
)
12145 xmlSchemaTypePtr type
, ctxtType
;
12146 xmlNodePtr child
= NULL
;
12147 const xmlChar
*name
= NULL
;
12149 const xmlChar
*attrValue
;
12150 #ifdef ENABLE_NAMED_LOCALS
12153 int final
= 0, block
= 0, hasRestrictionOrExtension
= 0;
12156 if ((ctxt
== NULL
) || (schema
== NULL
) || (node
== NULL
))
12159 ctxtType
= ctxt
->ctxtType
;
12162 attr
= xmlSchemaGetPropNode(node
, "name");
12163 if (attr
== NULL
) {
12164 xmlSchemaPMissingAttrErr(ctxt
,
12165 XML_SCHEMAP_S4S_ATTR_MISSING
, NULL
, node
, "name", NULL
);
12167 } else if (xmlSchemaPValAttrNode(ctxt
, NULL
, attr
,
12168 xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME
), &name
) != 0) {
12173 if (topLevel
== 0) {
12175 * Parse as local complex type definition.
12177 #ifdef ENABLE_NAMED_LOCALS
12178 snprintf(buf
, 39, "#CT%d", ctxt
->counter
++ + 1);
12179 type
= xmlSchemaAddType(ctxt
, schema
,
12180 XML_SCHEMA_TYPE_COMPLEX
,
12181 xmlDictLookup(ctxt
->dict
, (const xmlChar
*)buf
, -1),
12182 ctxt
->targetNamespace
, node
, 0);
12184 type
= xmlSchemaAddType(ctxt
, schema
,
12185 XML_SCHEMA_TYPE_COMPLEX
,
12186 NULL
, ctxt
->targetNamespace
, node
, 0);
12192 type
->type
= XML_SCHEMA_TYPE_COMPLEX
;
12194 * TODO: We need the target namespace.
12198 * Parse as global complex type definition.
12200 type
= xmlSchemaAddType(ctxt
, schema
,
12201 XML_SCHEMA_TYPE_COMPLEX
,
12202 name
, ctxt
->targetNamespace
, node
, 1);
12206 type
->type
= XML_SCHEMA_TYPE_COMPLEX
;
12207 type
->flags
|= XML_SCHEMAS_TYPE_GLOBAL
;
12209 type
->targetNamespace
= ctxt
->targetNamespace
;
12211 * Handle attributes.
12213 attr
= node
->properties
;
12214 while (attr
!= NULL
) {
12215 if (attr
->ns
== NULL
) {
12216 if (xmlStrEqual(attr
->name
, BAD_CAST
"id")) {
12220 xmlSchemaPValAttrID(ctxt
, node
, BAD_CAST
"id");
12221 } else if (xmlStrEqual(attr
->name
, BAD_CAST
"mixed")) {
12223 * Attribute "mixed".
12225 if (xmlSchemaPGetBoolNodeValue(ctxt
,
12226 NULL
, (xmlNodePtr
) attr
))
12227 type
->flags
|= XML_SCHEMAS_TYPE_MIXED
;
12228 } else if (topLevel
) {
12230 * Attributes of global complex type definitions.
12232 if (xmlStrEqual(attr
->name
, BAD_CAST
"name")) {
12234 } else if (xmlStrEqual(attr
->name
, BAD_CAST
"abstract")) {
12236 * Attribute "abstract".
12238 if (xmlSchemaPGetBoolNodeValue(ctxt
,
12239 NULL
, (xmlNodePtr
) attr
))
12240 type
->flags
|= XML_SCHEMAS_TYPE_ABSTRACT
;
12241 } else if (xmlStrEqual(attr
->name
, BAD_CAST
"final")) {
12243 * Attribute "final".
12245 attrValue
= xmlSchemaGetNodeContent(ctxt
,
12246 (xmlNodePtr
) attr
);
12247 if (xmlSchemaPValAttrBlockFinal(attrValue
,
12250 XML_SCHEMAS_TYPE_FINAL_EXTENSION
,
12251 XML_SCHEMAS_TYPE_FINAL_RESTRICTION
,
12254 xmlSchemaPSimpleTypeErr(ctxt
,
12255 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
12256 NULL
, (xmlNodePtr
) attr
, NULL
,
12257 "(#all | List of (extension | restriction))",
12258 attrValue
, NULL
, NULL
, NULL
);
12261 } else if (xmlStrEqual(attr
->name
, BAD_CAST
"block")) {
12263 * Attribute "block".
12265 attrValue
= xmlSchemaGetNodeContent(ctxt
,
12266 (xmlNodePtr
) attr
);
12267 if (xmlSchemaPValAttrBlockFinal(attrValue
, &(type
->flags
),
12269 XML_SCHEMAS_TYPE_BLOCK_EXTENSION
,
12270 XML_SCHEMAS_TYPE_BLOCK_RESTRICTION
,
12271 -1, -1, -1) != 0) {
12272 xmlSchemaPSimpleTypeErr(ctxt
,
12273 XML_SCHEMAP_S4S_ATTR_INVALID_VALUE
,
12274 NULL
, (xmlNodePtr
) attr
, NULL
,
12275 "(#all | List of (extension | restriction)) ",
12276 attrValue
, NULL
, NULL
, NULL
);
12280 xmlSchemaPIllegalAttrErr(ctxt
,
12281 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
12284 xmlSchemaPIllegalAttrErr(ctxt
,
12285 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
12287 } else if (xmlStrEqual(attr
->ns
->href
, xmlSchemaNs
)) {
12288 xmlSchemaPIllegalAttrErr(ctxt
,
12289 XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED
, NULL
, attr
);
12295 * Apply default "block" values.
12297 if (schema
->flags
& XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION
)
12298 type
->flags
|= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION
;
12299 if (schema
->flags
& XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION
)
12300 type
->flags
|= XML_SCHEMAS_TYPE_BLOCK_EXTENSION
;
12304 * Apply default "block" values.
12306 if (schema
->flags
& XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION
)
12307 type
->flags
|= XML_SCHEMAS_TYPE_FINAL_RESTRICTION
;
12308 if (schema
->flags
& XML_SCHEMAS_FINAL_DEFAULT_EXTENSION
)
12309 type
->flags
|= XML_SCHEMAS_TYPE_FINAL_EXTENSION
;
12312 * And now for the children...
12314 child
= node
->children
;
12315 if (IS_SCHEMA(child
, "annotation")) {
12316 type
->annot
= xmlSchemaParseAnnotation(ctxt
, child
, 1);
12317 child
= child
->next
;
12319 ctxt
->ctxtType
= type
;
12320 if (IS_SCHEMA(child
, "simpleContent")) {
12322 * <complexType><simpleContent>...
12324 * Specifying mixed='true' when the <simpleContent>
12325 * alternative is chosen has no effect
12327 if (type
->flags
& XML_SCHEMAS_TYPE_MIXED
)
12328 type
->flags
^= XML_SCHEMAS_TYPE_MIXED
;
12329 xmlSchemaParseSimpleContent(ctxt
, schema
, child
,
12330 &hasRestrictionOrExtension
);
12331 child
= child
->next
;
12332 } else if (IS_SCHEMA(child
, "complexContent")) {
12334 * <complexType><complexContent>...
12336 type
->contentType
= XML_SCHEMA_CONTENT_EMPTY
;
12337 xmlSchemaParseComplexContent(ctxt
, schema
, child
,
12338 &hasRestrictionOrExtension
);
12339 child
= child
->next
;
12342 * E.g <complexType><sequence>... or <complexType><attribute>... etc.
12345 * "...the third alternative (neither <simpleContent> nor
12346 * <complexContent>) is chosen. This case is understood as shorthand
12347 * for complex content restricting the `ur-type definition`, and the
12348 * details of the mappings should be modified as necessary.
12350 type
->baseType
= xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE
);
12351 type
->flags
|= XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION
;
12353 * Parse model groups.
12355 if (IS_SCHEMA(child
, "all")) {
12356 type
->subtypes
= (xmlSchemaTypePtr
)
12357 xmlSchemaParseModelGroup(ctxt
, schema
, child
,
12358 XML_SCHEMA_TYPE_ALL
, 1);
12359 child
= child
->next
;
12360 } else if (IS_SCHEMA(child
, "choice")) {
12361 type
->subtypes
= (xmlSchemaTypePtr
)
12362 xmlSchemaParseModelGroup(ctxt
, schema
, child
,
12363 XML_SCHEMA_TYPE_CHOICE
, 1);
12364 child
= child
->next
;
12365 } else if (IS_SCHEMA(child
, "sequence")) {
12366 type
->subtypes
= (xmlSchemaTypePtr
)
12367 xmlSchemaParseModelGroup(ctxt
, schema
, child
,
12368 XML_SCHEMA_TYPE_SEQUENCE
, 1);
12369 child
= child
->next
;
12370 } else if (IS_SCHEMA(child
, "group")) {
12371 type
->subtypes
= (xmlSchemaTypePtr
)
12372 xmlSchemaParseModelGroupDefRef(ctxt
, schema
, child
);
12374 * Note that the reference will be resolved in
12375 * xmlSchemaResolveTypeReferences();
12377 child
= child
->next
;
12380 * Parse attribute decls/refs.
12382 if (xmlSchemaParseLocalAttributes(ctxt
, schema
, &child
,
12383 (xmlSchemaItemListPtr
*) &(type
->attrUses
),
12384 XML_SCHEMA_TYPE_RESTRICTION
, NULL
) == -1)
12387 * Parse attribute wildcard.
12389 if (IS_SCHEMA(child
, "anyAttribute")) {
12390 type
->attributeWildcard
= xmlSchemaParseAnyAttribute(ctxt
, schema
, child
);
12391 child
= child
->next
;
12394 if (child
!= NULL
) {
12395 xmlSchemaPContentErr(ctxt
,
12396 XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED
,
12398 NULL
, "(annotation?, (simpleContent | complexContent | "
12399 "((group | all | choice | sequence)?, ((attribute | "
12400 "attributeGroup)*, anyAttribute?))))");
12403 * REDEFINE: SPEC src-redefine (5)
12405 if (topLevel
&& ctxt
->isRedefine
&& (! hasRestrictionOrExtension
)) {
12406 xmlSchemaPCustomErr(ctxt
, XML_SCHEMAP_SRC_REDEFINE
,
12407 NULL
, node
, "This is a redefinition, thus the "
12408 "<complexType> must have a <restriction> or <extension> "
12409 "grand-child", NULL
);
12411 ctxt
->ctxtType
= ctxtType
;
12415 /************************************************************************
12417 * Validating using Schemas *
12419 ************************************************************************/
12421 /************************************************************************
12423 * Reading/Writing Schemas *
12425 ************************************************************************/
12427 #if 0 /* Will be enabled if it is clear what options are needed. */
12429 * xmlSchemaParserCtxtSetOptions:
12430 * @ctxt: a schema parser context
12431 * @options: a combination of xmlSchemaParserOption
12433 * Sets the options to be used during the parse.
12435 * Returns 0 in case of success, -1 in case of an
12439 xmlSchemaParserCtxtSetOptions(xmlSchemaParserCtxtPtr ctxt
,
12448 * WARNING: Change the start value if adding to the
12449 * xmlSchemaParseOption.
12451 for (i
= 1; i
< (int) sizeof(int) * 8; i
++) {
12452 if (options
& 1<<i
) {
12456 ctxt
->options
= options
;
12461 * xmlSchemaValidCtxtGetOptions:
12462 * @ctxt: a schema parser context
12464 * Returns the option combination of the parser context.
12467 xmlSchemaParserCtxtGetOptions(xmlSchemaParserCtxtPtr ctxt
)
12473 return (ctxt
->options
);
12478 * xmlSchemaNewParserCtxt:
12479 * @URL: the location of the schema
12481 * Create an XML Schemas parse context for that file/resource expected
12482 * to contain an XML Schemas file.
12484 * Returns the parser context or NULL in case of error
12486 xmlSchemaParserCtxtPtr
12487 xmlSchemaNewParserCtxt(const char *URL
)
12489 xmlSchemaParserCtxtPtr ret
;
12494 ret
= xmlSchemaParserCtxtCreate();
12497 ret
->dict
= xmlDictCreate();
12498 ret
->URL
= xmlDictLookup(ret
->dict
, (const xmlChar
*) URL
, -1);
12503 * xmlSchemaNewMemParserCtxt:
12504 * @buffer: a pointer to a char array containing the schemas
12505 * @size: the size of the array
12507 * Create an XML Schemas parse context for that memory buffer expected
12508 * to contain an XML Schemas file.
12510 * Returns the parser context or NULL in case of error
12512 xmlSchemaParserCtxtPtr
12513 xmlSchemaNewMemParserCtxt(const char *buffer
, int size
)
12515 xmlSchemaParserCtxtPtr ret
;
12517 if ((buffer
== NULL
) || (size
<= 0))
12519 ret
= xmlSchemaParserCtxtCreate();
12522 ret
->buffer
= buffer
;
12524 ret
->dict
= xmlDictCreate();
12529 * xmlSchemaNewDocParserCtxt:
12530 * @doc: a preparsed document tree
12532 * Create an XML Schemas parse context for that document.
12533 * NB. The document may be modified during the parsing process.
12535 * Returns the parser context or NULL in case of error
12537 xmlSchemaParserCtxtPtr
12538 xmlSchemaNewDocParserCtxt(xmlDocPtr doc
)
12540 xmlSchemaParserCtxtPtr ret
;
12544 ret
= xmlSchemaParserCtxtCreate();
12548 ret
->dict
= xmlDictCreate();
12549 /* The application has responsibility for the document */
12556 * xmlSchemaFreeParserCtxt:
12557 * @ctxt: the schema parser context
12559 * Free the resources associated to the schema parser context
12562 xmlSchemaFreeParserCtxt(xmlSchemaParserCtxtPtr ctxt
)
12566 if (ctxt
->doc
!= NULL
&& !ctxt
->preserve
)
12567 xmlFreeDoc(ctxt
->doc
);
12568 if (ctxt
->vctxt
!= NULL
) {
12569 xmlSchemaFreeValidCtxt(ctxt
->vctxt
);
12571 if (ctxt
->ownsConstructor
&& (ctxt
->constructor
!= NULL
)) {
12572 xmlSchemaConstructionCtxtFree(ctxt
->constructor
);
12573 ctxt
->constructor
= NULL
;
12574 ctxt
->ownsConstructor
= 0;
12576 if (ctxt
->attrProhibs
!= NULL
)
12577 xmlSchemaItemListFree(ctxt
->attrProhibs
);
12578 xmlDictFree(ctxt
->dict
);
12582 /************************************************************************
12584 * Building the content models *
12586 ************************************************************************/
12589 * xmlSchemaBuildContentModelForSubstGroup:
12591 * Returns 1 if nillable, 0 otherwise
12594 xmlSchemaBuildContentModelForSubstGroup(xmlSchemaParserCtxtPtr pctxt
,
12595 xmlSchemaParticlePtr particle
, int counter
, xmlAutomataStatePtr end
)
12597 xmlAutomataStatePtr start
, tmp
;
12598 xmlSchemaElementPtr elemDecl
, member
;
12599 xmlSchemaSubstGroupPtr substGroup
;
12603 elemDecl
= (xmlSchemaElementPtr
) particle
->children
;
12605 * Wrap the substitution group with a CHOICE.
12607 start
= pctxt
->state
;
12609 end
= xmlAutomataNewState(pctxt
->am
);
12610 substGroup
= xmlSchemaSubstGroupGet(pctxt
, elemDecl
);
12611 if (substGroup
== NULL
) {
12612 xmlSchemaPErr(pctxt
, WXS_ITEM_NODE(particle
),
12613 XML_SCHEMAP_INTERNAL
,
12614 "Internal error: xmlSchemaBuildContentModelForSubstGroup, "
12615 "declaration is marked having a subst. group but none "
12616 "available.\n", elemDecl
->name
, NULL
);
12619 if (counter
>= 0) {
12621 * NOTE that we put the declaration in, even if it's abstract.
12622 * However, an error will be raised during *validation* if an element
12623 * information item shall be validated against an abstract element
12626 tmp
= xmlAutomataNewCountedTrans(pctxt
->am
, start
, NULL
, counter
);
12627 xmlAutomataNewTransition2(pctxt
->am
, tmp
, end
,
12628 elemDecl
->name
, elemDecl
->targetNamespace
, elemDecl
);
12630 * Add subst. group members.
12632 for (i
= 0; i
< substGroup
->members
->nbItems
; i
++) {
12633 member
= (xmlSchemaElementPtr
) substGroup
->members
->items
[i
];
12634 xmlAutomataNewTransition2(pctxt
->am
, tmp
, end
,
12635 member
->name
, member
->targetNamespace
, member
);
12637 } else if (particle
->maxOccurs
== 1) {
12639 * NOTE that we put the declaration in, even if it's abstract,
12641 xmlAutomataNewEpsilon(pctxt
->am
,
12642 xmlAutomataNewTransition2(pctxt
->am
,
12644 elemDecl
->name
, elemDecl
->targetNamespace
, elemDecl
), end
);
12646 * Add subst. group members.
12648 for (i
= 0; i
< substGroup
->members
->nbItems
; i
++) {
12649 member
= (xmlSchemaElementPtr
) substGroup
->members
->items
[i
];
12651 * NOTE: This fixes bug #341150. xmlAutomataNewOnceTrans2()
12652 * was incorrectly used instead of xmlAutomataNewTransition2()
12653 * (seems like a copy&paste bug from the XML_SCHEMA_TYPE_ALL
12654 * section in xmlSchemaBuildAContentModel() ).
12655 * TODO: Check if xmlAutomataNewOnceTrans2() was instead
12656 * intended for the above "counter" section originally. I.e.,
12657 * check xs:all with subst-groups.
12659 * tmp = xmlAutomataNewOnceTrans2(pctxt->am, start, NULL,
12660 * member->name, member->targetNamespace,
12663 tmp
= xmlAutomataNewTransition2(pctxt
->am
, start
, NULL
,
12664 member
->name
, member
->targetNamespace
, member
);
12665 xmlAutomataNewEpsilon(pctxt
->am
, tmp
, end
);
12668 xmlAutomataStatePtr hop
;
12669 int maxOccurs
= particle
->maxOccurs
== UNBOUNDED
?
12670 UNBOUNDED
: particle
->maxOccurs
- 1;
12671 int minOccurs
= particle
->minOccurs
< 1 ? 0 : particle
->minOccurs
- 1;
12674 xmlAutomataNewCounter(pctxt
->am
, minOccurs
,
12676 hop
= xmlAutomataNewState(pctxt
->am
);
12678 xmlAutomataNewEpsilon(pctxt
->am
,
12679 xmlAutomataNewTransition2(pctxt
->am
,
12681 elemDecl
->name
, elemDecl
->targetNamespace
, elemDecl
),
12684 * Add subst. group members.
12686 for (i
= 0; i
< substGroup
->members
->nbItems
; i
++) {
12687 member
= (xmlSchemaElementPtr
) substGroup
->members
->items
[i
];
12688 xmlAutomataNewEpsilon(pctxt
->am
,
12689 xmlAutomataNewTransition2(pctxt
->am
,
12691 member
->name
, member
->targetNamespace
, member
),
12694 xmlAutomataNewCountedTrans(pctxt
->am
, hop
, start
, counter
);
12695 xmlAutomataNewCounterTrans(pctxt
->am
, hop
, end
, counter
);
12697 if (particle
->minOccurs
== 0) {
12698 xmlAutomataNewEpsilon(pctxt
->am
, start
, end
);
12701 pctxt
->state
= end
;
12706 * xmlSchemaBuildContentModelForElement:
12708 * Returns 1 if nillable, 0 otherwise
12711 xmlSchemaBuildContentModelForElement(xmlSchemaParserCtxtPtr ctxt
,
12712 xmlSchemaParticlePtr particle
)
12716 if (((xmlSchemaElementPtr
) particle
->children
)->flags
&
12717 XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD
) {
12719 * Substitution groups.
12721 ret
= xmlSchemaBuildContentModelForSubstGroup(ctxt
, particle
, -1, NULL
);
12723 xmlSchemaElementPtr elemDecl
;
12724 xmlAutomataStatePtr start
;
12726 elemDecl
= (xmlSchemaElementPtr
) particle
->children
;
12728 if (elemDecl
->flags
& XML_SCHEMAS_ELEM_ABSTRACT
)
12730 if (particle
->maxOccurs
== 1) {
12731 start
= ctxt
->state
;
12732 ctxt
->state
= xmlAutomataNewTransition2(ctxt
->am
, start
, NULL
,
12733 elemDecl
->name
, elemDecl
->targetNamespace
, elemDecl
);
12734 } else if ((particle
->maxOccurs
>= UNBOUNDED
) &&
12735 (particle
->minOccurs
< 2)) {
12736 /* Special case. */
12737 start
= ctxt
->state
;
12738 ctxt
->state
= xmlAutomataNewTransition2(ctxt
->am
, start
, NULL
,
12739 elemDecl
->name
, elemDecl
->targetNamespace
, elemDecl
);
12740 ctxt
->state
= xmlAutomataNewTransition2(ctxt
->am
, ctxt
->state
, ctxt
->state
,
12741 elemDecl
->name
, elemDecl
->targetNamespace
, elemDecl
);
12744 int maxOccurs
= particle
->maxOccurs
== UNBOUNDED
?
12745 UNBOUNDED
: particle
->maxOccurs
- 1;
12746 int minOccurs
= particle
->minOccurs
< 1 ?
12747 0 : particle
->minOccurs
- 1;
12749 start
= xmlAutomataNewEpsilon(ctxt
->am
, ctxt
->state
, NULL
);
12750 counter
= xmlAutomataNewCounter(ctxt
->am
, minOccurs
, maxOccurs
);
12751 ctxt
->state
= xmlAutomataNewTransition2(ctxt
->am
, start
, NULL
,
12752 elemDecl
->name
, elemDecl
->targetNamespace
, elemDecl
);
12753 xmlAutomataNewCountedTrans(ctxt
->am
, ctxt
->state
, start
, counter
);
12754 ctxt
->state
= xmlAutomataNewCounterTrans(ctxt
->am
, ctxt
->state
,
12757 if (particle
->minOccurs
== 0) {
12758 xmlAutomataNewEpsilon(ctxt
->am
, start
, ctxt
->state
);
12766 * xmlSchemaBuildAContentModel:
12767 * @ctxt: the schema parser context
12768 * @particle: the particle component
12769 * @name: the complex type's name whose content is being built
12771 * Create the automaton for the {content type} of a complex type.
12773 * Returns 1 if the content is nillable, 0 otherwise
12776 xmlSchemaBuildAContentModel(xmlSchemaParserCtxtPtr pctxt
,
12777 xmlSchemaParticlePtr particle
)
12781 if (particle
== NULL
) {
12782 PERROR_INT("xmlSchemaBuildAContentModel", "particle is NULL");
12785 if (particle
->children
== NULL
) {
12787 * Just return in this case. A missing "term" of the particle
12788 * might arise due to an invalid "term" component.
12793 switch (particle
->children
->type
) {
12794 case XML_SCHEMA_TYPE_ANY
: {
12795 xmlAutomataStatePtr start
, end
;
12796 xmlSchemaWildcardPtr wild
;
12797 xmlSchemaWildcardNsPtr ns
;
12799 wild
= (xmlSchemaWildcardPtr
) particle
->children
;
12801 start
= pctxt
->state
;
12802 end
= xmlAutomataNewState(pctxt
->am
);
12804 if (particle
->maxOccurs
== 1) {
12805 if (wild
->any
== 1) {
12807 * We need to add both transitions:
12809 * 1. the {"*", "*"} for elements in a namespace.
12812 xmlAutomataNewTransition2(pctxt
->am
,
12813 start
, NULL
, BAD_CAST
"*", BAD_CAST
"*", wild
);
12814 xmlAutomataNewEpsilon(pctxt
->am
, pctxt
->state
, end
);
12816 * 2. the {"*"} for elements in no namespace.
12819 xmlAutomataNewTransition2(pctxt
->am
,
12820 start
, NULL
, BAD_CAST
"*", NULL
, wild
);
12821 xmlAutomataNewEpsilon(pctxt
->am
, pctxt
->state
, end
);
12823 } else if (wild
->nsSet
!= NULL
) {
12826 pctxt
->state
= start
;
12827 pctxt
->state
= xmlAutomataNewTransition2(pctxt
->am
,
12828 pctxt
->state
, NULL
, BAD_CAST
"*", ns
->value
, wild
);
12829 xmlAutomataNewEpsilon(pctxt
->am
, pctxt
->state
, end
);
12831 } while (ns
!= NULL
);
12833 } else if (wild
->negNsSet
!= NULL
) {
12834 pctxt
->state
= xmlAutomataNewNegTrans(pctxt
->am
,
12835 start
, end
, BAD_CAST
"*", wild
->negNsSet
->value
,
12840 xmlAutomataStatePtr hop
;
12842 particle
->maxOccurs
== UNBOUNDED
? UNBOUNDED
:
12843 particle
->maxOccurs
- 1;
12845 particle
->minOccurs
< 1 ? 0 : particle
->minOccurs
- 1;
12847 counter
= xmlAutomataNewCounter(pctxt
->am
, minOccurs
, maxOccurs
);
12848 hop
= xmlAutomataNewState(pctxt
->am
);
12849 if (wild
->any
== 1) {
12851 xmlAutomataNewTransition2(pctxt
->am
,
12852 start
, NULL
, BAD_CAST
"*", BAD_CAST
"*", wild
);
12853 xmlAutomataNewEpsilon(pctxt
->am
, pctxt
->state
, hop
);
12855 xmlAutomataNewTransition2(pctxt
->am
,
12856 start
, NULL
, BAD_CAST
"*", NULL
, wild
);
12857 xmlAutomataNewEpsilon(pctxt
->am
, pctxt
->state
, hop
);
12858 } else if (wild
->nsSet
!= NULL
) {
12862 xmlAutomataNewTransition2(pctxt
->am
,
12863 start
, NULL
, BAD_CAST
"*", ns
->value
, wild
);
12864 xmlAutomataNewEpsilon(pctxt
->am
, pctxt
->state
, hop
);
12866 } while (ns
!= NULL
);
12868 } else if (wild
->negNsSet
!= NULL
) {
12869 pctxt
->state
= xmlAutomataNewNegTrans(pctxt
->am
,
12870 start
, hop
, BAD_CAST
"*", wild
->negNsSet
->value
,
12873 xmlAutomataNewCountedTrans(pctxt
->am
, hop
, start
, counter
);
12874 xmlAutomataNewCounterTrans(pctxt
->am
, hop
, end
, counter
);
12876 if (particle
->minOccurs
== 0) {
12877 xmlAutomataNewEpsilon(pctxt
->am
, start
, end
);
12880 pctxt
->state
= end
;
12883 case XML_SCHEMA_TYPE_ELEMENT
:
12884 ret
= xmlSchemaBuildContentModelForElement(pctxt
, particle
);
12886 case XML_SCHEMA_TYPE_SEQUENCE
:{
12887 xmlSchemaTreeItemPtr sub
;
12891 * If max and min occurances are default (1) then
12892 * simply iterate over the particles of the <sequence>.
12894 if ((particle
->minOccurs
== 1) && (particle
->maxOccurs
== 1)) {
12895 sub
= particle
->children
->children
;
12897 while (sub
!= NULL
) {
12898 tmp2
= xmlSchemaBuildAContentModel(pctxt
,
12899 (xmlSchemaParticlePtr
) sub
);
12900 if (tmp2
!= 1) ret
= 0;
12904 xmlAutomataStatePtr oldstate
= pctxt
->state
;
12906 if (particle
->maxOccurs
>= UNBOUNDED
) {
12907 if (particle
->minOccurs
> 1) {
12908 xmlAutomataStatePtr tmp
;
12911 pctxt
->state
= xmlAutomataNewEpsilon(pctxt
->am
,
12913 oldstate
= pctxt
->state
;
12915 counter
= xmlAutomataNewCounter(pctxt
->am
,
12916 particle
->minOccurs
- 1, UNBOUNDED
);
12918 sub
= particle
->children
->children
;
12919 while (sub
!= NULL
) {
12920 tmp2
= xmlSchemaBuildAContentModel(pctxt
,
12921 (xmlSchemaParticlePtr
) sub
);
12922 if (tmp2
!= 1) ret
= 0;
12925 tmp
= pctxt
->state
;
12926 xmlAutomataNewCountedTrans(pctxt
->am
, tmp
,
12927 oldstate
, counter
);
12929 xmlAutomataNewCounterTrans(pctxt
->am
, tmp
,
12932 xmlAutomataNewEpsilon(pctxt
->am
,
12933 oldstate
, pctxt
->state
);
12936 pctxt
->state
= xmlAutomataNewEpsilon(pctxt
->am
,
12938 oldstate
= pctxt
->state
;
12940 sub
= particle
->children
->children
;
12941 while (sub
!= NULL
) {
12942 tmp2
= xmlSchemaBuildAContentModel(pctxt
,
12943 (xmlSchemaParticlePtr
) sub
);
12944 if (tmp2
!= 1) ret
= 0;
12947 xmlAutomataNewEpsilon(pctxt
->am
, pctxt
->state
,
12950 * epsilon needed to block previous trans from
12951 * being allowed to enter back from another
12954 pctxt
->state
= xmlAutomataNewEpsilon(pctxt
->am
,
12955 pctxt
->state
, NULL
);
12956 if (particle
->minOccurs
== 0) {
12957 xmlAutomataNewEpsilon(pctxt
->am
,
12958 oldstate
, pctxt
->state
);
12962 } else if ((particle
->maxOccurs
> 1)
12963 || (particle
->minOccurs
> 1)) {
12964 xmlAutomataStatePtr tmp
;
12967 pctxt
->state
= xmlAutomataNewEpsilon(pctxt
->am
,
12969 oldstate
= pctxt
->state
;
12971 counter
= xmlAutomataNewCounter(pctxt
->am
,
12972 particle
->minOccurs
- 1,
12973 particle
->maxOccurs
- 1);
12975 sub
= particle
->children
->children
;
12976 while (sub
!= NULL
) {
12977 tmp2
= xmlSchemaBuildAContentModel(pctxt
,
12978 (xmlSchemaParticlePtr
) sub
);
12979 if (tmp2
!= 1) ret
= 0;
12982 tmp
= pctxt
->state
;
12983 xmlAutomataNewCountedTrans(pctxt
->am
,
12984 tmp
, oldstate
, counter
);
12986 xmlAutomataNewCounterTrans(pctxt
->am
, tmp
, NULL
,
12988 if ((particle
->minOccurs
== 0) || (ret
== 1)) {
12989 xmlAutomataNewEpsilon(pctxt
->am
,
12990 oldstate
, pctxt
->state
);
12994 sub
= particle
->children
->children
;
12995 while (sub
!= NULL
) {
12996 tmp2
= xmlSchemaBuildAContentModel(pctxt
,
12997 (xmlSchemaParticlePtr
) sub
);
12998 if (tmp2
!= 1) ret
= 0;
13003 * epsilon needed to block previous trans from
13004 * being allowed to enter back from another
13007 pctxt
->state
= xmlAutomataNewEpsilon(pctxt
->am
,
13008 pctxt
->state
, NULL
);
13010 if (particle
->minOccurs
== 0) {
13011 xmlAutomataNewEpsilon(pctxt
->am
, oldstate
,
13019 case XML_SCHEMA_TYPE_CHOICE
:{
13020 xmlSchemaTreeItemPtr sub
;
13021 xmlAutomataStatePtr start
, end
;
13024 start
= pctxt
->state
;
13025 end
= xmlAutomataNewState(pctxt
->am
);
13028 * iterate over the subtypes and remerge the end with an
13029 * epsilon transition
13031 if (particle
->maxOccurs
== 1) {
13032 sub
= particle
->children
->children
;
13033 while (sub
!= NULL
) {
13034 pctxt
->state
= start
;
13035 tmp2
= xmlSchemaBuildAContentModel(pctxt
,
13036 (xmlSchemaParticlePtr
) sub
);
13037 if (tmp2
== 1) ret
= 1;
13038 xmlAutomataNewEpsilon(pctxt
->am
, pctxt
->state
, end
);
13043 xmlAutomataStatePtr hop
, base
;
13044 int maxOccurs
= particle
->maxOccurs
== UNBOUNDED
?
13045 UNBOUNDED
: particle
->maxOccurs
- 1;
13047 particle
->minOccurs
< 1 ? 0 : particle
->minOccurs
- 1;
13050 * use a counter to keep track of the number of transtions
13051 * which went through the choice.
13054 xmlAutomataNewCounter(pctxt
->am
, minOccurs
, maxOccurs
);
13055 hop
= xmlAutomataNewState(pctxt
->am
);
13056 base
= xmlAutomataNewState(pctxt
->am
);
13058 sub
= particle
->children
->children
;
13059 while (sub
!= NULL
) {
13060 pctxt
->state
= base
;
13061 tmp2
= xmlSchemaBuildAContentModel(pctxt
,
13062 (xmlSchemaParticlePtr
) sub
);
13063 if (tmp2
== 1) ret
= 1;
13064 xmlAutomataNewEpsilon(pctxt
->am
, pctxt
->state
, hop
);
13067 xmlAutomataNewEpsilon(pctxt
->am
, start
, base
);
13068 xmlAutomataNewCountedTrans(pctxt
->am
, hop
, base
, counter
);
13069 xmlAutomataNewCounterTrans(pctxt
->am
, hop
, end
, counter
);
13071 xmlAutomataNewEpsilon(pctxt
->am
, base
, end
);
13073 if (particle
->minOccurs
== 0) {
13074 xmlAutomataNewEpsilon(pctxt
->am
, start
, end
);
13077 pctxt
->state
= end
;
13080 case XML_SCHEMA_TYPE_ALL
:{
13081 xmlAutomataStatePtr start
, tmp
;
13082 xmlSchemaParticlePtr sub
;
13083 xmlSchemaElementPtr elemDecl
;
13087 sub
= (xmlSchemaParticlePtr
) particle
->children
->children
;
13093 start
= pctxt
->state
;
13094 tmp
= xmlAutomataNewState(pctxt
->am
);
13095 xmlAutomataNewEpsilon(pctxt
->am
, pctxt
->state
, tmp
);
13096 pctxt
->state
= tmp
;
13097 while (sub
!= NULL
) {
13098 pctxt
->state
= tmp
;
13100 elemDecl
= (xmlSchemaElementPtr
) sub
->children
;
13101 if (elemDecl
== NULL
) {
13102 PERROR_INT("xmlSchemaBuildAContentModel",
13103 "<element> particle has no term");
13107 * NOTE: The {max occurs} of all the particles in the
13108 * {particles} of the group must be 0 or 1; this is
13109 * already ensured during the parse of the content of
13112 if (elemDecl
->flags
& XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD
) {
13116 * This is an abstract group, we need to share
13117 * the same counter for all the element transitions
13118 * derived from the group
13120 counter
= xmlAutomataNewCounter(pctxt
->am
,
13121 sub
->minOccurs
, sub
->maxOccurs
);
13122 xmlSchemaBuildContentModelForSubstGroup(pctxt
,
13123 sub
, counter
, pctxt
->state
);
13125 if ((sub
->minOccurs
== 1) &&
13126 (sub
->maxOccurs
== 1)) {
13127 xmlAutomataNewOnceTrans2(pctxt
->am
, pctxt
->state
,
13130 elemDecl
->targetNamespace
,
13132 } else if ((sub
->minOccurs
== 0) &&
13133 (sub
->maxOccurs
== 1)) {
13135 xmlAutomataNewCountTrans2(pctxt
->am
, pctxt
->state
,
13138 elemDecl
->targetNamespace
,
13144 sub
= (xmlSchemaParticlePtr
) sub
->next
;
13147 xmlAutomataNewAllTrans(pctxt
->am
, pctxt
->state
, NULL
, 0);
13148 if (particle
->minOccurs
== 0) {
13149 xmlAutomataNewEpsilon(pctxt
->am
, start
, pctxt
->state
);
13154 case XML_SCHEMA_TYPE_GROUP
:
13156 * If we hit a model group definition, then this means that
13157 * it was empty, thus was not substituted for the containing
13158 * model group. Just do nothing in this case.
13159 * TODO: But the group should be substituted and not occur at
13160 * all in the content model at this point. Fix this.
13165 xmlSchemaInternalErr2(ACTXT_CAST pctxt
,
13166 "xmlSchemaBuildAContentModel",
13167 "found unexpected term of type '%s' in content model",
13168 WXS_ITEM_TYPE_NAME(particle
->children
), NULL
);
13175 * xmlSchemaBuildContentModel:
13176 * @ctxt: the schema parser context
13177 * @type: the complex type definition
13178 * @name: the element name
13180 * Builds the content model of the complex type.
13183 xmlSchemaBuildContentModel(xmlSchemaTypePtr type
,
13184 xmlSchemaParserCtxtPtr ctxt
)
13186 if ((type
->type
!= XML_SCHEMA_TYPE_COMPLEX
) ||
13187 (type
->contModel
!= NULL
) ||
13188 ((type
->contentType
!= XML_SCHEMA_CONTENT_ELEMENTS
) &&
13189 (type
->contentType
!= XML_SCHEMA_CONTENT_MIXED
)))
13192 #ifdef DEBUG_CONTENT
13193 xmlGenericError(xmlGenericErrorContext
,
13194 "Building content model for %s\n", name
);
13197 ctxt
->am
= xmlNewAutomata();
13198 if (ctxt
->am
== NULL
) {
13199 xmlGenericError(xmlGenericErrorContext
,
13200 "Cannot create automata for complex type %s\n", type
->name
);
13203 ctxt
->state
= xmlAutomataGetInitState(ctxt
->am
);
13205 * Build the automaton.
13207 xmlSchemaBuildAContentModel(ctxt
, WXS_TYPE_PARTICLE(type
));
13208 xmlAutomataSetFinalState(ctxt
->am
, ctxt
->state
);
13209 type
->contModel
= xmlAutomataCompile(ctxt
->am
);
13210 if (type
->contModel
== NULL
) {
13211 xmlSchemaPCustomErr(ctxt
,
13212 XML_SCHEMAP_INTERNAL
,
13213 WXS_BASIC_CAST type
, type
->node
,
13214 "Failed to compile the content model", NULL
);
13215 } else if (xmlRegexpIsDeterminist(type
->contModel
) != 1) {
13216 xmlSchemaPCustomErr(ctxt
,
13217 XML_SCHEMAP_NOT_DETERMINISTIC
,
13218 /* XML_SCHEMAS_ERR_NOTDETERMINIST, */
13219 WXS_BASIC_CAST type
, type
->node
,
13220 "The content model is not determinist", NULL
);
13222 #ifdef DEBUG_CONTENT_REGEXP
13223 xmlGenericError(xmlGenericErrorContext
,
13224 "Content model of %s:\n", type
->name
);
13225 xmlRegexpPrint(stderr
, type
->contModel
);
13228 ctxt
->state
= NULL
;
13229 xmlFreeAutomata(ctxt
->am
);
13234 * xmlSchemaResolveElementReferences:
13235 * @elem: the schema element context
13236 * @ctxt: the schema parser context
13238 * Resolves the references of an element declaration
13239 * or particle, which has an element declaration as it's
13243 xmlSchemaResolveElementReferences(xmlSchemaElementPtr elemDecl
,
13244 xmlSchemaParserCtxtPtr ctxt
)
13246 if ((ctxt
== NULL
) || (elemDecl
== NULL
) ||
13247 ((elemDecl
!= NULL
) &&
13248 (elemDecl
->flags
& XML_SCHEMAS_ELEM_INTERNAL_RESOLVED
)))
13250 elemDecl
->flags
|= XML_SCHEMAS_ELEM_INTERNAL_RESOLVED
;
13252 if ((elemDecl
->subtypes
== NULL
) && (elemDecl
->namedType
!= NULL
)) {
13253 xmlSchemaTypePtr type
;
13255 /* (type definition) ... otherwise the type definition `resolved`
13256 * to by the `actual value` of the type [attribute] ...
13258 type
= xmlSchemaGetType(ctxt
->schema
, elemDecl
->namedType
,
13259 elemDecl
->namedTypeNs
);
13260 if (type
== NULL
) {
13261 xmlSchemaPResCompAttrErr(ctxt
,
13262 XML_SCHEMAP_SRC_RESOLVE
,
13263 WXS_BASIC_CAST elemDecl
, elemDecl
->node
,
13264 "type", elemDecl
->namedType
, elemDecl
->namedTypeNs
,
13265 XML_SCHEMA_TYPE_BASIC
, "type definition");
13267 elemDecl
->subtypes
= type
;
13269 if (elemDecl
->substGroup
!= NULL
) {
13270 xmlSchemaElementPtr substHead
;
13273 * FIXME TODO: Do we need a new field in _xmlSchemaElement for
13274 * substitutionGroup?
13276 substHead
= xmlSchemaGetElem(ctxt
->schema
, elemDecl
->substGroup
,
13277 elemDecl
->substGroupNs
);
13278 if (substHead
== NULL
) {
13279 xmlSchemaPResCompAttrErr(ctxt
,
13280 XML_SCHEMAP_SRC_RESOLVE
,
13281 WXS_BASIC_CAST elemDecl
, NULL
,
13282 "substitutionGroup", elemDecl
->substGroup
,
13283 elemDecl
->substGroupNs
, XML_SCHEMA_TYPE_ELEMENT
, NULL
);
13285 xmlSchemaResolveElementReferences(substHead
, ctxt
);
13287 * Set the "substitution group affiliation".
13288 * NOTE that now we use the "refDecl" field for this.
13290 WXS_SUBST_HEAD(elemDecl
) = substHead
;
13292 * The type definitions is set to:
13293 * SPEC "...the {type definition} of the element
13294 * declaration `resolved` to by the `actual value`
13295 * of the substitutionGroup [attribute], if present"
13297 if (elemDecl
->subtypes
== NULL
)
13298 elemDecl
->subtypes
= substHead
->subtypes
;
13302 * SPEC "The definition of anyType serves as the default type definition
13303 * for element declarations whose XML representation does not specify one."
13305 if ((elemDecl
->subtypes
== NULL
) &&
13306 (elemDecl
->namedType
== NULL
) &&
13307 (elemDecl
->substGroup
== NULL
))
13308 elemDecl
->subtypes
= xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE
);
13312 * xmlSchemaResolveUnionMemberTypes:
13313 * @ctxt: the schema parser context
13314 * @type: the schema simple type definition
13316 * Checks and builds the "member type definitions" property of the union
13317 * simple type. This handles part (1), part (2) is done in
13318 * xmlSchemaFinishMemberTypeDefinitionsProperty()
13320 * Returns -1 in case of an internal error, 0 otherwise.
13323 xmlSchemaResolveUnionMemberTypes(xmlSchemaParserCtxtPtr ctxt
,
13324 xmlSchemaTypePtr type
)
13327 xmlSchemaTypeLinkPtr link
, lastLink
, newLink
;
13328 xmlSchemaTypePtr memberType
;
13331 * SPEC (1) "If the <union> alternative is chosen, then [Definition:]
13332 * define the explicit members as the type definitions `resolved`
13333 * to by the items in the `actual value` of the memberTypes [attribute],
13334 * if any, followed by the type definitions corresponding to the
13335 * <simpleType>s among the [children] of <union>, if any."
13338 * Resolve references.
13340 link
= type
->memberTypes
;
13342 while (link
!= NULL
) {
13343 const xmlChar
*name
, *nsName
;
13345 name
= ((xmlSchemaQNameRefPtr
) link
->type
)->name
;
13346 nsName
= ((xmlSchemaQNameRefPtr
) link
->type
)->targetNamespace
;
13348 memberType
= xmlSchemaGetType(ctxt
->schema
, name
, nsName
);
13349 if ((memberType
== NULL
) || (! WXS_IS_SIMPLE(memberType
))) {
13350 xmlSchemaPResCompAttrErr(ctxt
, XML_SCHEMAP_SRC_RESOLVE
,
13351 WXS_BASIC_CAST type
, type
->node
, "memberTypes",
13352 name
, nsName
, XML_SCHEMA_TYPE_SIMPLE
, NULL
);
13354 * Remove the member type link.
13356 if (lastLink
== NULL
)
13357 type
->memberTypes
= link
->next
;
13359 lastLink
->next
= link
->next
;
13364 link
->type
= memberType
;
13370 * Add local simple types,
13372 memberType
= type
->subtypes
;
13373 while (memberType
!= NULL
) {
13374 link
= (xmlSchemaTypeLinkPtr
) xmlMalloc(sizeof(xmlSchemaTypeLink
));
13375 if (link
== NULL
) {
13376 xmlSchemaPErrMemory(ctxt
, "allocating a type link", NULL
);
13379 link
->type
= memberType
;
13381 if (lastLink
== NULL
)
13382 type
->memberTypes
= link
;
13384 lastLink
->next
= link
;
13386 memberType
= memberType
->next
;
13392 * xmlSchemaIsDerivedFromBuiltInType:
13393 * @ctxt: the schema parser context
13394 * @type: the type definition
13395 * @valType: the value type
13398 * Returns 1 if the type has the given value type, or
13399 * is derived from such a type.
13402 xmlSchemaIsDerivedFromBuiltInType(xmlSchemaTypePtr type
, int valType
)
13406 if (WXS_IS_COMPLEX(type
))
13408 if (type
->type
== XML_SCHEMA_TYPE_BASIC
) {
13409 if (type
->builtInType
== valType
)
13411 if ((type
->builtInType
== XML_SCHEMAS_ANYSIMPLETYPE
) ||
13412 (type
->builtInType
== XML_SCHEMAS_ANYTYPE
))
13414 return(xmlSchemaIsDerivedFromBuiltInType(type
->subtypes
, valType
));
13416 return(xmlSchemaIsDerivedFromBuiltInType(type
->subtypes
, valType
));
13421 * xmlSchemaIsDerivedFromBuiltInType:
13422 * @ctxt: the schema parser context
13423 * @type: the type definition
13424 * @valType: the value type
13427 * Returns 1 if the type has the given value type, or
13428 * is derived from such a type.
13431 xmlSchemaIsUserDerivedFromBuiltInType(xmlSchemaTypePtr type
, int valType
)
13435 if (WXS_IS_COMPLEX(type
))
13437 if (type
->type
== XML_SCHEMA_TYPE_BASIC
) {
13438 if (type
->builtInType
== valType
)
13442 return(xmlSchemaIsDerivedFromBuiltInType(type
->subtypes
, valType
));
13447 static xmlSchemaTypePtr
13448 xmlSchemaQueryBuiltInType(xmlSchemaTypePtr type
)
13452 if (WXS_IS_COMPLEX(type
))
13454 if (type
->type
== XML_SCHEMA_TYPE_BASIC
)
13456 return(xmlSchemaQueryBuiltInType(type
->subtypes
));
13461 * xmlSchemaGetPrimitiveType:
13462 * @type: the simpleType definition
13464 * Returns the primitive type of the given type or
13465 * NULL in case of error.
13467 static xmlSchemaTypePtr
13468 xmlSchemaGetPrimitiveType(xmlSchemaTypePtr type
)
13471 while (type
!= NULL
) {
13473 * Note that anySimpleType is actually not a primitive type
13474 * but we need that here.
13476 if ((type
->builtInType
== XML_SCHEMAS_ANYSIMPLETYPE
) ||
13477 (type
->flags
& XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE
))
13479 type
= type
->baseType
;
13487 * xmlSchemaGetBuiltInTypeAncestor:
13488 * @type: the simpleType definition
13490 * Returns the primitive type of the given type or
13491 * NULL in case of error.
13493 static xmlSchemaTypePtr
13494 xmlSchemaGetBuiltInTypeAncestor(xmlSchemaTypePtr type
)
13496 if (WXS_IS_LIST(type
) || WXS_IS_UNION(type
))
13498 while (type
!= NULL
) {
13499 if (type
->type
== XML_SCHEMA_TYPE_BASIC
)
13501 type
= type
->baseType
;
13509 * xmlSchemaCloneWildcardNsConstraints:
13510 * @ctxt: the schema parser context
13511 * @dest: the destination wildcard
13512 * @source: the source wildcard
13514 * Clones the namespace constraints of source
13515 * and assignes them to dest.
13516 * Returns -1 on internal error, 0 otherwise.
13519 xmlSchemaCloneWildcardNsConstraints(xmlSchemaParserCtxtPtr ctxt
,
13520 xmlSchemaWildcardPtr dest
,
13521 xmlSchemaWildcardPtr source
)
13523 xmlSchemaWildcardNsPtr cur
, tmp
, last
;
13525 if ((source
== NULL
) || (dest
== NULL
))
13527 dest
->any
= source
->any
;
13528 cur
= source
->nsSet
;
13530 while (cur
!= NULL
) {
13531 tmp
= xmlSchemaNewWildcardNsConstraint(ctxt
);
13534 tmp
->value
= cur
->value
;
13542 if (dest
->negNsSet
!= NULL
)
13543 xmlSchemaFreeWildcardNsSet(dest
->negNsSet
);
13544 if (source
->negNsSet
!= NULL
) {
13545 dest
->negNsSet
= xmlSchemaNewWildcardNsConstraint(ctxt
);
13546 if (dest
->negNsSet
== NULL
)
13548 dest
->negNsSet
->value
= source
->negNsSet
->value
;
13550 dest
->negNsSet
= NULL
;
13555 * xmlSchemaUnionWildcards:
13556 * @ctxt: the schema parser context
13557 * @completeWild: the first wildcard
13558 * @curWild: the second wildcard
13560 * Unions the namespace constraints of the given wildcards.
13561 * @completeWild will hold the resulting union.
13562 * Returns a positive error code on failure, -1 in case of an
13563 * internal error, 0 otherwise.
13566 xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt
,
13567 xmlSchemaWildcardPtr completeWild
,
13568 xmlSchemaWildcardPtr curWild
)
13570 xmlSchemaWildcardNsPtr cur
, curB
, tmp
;
13573 * 1 If O1 and O2 are the same value, then that value must be the
13576 if ((completeWild
->any
== curWild
->any
) &&
13577 ((completeWild
->nsSet
== NULL
) == (curWild
->nsSet
== NULL
)) &&
13578 ((completeWild
->negNsSet
== NULL
) == (curWild
->negNsSet
== NULL
))) {
13580 if ((completeWild
->negNsSet
== NULL
) ||
13581 (completeWild
->negNsSet
->value
== curWild
->negNsSet
->value
)) {
13583 if (completeWild
->nsSet
!= NULL
) {
13587 * Check equality of sets.
13589 cur
= completeWild
->nsSet
;
13590 while (cur
!= NULL
) {
13592 curB
= curWild
->nsSet
;
13593 while (curB
!= NULL
) {
13594 if (cur
->value
== curB
->value
) {
13611 * 2 If either O1 or O2 is any, then any must be the value
13613 if (completeWild
->any
!= curWild
->any
) {
13614 if (completeWild
->any
== 0) {
13615 completeWild
->any
= 1;
13616 if (completeWild
->nsSet
!= NULL
) {
13617 xmlSchemaFreeWildcardNsSet(completeWild
->nsSet
);
13618 completeWild
->nsSet
= NULL
;
13620 if (completeWild
->negNsSet
!= NULL
) {
13621 xmlFree(completeWild
->negNsSet
);
13622 completeWild
->negNsSet
= NULL
;
13628 * 3 If both O1 and O2 are sets of (namespace names or `absent`),
13629 * then the union of those sets must be the value.
13631 if ((completeWild
->nsSet
!= NULL
) && (curWild
->nsSet
!= NULL
)) {
13633 xmlSchemaWildcardNsPtr start
;
13635 cur
= curWild
->nsSet
;
13636 start
= completeWild
->nsSet
;
13637 while (cur
!= NULL
) {
13640 while (curB
!= NULL
) {
13641 if (cur
->value
== curB
->value
) {
13648 tmp
= xmlSchemaNewWildcardNsConstraint(ctxt
);
13651 tmp
->value
= cur
->value
;
13652 tmp
->next
= completeWild
->nsSet
;
13653 completeWild
->nsSet
= tmp
;
13661 * 4 If the two are negations of different values (namespace names
13662 * or `absent`), then a pair of not and `absent` must be the value.
13664 if ((completeWild
->negNsSet
!= NULL
) &&
13665 (curWild
->negNsSet
!= NULL
) &&
13666 (completeWild
->negNsSet
->value
!= curWild
->negNsSet
->value
)) {
13667 completeWild
->negNsSet
->value
= NULL
;
13674 if (((completeWild
->negNsSet
!= NULL
) &&
13675 (completeWild
->negNsSet
->value
!= NULL
) &&
13676 (curWild
->nsSet
!= NULL
)) ||
13677 ((curWild
->negNsSet
!= NULL
) &&
13678 (curWild
->negNsSet
->value
!= NULL
) &&
13679 (completeWild
->nsSet
!= NULL
))) {
13681 int nsFound
, absentFound
= 0;
13683 if (completeWild
->nsSet
!= NULL
) {
13684 cur
= completeWild
->nsSet
;
13685 curB
= curWild
->negNsSet
;
13687 cur
= curWild
->nsSet
;
13688 curB
= completeWild
->negNsSet
;
13691 while (cur
!= NULL
) {
13692 if (cur
->value
== NULL
)
13694 else if (cur
->value
== curB
->value
)
13696 if (nsFound
&& absentFound
)
13701 if (nsFound
&& absentFound
) {
13703 * 5.1 If the set S includes both the negated namespace
13704 * name and `absent`, then any must be the value.
13706 completeWild
->any
= 1;
13707 if (completeWild
->nsSet
!= NULL
) {
13708 xmlSchemaFreeWildcardNsSet(completeWild
->nsSet
);
13709 completeWild
->nsSet
= NULL
;
13711 if (completeWild
->negNsSet
!= NULL
) {
13712 xmlFree(completeWild
->negNsSet
);
13713 completeWild
->negNsSet
= NULL
;
13715 } else if (nsFound
&& (!absentFound
)) {
13717 * 5.2 If the set S includes the negated namespace name
13718 * but not `absent`, then a pair of not and `absent` must
13721 if (completeWild
->nsSet
!= NULL
) {
13722 xmlSchemaFreeWildcardNsSet(completeWild
->nsSet
);
13723 completeWild
->nsSet
= NULL
;
13725 if (completeWild
->negNsSet
== NULL
) {
13726 completeWild
->negNsSet
= xmlSchemaNewWildcardNsConstraint(ctxt
);
13727 if (completeWild
->negNsSet
== NULL
)
13730 completeWild
->negNsSet
->value
= NULL
;
13731 } else if ((!nsFound
) && absentFound
) {
13733 * 5.3 If the set S includes `absent` but not the negated
13734 * namespace name, then the union is not expressible.
13736 xmlSchemaPErr(ctxt
, completeWild
->node
,
13737 XML_SCHEMAP_UNION_NOT_EXPRESSIBLE
,
13738 "The union of the wilcard is not expressible.\n",
13740 return(XML_SCHEMAP_UNION_NOT_EXPRESSIBLE
);
13741 } else if ((!nsFound
) && (!absentFound
)) {
13743 * 5.4 If the set S does not include either the negated namespace
13744 * name or `absent`, then whichever of O1 or O2 is a pair of not
13745 * and a namespace name must be the value.
13747 if (completeWild
->negNsSet
== NULL
) {
13748 if (completeWild
->nsSet
!= NULL
) {
13749 xmlSchemaFreeWildcardNsSet(completeWild
->nsSet
);
13750 completeWild
->nsSet
= NULL
;
13752 completeWild
->negNsSet
= xmlSchemaNewWildcardNsConstraint(ctxt
);
13753 if (completeWild
->negNsSet
== NULL
)
13755 completeWild
->negNsSet
->value
= curWild
->negNsSet
->value
;
13763 if (((completeWild
->negNsSet
!= NULL
) &&
13764 (completeWild
->negNsSet
->value
== NULL
) &&
13765 (curWild
->nsSet
!= NULL
)) ||
13766 ((curWild
->negNsSet
!= NULL
) &&
13767 (curWild
->negNsSet
->value
== NULL
) &&
13768 (completeWild
->nsSet
!= NULL
))) {
13770 if (completeWild
->nsSet
!= NULL
) {
13771 cur
= completeWild
->nsSet
;
13773 cur
= curWild
->nsSet
;
13775 while (cur
!= NULL
) {
13776 if (cur
->value
== NULL
) {
13778 * 6.1 If the set S includes `absent`, then any must be the
13781 completeWild
->any
= 1;
13782 if (completeWild
->nsSet
!= NULL
) {
13783 xmlSchemaFreeWildcardNsSet(completeWild
->nsSet
);
13784 completeWild
->nsSet
= NULL
;
13786 if (completeWild
->negNsSet
!= NULL
) {
13787 xmlFree(completeWild
->negNsSet
);
13788 completeWild
->negNsSet
= NULL
;
13794 if (completeWild
->negNsSet
== NULL
) {
13796 * 6.2 If the set S does not include `absent`, then a pair of not
13797 * and `absent` must be the value.
13799 if (completeWild
->nsSet
!= NULL
) {
13800 xmlSchemaFreeWildcardNsSet(completeWild
->nsSet
);
13801 completeWild
->nsSet
= NULL
;
13803 completeWild
->negNsSet
= xmlSchemaNewWildcardNsConstraint(ctxt
);
13804 if (completeWild
->negNsSet
== NULL
)
13806 completeWild
->negNsSet
->value
= NULL
;
13815 * xmlSchemaIntersectWildcards:
13816 * @ctxt: the schema parser context
13817 * @completeWild: the first wildcard
13818 * @curWild: the second wildcard
13820 * Intersects the namespace constraints of the given wildcards.
13821 * @completeWild will hold the resulting intersection.
13822 * Returns a positive error code on failure, -1 in case of an
13823 * internal error, 0 otherwise.
13826 xmlSchemaIntersectWildcards(xmlSchemaParserCtxtPtr ctxt
,
13827 xmlSchemaWildcardPtr completeWild
,
13828 xmlSchemaWildcardPtr curWild
)
13830 xmlSchemaWildcardNsPtr cur
, curB
, prev
, tmp
;
13833 * 1 If O1 and O2 are the same value, then that value must be the
13836 if ((completeWild
->any
== curWild
->any
) &&
13837 ((completeWild
->nsSet
== NULL
) == (curWild
->nsSet
== NULL
)) &&
13838 ((completeWild
->negNsSet
== NULL
) == (curWild
->negNsSet
== NULL
))) {
13840 if ((completeWild
->negNsSet
== NULL
) ||
13841 (completeWild
->negNsSet
->value
== curWild
->negNsSet
->value
)) {
13843 if (completeWild
->nsSet
!= NULL
) {
13847 * Check equality of sets.
13849 cur
= completeWild
->nsSet
;
13850 while (cur
!= NULL
) {
13852 curB
= curWild
->nsSet
;
13853 while (curB
!= NULL
) {
13854 if (cur
->value
== curB
->value
) {
13871 * 2 If either O1 or O2 is any, then the other must be the value.
13873 if ((completeWild
->any
!= curWild
->any
) && (completeWild
->any
)) {
13874 if (xmlSchemaCloneWildcardNsConstraints(ctxt
, completeWild
, curWild
) == -1)
13879 * 3 If either O1 or O2 is a pair of not and a value (a namespace
13880 * name or `absent`) and the other is a set of (namespace names or
13881 * `absent`), then that set, minus the negated value if it was in
13882 * the set, minus `absent` if it was in the set, must be the value.
13884 if (((completeWild
->negNsSet
!= NULL
) && (curWild
->nsSet
!= NULL
)) ||
13885 ((curWild
->negNsSet
!= NULL
) && (completeWild
->nsSet
!= NULL
))) {
13886 const xmlChar
*neg
;
13888 if (completeWild
->nsSet
== NULL
) {
13889 neg
= completeWild
->negNsSet
->value
;
13890 if (xmlSchemaCloneWildcardNsConstraints(ctxt
, completeWild
, curWild
) == -1)
13893 neg
= curWild
->negNsSet
->value
;
13895 * Remove absent and negated.
13898 cur
= completeWild
->nsSet
;
13899 while (cur
!= NULL
) {
13900 if (cur
->value
== NULL
) {
13902 completeWild
->nsSet
= cur
->next
;
13904 prev
->next
= cur
->next
;
13913 cur
= completeWild
->nsSet
;
13914 while (cur
!= NULL
) {
13915 if (cur
->value
== neg
) {
13917 completeWild
->nsSet
= cur
->next
;
13919 prev
->next
= cur
->next
;
13931 * 4 If both O1 and O2 are sets of (namespace names or `absent`),
13932 * then the intersection of those sets must be the value.
13934 if ((completeWild
->nsSet
!= NULL
) && (curWild
->nsSet
!= NULL
)) {
13937 cur
= completeWild
->nsSet
;
13939 while (cur
!= NULL
) {
13941 curB
= curWild
->nsSet
;
13942 while (curB
!= NULL
) {
13943 if (cur
->value
== curB
->value
) {
13951 completeWild
->nsSet
= cur
->next
;
13953 prev
->next
= cur
->next
;
13965 /* 5 If the two are negations of different namespace names,
13966 * then the intersection is not expressible
13968 if ((completeWild
->negNsSet
!= NULL
) &&
13969 (curWild
->negNsSet
!= NULL
) &&
13970 (completeWild
->negNsSet
->value
!= curWild
->negNsSet
->value
) &&
13971 (completeWild
->negNsSet
->value
!= NULL
) &&
13972 (curWild
->negNsSet
->value
!= NULL
)) {
13974 xmlSchemaPErr(ctxt
, completeWild
->node
, XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE
,
13975 "The intersection of the wilcard is not expressible.\n",
13977 return(XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE
);
13980 * 6 If the one is a negation of a namespace name and the other
13981 * is a negation of `absent`, then the one which is the negation
13982 * of a namespace name must be the value.
13984 if ((completeWild
->negNsSet
!= NULL
) && (curWild
->negNsSet
!= NULL
) &&
13985 (completeWild
->negNsSet
->value
!= curWild
->negNsSet
->value
) &&
13986 (completeWild
->negNsSet
->value
== NULL
)) {
13987 completeWild
->negNsSet
->value
= curWild
->negNsSet
->value
;
13993 * xmlSchemaIsWildcardNsConstraintSubset:
13994 * @ctxt: the schema parser context
13995 * @sub: the first wildcard
13996 * @super: the second wildcard
13998 * Schema Component Constraint: Wildcard Subset (cos-ns-subset)
14000 * Returns 0 if the namespace constraint of @sub is an intensional
14001 * subset of @super, 1 otherwise.
14004 xmlSchemaCheckCOSNSSubset(xmlSchemaWildcardPtr sub
,
14005 xmlSchemaWildcardPtr super
)
14008 * 1 super must be any.
14013 * 2.1 sub must be a pair of not and a namespace name or `absent`.
14014 * 2.2 super must be a pair of not and the same value.
14016 if ((sub
->negNsSet
!= NULL
) &&
14017 (super
->negNsSet
!= NULL
) &&
14018 (sub
->negNsSet
->value
== super
->negNsSet
->value
))
14021 * 3.1 sub must be a set whose members are either namespace names or `absent`.
14023 if (sub
->nsSet
!= NULL
) {
14025 * 3.2.1 super must be the same set or a superset thereof.
14027 if (super
->nsSet
!= NULL
) {
14028 xmlSchemaWildcardNsPtr cur
, curB
;
14032 while (cur
!= NULL
) {
14034 curB
= super
->nsSet
;
14035 while (curB
!= NULL
) {
14036 if (cur
->value
== curB
->value
) {
14048 } else if (super
->negNsSet
!= NULL
) {
14049 xmlSchemaWildcardNsPtr cur
;
14051 * 3.2.2 super must be a pair of not and a namespace name or
14052 * `absent` and that value must not be in sub's set.
14055 while (cur
!= NULL
) {
14056 if (cur
->value
== super
->negNsSet
->value
)
14067 xmlSchemaGetEffectiveValueConstraint(xmlSchemaAttributeUsePtr attruse
,
14069 const xmlChar
**value
,
14070 xmlSchemaValPtr
*val
)
14077 if (attruse
->defValue
!= NULL
) {
14078 *value
= attruse
->defValue
;
14080 *val
= attruse
->defVal
;
14081 if (attruse
->flags
& XML_SCHEMA_ATTR_USE_FIXED
)
14084 } else if ((attruse
->attrDecl
!= NULL
) &&
14085 (attruse
->attrDecl
->defValue
!= NULL
)) {
14086 *value
= attruse
->attrDecl
->defValue
;
14088 *val
= attruse
->attrDecl
->defVal
;
14089 if (attruse
->attrDecl
->flags
& XML_SCHEMAS_ATTR_FIXED
)
14096 * xmlSchemaCheckCVCWildcardNamespace:
14097 * @wild: the wildcard
14098 * @ns: the namespace
14100 * Validation Rule: Wildcard allows Namespace Name
14101 * (cvc-wildcard-namespace)
14103 * Returns 0 if the given namespace matches the wildcard,
14104 * 1 otherwise and -1 on API errors.
14107 xmlSchemaCheckCVCWildcardNamespace(xmlSchemaWildcardPtr wild
,
14115 else if (wild
->nsSet
!= NULL
) {
14116 xmlSchemaWildcardNsPtr cur
;
14119 while (cur
!= NULL
) {
14120 if (xmlStrEqual(cur
->value
, ns
))
14124 } else if ((wild
->negNsSet
!= NULL
) && (ns
!= NULL
) &&
14125 (!xmlStrEqual(wild
->negNsSet
->value
, ns
)))
14131 #define XML_SCHEMA_ACTION_DERIVE 0
14132 #define XML_SCHEMA_ACTION_REDEFINE 1
14134 #define WXS_ACTION_STR(a) \
14135 ((a) == XML_SCHEMA_ACTION_DERIVE) ? (const xmlChar *) "base" : (const xmlChar *) "redefined"
14138 * Schema Component Constraint:
14139 * Derivation Valid (Restriction, Complex)
14140 * derivation-ok-restriction (2) - (4)
14143 * In XML Schema 1.1 this will be:
14145 * Checking complex type subsumption (practicalSubsumption) (1, 2 and 3)
14149 xmlSchemaCheckDerivationOKRestriction2to4(xmlSchemaParserCtxtPtr pctxt
,
14151 xmlSchemaBasicItemPtr item
,
14152 xmlSchemaBasicItemPtr baseItem
,
14153 xmlSchemaItemListPtr uses
,
14154 xmlSchemaItemListPtr baseUses
,
14155 xmlSchemaWildcardPtr wild
,
14156 xmlSchemaWildcardPtr baseWild
)
14158 xmlSchemaAttributeUsePtr cur
= NULL
, bcur
;
14159 int i
, j
, found
; /* err = 0; */
14160 const xmlChar
*bEffValue
;
14163 if (uses
!= NULL
) {
14164 for (i
= 0; i
< uses
->nbItems
; i
++) {
14165 cur
= uses
->items
[i
];
14167 if (baseUses
== NULL
)
14169 for (j
= 0; j
< baseUses
->nbItems
; j
++) {
14170 bcur
= baseUses
->items
[j
];
14171 if ((WXS_ATTRUSE_DECL_NAME(cur
) ==
14172 WXS_ATTRUSE_DECL_NAME(bcur
)) &&
14173 (WXS_ATTRUSE_DECL_TNS(cur
) ==
14174 WXS_ATTRUSE_DECL_TNS(bcur
)))
14177 * (2.1) "If there is an attribute use in the {attribute
14178 * uses} of the {base type definition} (call this B) whose
14179 * {attribute declaration} has the same {name} and {target
14180 * namespace}, then all of the following must be true:"
14184 if ((cur
->occurs
== XML_SCHEMAS_ATTR_USE_OPTIONAL
) &&
14185 (bcur
->occurs
== XML_SCHEMAS_ATTR_USE_REQUIRED
))
14187 xmlChar
*str
= NULL
;
14189 * (2.1.1) "one of the following must be true:"
14190 * (2.1.1.1) "B's {required} is false."
14191 * (2.1.1.2) "R's {required} is true."
14193 xmlSchemaPAttrUseErr4(pctxt
,
14194 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_1
,
14195 WXS_ITEM_NODE(item
), item
, cur
,
14196 "The 'optional' attribute use is inconsistent "
14197 "with the corresponding 'required' attribute use of "
14199 WXS_ACTION_STR(action
),
14200 xmlSchemaGetComponentDesignation(&str
, baseItem
),
14202 FREE_AND_NULL(str
);
14203 /* err = pctxt->err; */
14204 } else if (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt
,
14205 WXS_ATTRUSE_TYPEDEF(cur
),
14206 WXS_ATTRUSE_TYPEDEF(bcur
), 0) != 0)
14208 xmlChar
*strA
= NULL
, *strB
= NULL
, *strC
= NULL
;
14211 * SPEC (2.1.2) "R's {attribute declaration}'s
14212 * {type definition} must be validly derived from
14213 * B's {type definition} given the empty set as
14214 * defined in Type Derivation OK (Simple) ($3.14.6)."
14216 xmlSchemaPAttrUseErr4(pctxt
,
14217 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_2
,
14218 WXS_ITEM_NODE(item
), item
, cur
,
14219 "The attribute declaration's %s "
14220 "is not validly derived from "
14221 "the corresponding %s of the "
14222 "attribute declaration in the %s %s",
14223 xmlSchemaGetComponentDesignation(&strA
,
14224 WXS_ATTRUSE_TYPEDEF(cur
)),
14225 xmlSchemaGetComponentDesignation(&strB
,
14226 WXS_ATTRUSE_TYPEDEF(bcur
)),
14227 WXS_ACTION_STR(action
),
14228 xmlSchemaGetComponentDesignation(&strC
, baseItem
));
14229 /* xmlSchemaGetComponentDesignation(&str, baseItem), */
14230 FREE_AND_NULL(strA
);
14231 FREE_AND_NULL(strB
);
14232 FREE_AND_NULL(strC
);
14233 /* err = pctxt->err; */
14236 * 2.1.3 [Definition:] Let the effective value
14237 * constraint of an attribute use be its {value
14238 * constraint}, if present, otherwise its {attribute
14239 * declaration}'s {value constraint} .
14241 xmlSchemaGetEffectiveValueConstraint(bcur
,
14242 &effFixed
, &bEffValue
, NULL
);
14244 * 2.1.3 ... one of the following must be true
14246 * 2.1.3.1 B's `effective value constraint` is
14247 * `absent` or default.
14249 if ((bEffValue
!= NULL
) &&
14251 const xmlChar
*rEffValue
= NULL
;
14253 xmlSchemaGetEffectiveValueConstraint(bcur
,
14254 &effFixed
, &rEffValue
, NULL
);
14256 * 2.1.3.2 R's `effective value constraint` is
14257 * fixed with the same string as B's.
14258 * MAYBE TODO: Compare the computed values.
14259 * Hmm, it says "same string" so
14260 * string-equality might really be sufficient.
14262 if ((effFixed
== 0) ||
14263 (! WXS_ARE_DEFAULT_STR_EQUAL(rEffValue
, bEffValue
)))
14265 xmlChar
*str
= NULL
;
14267 xmlSchemaPAttrUseErr4(pctxt
,
14268 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_3
,
14269 WXS_ITEM_NODE(item
), item
, cur
,
14270 "The effective value constraint of the "
14271 "attribute use is inconsistent with "
14272 "its correspondent in the %s %s",
14273 WXS_ACTION_STR(action
),
14274 xmlSchemaGetComponentDesignation(&str
,
14277 FREE_AND_NULL(str
);
14278 /* err = pctxt->err; */
14288 * (2.2) "otherwise the {base type definition} must have an
14289 * {attribute wildcard} and the {target namespace} of the
14290 * R's {attribute declaration} must be `valid` with respect
14291 * to that wildcard, as defined in Wildcard allows Namespace
14294 if ((baseWild
== NULL
) ||
14295 (xmlSchemaCheckCVCWildcardNamespace(baseWild
,
14296 (WXS_ATTRUSE_DECL(cur
))->targetNamespace
) != 0))
14298 xmlChar
*str
= NULL
;
14300 xmlSchemaPAttrUseErr4(pctxt
,
14301 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_2
,
14302 WXS_ITEM_NODE(item
), item
, cur
,
14303 "Neither a matching attribute use, "
14304 "nor a matching wildcard exists in the %s %s",
14305 WXS_ACTION_STR(action
),
14306 xmlSchemaGetComponentDesignation(&str
, baseItem
),
14308 FREE_AND_NULL(str
);
14309 /* err = pctxt->err; */
14315 * SPEC derivation-ok-restriction (3):
14316 * (3) "For each attribute use in the {attribute uses} of the {base type
14317 * definition} whose {required} is true, there must be an attribute
14318 * use with an {attribute declaration} with the same {name} and
14319 * {target namespace} as its {attribute declaration} in the {attribute
14320 * uses} of the complex type definition itself whose {required} is true.
14322 if (baseUses
!= NULL
) {
14323 for (j
= 0; j
< baseUses
->nbItems
; j
++) {
14324 bcur
= baseUses
->items
[j
];
14325 if (bcur
->occurs
!= XML_SCHEMAS_ATTR_USE_REQUIRED
)
14328 if (uses
!= NULL
) {
14329 for (i
= 0; i
< uses
->nbItems
; i
++) {
14330 cur
= uses
->items
[i
];
14331 if ((WXS_ATTRUSE_DECL_NAME(cur
) ==
14332 WXS_ATTRUSE_DECL_NAME(bcur
)) &&
14333 (WXS_ATTRUSE_DECL_TNS(cur
) ==
14334 WXS_ATTRUSE_DECL_TNS(bcur
))) {
14341 xmlChar
*strA
= NULL
, *strB
= NULL
;
14343 xmlSchemaCustomErr4(ACTXT_CAST pctxt
,
14344 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_3
,
14346 "A matching attribute use for the "
14347 "'required' %s of the %s %s is missing",
14348 xmlSchemaGetComponentDesignation(&strA
, bcur
),
14349 WXS_ACTION_STR(action
),
14350 xmlSchemaGetComponentDesignation(&strB
, baseItem
),
14352 FREE_AND_NULL(strA
);
14353 FREE_AND_NULL(strB
);
14358 * derivation-ok-restriction (4)
14360 if (wild
!= NULL
) {
14362 * (4) "If there is an {attribute wildcard}, all of the
14363 * following must be true:"
14365 if (baseWild
== NULL
) {
14366 xmlChar
*str
= NULL
;
14369 * (4.1) "The {base type definition} must also have one."
14371 xmlSchemaCustomErr4(ACTXT_CAST pctxt
,
14372 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_1
,
14374 "The %s has an attribute wildcard, "
14375 "but the %s %s '%s' does not have one",
14376 WXS_ITEM_TYPE_NAME(item
),
14377 WXS_ACTION_STR(action
),
14378 WXS_ITEM_TYPE_NAME(baseItem
),
14379 xmlSchemaGetComponentQName(&str
, baseItem
));
14380 FREE_AND_NULL(str
);
14381 return(pctxt
->err
);
14382 } else if ((baseWild
->any
== 0) &&
14383 xmlSchemaCheckCOSNSSubset(wild
, baseWild
))
14385 xmlChar
*str
= NULL
;
14387 * (4.2) "The complex type definition's {attribute wildcard}'s
14388 * {namespace constraint} must be a subset of the {base type
14389 * definition}'s {attribute wildcard}'s {namespace constraint},
14390 * as defined by Wildcard Subset ($3.10.6)."
14392 xmlSchemaCustomErr4(ACTXT_CAST pctxt
,
14393 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_2
,
14395 "The attribute wildcard is not a valid "
14396 "subset of the wildcard in the %s %s '%s'",
14397 WXS_ACTION_STR(action
),
14398 WXS_ITEM_TYPE_NAME(baseItem
),
14399 xmlSchemaGetComponentQName(&str
, baseItem
),
14401 FREE_AND_NULL(str
);
14402 return(pctxt
->err
);
14404 /* 4.3 Unless the {base type definition} is the `ur-type
14405 * definition`, the complex type definition's {attribute
14406 * wildcard}'s {process contents} must be identical to or
14407 * stronger than the {base type definition}'s {attribute
14408 * wildcard}'s {process contents}, where strict is stronger
14409 * than lax is stronger than skip.
14411 if ((! WXS_IS_ANYTYPE(baseItem
)) &&
14412 (wild
->processContents
< baseWild
->processContents
)) {
14413 xmlChar
*str
= NULL
;
14414 xmlSchemaCustomErr4(ACTXT_CAST pctxt
,
14415 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_3
,
14417 "The {process contents} of the attribute wildcard is "
14418 "weaker than the one in the %s %s '%s'",
14419 WXS_ACTION_STR(action
),
14420 WXS_ITEM_TYPE_NAME(baseItem
),
14421 xmlSchemaGetComponentQName(&str
, baseItem
),
14424 return(pctxt
->err
);
14432 xmlSchemaExpandAttributeGroupRefs(xmlSchemaParserCtxtPtr pctxt
,
14433 xmlSchemaBasicItemPtr item
,
14434 xmlSchemaWildcardPtr
*completeWild
,
14435 xmlSchemaItemListPtr list
,
14436 xmlSchemaItemListPtr prohibs
);
14438 * xmlSchemaFixupTypeAttributeUses:
14439 * @ctxt: the schema parser context
14440 * @type: the complex type definition
14443 * Builds the wildcard and the attribute uses on the given complex type.
14444 * Returns -1 if an internal error occurs, 0 otherwise.
14446 * ATTENTION TODO: Experimantally this uses pointer comparisons for
14447 * strings, so recheck this if we start to hardcode some schemata, since
14448 * they might not be in the same dict.
14449 * NOTE: It is allowed to "extend" the xs:anyType type.
14452 xmlSchemaFixupTypeAttributeUses(xmlSchemaParserCtxtPtr pctxt
,
14453 xmlSchemaTypePtr type
)
14455 xmlSchemaTypePtr baseType
= NULL
;
14456 xmlSchemaAttributeUsePtr use
;
14457 xmlSchemaItemListPtr uses
, baseUses
, prohibs
= NULL
;
14459 if (type
->baseType
== NULL
) {
14460 PERROR_INT("xmlSchemaFixupTypeAttributeUses",
14464 baseType
= type
->baseType
;
14465 if (WXS_IS_TYPE_NOT_FIXED(baseType
))
14466 if (xmlSchemaTypeFixup(baseType
, ACTXT_CAST pctxt
) == -1)
14469 uses
= type
->attrUses
;
14470 baseUses
= baseType
->attrUses
;
14472 * Expand attribute group references. And build the 'complete'
14473 * wildcard, i.e. intersect multiple wildcards.
14474 * Move attribute prohibitions into a separate list.
14476 if (uses
!= NULL
) {
14477 if (WXS_IS_RESTRICTION(type
)) {
14479 * This one will transfer all attr. prohibitions
14480 * into pctxt->attrProhibs.
14482 if (xmlSchemaExpandAttributeGroupRefs(pctxt
,
14483 WXS_BASIC_CAST type
, &(type
->attributeWildcard
), uses
,
14484 pctxt
->attrProhibs
) == -1)
14486 PERROR_INT("xmlSchemaFixupTypeAttributeUses",
14487 "failed to expand attributes");
14489 if (pctxt
->attrProhibs
->nbItems
!= 0)
14490 prohibs
= pctxt
->attrProhibs
;
14492 if (xmlSchemaExpandAttributeGroupRefs(pctxt
,
14493 WXS_BASIC_CAST type
, &(type
->attributeWildcard
), uses
,
14496 PERROR_INT("xmlSchemaFixupTypeAttributeUses",
14497 "failed to expand attributes");
14502 * Inherit the attribute uses of the base type.
14504 if (baseUses
!= NULL
) {
14506 xmlSchemaAttributeUseProhibPtr pro
;
14508 if (WXS_IS_RESTRICTION(type
)) {
14510 xmlSchemaAttributeUsePtr tmp
;
14513 usesCount
= uses
->nbItems
;
14518 for (i
= 0; i
< baseUses
->nbItems
; i
++) {
14519 use
= baseUses
->items
[i
];
14522 * Filter out prohibited uses.
14524 for (j
= 0; j
< prohibs
->nbItems
; j
++) {
14525 pro
= prohibs
->items
[j
];
14526 if ((WXS_ATTRUSE_DECL_NAME(use
) == pro
->name
) &&
14527 (WXS_ATTRUSE_DECL_TNS(use
) ==
14528 pro
->targetNamespace
))
14536 * Filter out existing uses.
14538 for (j
= 0; j
< usesCount
; j
++) {
14539 tmp
= uses
->items
[j
];
14540 if ((WXS_ATTRUSE_DECL_NAME(use
) ==
14541 WXS_ATTRUSE_DECL_NAME(tmp
)) &&
14542 (WXS_ATTRUSE_DECL_TNS(use
) ==
14543 WXS_ATTRUSE_DECL_TNS(tmp
)))
14549 if (uses
== NULL
) {
14550 type
->attrUses
= xmlSchemaItemListCreate();
14551 if (type
->attrUses
== NULL
)
14553 uses
= type
->attrUses
;
14555 xmlSchemaItemListAddSize(uses
, 2, use
);
14560 for (i
= 0; i
< baseUses
->nbItems
; i
++) {
14561 use
= baseUses
->items
[i
];
14562 if (uses
== NULL
) {
14563 type
->attrUses
= xmlSchemaItemListCreate();
14564 if (type
->attrUses
== NULL
)
14566 uses
= type
->attrUses
;
14568 xmlSchemaItemListAddSize(uses
, baseUses
->nbItems
, use
);
14573 * Shrink attr. uses.
14576 if (uses
->nbItems
== 0) {
14577 xmlSchemaItemListFree(uses
);
14578 type
->attrUses
= NULL
;
14581 * TODO: We could shrink the size of the array
14582 * to fit the actual number of items.
14586 * Compute the complete wildcard.
14588 if (WXS_IS_EXTENSION(type
)) {
14589 if (baseType
->attributeWildcard
!= NULL
) {
14591 * (3.2.2.1) "If the `base wildcard` is non-`absent`, then
14592 * the appropriate case among the following:"
14594 if (type
->attributeWildcard
!= NULL
) {
14596 * Union the complete wildcard with the base wildcard.
14597 * SPEC {attribute wildcard}
14598 * (3.2.2.1.2) "otherwise a wildcard whose {process contents}
14599 * and {annotation} are those of the `complete wildcard`,
14600 * and whose {namespace constraint} is the intensional union
14601 * of the {namespace constraint} of the `complete wildcard`
14602 * and of the `base wildcard`, as defined in Attribute
14603 * Wildcard Union ($3.10.6)."
14605 if (xmlSchemaUnionWildcards(pctxt
, type
->attributeWildcard
,
14606 baseType
->attributeWildcard
) == -1)
14610 * (3.2.2.1.1) "If the `complete wildcard` is `absent`,
14611 * then the `base wildcard`."
14613 type
->attributeWildcard
= baseType
->attributeWildcard
;
14617 * (3.2.2.2) "otherwise (the `base wildcard` is `absent`) the
14618 * `complete wildcard`"
14624 * SPEC {attribute wildcard}
14625 * (3.1) "If the <restriction> alternative is chosen, then the
14626 * `complete wildcard`;"
14638 * xmlSchemaTypeFinalContains:
14639 * @schema: the schema
14640 * @type: the type definition
14641 * @final: the final
14643 * Evaluates if a type definition contains the given "final".
14644 * This does take "finalDefault" into account as well.
14646 * Returns 1 if the type does containt the given "final",
14650 xmlSchemaTypeFinalContains(xmlSchemaTypePtr type
, int final
)
14654 if (type
->flags
& final
)
14661 * xmlSchemaGetUnionSimpleTypeMemberTypes:
14662 * @type: the Union Simple Type
14664 * Returns a list of member types of @type if existing,
14665 * returns NULL otherwise.
14667 static xmlSchemaTypeLinkPtr
14668 xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type
)
14670 while ((type
!= NULL
) && (type
->type
== XML_SCHEMA_TYPE_SIMPLE
)) {
14671 if (type
->memberTypes
!= NULL
)
14672 return (type
->memberTypes
);
14674 type
= type
->baseType
;
14680 * xmlSchemaGetParticleTotalRangeMin:
14681 * @particle: the particle
14683 * Schema Component Constraint: Effective Total Range
14684 * (all and sequence) + (choice)
14686 * Returns the minimun Effective Total Range.
14689 xmlSchemaGetParticleTotalRangeMin(xmlSchemaParticlePtr particle
)
14691 if ((particle
->children
== NULL
) ||
14692 (particle
->minOccurs
== 0))
14694 if (particle
->children
->type
== XML_SCHEMA_TYPE_CHOICE
) {
14696 xmlSchemaParticlePtr part
=
14697 (xmlSchemaParticlePtr
) particle
->children
->children
;
14701 while (part
!= NULL
) {
14702 if ((part
->children
->type
== XML_SCHEMA_TYPE_ELEMENT
) ||
14703 (part
->children
->type
== XML_SCHEMA_TYPE_ANY
))
14704 cur
= part
->minOccurs
;
14706 cur
= xmlSchemaGetParticleTotalRangeMin(part
);
14709 if ((min
> cur
) || (min
== -1))
14711 part
= (xmlSchemaParticlePtr
) part
->next
;
14713 return (particle
->minOccurs
* min
);
14715 /* <all> and <sequence> */
14717 xmlSchemaParticlePtr part
=
14718 (xmlSchemaParticlePtr
) particle
->children
->children
;
14723 if ((part
->children
->type
== XML_SCHEMA_TYPE_ELEMENT
) ||
14724 (part
->children
->type
== XML_SCHEMA_TYPE_ANY
))
14725 sum
+= part
->minOccurs
;
14727 sum
+= xmlSchemaGetParticleTotalRangeMin(part
);
14728 part
= (xmlSchemaParticlePtr
) part
->next
;
14729 } while (part
!= NULL
);
14730 return (particle
->minOccurs
* sum
);
14736 * xmlSchemaGetParticleTotalRangeMax:
14737 * @particle: the particle
14739 * Schema Component Constraint: Effective Total Range
14740 * (all and sequence) + (choice)
14742 * Returns the maximum Effective Total Range.
14745 xmlSchemaGetParticleTotalRangeMax(xmlSchemaParticlePtr particle
)
14747 if ((particle
->children
== NULL
) ||
14748 (particle
->children
->children
== NULL
))
14750 if (particle
->children
->type
== XML_SCHEMA_TYPE_CHOICE
) {
14752 xmlSchemaParticlePtr part
=
14753 (xmlSchemaParticlePtr
) particle
->children
->children
;
14755 for (; part
!= NULL
; part
= (xmlSchemaParticlePtr
) part
->next
) {
14756 if (part
->children
== NULL
)
14758 if ((part
->children
->type
== XML_SCHEMA_TYPE_ELEMENT
) ||
14759 (part
->children
->type
== XML_SCHEMA_TYPE_ANY
))
14760 cur
= part
->maxOccurs
;
14762 cur
= xmlSchemaGetParticleTotalRangeMax(part
);
14763 if (cur
== UNBOUNDED
)
14764 return (UNBOUNDED
);
14765 if ((max
< cur
) || (max
== -1))
14768 /* TODO: Handle overflows? */
14769 return (particle
->maxOccurs
* max
);
14771 /* <all> and <sequence> */
14773 xmlSchemaParticlePtr part
=
14774 (xmlSchemaParticlePtr
) particle
->children
->children
;
14776 for (; part
!= NULL
; part
= (xmlSchemaParticlePtr
) part
->next
) {
14777 if (part
->children
== NULL
)
14779 if ((part
->children
->type
== XML_SCHEMA_TYPE_ELEMENT
) ||
14780 (part
->children
->type
== XML_SCHEMA_TYPE_ANY
))
14781 cur
= part
->maxOccurs
;
14783 cur
= xmlSchemaGetParticleTotalRangeMax(part
);
14784 if (cur
== UNBOUNDED
)
14785 return (UNBOUNDED
);
14786 if ((cur
> 0) && (particle
->maxOccurs
== UNBOUNDED
))
14787 return (UNBOUNDED
);
14790 /* TODO: Handle overflows? */
14791 return (particle
->maxOccurs
* sum
);
14797 * xmlSchemaIsParticleEmptiable:
14798 * @particle: the particle
14800 * Schema Component Constraint: Particle Emptiable
14801 * Checks whether the given particle is emptiable.
14803 * Returns 1 if emptiable, 0 otherwise.
14806 xmlSchemaIsParticleEmptiable(xmlSchemaParticlePtr particle
)
14809 * SPEC (1) "Its {min occurs} is 0."
14811 if ((particle
== NULL
) || (particle
->minOccurs
== 0) ||
14812 (particle
->children
== NULL
))
14815 * SPEC (2) "Its {term} is a group and the minimum part of the
14816 * effective total range of that group, [...] is 0."
14818 if (WXS_IS_MODEL_GROUP(particle
->children
)) {
14819 if (xmlSchemaGetParticleTotalRangeMin(particle
) == 0)
14826 * xmlSchemaCheckCOSSTDerivedOK:
14827 * @actxt: a context
14828 * @type: the derived simple type definition
14829 * @baseType: the base type definition
14830 * @subset: the subset of ('restriction', ect.)
14832 * Schema Component Constraint:
14833 * Type Derivation OK (Simple) (cos-st-derived-OK)
14835 * Checks wheter @type can be validly
14836 * derived from @baseType.
14838 * Returns 0 on success, an positive error code otherwise.
14841 xmlSchemaCheckCOSSTDerivedOK(xmlSchemaAbstractCtxtPtr actxt
,
14842 xmlSchemaTypePtr type
,
14843 xmlSchemaTypePtr baseType
,
14847 * 1 They are the same type definition.
14848 * TODO: The identy check might have to be more complex than this.
14850 if (type
== baseType
)
14853 * 2.1 restriction is not in the subset, or in the {final}
14854 * of its own {base type definition};
14856 * NOTE that this will be used also via "xsi:type".
14858 * TODO: Revise this, it looks strange. How can the "type"
14859 * not be fixed or *in* fixing?
14861 if (WXS_IS_TYPE_NOT_FIXED(type
))
14862 if (xmlSchemaTypeFixup(type
, actxt
) == -1)
14864 if (WXS_IS_TYPE_NOT_FIXED(baseType
))
14865 if (xmlSchemaTypeFixup(baseType
, actxt
) == -1)
14867 if ((subset
& SUBSET_RESTRICTION
) ||
14868 (xmlSchemaTypeFinalContains(type
->baseType
,
14869 XML_SCHEMAS_TYPE_FINAL_RESTRICTION
))) {
14870 return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_1
);
14873 if (type
->baseType
== baseType
) {
14875 * 2.2.1 D's `base type definition` is B.
14880 * 2.2.2 D's `base type definition` is not the `ur-type definition`
14881 * and is validly derived from B given the subset, as defined by this
14884 if ((! WXS_IS_ANYTYPE(type
->baseType
)) &&
14885 (xmlSchemaCheckCOSSTDerivedOK(actxt
, type
->baseType
,
14886 baseType
, subset
) == 0)) {
14890 * 2.2.3 D's {variety} is list or union and B is the `simple ur-type
14893 if (WXS_IS_ANY_SIMPLE_TYPE(baseType
) &&
14894 (WXS_IS_LIST(type
) || WXS_IS_UNION(type
))) {
14898 * 2.2.4 B's {variety} is union and D is validly derived from a type
14899 * definition in B's {member type definitions} given the subset, as
14900 * defined by this constraint.
14902 * NOTE: This seems not to involve built-in types, since there is no
14903 * built-in Union Simple Type.
14905 if (WXS_IS_UNION(baseType
)) {
14906 xmlSchemaTypeLinkPtr cur
;
14908 cur
= baseType
->memberTypes
;
14909 while (cur
!= NULL
) {
14910 if (WXS_IS_TYPE_NOT_FIXED(cur
->type
))
14911 if (xmlSchemaTypeFixup(cur
->type
, actxt
) == -1)
14913 if (xmlSchemaCheckCOSSTDerivedOK(actxt
,
14914 type
, cur
->type
, subset
) == 0)
14917 * It just has to be validly derived from at least one
14925 return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_2
);
14929 * xmlSchemaCheckTypeDefCircularInternal:
14930 * @pctxt: the schema parser context
14931 * @ctxtType: the type definition
14932 * @ancestor: an ancestor of @ctxtType
14934 * Checks st-props-correct (2) + ct-props-correct (3).
14935 * Circular type definitions are not allowed.
14937 * Returns XML_SCHEMAP_ST_PROPS_CORRECT_2 if the given type is
14938 * circular, 0 otherwise.
14941 xmlSchemaCheckTypeDefCircularInternal(xmlSchemaParserCtxtPtr pctxt
,
14942 xmlSchemaTypePtr ctxtType
,
14943 xmlSchemaTypePtr ancestor
)
14947 if ((ancestor
== NULL
) || (ancestor
->type
== XML_SCHEMA_TYPE_BASIC
))
14950 if (ctxtType
== ancestor
) {
14951 xmlSchemaPCustomErr(pctxt
,
14952 XML_SCHEMAP_ST_PROPS_CORRECT_2
,
14953 WXS_BASIC_CAST ctxtType
, WXS_ITEM_NODE(ctxtType
),
14954 "The definition is circular", NULL
);
14955 return (XML_SCHEMAP_ST_PROPS_CORRECT_2
);
14957 if (ancestor
->flags
& XML_SCHEMAS_TYPE_MARKED
) {
14959 * Avoid inifinite recursion on circular types not yet checked.
14963 ancestor
->flags
|= XML_SCHEMAS_TYPE_MARKED
;
14964 ret
= xmlSchemaCheckTypeDefCircularInternal(pctxt
, ctxtType
,
14965 ancestor
->baseType
);
14966 ancestor
->flags
^= XML_SCHEMAS_TYPE_MARKED
;
14971 * xmlSchemaCheckTypeDefCircular:
14972 * @item: the complex/simple type definition
14973 * @ctxt: the parser context
14976 * Checks for circular type definitions.
14979 xmlSchemaCheckTypeDefCircular(xmlSchemaTypePtr item
,
14980 xmlSchemaParserCtxtPtr ctxt
)
14982 if ((item
== NULL
) ||
14983 (item
->type
== XML_SCHEMA_TYPE_BASIC
) ||
14984 (item
->baseType
== NULL
))
14986 xmlSchemaCheckTypeDefCircularInternal(ctxt
, item
,
14991 * Simple Type Definition Representation OK (src-simple-type) 4
14993 * "4 Circular union type definition is disallowed. That is, if the
14994 * <union> alternative is chosen, there must not be any entries in the
14995 * memberTypes [attribute] at any depth which resolve to the component
14996 * corresponding to the <simpleType>."
14998 * Note that this should work on the *representation* of a component,
14999 * thus assumes any union types in the member types not being yet
15000 * substituted. At this stage we need the variety of the types
15001 * to be already computed.
15004 xmlSchemaCheckUnionTypeDefCircularRecur(xmlSchemaParserCtxtPtr pctxt
,
15005 xmlSchemaTypePtr ctxType
,
15006 xmlSchemaTypeLinkPtr members
)
15008 xmlSchemaTypeLinkPtr member
;
15009 xmlSchemaTypePtr memberType
;
15012 while (member
!= NULL
) {
15013 memberType
= member
->type
;
15014 while ((memberType
!= NULL
) &&
15015 (memberType
->type
!= XML_SCHEMA_TYPE_BASIC
)) {
15016 if (memberType
== ctxType
) {
15017 xmlSchemaPCustomErr(pctxt
,
15018 XML_SCHEMAP_SRC_SIMPLE_TYPE_4
,
15019 WXS_BASIC_CAST ctxType
, NULL
,
15020 "The union type definition is circular", NULL
);
15021 return (XML_SCHEMAP_SRC_SIMPLE_TYPE_4
);
15023 if ((WXS_IS_UNION(memberType
)) &&
15024 ((memberType
->flags
& XML_SCHEMAS_TYPE_MARKED
) == 0))
15027 memberType
->flags
|= XML_SCHEMAS_TYPE_MARKED
;
15028 res
= xmlSchemaCheckUnionTypeDefCircularRecur(pctxt
,
15030 xmlSchemaGetUnionSimpleTypeMemberTypes(memberType
));
15031 memberType
->flags
^= XML_SCHEMAS_TYPE_MARKED
;
15035 memberType
= memberType
->baseType
;
15037 member
= member
->next
;
15043 xmlSchemaCheckUnionTypeDefCircular(xmlSchemaParserCtxtPtr pctxt
,
15044 xmlSchemaTypePtr type
)
15046 if (! WXS_IS_UNION(type
))
15048 return(xmlSchemaCheckUnionTypeDefCircularRecur(pctxt
, type
,
15049 type
->memberTypes
));
15053 * xmlSchemaResolveTypeReferences:
15054 * @item: the complex/simple type definition
15055 * @ctxt: the parser context
15058 * Resolvese type definition references
15061 xmlSchemaResolveTypeReferences(xmlSchemaTypePtr typeDef
,
15062 xmlSchemaParserCtxtPtr ctxt
)
15064 if (typeDef
== NULL
)
15068 * Resolve the base type.
15070 if (typeDef
->baseType
== NULL
) {
15071 typeDef
->baseType
= xmlSchemaGetType(ctxt
->schema
,
15072 typeDef
->base
, typeDef
->baseNs
);
15073 if (typeDef
->baseType
== NULL
) {
15074 xmlSchemaPResCompAttrErr(ctxt
,
15075 XML_SCHEMAP_SRC_RESOLVE
,
15076 WXS_BASIC_CAST typeDef
, typeDef
->node
,
15077 "base", typeDef
->base
, typeDef
->baseNs
,
15078 XML_SCHEMA_TYPE_SIMPLE
, NULL
);
15082 if (WXS_IS_SIMPLE(typeDef
)) {
15083 if (WXS_IS_UNION(typeDef
)) {
15085 * Resolve the memberTypes.
15087 xmlSchemaResolveUnionMemberTypes(ctxt
, typeDef
);
15089 } else if (WXS_IS_LIST(typeDef
)) {
15091 * Resolve the itemType.
15093 if ((typeDef
->subtypes
== NULL
) && (typeDef
->base
!= NULL
)) {
15095 typeDef
->subtypes
= xmlSchemaGetType(ctxt
->schema
,
15096 typeDef
->base
, typeDef
->baseNs
);
15098 if ((typeDef
->subtypes
== NULL
) ||
15099 (! WXS_IS_SIMPLE(typeDef
->subtypes
)))
15101 typeDef
->subtypes
= NULL
;
15102 xmlSchemaPResCompAttrErr(ctxt
,
15103 XML_SCHEMAP_SRC_RESOLVE
,
15104 WXS_BASIC_CAST typeDef
, typeDef
->node
,
15105 "itemType", typeDef
->base
, typeDef
->baseNs
,
15106 XML_SCHEMA_TYPE_SIMPLE
, NULL
);
15113 * The ball of letters below means, that if we have a particle
15114 * which has a QName-helper component as its {term}, we want
15117 else if ((WXS_TYPE_CONTENTTYPE(typeDef
) != NULL
) &&
15118 ((WXS_TYPE_CONTENTTYPE(typeDef
))->type
==
15119 XML_SCHEMA_TYPE_PARTICLE
) &&
15120 (WXS_TYPE_PARTICLE_TERM(typeDef
) != NULL
) &&
15121 ((WXS_TYPE_PARTICLE_TERM(typeDef
))->type
==
15122 XML_SCHEMA_EXTRA_QNAMEREF
))
15124 xmlSchemaQNameRefPtr ref
=
15125 WXS_QNAME_CAST
WXS_TYPE_PARTICLE_TERM(typeDef
);
15126 xmlSchemaModelGroupDefPtr groupDef
;
15129 * URGENT TODO: Test this.
15131 WXS_TYPE_PARTICLE_TERM(typeDef
) = NULL
;
15133 * Resolve the MG definition reference.
15136 WXS_MODEL_GROUPDEF_CAST
xmlSchemaGetNamedComponent(ctxt
->schema
,
15137 ref
->itemType
, ref
->name
, ref
->targetNamespace
);
15138 if (groupDef
== NULL
) {
15139 xmlSchemaPResCompAttrErr(ctxt
, XML_SCHEMAP_SRC_RESOLVE
,
15140 NULL
, WXS_ITEM_NODE(WXS_TYPE_PARTICLE(typeDef
)),
15141 "ref", ref
->name
, ref
->targetNamespace
, ref
->itemType
,
15143 /* Remove the particle. */
15144 WXS_TYPE_CONTENTTYPE(typeDef
) = NULL
;
15145 } else if (WXS_MODELGROUPDEF_MODEL(groupDef
) == NULL
)
15146 /* Remove the particle. */
15147 WXS_TYPE_CONTENTTYPE(typeDef
) = NULL
;
15150 * Assign the MG definition's {model group} to the
15151 * particle's {term}.
15153 WXS_TYPE_PARTICLE_TERM(typeDef
) = WXS_MODELGROUPDEF_MODEL(groupDef
);
15155 if (WXS_MODELGROUPDEF_MODEL(groupDef
)->type
== XML_SCHEMA_TYPE_ALL
) {
15157 * SPEC cos-all-limited (1.2)
15158 * "1.2 the {term} property of a particle with
15159 * {max occurs}=1 which is part of a pair which constitutes
15160 * the {content type} of a complex type definition."
15162 if ((WXS_TYPE_PARTICLE(typeDef
))->maxOccurs
!= 1) {
15163 xmlSchemaCustomErr(ACTXT_CAST ctxt
,
15164 /* TODO: error code */
15165 XML_SCHEMAP_COS_ALL_LIMITED
,
15166 WXS_ITEM_NODE(WXS_TYPE_PARTICLE(typeDef
)), NULL
,
15167 "The particle's {max occurs} must be 1, since the "
15168 "reference resolves to an 'all' model group",
15179 * xmlSchemaCheckSTPropsCorrect:
15180 * @ctxt: the schema parser context
15181 * @type: the simple type definition
15183 * Checks st-props-correct.
15185 * Returns 0 if the properties are correct,
15186 * if not, a positive error code and -1 on internal
15190 xmlSchemaCheckSTPropsCorrect(xmlSchemaParserCtxtPtr ctxt
,
15191 xmlSchemaTypePtr type
)
15193 xmlSchemaTypePtr baseType
= type
->baseType
;
15194 xmlChar
*str
= NULL
;
15196 /* STATE: error funcs converted. */
15198 * Schema Component Constraint: Simple Type Definition Properties Correct
15200 * NOTE: This is somehow redundant, since we actually built a simple type
15201 * to have all the needed information; this acts as an self test.
15203 /* Base type: If the datatype has been `derived` by `restriction`
15204 * then the Simple Type Definition component from which it is `derived`,
15205 * otherwise the Simple Type Definition for anySimpleType ($4.1.6).
15207 if (baseType
== NULL
) {
15209 * TODO: Think about: "modulo the impact of Missing
15210 * Sub-components ($5.3)."
15212 xmlSchemaPCustomErr(ctxt
,
15213 XML_SCHEMAP_ST_PROPS_CORRECT_1
,
15214 WXS_BASIC_CAST type
, NULL
,
15215 "No base type existent", NULL
);
15216 return (XML_SCHEMAP_ST_PROPS_CORRECT_1
);
15219 if (! WXS_IS_SIMPLE(baseType
)) {
15220 xmlSchemaPCustomErr(ctxt
,
15221 XML_SCHEMAP_ST_PROPS_CORRECT_1
,
15222 WXS_BASIC_CAST type
, NULL
,
15223 "The base type '%s' is not a simple type",
15224 xmlSchemaGetComponentQName(&str
, baseType
));
15226 return (XML_SCHEMAP_ST_PROPS_CORRECT_1
);
15228 if ((WXS_IS_LIST(type
) || WXS_IS_UNION(type
)) &&
15229 (WXS_IS_RESTRICTION(type
) == 0) &&
15230 ((! WXS_IS_ANY_SIMPLE_TYPE(baseType
)) &&
15231 (baseType
->type
!= XML_SCHEMA_TYPE_SIMPLE
))) {
15232 xmlSchemaPCustomErr(ctxt
,
15233 XML_SCHEMAP_ST_PROPS_CORRECT_1
,
15234 WXS_BASIC_CAST type
, NULL
,
15235 "A type, derived by list or union, must have "
15236 "the simple ur-type definition as base type, not '%s'",
15237 xmlSchemaGetComponentQName(&str
, baseType
));
15239 return (XML_SCHEMAP_ST_PROPS_CORRECT_1
);
15242 * Variety: One of {atomic, list, union}.
15244 if ((! WXS_IS_ATOMIC(type
)) && (! WXS_IS_UNION(type
)) &&
15245 (! WXS_IS_LIST(type
))) {
15246 xmlSchemaPCustomErr(ctxt
,
15247 XML_SCHEMAP_ST_PROPS_CORRECT_1
,
15248 WXS_BASIC_CAST type
, NULL
,
15249 "The variety is absent", NULL
);
15250 return (XML_SCHEMAP_ST_PROPS_CORRECT_1
);
15252 /* TODO: Finish this. Hmm, is this finished? */
15255 * 3 The {final} of the {base type definition} must not contain restriction.
15257 if (xmlSchemaTypeFinalContains(baseType
,
15258 XML_SCHEMAS_TYPE_FINAL_RESTRICTION
)) {
15259 xmlSchemaPCustomErr(ctxt
,
15260 XML_SCHEMAP_ST_PROPS_CORRECT_3
,
15261 WXS_BASIC_CAST type
, NULL
,
15262 "The 'final' of its base type '%s' must not contain "
15264 xmlSchemaGetComponentQName(&str
, baseType
));
15266 return (XML_SCHEMAP_ST_PROPS_CORRECT_3
);
15270 * 2 All simple type definitions must be derived ultimately from the `simple
15271 * ur-type definition` (so circular definitions are disallowed). That is, it
15272 * must be possible to reach a built-in primitive datatype or the `simple
15273 * ur-type definition` by repeatedly following the {base type definition}.
15275 * NOTE: this is done in xmlSchemaCheckTypeDefCircular().
15281 * xmlSchemaCheckCOSSTRestricts:
15282 * @ctxt: the schema parser context
15283 * @type: the simple type definition
15285 * Schema Component Constraint:
15286 * Derivation Valid (Restriction, Simple) (cos-st-restricts)
15288 * Checks if the given @type (simpleType) is derived validly by restriction.
15291 * Returns -1 on internal errors, 0 if the type is validly derived,
15292 * a positive error code otherwise.
15295 xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr pctxt
,
15296 xmlSchemaTypePtr type
)
15298 xmlChar
*str
= NULL
;
15300 if (type
->type
!= XML_SCHEMA_TYPE_SIMPLE
) {
15301 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15302 "given type is not a user-derived simpleType");
15306 if (WXS_IS_ATOMIC(type
)) {
15307 xmlSchemaTypePtr primitive
;
15309 * 1.1 The {base type definition} must be an atomic simple
15310 * type definition or a built-in primitive datatype.
15312 if (! WXS_IS_ATOMIC(type
->baseType
)) {
15313 xmlSchemaPCustomErr(pctxt
,
15314 XML_SCHEMAP_COS_ST_RESTRICTS_1_1
,
15315 WXS_BASIC_CAST type
, NULL
,
15316 "The base type '%s' is not an atomic simple type",
15317 xmlSchemaGetComponentQName(&str
, type
->baseType
));
15319 return (XML_SCHEMAP_COS_ST_RESTRICTS_1_1
);
15321 /* 1.2 The {final} of the {base type definition} must not contain
15324 /* OPTIMIZE TODO : This is already done in xmlSchemaCheckStPropsCorrect */
15325 if (xmlSchemaTypeFinalContains(type
->baseType
,
15326 XML_SCHEMAS_TYPE_FINAL_RESTRICTION
)) {
15327 xmlSchemaPCustomErr(pctxt
,
15328 XML_SCHEMAP_COS_ST_RESTRICTS_1_2
,
15329 WXS_BASIC_CAST type
, NULL
,
15330 "The final of its base type '%s' must not contain 'restriction'",
15331 xmlSchemaGetComponentQName(&str
, type
->baseType
));
15333 return (XML_SCHEMAP_COS_ST_RESTRICTS_1_2
);
15337 * 1.3.1 DF must be an allowed constraining facet for the {primitive
15338 * type definition}, as specified in the appropriate subsection of 3.2
15339 * Primitive datatypes.
15341 if (type
->facets
!= NULL
) {
15342 xmlSchemaFacetPtr facet
;
15345 primitive
= xmlSchemaGetPrimitiveType(type
);
15346 if (primitive
== NULL
) {
15347 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15348 "failed to get primitive type");
15351 facet
= type
->facets
;
15353 if (xmlSchemaIsBuiltInTypeFacet(primitive
, facet
->type
) == 0) {
15355 xmlSchemaPIllegalFacetAtomicErr(pctxt
,
15356 XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1
,
15357 type
, primitive
, facet
);
15359 facet
= facet
->next
;
15360 } while (facet
!= NULL
);
15362 return (XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1
);
15365 * SPEC (1.3.2) "If there is a facet of the same kind in the {facets}
15366 * of the {base type definition} (call this BF),then the DF's {value}
15367 * must be a valid restriction of BF's {value} as defined in
15368 * [XML Schemas: Datatypes]."
15370 * NOTE (1.3.2) Facet derivation constraints are currently handled in
15371 * xmlSchemaDeriveAndValidateFacets()
15373 } else if (WXS_IS_LIST(type
)) {
15374 xmlSchemaTypePtr itemType
= NULL
;
15376 itemType
= type
->subtypes
;
15377 if ((itemType
== NULL
) || (! WXS_IS_SIMPLE(itemType
))) {
15378 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15379 "failed to evaluate the item type");
15382 if (WXS_IS_TYPE_NOT_FIXED(itemType
))
15383 xmlSchemaTypeFixup(itemType
, ACTXT_CAST pctxt
);
15385 * 2.1 The {item type definition} must have a {variety} of atomic or
15386 * union (in which case all the {member type definitions}
15389 if ((! WXS_IS_ATOMIC(itemType
)) &&
15390 (! WXS_IS_UNION(itemType
))) {
15391 xmlSchemaPCustomErr(pctxt
,
15392 XML_SCHEMAP_COS_ST_RESTRICTS_2_1
,
15393 WXS_BASIC_CAST type
, NULL
,
15394 "The item type '%s' does not have a variety of atomic or union",
15395 xmlSchemaGetComponentQName(&str
, itemType
));
15397 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1
);
15398 } else if (WXS_IS_UNION(itemType
)) {
15399 xmlSchemaTypeLinkPtr member
;
15401 member
= itemType
->memberTypes
;
15402 while (member
!= NULL
) {
15403 if (! WXS_IS_ATOMIC(member
->type
)) {
15404 xmlSchemaPCustomErr(pctxt
,
15405 XML_SCHEMAP_COS_ST_RESTRICTS_2_1
,
15406 WXS_BASIC_CAST type
, NULL
,
15407 "The item type is a union type, but the "
15408 "member type '%s' of this item type is not atomic",
15409 xmlSchemaGetComponentQName(&str
, member
->type
));
15411 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1
);
15413 member
= member
->next
;
15417 if (WXS_IS_ANY_SIMPLE_TYPE(type
->baseType
)) {
15418 xmlSchemaFacetPtr facet
;
15420 * This is the case if we have: <simpleType><list ..
15424 * 2.3.1.1 The {final} of the {item type definition} must not
15427 if (xmlSchemaTypeFinalContains(itemType
,
15428 XML_SCHEMAS_TYPE_FINAL_LIST
)) {
15429 xmlSchemaPCustomErr(pctxt
,
15430 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1
,
15431 WXS_BASIC_CAST type
, NULL
,
15432 "The final of its item type '%s' must not contain 'list'",
15433 xmlSchemaGetComponentQName(&str
, itemType
));
15435 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1
);
15438 * 2.3.1.2 The {facets} must only contain the whiteSpace
15440 * OPTIMIZE TODO: the S4S already disallows any facet
15443 if (type
->facets
!= NULL
) {
15444 facet
= type
->facets
;
15446 if (facet
->type
!= XML_SCHEMA_FACET_WHITESPACE
) {
15447 xmlSchemaPIllegalFacetListUnionErr(pctxt
,
15448 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2
,
15450 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2
);
15452 facet
= facet
->next
;
15453 } while (facet
!= NULL
);
15456 * MAYBE TODO: (Hmm, not really) Datatypes states:
15457 * A `list` datatype can be `derived` from an `atomic` datatype
15458 * whose `lexical space` allows space (such as string or anyURI)or
15459 * a `union` datatype any of whose {member type definitions}'s
15460 * `lexical space` allows space.
15464 * This is the case if we have: <simpleType><restriction ...
15465 * I.e. the variety of "list" is inherited.
15469 * 2.3.2.1 The {base type definition} must have a {variety} of list.
15471 if (! WXS_IS_LIST(type
->baseType
)) {
15472 xmlSchemaPCustomErr(pctxt
,
15473 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1
,
15474 WXS_BASIC_CAST type
, NULL
,
15475 "The base type '%s' must be a list type",
15476 xmlSchemaGetComponentQName(&str
, type
->baseType
));
15478 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1
);
15481 * 2.3.2.2 The {final} of the {base type definition} must not
15482 * contain restriction.
15484 if (xmlSchemaTypeFinalContains(type
->baseType
,
15485 XML_SCHEMAS_TYPE_FINAL_RESTRICTION
)) {
15486 xmlSchemaPCustomErr(pctxt
,
15487 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2
,
15488 WXS_BASIC_CAST type
, NULL
,
15489 "The 'final' of the base type '%s' must not contain 'restriction'",
15490 xmlSchemaGetComponentQName(&str
, type
->baseType
));
15492 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2
);
15495 * 2.3.2.3 The {item type definition} must be validly derived
15496 * from the {base type definition}'s {item type definition} given
15497 * the empty set, as defined in Type Derivation OK (Simple) ($3.14.6).
15500 xmlSchemaTypePtr baseItemType
;
15502 baseItemType
= type
->baseType
->subtypes
;
15503 if ((baseItemType
== NULL
) || (! WXS_IS_SIMPLE(baseItemType
))) {
15504 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15505 "failed to eval the item type of a base type");
15508 if ((itemType
!= baseItemType
) &&
15509 (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt
, itemType
,
15510 baseItemType
, 0) != 0)) {
15511 xmlChar
*strBIT
= NULL
, *strBT
= NULL
;
15512 xmlSchemaPCustomErrExt(pctxt
,
15513 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3
,
15514 WXS_BASIC_CAST type
, NULL
,
15515 "The item type '%s' is not validly derived from "
15516 "the item type '%s' of the base type '%s'",
15517 xmlSchemaGetComponentQName(&str
, itemType
),
15518 xmlSchemaGetComponentQName(&strBIT
, baseItemType
),
15519 xmlSchemaGetComponentQName(&strBT
, type
->baseType
));
15522 FREE_AND_NULL(strBIT
)
15523 FREE_AND_NULL(strBT
)
15524 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3
);
15528 if (type
->facets
!= NULL
) {
15529 xmlSchemaFacetPtr facet
;
15532 * 2.3.2.4 Only length, minLength, maxLength, whiteSpace, pattern
15533 * and enumeration facet components are allowed among the {facets}.
15535 facet
= type
->facets
;
15537 switch (facet
->type
) {
15538 case XML_SCHEMA_FACET_LENGTH
:
15539 case XML_SCHEMA_FACET_MINLENGTH
:
15540 case XML_SCHEMA_FACET_MAXLENGTH
:
15541 case XML_SCHEMA_FACET_WHITESPACE
:
15543 * TODO: 2.5.1.2 List datatypes
15544 * The value of `whiteSpace` is fixed to the value collapse.
15546 case XML_SCHEMA_FACET_PATTERN
:
15547 case XML_SCHEMA_FACET_ENUMERATION
:
15550 xmlSchemaPIllegalFacetListUnionErr(pctxt
,
15551 XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4
,
15554 * We could return, but it's nicer to report all
15560 facet
= facet
->next
;
15561 } while (facet
!= NULL
);
15563 return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4
);
15565 * SPEC (2.3.2.5) (same as 1.3.2)
15567 * NOTE (2.3.2.5) This is currently done in
15568 * xmlSchemaDeriveAndValidateFacets()
15572 } else if (WXS_IS_UNION(type
)) {
15574 * 3.1 The {member type definitions} must all have {variety} of
15577 xmlSchemaTypeLinkPtr member
;
15579 member
= type
->memberTypes
;
15580 while (member
!= NULL
) {
15581 if (WXS_IS_TYPE_NOT_FIXED(member
->type
))
15582 xmlSchemaTypeFixup(member
->type
, ACTXT_CAST pctxt
);
15584 if ((! WXS_IS_ATOMIC(member
->type
)) &&
15585 (! WXS_IS_LIST(member
->type
))) {
15586 xmlSchemaPCustomErr(pctxt
,
15587 XML_SCHEMAP_COS_ST_RESTRICTS_3_1
,
15588 WXS_BASIC_CAST type
, NULL
,
15589 "The member type '%s' is neither an atomic, nor a list type",
15590 xmlSchemaGetComponentQName(&str
, member
->type
));
15592 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_1
);
15594 member
= member
->next
;
15597 * 3.3.1 If the {base type definition} is the `simple ur-type
15600 if (type
->baseType
->builtInType
== XML_SCHEMAS_ANYSIMPLETYPE
) {
15602 * 3.3.1.1 All of the {member type definitions} must have a
15603 * {final} which does not contain union.
15605 member
= type
->memberTypes
;
15606 while (member
!= NULL
) {
15607 if (xmlSchemaTypeFinalContains(member
->type
,
15608 XML_SCHEMAS_TYPE_FINAL_UNION
)) {
15609 xmlSchemaPCustomErr(pctxt
,
15610 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1
,
15611 WXS_BASIC_CAST type
, NULL
,
15612 "The 'final' of member type '%s' contains 'union'",
15613 xmlSchemaGetComponentQName(&str
, member
->type
));
15615 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1
);
15617 member
= member
->next
;
15620 * 3.3.1.2 The {facets} must be empty.
15622 if (type
->facetSet
!= NULL
) {
15623 xmlSchemaPCustomErr(pctxt
,
15624 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2
,
15625 WXS_BASIC_CAST type
, NULL
,
15626 "No facets allowed", NULL
);
15627 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2
);
15631 * 3.3.2.1 The {base type definition} must have a {variety} of union.
15632 * I.e. the variety of "list" is inherited.
15634 if (! WXS_IS_UNION(type
->baseType
)) {
15635 xmlSchemaPCustomErr(pctxt
,
15636 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1
,
15637 WXS_BASIC_CAST type
, NULL
,
15638 "The base type '%s' is not a union type",
15639 xmlSchemaGetComponentQName(&str
, type
->baseType
));
15641 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1
);
15644 * 3.3.2.2 The {final} of the {base type definition} must not contain restriction.
15646 if (xmlSchemaTypeFinalContains(type
->baseType
,
15647 XML_SCHEMAS_TYPE_FINAL_RESTRICTION
)) {
15648 xmlSchemaPCustomErr(pctxt
,
15649 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2
,
15650 WXS_BASIC_CAST type
, NULL
,
15651 "The 'final' of its base type '%s' must not contain 'restriction'",
15652 xmlSchemaGetComponentQName(&str
, type
->baseType
));
15654 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2
);
15657 * 3.3.2.3 The {member type definitions}, in order, must be validly
15658 * derived from the corresponding type definitions in the {base
15659 * type definition}'s {member type definitions} given the empty set,
15660 * as defined in Type Derivation OK (Simple) ($3.14.6).
15663 xmlSchemaTypeLinkPtr baseMember
;
15666 * OPTIMIZE: if the type is restricting, it has no local defined
15667 * member types and inherits the member types of the base type;
15668 * thus a check for equality can be skipped.
15671 * Even worse: I cannot see a scenario where a restricting
15672 * union simple type can have other member types as the member
15673 * types of it's base type. This check seems not necessary with
15674 * respect to the derivation process in libxml2.
15675 * But necessary if constructing types with an API.
15677 if (type
->memberTypes
!= NULL
) {
15678 member
= type
->memberTypes
;
15679 baseMember
= xmlSchemaGetUnionSimpleTypeMemberTypes(type
->baseType
);
15680 if ((member
== NULL
) && (baseMember
!= NULL
)) {
15681 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15682 "different number of member types in base");
15684 while (member
!= NULL
) {
15685 if (baseMember
== NULL
) {
15686 PERROR_INT("xmlSchemaCheckCOSSTRestricts",
15687 "different number of member types in base");
15688 } else if ((member
->type
!= baseMember
->type
) &&
15689 (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt
,
15690 member
->type
, baseMember
->type
, 0) != 0)) {
15691 xmlChar
*strBMT
= NULL
, *strBT
= NULL
;
15693 xmlSchemaPCustomErrExt(pctxt
,
15694 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3
,
15695 WXS_BASIC_CAST type
, NULL
,
15696 "The member type %s is not validly "
15697 "derived from its corresponding member "
15698 "type %s of the base type %s",
15699 xmlSchemaGetComponentQName(&str
, member
->type
),
15700 xmlSchemaGetComponentQName(&strBMT
, baseMember
->type
),
15701 xmlSchemaGetComponentQName(&strBT
, type
->baseType
));
15703 FREE_AND_NULL(strBMT
)
15704 FREE_AND_NULL(strBT
)
15705 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3
);
15707 member
= member
->next
;
15708 if (baseMember
!= NULL
)
15709 baseMember
= baseMember
->next
;
15714 * 3.3.2.4 Only pattern and enumeration facet components are
15715 * allowed among the {facets}.
15717 if (type
->facets
!= NULL
) {
15718 xmlSchemaFacetPtr facet
;
15721 facet
= type
->facets
;
15723 if ((facet
->type
!= XML_SCHEMA_FACET_PATTERN
) &&
15724 (facet
->type
!= XML_SCHEMA_FACET_ENUMERATION
)) {
15725 xmlSchemaPIllegalFacetListUnionErr(pctxt
,
15726 XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4
,
15730 facet
= facet
->next
;
15731 } while (facet
!= NULL
);
15733 return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4
);
15737 * SPEC (3.3.2.5) (same as 1.3.2)
15739 * NOTE (3.3.2.5) This is currently done in
15740 * xmlSchemaDeriveAndValidateFacets()
15749 * xmlSchemaCheckSRCSimpleType:
15750 * @ctxt: the schema parser context
15751 * @type: the simple type definition
15753 * Checks crc-simple-type constraints.
15755 * Returns 0 if the constraints are satisfied,
15756 * if not a positive error code and -1 on internal
15761 xmlSchemaCheckSRCSimpleType(xmlSchemaParserCtxtPtr ctxt
,
15762 xmlSchemaTypePtr type
)
15765 * src-simple-type.1 The corresponding simple type definition, if any,
15766 * must satisfy the conditions set out in Constraints on Simple Type
15767 * Definition Schema Components ($3.14.6).
15769 if (WXS_IS_RESTRICTION(type
)) {
15771 * src-simple-type.2 "If the <restriction> alternative is chosen,
15772 * either it must have a base [attribute] or a <simpleType> among its
15773 * [children], but not both."
15774 * NOTE: This is checked in the parse function of <restriction>.
15779 } else if (WXS_IS_LIST(type
)) {
15780 /* src-simple-type.3 "If the <list> alternative is chosen, either it must have
15781 * an itemType [attribute] or a <simpleType> among its [children],
15784 * NOTE: This is checked in the parse function of <list>.
15786 } else if (WXS_IS_UNION(type
)) {
15788 * src-simple-type.4 is checked in xmlSchemaCheckUnionTypeDefCircular().
15796 xmlSchemaCreateVCtxtOnPCtxt(xmlSchemaParserCtxtPtr ctxt
)
15798 if (ctxt
->vctxt
== NULL
) {
15799 ctxt
->vctxt
= xmlSchemaNewValidCtxt(NULL
);
15800 if (ctxt
->vctxt
== NULL
) {
15801 xmlSchemaPErr(ctxt
, NULL
,
15802 XML_SCHEMAP_INTERNAL
,
15803 "Internal error: xmlSchemaCreateVCtxtOnPCtxt, "
15804 "failed to create a temp. validation context.\n",
15808 /* TODO: Pass user data. */
15809 xmlSchemaSetValidErrors(ctxt
->vctxt
,
15810 ctxt
->error
, ctxt
->warning
, ctxt
->errCtxt
);
15811 xmlSchemaSetValidStructuredErrors(ctxt
->vctxt
,
15812 ctxt
->serror
, ctxt
->errCtxt
);
15818 xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt
,
15820 xmlSchemaTypePtr type
,
15821 const xmlChar
*value
,
15822 xmlSchemaValPtr
*retVal
,
15828 * xmlSchemaParseCheckCOSValidDefault:
15829 * @pctxt: the schema parser context
15830 * @type: the simple type definition
15831 * @value: the default value
15832 * @node: an optional node (the holder of the value)
15834 * Schema Component Constraint: Element Default Valid (Immediate)
15835 * (cos-valid-default)
15836 * This will be used by the parser only. For the validator there's
15837 * an other version.
15839 * Returns 0 if the constraints are satisfied,
15840 * if not, a positive error code and -1 on internal
15844 xmlSchemaParseCheckCOSValidDefault(xmlSchemaParserCtxtPtr pctxt
,
15846 xmlSchemaTypePtr type
,
15847 const xmlChar
*value
,
15848 xmlSchemaValPtr
*val
)
15853 * cos-valid-default:
15854 * Schema Component Constraint: Element Default Valid (Immediate)
15855 * For a string to be a valid default with respect to a type
15856 * definition the appropriate case among the following must be true:
15858 if WXS_IS_COMPLEX(type
) {
15862 * SPEC (2.1) "its {content type} must be a simple type definition
15864 * SPEC (2.2.2) "If the {content type} is mixed, then the {content
15865 * type}'s particle must be `emptiable` as defined by
15866 * Particle Emptiable ($3.9.6)."
15868 if ((! WXS_HAS_SIMPLE_CONTENT(type
)) &&
15869 ((! WXS_HAS_MIXED_CONTENT(type
)) || (! WXS_EMPTIABLE(type
)))) {
15870 /* NOTE that this covers (2.2.2) as well. */
15871 xmlSchemaPCustomErr(pctxt
,
15872 XML_SCHEMAP_COS_VALID_DEFAULT_2_1
,
15873 WXS_BASIC_CAST type
, type
->node
,
15874 "For a string to be a valid default, the type definition "
15875 "must be a simple type or a complex type with mixed content "
15876 "and a particle emptiable", NULL
);
15877 return(XML_SCHEMAP_COS_VALID_DEFAULT_2_1
);
15881 * 1 If the type definition is a simple type definition, then the string
15882 * must be `valid` with respect to that definition as defined by String
15887 * 2.2.1 If the {content type} is a simple type definition, then the
15888 * string must be `valid` with respect to that simple type definition
15889 * as defined by String Valid ($3.14.4).
15891 if (WXS_IS_SIMPLE(type
))
15892 ret
= xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt
, node
,
15893 type
, value
, val
, 1, 1, 0);
15894 else if (WXS_HAS_SIMPLE_CONTENT(type
))
15895 ret
= xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt
, node
,
15896 type
->contentTypeDef
, value
, val
, 1, 1, 0);
15901 PERROR_INT("xmlSchemaParseCheckCOSValidDefault",
15902 "calling xmlSchemaVCheckCVCSimpleType()");
15909 * xmlSchemaCheckCTPropsCorrect:
15910 * @ctxt: the schema parser context
15911 * @type: the complex type definition
15913 *.(4.6) Constraints on Complex Type Definition Schema Components
15914 * Schema Component Constraint:
15915 * Complex Type Definition Properties Correct (ct-props-correct)
15916 * STATUS: (seems) complete
15918 * Returns 0 if the constraints are satisfied, a positive
15919 * error code if not and -1 if an internal error occurred.
15922 xmlSchemaCheckCTPropsCorrect(xmlSchemaParserCtxtPtr pctxt
,
15923 xmlSchemaTypePtr type
)
15926 * TODO: Correct the error code; XML_SCHEMAP_SRC_CT_1 is used temporarily.
15928 * SPEC (1) "The values of the properties of a complex type definition must
15929 * be as described in the property tableau in The Complex Type Definition
15930 * Schema Component ($3.4.1), modulo the impact of Missing
15931 * Sub-components ($5.3)."
15933 if ((type
->baseType
!= NULL
) &&
15934 (WXS_IS_SIMPLE(type
->baseType
)) &&
15935 (WXS_IS_EXTENSION(type
) == 0)) {
15937 * SPEC (2) "If the {base type definition} is a simple type definition,
15938 * the {derivation method} must be extension."
15940 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
15941 XML_SCHEMAP_SRC_CT_1
,
15942 NULL
, WXS_BASIC_CAST type
,
15943 "If the base type is a simple type, the derivation method must be "
15944 "'extension'", NULL
, NULL
);
15945 return (XML_SCHEMAP_SRC_CT_1
);
15948 * SPEC (3) "Circular definitions are disallowed, except for the `ur-type
15949 * definition`. That is, it must be possible to reach the `ur-type
15950 * definition` by repeatedly following the {base type definition}."
15952 * NOTE (3) is done in xmlSchemaCheckTypeDefCircular().
15955 * NOTE that (4) and (5) need the following:
15956 * - attribute uses need to be already inherited (apply attr. prohibitions)
15957 * - attribute group references need to be expanded already
15958 * - simple types need to be typefixed already
15960 if (type
->attrUses
&&
15961 (((xmlSchemaItemListPtr
) type
->attrUses
)->nbItems
> 1))
15963 xmlSchemaItemListPtr uses
= (xmlSchemaItemListPtr
) type
->attrUses
;
15964 xmlSchemaAttributeUsePtr use
, tmp
;
15965 int i
, j
, hasId
= 0;
15967 for (i
= uses
->nbItems
-1; i
>= 0; i
--) {
15968 use
= uses
->items
[i
];
15971 * SPEC ct-props-correct
15972 * (4) "Two distinct attribute declarations in the
15973 * {attribute uses} must not have identical {name}s and
15974 * {target namespace}s."
15977 for (j
= i
-1; j
>= 0; j
--) {
15978 tmp
= uses
->items
[j
];
15979 if ((WXS_ATTRUSE_DECL_NAME(use
) ==
15980 WXS_ATTRUSE_DECL_NAME(tmp
)) &&
15981 (WXS_ATTRUSE_DECL_TNS(use
) ==
15982 WXS_ATTRUSE_DECL_TNS(tmp
)))
15984 xmlChar
*str
= NULL
;
15986 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
15987 XML_SCHEMAP_AG_PROPS_CORRECT
,
15988 NULL
, WXS_BASIC_CAST type
,
15990 xmlSchemaGetComponentDesignation(&str
, use
),
15992 FREE_AND_NULL(str
);
15994 * Remove the duplicate.
15996 if (xmlSchemaItemListRemove(uses
, i
) == -1)
16003 * SPEC ct-props-correct
16004 * (5) "Two distinct attribute declarations in the
16005 * {attribute uses} must not have {type definition}s which
16006 * are or are derived from ID."
16008 if (WXS_ATTRUSE_TYPEDEF(use
) != NULL
) {
16009 if (xmlSchemaIsDerivedFromBuiltInType(
16010 WXS_ATTRUSE_TYPEDEF(use
), XML_SCHEMAS_ID
))
16013 xmlChar
*str
= NULL
;
16015 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
16016 XML_SCHEMAP_AG_PROPS_CORRECT
,
16017 NULL
, WXS_BASIC_CAST type
,
16018 "There must not exist more than one attribute "
16019 "declaration of type 'xs:ID' "
16020 "(or derived from 'xs:ID'). The %s violates this "
16022 xmlSchemaGetComponentDesignation(&str
, use
),
16024 FREE_AND_NULL(str
);
16025 if (xmlSchemaItemListRemove(uses
, i
) == -1)
16041 xmlSchemaAreEqualTypes(xmlSchemaTypePtr typeA
,
16042 xmlSchemaTypePtr typeB
)
16045 * TODO: This should implement component-identity
16048 if ((typeA
== NULL
) || (typeB
== NULL
))
16050 return (typeA
== typeB
);
16054 * xmlSchemaCheckCOSCTDerivedOK:
16055 * @ctxt: the schema parser context
16056 * @type: the to-be derived complex type definition
16057 * @baseType: the base complex type definition
16058 * @set: the given set
16060 * Schema Component Constraint:
16061 * Type Derivation OK (Complex) (cos-ct-derived-ok)
16063 * STATUS: completed
16065 * Returns 0 if the constraints are satisfied, or 1
16069 xmlSchemaCheckCOSCTDerivedOK(xmlSchemaAbstractCtxtPtr actxt
,
16070 xmlSchemaTypePtr type
,
16071 xmlSchemaTypePtr baseType
,
16074 int equal
= xmlSchemaAreEqualTypes(type
, baseType
);
16075 /* TODO: Error codes. */
16077 * SPEC "For a complex type definition (call it D, for derived)
16078 * to be validly derived from a type definition (call this
16079 * B, for base) given a subset of {extension, restriction}
16080 * all of the following must be true:"
16084 * SPEC (1) "If B and D are not the same type definition, then the
16085 * {derivation method} of D must not be in the subset."
16087 if (((set
& SUBSET_EXTENSION
) && (WXS_IS_EXTENSION(type
))) ||
16088 ((set
& SUBSET_RESTRICTION
) && (WXS_IS_RESTRICTION(type
))))
16092 * SPEC (2.1) "B and D must be the same type definition."
16097 * SPEC (2.2) "B must be D's {base type definition}."
16099 if (type
->baseType
== baseType
)
16102 * SPEC (2.3.1) "D's {base type definition} must not be the `ur-type
16105 if (WXS_IS_ANYTYPE(type
->baseType
))
16108 if (WXS_IS_COMPLEX(type
->baseType
)) {
16110 * SPEC (2.3.2.1) "If D's {base type definition} is complex, then it
16111 * must be validly derived from B given the subset as defined by this
16114 return (xmlSchemaCheckCOSCTDerivedOK(actxt
, type
->baseType
,
16118 * SPEC (2.3.2.2) "If D's {base type definition} is simple, then it
16119 * must be validly derived from B given the subset as defined in Type
16120 * Derivation OK (Simple) ($3.14.6).
16122 return (xmlSchemaCheckCOSSTDerivedOK(actxt
, type
->baseType
,
16128 * xmlSchemaCheckCOSDerivedOK:
16129 * @type: the derived simple type definition
16130 * @baseType: the base type definition
16133 * Type Derivation OK (Simple) AND Type Derivation OK (Complex)
16135 * Checks wheter @type can be validly derived from @baseType.
16137 * Returns 0 on success, an positive error code otherwise.
16140 xmlSchemaCheckCOSDerivedOK(xmlSchemaAbstractCtxtPtr actxt
,
16141 xmlSchemaTypePtr type
,
16142 xmlSchemaTypePtr baseType
,
16145 if (WXS_IS_SIMPLE(type
))
16146 return (xmlSchemaCheckCOSSTDerivedOK(actxt
, type
, baseType
, set
));
16148 return (xmlSchemaCheckCOSCTDerivedOK(actxt
, type
, baseType
, set
));
16152 * xmlSchemaCheckCOSCTExtends:
16153 * @ctxt: the schema parser context
16154 * @type: the complex type definition
16156 * (3.4.6) Constraints on Complex Type Definition Schema Components
16157 * Schema Component Constraint:
16158 * Derivation Valid (Extension) (cos-ct-extends)
16163 * (1.4.3.2.2.2) "Particle Valid (Extension)"
16165 * Returns 0 if the constraints are satisfied, a positive
16166 * error code if not and -1 if an internal error occurred.
16169 xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt
,
16170 xmlSchemaTypePtr type
)
16172 xmlSchemaTypePtr base
= type
->baseType
;
16174 * TODO: Correct the error code; XML_SCHEMAP_COS_CT_EXTENDS_1_1 is used
16175 * temporarily only.
16178 * SPEC (1) "If the {base type definition} is a complex type definition,
16179 * then all of the following must be true:"
16181 if (WXS_IS_COMPLEX(base
)) {
16183 * SPEC (1.1) "The {final} of the {base type definition} must not
16184 * contain extension."
16186 if (base
->flags
& XML_SCHEMAS_TYPE_FINAL_EXTENSION
) {
16187 xmlSchemaPCustomErr(ctxt
,
16188 XML_SCHEMAP_COS_CT_EXTENDS_1_1
,
16189 WXS_BASIC_CAST type
, NULL
,
16190 "The 'final' of the base type definition "
16191 "contains 'extension'", NULL
);
16192 return (XML_SCHEMAP_COS_CT_EXTENDS_1_1
);
16196 * ATTENTION: The constrains (1.2) and (1.3) are not applied,
16197 * since they are automatically satisfied through the
16198 * inheriting mechanism.
16199 * Note that even if redefining components, the inheriting mechanism
16204 * SPEC (1.2) "Its {attribute uses} must be a subset of the {attribute
16206 * of the complex type definition itself, that is, for every attribute
16207 * use in the {attribute uses} of the {base type definition}, there
16208 * must be an attribute use in the {attribute uses} of the complex
16209 * type definition itself whose {attribute declaration} has the same
16210 * {name}, {target namespace} and {type definition} as its attribute
16213 if (base
->attrUses
!= NULL
) {
16215 xmlSchemaAttributeUsePtr use
, buse
;
16217 for (i
= 0; i
< (WXS_LIST_CAST base
->attrUses
)->nbItems
; i
++) {
16218 buse
= (WXS_LIST_CAST base
->attrUses
)->items
[i
];
16220 if (type
->attrUses
!= NULL
) {
16221 use
= (WXS_LIST_CAST type
->attrUses
)->items
[j
];
16222 for (j
= 0; j
< (WXS_LIST_CAST type
->attrUses
)->nbItems
; j
++)
16224 if ((WXS_ATTRUSE_DECL_NAME(use
) ==
16225 WXS_ATTRUSE_DECL_NAME(buse
)) &&
16226 (WXS_ATTRUSE_DECL_TNS(use
) ==
16227 WXS_ATTRUSE_DECL_TNS(buse
)) &&
16228 (WXS_ATTRUSE_TYPEDEF(use
) ==
16229 WXS_ATTRUSE_TYPEDEF(buse
))
16237 xmlChar
*str
= NULL
;
16239 xmlSchemaCustomErr(ACTXT_CAST ctxt
,
16240 XML_SCHEMAP_COS_CT_EXTENDS_1_2
,
16241 NULL
, WXS_BASIC_CAST type
,
16243 * TODO: The report does not indicate that also the
16244 * type needs to be the same.
16246 "This type is missing a matching correspondent "
16247 "for its {base type}'s %s in its {attribute uses}",
16248 xmlSchemaGetComponentDesignation(&str
,
16256 * SPEC (1.3) "If it has an {attribute wildcard}, the complex type
16257 * definition must also have one, and the base type definition's
16258 * {attribute wildcard}'s {namespace constraint} must be a subset
16259 * of the complex type definition's {attribute wildcard}'s {namespace
16260 * constraint}, as defined by Wildcard Subset ($3.10.6)."
16264 * MAYBE TODO: Enable if ever needed. But this will be needed only
16265 * if created the type via a schema construction API.
16267 if (base
->attributeWildcard
!= NULL
) {
16268 if (type
->attributeWilcard
== NULL
) {
16269 xmlChar
*str
= NULL
;
16271 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
16272 XML_SCHEMAP_COS_CT_EXTENDS_1_3
,
16274 "The base %s has an attribute wildcard, "
16275 "but this type is missing an attribute wildcard",
16276 xmlSchemaGetComponentDesignation(&str
, base
));
16279 } else if (xmlSchemaCheckCOSNSSubset(
16280 base
->attributeWildcard
, type
->attributeWildcard
))
16282 xmlChar
*str
= NULL
;
16284 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
16285 XML_SCHEMAP_COS_CT_EXTENDS_1_3
,
16287 "The attribute wildcard is not a valid "
16288 "superset of the one in the base %s",
16289 xmlSchemaGetComponentDesignation(&str
, base
));
16295 * SPEC (1.4) "One of the following must be true:"
16297 if ((type
->contentTypeDef
!= NULL
) &&
16298 (type
->contentTypeDef
== base
->contentTypeDef
)) {
16300 * SPEC (1.4.1) "The {content type} of the {base type definition}
16301 * and the {content type} of the complex type definition itself
16302 * must be the same simple type definition"
16305 } else if ((type
->contentType
== XML_SCHEMA_CONTENT_EMPTY
) &&
16306 (base
->contentType
== XML_SCHEMA_CONTENT_EMPTY
) ) {
16308 * SPEC (1.4.2) "The {content type} of both the {base type
16309 * definition} and the complex type definition itself must
16315 * SPEC (1.4.3) "All of the following must be true:"
16317 if (type
->subtypes
== NULL
) {
16319 * SPEC 1.4.3.1 The {content type} of the complex type
16320 * definition itself must specify a particle.
16322 xmlSchemaPCustomErr(ctxt
,
16323 XML_SCHEMAP_COS_CT_EXTENDS_1_1
,
16324 WXS_BASIC_CAST type
, NULL
,
16325 "The content type must specify a particle", NULL
);
16326 return (XML_SCHEMAP_COS_CT_EXTENDS_1_1
);
16329 * SPEC (1.4.3.2) "One of the following must be true:"
16331 if (base
->contentType
== XML_SCHEMA_CONTENT_EMPTY
) {
16333 * SPEC (1.4.3.2.1) "The {content type} of the {base type
16334 * definition} must be empty.
16339 * SPEC (1.4.3.2.2) "All of the following must be true:"
16341 if ((type
->contentType
!= base
->contentType
) ||
16342 ((type
->contentType
!= XML_SCHEMA_CONTENT_MIXED
) &&
16343 (type
->contentType
!= XML_SCHEMA_CONTENT_ELEMENTS
))) {
16345 * SPEC (1.4.3.2.2.1) "Both {content type}s must be mixed
16346 * or both must be element-only."
16348 xmlSchemaPCustomErr(ctxt
,
16349 XML_SCHEMAP_COS_CT_EXTENDS_1_1
,
16350 WXS_BASIC_CAST type
, NULL
,
16351 "The content type of both, the type and its base "
16352 "type, must either 'mixed' or 'element-only'", NULL
);
16353 return (XML_SCHEMAP_COS_CT_EXTENDS_1_1
);
16356 * URGENT TODO SPEC (1.4.3.2.2.2) "The particle of the
16357 * complex type definition must be a `valid extension`
16358 * of the {base type definition}'s particle, as defined
16359 * in Particle Valid (Extension) ($3.9.6)."
16361 * NOTE that we won't check "Particle Valid (Extension)",
16362 * since it is ensured by the derivation process in
16363 * xmlSchemaTypeFixup(). We need to implement this when heading
16364 * for a construction API
16365 * TODO: !! This is needed to be checked if redefining a type !!
16369 * URGENT TODO (1.5)
16374 * SPEC (2) "If the {base type definition} is a simple type definition,
16375 * then all of the following must be true:"
16377 if (type
->contentTypeDef
!= base
) {
16379 * SPEC (2.1) "The {content type} must be the same simple type
16382 xmlSchemaPCustomErr(ctxt
,
16383 XML_SCHEMAP_COS_CT_EXTENDS_1_1
,
16384 WXS_BASIC_CAST type
, NULL
,
16385 "The content type must be the simple base type", NULL
);
16386 return (XML_SCHEMAP_COS_CT_EXTENDS_1_1
);
16388 if (base
->flags
& XML_SCHEMAS_TYPE_FINAL_EXTENSION
) {
16390 * SPEC (2.2) "The {final} of the {base type definition} must not
16391 * contain extension"
16392 * NOTE that this is the same as (1.1).
16394 xmlSchemaPCustomErr(ctxt
,
16395 XML_SCHEMAP_COS_CT_EXTENDS_1_1
,
16396 WXS_BASIC_CAST type
, NULL
,
16397 "The 'final' of the base type definition "
16398 "contains 'extension'", NULL
);
16399 return (XML_SCHEMAP_COS_CT_EXTENDS_1_1
);
16406 * xmlSchemaCheckDerivationOKRestriction:
16407 * @ctxt: the schema parser context
16408 * @type: the complex type definition
16410 * (3.4.6) Constraints on Complex Type Definition Schema Components
16411 * Schema Component Constraint:
16412 * Derivation Valid (Restriction, Complex) (derivation-ok-restriction)
16419 * In XML Schema 1.1 this will be:
16420 * Validation Rule: Checking complex type subsumption
16422 * Returns 0 if the constraints are satisfied, a positive
16423 * error code if not and -1 if an internal error occurred.
16426 xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt
,
16427 xmlSchemaTypePtr type
)
16429 xmlSchemaTypePtr base
;
16432 * TODO: Correct the error code; XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1 is used
16433 * temporarily only.
16435 base
= type
->baseType
;
16436 if (! WXS_IS_COMPLEX(base
)) {
16437 xmlSchemaCustomErr(ACTXT_CAST ctxt
,
16438 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1
,
16439 type
->node
, WXS_BASIC_CAST type
,
16440 "The base type must be a complex type", NULL
, NULL
);
16443 if (base
->flags
& XML_SCHEMAS_TYPE_FINAL_RESTRICTION
) {
16445 * SPEC (1) "The {base type definition} must be a complex type
16446 * definition whose {final} does not contain restriction."
16448 xmlSchemaCustomErr(ACTXT_CAST ctxt
,
16449 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1
,
16450 type
->node
, WXS_BASIC_CAST type
,
16451 "The 'final' of the base type definition "
16452 "contains 'restriction'", NULL
, NULL
);
16453 return (ctxt
->err
);
16456 * SPEC (2), (3) and (4)
16457 * Those are handled in a separate function, since the
16458 * same constraints are needed for redefinition of
16459 * attribute groups as well.
16461 if (xmlSchemaCheckDerivationOKRestriction2to4(ctxt
,
16462 XML_SCHEMA_ACTION_DERIVE
,
16463 WXS_BASIC_CAST type
, WXS_BASIC_CAST base
,
16464 type
->attrUses
, base
->attrUses
,
16465 type
->attributeWildcard
,
16466 base
->attributeWildcard
) == -1)
16471 * SPEC (5) "One of the following must be true:"
16473 if (base
->builtInType
== XML_SCHEMAS_ANYTYPE
) {
16475 * SPEC (5.1) "The {base type definition} must be the
16476 * `ur-type definition`."
16479 } else if ((type
->contentType
== XML_SCHEMA_CONTENT_SIMPLE
) ||
16480 (type
->contentType
== XML_SCHEMA_CONTENT_BASIC
)) {
16482 * SPEC (5.2.1) "The {content type} of the complex type definition
16483 * must be a simple type definition"
16485 * SPEC (5.2.2) "One of the following must be true:"
16487 if ((base
->contentType
== XML_SCHEMA_CONTENT_SIMPLE
) ||
16488 (base
->contentType
== XML_SCHEMA_CONTENT_BASIC
))
16492 * SPEC (5.2.2.1) "The {content type} of the {base type
16493 * definition} must be a simple type definition from which
16494 * the {content type} is validly derived given the empty
16495 * set as defined in Type Derivation OK (Simple) ($3.14.6)."
16497 * ATTENTION TODO: This seems not needed if the type implicitely
16498 * derived from the base type.
16501 err
= xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST ctxt
,
16502 type
->contentTypeDef
, base
->contentTypeDef
, 0);
16504 xmlChar
*strA
= NULL
, *strB
= NULL
;
16508 xmlSchemaCustomErr(ACTXT_CAST ctxt
,
16509 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1
,
16510 NULL
, WXS_BASIC_CAST type
,
16511 "The {content type} %s is not validly derived from the "
16512 "base type's {content type} %s",
16513 xmlSchemaGetComponentDesignation(&strA
,
16514 type
->contentTypeDef
),
16515 xmlSchemaGetComponentDesignation(&strB
,
16516 base
->contentTypeDef
));
16517 FREE_AND_NULL(strA
);
16518 FREE_AND_NULL(strB
);
16521 } else if ((base
->contentType
== XML_SCHEMA_CONTENT_MIXED
) &&
16522 (xmlSchemaIsParticleEmptiable(
16523 (xmlSchemaParticlePtr
) base
->subtypes
))) {
16525 * SPEC (5.2.2.2) "The {base type definition} must be mixed
16526 * and have a particle which is `emptiable` as defined in
16527 * Particle Emptiable ($3.9.6)."
16531 xmlSchemaPCustomErr(ctxt
,
16532 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1
,
16533 WXS_BASIC_CAST type
, NULL
,
16534 "The content type of the base type must be either "
16535 "a simple type or 'mixed' and an emptiable particle", NULL
);
16536 return (ctxt
->err
);
16538 } else if (type
->contentType
== XML_SCHEMA_CONTENT_EMPTY
) {
16540 * SPEC (5.3.1) "The {content type} of the complex type itself must
16543 if (base
->contentType
== XML_SCHEMA_CONTENT_EMPTY
) {
16545 * SPEC (5.3.2.1) "The {content type} of the {base type
16546 * definition} must also be empty."
16549 } else if (((base
->contentType
== XML_SCHEMA_CONTENT_ELEMENTS
) ||
16550 (base
->contentType
== XML_SCHEMA_CONTENT_MIXED
)) &&
16551 xmlSchemaIsParticleEmptiable(
16552 (xmlSchemaParticlePtr
) base
->subtypes
)) {
16554 * SPEC (5.3.2.2) "The {content type} of the {base type
16555 * definition} must be elementOnly or mixed and have a particle
16556 * which is `emptiable` as defined in Particle Emptiable ($3.9.6)."
16560 xmlSchemaPCustomErr(ctxt
,
16561 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1
,
16562 WXS_BASIC_CAST type
, NULL
,
16563 "The content type of the base type must be either "
16564 "empty or 'mixed' (or 'elements-only') and an emptiable "
16566 return (ctxt
->err
);
16568 } else if ((type
->contentType
== XML_SCHEMA_CONTENT_ELEMENTS
) ||
16569 WXS_HAS_MIXED_CONTENT(type
)) {
16571 * SPEC (5.4.1.1) "The {content type} of the complex type definition
16572 * itself must be element-only"
16574 if (WXS_HAS_MIXED_CONTENT(type
) && (! WXS_HAS_MIXED_CONTENT(base
))) {
16576 * SPEC (5.4.1.2) "The {content type} of the complex type
16577 * definition itself and of the {base type definition} must be
16580 xmlSchemaPCustomErr(ctxt
,
16581 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1
,
16582 WXS_BASIC_CAST type
, NULL
,
16583 "If the content type is 'mixed', then the content type of the "
16584 "base type must also be 'mixed'", NULL
);
16585 return (ctxt
->err
);
16588 * SPEC (5.4.2) "The particle of the complex type definition itself
16589 * must be a `valid restriction` of the particle of the {content
16590 * type} of the {base type definition} as defined in Particle Valid
16591 * (Restriction) ($3.9.6).
16593 * URGENT TODO: (5.4.2)
16596 xmlSchemaPCustomErr(ctxt
,
16597 XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1
,
16598 WXS_BASIC_CAST type
, NULL
,
16599 "The type is not a valid restriction of its base type", NULL
);
16600 return (ctxt
->err
);
16606 * xmlSchemaCheckCTComponent:
16607 * @ctxt: the schema parser context
16608 * @type: the complex type definition
16610 * (3.4.6) Constraints on Complex Type Definition Schema Components
16612 * Returns 0 if the constraints are satisfied, a positive
16613 * error code if not and -1 if an internal error occurred.
16616 xmlSchemaCheckCTComponent(xmlSchemaParserCtxtPtr ctxt
,
16617 xmlSchemaTypePtr type
)
16621 * Complex Type Definition Properties Correct
16623 ret
= xmlSchemaCheckCTPropsCorrect(ctxt
, type
);
16626 if (WXS_IS_EXTENSION(type
))
16627 ret
= xmlSchemaCheckCOSCTExtends(ctxt
, type
);
16629 ret
= xmlSchemaCheckDerivationOKRestriction(ctxt
, type
);
16634 * xmlSchemaCheckSRCCT:
16635 * @ctxt: the schema parser context
16636 * @type: the complex type definition
16638 * (3.4.3) Constraints on XML Representations of Complex Type Definitions:
16639 * Schema Representation Constraint:
16640 * Complex Type Definition Representation OK (src-ct)
16642 * Returns 0 if the constraints are satisfied, a positive
16643 * error code if not and -1 if an internal error occurred.
16646 xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt
,
16647 xmlSchemaTypePtr type
)
16649 xmlSchemaTypePtr base
;
16653 * TODO: Adjust the error codes here, as I used
16654 * XML_SCHEMAP_SRC_CT_1 only yet.
16656 base
= type
->baseType
;
16657 if (! WXS_HAS_SIMPLE_CONTENT(type
)) {
16659 * 1 If the <complexContent> alternative is chosen, the type definition
16660 * `resolved` to by the `actual value` of the base [attribute]
16661 * must be a complex type definition;
16663 if (! WXS_IS_COMPLEX(base
)) {
16664 xmlChar
*str
= NULL
;
16665 xmlSchemaPCustomErr(ctxt
,
16666 XML_SCHEMAP_SRC_CT_1
,
16667 WXS_BASIC_CAST type
, type
->node
,
16668 "If using <complexContent>, the base type is expected to be "
16669 "a complex type. The base type '%s' is a simple type",
16670 xmlSchemaFormatQName(&str
, base
->targetNamespace
,
16673 return (XML_SCHEMAP_SRC_CT_1
);
16678 * 2 If the <simpleContent> alternative is chosen, all of the
16679 * following must be true:
16680 * 2.1 The type definition `resolved` to by the `actual value` of the
16681 * base [attribute] must be one of the following:
16683 if (WXS_IS_SIMPLE(base
)) {
16684 if (WXS_IS_EXTENSION(type
) == 0) {
16685 xmlChar
*str
= NULL
;
16687 * 2.1.3 only if the <extension> alternative is also
16688 * chosen, a simple type definition.
16690 /* TODO: Change error code to ..._SRC_CT_2_1_3. */
16691 xmlSchemaPCustomErr(ctxt
,
16692 XML_SCHEMAP_SRC_CT_1
,
16693 WXS_BASIC_CAST type
, NULL
,
16694 "If using <simpleContent> and <restriction>, the base "
16695 "type must be a complex type. The base type '%s' is "
16697 xmlSchemaFormatQName(&str
, base
->targetNamespace
,
16700 return (XML_SCHEMAP_SRC_CT_1
);
16703 /* Base type is a complex type. */
16704 if ((base
->contentType
== XML_SCHEMA_CONTENT_SIMPLE
) ||
16705 (base
->contentType
== XML_SCHEMA_CONTENT_BASIC
)) {
16707 * 2.1.1 a complex type definition whose {content type} is a
16708 * simple type definition;
16711 if (base
->contentTypeDef
== NULL
) {
16712 xmlSchemaPCustomErr(ctxt
, XML_SCHEMAP_INTERNAL
,
16713 WXS_BASIC_CAST type
, NULL
,
16714 "Internal error: xmlSchemaCheckSRCCT, "
16715 "'%s', base type has no content type",
16719 } else if ((base
->contentType
== XML_SCHEMA_CONTENT_MIXED
) &&
16720 (WXS_IS_RESTRICTION(type
))) {
16723 * 2.1.2 only if the <restriction> alternative is also
16724 * chosen, a complex type definition whose {content type}
16725 * is mixed and a particle emptiable.
16727 if (! xmlSchemaIsParticleEmptiable(
16728 (xmlSchemaParticlePtr
) base
->subtypes
)) {
16729 ret
= XML_SCHEMAP_SRC_CT_1
;
16732 * Attention: at this point the <simpleType> child is in
16733 * ->contentTypeDef (put there during parsing).
16735 if (type
->contentTypeDef
== NULL
) {
16736 xmlChar
*str
= NULL
;
16738 * 2.2 If clause 2.1.2 above is satisfied, then there
16739 * must be a <simpleType> among the [children] of
16742 /* TODO: Change error code to ..._SRC_CT_2_2. */
16743 xmlSchemaPCustomErr(ctxt
,
16744 XML_SCHEMAP_SRC_CT_1
,
16745 WXS_BASIC_CAST type
, NULL
,
16746 "A <simpleType> is expected among the children "
16747 "of <restriction>, if <simpleContent> is used and "
16748 "the base type '%s' is a complex type",
16749 xmlSchemaFormatQName(&str
, base
->targetNamespace
,
16752 return (XML_SCHEMAP_SRC_CT_1
);
16755 ret
= XML_SCHEMAP_SRC_CT_1
;
16759 xmlChar
*str
= NULL
;
16760 if (WXS_IS_RESTRICTION(type
)) {
16761 xmlSchemaPCustomErr(ctxt
,
16762 XML_SCHEMAP_SRC_CT_1
,
16763 WXS_BASIC_CAST type
, NULL
,
16764 "If <simpleContent> and <restriction> is used, the "
16765 "base type must be a simple type or a complex type with "
16766 "mixed content and particle emptiable. The base type "
16767 "'%s' is none of those",
16768 xmlSchemaFormatQName(&str
, base
->targetNamespace
,
16771 xmlSchemaPCustomErr(ctxt
,
16772 XML_SCHEMAP_SRC_CT_1
,
16773 WXS_BASIC_CAST type
, NULL
,
16774 "If <simpleContent> and <extension> is used, the "
16775 "base type must be a simple type. The base type '%s' "
16776 "is a complex type",
16777 xmlSchemaFormatQName(&str
, base
->targetNamespace
,
16784 * SPEC (3) "The corresponding complex type definition component must
16785 * satisfy the conditions set out in Constraints on Complex Type
16786 * Definition Schema Components ($3.4.6);"
16787 * NOTE (3) will be done in xmlSchemaTypeFixup().
16790 * SPEC (4) If clause 2.2.1 or clause 2.2.2 in the correspondence specification
16791 * above for {attribute wildcard} is satisfied, the intensional
16792 * intersection must be expressible, as defined in Attribute Wildcard
16793 * Intersection ($3.10.6).
16794 * NOTE (4) is done in xmlSchemaFixupTypeAttributeUses().
16799 #ifdef ENABLE_PARTICLE_RESTRICTION
16801 * xmlSchemaCheckParticleRangeOK:
16802 * @ctxt: the schema parser context
16803 * @type: the complex type definition
16805 * (3.9.6) Constraints on Particle Schema Components
16806 * Schema Component Constraint:
16807 * Occurrence Range OK (range-ok)
16811 * Returns 0 if the constraints are satisfied, a positive
16812 * error code if not and -1 if an internal error occurred.
16815 xmlSchemaCheckParticleRangeOK(int rmin
, int rmax
,
16816 int bmin
, int bmax
)
16820 if ((bmax
!= UNBOUNDED
) &&
16827 * xmlSchemaCheckRCaseNameAndTypeOK:
16828 * @ctxt: the schema parser context
16829 * @r: the restricting element declaration particle
16830 * @b: the base element declaration particle
16832 * (3.9.6) Constraints on Particle Schema Components
16833 * Schema Component Constraint:
16834 * Particle Restriction OK (Elt:Elt -- NameAndTypeOK)
16835 * (rcase-NameAndTypeOK)
16841 * Returns 0 if the constraints are satisfied, a positive
16842 * error code if not and -1 if an internal error occurred.
16845 xmlSchemaCheckRCaseNameAndTypeOK(xmlSchemaParserCtxtPtr ctxt
,
16846 xmlSchemaParticlePtr r
,
16847 xmlSchemaParticlePtr b
)
16849 xmlSchemaElementPtr elemR
, elemB
;
16851 /* TODO: Error codes (rcase-NameAndTypeOK). */
16852 elemR
= (xmlSchemaElementPtr
) r
->children
;
16853 elemB
= (xmlSchemaElementPtr
) b
->children
;
16855 * SPEC (1) "The declarations' {name}s and {target namespace}s are
16858 if ((elemR
!= elemB
) &&
16859 ((! xmlStrEqual(elemR
->name
, elemB
->name
)) ||
16860 (! xmlStrEqual(elemR
->targetNamespace
, elemB
->targetNamespace
))))
16863 * SPEC (2) "R's occurrence range is a valid restriction of B's
16864 * occurrence range as defined by Occurrence Range OK ($3.9.6)."
16866 if (xmlSchemaCheckParticleRangeOK(r
->minOccurs
, r
->maxOccurs
,
16867 b
->minOccurs
, b
->maxOccurs
) != 0)
16870 * SPEC (3.1) "Both B's declaration's {scope} and R's declaration's
16871 * {scope} are global."
16873 if (elemR
== elemB
)
16876 * SPEC (3.2.1) "Either B's {nillable} is true or R's {nillable} is false."
16878 if (((elemB
->flags
& XML_SCHEMAS_ELEM_NILLABLE
) == 0) &&
16879 (elemR
->flags
& XML_SCHEMAS_ELEM_NILLABLE
))
16882 * SPEC (3.2.2) "either B's declaration's {value constraint} is absent,
16883 * or is not fixed, or R's declaration's {value constraint} is fixed
16884 * with the same value."
16886 if ((elemB
->value
!= NULL
) && (elemB
->flags
& XML_SCHEMAS_ELEM_FIXED
) &&
16887 ((elemR
->value
== NULL
) ||
16888 ((elemR
->flags
& XML_SCHEMAS_ELEM_FIXED
) == 0) ||
16889 /* TODO: Equality of the initial value or normalized or canonical? */
16890 (! xmlStrEqual(elemR
->value
, elemB
->value
))))
16893 * TODO: SPEC (3.2.3) "R's declaration's {identity-constraint
16894 * definitions} is a subset of B's declaration's {identity-constraint
16895 * definitions}, if any."
16897 if (elemB
->idcs
!= NULL
) {
16901 * SPEC (3.2.4) "R's declaration's {disallowed substitutions} is a
16902 * superset of B's declaration's {disallowed substitutions}."
16904 if (((elemB
->flags
& XML_SCHEMAS_ELEM_BLOCK_EXTENSION
) &&
16905 ((elemR
->flags
& XML_SCHEMAS_ELEM_BLOCK_EXTENSION
) == 0)) ||
16906 ((elemB
->flags
& XML_SCHEMAS_ELEM_BLOCK_RESTRICTION
) &&
16907 ((elemR
->flags
& XML_SCHEMAS_ELEM_BLOCK_RESTRICTION
) == 0)) ||
16908 ((elemB
->flags
& XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION
) &&
16909 ((elemR
->flags
& XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION
) == 0)))
16912 * SPEC (3.2.5) "R's {type definition} is validly derived given
16913 * {extension, list, union} from B's {type definition}"
16915 * BADSPEC TODO: What's the point of adding "list" and "union" to the
16916 * set, if the corresponding constraints handle "restriction" and
16917 * "extension" only?
16923 set
|= SUBSET_EXTENSION
;
16924 set
|= SUBSET_LIST
;
16925 set
|= SUBSET_UNION
;
16926 if (xmlSchemaCheckCOSDerivedOK(ACTXT_CAST ctxt
, elemR
->subtypes
,
16927 elemB
->subtypes
, set
) != 0)
16934 * xmlSchemaCheckRCaseNSCompat:
16935 * @ctxt: the schema parser context
16936 * @r: the restricting element declaration particle
16937 * @b: the base wildcard particle
16939 * (3.9.6) Constraints on Particle Schema Components
16940 * Schema Component Constraint:
16941 * Particle Derivation OK (Elt:Any -- NSCompat)
16946 * Returns 0 if the constraints are satisfied, a positive
16947 * error code if not and -1 if an internal error occurred.
16950 xmlSchemaCheckRCaseNSCompat(xmlSchemaParserCtxtPtr ctxt
,
16951 xmlSchemaParticlePtr r
,
16952 xmlSchemaParticlePtr b
)
16954 /* TODO:Error codes (rcase-NSCompat). */
16956 * SPEC "For an element declaration particle to be a `valid restriction`
16957 * of a wildcard particle all of the following must be true:"
16959 * SPEC (1) "The element declaration's {target namespace} is `valid`
16960 * with respect to the wildcard's {namespace constraint} as defined by
16961 * Wildcard allows Namespace Name ($3.10.4)."
16963 if (xmlSchemaCheckCVCWildcardNamespace((xmlSchemaWildcardPtr
) b
->children
,
16964 ((xmlSchemaElementPtr
) r
->children
)->targetNamespace
) != 0)
16967 * SPEC (2) "R's occurrence range is a valid restriction of B's
16968 * occurrence range as defined by Occurrence Range OK ($3.9.6)."
16970 if (xmlSchemaCheckParticleRangeOK(r
->minOccurs
, r
->maxOccurs
,
16971 b
->minOccurs
, b
->maxOccurs
) != 0)
16978 * xmlSchemaCheckRCaseRecurseAsIfGroup:
16979 * @ctxt: the schema parser context
16980 * @r: the restricting element declaration particle
16981 * @b: the base model group particle
16983 * (3.9.6) Constraints on Particle Schema Components
16984 * Schema Component Constraint:
16985 * Particle Derivation OK (Elt:All/Choice/Sequence -- RecurseAsIfGroup)
16986 * (rcase-RecurseAsIfGroup)
16990 * Returns 0 if the constraints are satisfied, a positive
16991 * error code if not and -1 if an internal error occurred.
16994 xmlSchemaCheckRCaseRecurseAsIfGroup(xmlSchemaParserCtxtPtr ctxt
,
16995 xmlSchemaParticlePtr r
,
16996 xmlSchemaParticlePtr b
)
16998 /* TODO: Error codes (rcase-RecurseAsIfGroup). */
17004 * xmlSchemaCheckRCaseNSSubset:
17005 * @ctxt: the schema parser context
17006 * @r: the restricting wildcard particle
17007 * @b: the base wildcard particle
17009 * (3.9.6) Constraints on Particle Schema Components
17010 * Schema Component Constraint:
17011 * Particle Derivation OK (Any:Any -- NSSubset)
17016 * Returns 0 if the constraints are satisfied, a positive
17017 * error code if not and -1 if an internal error occurred.
17020 xmlSchemaCheckRCaseNSSubset(xmlSchemaParserCtxtPtr ctxt
,
17021 xmlSchemaParticlePtr r
,
17022 xmlSchemaParticlePtr b
,
17025 /* TODO: Error codes (rcase-NSSubset). */
17027 * SPEC (1) "R's occurrence range is a valid restriction of B's
17028 * occurrence range as defined by Occurrence Range OK ($3.9.6)."
17030 if (xmlSchemaCheckParticleRangeOK(r
->minOccurs
, r
->maxOccurs
,
17031 b
->minOccurs
, b
->maxOccurs
))
17034 * SPEC (2) "R's {namespace constraint} must be an intensional subset
17035 * of B's {namespace constraint} as defined by Wildcard Subset ($3.10.6)."
17037 if (xmlSchemaCheckCOSNSSubset((xmlSchemaWildcardPtr
) r
->children
,
17038 (xmlSchemaWildcardPtr
) b
->children
))
17041 * SPEC (3) "Unless B is the content model wildcard of the `ur-type
17042 * definition`, R's {process contents} must be identical to or stronger
17043 * than B's {process contents}, where strict is stronger than lax is
17044 * stronger than skip."
17046 if (! isAnyTypeBase
) {
17047 if ( ((xmlSchemaWildcardPtr
) r
->children
)->processContents
<
17048 ((xmlSchemaWildcardPtr
) b
->children
)->processContents
)
17056 * xmlSchemaCheckCOSParticleRestrict:
17057 * @ctxt: the schema parser context
17058 * @type: the complex type definition
17060 * (3.9.6) Constraints on Particle Schema Components
17061 * Schema Component Constraint:
17062 * Particle Valid (Restriction) (cos-particle-restrict)
17066 * Returns 0 if the constraints are satisfied, a positive
17067 * error code if not and -1 if an internal error occurred.
17070 xmlSchemaCheckCOSParticleRestrict(xmlSchemaParserCtxtPtr ctxt
,
17071 xmlSchemaParticlePtr r
,
17072 xmlSchemaParticlePtr b
)
17076 /*part = WXS_TYPE_PARTICLE(type);
17077 basePart = WXS_TYPE_PARTICLE(base);
17083 * SPEC (1) "They are the same particle."
17094 * xmlSchemaCheckRCaseNSRecurseCheckCardinality:
17095 * @ctxt: the schema parser context
17096 * @r: the model group particle
17097 * @b: the base wildcard particle
17099 * (3.9.6) Constraints on Particle Schema Components
17100 * Schema Component Constraint:
17101 * Particle Derivation OK (All/Choice/Sequence:Any --
17102 * NSRecurseCheckCardinality)
17103 * (rcase-NSRecurseCheckCardinality)
17105 * STATUS: TODO: subst-groups
17107 * Returns 0 if the constraints are satisfied, a positive
17108 * error code if not and -1 if an internal error occurred.
17111 xmlSchemaCheckRCaseNSRecurseCheckCardinality(xmlSchemaParserCtxtPtr ctxt
,
17112 xmlSchemaParticlePtr r
,
17113 xmlSchemaParticlePtr b
)
17115 xmlSchemaParticlePtr part
;
17116 /* TODO: Error codes (rcase-NSRecurseCheckCardinality). */
17117 if ((r
->children
== NULL
) || (r
->children
->children
== NULL
))
17120 * SPEC "For a group particle to be a `valid restriction` of a
17121 * wildcard particle..."
17123 * SPEC (1) "Every member of the {particles} of the group is a `valid
17124 * restriction` of the wildcard as defined by
17125 * Particle Valid (Restriction) ($3.9.6)."
17127 part
= (xmlSchemaParticlePtr
) r
->children
->children
;
17129 if (xmlSchemaCheckCOSParticleRestrict(ctxt
, part
, b
))
17131 part
= (xmlSchemaParticlePtr
) part
->next
;
17132 } while (part
!= NULL
);
17134 * SPEC (2) "The effective total range of the group [...] is a
17135 * valid restriction of B's occurrence range as defined by
17136 * Occurrence Range OK ($3.9.6)."
17138 if (xmlSchemaCheckParticleRangeOK(
17139 xmlSchemaGetParticleTotalRangeMin(r
),
17140 xmlSchemaGetParticleTotalRangeMax(r
),
17141 b
->minOccurs
, b
->maxOccurs
) != 0)
17148 * xmlSchemaCheckRCaseRecurse:
17149 * @ctxt: the schema parser context
17150 * @r: the <all> or <sequence> model group particle
17151 * @b: the base <all> or <sequence> model group particle
17153 * (3.9.6) Constraints on Particle Schema Components
17154 * Schema Component Constraint:
17155 * Particle Derivation OK (All:All,Sequence:Sequence --
17160 * TODO: subst-groups
17162 * Returns 0 if the constraints are satisfied, a positive
17163 * error code if not and -1 if an internal error occurred.
17166 xmlSchemaCheckRCaseRecurse(xmlSchemaParserCtxtPtr ctxt
,
17167 xmlSchemaParticlePtr r
,
17168 xmlSchemaParticlePtr b
)
17170 /* xmlSchemaParticlePtr part; */
17171 /* TODO: Error codes (rcase-Recurse). */
17172 if ((r
->children
== NULL
) || (b
->children
== NULL
) ||
17173 (r
->children
->type
!= b
->children
->type
))
17176 * SPEC "For an all or sequence group particle to be a `valid
17177 * restriction` of another group particle with the same {compositor}..."
17179 * SPEC (1) "R's occurrence range is a valid restriction of B's
17180 * occurrence range as defined by Occurrence Range OK ($3.9.6)."
17182 if (xmlSchemaCheckParticleRangeOK(r
->minOccurs
, r
->maxOccurs
,
17183 b
->minOccurs
, b
->maxOccurs
))
17192 #define FACET_RESTR_MUTUAL_ERR(fac1, fac2) \
17193 xmlSchemaPCustomErrExt(pctxt, \
17194 XML_SCHEMAP_INVALID_FACET_VALUE, \
17195 WXS_BASIC_CAST fac1, fac1->node, \
17196 "It is an error for both '%s' and '%s' to be specified on the "\
17197 "same type definition", \
17198 BAD_CAST xmlSchemaFacetTypeToString(fac1->type), \
17199 BAD_CAST xmlSchemaFacetTypeToString(fac2->type), NULL);
17201 #define FACET_RESTR_ERR(fac1, msg) \
17202 xmlSchemaPCustomErr(pctxt, \
17203 XML_SCHEMAP_INVALID_FACET_VALUE, \
17204 WXS_BASIC_CAST fac1, fac1->node, \
17207 #define FACET_RESTR_FIXED_ERR(fac) \
17208 xmlSchemaPCustomErr(pctxt, \
17209 XML_SCHEMAP_INVALID_FACET_VALUE, \
17210 WXS_BASIC_CAST fac, fac->node, \
17211 "The base type's facet is 'fixed', thus the value must not " \
17215 xmlSchemaDeriveFacetErr(xmlSchemaParserCtxtPtr pctxt
,
17216 xmlSchemaFacetPtr facet1
,
17217 xmlSchemaFacetPtr facet2
,
17222 xmlChar
*msg
= NULL
;
17224 msg
= xmlStrdup(BAD_CAST
"'");
17225 msg
= xmlStrcat(msg
, xmlSchemaFacetTypeToString(facet1
->type
));
17226 msg
= xmlStrcat(msg
, BAD_CAST
"' has to be");
17227 if (lessGreater
== 0)
17228 msg
= xmlStrcat(msg
, BAD_CAST
" equal to");
17229 if (lessGreater
== 1)
17230 msg
= xmlStrcat(msg
, BAD_CAST
" greater than");
17232 msg
= xmlStrcat(msg
, BAD_CAST
" less than");
17235 msg
= xmlStrcat(msg
, BAD_CAST
" or equal to");
17236 msg
= xmlStrcat(msg
, BAD_CAST
" '");
17237 msg
= xmlStrcat(msg
, xmlSchemaFacetTypeToString(facet2
->type
));
17239 msg
= xmlStrcat(msg
, BAD_CAST
"' of the base type");
17241 msg
= xmlStrcat(msg
, BAD_CAST
"'");
17243 xmlSchemaPCustomErr(pctxt
,
17244 XML_SCHEMAP_INVALID_FACET_VALUE
,
17245 WXS_BASIC_CAST facet1
, NULL
,
17246 (const char *) msg
, NULL
);
17253 * xmlSchemaDeriveAndValidateFacets:
17255 * Schema Component Constraint: Simple Type Restriction (Facets)
17256 * (st-restrict-facets)
17259 xmlSchemaDeriveAndValidateFacets(xmlSchemaParserCtxtPtr pctxt
,
17260 xmlSchemaTypePtr type
)
17262 xmlSchemaTypePtr base
= type
->baseType
;
17263 xmlSchemaFacetLinkPtr link
, cur
, last
= NULL
;
17264 xmlSchemaFacetPtr facet
, bfacet
,
17265 flength
= NULL
, ftotdig
= NULL
, ffracdig
= NULL
,
17266 fmaxlen
= NULL
, fminlen
= NULL
, /* facets of the current type */
17267 fmininc
= NULL
, fmaxinc
= NULL
,
17268 fminexc
= NULL
, fmaxexc
= NULL
,
17269 bflength
= NULL
, bftotdig
= NULL
, bffracdig
= NULL
,
17270 bfmaxlen
= NULL
, bfminlen
= NULL
, /* facets of the base type */
17271 bfmininc
= NULL
, bfmaxinc
= NULL
,
17272 bfminexc
= NULL
, bfmaxexc
= NULL
;
17273 int res
; /* err = 0, fixedErr; */
17276 * SPEC st-restrict-facets 1:
17277 * "The {variety} of R is the same as that of B."
17280 * SPEC st-restrict-facets 2:
17281 * "If {variety} is atomic, the {primitive type definition}
17282 * of R is the same as that of B."
17284 * NOTE: we leave 1 & 2 out for now, since this will be
17285 * satisfied by the derivation process.
17286 * CONSTRUCTION TODO: Maybe needed if using a construction API.
17289 * SPEC st-restrict-facets 3:
17290 * "The {facets} of R are the union of S and the {facets}
17291 * of B, eliminating duplicates. To eliminate duplicates,
17292 * when a facet of the same kind occurs in both S and the
17293 * {facets} of B, the one in the {facets} of B is not
17294 * included, with the exception of enumeration and pattern
17295 * facets, for which multiple occurrences with distinct values
17299 if ((type
->facetSet
== NULL
) && (base
->facetSet
== NULL
))
17302 last
= type
->facetSet
;
17304 while (last
->next
!= NULL
)
17307 for (cur
= type
->facetSet
; cur
!= NULL
; cur
= cur
->next
) {
17308 facet
= cur
->facet
;
17309 switch (facet
->type
) {
17310 case XML_SCHEMA_FACET_LENGTH
:
17311 flength
= facet
; break;
17312 case XML_SCHEMA_FACET_MINLENGTH
:
17313 fminlen
= facet
; break;
17314 case XML_SCHEMA_FACET_MININCLUSIVE
:
17315 fmininc
= facet
; break;
17316 case XML_SCHEMA_FACET_MINEXCLUSIVE
:
17317 fminexc
= facet
; break;
17318 case XML_SCHEMA_FACET_MAXLENGTH
:
17319 fmaxlen
= facet
; break;
17320 case XML_SCHEMA_FACET_MAXINCLUSIVE
:
17321 fmaxinc
= facet
; break;
17322 case XML_SCHEMA_FACET_MAXEXCLUSIVE
:
17323 fmaxexc
= facet
; break;
17324 case XML_SCHEMA_FACET_TOTALDIGITS
:
17325 ftotdig
= facet
; break;
17326 case XML_SCHEMA_FACET_FRACTIONDIGITS
:
17327 ffracdig
= facet
; break;
17332 for (cur
= base
->facetSet
; cur
!= NULL
; cur
= cur
->next
) {
17333 facet
= cur
->facet
;
17334 switch (facet
->type
) {
17335 case XML_SCHEMA_FACET_LENGTH
:
17336 bflength
= facet
; break;
17337 case XML_SCHEMA_FACET_MINLENGTH
:
17338 bfminlen
= facet
; break;
17339 case XML_SCHEMA_FACET_MININCLUSIVE
:
17340 bfmininc
= facet
; break;
17341 case XML_SCHEMA_FACET_MINEXCLUSIVE
:
17342 bfminexc
= facet
; break;
17343 case XML_SCHEMA_FACET_MAXLENGTH
:
17344 bfmaxlen
= facet
; break;
17345 case XML_SCHEMA_FACET_MAXINCLUSIVE
:
17346 bfmaxinc
= facet
; break;
17347 case XML_SCHEMA_FACET_MAXEXCLUSIVE
:
17348 bfmaxexc
= facet
; break;
17349 case XML_SCHEMA_FACET_TOTALDIGITS
:
17350 bftotdig
= facet
; break;
17351 case XML_SCHEMA_FACET_FRACTIONDIGITS
:
17352 bffracdig
= facet
; break;
17358 * length and minLength or maxLength (2.2) + (3.2)
17360 if (flength
&& (fminlen
|| fmaxlen
)) {
17361 FACET_RESTR_ERR(flength
, "It is an error for both 'length' and "
17362 "either of 'minLength' or 'maxLength' to be specified on "
17363 "the same type definition")
17366 * Mutual exclusions in the same derivation step.
17368 if ((fmaxinc
) && (fmaxexc
)) {
17370 * SCC "maxInclusive and maxExclusive"
17372 FACET_RESTR_MUTUAL_ERR(fmaxinc
, fmaxexc
)
17374 if ((fmininc
) && (fminexc
)) {
17376 * SCC "minInclusive and minExclusive"
17378 FACET_RESTR_MUTUAL_ERR(fmininc
, fminexc
)
17381 if (flength
&& bflength
) {
17383 * SCC "length valid restriction"
17384 * The values have to be equal.
17386 res
= xmlSchemaCompareValues(flength
->val
, bflength
->val
);
17388 goto internal_error
;
17390 xmlSchemaDeriveFacetErr(pctxt
, flength
, bflength
, 0, 0, 1);
17391 if ((res
!= 0) && (bflength
->fixed
)) {
17392 FACET_RESTR_FIXED_ERR(flength
)
17396 if (fminlen
&& bfminlen
) {
17398 * SCC "minLength valid restriction"
17399 * minLength >= BASE minLength
17401 res
= xmlSchemaCompareValues(fminlen
->val
, bfminlen
->val
);
17403 goto internal_error
;
17405 xmlSchemaDeriveFacetErr(pctxt
, fminlen
, bfminlen
, 1, 1, 1);
17406 if ((res
!= 0) && (bfminlen
->fixed
)) {
17407 FACET_RESTR_FIXED_ERR(fminlen
)
17410 if (fmaxlen
&& bfmaxlen
) {
17412 * SCC "maxLength valid restriction"
17413 * maxLength <= BASE minLength
17415 res
= xmlSchemaCompareValues(fmaxlen
->val
, bfmaxlen
->val
);
17417 goto internal_error
;
17419 xmlSchemaDeriveFacetErr(pctxt
, fmaxlen
, bfmaxlen
, -1, 1, 1);
17420 if ((res
!= 0) && (bfmaxlen
->fixed
)) {
17421 FACET_RESTR_FIXED_ERR(fmaxlen
)
17425 * SCC "length and minLength or maxLength"
17428 flength
= bflength
;
17431 fminlen
= bfminlen
;
17433 /* (1.1) length >= minLength */
17434 res
= xmlSchemaCompareValues(flength
->val
, fminlen
->val
);
17436 goto internal_error
;
17438 xmlSchemaDeriveFacetErr(pctxt
, flength
, fminlen
, 1, 1, 0);
17441 fmaxlen
= bfmaxlen
;
17443 /* (2.1) length <= maxLength */
17444 res
= xmlSchemaCompareValues(flength
->val
, fmaxlen
->val
);
17446 goto internal_error
;
17448 xmlSchemaDeriveFacetErr(pctxt
, flength
, fmaxlen
, -1, 1, 0);
17456 /* SCC "maxInclusive >= minInclusive" */
17457 res
= xmlSchemaCompareValues(fmaxinc
->val
, fmininc
->val
);
17459 goto internal_error
;
17461 xmlSchemaDeriveFacetErr(pctxt
, fmaxinc
, fmininc
, 1, 1, 0);
17465 * SCC "maxInclusive valid restriction"
17468 /* maxInclusive <= BASE maxInclusive */
17469 res
= xmlSchemaCompareValues(fmaxinc
->val
, bfmaxinc
->val
);
17471 goto internal_error
;
17473 xmlSchemaDeriveFacetErr(pctxt
, fmaxinc
, bfmaxinc
, -1, 1, 1);
17474 if ((res
!= 0) && (bfmaxinc
->fixed
)) {
17475 FACET_RESTR_FIXED_ERR(fmaxinc
)
17479 /* maxInclusive < BASE maxExclusive */
17480 res
= xmlSchemaCompareValues(fmaxinc
->val
, bfmaxexc
->val
);
17482 goto internal_error
;
17484 xmlSchemaDeriveFacetErr(pctxt
, fmaxinc
, bfmaxexc
, -1, 0, 1);
17488 /* maxInclusive >= BASE minInclusive */
17489 res
= xmlSchemaCompareValues(fmaxinc
->val
, bfmininc
->val
);
17491 goto internal_error
;
17493 xmlSchemaDeriveFacetErr(pctxt
, fmaxinc
, bfmininc
, 1, 1, 1);
17497 /* maxInclusive > BASE minExclusive */
17498 res
= xmlSchemaCompareValues(fmaxinc
->val
, bfminexc
->val
);
17500 goto internal_error
;
17502 xmlSchemaDeriveFacetErr(pctxt
, fmaxinc
, bfminexc
, 1, 0, 1);
17508 * "maxExclusive >= minExclusive"
17511 res
= xmlSchemaCompareValues(fmaxexc
->val
, fminexc
->val
);
17513 goto internal_error
;
17515 xmlSchemaDeriveFacetErr(pctxt
, fmaxexc
, fminexc
, 1, 1, 0);
17519 * "maxExclusive valid restriction"
17522 /* maxExclusive <= BASE maxExclusive */
17523 res
= xmlSchemaCompareValues(fmaxexc
->val
, bfmaxexc
->val
);
17525 goto internal_error
;
17527 xmlSchemaDeriveFacetErr(pctxt
, fmaxexc
, bfmaxexc
, -1, 1, 1);
17529 if ((res
!= 0) && (bfmaxexc
->fixed
)) {
17530 FACET_RESTR_FIXED_ERR(fmaxexc
)
17534 /* maxExclusive <= BASE maxInclusive */
17535 res
= xmlSchemaCompareValues(fmaxexc
->val
, bfmaxinc
->val
);
17537 goto internal_error
;
17539 xmlSchemaDeriveFacetErr(pctxt
, fmaxexc
, bfmaxinc
, -1, 1, 1);
17543 /* maxExclusive > BASE minInclusive */
17544 res
= xmlSchemaCompareValues(fmaxexc
->val
, bfmininc
->val
);
17546 goto internal_error
;
17548 xmlSchemaDeriveFacetErr(pctxt
, fmaxexc
, bfmininc
, 1, 0, 1);
17552 /* maxExclusive > BASE minExclusive */
17553 res
= xmlSchemaCompareValues(fmaxexc
->val
, bfminexc
->val
);
17555 goto internal_error
;
17557 xmlSchemaDeriveFacetErr(pctxt
, fmaxexc
, bfminexc
, 1, 0, 1);
17563 * "minExclusive < maxInclusive"
17566 res
= xmlSchemaCompareValues(fminexc
->val
, fmaxinc
->val
);
17568 goto internal_error
;
17570 xmlSchemaDeriveFacetErr(pctxt
, fminexc
, fmaxinc
, -1, 0, 0);
17574 * "minExclusive valid restriction"
17577 /* minExclusive >= BASE minExclusive */
17578 res
= xmlSchemaCompareValues(fminexc
->val
, bfminexc
->val
);
17580 goto internal_error
;
17582 xmlSchemaDeriveFacetErr(pctxt
, fminexc
, bfminexc
, 1, 1, 1);
17584 if ((res
!= 0) && (bfminexc
->fixed
)) {
17585 FACET_RESTR_FIXED_ERR(fminexc
)
17589 /* minExclusive <= BASE maxInclusive */
17590 res
= xmlSchemaCompareValues(fminexc
->val
, bfmaxinc
->val
);
17592 goto internal_error
;
17594 xmlSchemaDeriveFacetErr(pctxt
, fminexc
, bfmaxinc
, -1, 1, 1);
17598 /* minExclusive >= BASE minInclusive */
17599 res
= xmlSchemaCompareValues(fminexc
->val
, bfmininc
->val
);
17601 goto internal_error
;
17603 xmlSchemaDeriveFacetErr(pctxt
, fminexc
, bfmininc
, 1, 1, 1);
17607 /* minExclusive < BASE maxExclusive */
17608 res
= xmlSchemaCompareValues(fminexc
->val
, bfmaxexc
->val
);
17610 goto internal_error
;
17612 xmlSchemaDeriveFacetErr(pctxt
, fminexc
, bfmaxexc
, -1, 0, 1);
17618 * "minInclusive < maxExclusive"
17621 res
= xmlSchemaCompareValues(fmininc
->val
, fmaxexc
->val
);
17623 goto internal_error
;
17625 xmlSchemaDeriveFacetErr(pctxt
, fmininc
, fmaxexc
, -1, 0, 0);
17629 * "minExclusive valid restriction"
17632 /* minInclusive >= BASE minInclusive */
17633 res
= xmlSchemaCompareValues(fmininc
->val
, bfmininc
->val
);
17635 goto internal_error
;
17637 xmlSchemaDeriveFacetErr(pctxt
, fmininc
, bfmininc
, 1, 1, 1);
17639 if ((res
!= 0) && (bfmininc
->fixed
)) {
17640 FACET_RESTR_FIXED_ERR(fmininc
)
17644 /* minInclusive <= BASE maxInclusive */
17645 res
= xmlSchemaCompareValues(fmininc
->val
, bfmaxinc
->val
);
17647 goto internal_error
;
17649 xmlSchemaDeriveFacetErr(pctxt
, fmininc
, bfmaxinc
, -1, 1, 1);
17653 /* minInclusive > BASE minExclusive */
17654 res
= xmlSchemaCompareValues(fmininc
->val
, bfminexc
->val
);
17656 goto internal_error
;
17658 xmlSchemaDeriveFacetErr(pctxt
, fmininc
, bfminexc
, 1, 0, 1);
17661 /* minInclusive < BASE maxExclusive */
17662 res
= xmlSchemaCompareValues(fmininc
->val
, bfmaxexc
->val
);
17664 goto internal_error
;
17666 xmlSchemaDeriveFacetErr(pctxt
, fmininc
, bfmaxexc
, -1, 0, 1);
17669 if (ftotdig
&& bftotdig
) {
17671 * SCC " totalDigits valid restriction"
17672 * totalDigits <= BASE totalDigits
17674 res
= xmlSchemaCompareValues(ftotdig
->val
, bftotdig
->val
);
17676 goto internal_error
;
17678 xmlSchemaDeriveFacetErr(pctxt
, ftotdig
, bftotdig
,
17680 if ((res
!= 0) && (bftotdig
->fixed
)) {
17681 FACET_RESTR_FIXED_ERR(ftotdig
)
17684 if (ffracdig
&& bffracdig
) {
17686 * SCC "fractionDigits valid restriction"
17687 * fractionDigits <= BASE fractionDigits
17689 res
= xmlSchemaCompareValues(ffracdig
->val
, bffracdig
->val
);
17691 goto internal_error
;
17693 xmlSchemaDeriveFacetErr(pctxt
, ffracdig
, bffracdig
,
17695 if ((res
!= 0) && (bffracdig
->fixed
)) {
17696 FACET_RESTR_FIXED_ERR(ffracdig
)
17700 * SCC "fractionDigits less than or equal to totalDigits"
17703 ftotdig
= bftotdig
;
17705 ffracdig
= bffracdig
;
17706 if (ftotdig
&& ffracdig
) {
17707 res
= xmlSchemaCompareValues(ffracdig
->val
, ftotdig
->val
);
17709 goto internal_error
;
17711 xmlSchemaDeriveFacetErr(pctxt
, ffracdig
, ftotdig
,
17715 * *Enumerations* won' be added here, since only the first set
17716 * of enumerations in the ancestor-or-self axis is used
17717 * for validation, plus we need to use the base type of those
17718 * enumerations for whitespace.
17720 * *Patterns*: won't be add here, since they are ORed at
17721 * type level and ANDed at ancestor level. This will
17722 * happed during validation by walking the base axis
17725 for (cur
= base
->facetSet
; cur
!= NULL
; cur
= cur
->next
) {
17726 bfacet
= cur
->facet
;
17728 * Special handling of enumerations and patterns.
17729 * TODO: hmm, they should not appear in the set, so remove this.
17731 if ((bfacet
->type
== XML_SCHEMA_FACET_PATTERN
) ||
17732 (bfacet
->type
== XML_SCHEMA_FACET_ENUMERATION
))
17735 * Search for a duplicate facet in the current type.
17737 link
= type
->facetSet
;
17739 /* fixedErr = 0; */
17740 while (link
!= NULL
) {
17741 facet
= link
->facet
;
17742 if (facet
->type
== bfacet
->type
) {
17743 switch (facet
->type
) {
17744 case XML_SCHEMA_FACET_WHITESPACE
:
17746 * The whitespace must be stronger.
17748 if (facet
->whitespace
< bfacet
->whitespace
) {
17749 FACET_RESTR_ERR(facet
,
17750 "The 'whitespace' value has to be equal to "
17751 "or stronger than the 'whitespace' value of "
17754 if ((bfacet
->fixed
) &&
17755 (facet
->whitespace
!= bfacet
->whitespace
)) {
17756 FACET_RESTR_FIXED_ERR(facet
)
17762 /* Duplicate found. */
17768 * If no duplicate was found: add the base types's facet
17771 if (link
== NULL
) {
17772 link
= (xmlSchemaFacetLinkPtr
)
17773 xmlMalloc(sizeof(xmlSchemaFacetLink
));
17774 if (link
== NULL
) {
17775 xmlSchemaPErrMemory(pctxt
,
17776 "deriving facets, creating a facet link", NULL
);
17779 link
->facet
= cur
->facet
;
17782 type
->facetSet
= link
;
17792 PERROR_INT("xmlSchemaDeriveAndValidateFacets",
17793 "an error occurred");
17798 xmlSchemaFinishMemberTypeDefinitionsProperty(xmlSchemaParserCtxtPtr pctxt
,
17799 xmlSchemaTypePtr type
)
17801 xmlSchemaTypeLinkPtr link
, lastLink
, prevLink
, subLink
, newLink
;
17803 * The actual value is then formed by replacing any union type
17804 * definition in the `explicit members` with the members of their
17805 * {member type definitions}, in order.
17807 * TODO: There's a bug entry at
17808 * "http://lists.w3.org/Archives/Public/www-xml-schema-comments/2005JulSep/0287.html"
17809 * which indicates that we'll keep the union types the future.
17811 link
= type
->memberTypes
;
17812 while (link
!= NULL
) {
17814 if (WXS_IS_TYPE_NOT_FIXED(link
->type
))
17815 xmlSchemaTypeFixup(link
->type
, ACTXT_CAST pctxt
);
17817 if (WXS_IS_UNION(link
->type
)) {
17818 subLink
= xmlSchemaGetUnionSimpleTypeMemberTypes(link
->type
);
17819 if (subLink
!= NULL
) {
17820 link
->type
= subLink
->type
;
17821 if (subLink
->next
!= NULL
) {
17822 lastLink
= link
->next
;
17823 subLink
= subLink
->next
;
17825 while (subLink
!= NULL
) {
17826 newLink
= (xmlSchemaTypeLinkPtr
)
17827 xmlMalloc(sizeof(xmlSchemaTypeLink
));
17828 if (newLink
== NULL
) {
17829 xmlSchemaPErrMemory(pctxt
, "allocating a type link",
17833 newLink
->type
= subLink
->type
;
17834 prevLink
->next
= newLink
;
17835 prevLink
= newLink
;
17836 newLink
->next
= lastLink
;
17838 subLink
= subLink
->next
;
17849 xmlSchemaTypeFixupOptimFacets(xmlSchemaTypePtr type
)
17851 int has
= 0, needVal
= 0, normVal
= 0;
17853 has
= (type
->baseType
->flags
& XML_SCHEMAS_TYPE_HAS_FACETS
) ? 1 : 0;
17855 needVal
= (type
->baseType
->flags
&
17856 XML_SCHEMAS_TYPE_FACETSNEEDVALUE
) ? 1 : 0;
17857 normVal
= (type
->baseType
->flags
&
17858 XML_SCHEMAS_TYPE_NORMVALUENEEDED
) ? 1 : 0;
17860 if (type
->facets
!= NULL
) {
17861 xmlSchemaFacetPtr fac
;
17863 for (fac
= type
->facets
; fac
!= NULL
; fac
= fac
->next
) {
17864 switch (fac
->type
) {
17865 case XML_SCHEMA_FACET_WHITESPACE
:
17867 case XML_SCHEMA_FACET_PATTERN
:
17871 case XML_SCHEMA_FACET_ENUMERATION
:
17883 type
->flags
|= XML_SCHEMAS_TYPE_NORMVALUENEEDED
;
17885 type
->flags
|= XML_SCHEMAS_TYPE_FACETSNEEDVALUE
;
17887 type
->flags
|= XML_SCHEMAS_TYPE_HAS_FACETS
;
17889 if (has
&& (! needVal
) && WXS_IS_ATOMIC(type
)) {
17890 xmlSchemaTypePtr prim
= xmlSchemaGetPrimitiveType(type
);
17892 * OPTIMIZE VAL TODO: Some facets need a computed value.
17894 if ((prim
->builtInType
!= XML_SCHEMAS_ANYSIMPLETYPE
) &&
17895 (prim
->builtInType
!= XML_SCHEMAS_STRING
)) {
17896 type
->flags
|= XML_SCHEMAS_TYPE_FACETSNEEDVALUE
;
17902 xmlSchemaTypeFixupWhitespace(xmlSchemaTypePtr type
)
17907 * Evaluate the whitespace-facet value.
17909 if (WXS_IS_LIST(type
)) {
17910 type
->flags
|= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE
;
17912 } else if (WXS_IS_UNION(type
))
17915 if (type
->facetSet
!= NULL
) {
17916 xmlSchemaFacetLinkPtr lin
;
17918 for (lin
= type
->facetSet
; lin
!= NULL
; lin
= lin
->next
) {
17919 if (lin
->facet
->type
== XML_SCHEMA_FACET_WHITESPACE
) {
17920 switch (lin
->facet
->whitespace
) {
17921 case XML_SCHEMAS_FACET_PRESERVE
:
17922 type
->flags
|= XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE
;
17924 case XML_SCHEMAS_FACET_REPLACE
:
17925 type
->flags
|= XML_SCHEMAS_TYPE_WHITESPACE_REPLACE
;
17927 case XML_SCHEMAS_FACET_COLLAPSE
:
17928 type
->flags
|= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE
;
17938 * For all `atomic` datatypes other than string (and types `derived`
17939 * by `restriction` from it) the value of whiteSpace is fixed to
17943 xmlSchemaTypePtr anc
;
17945 for (anc
= type
->baseType
; anc
!= NULL
&&
17946 anc
->builtInType
!= XML_SCHEMAS_ANYTYPE
;
17947 anc
= anc
->baseType
) {
17949 if (anc
->type
== XML_SCHEMA_TYPE_BASIC
) {
17950 if (anc
->builtInType
== XML_SCHEMAS_NORMSTRING
) {
17951 type
->flags
|= XML_SCHEMAS_TYPE_WHITESPACE_REPLACE
;
17953 } else if ((anc
->builtInType
== XML_SCHEMAS_STRING
) ||
17954 (anc
->builtInType
== XML_SCHEMAS_ANYSIMPLETYPE
)) {
17955 type
->flags
|= XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE
;
17958 type
->flags
|= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE
;
17967 xmlSchemaFixupSimpleTypeStageOne(xmlSchemaParserCtxtPtr pctxt
,
17968 xmlSchemaTypePtr type
)
17970 if (type
->type
!= XML_SCHEMA_TYPE_SIMPLE
)
17972 if (! WXS_IS_TYPE_NOT_FIXED_1(type
))
17974 type
->flags
|= XML_SCHEMAS_TYPE_FIXUP_1
;
17976 if (WXS_IS_LIST(type
)) {
17978 * Corresponds to <simpleType><list>...
17980 if (type
->subtypes
== NULL
) {
17982 * This one is really needed, so get out.
17984 PERROR_INT("xmlSchemaFixupSimpleTypeStageOne",
17985 "list type has no item-type assigned");
17988 } else if (WXS_IS_UNION(type
)) {
17990 * Corresponds to <simpleType><union>...
17992 if (type
->memberTypes
== NULL
) {
17994 * This one is really needed, so get out.
17996 PERROR_INT("xmlSchemaFixupSimpleTypeStageOne",
17997 "union type has no member-types assigned");
18002 * Corresponds to <simpleType><restriction>...
18004 if (type
->baseType
== NULL
) {
18005 PERROR_INT("xmlSchemaFixupSimpleTypeStageOne",
18006 "type has no base-type assigned");
18009 if (WXS_IS_TYPE_NOT_FIXED_1(type
->baseType
))
18010 if (xmlSchemaFixupSimpleTypeStageOne(pctxt
, type
->baseType
) == -1)
18014 * If the <restriction> alternative is chosen, then the
18015 * {variety} of the {base type definition}.
18017 if (WXS_IS_ATOMIC(type
->baseType
))
18018 type
->flags
|= XML_SCHEMAS_TYPE_VARIETY_ATOMIC
;
18019 else if (WXS_IS_LIST(type
->baseType
)) {
18020 type
->flags
|= XML_SCHEMAS_TYPE_VARIETY_LIST
;
18022 * Inherit the itemType.
18024 type
->subtypes
= type
->baseType
->subtypes
;
18025 } else if (WXS_IS_UNION(type
->baseType
)) {
18026 type
->flags
|= XML_SCHEMAS_TYPE_VARIETY_UNION
;
18028 * NOTE that we won't assign the memberTypes of the base,
18029 * since this will make trouble when freeing them; we will
18030 * use a lookup function to access them instead.
18039 xmlSchemaDebugFixedType(xmlSchemaParserCtxtPtr pctxt
,
18040 xmlSchemaTypePtr type
)
18042 if (type
->node
!= NULL
) {
18043 xmlGenericError(xmlGenericErrorContext
,
18044 "Type of %s : %s:%d :", name
,
18045 type
->node
->doc
->URL
,
18046 xmlGetLineNo(type
->node
));
18048 xmlGenericError(xmlGenericErrorContext
, "Type of %s :", name
);
18050 if ((WXS_IS_SIMPLE(type
)) || (WXS_IS_COMPLEX(type
))) {
18051 switch (type
->contentType
) {
18052 case XML_SCHEMA_CONTENT_SIMPLE
:
18053 xmlGenericError(xmlGenericErrorContext
, "simple\n");
18055 case XML_SCHEMA_CONTENT_ELEMENTS
:
18056 xmlGenericError(xmlGenericErrorContext
, "elements\n");
18058 case XML_SCHEMA_CONTENT_UNKNOWN
:
18059 xmlGenericError(xmlGenericErrorContext
, "unknown !!!\n");
18061 case XML_SCHEMA_CONTENT_EMPTY
:
18062 xmlGenericError(xmlGenericErrorContext
, "empty\n");
18064 case XML_SCHEMA_CONTENT_MIXED
:
18065 if (xmlSchemaIsParticleEmptiable((xmlSchemaParticlePtr
)
18067 xmlGenericError(xmlGenericErrorContext
,
18068 "mixed as emptiable particle\n");
18070 xmlGenericError(xmlGenericErrorContext
, "mixed\n");
18072 /* Removed, since not used. */
18074 case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS:
18075 xmlGenericError(xmlGenericErrorContext, "mixed or elems\n");
18078 case XML_SCHEMA_CONTENT_BASIC
:
18079 xmlGenericError(xmlGenericErrorContext
, "basic\n");
18082 xmlGenericError(xmlGenericErrorContext
,
18083 "not registered !!!\n");
18091 * 3.14.6 Constraints on Simple Type Definition Schema Components
18094 xmlSchemaFixupSimpleTypeStageTwo(xmlSchemaParserCtxtPtr pctxt
,
18095 xmlSchemaTypePtr type
)
18097 int res
, olderrs
= pctxt
->nberrors
;
18099 if (type
->type
!= XML_SCHEMA_TYPE_SIMPLE
)
18102 if (! WXS_IS_TYPE_NOT_FIXED(type
))
18105 type
->flags
|= XML_SCHEMAS_TYPE_INTERNAL_RESOLVED
;
18106 type
->contentType
= XML_SCHEMA_CONTENT_SIMPLE
;
18108 if (type
->baseType
== NULL
) {
18109 PERROR_INT("xmlSchemaFixupSimpleTypeStageTwo",
18110 "missing baseType");
18113 if (WXS_IS_TYPE_NOT_FIXED(type
->baseType
))
18114 xmlSchemaTypeFixup(type
->baseType
, ACTXT_CAST pctxt
);
18116 * If a member type of a union is a union itself, we need to substitute
18117 * that member type for its member types.
18118 * NOTE that this might change in WXS 1.1; i.e. we will keep the union
18119 * types in WXS 1.1.
18121 if ((type
->memberTypes
!= NULL
) &&
18122 (xmlSchemaFinishMemberTypeDefinitionsProperty(pctxt
, type
) == -1))
18125 * SPEC src-simple-type 1
18126 * "The corresponding simple type definition, if any, must satisfy
18127 * the conditions set out in Constraints on Simple Type Definition
18128 * Schema Components ($3.14.6)."
18131 * Schema Component Constraint: Simple Type Definition Properties Correct
18132 * (st-props-correct)
18134 res
= xmlSchemaCheckSTPropsCorrect(pctxt
, type
);
18137 * Schema Component Constraint: Derivation Valid (Restriction, Simple)
18138 * (cos-st-restricts)
18140 res
= xmlSchemaCheckCOSSTRestricts(pctxt
, type
);
18143 * TODO: Removed the error report, since it got annoying to get an
18144 * extra error report, if anything failed until now.
18145 * Enable this if needed.
18147 * xmlSchemaPErr(ctxt, type->node,
18148 * XML_SCHEMAP_SRC_SIMPLE_TYPE_1,
18149 * "Simple type '%s' does not satisfy the constraints "
18150 * "on simple type definitions.\n",
18151 * type->name, NULL);
18154 * Schema Component Constraint: Simple Type Restriction (Facets)
18155 * (st-restrict-facets)
18157 res
= xmlSchemaCheckFacetValues(type
, pctxt
);
18159 if ((type
->facetSet
!= NULL
) ||
18160 (type
->baseType
->facetSet
!= NULL
)) {
18161 res
= xmlSchemaDeriveAndValidateFacets(pctxt
, type
);
18165 * Whitespace value.
18167 res
= xmlSchemaTypeFixupWhitespace(type
);
18169 xmlSchemaTypeFixupOptimFacets(type
);
18173 xmlSchemaDebugFixedType(pctxt
, type
);
18175 if (olderrs
!= pctxt
->nberrors
)
18176 return(pctxt
->err
);
18181 xmlSchemaDebugFixedType(pctxt
, type
);
18187 xmlSchemaFixupComplexType(xmlSchemaParserCtxtPtr pctxt
,
18188 xmlSchemaTypePtr type
)
18190 int res
= 0, olderrs
= pctxt
->nberrors
;
18191 xmlSchemaTypePtr baseType
= type
->baseType
;
18193 if (! WXS_IS_TYPE_NOT_FIXED(type
))
18195 type
->flags
|= XML_SCHEMAS_TYPE_INTERNAL_RESOLVED
;
18196 if (baseType
== NULL
) {
18197 PERROR_INT("xmlSchemaFixupComplexType",
18198 "missing baseType");
18202 * Fixup the base type.
18204 if (WXS_IS_TYPE_NOT_FIXED(baseType
))
18205 xmlSchemaTypeFixup(baseType
, ACTXT_CAST pctxt
);
18206 if (baseType
->flags
& XML_SCHEMAS_TYPE_INTERNAL_INVALID
) {
18208 * Skip fixup if the base type is invalid.
18209 * TODO: Generate a warning!
18214 * This basically checks if the base type can be derived.
18216 res
= xmlSchemaCheckSRCCT(pctxt
, type
);
18219 * Fixup the content type.
18221 if (type
->contentType
== XML_SCHEMA_CONTENT_SIMPLE
) {
18223 * Corresponds to <complexType><simpleContent>...
18225 if ((WXS_IS_COMPLEX(baseType
)) &&
18226 (baseType
->contentTypeDef
!= NULL
) &&
18227 (WXS_IS_RESTRICTION(type
))) {
18228 xmlSchemaTypePtr contentBase
, content
;
18229 #ifdef ENABLE_NAMED_LOCALS
18231 const xmlChar
*tmpname
;
18234 * SPEC (1) If <restriction> + base type is <complexType>,
18235 * "whose own {content type} is a simple type..."
18237 if (type
->contentTypeDef
!= NULL
) {
18239 * SPEC (1.1) "the simple type definition corresponding to the
18240 * <simpleType> among the [children] of <restriction> if there
18242 * Note that this "<simpleType> among the [children]" was put
18243 * into ->contentTypeDef during parsing.
18245 contentBase
= type
->contentTypeDef
;
18246 type
->contentTypeDef
= NULL
;
18249 * (1.2) "...otherwise (<restriction> has no <simpleType>
18250 * among its [children]), the simple type definition which
18251 * is the {content type} of the ... base type."
18253 contentBase
= baseType
->contentTypeDef
;
18257 * "... a simple type definition which restricts the simple
18258 * type definition identified in clause 1.1 or clause 1.2
18259 * with a set of facet components"
18261 * Create the anonymous simple type, which will be the content
18262 * type of the complex type.
18264 #ifdef ENABLE_NAMED_LOCALS
18265 snprintf(buf
, 29, "#scST%d", ++(pctxt
->counter
));
18266 tmpname
= xmlDictLookup(pctxt
->dict
, BAD_CAST buf
, -1);
18267 content
= xmlSchemaAddType(pctxt
, pctxt
->schema
,
18268 XML_SCHEMA_TYPE_SIMPLE
, tmpname
, type
->targetNamespace
,
18271 content
= xmlSchemaAddType(pctxt
, pctxt
->schema
,
18272 XML_SCHEMA_TYPE_SIMPLE
, NULL
, type
->targetNamespace
,
18275 if (content
== NULL
)
18278 * We will use the same node as for the <complexType>
18279 * to have it somehow anchored in the schema doc.
18281 content
->type
= XML_SCHEMA_TYPE_SIMPLE
;
18282 content
->baseType
= contentBase
;
18284 * Move the facets, previously anchored on the
18285 * complexType during parsing.
18287 content
->facets
= type
->facets
;
18288 type
->facets
= NULL
;
18289 content
->facetSet
= type
->facetSet
;
18290 type
->facetSet
= NULL
;
18292 type
->contentTypeDef
= content
;
18293 if (WXS_IS_TYPE_NOT_FIXED(contentBase
))
18294 xmlSchemaTypeFixup(contentBase
, ACTXT_CAST pctxt
);
18296 * Fixup the newly created type. We don't need to check
18297 * for circularity here.
18299 res
= xmlSchemaFixupSimpleTypeStageOne(pctxt
, content
);
18301 res
= xmlSchemaFixupSimpleTypeStageTwo(pctxt
, content
);
18304 } else if ((WXS_IS_COMPLEX(baseType
)) &&
18305 (baseType
->contentType
== XML_SCHEMA_CONTENT_MIXED
) &&
18306 (WXS_IS_RESTRICTION(type
))) {
18308 * SPEC (2) If <restriction> + base is a mixed <complexType> with
18309 * an emptiable particle, then a simple type definition which
18310 * restricts the <restriction>'s <simpleType> child.
18312 if ((type
->contentTypeDef
== NULL
) ||
18313 (type
->contentTypeDef
->baseType
== NULL
)) {
18315 * TODO: Check if this ever happens.
18317 xmlSchemaPCustomErr(pctxt
,
18318 XML_SCHEMAP_INTERNAL
,
18319 WXS_BASIC_CAST type
, NULL
,
18320 "Internal error: xmlSchemaTypeFixup, "
18321 "complex type '%s': the <simpleContent><restriction> "
18322 "is missing a <simpleType> child, but was not catched "
18323 "by xmlSchemaCheckSRCCT()", type
->name
);
18326 } else if ((WXS_IS_COMPLEX(baseType
)) && WXS_IS_EXTENSION(type
)) {
18328 * SPEC (3) If <extension> + base is <complexType> with
18329 * <simpleType> content, "...then the {content type} of that
18330 * complex type definition"
18332 if (baseType
->contentTypeDef
== NULL
) {
18334 * TODO: Check if this ever happens. xmlSchemaCheckSRCCT
18335 * should have catched this already.
18337 xmlSchemaPCustomErr(pctxt
,
18338 XML_SCHEMAP_INTERNAL
,
18339 WXS_BASIC_CAST type
, NULL
,
18340 "Internal error: xmlSchemaTypeFixup, "
18341 "complex type '%s': the <extension>ed base type is "
18342 "a complex type with no simple content type",
18346 type
->contentTypeDef
= baseType
->contentTypeDef
;
18347 } else if ((WXS_IS_SIMPLE(baseType
)) && WXS_IS_EXTENSION(type
)) {
18349 * SPEC (4) <extension> + base is <simpleType>
18350 * "... then that simple type definition"
18352 type
->contentTypeDef
= baseType
;
18355 * TODO: Check if this ever happens.
18357 xmlSchemaPCustomErr(pctxt
,
18358 XML_SCHEMAP_INTERNAL
,
18359 WXS_BASIC_CAST type
, NULL
,
18360 "Internal error: xmlSchemaTypeFixup, "
18361 "complex type '%s' with <simpleContent>: unhandled "
18362 "derivation case", type
->name
);
18366 int dummySequence
= 0;
18367 xmlSchemaParticlePtr particle
=
18368 (xmlSchemaParticlePtr
) type
->subtypes
;
18370 * Corresponds to <complexType><complexContent>...
18372 * NOTE that the effective mixed was already set during parsing of
18373 * <complexType> and <complexContent>; its flag value is
18374 * XML_SCHEMAS_TYPE_MIXED.
18376 * Compute the "effective content":
18377 * (2.1.1) + (2.1.2) + (2.1.3)
18379 if ((particle
== NULL
) ||
18380 ((particle
->type
== XML_SCHEMA_TYPE_PARTICLE
) &&
18381 ((particle
->children
->type
== XML_SCHEMA_TYPE_ALL
) ||
18382 (particle
->children
->type
== XML_SCHEMA_TYPE_SEQUENCE
) ||
18383 ((particle
->children
->type
== XML_SCHEMA_TYPE_CHOICE
) &&
18384 (particle
->minOccurs
== 0))) &&
18385 ( ((xmlSchemaTreeItemPtr
) particle
->children
)->children
== NULL
))) {
18386 if (type
->flags
& XML_SCHEMAS_TYPE_MIXED
) {
18388 * SPEC (2.1.4) "If the `effective mixed` is true, then
18389 * a particle whose properties are as follows:..."
18391 * Empty sequence model group with
18392 * minOccurs/maxOccurs = 1 (i.e. a "particle emptiable").
18393 * NOTE that we sill assign it the <complexType> node to
18394 * somehow anchor it in the doc.
18396 if ((particle
== NULL
) ||
18397 (particle
->children
->type
!= XML_SCHEMA_TYPE_SEQUENCE
)) {
18399 * Create the particle.
18401 particle
= xmlSchemaAddParticle(pctxt
,
18403 if (particle
== NULL
)
18406 * Create the model group.
18407 */ /* URGENT TODO: avoid adding to pending items. */
18408 particle
->children
= (xmlSchemaTreeItemPtr
)
18409 xmlSchemaAddModelGroup(pctxt
, pctxt
->schema
,
18410 XML_SCHEMA_TYPE_SEQUENCE
, type
->node
);
18411 if (particle
->children
== NULL
)
18414 type
->subtypes
= (xmlSchemaTypePtr
) particle
;
18417 type
->contentType
= XML_SCHEMA_CONTENT_ELEMENTS
;
18420 * SPEC (2.1.5) "otherwise empty"
18422 type
->contentType
= XML_SCHEMA_CONTENT_EMPTY
;
18426 * SPEC (2.2) "otherwise the particle corresponding to the
18427 * <all>, <choice>, <group> or <sequence> among the
18430 type
->contentType
= XML_SCHEMA_CONTENT_ELEMENTS
;
18433 * Compute the "content type".
18435 if (WXS_IS_RESTRICTION(type
)) {
18437 * SPEC (3.1) "If <restriction>..."
18438 * (3.1.1) + (3.1.2) */
18439 if (type
->contentType
!= XML_SCHEMA_CONTENT_EMPTY
) {
18440 if (type
->flags
& XML_SCHEMAS_TYPE_MIXED
)
18441 type
->contentType
= XML_SCHEMA_CONTENT_MIXED
;
18445 * SPEC (3.2) "If <extension>..."
18447 if (type
->contentType
== XML_SCHEMA_CONTENT_EMPTY
) {
18450 * "If the `effective content` is empty, then the
18451 * {content type} of the [...] base ..."
18453 type
->contentType
= baseType
->contentType
;
18454 type
->subtypes
= baseType
->subtypes
;
18456 * Fixes bug #347316:
18457 * This is the case when the base type has a simple
18458 * type definition as content.
18460 type
->contentTypeDef
= baseType
->contentTypeDef
;
18462 * NOTE that the effective mixed is ignored here.
18464 } else if (baseType
->contentType
== XML_SCHEMA_CONTENT_EMPTY
) {
18468 if (type
->flags
& XML_SCHEMAS_TYPE_MIXED
)
18469 type
->contentType
= XML_SCHEMA_CONTENT_MIXED
;
18474 if (type
->flags
& XML_SCHEMAS_TYPE_MIXED
)
18475 type
->contentType
= XML_SCHEMA_CONTENT_MIXED
;
18477 * "A model group whose {compositor} is sequence and whose
18478 * {particles} are..."
18480 if ((WXS_TYPE_PARTICLE(type
) != NULL
) &&
18481 (WXS_TYPE_PARTICLE_TERM(type
) != NULL
) &&
18482 ((WXS_TYPE_PARTICLE_TERM(type
))->type
==
18483 XML_SCHEMA_TYPE_ALL
))
18486 * SPEC cos-all-limited (1)
18488 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
18489 /* TODO: error code */
18490 XML_SCHEMAP_COS_ALL_LIMITED
,
18491 WXS_ITEM_NODE(type
), NULL
,
18492 "The type has an 'all' model group in its "
18493 "{content type} and thus cannot be derived from "
18494 "a non-empty type, since this would produce a "
18495 "'sequence' model group containing the 'all' "
18496 "model group; 'all' model groups are not "
18497 "allowed to appear inside other model groups",
18500 } else if ((WXS_TYPE_PARTICLE(baseType
) != NULL
) &&
18501 (WXS_TYPE_PARTICLE_TERM(baseType
) != NULL
) &&
18502 ((WXS_TYPE_PARTICLE_TERM(baseType
))->type
==
18503 XML_SCHEMA_TYPE_ALL
))
18506 * SPEC cos-all-limited (1)
18508 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
18509 /* TODO: error code */
18510 XML_SCHEMAP_COS_ALL_LIMITED
,
18511 WXS_ITEM_NODE(type
), NULL
,
18512 "A type cannot be derived by extension from a type "
18513 "which has an 'all' model group in its "
18514 "{content type}, since this would produce a "
18515 "'sequence' model group containing the 'all' "
18516 "model group; 'all' model groups are not "
18517 "allowed to appear inside other model groups",
18520 } else if (! dummySequence
) {
18521 xmlSchemaTreeItemPtr effectiveContent
=
18522 (xmlSchemaTreeItemPtr
) type
->subtypes
;
18524 * Create the particle.
18526 particle
= xmlSchemaAddParticle(pctxt
,
18528 if (particle
== NULL
)
18531 * Create the "sequence" model group.
18533 particle
->children
= (xmlSchemaTreeItemPtr
)
18534 xmlSchemaAddModelGroup(pctxt
, pctxt
->schema
,
18535 XML_SCHEMA_TYPE_SEQUENCE
, type
->node
);
18536 if (particle
->children
== NULL
)
18538 WXS_TYPE_CONTENTTYPE(type
) = (xmlSchemaTypePtr
) particle
;
18540 * SPEC "the particle of the {content type} of
18541 * the ... base ..."
18542 * Create a duplicate of the base type's particle
18543 * and assign its "term" to it.
18545 particle
->children
->children
=
18546 (xmlSchemaTreeItemPtr
) xmlSchemaAddParticle(pctxt
,
18548 ((xmlSchemaParticlePtr
) baseType
->subtypes
)->minOccurs
,
18549 ((xmlSchemaParticlePtr
) baseType
->subtypes
)->maxOccurs
);
18550 if (particle
->children
->children
== NULL
)
18552 particle
= (xmlSchemaParticlePtr
)
18553 particle
->children
->children
;
18554 particle
->children
=
18555 ((xmlSchemaParticlePtr
) baseType
->subtypes
)->children
;
18557 * SPEC "followed by the `effective content`."
18559 particle
->next
= effectiveContent
;
18561 * This all will result in:
18563 * --> new-sequence(
18572 * This is the case when there is already an empty
18573 * <sequence> with minOccurs==maxOccurs==1.
18574 * Just add the base types's content type.
18575 * NOTE that, although we miss to add an intermediate
18576 * <sequence>, this should produce no difference to
18577 * neither the regex compilation of the content model,
18578 * nor to the complex type contraints.
18580 particle
->children
->children
=
18581 (xmlSchemaTreeItemPtr
) baseType
->subtypes
;
18587 * Now fixup attribute uses:
18588 * - expand attr. group references
18589 * - intersect attribute wildcards
18590 * - inherit attribute uses of the base type
18591 * - inherit or union attr. wildcards if extending
18592 * - apply attr. use prohibitions if restricting
18594 res
= xmlSchemaFixupTypeAttributeUses(pctxt
, type
);
18597 * Apply the complex type component constraints; this will not
18598 * check attributes, since this is done in
18599 * xmlSchemaFixupTypeAttributeUses().
18601 res
= xmlSchemaCheckCTComponent(pctxt
, type
);
18605 xmlSchemaDebugFixedType(pctxt
, type
);
18607 if (olderrs
!= pctxt
->nberrors
)
18608 return(pctxt
->err
);
18613 type
->flags
|= XML_SCHEMAS_TYPE_INTERNAL_INVALID
;
18615 xmlSchemaDebugFixedType(pctxt
, type
);
18617 return(pctxt
->err
);
18620 type
->flags
|= XML_SCHEMAS_TYPE_INTERNAL_INVALID
;
18622 xmlSchemaDebugFixedType(pctxt
, type
);
18629 * xmlSchemaTypeFixup:
18630 * @typeDecl: the schema type definition
18631 * @ctxt: the schema parser context
18633 * Fixes the content model of the type.
18634 * URGENT TODO: We need an int result!
18637 xmlSchemaTypeFixup(xmlSchemaTypePtr type
,
18638 xmlSchemaAbstractCtxtPtr actxt
)
18642 if (actxt
->type
!= XML_SCHEMA_CTXT_PARSER
) {
18643 AERROR_INT("xmlSchemaTypeFixup",
18644 "this function needs a parser context");
18647 if (! WXS_IS_TYPE_NOT_FIXED(type
))
18649 if (type
->type
== XML_SCHEMA_TYPE_COMPLEX
)
18650 return(xmlSchemaFixupComplexType(PCTXT_CAST actxt
, type
));
18651 else if (type
->type
== XML_SCHEMA_TYPE_SIMPLE
)
18652 return(xmlSchemaFixupSimpleTypeStageTwo(PCTXT_CAST actxt
, type
));
18657 * xmlSchemaCheckFacet:
18658 * @facet: the facet
18659 * @typeDecl: the schema type definition
18660 * @pctxt: the schema parser context or NULL
18661 * @name: the optional name of the type
18663 * Checks and computes the values of facets.
18665 * Returns 0 if valid, a positive error code if not valid and
18666 * -1 in case of an internal or API error.
18669 xmlSchemaCheckFacet(xmlSchemaFacetPtr facet
,
18670 xmlSchemaTypePtr typeDecl
,
18671 xmlSchemaParserCtxtPtr pctxt
,
18672 const xmlChar
* name ATTRIBUTE_UNUSED
)
18674 int ret
= 0, ctxtGiven
;
18676 if ((facet
== NULL
) || (typeDecl
== NULL
))
18679 * TODO: will the parser context be given if used from
18680 * the relaxNG module?
18687 switch (facet
->type
) {
18688 case XML_SCHEMA_FACET_MININCLUSIVE
:
18689 case XML_SCHEMA_FACET_MINEXCLUSIVE
:
18690 case XML_SCHEMA_FACET_MAXINCLUSIVE
:
18691 case XML_SCHEMA_FACET_MAXEXCLUSIVE
:
18692 case XML_SCHEMA_FACET_ENUMERATION
: {
18694 * Okay we need to validate the value
18697 xmlSchemaTypePtr base
;
18699 /* 4.3.5.5 Constraints on enumeration Schema Components
18700 * Schema Component Constraint: enumeration valid restriction
18701 * It is an `error` if any member of {value} is not in the
18702 * `value space` of {base type definition}.
18704 * minInclusive, maxInclusive, minExclusive, maxExclusive:
18705 * The value `must` be in the
18706 * `value space` of the `base type`.
18709 * This function is intended to deliver a compiled value
18710 * on the facet. In this implementation of XML Schemata the
18711 * type holding a facet, won't be a built-in type.
18712 * Thus to ensure that other API
18713 * calls (relaxng) do work, if the given type is a built-in
18714 * type, we will assume that the given built-in type *is
18715 * already* the base type.
18717 if (typeDecl
->type
!= XML_SCHEMA_TYPE_BASIC
) {
18718 base
= typeDecl
->baseType
;
18719 if (base
== NULL
) {
18720 PERROR_INT("xmlSchemaCheckFacet",
18721 "a type user derived type has no base type");
18729 * A context is needed if called from RelaxNG.
18731 pctxt
= xmlSchemaNewParserCtxt("*");
18736 * NOTE: This call does not check the content nodes,
18737 * since they are not available:
18738 * facet->node is just the node holding the facet
18739 * definition, *not* the attribute holding the *value*
18742 ret
= xmlSchemaVCheckCVCSimpleType(
18743 ACTXT_CAST pctxt
, facet
->node
, base
,
18744 facet
->value
, &(facet
->val
), 1, 1, 0);
18747 /* No error message for RelaxNG. */
18749 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
18750 XML_SCHEMAP_INTERNAL
, facet
->node
, NULL
,
18751 "Internal error: xmlSchemaCheckFacet, "
18752 "failed to validate the value '%s' of the "
18753 "facet '%s' against the base type",
18754 facet
->value
, xmlSchemaFacetTypeToString(facet
->type
));
18756 goto internal_error
;
18758 ret
= XML_SCHEMAP_INVALID_FACET_VALUE
;
18759 /* No error message for RelaxNG. */
18761 xmlChar
*str
= NULL
;
18763 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
18764 ret
, facet
->node
, WXS_BASIC_CAST facet
,
18765 "The value '%s' of the facet does not validate "
18766 "against the base type '%s'",
18768 xmlSchemaFormatQName(&str
,
18769 base
->targetNamespace
, base
->name
));
18770 FREE_AND_NULL(str
);
18773 } else if (facet
->val
== NULL
) {
18775 PERROR_INT("xmlSchemaCheckFacet",
18776 "value was not computed");
18782 case XML_SCHEMA_FACET_PATTERN
:
18783 facet
->regexp
= xmlRegexpCompile(facet
->value
);
18784 if (facet
->regexp
== NULL
) {
18785 ret
= XML_SCHEMAP_REGEXP_INVALID
;
18786 /* No error message for RelaxNG. */
18788 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
18789 ret
, facet
->node
, WXS_BASIC_CAST typeDecl
,
18790 "The value '%s' of the facet 'pattern' is not a "
18791 "valid regular expression",
18792 facet
->value
, NULL
);
18796 case XML_SCHEMA_FACET_TOTALDIGITS
:
18797 case XML_SCHEMA_FACET_FRACTIONDIGITS
:
18798 case XML_SCHEMA_FACET_LENGTH
:
18799 case XML_SCHEMA_FACET_MAXLENGTH
:
18800 case XML_SCHEMA_FACET_MINLENGTH
:
18802 if (facet
->type
== XML_SCHEMA_FACET_TOTALDIGITS
) {
18803 ret
= xmlSchemaValidatePredefinedType(
18804 xmlSchemaGetBuiltInType(XML_SCHEMAS_PINTEGER
),
18805 facet
->value
, &(facet
->val
));
18807 ret
= xmlSchemaValidatePredefinedType(
18808 xmlSchemaGetBuiltInType(XML_SCHEMAS_NNINTEGER
),
18809 facet
->value
, &(facet
->val
));
18813 /* No error message for RelaxNG. */
18815 PERROR_INT("xmlSchemaCheckFacet",
18816 "validating facet value");
18818 goto internal_error
;
18820 ret
= XML_SCHEMAP_INVALID_FACET_VALUE
;
18821 /* No error message for RelaxNG. */
18824 xmlSchemaCustomErr4(ACTXT_CAST pctxt
,
18825 ret
, facet
->node
, WXS_BASIC_CAST typeDecl
,
18826 "The value '%s' of the facet '%s' is not a valid '%s'",
18828 xmlSchemaFacetTypeToString(facet
->type
),
18829 (facet
->type
!= XML_SCHEMA_FACET_TOTALDIGITS
) ?
18830 BAD_CAST
"nonNegativeInteger" :
18831 BAD_CAST
"positiveInteger",
18837 case XML_SCHEMA_FACET_WHITESPACE
:{
18838 if (xmlStrEqual(facet
->value
, BAD_CAST
"preserve")) {
18839 facet
->whitespace
= XML_SCHEMAS_FACET_PRESERVE
;
18840 } else if (xmlStrEqual(facet
->value
, BAD_CAST
"replace")) {
18841 facet
->whitespace
= XML_SCHEMAS_FACET_REPLACE
;
18842 } else if (xmlStrEqual(facet
->value
, BAD_CAST
"collapse")) {
18843 facet
->whitespace
= XML_SCHEMAS_FACET_COLLAPSE
;
18845 ret
= XML_SCHEMAP_INVALID_FACET_VALUE
;
18846 /* No error message for RelaxNG. */
18848 /* error was previously: XML_SCHEMAP_INVALID_WHITE_SPACE */
18849 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
18850 ret
, facet
->node
, WXS_BASIC_CAST typeDecl
,
18851 "The value '%s' of the facet 'whitespace' is not "
18852 "valid", facet
->value
, NULL
);
18860 if ((! ctxtGiven
) && (pctxt
!= NULL
))
18861 xmlSchemaFreeParserCtxt(pctxt
);
18864 if ((! ctxtGiven
) && (pctxt
!= NULL
))
18865 xmlSchemaFreeParserCtxt(pctxt
);
18870 * xmlSchemaCheckFacetValues:
18871 * @typeDecl: the schema type definition
18872 * @ctxt: the schema parser context
18874 * Checks the default values types, especially for facets
18877 xmlSchemaCheckFacetValues(xmlSchemaTypePtr typeDecl
,
18878 xmlSchemaParserCtxtPtr pctxt
)
18880 int res
, olderrs
= pctxt
->nberrors
;
18881 const xmlChar
*name
= typeDecl
->name
;
18883 * NOTE: It is intended to use the facets list, instead
18886 if (typeDecl
->facets
!= NULL
) {
18887 xmlSchemaFacetPtr facet
= typeDecl
->facets
;
18890 * Temporarily assign the "schema" to the validation context
18891 * of the parser context. This is needed for NOTATION validation.
18893 if (pctxt
->vctxt
== NULL
) {
18894 if (xmlSchemaCreateVCtxtOnPCtxt(pctxt
) == -1)
18897 pctxt
->vctxt
->schema
= pctxt
->schema
;
18898 while (facet
!= NULL
) {
18899 res
= xmlSchemaCheckFacet(facet
, typeDecl
, pctxt
, name
);
18901 facet
= facet
->next
;
18903 pctxt
->vctxt
->schema
= NULL
;
18905 if (olderrs
!= pctxt
->nberrors
)
18906 return(pctxt
->err
);
18913 * xmlSchemaGetCircModelGrDefRef:
18914 * @ctxtMGroup: the searched model group
18915 * @selfMGroup: the second searched model group
18916 * @particle: the first particle
18918 * This one is intended to be used by
18919 * xmlSchemaCheckGroupDefCircular only.
18921 * Returns the particle with the circular model group definition reference,
18924 static xmlSchemaTreeItemPtr
18925 xmlSchemaGetCircModelGrDefRef(xmlSchemaModelGroupDefPtr groupDef
,
18926 xmlSchemaTreeItemPtr particle
)
18928 xmlSchemaTreeItemPtr circ
= NULL
;
18929 xmlSchemaTreeItemPtr term
;
18930 xmlSchemaModelGroupDefPtr gdef
;
18932 for (; particle
!= NULL
; particle
= particle
->next
) {
18933 term
= particle
->children
;
18936 switch (term
->type
) {
18937 case XML_SCHEMA_TYPE_GROUP
:
18938 gdef
= (xmlSchemaModelGroupDefPtr
) term
;
18939 if (gdef
== groupDef
)
18942 * Mark this model group definition to avoid infinite
18943 * recursion on circular references not yet examined.
18945 if (gdef
->flags
& XML_SCHEMA_MODEL_GROUP_DEF_MARKED
)
18947 if (gdef
->children
!= NULL
) {
18948 gdef
->flags
|= XML_SCHEMA_MODEL_GROUP_DEF_MARKED
;
18949 circ
= xmlSchemaGetCircModelGrDefRef(groupDef
,
18950 gdef
->children
->children
);
18951 gdef
->flags
^= XML_SCHEMA_MODEL_GROUP_DEF_MARKED
;
18956 case XML_SCHEMA_TYPE_SEQUENCE
:
18957 case XML_SCHEMA_TYPE_CHOICE
:
18958 case XML_SCHEMA_TYPE_ALL
:
18959 circ
= xmlSchemaGetCircModelGrDefRef(groupDef
, term
->children
);
18971 * xmlSchemaCheckGroupDefCircular:
18972 * @item: the model group definition
18973 * @ctxt: the parser context
18976 * Checks for circular references to model group definitions.
18979 xmlSchemaCheckGroupDefCircular(xmlSchemaModelGroupDefPtr item
,
18980 xmlSchemaParserCtxtPtr ctxt
)
18983 * Schema Component Constraint: Model Group Correct
18984 * 2 Circular groups are disallowed. That is, within the {particles}
18985 * of a group there must not be at any depth a particle whose {term}
18986 * is the group itself.
18988 if ((item
== NULL
) ||
18989 (item
->type
!= XML_SCHEMA_TYPE_GROUP
) ||
18990 (item
->children
== NULL
))
18993 xmlSchemaTreeItemPtr circ
;
18995 circ
= xmlSchemaGetCircModelGrDefRef(item
, item
->children
->children
);
18996 if (circ
!= NULL
) {
18997 xmlChar
*str
= NULL
;
18999 * TODO: The error report is not adequate: this constraint
19000 * is defined for model groups but not definitions, but since
19001 * there cannot be any circular model groups without a model group
19002 * definition (if not using a construction API), we check those
19005 xmlSchemaPCustomErr(ctxt
,
19006 XML_SCHEMAP_MG_PROPS_CORRECT_2
,
19007 NULL
, WXS_ITEM_NODE(circ
),
19008 "Circular reference to the model group definition '%s' "
19009 "defined", xmlSchemaFormatQName(&str
,
19010 item
->targetNamespace
, item
->name
));
19013 * NOTE: We will cut the reference to avoid further
19014 * confusion of the processor. This is a fatal error.
19016 circ
->children
= NULL
;
19022 * xmlSchemaModelGroupToModelGroupDefFixup:
19023 * @ctxt: the parser context
19024 * @mg: the model group
19026 * Assigns the model group of model group definitions to the "term"
19027 * of the referencing particle.
19028 * In xmlSchemaResolveModelGroupParticleReferences the model group
19029 * definitions were assigned to the "term", since needed for the
19030 * circularity check.
19032 * Schema Component Constraint:
19033 * All Group Limited (cos-all-limited) (1.2)
19036 xmlSchemaModelGroupToModelGroupDefFixup(
19037 xmlSchemaParserCtxtPtr ctxt ATTRIBUTE_UNUSED
,
19038 xmlSchemaModelGroupPtr mg
)
19040 xmlSchemaParticlePtr particle
= WXS_MODELGROUP_PARTICLE(mg
);
19042 while (particle
!= NULL
) {
19043 if ((WXS_PARTICLE_TERM(particle
) == NULL
) ||
19044 ((WXS_PARTICLE_TERM(particle
))->type
!=
19045 XML_SCHEMA_TYPE_GROUP
))
19047 particle
= WXS_PTC_CAST particle
->next
;
19050 if (WXS_MODELGROUPDEF_MODEL(WXS_PARTICLE_TERM(particle
)) == NULL
) {
19052 * TODO: Remove the particle.
19054 WXS_PARTICLE_TERM(particle
) = NULL
;
19055 particle
= WXS_PTC_CAST particle
->next
;
19059 * Assign the model group to the {term} of the particle.
19061 WXS_PARTICLE_TERM(particle
) =
19062 WXS_TREE_CAST
WXS_MODELGROUPDEF_MODEL(WXS_PARTICLE_TERM(particle
));
19064 particle
= WXS_PTC_CAST particle
->next
;
19069 * xmlSchemaCheckAttrGroupCircularRecur:
19070 * @ctxtGr: the searched attribute group
19071 * @attr: the current attribute list to be processed
19073 * This one is intended to be used by
19074 * xmlSchemaCheckAttrGroupCircular only.
19076 * Returns the circular attribute grou reference, otherwise NULL.
19078 static xmlSchemaQNameRefPtr
19079 xmlSchemaCheckAttrGroupCircularRecur(xmlSchemaAttributeGroupPtr ctxtGr
,
19080 xmlSchemaItemListPtr list
)
19082 xmlSchemaAttributeGroupPtr gr
;
19083 xmlSchemaQNameRefPtr ref
, circ
;
19086 * We will search for an attribute group reference which
19087 * references the context attribute group.
19089 for (i
= 0; i
< list
->nbItems
; i
++) {
19090 ref
= list
->items
[i
];
19091 if ((ref
->type
== XML_SCHEMA_EXTRA_QNAMEREF
) &&
19092 (ref
->itemType
== XML_SCHEMA_TYPE_ATTRIBUTEGROUP
) &&
19093 (ref
->item
!= NULL
))
19095 gr
= WXS_ATTR_GROUP_CAST ref
->item
;
19098 if (gr
->flags
& XML_SCHEMAS_ATTRGROUP_MARKED
)
19101 * Mark as visited to avoid infinite recursion on
19102 * circular references not yet examined.
19104 if ((gr
->attrUses
) &&
19105 (gr
->flags
& XML_SCHEMAS_ATTRGROUP_HAS_REFS
))
19107 gr
->flags
|= XML_SCHEMAS_ATTRGROUP_MARKED
;
19108 circ
= xmlSchemaCheckAttrGroupCircularRecur(ctxtGr
,
19109 (xmlSchemaItemListPtr
) gr
->attrUses
);
19110 gr
->flags
^= XML_SCHEMAS_ATTRGROUP_MARKED
;
19121 * xmlSchemaCheckAttrGroupCircular:
19122 * attrGr: the attribute group definition
19123 * @ctxt: the parser context
19126 * Checks for circular references of attribute groups.
19129 xmlSchemaCheckAttrGroupCircular(xmlSchemaAttributeGroupPtr attrGr
,
19130 xmlSchemaParserCtxtPtr ctxt
)
19133 * Schema Representation Constraint:
19134 * Attribute Group Definition Representation OK
19135 * 3 Circular group reference is disallowed outside <redefine>.
19136 * That is, unless this element information item's parent is
19137 * <redefine>, then among the [children], if any, there must
19138 * not be an <attributeGroup> with ref [attribute] which resolves
19139 * to the component corresponding to this <attributeGroup>. Indirect
19140 * circularity is also ruled out. That is, when QName resolution
19141 * (Schema Document) ($3.15.3) is applied to a `QName` arising from
19142 * any <attributeGroup>s with a ref [attribute] among the [children],
19143 * it must not be the case that a `QName` is encountered at any depth
19144 * which resolves to the component corresponding to this <attributeGroup>.
19146 if (attrGr
->attrUses
== NULL
)
19148 else if ((attrGr
->flags
& XML_SCHEMAS_ATTRGROUP_HAS_REFS
) == 0)
19151 xmlSchemaQNameRefPtr circ
;
19153 circ
= xmlSchemaCheckAttrGroupCircularRecur(attrGr
,
19154 (xmlSchemaItemListPtr
) attrGr
->attrUses
);
19155 if (circ
!= NULL
) {
19156 xmlChar
*str
= NULL
;
19158 * TODO: Report the referenced attr group as QName.
19160 xmlSchemaPCustomErr(ctxt
,
19161 XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_3
,
19162 NULL
, WXS_ITEM_NODE(WXS_BASIC_CAST circ
),
19163 "Circular reference to the attribute group '%s' "
19164 "defined", xmlSchemaGetComponentQName(&str
, attrGr
));
19165 FREE_AND_NULL(str
);
19167 * NOTE: We will cut the reference to avoid further
19168 * confusion of the processor.
19169 * BADSPEC TODO: The spec should define how to process in this case.
19179 xmlSchemaAttributeGroupExpandRefs(xmlSchemaParserCtxtPtr pctxt
,
19180 xmlSchemaAttributeGroupPtr attrGr
);
19183 * xmlSchemaExpandAttributeGroupRefs:
19184 * @pctxt: the parser context
19185 * @node: the node of the component holding the attribute uses
19186 * @completeWild: the intersected wildcard to be returned
19187 * @list: the attribute uses
19189 * Substitutes contained attribute group references
19190 * for their attribute uses. Wilcards are intersected.
19191 * Attribute use prohibitions are removed from the list
19192 * and returned via the @prohibs list.
19193 * Pointlessness of attr. prohibs, if a matching attr. decl
19194 * is existent a well, are checked.
19197 xmlSchemaExpandAttributeGroupRefs(xmlSchemaParserCtxtPtr pctxt
,
19198 xmlSchemaBasicItemPtr item
,
19199 xmlSchemaWildcardPtr
*completeWild
,
19200 xmlSchemaItemListPtr list
,
19201 xmlSchemaItemListPtr prohibs
)
19203 xmlSchemaAttributeGroupPtr gr
;
19204 xmlSchemaAttributeUsePtr use
;
19205 xmlSchemaItemListPtr sublist
;
19207 int created
= (*completeWild
== NULL
) ? 0 : 1;
19210 prohibs
->nbItems
= 0;
19212 for (i
= 0; i
< list
->nbItems
; i
++) {
19213 use
= list
->items
[i
];
19215 if (use
->type
== XML_SCHEMA_EXTRA_ATTR_USE_PROHIB
) {
19216 if (prohibs
== NULL
) {
19217 PERROR_INT("xmlSchemaExpandAttributeGroupRefs",
19218 "unexpected attr prohibition found");
19222 * Remove from attribute uses.
19224 if (xmlSchemaItemListRemove(list
, i
) == -1)
19228 * Note that duplicate prohibitions were already
19229 * handled at parsing time.
19232 * Add to list of prohibitions.
19234 xmlSchemaItemListAddSize(prohibs
, 2, use
);
19237 if ((use
->type
== XML_SCHEMA_EXTRA_QNAMEREF
) &&
19238 ((WXS_QNAME_CAST use
)->itemType
== XML_SCHEMA_TYPE_ATTRIBUTEGROUP
))
19240 if ((WXS_QNAME_CAST use
)->item
== NULL
)
19242 gr
= WXS_ATTR_GROUP_CAST (WXS_QNAME_CAST use
)->item
;
19244 * Expand the referenced attr. group.
19245 * TODO: remove this, this is done in a previous step, so
19246 * already done here.
19248 if ((gr
->flags
& XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED
) == 0) {
19249 if (xmlSchemaAttributeGroupExpandRefs(pctxt
, gr
) == -1)
19253 * Build the 'complete' wildcard; i.e. intersect multiple
19256 if (gr
->attributeWildcard
!= NULL
) {
19257 if (*completeWild
== NULL
) {
19258 *completeWild
= gr
->attributeWildcard
;
19261 xmlSchemaWildcardPtr tmpWild
;
19264 * Copy the first encountered wildcard as context,
19265 * except for the annotation.
19267 * Although the complete wildcard might not correspond
19268 * to any node in the schema, we will anchor it on
19269 * the node of the owner component.
19271 tmpWild
= xmlSchemaAddWildcard(pctxt
, pctxt
->schema
,
19272 XML_SCHEMA_TYPE_ANY_ATTRIBUTE
,
19273 WXS_ITEM_NODE(item
));
19274 if (tmpWild
== NULL
)
19276 if (xmlSchemaCloneWildcardNsConstraints(pctxt
,
19277 tmpWild
, *completeWild
) == -1)
19279 tmpWild
->processContents
= (*completeWild
)->processContents
;
19280 *completeWild
= tmpWild
;
19284 if (xmlSchemaIntersectWildcards(pctxt
, *completeWild
,
19285 gr
->attributeWildcard
) == -1)
19290 * Just remove the reference if the referenced group does not
19291 * contain any attribute uses.
19293 sublist
= ((xmlSchemaItemListPtr
) gr
->attrUses
);
19294 if ((sublist
== NULL
) || sublist
->nbItems
== 0) {
19295 if (xmlSchemaItemListRemove(list
, i
) == -1)
19301 * Add the attribute uses.
19303 list
->items
[i
] = sublist
->items
[0];
19304 if (sublist
->nbItems
!= 1) {
19305 for (j
= 1; j
< sublist
->nbItems
; j
++) {
19307 if (xmlSchemaItemListInsert(list
,
19308 sublist
->items
[j
], i
) == -1)
19316 * Handle pointless prohibitions of declared attributes.
19318 if (prohibs
&& (prohibs
->nbItems
!= 0) && (list
->nbItems
!= 0)) {
19319 xmlSchemaAttributeUseProhibPtr prohib
;
19321 for (i
= prohibs
->nbItems
-1; i
>= 0; i
--) {
19322 prohib
= prohibs
->items
[i
];
19323 for (j
= 0; j
< list
->nbItems
; j
++) {
19324 use
= list
->items
[j
];
19326 if ((prohib
->name
== WXS_ATTRUSE_DECL_NAME(use
)) &&
19327 (prohib
->targetNamespace
== WXS_ATTRUSE_DECL_TNS(use
)))
19329 xmlChar
*str
= NULL
;
19331 xmlSchemaCustomWarning(ACTXT_CAST pctxt
,
19332 XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH
,
19333 prohib
->node
, NULL
,
19334 "Skipping pointless attribute use prohibition "
19335 "'%s', since a corresponding attribute use "
19336 "exists already in the type definition",
19337 xmlSchemaFormatQName(&str
,
19338 prohib
->targetNamespace
, prohib
->name
),
19340 FREE_AND_NULL(str
);
19342 * Remove the prohibition.
19344 if (xmlSchemaItemListRemove(prohibs
, i
) == -1)
19355 * xmlSchemaAttributeGroupExpandRefs:
19356 * @pctxt: the parser context
19357 * @attrGr: the attribute group definition
19360 * {attribute uses} property
19361 * {attribute wildcard} property
19363 * Substitutes contained attribute group references
19364 * for their attribute uses. Wilcards are intersected.
19367 xmlSchemaAttributeGroupExpandRefs(xmlSchemaParserCtxtPtr pctxt
,
19368 xmlSchemaAttributeGroupPtr attrGr
)
19370 if ((attrGr
->attrUses
== NULL
) ||
19371 (attrGr
->flags
& XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED
))
19374 attrGr
->flags
|= XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED
;
19375 if (xmlSchemaExpandAttributeGroupRefs(pctxt
, WXS_BASIC_CAST attrGr
,
19376 &(attrGr
->attributeWildcard
), attrGr
->attrUses
, NULL
) == -1)
19382 * xmlSchemaAttributeGroupExpandRefs:
19383 * @pctxt: the parser context
19384 * @attrGr: the attribute group definition
19386 * Substitutes contained attribute group references
19387 * for their attribute uses. Wilcards are intersected.
19389 * Schema Component Constraint:
19390 * Attribute Group Definition Properties Correct (ag-props-correct)
19393 xmlSchemaCheckAGPropsCorrect(xmlSchemaParserCtxtPtr pctxt
,
19394 xmlSchemaAttributeGroupPtr attrGr
)
19397 * SPEC ag-props-correct
19398 * (1) "The values of the properties of an attribute group definition
19399 * must be as described in the property tableau in The Attribute
19400 * Group Definition Schema Component ($3.6.1), modulo the impact of
19401 * Missing Sub-components ($5.3);"
19404 if ((attrGr
->attrUses
!= NULL
) &&
19405 (WXS_LIST_CAST attrGr
->attrUses
)->nbItems
> 1)
19407 xmlSchemaItemListPtr uses
= WXS_LIST_CAST attrGr
->attrUses
;
19408 xmlSchemaAttributeUsePtr use
, tmp
;
19409 int i
, j
, hasId
= 0;
19411 for (i
= uses
->nbItems
-1; i
>= 0; i
--) {
19412 use
= uses
->items
[i
];
19414 * SPEC ag-props-correct
19415 * (2) "Two distinct members of the {attribute uses} must not have
19416 * {attribute declaration}s both of whose {name}s match and whose
19417 * {target namespace}s are identical."
19420 for (j
= i
-1; j
>= 0; j
--) {
19421 tmp
= uses
->items
[j
];
19422 if ((WXS_ATTRUSE_DECL_NAME(use
) ==
19423 WXS_ATTRUSE_DECL_NAME(tmp
)) &&
19424 (WXS_ATTRUSE_DECL_TNS(use
) ==
19425 WXS_ATTRUSE_DECL_TNS(tmp
)))
19427 xmlChar
*str
= NULL
;
19429 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
19430 XML_SCHEMAP_AG_PROPS_CORRECT
,
19431 attrGr
->node
, WXS_BASIC_CAST attrGr
,
19433 xmlSchemaGetComponentDesignation(&str
, use
),
19435 FREE_AND_NULL(str
);
19437 * Remove the duplicate.
19439 if (xmlSchemaItemListRemove(uses
, i
) == -1)
19446 * SPEC ag-props-correct
19447 * (3) "Two distinct members of the {attribute uses} must not have
19448 * {attribute declaration}s both of whose {type definition}s are or
19449 * are derived from ID."
19450 * TODO: Does 'derived' include member-types of unions?
19452 if (WXS_ATTRUSE_TYPEDEF(use
) != NULL
) {
19453 if (xmlSchemaIsDerivedFromBuiltInType(
19454 WXS_ATTRUSE_TYPEDEF(use
), XML_SCHEMAS_ID
))
19457 xmlChar
*str
= NULL
;
19459 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
19460 XML_SCHEMAP_AG_PROPS_CORRECT
,
19461 attrGr
->node
, WXS_BASIC_CAST attrGr
,
19462 "There must not exist more than one attribute "
19463 "declaration of type 'xs:ID' "
19464 "(or derived from 'xs:ID'). The %s violates this "
19466 xmlSchemaGetComponentDesignation(&str
, use
),
19468 FREE_AND_NULL(str
);
19469 if (xmlSchemaItemListRemove(uses
, i
) == -1)
19482 * xmlSchemaResolveAttrGroupReferences:
19483 * @attrgrpDecl: the schema attribute definition
19484 * @ctxt: the schema parser context
19485 * @name: the attribute name
19487 * Resolves references to attribute group definitions.
19490 xmlSchemaResolveAttrGroupReferences(xmlSchemaQNameRefPtr ref
,
19491 xmlSchemaParserCtxtPtr ctxt
)
19493 xmlSchemaAttributeGroupPtr group
;
19495 if (ref
->item
!= NULL
)
19497 group
= xmlSchemaGetAttributeGroup(ctxt
->schema
,
19499 ref
->targetNamespace
);
19500 if (group
== NULL
) {
19501 xmlSchemaPResCompAttrErr(ctxt
,
19502 XML_SCHEMAP_SRC_RESOLVE
,
19504 "ref", ref
->name
, ref
->targetNamespace
,
19505 ref
->itemType
, NULL
);
19508 ref
->item
= WXS_BASIC_CAST group
;
19513 * xmlSchemaCheckAttrPropsCorrect:
19514 * @item: an schema attribute declaration/use
19515 * @ctxt: a schema parser context
19516 * @name: the name of the attribute
19519 * Schema Component Constraint:
19520 * Attribute Declaration Properties Correct (a-props-correct)
19522 * Validates the value constraints of an attribute declaration/use.
19523 * NOTE that this needs the simle type definitions to be already
19524 * builded and checked.
19527 xmlSchemaCheckAttrPropsCorrect(xmlSchemaParserCtxtPtr pctxt
,
19528 xmlSchemaAttributePtr attr
)
19532 * SPEC a-props-correct (1)
19533 * "The values of the properties of an attribute declaration must
19534 * be as described in the property tableau in The Attribute
19535 * Declaration Schema Component ($3.2.1), modulo the impact of
19536 * Missing Sub-components ($5.3)."
19539 if (WXS_ATTR_TYPEDEF(attr
) == NULL
)
19542 if (attr
->defValue
!= NULL
) {
19546 * SPEC a-props-correct (3)
19547 * "If the {type definition} is or is derived from ID then there
19548 * must not be a {value constraint}."
19550 if (xmlSchemaIsDerivedFromBuiltInType(
19551 WXS_ATTR_TYPEDEF(attr
), XML_SCHEMAS_ID
))
19553 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
19554 XML_SCHEMAP_A_PROPS_CORRECT_3
,
19555 NULL
, WXS_BASIC_CAST attr
,
19556 "Value constraints are not allowed if the type definition "
19557 "is or is derived from xs:ID",
19559 return(pctxt
->err
);
19562 * SPEC a-props-correct (2)
19563 * "if there is a {value constraint}, the canonical lexical
19564 * representation of its value must be `valid` with respect
19565 * to the {type definition} as defined in String Valid ($3.14.4)."
19566 * TODO: Don't care about the *canonical* stuff here, this requirement
19567 * will be removed in WXS 1.1 anyway.
19569 ret
= xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt
,
19570 attr
->node
, WXS_ATTR_TYPEDEF(attr
),
19571 attr
->defValue
, &(attr
->defVal
),
19575 PERROR_INT("xmlSchemaCheckAttrPropsCorrect",
19576 "calling xmlSchemaVCheckCVCSimpleType()");
19579 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
19580 XML_SCHEMAP_A_PROPS_CORRECT_2
,
19581 NULL
, WXS_BASIC_CAST attr
,
19582 "The value of the value constraint is not valid",
19584 return(pctxt
->err
);
19591 static xmlSchemaElementPtr
19592 xmlSchemaCheckSubstGroupCircular(xmlSchemaElementPtr elemDecl
,
19593 xmlSchemaElementPtr ancestor
)
19595 xmlSchemaElementPtr ret
;
19597 if (WXS_SUBST_HEAD(ancestor
) == NULL
)
19599 if (WXS_SUBST_HEAD(ancestor
) == elemDecl
)
19602 if (WXS_SUBST_HEAD(ancestor
)->flags
& XML_SCHEMAS_ELEM_CIRCULAR
)
19604 WXS_SUBST_HEAD(ancestor
)->flags
|= XML_SCHEMAS_ELEM_CIRCULAR
;
19605 ret
= xmlSchemaCheckSubstGroupCircular(elemDecl
,
19606 WXS_SUBST_HEAD(ancestor
));
19607 WXS_SUBST_HEAD(ancestor
)->flags
^= XML_SCHEMAS_ELEM_CIRCULAR
;
19613 * xmlSchemaCheckElemPropsCorrect:
19614 * @ctxt: a schema parser context
19615 * @decl: the element declaration
19616 * @name: the name of the attribute
19618 * Schema Component Constraint:
19619 * Element Declaration Properties Correct (e-props-correct)
19625 xmlSchemaCheckElemPropsCorrect(xmlSchemaParserCtxtPtr pctxt
,
19626 xmlSchemaElementPtr elemDecl
)
19629 xmlSchemaTypePtr typeDef
= WXS_ELEM_TYPEDEF(elemDecl
);
19631 * SPEC (1) "The values of the properties of an element declaration
19632 * must be as described in the property tableau in The Element
19633 * Declaration Schema Component ($3.3.1), modulo the impact of Missing
19634 * Sub-components ($5.3)."
19636 if (WXS_SUBST_HEAD(elemDecl
) != NULL
) {
19637 xmlSchemaElementPtr head
= WXS_SUBST_HEAD(elemDecl
), circ
;
19639 xmlSchemaCheckElementDeclComponent(head
, pctxt
);
19641 * SPEC (3) "If there is a non-`absent` {substitution group
19642 * affiliation}, then {scope} must be global."
19644 if ((elemDecl
->flags
& XML_SCHEMAS_ELEM_GLOBAL
) == 0) {
19645 xmlSchemaPCustomErr(pctxt
,
19646 XML_SCHEMAP_E_PROPS_CORRECT_3
,
19647 WXS_BASIC_CAST elemDecl
, NULL
,
19648 "Only global element declarations can have a "
19649 "substitution group affiliation", NULL
);
19650 ret
= XML_SCHEMAP_E_PROPS_CORRECT_3
;
19653 * TODO: SPEC (6) "Circular substitution groups are disallowed.
19654 * That is, it must not be possible to return to an element declaration
19655 * by repeatedly following the {substitution group affiliation}
19658 if (head
== elemDecl
)
19660 else if (WXS_SUBST_HEAD(head
) != NULL
)
19661 circ
= xmlSchemaCheckSubstGroupCircular(head
, head
);
19664 if (circ
!= NULL
) {
19665 xmlChar
*strA
= NULL
, *strB
= NULL
;
19667 xmlSchemaPCustomErrExt(pctxt
,
19668 XML_SCHEMAP_E_PROPS_CORRECT_6
,
19669 WXS_BASIC_CAST circ
, NULL
,
19670 "The element declaration '%s' defines a circular "
19671 "substitution group to element declaration '%s'",
19672 xmlSchemaGetComponentQName(&strA
, circ
),
19673 xmlSchemaGetComponentQName(&strB
, head
),
19675 FREE_AND_NULL(strA
)
19676 FREE_AND_NULL(strB
)
19677 ret
= XML_SCHEMAP_E_PROPS_CORRECT_6
;
19680 * SPEC (4) "If there is a {substitution group affiliation},
19681 * the {type definition}
19682 * of the element declaration must be validly derived from the {type
19683 * definition} of the {substitution group affiliation}, given the value
19684 * of the {substitution group exclusions} of the {substitution group
19685 * affiliation}, as defined in Type Derivation OK (Complex) ($3.4.6)
19686 * (if the {type definition} is complex) or as defined in
19687 * Type Derivation OK (Simple) ($3.14.6) (if the {type definition} is
19690 * NOTE: {substitution group exclusions} means the values of the
19691 * attribute "final".
19694 if (typeDef
!= WXS_ELEM_TYPEDEF(WXS_SUBST_HEAD(elemDecl
))) {
19697 if (head
->flags
& XML_SCHEMAS_ELEM_FINAL_EXTENSION
)
19698 set
|= SUBSET_EXTENSION
;
19699 if (head
->flags
& XML_SCHEMAS_ELEM_FINAL_RESTRICTION
)
19700 set
|= SUBSET_RESTRICTION
;
19702 if (xmlSchemaCheckCOSDerivedOK(ACTXT_CAST pctxt
, typeDef
,
19703 WXS_ELEM_TYPEDEF(head
), set
) != 0) {
19704 xmlChar
*strA
= NULL
, *strB
= NULL
, *strC
= NULL
;
19706 ret
= XML_SCHEMAP_E_PROPS_CORRECT_4
;
19707 xmlSchemaPCustomErrExt(pctxt
,
19708 XML_SCHEMAP_E_PROPS_CORRECT_4
,
19709 WXS_BASIC_CAST elemDecl
, NULL
,
19710 "The type definition '%s' was "
19711 "either rejected by the substitution group "
19712 "affiliation '%s', or not validly derived from its type "
19714 xmlSchemaGetComponentQName(&strA
, typeDef
),
19715 xmlSchemaGetComponentQName(&strB
, head
),
19716 xmlSchemaGetComponentQName(&strC
, WXS_ELEM_TYPEDEF(head
)));
19717 FREE_AND_NULL(strA
)
19718 FREE_AND_NULL(strB
)
19719 FREE_AND_NULL(strC
)
19724 * SPEC (5) "If the {type definition} or {type definition}'s
19726 * is or is derived from ID then there must not be a {value constraint}.
19727 * Note: The use of ID as a type definition for elements goes beyond
19728 * XML 1.0, and should be avoided if backwards compatibility is desired"
19730 if ((elemDecl
->value
!= NULL
) &&
19731 ((WXS_IS_SIMPLE(typeDef
) &&
19732 xmlSchemaIsDerivedFromBuiltInType(typeDef
, XML_SCHEMAS_ID
)) ||
19733 (WXS_IS_COMPLEX(typeDef
) &&
19734 WXS_HAS_SIMPLE_CONTENT(typeDef
) &&
19735 xmlSchemaIsDerivedFromBuiltInType(typeDef
->contentTypeDef
,
19736 XML_SCHEMAS_ID
)))) {
19738 ret
= XML_SCHEMAP_E_PROPS_CORRECT_5
;
19739 xmlSchemaPCustomErr(pctxt
,
19740 XML_SCHEMAP_E_PROPS_CORRECT_5
,
19741 WXS_BASIC_CAST elemDecl
, NULL
,
19742 "The type definition (or type definition's content type) is or "
19743 "is derived from ID; value constraints are not allowed in "
19744 "conjunction with such a type definition", NULL
);
19745 } else if (elemDecl
->value
!= NULL
) {
19747 xmlNodePtr node
= NULL
;
19750 * SPEC (2) "If there is a {value constraint}, the canonical lexical
19751 * representation of its value must be `valid` with respect to the
19752 * {type definition} as defined in Element Default Valid (Immediate)
19755 if (typeDef
== NULL
) {
19756 xmlSchemaPErr(pctxt
, elemDecl
->node
,
19757 XML_SCHEMAP_INTERNAL
,
19758 "Internal error: xmlSchemaCheckElemPropsCorrect, "
19759 "type is missing... skipping validation of "
19760 "the value constraint", NULL
, NULL
);
19763 if (elemDecl
->node
!= NULL
) {
19764 if (elemDecl
->flags
& XML_SCHEMAS_ELEM_FIXED
)
19765 node
= (xmlNodePtr
) xmlHasProp(elemDecl
->node
,
19768 node
= (xmlNodePtr
) xmlHasProp(elemDecl
->node
,
19769 BAD_CAST
"default");
19771 vcret
= xmlSchemaParseCheckCOSValidDefault(pctxt
, node
,
19772 typeDef
, elemDecl
->value
, &(elemDecl
->defVal
));
19775 PERROR_INT("xmlSchemaElemCheckValConstr",
19776 "failed to validate the value constraint of an "
19777 "element declaration");
19788 * xmlSchemaCheckElemSubstGroup:
19789 * @ctxt: a schema parser context
19790 * @decl: the element declaration
19791 * @name: the name of the attribute
19793 * Schema Component Constraint:
19794 * Substitution Group (cos-equiv-class)
19796 * In Libxml2 the subst. groups will be precomputed, in terms of that
19797 * a list will be built for each subst. group head, holding all direct
19798 * referents to this head.
19799 * NOTE that this function needs:
19800 * 1. circular subst. groups to be checked beforehand
19801 * 2. the declaration's type to be derived from the head's type
19807 xmlSchemaCheckElemSubstGroup(xmlSchemaParserCtxtPtr ctxt
,
19808 xmlSchemaElementPtr elemDecl
)
19810 if ((WXS_SUBST_HEAD(elemDecl
) == NULL
) ||
19811 /* SPEC (1) "Its {abstract} is false." */
19812 (elemDecl
->flags
& XML_SCHEMAS_ELEM_ABSTRACT
))
19815 xmlSchemaElementPtr head
;
19816 xmlSchemaTypePtr headType
, type
;
19819 * SPEC (2) "It is validly substitutable for HEAD subject to HEAD's
19820 * {disallowed substitutions} as the blocking constraint, as defined in
19821 * Substitution Group OK (Transitive) ($3.3.6)."
19823 for (head
= WXS_SUBST_HEAD(elemDecl
); head
!= NULL
;
19824 head
= WXS_SUBST_HEAD(head
)) {
19828 * The blocking constraints.
19830 if (head
->flags
& XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION
)
19832 headType
= head
->subtypes
;
19833 type
= elemDecl
->subtypes
;
19834 if (headType
== type
)
19836 if (head
->flags
& XML_SCHEMAS_ELEM_BLOCK_RESTRICTION
)
19837 set
|= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION
;
19838 if (head
->flags
& XML_SCHEMAS_ELEM_BLOCK_EXTENSION
)
19839 set
|= XML_SCHEMAS_TYPE_BLOCK_EXTENSION
;
19841 * SPEC: Substitution Group OK (Transitive) (2.3)
19842 * "The set of all {derivation method}s involved in the
19843 * derivation of D's {type definition} from C's {type definition}
19844 * does not intersect with the union of the blocking constraint,
19845 * C's {prohibited substitutions} (if C is complex, otherwise the
19846 * empty set) and the {prohibited substitutions} (respectively the
19847 * empty set) of any intermediate {type definition}s in the
19848 * derivation of D's {type definition} from C's {type definition}."
19851 * OPTIMIZE TODO: Optimize this a bit, since, if traversing the
19852 * subst.head axis, the methSet does not need to be computed for
19853 * the full depth over and over.
19856 * The set of all {derivation method}s involved in the derivation
19858 while ((type
!= NULL
) && (type
!= headType
)) {
19859 if ((WXS_IS_EXTENSION(type
)) &&
19860 ((methSet
& XML_SCHEMAS_TYPE_BLOCK_RESTRICTION
) == 0))
19861 methSet
|= XML_SCHEMAS_TYPE_BLOCK_EXTENSION
;
19863 if (WXS_IS_RESTRICTION(type
) &&
19864 ((methSet
& XML_SCHEMAS_TYPE_BLOCK_RESTRICTION
) == 0))
19865 methSet
|= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION
;
19867 type
= type
->baseType
;
19870 * The {prohibited substitutions} of all intermediate types +
19873 type
= elemDecl
->subtypes
->baseType
;
19874 while (type
!= NULL
) {
19875 if (WXS_IS_COMPLEX(type
)) {
19877 XML_SCHEMAS_TYPE_BLOCK_EXTENSION
) &&
19878 ((set
& XML_SCHEMAS_TYPE_BLOCK_EXTENSION
) == 0))
19879 set
|= XML_SCHEMAS_TYPE_BLOCK_EXTENSION
;
19881 XML_SCHEMAS_TYPE_BLOCK_RESTRICTION
) &&
19882 ((set
& XML_SCHEMAS_TYPE_BLOCK_RESTRICTION
) == 0))
19883 set
|= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION
;
19886 if (type
== headType
)
19888 type
= type
->baseType
;
19891 (((set
& XML_SCHEMAS_TYPE_BLOCK_EXTENSION
) &&
19892 (methSet
& XML_SCHEMAS_TYPE_BLOCK_EXTENSION
)) ||
19893 ((set
& XML_SCHEMAS_TYPE_BLOCK_RESTRICTION
) &&
19894 (methSet
& XML_SCHEMAS_TYPE_BLOCK_RESTRICTION
)))) {
19898 xmlSchemaAddElementSubstitutionMember(ctxt
, head
, elemDecl
);
19899 if ((head
->flags
& XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD
) == 0)
19900 head
->flags
|= XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD
;
19905 #ifdef WXS_ELEM_DECL_CONS_ENABLED /* enable when finished */
19907 * xmlSchemaCheckElementDeclComponent
19908 * @pctxt: the schema parser context
19909 * @ctxtComponent: the context component (an element declaration)
19910 * @ctxtParticle: the first particle of the context component
19911 * @searchParticle: the element declaration particle to be analysed
19913 * Schema Component Constraint: Element Declarations Consistent
19916 xmlSchemaCheckElementDeclConsistent(xmlSchemaParserCtxtPtr pctxt
,
19917 xmlSchemaBasicItemPtr ctxtComponent
,
19918 xmlSchemaParticlePtr ctxtParticle
,
19919 xmlSchemaParticlePtr searchParticle
,
19920 xmlSchemaParticlePtr curParticle
,
19926 xmlSchemaParticlePtr cur
= curParticle
;
19927 if (curParticle
== NULL
) {
19930 if (WXS_PARTICLE_TERM(curParticle
) == NULL
) {
19932 * Just return in this case. A missing "term" of the particle
19933 * might arise due to an invalid "term" component.
19937 while (cur
!= NULL
) {
19938 switch (WXS_PARTICLE_TERM(cur
)->type
) {
19939 case XML_SCHEMA_TYPE_ANY
:
19941 case XML_SCHEMA_TYPE_ELEMENT
:
19943 ret
= xmlSchemaCheckElementDeclConsistent(pctxt
,
19944 ctxtComponent
, ctxtParticle
, cur
, ctxtParticle
, 1);
19948 xmlSchemaElementPtr elem
=
19949 WXS_ELEM_CAST(WXS_PARTICLE_TERM(cur
));
19951 * SPEC Element Declarations Consistent:
19952 * "If the {particles} contains, either directly,
19953 * indirectly (that is, within the {particles} of a
19954 * contained model group, recursively) or `implicitly`
19955 * two or more element declaration particles with
19956 * the same {name} and {target namespace}, then
19957 * all their type definitions must be the same
19958 * top-level definition [...]"
19960 if (xmlStrEqual(WXS_PARTICLE_TERM_AS_ELEM(cur
)->name
,
19961 WXS_PARTICLE_TERM_AS_ELEM(searchParticle
)->name
) &&
19962 xmlStrEqual(WXS_PARTICLE_TERM_AS_ELEM(cur
)->targetNamespace
,
19963 WXS_PARTICLE_TERM_AS_ELEM(searchParticle
)->targetNamespace
))
19965 xmlChar
*strA
= NULL
, *strB
= NULL
;
19967 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
19968 /* TODO: error code */
19969 XML_SCHEMAP_COS_NONAMBIG
,
19970 WXS_ITEM_NODE(cur
), NULL
,
19971 "In the content model of %s, there are multiple "
19972 "element declarations for '%s' with different "
19973 "type definitions",
19974 xmlSchemaGetComponentDesignation(&strA
,
19976 xmlSchemaFormatQName(&strB
,
19977 WXS_PARTICLE_TERM_AS_ELEM(cur
)->targetNamespace
,
19978 WXS_PARTICLE_TERM_AS_ELEM(cur
)->name
));
19979 FREE_AND_NULL(strA
);
19980 FREE_AND_NULL(strB
);
19981 return(XML_SCHEMAP_COS_NONAMBIG
);
19985 case XML_SCHEMA_TYPE_SEQUENCE
: {
19988 case XML_SCHEMA_TYPE_CHOICE
:{
19990 xmlSchemaTreeItemPtr sub;
19992 sub = WXS_PARTICLE_TERM(particle)->children; (xmlSchemaParticlePtr)
19993 while (sub != NULL) {
19994 ret = xmlSchemaCheckElementDeclConsistent(pctxt, ctxtComponent,
19995 ctxtParticle, ctxtElem);
20003 case XML_SCHEMA_TYPE_ALL
:
20005 case XML_SCHEMA_TYPE_GROUP
:
20008 xmlSchemaInternalErr2(ACTXT_CAST pctxt
,
20009 "xmlSchemaCheckElementDeclConsistent",
20010 "found unexpected term of type '%s' in content model",
20011 WXS_ITEM_TYPE_NAME(WXS_PARTICLE_TERM(cur
)), NULL
);
20014 cur
= (xmlSchemaParticlePtr
) cur
->next
;
20023 * xmlSchemaCheckElementDeclComponent
20024 * @item: an schema element declaration/particle
20025 * @ctxt: a schema parser context
20026 * @name: the name of the attribute
20028 * Validates the value constraints of an element declaration.
20029 * Adds substitution group members.
20032 xmlSchemaCheckElementDeclComponent(xmlSchemaElementPtr elemDecl
,
20033 xmlSchemaParserCtxtPtr ctxt
)
20035 if (elemDecl
== NULL
)
20037 if (elemDecl
->flags
& XML_SCHEMAS_ELEM_INTERNAL_CHECKED
)
20039 elemDecl
->flags
|= XML_SCHEMAS_ELEM_INTERNAL_CHECKED
;
20040 if (xmlSchemaCheckElemPropsCorrect(ctxt
, elemDecl
) == 0) {
20042 * Adds substitution group members.
20044 xmlSchemaCheckElemSubstGroup(ctxt
, elemDecl
);
20049 * xmlSchemaResolveModelGroupParticleReferences:
20050 * @particle: a particle component
20051 * @ctxt: a parser context
20053 * Resolves references of a model group's {particles} to
20054 * model group definitions and to element declarations.
20057 xmlSchemaResolveModelGroupParticleReferences(
20058 xmlSchemaParserCtxtPtr ctxt
,
20059 xmlSchemaModelGroupPtr mg
)
20061 xmlSchemaParticlePtr particle
= WXS_MODELGROUP_PARTICLE(mg
);
20062 xmlSchemaQNameRefPtr ref
;
20063 xmlSchemaBasicItemPtr refItem
;
20066 * URGENT TODO: Test this.
20068 while (particle
!= NULL
) {
20069 if ((WXS_PARTICLE_TERM(particle
) == NULL
) ||
20070 ((WXS_PARTICLE_TERM(particle
))->type
!=
20071 XML_SCHEMA_EXTRA_QNAMEREF
))
20073 goto next_particle
;
20075 ref
= WXS_QNAME_CAST
WXS_PARTICLE_TERM(particle
);
20077 * Resolve the reference.
20078 * NULL the {term} by default.
20080 particle
->children
= NULL
;
20082 refItem
= xmlSchemaGetNamedComponent(ctxt
->schema
,
20083 ref
->itemType
, ref
->name
, ref
->targetNamespace
);
20084 if (refItem
== NULL
) {
20085 xmlSchemaPResCompAttrErr(ctxt
, XML_SCHEMAP_SRC_RESOLVE
,
20086 NULL
, WXS_ITEM_NODE(particle
), "ref", ref
->name
,
20087 ref
->targetNamespace
, ref
->itemType
, NULL
);
20088 /* TODO: remove the particle. */
20089 goto next_particle
;
20091 if (refItem
->type
== XML_SCHEMA_TYPE_GROUP
) {
20092 if (WXS_MODELGROUPDEF_MODEL(refItem
) == NULL
)
20093 /* TODO: remove the particle. */
20094 goto next_particle
;
20096 * NOTE that we will assign the model group definition
20097 * itself to the "term" of the particle. This will ease
20098 * the check for circular model group definitions. After
20099 * that the "term" will be assigned the model group of the
20100 * model group definition.
20102 if ((WXS_MODELGROUPDEF_MODEL(refItem
))->type
==
20103 XML_SCHEMA_TYPE_ALL
) {
20105 * SPEC cos-all-limited (1)
20106 * SPEC cos-all-limited (1.2)
20107 * "It appears only as the value of one or both of the
20108 * following properties:"
20109 * (1.1) "the {model group} property of a model group
20111 * (1.2) "the {term} property of a particle [... of] the "
20112 * {content type} of a complex type definition."
20114 xmlSchemaCustomErr(ACTXT_CAST ctxt
,
20115 /* TODO: error code */
20116 XML_SCHEMAP_COS_ALL_LIMITED
,
20117 WXS_ITEM_NODE(particle
), NULL
,
20118 "A model group definition is referenced, but "
20119 "it contains an 'all' model group, which "
20120 "cannot be contained by model groups",
20122 /* TODO: remove the particle. */
20123 goto next_particle
;
20125 particle
->children
= (xmlSchemaTreeItemPtr
) refItem
;
20128 * TODO: Are referenced element declarations the only
20129 * other components we expect here?
20131 particle
->children
= (xmlSchemaTreeItemPtr
) refItem
;
20134 particle
= WXS_PTC_CAST particle
->next
;
20139 xmlSchemaAreValuesEqual(xmlSchemaValPtr x
,
20142 xmlSchemaTypePtr tx
, ty
, ptx
, pty
;
20145 while (x
!= NULL
) {
20147 tx
= xmlSchemaGetBuiltInType(xmlSchemaGetValType(x
));
20148 ty
= xmlSchemaGetBuiltInType(xmlSchemaGetValType(y
));
20149 ptx
= xmlSchemaGetPrimitiveType(tx
);
20150 pty
= xmlSchemaGetPrimitiveType(ty
);
20152 * (1) if a datatype T' is `derived` by `restriction` from an
20153 * atomic datatype T then the `value space` of T' is a subset of
20154 * the `value space` of T. */
20156 * (2) if datatypes T' and T'' are `derived` by `restriction`
20157 * from a common atomic ancestor T then the `value space`s of T'
20158 * and T'' may overlap.
20163 * We assume computed values to be normalized, so do a fast
20164 * string comparison for string based types.
20166 if ((ptx
->builtInType
== XML_SCHEMAS_STRING
) ||
20167 WXS_IS_ANY_SIMPLE_TYPE(ptx
)) {
20169 xmlSchemaValueGetAsString(x
),
20170 xmlSchemaValueGetAsString(y
)))
20173 ret
= xmlSchemaCompareValuesWhtsp(
20174 x
, XML_SCHEMA_WHITESPACE_PRESERVE
,
20175 y
, XML_SCHEMA_WHITESPACE_PRESERVE
);
20184 x
= xmlSchemaValueGetNext(x
);
20186 y
= xmlSchemaValueGetNext(y
);
20189 } else if (xmlSchemaValueGetNext(y
) != NULL
)
20198 * xmlSchemaResolveAttrUseReferences:
20199 * @item: an attribute use
20200 * @ctxt: a parser context
20202 * Resolves the referenced attribute declaration.
20205 xmlSchemaResolveAttrUseReferences(xmlSchemaAttributeUsePtr ause
,
20206 xmlSchemaParserCtxtPtr ctxt
)
20208 if ((ctxt
== NULL
) || (ause
== NULL
))
20210 if ((ause
->attrDecl
== NULL
) ||
20211 (ause
->attrDecl
->type
!= XML_SCHEMA_EXTRA_QNAMEREF
))
20215 xmlSchemaQNameRefPtr ref
= WXS_QNAME_CAST ause
->attrDecl
;
20218 * TODO: Evaluate, what errors could occur if the declaration is not
20221 ause
->attrDecl
= xmlSchemaGetAttributeDecl(ctxt
->schema
,
20222 ref
->name
, ref
->targetNamespace
);
20223 if (ause
->attrDecl
== NULL
) {
20224 xmlSchemaPResCompAttrErr(ctxt
,
20225 XML_SCHEMAP_SRC_RESOLVE
,
20226 WXS_BASIC_CAST ause
, ause
->node
,
20227 "ref", ref
->name
, ref
->targetNamespace
,
20228 XML_SCHEMA_TYPE_ATTRIBUTE
, NULL
);
20229 return(ctxt
->err
);;
20236 * xmlSchemaCheckAttrUsePropsCorrect:
20237 * @ctxt: a parser context
20238 * @use: an attribute use
20240 * Schema Component Constraint:
20241 * Attribute Use Correct (au-props-correct)
20245 xmlSchemaCheckAttrUsePropsCorrect(xmlSchemaParserCtxtPtr ctxt
,
20246 xmlSchemaAttributeUsePtr use
)
20248 if ((ctxt
== NULL
) || (use
== NULL
))
20250 if ((use
->defValue
== NULL
) || (WXS_ATTRUSE_DECL(use
) == NULL
) ||
20251 ((WXS_ATTRUSE_DECL(use
))->type
!= XML_SCHEMA_TYPE_ATTRIBUTE
))
20255 * SPEC au-props-correct (1)
20256 * "The values of the properties of an attribute use must be as
20257 * described in the property tableau in The Attribute Use Schema
20258 * Component ($3.5.1), modulo the impact of Missing
20259 * Sub-components ($5.3)."
20262 if (((WXS_ATTRUSE_DECL(use
))->defValue
!= NULL
) &&
20263 ((WXS_ATTRUSE_DECL(use
))->flags
& XML_SCHEMAS_ATTR_FIXED
) &&
20264 ((use
->flags
& XML_SCHEMA_ATTR_USE_FIXED
) == 0))
20266 xmlSchemaPCustomErr(ctxt
,
20267 XML_SCHEMAP_AU_PROPS_CORRECT_2
,
20268 WXS_BASIC_CAST use
, NULL
,
20269 "The attribute declaration has a 'fixed' value constraint "
20270 ", thus the attribute use must also have a 'fixed' value "
20276 * Compute and check the value constraint's value.
20278 if ((use
->defVal
!= NULL
) && (WXS_ATTRUSE_TYPEDEF(use
) != NULL
)) {
20281 * TODO: The spec seems to be missing a check of the
20282 * value constraint of the attribute use. We will do it here.
20285 * SPEC a-props-correct (3)
20287 if (xmlSchemaIsDerivedFromBuiltInType(
20288 WXS_ATTRUSE_TYPEDEF(use
), XML_SCHEMAS_ID
))
20290 xmlSchemaCustomErr(ACTXT_CAST ctxt
,
20291 XML_SCHEMAP_AU_PROPS_CORRECT
,
20292 NULL
, WXS_BASIC_CAST use
,
20293 "Value constraints are not allowed if the type definition "
20294 "is or is derived from xs:ID",
20299 ret
= xmlSchemaVCheckCVCSimpleType(ACTXT_CAST ctxt
,
20300 use
->node
, WXS_ATTRUSE_TYPEDEF(use
),
20301 use
->defValue
, &(use
->defVal
),
20305 PERROR_INT2("xmlSchemaCheckAttrUsePropsCorrect",
20306 "calling xmlSchemaVCheckCVCSimpleType()");
20309 xmlSchemaCustomErr(ACTXT_CAST ctxt
,
20310 XML_SCHEMAP_AU_PROPS_CORRECT
,
20311 NULL
, WXS_BASIC_CAST use
,
20312 "The value of the value constraint is not valid",
20318 * SPEC au-props-correct (2)
20319 * "If the {attribute declaration} has a fixed
20320 * {value constraint}, then if the attribute use itself has a
20321 * {value constraint}, it must also be fixed and its value must match
20322 * that of the {attribute declaration}'s {value constraint}."
20324 if (((WXS_ATTRUSE_DECL(use
))->defVal
!= NULL
) &&
20325 (((WXS_ATTRUSE_DECL(use
))->flags
& XML_SCHEMA_ATTR_USE_FIXED
) == 0))
20327 if (! xmlSchemaAreValuesEqual(use
->defVal
,
20328 (WXS_ATTRUSE_DECL(use
))->defVal
))
20330 xmlSchemaPCustomErr(ctxt
,
20331 XML_SCHEMAP_AU_PROPS_CORRECT_2
,
20332 WXS_BASIC_CAST use
, NULL
,
20333 "The 'fixed' value constraint of the attribute use "
20334 "must match the attribute declaration's value "
20336 (WXS_ATTRUSE_DECL(use
))->defValue
);
20347 * xmlSchemaResolveAttrTypeReferences:
20348 * @item: an attribute declaration
20349 * @ctxt: a parser context
20351 * Resolves the referenced type definition component.
20354 xmlSchemaResolveAttrTypeReferences(xmlSchemaAttributePtr item
,
20355 xmlSchemaParserCtxtPtr ctxt
)
20358 * The simple type definition corresponding to the <simpleType> element
20359 * information item in the [children], if present, otherwise the simple
20360 * type definition `resolved` to by the `actual value` of the type
20361 * [attribute], if present, otherwise the `simple ur-type definition`.
20363 if (item
->flags
& XML_SCHEMAS_ATTR_INTERNAL_RESOLVED
)
20365 item
->flags
|= XML_SCHEMAS_ATTR_INTERNAL_RESOLVED
;
20366 if (item
->subtypes
!= NULL
)
20368 if (item
->typeName
!= NULL
) {
20369 xmlSchemaTypePtr type
;
20371 type
= xmlSchemaGetType(ctxt
->schema
, item
->typeName
,
20373 if ((type
== NULL
) || (! WXS_IS_SIMPLE(type
))) {
20374 xmlSchemaPResCompAttrErr(ctxt
,
20375 XML_SCHEMAP_SRC_RESOLVE
,
20376 WXS_BASIC_CAST item
, item
->node
,
20377 "type", item
->typeName
, item
->typeNs
,
20378 XML_SCHEMA_TYPE_SIMPLE
, NULL
);
20381 item
->subtypes
= type
;
20385 * The type defaults to the xs:anySimpleType.
20387 item
->subtypes
= xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE
);
20393 * xmlSchemaResolveIDCKeyReferences:
20394 * @idc: the identity-constraint definition
20395 * @ctxt: the schema parser context
20396 * @name: the attribute name
20398 * Resolve keyRef references to key/unique IDCs.
20399 * Schema Component Constraint:
20400 * Identity-constraint Definition Properties Correct (c-props-correct)
20403 xmlSchemaResolveIDCKeyReferences(xmlSchemaIDCPtr idc
,
20404 xmlSchemaParserCtxtPtr pctxt
)
20406 if (idc
->type
!= XML_SCHEMA_TYPE_IDC_KEYREF
)
20408 if (idc
->ref
->name
!= NULL
) {
20409 idc
->ref
->item
= (xmlSchemaBasicItemPtr
)
20410 xmlSchemaGetIDC(pctxt
->schema
, idc
->ref
->name
,
20411 idc
->ref
->targetNamespace
);
20412 if (idc
->ref
->item
== NULL
) {
20414 * TODO: It is actually not an error to fail to resolve
20415 * at this stage. BUT we need to be that strict!
20417 xmlSchemaPResCompAttrErr(pctxt
,
20418 XML_SCHEMAP_SRC_RESOLVE
,
20419 WXS_BASIC_CAST idc
, idc
->node
,
20420 "refer", idc
->ref
->name
,
20421 idc
->ref
->targetNamespace
,
20422 XML_SCHEMA_TYPE_IDC_KEY
, NULL
);
20423 return(pctxt
->err
);
20424 } else if (idc
->ref
->item
->type
== XML_SCHEMA_TYPE_IDC_KEYREF
) {
20426 * SPEC c-props-correct (1)
20428 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
20429 XML_SCHEMAP_C_PROPS_CORRECT
,
20430 NULL
, WXS_BASIC_CAST idc
,
20431 "The keyref references a keyref",
20433 idc
->ref
->item
= NULL
;
20434 return(pctxt
->err
);
20436 if (idc
->nbFields
!=
20437 ((xmlSchemaIDCPtr
) idc
->ref
->item
)->nbFields
) {
20438 xmlChar
*str
= NULL
;
20439 xmlSchemaIDCPtr refer
;
20441 refer
= (xmlSchemaIDCPtr
) idc
->ref
->item
;
20443 * SPEC c-props-correct(2)
20444 * "If the {identity-constraint category} is keyref,
20445 * the cardinality of the {fields} must equal that of
20446 * the {fields} of the {referenced key}.
20448 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
20449 XML_SCHEMAP_C_PROPS_CORRECT
,
20450 NULL
, WXS_BASIC_CAST idc
,
20451 "The cardinality of the keyref differs from the "
20452 "cardinality of the referenced key/unique '%s'",
20453 xmlSchemaFormatQName(&str
, refer
->targetNamespace
,
20457 return(pctxt
->err
);
20465 xmlSchemaResolveAttrUseProhibReferences(xmlSchemaAttributeUseProhibPtr prohib
,
20466 xmlSchemaParserCtxtPtr pctxt
)
20468 if (xmlSchemaGetAttributeDecl(pctxt
->schema
, prohib
->name
,
20469 prohib
->targetNamespace
) == NULL
) {
20471 xmlSchemaPResCompAttrErr(pctxt
,
20472 XML_SCHEMAP_SRC_RESOLVE
,
20473 NULL
, prohib
->node
,
20474 "ref", prohib
->name
, prohib
->targetNamespace
,
20475 XML_SCHEMA_TYPE_ATTRIBUTE
, NULL
);
20476 return(XML_SCHEMAP_SRC_RESOLVE
);
20481 #define WXS_REDEFINED_TYPE(c) \
20482 (((xmlSchemaTypePtr) item)->flags & XML_SCHEMAS_TYPE_REDEFINED)
20484 #define WXS_REDEFINED_MODEL_GROUP_DEF(c) \
20485 (((xmlSchemaModelGroupDefPtr) item)->flags & XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED)
20487 #define WXS_REDEFINED_ATTR_GROUP(c) \
20488 (((xmlSchemaAttributeGroupPtr) item)->flags & XML_SCHEMAS_ATTRGROUP_REDEFINED)
20491 xmlSchemaCheckSRCRedefineFirst(xmlSchemaParserCtxtPtr pctxt
)
20494 xmlSchemaRedefPtr redef
= WXS_CONSTRUCTOR(pctxt
)->redefs
;
20495 xmlSchemaBasicItemPtr prev
, item
;
20502 item
= redef
->item
;
20504 * First try to locate the redefined component in the
20505 * schema graph starting with the redefined schema.
20506 * NOTE: According to this schema bug entry:
20507 * http://lists.w3.org/Archives/Public/www-xml-schema-comments/2005OctDec/0019.html
20508 * it's not clear if the referenced component needs to originate
20509 * from the <redefine>d schema _document_ or the schema; the latter
20510 * would include all imported and included sub-schemas of the
20511 * <redefine>d schema. Currenlty we latter approach is used.
20512 * SUPPLEMENT: It seems that the WG moves towards the latter
20513 * approach, so we are doing it right.
20516 prev
= xmlSchemaFindRedefCompInGraph(
20517 redef
->targetBucket
, item
->type
,
20518 redef
->refName
, redef
->refTargetNs
);
20519 if (prev
== NULL
) {
20520 xmlChar
*str
= NULL
;
20524 * SPEC src-redefine:
20525 * (6.2.1) "The `actual value` of its own name attribute plus
20526 * target namespace must successfully `resolve` to a model
20527 * group definition in I."
20528 * (7.2.1) "The `actual value` of its own name attribute plus
20529 * target namespace must successfully `resolve` to an attribute
20530 * group definition in I."
20533 * Note that, if we are redefining with the use of references
20534 * to components, the spec assumes the src-resolve to be used;
20535 * but this won't assure that we search only *inside* the
20536 * redefined schema.
20538 if (redef
->reference
)
20539 node
= WXS_ITEM_NODE(redef
->reference
);
20541 node
= WXS_ITEM_NODE(item
);
20542 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
20544 * TODO: error code.
20545 * Probably XML_SCHEMAP_SRC_RESOLVE, if this is using the
20548 XML_SCHEMAP_SRC_REDEFINE
, node
, NULL
,
20549 "The %s '%s' to be redefined could not be found in "
20550 "the redefined schema",
20551 WXS_ITEM_TYPE_NAME(item
),
20552 xmlSchemaFormatQName(&str
, redef
->refTargetNs
,
20554 FREE_AND_NULL(str
);
20556 redef
= redef
->next
;
20560 * TODO: Obtaining and setting the redefinition state is really
20564 switch (item
->type
) {
20565 case XML_SCHEMA_TYPE_COMPLEX
:
20566 case XML_SCHEMA_TYPE_SIMPLE
:
20567 if ((WXS_TYPE_CAST prev
)->flags
&
20568 XML_SCHEMAS_TYPE_REDEFINED
)
20573 /* Mark it as redefined. */
20574 (WXS_TYPE_CAST prev
)->flags
|= XML_SCHEMAS_TYPE_REDEFINED
;
20576 * Assign the redefined type to the
20577 * base type of the redefining type.
20580 ((xmlSchemaTypePtr
) item
)->baseType
=
20581 (xmlSchemaTypePtr
) prev
;
20583 case XML_SCHEMA_TYPE_GROUP
:
20584 if ((WXS_MODEL_GROUPDEF_CAST prev
)->flags
&
20585 XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED
)
20590 /* Mark it as redefined. */
20591 (WXS_MODEL_GROUPDEF_CAST prev
)->flags
|=
20592 XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED
;
20593 if (redef
->reference
!= NULL
) {
20595 * Overwrite the QName-reference with the
20596 * referenced model group def.
20598 (WXS_PTC_CAST redef
->reference
)->children
=
20599 WXS_TREE_CAST prev
;
20601 redef
->target
= prev
;
20603 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP
:
20604 if ((WXS_ATTR_GROUP_CAST prev
)->flags
&
20605 XML_SCHEMAS_ATTRGROUP_REDEFINED
)
20610 (WXS_ATTR_GROUP_CAST prev
)->flags
|=
20611 XML_SCHEMAS_ATTRGROUP_REDEFINED
;
20612 if (redef
->reference
!= NULL
) {
20614 * Assign the redefined attribute group to the
20615 * QName-reference component.
20616 * This is the easy case, since we will just
20617 * expand the redefined group.
20619 (WXS_QNAME_CAST redef
->reference
)->item
= prev
;
20620 redef
->target
= NULL
;
20623 * This is the complicated case: we need
20624 * to apply src-redefine (7.2.2) at a later
20625 * stage, i.e. when attribute group references
20626 * have beed expanded and simple types have
20629 redef
->target
= prev
;
20633 PERROR_INT("xmlSchemaResolveRedefReferences",
20634 "Unexpected redefined component type");
20637 if (wasRedefined
) {
20638 xmlChar
*str
= NULL
;
20641 if (redef
->reference
)
20642 node
= WXS_ITEM_NODE(redef
->reference
);
20644 node
= WXS_ITEM_NODE(redef
->item
);
20646 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
20647 /* TODO: error code. */
20648 XML_SCHEMAP_SRC_REDEFINE
,
20650 "The referenced %s was already redefined. Multiple "
20651 "redefinition of the same component is not supported",
20652 xmlSchemaGetComponentDesignation(&str
, prev
),
20656 redef
= redef
->next
;
20659 redef
= redef
->next
;
20660 } while (redef
!= NULL
);
20666 xmlSchemaCheckSRCRedefineSecond(xmlSchemaParserCtxtPtr pctxt
)
20669 xmlSchemaRedefPtr redef
= WXS_CONSTRUCTOR(pctxt
)->redefs
;
20670 xmlSchemaBasicItemPtr item
;
20676 if (redef
->target
== NULL
) {
20677 redef
= redef
->next
;
20680 item
= redef
->item
;
20682 switch (item
->type
) {
20683 case XML_SCHEMA_TYPE_SIMPLE
:
20684 case XML_SCHEMA_TYPE_COMPLEX
:
20686 * Since the spec wants the {name} of the redefined
20687 * type to be 'absent', we'll NULL it.
20689 (WXS_TYPE_CAST redef
->target
)->name
= NULL
;
20692 * TODO: Seems like there's nothing more to do. The normal
20693 * inheritance mechanism is used. But not 100% sure.
20696 case XML_SCHEMA_TYPE_GROUP
:
20699 * SPEC src-redefine:
20700 * (6.2.2) "The {model group} of the model group definition
20701 * which corresponds to it per XML Representation of Model
20702 * Group Definition Schema Components ($3.7.2) must be a
20703 * `valid restriction` of the {model group} of that model
20704 * group definition in I, as defined in Particle Valid
20705 * (Restriction) ($3.9.6)."
20708 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP
:
20710 * SPEC src-redefine:
20711 * (7.2.2) "The {attribute uses} and {attribute wildcard} of
20712 * the attribute group definition which corresponds to it
20713 * per XML Representation of Attribute Group Definition Schema
20714 * Components ($3.6.2) must be `valid restrictions` of the
20715 * {attribute uses} and {attribute wildcard} of that attribute
20716 * group definition in I, as defined in clause 2, clause 3 and
20717 * clause 4 of Derivation Valid (Restriction, Complex)
20718 * ($3.4.6) (where references to the base type definition are
20719 * understood as references to the attribute group definition
20722 err
= xmlSchemaCheckDerivationOKRestriction2to4(pctxt
,
20723 XML_SCHEMA_ACTION_REDEFINE
,
20724 item
, redef
->target
,
20725 (WXS_ATTR_GROUP_CAST item
)->attrUses
,
20726 (WXS_ATTR_GROUP_CAST redef
->target
)->attrUses
,
20727 (WXS_ATTR_GROUP_CAST item
)->attributeWildcard
,
20728 (WXS_ATTR_GROUP_CAST redef
->target
)->attributeWildcard
);
20735 redef
= redef
->next
;
20736 } while (redef
!= NULL
);
20742 xmlSchemaAddComponents(xmlSchemaParserCtxtPtr pctxt
,
20743 xmlSchemaBucketPtr bucket
)
20745 xmlSchemaBasicItemPtr item
;
20747 xmlHashTablePtr
*table
;
20748 const xmlChar
*name
;
20751 #define WXS_GET_GLOBAL_HASH(c, slot) { \
20752 if (WXS_IS_BUCKET_IMPMAIN((c)->type)) \
20753 table = &(WXS_IMPBUCKET((c))->schema->slot); \
20755 table = &(WXS_INCBUCKET((c))->ownerImport->schema->slot); }
20758 * Add global components to the schema's hash tables.
20759 * This is the place where duplicate components will be
20761 * TODO: I think normally we should support imports of the
20762 * same namespace from multiple locations. We don't do currently,
20763 * but if we do then according to:
20764 * http://www.w3.org/Bugs/Public/show_bug.cgi?id=2224
20765 * we would need, if imported directly, to import redefined
20766 * components as well to be able to catch clashing components.
20767 * (I hope I'll still know what this means after some months :-()
20769 if (bucket
== NULL
)
20771 if (bucket
->flags
& XML_SCHEMA_BUCKET_COMPS_ADDED
)
20773 bucket
->flags
|= XML_SCHEMA_BUCKET_COMPS_ADDED
;
20775 for (i
= 0; i
< bucket
->globals
->nbItems
; i
++) {
20776 item
= bucket
->globals
->items
[i
];
20778 switch (item
->type
) {
20779 case XML_SCHEMA_TYPE_COMPLEX
:
20780 case XML_SCHEMA_TYPE_SIMPLE
:
20781 if (WXS_REDEFINED_TYPE(item
))
20783 name
= (WXS_TYPE_CAST item
)->name
;
20784 WXS_GET_GLOBAL_HASH(bucket
, typeDecl
)
20786 case XML_SCHEMA_TYPE_ELEMENT
:
20787 name
= (WXS_ELEM_CAST item
)->name
;
20788 WXS_GET_GLOBAL_HASH(bucket
, elemDecl
)
20790 case XML_SCHEMA_TYPE_ATTRIBUTE
:
20791 name
= (WXS_ATTR_CAST item
)->name
;
20792 WXS_GET_GLOBAL_HASH(bucket
, attrDecl
)
20794 case XML_SCHEMA_TYPE_GROUP
:
20795 if (WXS_REDEFINED_MODEL_GROUP_DEF(item
))
20797 name
= (WXS_MODEL_GROUPDEF_CAST item
)->name
;
20798 WXS_GET_GLOBAL_HASH(bucket
, groupDecl
)
20800 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP
:
20801 if (WXS_REDEFINED_ATTR_GROUP(item
))
20803 name
= (WXS_ATTR_GROUP_CAST item
)->name
;
20804 WXS_GET_GLOBAL_HASH(bucket
, attrgrpDecl
)
20806 case XML_SCHEMA_TYPE_IDC_KEY
:
20807 case XML_SCHEMA_TYPE_IDC_UNIQUE
:
20808 case XML_SCHEMA_TYPE_IDC_KEYREF
:
20809 name
= (WXS_IDC_CAST item
)->name
;
20810 WXS_GET_GLOBAL_HASH(bucket
, idcDef
)
20812 case XML_SCHEMA_TYPE_NOTATION
:
20813 name
= ((xmlSchemaNotationPtr
) item
)->name
;
20814 WXS_GET_GLOBAL_HASH(bucket
, notaDecl
)
20817 PERROR_INT("xmlSchemaAddComponents",
20818 "Unexpected global component type");
20821 if (*table
== NULL
) {
20822 *table
= xmlHashCreateDict(10, pctxt
->dict
);
20823 if (*table
== NULL
) {
20824 PERROR_INT("xmlSchemaAddComponents",
20825 "failed to create a component hash table");
20829 err
= xmlHashAddEntry(*table
, name
, item
);
20831 xmlChar
*str
= NULL
;
20833 xmlSchemaCustomErr(ACTXT_CAST pctxt
,
20834 XML_SCHEMAP_REDEFINED_TYPE
,
20835 WXS_ITEM_NODE(item
),
20836 WXS_BASIC_CAST item
,
20837 "A global %s '%s' does already exist",
20838 WXS_ITEM_TYPE_NAME(item
),
20839 xmlSchemaGetComponentQName(&str
, item
));
20840 FREE_AND_NULL(str
);
20844 * Process imported/included schemas.
20846 if (bucket
->relations
!= NULL
) {
20847 xmlSchemaSchemaRelationPtr rel
= bucket
->relations
;
20849 if ((rel
->bucket
!= NULL
) &&
20850 ((rel
->bucket
->flags
& XML_SCHEMA_BUCKET_COMPS_ADDED
) == 0)) {
20851 if (xmlSchemaAddComponents(pctxt
, rel
->bucket
) == -1)
20855 } while (rel
!= NULL
);
20861 xmlSchemaFixupComponents(xmlSchemaParserCtxtPtr pctxt
,
20862 xmlSchemaBucketPtr rootBucket
)
20864 xmlSchemaConstructionCtxtPtr con
= pctxt
->constructor
;
20865 xmlSchemaTreeItemPtr item
, *items
;
20866 int nbItems
, i
, ret
= 0;
20867 xmlSchemaBucketPtr oldbucket
= con
->bucket
;
20868 xmlSchemaElementPtr elemDecl
;
20870 #define FIXHFAILURE if (pctxt->err == XML_SCHEMAP_INTERNAL) goto exit_failure;
20872 if ((con
->pending
== NULL
) ||
20873 (con
->pending
->nbItems
== 0))
20877 * Since xmlSchemaFixupComplexType() will create new particles
20878 * (local components), and those particle components need a bucket
20879 * on the constructor, we'll assure here that the constructor has
20881 * TODO: Think about storing locals _only_ on the main bucket.
20883 if (con
->bucket
== NULL
)
20884 con
->bucket
= rootBucket
;
20887 * SPEC (src-redefine):
20888 * (6.2) "If it has no such self-reference, then all of the
20889 * following must be true:"
20891 * (6.2.2) The {model group} of the model group definition which
20892 * corresponds to it per XML Representation of Model Group
20893 * Definition Schema Components ($3.7.2) must be a `valid
20894 * restriction` of the {model group} of that model group definition
20895 * in I, as defined in Particle Valid (Restriction) ($3.9.6)."
20897 xmlSchemaCheckSRCRedefineFirst(pctxt
);
20900 * Add global components to the schemata's hash tables.
20902 xmlSchemaAddComponents(pctxt
, rootBucket
);
20904 pctxt
->ctxtType
= NULL
;
20905 items
= (xmlSchemaTreeItemPtr
*) con
->pending
->items
;
20906 nbItems
= con
->pending
->nbItems
;
20908 * Now that we have parsed *all* the schema document(s) and converted
20909 * them to schema components, we can resolve references, apply component
20910 * constraints, create the FSA from the content model, etc.
20913 * Resolve references of..
20915 * 1. element declarations:
20916 * - the type definition
20917 * - the substitution group affiliation
20918 * 2. simple/complex types:
20919 * - the base type definition
20920 * - the memberTypes of union types
20921 * - the itemType of list types
20922 * 3. attributes declarations and attribute uses:
20923 * - the type definition
20924 * - if an attribute use, then the attribute declaration
20925 * 4. attribute group references:
20926 * - the attribute group definition
20928 * - the term of the particle (e.g. a model group)
20929 * 6. IDC key-references:
20930 * - the referenced IDC 'key' or 'unique' definition
20931 * 7. Attribute prohibitions which had a "ref" attribute.
20933 for (i
= 0; i
< nbItems
; i
++) {
20935 switch (item
->type
) {
20936 case XML_SCHEMA_TYPE_ELEMENT
:
20937 xmlSchemaResolveElementReferences(
20938 (xmlSchemaElementPtr
) item
, pctxt
);
20941 case XML_SCHEMA_TYPE_COMPLEX
:
20942 case XML_SCHEMA_TYPE_SIMPLE
:
20943 xmlSchemaResolveTypeReferences(
20944 (xmlSchemaTypePtr
) item
, pctxt
);
20947 case XML_SCHEMA_TYPE_ATTRIBUTE
:
20948 xmlSchemaResolveAttrTypeReferences(
20949 (xmlSchemaAttributePtr
) item
, pctxt
);
20952 case XML_SCHEMA_TYPE_ATTRIBUTE_USE
:
20953 xmlSchemaResolveAttrUseReferences(
20954 (xmlSchemaAttributeUsePtr
) item
, pctxt
);
20957 case XML_SCHEMA_EXTRA_QNAMEREF
:
20958 if ((WXS_QNAME_CAST item
)->itemType
==
20959 XML_SCHEMA_TYPE_ATTRIBUTEGROUP
)
20961 xmlSchemaResolveAttrGroupReferences(
20962 WXS_QNAME_CAST item
, pctxt
);
20966 case XML_SCHEMA_TYPE_SEQUENCE
:
20967 case XML_SCHEMA_TYPE_CHOICE
:
20968 case XML_SCHEMA_TYPE_ALL
:
20969 xmlSchemaResolveModelGroupParticleReferences(pctxt
,
20970 WXS_MODEL_GROUP_CAST item
);
20973 case XML_SCHEMA_TYPE_IDC_KEY
:
20974 case XML_SCHEMA_TYPE_IDC_UNIQUE
:
20975 case XML_SCHEMA_TYPE_IDC_KEYREF
:
20976 xmlSchemaResolveIDCKeyReferences(
20977 (xmlSchemaIDCPtr
) item
, pctxt
);
20980 case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB
:
20982 * Handle attribue prohibition which had a
20985 xmlSchemaResolveAttrUseProhibReferences(
20986 WXS_ATTR_PROHIB_CAST item
, pctxt
);
20993 if (pctxt
->nberrors
!= 0)
20997 * Now that all references are resolved we
20998 * can check for circularity of...
20999 * 1. the base axis of type definitions
21000 * 2. nested model group definitions
21001 * 3. nested attribute group definitions
21002 * TODO: check for circual substitution groups.
21004 for (i
= 0; i
< nbItems
; i
++) {
21007 * Let's better stop on the first error here.
21009 switch (item
->type
) {
21010 case XML_SCHEMA_TYPE_COMPLEX
:
21011 case XML_SCHEMA_TYPE_SIMPLE
:
21012 xmlSchemaCheckTypeDefCircular(
21013 (xmlSchemaTypePtr
) item
, pctxt
);
21015 if (pctxt
->nberrors
!= 0)
21018 case XML_SCHEMA_TYPE_GROUP
:
21019 xmlSchemaCheckGroupDefCircular(
21020 (xmlSchemaModelGroupDefPtr
) item
, pctxt
);
21022 if (pctxt
->nberrors
!= 0)
21025 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP
:
21026 xmlSchemaCheckAttrGroupCircular(
21027 (xmlSchemaAttributeGroupPtr
) item
, pctxt
);
21029 if (pctxt
->nberrors
!= 0)
21036 if (pctxt
->nberrors
!= 0)
21039 * Model group definition references:
21040 * Such a reference is reflected by a particle at the component
21041 * level. Until now the 'term' of such particles pointed
21042 * to the model group definition; this was done, in order to
21043 * ease circularity checks. Now we need to set the 'term' of
21044 * such particles to the model group of the model group definition.
21046 for (i
= 0; i
< nbItems
; i
++) {
21048 switch (item
->type
) {
21049 case XML_SCHEMA_TYPE_SEQUENCE
:
21050 case XML_SCHEMA_TYPE_CHOICE
:
21051 xmlSchemaModelGroupToModelGroupDefFixup(pctxt
,
21052 WXS_MODEL_GROUP_CAST item
);
21058 if (pctxt
->nberrors
!= 0)
21061 * Expand attribute group references of attribute group definitions.
21063 for (i
= 0; i
< nbItems
; i
++) {
21065 switch (item
->type
) {
21066 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP
:
21067 if ((! WXS_ATTR_GROUP_EXPANDED(item
)) &&
21068 WXS_ATTR_GROUP_HAS_REFS(item
))
21070 xmlSchemaAttributeGroupExpandRefs(pctxt
,
21071 WXS_ATTR_GROUP_CAST item
);
21079 if (pctxt
->nberrors
!= 0)
21082 * First compute the variety of simple types. This is needed as
21083 * a seperate step, since otherwise we won't be able to detect
21084 * circular union types in all cases.
21086 for (i
= 0; i
< nbItems
; i
++) {
21088 switch (item
->type
) {
21089 case XML_SCHEMA_TYPE_SIMPLE
:
21090 if (WXS_IS_TYPE_NOT_FIXED_1((xmlSchemaTypePtr
) item
)) {
21091 xmlSchemaFixupSimpleTypeStageOne(pctxt
,
21092 (xmlSchemaTypePtr
) item
);
21100 if (pctxt
->nberrors
!= 0)
21103 * Detect circular union types. Note that this needs the variety to
21104 * be already computed.
21106 for (i
= 0; i
< nbItems
; i
++) {
21108 switch (item
->type
) {
21109 case XML_SCHEMA_TYPE_SIMPLE
:
21110 if (((xmlSchemaTypePtr
) item
)->memberTypes
!= NULL
) {
21111 xmlSchemaCheckUnionTypeDefCircular(pctxt
,
21112 (xmlSchemaTypePtr
) item
);
21120 if (pctxt
->nberrors
!= 0)
21124 * Do the complete type fixup for simple types.
21126 for (i
= 0; i
< nbItems
; i
++) {
21128 switch (item
->type
) {
21129 case XML_SCHEMA_TYPE_SIMPLE
:
21130 if (WXS_IS_TYPE_NOT_FIXED(WXS_TYPE_CAST item
)) {
21131 xmlSchemaFixupSimpleTypeStageTwo(pctxt
, WXS_TYPE_CAST item
);
21139 if (pctxt
->nberrors
!= 0)
21142 * At this point we need build and check all simple types.
21145 * Apply contraints for attribute declarations.
21147 for (i
= 0; i
< nbItems
; i
++) {
21149 switch (item
->type
) {
21150 case XML_SCHEMA_TYPE_ATTRIBUTE
:
21151 xmlSchemaCheckAttrPropsCorrect(pctxt
, WXS_ATTR_CAST item
);
21158 if (pctxt
->nberrors
!= 0)
21161 * Apply constraints for attribute uses.
21163 for (i
= 0; i
< nbItems
; i
++) {
21165 switch (item
->type
) {
21166 case XML_SCHEMA_TYPE_ATTRIBUTE_USE
:
21167 if (((xmlSchemaAttributeUsePtr
)item
)->defValue
!= NULL
) {
21168 xmlSchemaCheckAttrUsePropsCorrect(pctxt
,
21169 WXS_ATTR_USE_CAST item
);
21177 if (pctxt
->nberrors
!= 0)
21181 * Apply constraints for attribute group definitions.
21183 for (i
= 0; i
< nbItems
; i
++) {
21185 switch (item
->type
) {
21186 case XML_SCHEMA_TYPE_ATTRIBUTEGROUP
:
21187 if (( (WXS_ATTR_GROUP_CAST item
)->attrUses
!= NULL
) &&
21188 ( (WXS_LIST_CAST (WXS_ATTR_GROUP_CAST item
)->attrUses
)->nbItems
> 1))
21190 xmlSchemaCheckAGPropsCorrect(pctxt
, WXS_ATTR_GROUP_CAST item
);
21198 if (pctxt
->nberrors
!= 0)
21202 * Apply constraints for redefinitions.
21204 if (WXS_CONSTRUCTOR(pctxt
)->redefs
!= NULL
)
21205 xmlSchemaCheckSRCRedefineSecond(pctxt
);
21206 if (pctxt
->nberrors
!= 0)
21210 * Complex types are builded and checked.
21212 for (i
= 0; i
< nbItems
; i
++) {
21213 item
= con
->pending
->items
[i
];
21214 switch (item
->type
) {
21215 case XML_SCHEMA_TYPE_COMPLEX
:
21216 if (WXS_IS_TYPE_NOT_FIXED(WXS_TYPE_CAST item
)) {
21217 xmlSchemaFixupComplexType(pctxt
, WXS_TYPE_CAST item
);
21225 if (pctxt
->nberrors
!= 0)
21229 * The list could have changed, since xmlSchemaFixupComplexType()
21230 * will create particles and model groups in some cases.
21232 items
= (xmlSchemaTreeItemPtr
*) con
->pending
->items
;
21233 nbItems
= con
->pending
->nbItems
;
21236 * Apply some constraints for element declarations.
21238 for (i
= 0; i
< nbItems
; i
++) {
21240 switch (item
->type
) {
21241 case XML_SCHEMA_TYPE_ELEMENT
:
21242 elemDecl
= (xmlSchemaElementPtr
) item
;
21244 if ((elemDecl
->flags
& XML_SCHEMAS_ELEM_INTERNAL_CHECKED
) == 0)
21246 xmlSchemaCheckElementDeclComponent(
21247 (xmlSchemaElementPtr
) elemDecl
, pctxt
);
21251 #ifdef WXS_ELEM_DECL_CONS_ENABLED
21253 * Schema Component Constraint: Element Declarations Consistent
21254 * Apply this constraint to local types of element declarations.
21256 if ((WXS_ELEM_TYPEDEF(elemDecl
) != NULL
) &&
21257 (WXS_IS_COMPLEX(WXS_ELEM_TYPEDEF(elemDecl
))) &&
21258 (WXS_TYPE_IS_LOCAL(WXS_ELEM_TYPEDEF(elemDecl
))))
21260 xmlSchemaCheckElementDeclConsistent(pctxt
,
21261 WXS_BASIC_CAST elemDecl
,
21262 WXS_TYPE_PARTICLE(WXS_ELEM_TYPEDEF(elemDecl
)),
21271 if (pctxt
->nberrors
!= 0)
21275 * Finally we can build the automaton from the content model of
21279 for (i
= 0; i
< nbItems
; i
++) {
21281 switch (item
->type
) {
21282 case XML_SCHEMA_TYPE_COMPLEX
:
21283 xmlSchemaBuildContentModel((xmlSchemaTypePtr
) item
, pctxt
);
21290 if (pctxt
->nberrors
!= 0)
21293 * URGENT TODO: cos-element-consistent
21306 * Reset the constructor. This is needed for XSI acquisition, since
21307 * those items will be processed over and over again for every XSI
21308 * if not cleared here.
21310 con
->bucket
= oldbucket
;
21311 con
->pending
->nbItems
= 0;
21312 if (con
->substGroups
!= NULL
) {
21313 xmlHashFree(con
->substGroups
, xmlSchemaSubstGroupFreeEntry
);
21314 con
->substGroups
= NULL
;
21316 if (con
->redefs
!= NULL
) {
21317 xmlSchemaRedefListFree(con
->redefs
);
21318 con
->redefs
= NULL
;
21324 * @ctxt: a schema validation context
21326 * parse a schema definition resource and build an internal
21327 * XML Shema struture which can be used to validate instances.
21329 * Returns the internal XML Schema structure built from the resource or
21330 * NULL in case of error
21333 xmlSchemaParse(xmlSchemaParserCtxtPtr ctxt
)
21335 xmlSchemaPtr mainSchema
= NULL
;
21336 xmlSchemaBucketPtr bucket
= NULL
;
21340 * This one is used if the schema to be parsed was specified via
21341 * the API; i.e. not automatically by the validated instance document.
21344 xmlSchemaInitTypes();
21349 /* TODO: Init the context. Is this all we need?*/
21350 ctxt
->nberrors
= 0;
21354 /* Create the *main* schema. */
21355 mainSchema
= xmlSchemaNewSchema(ctxt
);
21356 if (mainSchema
== NULL
)
21359 * Create the schema constructor.
21361 if (ctxt
->constructor
== NULL
) {
21362 ctxt
->constructor
= xmlSchemaConstructionCtxtCreate(ctxt
->dict
);
21363 if (ctxt
->constructor
== NULL
)
21365 /* Take ownership of the constructor to be able to free it. */
21366 ctxt
->ownsConstructor
= 1;
21368 ctxt
->constructor
->mainSchema
= mainSchema
;
21370 * Locate and add the schema document.
21372 res
= xmlSchemaAddSchemaDoc(ctxt
, XML_SCHEMA_SCHEMA_MAIN
,
21373 ctxt
->URL
, ctxt
->doc
, ctxt
->buffer
, ctxt
->size
, NULL
,
21374 NULL
, NULL
, &bucket
);
21380 if (bucket
== NULL
) {
21381 /* TODO: Error code, actually we failed to *locate* the schema. */
21383 xmlSchemaCustomErr(ACTXT_CAST ctxt
, XML_SCHEMAP_FAILED_LOAD
,
21385 "Failed to locate the main schema resource at '%s'",
21388 xmlSchemaCustomErr(ACTXT_CAST ctxt
, XML_SCHEMAP_FAILED_LOAD
,
21390 "Failed to locate the main schema resource",
21394 /* Then do the parsing for good. */
21395 if (xmlSchemaParseNewDocWithContext(ctxt
, mainSchema
, bucket
) == -1)
21397 if (ctxt
->nberrors
!= 0)
21400 mainSchema
->doc
= bucket
->doc
;
21401 mainSchema
->preserve
= ctxt
->preserve
;
21403 ctxt
->schema
= mainSchema
;
21405 if (xmlSchemaFixupComponents(ctxt
, WXS_CONSTRUCTOR(ctxt
)->mainBucket
) == -1)
21409 * TODO: This is not nice, since we cannot distinguish from the
21410 * result if there was an internal error or not.
21413 if (ctxt
->nberrors
!= 0) {
21415 xmlSchemaFree(mainSchema
);
21418 if (ctxt
->constructor
) {
21419 xmlSchemaConstructionCtxtFree(ctxt
->constructor
);
21420 ctxt
->constructor
= NULL
;
21421 ctxt
->ownsConstructor
= 0;
21424 ctxt
->schema
= NULL
;
21425 return(mainSchema
);
21428 * Quite verbose, but should catch internal errors, which were
21429 * not communitated.
21432 xmlSchemaFree(mainSchema
);
21435 if (ctxt
->constructor
) {
21436 xmlSchemaConstructionCtxtFree(ctxt
->constructor
);
21437 ctxt
->constructor
= NULL
;
21438 ctxt
->ownsConstructor
= 0;
21440 PERROR_INT2("xmlSchemaParse",
21441 "An internal error occurred");
21442 ctxt
->schema
= NULL
;
21447 * xmlSchemaSetParserErrors:
21448 * @ctxt: a schema validation context
21449 * @err: the error callback
21450 * @warn: the warning callback
21451 * @ctx: contextual data for the callbacks
21453 * Set the callback functions used to handle errors for a validation context
21456 xmlSchemaSetParserErrors(xmlSchemaParserCtxtPtr ctxt
,
21457 xmlSchemaValidityErrorFunc err
,
21458 xmlSchemaValidityWarningFunc warn
, void *ctx
)
21463 ctxt
->warning
= warn
;
21464 ctxt
->errCtxt
= ctx
;
21465 if (ctxt
->vctxt
!= NULL
)
21466 xmlSchemaSetValidErrors(ctxt
->vctxt
, err
, warn
, ctx
);
21470 * xmlSchemaSetParserStructuredErrors:
21471 * @ctxt: a schema parser context
21472 * @serror: the structured error function
21473 * @ctx: the functions context
21475 * Set the structured error callback
21478 xmlSchemaSetParserStructuredErrors(xmlSchemaParserCtxtPtr ctxt
,
21479 xmlStructuredErrorFunc serror
,
21484 ctxt
->serror
= serror
;
21485 ctxt
->errCtxt
= ctx
;
21486 if (ctxt
->vctxt
!= NULL
)
21487 xmlSchemaSetValidStructuredErrors(ctxt
->vctxt
, serror
, ctx
);
21491 * xmlSchemaGetParserErrors:
21492 * @ctxt: a XMl-Schema parser context
21493 * @err: the error callback result
21494 * @warn: the warning callback result
21495 * @ctx: contextual data for the callbacks result
21497 * Get the callback information used to handle errors for a parser context
21499 * Returns -1 in case of failure, 0 otherwise
21502 xmlSchemaGetParserErrors(xmlSchemaParserCtxtPtr ctxt
,
21503 xmlSchemaValidityErrorFunc
* err
,
21504 xmlSchemaValidityWarningFunc
* warn
, void **ctx
)
21509 *err
= ctxt
->error
;
21511 *warn
= ctxt
->warning
;
21513 *ctx
= ctxt
->errCtxt
;
21518 * xmlSchemaFacetTypeToString:
21519 * @type: the facet type
21521 * Convert the xmlSchemaTypeType to a char string.
21523 * Returns the char string representation of the facet type if the
21524 * type is a facet and an "Internal Error" string otherwise.
21526 static const xmlChar
*
21527 xmlSchemaFacetTypeToString(xmlSchemaTypeType type
)
21530 case XML_SCHEMA_FACET_PATTERN
:
21531 return (BAD_CAST
"pattern");
21532 case XML_SCHEMA_FACET_MAXEXCLUSIVE
:
21533 return (BAD_CAST
"maxExclusive");
21534 case XML_SCHEMA_FACET_MAXINCLUSIVE
:
21535 return (BAD_CAST
"maxInclusive");
21536 case XML_SCHEMA_FACET_MINEXCLUSIVE
:
21537 return (BAD_CAST
"minExclusive");
21538 case XML_SCHEMA_FACET_MININCLUSIVE
:
21539 return (BAD_CAST
"minInclusive");
21540 case XML_SCHEMA_FACET_WHITESPACE
:
21541 return (BAD_CAST
"whiteSpace");
21542 case XML_SCHEMA_FACET_ENUMERATION
:
21543 return (BAD_CAST
"enumeration");
21544 case XML_SCHEMA_FACET_LENGTH
:
21545 return (BAD_CAST
"length");
21546 case XML_SCHEMA_FACET_MAXLENGTH
:
21547 return (BAD_CAST
"maxLength");
21548 case XML_SCHEMA_FACET_MINLENGTH
:
21549 return (BAD_CAST
"minLength");
21550 case XML_SCHEMA_FACET_TOTALDIGITS
:
21551 return (BAD_CAST
"totalDigits");
21552 case XML_SCHEMA_FACET_FRACTIONDIGITS
:
21553 return (BAD_CAST
"fractionDigits");
21557 return (BAD_CAST
"Internal Error");
21560 static xmlSchemaWhitespaceValueType
21561 xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type
)
21564 * The normalization type can be changed only for types which are derived
21567 if (type
->type
== XML_SCHEMA_TYPE_BASIC
) {
21569 * Note that we assume a whitespace of preserve for anySimpleType.
21571 if ((type
->builtInType
== XML_SCHEMAS_STRING
) ||
21572 (type
->builtInType
== XML_SCHEMAS_ANYSIMPLETYPE
))
21573 return(XML_SCHEMA_WHITESPACE_PRESERVE
);
21574 else if (type
->builtInType
== XML_SCHEMAS_NORMSTRING
)
21575 return(XML_SCHEMA_WHITESPACE_REPLACE
);
21578 * For all `atomic` datatypes other than string (and types `derived`
21579 * by `restriction` from it) the value of whiteSpace is fixed to
21581 * Note that this includes built-in list datatypes.
21583 return(XML_SCHEMA_WHITESPACE_COLLAPSE
);
21585 } else if (WXS_IS_LIST(type
)) {
21587 * For list types the facet "whiteSpace" is fixed to "collapse".
21589 return (XML_SCHEMA_WHITESPACE_COLLAPSE
);
21590 } else if (WXS_IS_UNION(type
)) {
21591 return (XML_SCHEMA_WHITESPACE_UNKNOWN
);
21592 } else if (WXS_IS_ATOMIC(type
)) {
21593 if (type
->flags
& XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE
)
21594 return (XML_SCHEMA_WHITESPACE_PRESERVE
);
21595 else if (type
->flags
& XML_SCHEMAS_TYPE_WHITESPACE_REPLACE
)
21596 return (XML_SCHEMA_WHITESPACE_REPLACE
);
21598 return (XML_SCHEMA_WHITESPACE_COLLAPSE
);
21603 /************************************************************************
21605 * Simple type validation *
21607 ************************************************************************/
21610 /************************************************************************
21612 * DOM Validation code *
21614 ************************************************************************/
21617 * xmlSchemaAssembleByLocation:
21618 * @pctxt: a schema parser context
21619 * @vctxt: a schema validation context
21620 * @schema: the existing schema
21621 * @node: the node that fired the assembling
21622 * @nsName: the namespace name of the new schema
21623 * @location: the location of the schema
21625 * Expands an existing schema by an additional schema.
21627 * Returns 0 if the new schema is correct, a positive error code
21628 * number otherwise and -1 in case of an internal or API error.
21631 xmlSchemaAssembleByLocation(xmlSchemaValidCtxtPtr vctxt
,
21632 xmlSchemaPtr schema
,
21634 const xmlChar
*nsName
,
21635 const xmlChar
*location
)
21638 xmlSchemaParserCtxtPtr pctxt
;
21639 xmlSchemaBucketPtr bucket
= NULL
;
21641 if ((vctxt
== NULL
) || (schema
== NULL
))
21644 if (vctxt
->pctxt
== NULL
) {
21645 VERROR_INT("xmlSchemaAssembleByLocation",
21646 "no parser context available");
21649 pctxt
= vctxt
->pctxt
;
21650 if (pctxt
->constructor
== NULL
) {
21651 PERROR_INT("xmlSchemaAssembleByLocation",
21656 * Acquire the schema document.
21658 location
= xmlSchemaBuildAbsoluteURI(pctxt
->dict
,
21661 * Note that we pass XML_SCHEMA_SCHEMA_IMPORT here;
21662 * the process will automatically change this to
21663 * XML_SCHEMA_SCHEMA_MAIN if it is the first schema document.
21665 ret
= xmlSchemaAddSchemaDoc(pctxt
, XML_SCHEMA_SCHEMA_IMPORT
,
21666 location
, NULL
, NULL
, 0, node
, NULL
, nsName
,
21670 if (bucket
== NULL
) {
21672 * Generate a warning that the document could not be located.
21674 xmlSchemaCustomWarning(ACTXT_CAST vctxt
, XML_SCHEMAV_MISC
,
21676 "The document at location '%s' could not be acquired",
21677 location
, NULL
, NULL
);
21681 * The first located schema will be handled as if all other
21682 * schemas imported by XSI were imported by this first schema.
21684 if ((bucket
!= NULL
) &&
21685 (WXS_CONSTRUCTOR(pctxt
)->bucket
== NULL
))
21686 WXS_CONSTRUCTOR(pctxt
)->bucket
= bucket
;
21688 * TODO: Is this handled like an import? I.e. is it not an error
21689 * if the schema cannot be located?
21691 if ((bucket
== NULL
) || (! CAN_PARSE_SCHEMA(bucket
)))
21694 * We will reuse the parser context for every schema imported
21695 * directly via XSI. So reset the context.
21697 pctxt
->nberrors
= 0;
21699 pctxt
->doc
= bucket
->doc
;
21701 ret
= xmlSchemaParseNewDocWithContext(pctxt
, schema
, bucket
);
21706 /* Paranoid error channelling. */
21707 if ((ret
== 0) && (pctxt
->nberrors
!= 0))
21709 if (pctxt
->nberrors
== 0) {
21711 * Only bother to fixup pending components, if there was
21713 * For every XSI acquired schema (and its sub-schemata) we will
21714 * fixup the components.
21716 xmlSchemaFixupComponents(pctxt
, bucket
);
21719 * Not nice, but we need somehow to channel the schema parser
21720 * error to the validation context.
21722 if ((ret
!= 0) && (vctxt
->err
== 0))
21724 vctxt
->nberrors
+= pctxt
->nberrors
;
21726 /* Add to validation error sum. */
21727 vctxt
->nberrors
+= pctxt
->nberrors
;
21736 static xmlSchemaAttrInfoPtr
21737 xmlSchemaGetMetaAttrInfo(xmlSchemaValidCtxtPtr vctxt
,
21740 if (vctxt
->nbAttrInfos
== 0)
21744 xmlSchemaAttrInfoPtr iattr
;
21746 for (i
= 0; i
< vctxt
->nbAttrInfos
; i
++) {
21747 iattr
= vctxt
->attrInfos
[i
];
21748 if (iattr
->metaType
== metaType
)
21757 * xmlSchemaAssembleByXSI:
21758 * @vctxt: a schema validation context
21760 * Expands an existing schema by an additional schema using
21761 * the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attribute
21762 * of an instance. If xsi:noNamespaceSchemaLocation is used, @noNamespace
21763 * must be set to 1.
21765 * Returns 0 if the new schema is correct, a positive error code
21766 * number otherwise and -1 in case of an internal or API error.
21769 xmlSchemaAssembleByXSI(xmlSchemaValidCtxtPtr vctxt
)
21771 const xmlChar
*cur
, *end
;
21772 const xmlChar
*nsname
= NULL
, *location
;
21775 xmlSchemaAttrInfoPtr iattr
;
21778 * Parse the value; we will assume an even number of values
21779 * to be given (this is how Xerces and XSV work).
21781 * URGENT TODO: !! This needs to work for both
21782 * @noNamespaceSchemaLocation AND @schemaLocation on the same
21785 iattr
= xmlSchemaGetMetaAttrInfo(vctxt
,
21786 XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC
);
21788 iattr
= xmlSchemaGetMetaAttrInfo(vctxt
,
21789 XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC
);
21792 cur
= iattr
->value
;
21795 * TODO: Move the string parsing mechanism away from here.
21797 if (iattr
->metaType
== XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC
) {
21799 * Get the namespace name.
21801 while (IS_BLANK_CH(*cur
))
21804 while ((*end
!= 0) && (!(IS_BLANK_CH(*end
))))
21808 count
++; /* TODO: Don't use the schema's dict. */
21809 nsname
= xmlDictLookup(vctxt
->schema
->dict
, cur
, end
- cur
);
21815 while (IS_BLANK_CH(*cur
))
21818 while ((*end
!= 0) && (!(IS_BLANK_CH(*end
))))
21821 if (iattr
->metaType
==
21822 XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC
)
21825 * If using @schemaLocation then tuples are expected.
21826 * I.e. the namespace name *and* the document's URI.
21828 xmlSchemaCustomWarning(ACTXT_CAST vctxt
, XML_SCHEMAV_MISC
,
21830 "The value must consist of tuples: the target namespace "
21831 "name and the document's URI", NULL
, NULL
, NULL
);
21835 count
++; /* TODO: Don't use the schema's dict. */
21836 location
= xmlDictLookup(vctxt
->schema
->dict
, cur
, end
- cur
);
21838 ret
= xmlSchemaAssembleByLocation(vctxt
, vctxt
->schema
,
21839 iattr
->node
, nsname
, location
);
21841 VERROR_INT("xmlSchemaAssembleByXSI",
21842 "assembling schemata");
21845 } while (*cur
!= 0);
21849 static const xmlChar
*
21850 xmlSchemaLookupNamespace(xmlSchemaValidCtxtPtr vctxt
,
21851 const xmlChar
*prefix
)
21853 if (vctxt
->sax
!= NULL
) {
21855 xmlSchemaNodeInfoPtr inode
;
21857 for (i
= vctxt
->depth
; i
>= 0; i
--) {
21858 if (vctxt
->elemInfos
[i
]->nbNsBindings
!= 0) {
21859 inode
= vctxt
->elemInfos
[i
];
21860 for (j
= 0; j
< inode
->nbNsBindings
* 2; j
+= 2) {
21861 if (((prefix
== NULL
) &&
21862 (inode
->nsBindings
[j
] == NULL
)) ||
21863 ((prefix
!= NULL
) && xmlStrEqual(prefix
,
21864 inode
->nsBindings
[j
]))) {
21867 * Note that the namespace bindings are already
21868 * in a string dict.
21870 return (inode
->nsBindings
[j
+1]);
21876 #ifdef LIBXML_READER_ENABLED
21877 } else if (vctxt
->reader
!= NULL
) {
21880 nsName
= xmlTextReaderLookupNamespace(vctxt
->reader
, prefix
);
21881 if (nsName
!= NULL
) {
21882 const xmlChar
*ret
;
21884 ret
= xmlDictLookup(vctxt
->dict
, nsName
, -1);
21893 if ((vctxt
->inode
->node
== NULL
) ||
21894 (vctxt
->inode
->node
->doc
== NULL
)) {
21895 VERROR_INT("xmlSchemaLookupNamespace",
21896 "no node or node's doc avaliable");
21899 ns
= xmlSearchNs(vctxt
->inode
->node
->doc
,
21900 vctxt
->inode
->node
, prefix
);
21908 * This one works on the schema of the validation context.
21911 xmlSchemaValidateNotation(xmlSchemaValidCtxtPtr vctxt
,
21912 xmlSchemaPtr schema
,
21914 const xmlChar
*value
,
21915 xmlSchemaValPtr
*val
,
21920 if (vctxt
&& (vctxt
->schema
== NULL
)) {
21921 VERROR_INT("xmlSchemaValidateNotation",
21922 "a schema is needed on the validation context");
21925 ret
= xmlValidateQName(value
, 1);
21929 xmlChar
*localName
= NULL
;
21930 xmlChar
*prefix
= NULL
;
21932 localName
= xmlSplitQName2(value
, &prefix
);
21933 if (prefix
!= NULL
) {
21934 const xmlChar
*nsName
= NULL
;
21937 nsName
= xmlSchemaLookupNamespace(vctxt
, BAD_CAST prefix
);
21938 else if (node
!= NULL
) {
21939 xmlNsPtr ns
= xmlSearchNs(node
->doc
, node
, prefix
);
21944 xmlFree(localName
);
21947 if (nsName
== NULL
) {
21949 xmlFree(localName
);
21952 if (xmlSchemaGetNotation(schema
, localName
, nsName
) != NULL
) {
21953 if ((valNeeded
) && (val
!= NULL
)) {
21954 (*val
) = xmlSchemaNewNOTATIONValue(xmlStrdup(localName
),
21955 xmlStrdup(nsName
));
21962 xmlFree(localName
);
21964 if (xmlSchemaGetNotation(schema
, value
, NULL
) != NULL
) {
21965 if (valNeeded
&& (val
!= NULL
)) {
21966 (*val
) = xmlSchemaNewNOTATIONValue(
21967 BAD_CAST
xmlStrdup(value
), NULL
);
21979 xmlSchemaVAddNodeQName(xmlSchemaValidCtxtPtr vctxt
,
21980 const xmlChar
* lname
,
21981 const xmlChar
* nsname
)
21985 lname
= xmlDictLookup(vctxt
->dict
, lname
, -1);
21988 if (nsname
!= NULL
) {
21989 nsname
= xmlDictLookup(vctxt
->dict
, nsname
, -1);
21990 if (nsname
== NULL
)
21993 for (i
= 0; i
< vctxt
->nodeQNames
->nbItems
; i
+= 2) {
21994 if ((vctxt
->nodeQNames
->items
[i
] == lname
) &&
21995 (vctxt
->nodeQNames
->items
[i
+1] == nsname
))
21996 /* Already there */
21999 /* Add new entry. */
22000 i
= vctxt
->nodeQNames
->nbItems
;
22001 xmlSchemaItemListAdd(vctxt
->nodeQNames
, (void *) lname
);
22002 xmlSchemaItemListAdd(vctxt
->nodeQNames
, (void *) nsname
);
22006 /************************************************************************
22008 * Validation of identity-constraints (IDC) *
22010 ************************************************************************/
22013 * xmlSchemaAugmentIDC:
22014 * @idcDef: the IDC definition
22016 * Creates an augmented IDC definition item.
22018 * Returns the item, or NULL on internal errors.
22021 xmlSchemaAugmentIDC(void *payload
, void *data
,
22022 const xmlChar
*name ATTRIBUTE_UNUSED
)
22024 xmlSchemaIDCPtr idcDef
= (xmlSchemaIDCPtr
) payload
;
22025 xmlSchemaValidCtxtPtr vctxt
= (xmlSchemaValidCtxtPtr
) data
;
22026 xmlSchemaIDCAugPtr aidc
;
22028 aidc
= (xmlSchemaIDCAugPtr
) xmlMalloc(sizeof(xmlSchemaIDCAug
));
22029 if (aidc
== NULL
) {
22030 xmlSchemaVErrMemory(vctxt
,
22031 "xmlSchemaAugmentIDC: allocating an augmented IDC definition",
22035 aidc
->keyrefDepth
= -1;
22036 aidc
->def
= idcDef
;
22038 if (vctxt
->aidcs
== NULL
)
22039 vctxt
->aidcs
= aidc
;
22041 aidc
->next
= vctxt
->aidcs
;
22042 vctxt
->aidcs
= aidc
;
22045 * Save if we have keyrefs at all.
22047 if ((vctxt
->hasKeyrefs
== 0) &&
22048 (idcDef
->type
== XML_SCHEMA_TYPE_IDC_KEYREF
))
22049 vctxt
->hasKeyrefs
= 1;
22053 * xmlSchemaAugmentImportedIDC:
22054 * @imported: the imported schema
22056 * Creates an augmented IDC definition for the imported schema.
22059 xmlSchemaAugmentImportedIDC(void *payload
, void *data
,
22060 const xmlChar
*name ATTRIBUTE_UNUSED
) {
22061 xmlSchemaImportPtr imported
= (xmlSchemaImportPtr
) payload
;
22062 xmlSchemaValidCtxtPtr vctxt
= (xmlSchemaValidCtxtPtr
) data
;
22063 if (imported
->schema
->idcDef
!= NULL
) {
22064 xmlHashScan(imported
->schema
->idcDef
, xmlSchemaAugmentIDC
, vctxt
);
22069 * xmlSchemaIDCNewBinding:
22070 * @idcDef: the IDC definition of this binding
22072 * Creates a new IDC binding.
22074 * Returns the new IDC binding, NULL on internal errors.
22076 static xmlSchemaPSVIIDCBindingPtr
22077 xmlSchemaIDCNewBinding(xmlSchemaIDCPtr idcDef
)
22079 xmlSchemaPSVIIDCBindingPtr ret
;
22081 ret
= (xmlSchemaPSVIIDCBindingPtr
) xmlMalloc(
22082 sizeof(xmlSchemaPSVIIDCBinding
));
22084 xmlSchemaVErrMemory(NULL
,
22085 "allocating a PSVI IDC binding item", NULL
);
22088 memset(ret
, 0, sizeof(xmlSchemaPSVIIDCBinding
));
22089 ret
->definition
= idcDef
;
22094 * xmlSchemaIDCStoreNodeTableItem:
22095 * @vctxt: the WXS validation context
22096 * @item: the IDC node table item
22098 * The validation context is used to store IDC node table items.
22099 * They are stored to avoid copying them if IDC node-tables are merged
22100 * with corresponding parent IDC node-tables (bubbling).
22102 * Returns 0 if succeeded, -1 on internal errors.
22105 xmlSchemaIDCStoreNodeTableItem(xmlSchemaValidCtxtPtr vctxt
,
22106 xmlSchemaPSVIIDCNodePtr item
)
22109 * Add to gobal list.
22111 if (vctxt
->idcNodes
== NULL
) {
22112 vctxt
->idcNodes
= (xmlSchemaPSVIIDCNodePtr
*)
22113 xmlMalloc(20 * sizeof(xmlSchemaPSVIIDCNodePtr
));
22114 if (vctxt
->idcNodes
== NULL
) {
22115 xmlSchemaVErrMemory(vctxt
,
22116 "allocating the IDC node table item list", NULL
);
22119 vctxt
->sizeIdcNodes
= 20;
22120 } else if (vctxt
->sizeIdcNodes
<= vctxt
->nbIdcNodes
) {
22121 vctxt
->sizeIdcNodes
*= 2;
22122 vctxt
->idcNodes
= (xmlSchemaPSVIIDCNodePtr
*)
22123 xmlRealloc(vctxt
->idcNodes
, vctxt
->sizeIdcNodes
*
22124 sizeof(xmlSchemaPSVIIDCNodePtr
));
22125 if (vctxt
->idcNodes
== NULL
) {
22126 xmlSchemaVErrMemory(vctxt
,
22127 "re-allocating the IDC node table item list", NULL
);
22131 vctxt
->idcNodes
[vctxt
->nbIdcNodes
++] = item
;
22137 * xmlSchemaIDCStoreKey:
22138 * @vctxt: the WXS validation context
22139 * @item: the IDC key
22141 * The validation context is used to store an IDC key.
22143 * Returns 0 if succeeded, -1 on internal errors.
22146 xmlSchemaIDCStoreKey(xmlSchemaValidCtxtPtr vctxt
,
22147 xmlSchemaPSVIIDCKeyPtr key
)
22150 * Add to gobal list.
22152 if (vctxt
->idcKeys
== NULL
) {
22153 vctxt
->idcKeys
= (xmlSchemaPSVIIDCKeyPtr
*)
22154 xmlMalloc(40 * sizeof(xmlSchemaPSVIIDCKeyPtr
));
22155 if (vctxt
->idcKeys
== NULL
) {
22156 xmlSchemaVErrMemory(vctxt
,
22157 "allocating the IDC key storage list", NULL
);
22160 vctxt
->sizeIdcKeys
= 40;
22161 } else if (vctxt
->sizeIdcKeys
<= vctxt
->nbIdcKeys
) {
22162 vctxt
->sizeIdcKeys
*= 2;
22163 vctxt
->idcKeys
= (xmlSchemaPSVIIDCKeyPtr
*)
22164 xmlRealloc(vctxt
->idcKeys
, vctxt
->sizeIdcKeys
*
22165 sizeof(xmlSchemaPSVIIDCKeyPtr
));
22166 if (vctxt
->idcKeys
== NULL
) {
22167 xmlSchemaVErrMemory(vctxt
,
22168 "re-allocating the IDC key storage list", NULL
);
22172 vctxt
->idcKeys
[vctxt
->nbIdcKeys
++] = key
;
22178 * xmlSchemaIDCAppendNodeTableItem:
22179 * @bind: the IDC binding
22180 * @ntItem: the node-table item
22182 * Appends the IDC node-table item to the binding.
22184 * Returns 0 on success and -1 on internal errors.
22187 xmlSchemaIDCAppendNodeTableItem(xmlSchemaPSVIIDCBindingPtr bind
,
22188 xmlSchemaPSVIIDCNodePtr ntItem
)
22190 if (bind
->nodeTable
== NULL
) {
22191 bind
->sizeNodes
= 10;
22192 bind
->nodeTable
= (xmlSchemaPSVIIDCNodePtr
*)
22193 xmlMalloc(10 * sizeof(xmlSchemaPSVIIDCNodePtr
));
22194 if (bind
->nodeTable
== NULL
) {
22195 xmlSchemaVErrMemory(NULL
,
22196 "allocating an array of IDC node-table items", NULL
);
22199 } else if (bind
->sizeNodes
<= bind
->nbNodes
) {
22200 bind
->sizeNodes
*= 2;
22201 bind
->nodeTable
= (xmlSchemaPSVIIDCNodePtr
*)
22202 xmlRealloc(bind
->nodeTable
, bind
->sizeNodes
*
22203 sizeof(xmlSchemaPSVIIDCNodePtr
));
22204 if (bind
->nodeTable
== NULL
) {
22205 xmlSchemaVErrMemory(NULL
,
22206 "re-allocating an array of IDC node-table items", NULL
);
22210 bind
->nodeTable
[bind
->nbNodes
++] = ntItem
;
22215 * xmlSchemaIDCAcquireBinding:
22216 * @vctxt: the WXS validation context
22217 * @matcher: the IDC matcher
22219 * Looks up an PSVI IDC binding, for the IDC definition and
22220 * of the given matcher. If none found, a new one is created
22221 * and added to the IDC table.
22223 * Returns an IDC binding or NULL on internal errors.
22225 static xmlSchemaPSVIIDCBindingPtr
22226 xmlSchemaIDCAcquireBinding(xmlSchemaValidCtxtPtr vctxt
,
22227 xmlSchemaIDCMatcherPtr matcher
)
22229 xmlSchemaNodeInfoPtr ielem
;
22231 ielem
= vctxt
->elemInfos
[matcher
->depth
];
22233 if (ielem
->idcTable
== NULL
) {
22234 ielem
->idcTable
= xmlSchemaIDCNewBinding(matcher
->aidc
->def
);
22235 if (ielem
->idcTable
== NULL
)
22237 return(ielem
->idcTable
);
22239 xmlSchemaPSVIIDCBindingPtr bind
= NULL
;
22241 bind
= ielem
->idcTable
;
22243 if (bind
->definition
== matcher
->aidc
->def
)
22245 if (bind
->next
== NULL
) {
22246 bind
->next
= xmlSchemaIDCNewBinding(matcher
->aidc
->def
);
22247 if (bind
->next
== NULL
)
22249 return(bind
->next
);
22252 } while (bind
!= NULL
);
22257 static xmlSchemaItemListPtr
22258 xmlSchemaIDCAcquireTargetList(xmlSchemaValidCtxtPtr vctxt ATTRIBUTE_UNUSED
,
22259 xmlSchemaIDCMatcherPtr matcher
)
22261 if (matcher
->targets
== NULL
)
22262 matcher
->targets
= xmlSchemaItemListCreate();
22263 return(matcher
->targets
);
22267 * xmlSchemaIDCFreeKey:
22268 * @key: the IDC key
22270 * Frees an IDC key together with its compiled value.
22273 xmlSchemaIDCFreeKey(xmlSchemaPSVIIDCKeyPtr key
)
22275 if (key
->val
!= NULL
)
22276 xmlSchemaFreeValue(key
->val
);
22281 * xmlSchemaIDCFreeBinding:
22283 * Frees an IDC binding. Note that the node table-items
22287 xmlSchemaIDCFreeBinding(xmlSchemaPSVIIDCBindingPtr bind
)
22289 if (bind
->nodeTable
!= NULL
)
22290 xmlFree(bind
->nodeTable
);
22291 if (bind
->dupls
!= NULL
)
22292 xmlSchemaItemListFree(bind
->dupls
);
22297 * xmlSchemaIDCFreeIDCTable:
22298 * @bind: the first IDC binding in the list
22300 * Frees an IDC table, i.e. all the IDC bindings in the list.
22303 xmlSchemaIDCFreeIDCTable(xmlSchemaPSVIIDCBindingPtr bind
)
22305 xmlSchemaPSVIIDCBindingPtr prev
;
22307 while (bind
!= NULL
) {
22310 xmlSchemaIDCFreeBinding(prev
);
22315 * xmlSchemaIDCFreeMatcherList:
22316 * @matcher: the first IDC matcher in the list
22318 * Frees a list of IDC matchers.
22321 xmlSchemaIDCFreeMatcherList(xmlSchemaIDCMatcherPtr matcher
)
22323 xmlSchemaIDCMatcherPtr next
;
22325 while (matcher
!= NULL
) {
22326 next
= matcher
->next
;
22327 if (matcher
->keySeqs
!= NULL
) {
22329 for (i
= 0; i
< matcher
->sizeKeySeqs
; i
++)
22330 if (matcher
->keySeqs
[i
] != NULL
)
22331 xmlFree(matcher
->keySeqs
[i
]);
22332 xmlFree(matcher
->keySeqs
);
22334 if (matcher
->targets
!= NULL
) {
22335 if (matcher
->idcType
== XML_SCHEMA_TYPE_IDC_KEYREF
) {
22337 xmlSchemaPSVIIDCNodePtr idcNode
;
22339 * Node-table items for keyrefs are not stored globally
22340 * to the validation context, since they are not bubbled.
22341 * We need to free them here.
22343 for (i
= 0; i
< matcher
->targets
->nbItems
; i
++) {
22345 (xmlSchemaPSVIIDCNodePtr
) matcher
->targets
->items
[i
];
22346 xmlFree(idcNode
->keys
);
22350 xmlSchemaItemListFree(matcher
->targets
);
22358 * xmlSchemaIDCReleaseMatcherList:
22359 * @vctxt: the WXS validation context
22360 * @matcher: the first IDC matcher in the list
22362 * Caches a list of IDC matchers for reuse.
22365 xmlSchemaIDCReleaseMatcherList(xmlSchemaValidCtxtPtr vctxt
,
22366 xmlSchemaIDCMatcherPtr matcher
)
22368 xmlSchemaIDCMatcherPtr next
;
22370 while (matcher
!= NULL
) {
22371 next
= matcher
->next
;
22372 if (matcher
->keySeqs
!= NULL
) {
22375 * Don't free the array, but only the content.
22377 for (i
= 0; i
< matcher
->sizeKeySeqs
; i
++)
22378 if (matcher
->keySeqs
[i
] != NULL
) {
22379 xmlFree(matcher
->keySeqs
[i
]);
22380 matcher
->keySeqs
[i
] = NULL
;
22383 if (matcher
->targets
) {
22384 if (matcher
->idcType
== XML_SCHEMA_TYPE_IDC_KEYREF
) {
22386 xmlSchemaPSVIIDCNodePtr idcNode
;
22388 * Node-table items for keyrefs are not stored globally
22389 * to the validation context, since they are not bubbled.
22390 * We need to free them here.
22392 for (i
= 0; i
< matcher
->targets
->nbItems
; i
++) {
22394 (xmlSchemaPSVIIDCNodePtr
) matcher
->targets
->items
[i
];
22395 xmlFree(idcNode
->keys
);
22399 xmlSchemaItemListFree(matcher
->targets
);
22400 matcher
->targets
= NULL
;
22402 matcher
->next
= NULL
;
22404 * Cache the matcher.
22406 if (vctxt
->idcMatcherCache
!= NULL
)
22407 matcher
->nextCached
= vctxt
->idcMatcherCache
;
22408 vctxt
->idcMatcherCache
= matcher
;
22415 * xmlSchemaIDCAddStateObject:
22416 * @vctxt: the WXS validation context
22417 * @matcher: the IDC matcher
22418 * @sel: the XPath information
22419 * @parent: the parent "selector" state object if any
22420 * @type: "selector" or "field"
22422 * Creates/reuses and activates state objects for the given
22423 * XPath information; if the XPath expression consists of unions,
22424 * multiple state objects are created for every unioned expression.
22426 * Returns 0 on success and -1 on internal errors.
22429 xmlSchemaIDCAddStateObject(xmlSchemaValidCtxtPtr vctxt
,
22430 xmlSchemaIDCMatcherPtr matcher
,
22431 xmlSchemaIDCSelectPtr sel
,
22434 xmlSchemaIDCStateObjPtr sto
;
22437 * Reuse the state objects from the pool.
22439 if (vctxt
->xpathStatePool
!= NULL
) {
22440 sto
= vctxt
->xpathStatePool
;
22441 vctxt
->xpathStatePool
= sto
->next
;
22445 * Create a new state object.
22447 sto
= (xmlSchemaIDCStateObjPtr
) xmlMalloc(sizeof(xmlSchemaIDCStateObj
));
22449 xmlSchemaVErrMemory(NULL
,
22450 "allocating an IDC state object", NULL
);
22453 memset(sto
, 0, sizeof(xmlSchemaIDCStateObj
));
22456 * Add to global list.
22458 if (vctxt
->xpathStates
!= NULL
)
22459 sto
->next
= vctxt
->xpathStates
;
22460 vctxt
->xpathStates
= sto
;
22463 * Free the old xpath validation context.
22465 if (sto
->xpathCtxt
!= NULL
)
22466 xmlFreeStreamCtxt((xmlStreamCtxtPtr
) sto
->xpathCtxt
);
22469 * Create a new XPath (pattern) validation context.
22471 sto
->xpathCtxt
= (void *) xmlPatternGetStreamCtxt(
22472 (xmlPatternPtr
) sel
->xpathComp
);
22473 if (sto
->xpathCtxt
== NULL
) {
22474 VERROR_INT("xmlSchemaIDCAddStateObject",
22475 "failed to create an XPath validation context");
22479 sto
->depth
= vctxt
->depth
;
22480 sto
->matcher
= matcher
;
22482 sto
->nbHistory
= 0;
22485 xmlGenericError(xmlGenericErrorContext
, "IDC: STO push '%s'\n",
22492 * xmlSchemaXPathEvaluate:
22493 * @vctxt: the WXS validation context
22494 * @nodeType: the nodeType of the current node
22496 * Evaluates all active XPath state objects.
22498 * Returns the number of IC "field" state objects which resolved to
22499 * this node, 0 if none resolved and -1 on internal errors.
22502 xmlSchemaXPathEvaluate(xmlSchemaValidCtxtPtr vctxt
,
22503 xmlElementType nodeType
)
22505 xmlSchemaIDCStateObjPtr sto
, head
= NULL
, first
;
22506 int res
, resolved
= 0, depth
= vctxt
->depth
;
22508 if (vctxt
->xpathStates
== NULL
)
22511 if (nodeType
== XML_ATTRIBUTE_NODE
)
22515 xmlChar
*str
= NULL
;
22516 xmlGenericError(xmlGenericErrorContext
,
22517 "IDC: EVAL on %s, depth %d, type %d\n",
22518 xmlSchemaFormatQName(&str
, vctxt
->inode
->nsName
,
22519 vctxt
->inode
->localName
), depth
, nodeType
);
22524 * Process all active XPath state objects.
22526 first
= vctxt
->xpathStates
;
22528 while (sto
!= head
) {
22530 if (sto
->type
== XPATH_STATE_OBJ_TYPE_IDC_SELECTOR
)
22531 xmlGenericError(xmlGenericErrorContext
, "IDC: ['%s'] selector '%s'\n",
22532 sto
->matcher
->aidc
->def
->name
, sto
->sel
->xpath
);
22534 xmlGenericError(xmlGenericErrorContext
, "IDC: ['%s'] field '%s'\n",
22535 sto
->matcher
->aidc
->def
->name
, sto
->sel
->xpath
);
22537 if (nodeType
== XML_ELEMENT_NODE
)
22538 res
= xmlStreamPush((xmlStreamCtxtPtr
) sto
->xpathCtxt
,
22539 vctxt
->inode
->localName
, vctxt
->inode
->nsName
);
22541 res
= xmlStreamPushAttr((xmlStreamCtxtPtr
) sto
->xpathCtxt
,
22542 vctxt
->inode
->localName
, vctxt
->inode
->nsName
);
22545 VERROR_INT("xmlSchemaXPathEvaluate",
22546 "calling xmlStreamPush()");
22555 xmlGenericError(xmlGenericErrorContext
, "IDC: "
22559 * Register a match in the state object history.
22561 if (sto
->history
== NULL
) {
22562 sto
->history
= (int *) xmlMalloc(5 * sizeof(int));
22563 if (sto
->history
== NULL
) {
22564 xmlSchemaVErrMemory(NULL
,
22565 "allocating the state object history", NULL
);
22568 sto
->sizeHistory
= 5;
22569 } else if (sto
->sizeHistory
<= sto
->nbHistory
) {
22570 sto
->sizeHistory
*= 2;
22571 sto
->history
= (int *) xmlRealloc(sto
->history
,
22572 sto
->sizeHistory
* sizeof(int));
22573 if (sto
->history
== NULL
) {
22574 xmlSchemaVErrMemory(NULL
,
22575 "re-allocating the state object history", NULL
);
22579 sto
->history
[sto
->nbHistory
++] = depth
;
22582 xmlGenericError(xmlGenericErrorContext
, "IDC: push match '%d'\n",
22586 if (sto
->type
== XPATH_STATE_OBJ_TYPE_IDC_SELECTOR
) {
22587 xmlSchemaIDCSelectPtr sel
;
22589 * Activate state objects for the IDC fields of
22590 * the IDC selector.
22593 xmlGenericError(xmlGenericErrorContext
, "IDC: "
22594 "activating field states\n");
22596 sel
= sto
->matcher
->aidc
->def
->fields
;
22597 while (sel
!= NULL
) {
22598 if (xmlSchemaIDCAddStateObject(vctxt
, sto
->matcher
,
22599 sel
, XPATH_STATE_OBJ_TYPE_IDC_FIELD
) == -1)
22603 } else if (sto
->type
== XPATH_STATE_OBJ_TYPE_IDC_FIELD
) {
22605 * An IDC key node was found by the IDC field.
22608 xmlGenericError(xmlGenericErrorContext
,
22609 "IDC: key found\n");
22612 * Notify that the character value of this node is
22615 if (resolved
== 0) {
22616 if ((vctxt
->inode
->flags
&
22617 XML_SCHEMA_NODE_INFO_VALUE_NEEDED
) == 0)
22618 vctxt
->inode
->flags
|= XML_SCHEMA_NODE_INFO_VALUE_NEEDED
;
22623 if (sto
->next
== NULL
) {
22625 * Evaluate field state objects created on this node as well.
22628 sto
= vctxt
->xpathStates
;
22635 static const xmlChar
*
22636 xmlSchemaFormatIDCKeySequence(xmlSchemaValidCtxtPtr vctxt
,
22638 xmlSchemaPSVIIDCKeyPtr
*seq
,
22642 xmlChar
*value
= NULL
;
22644 *buf
= xmlStrdup(BAD_CAST
"[");
22645 for (i
= 0; i
< count
; i
++) {
22646 *buf
= xmlStrcat(*buf
, BAD_CAST
"'");
22647 res
= xmlSchemaGetCanonValueWhtspExt(seq
[i
]->val
,
22648 xmlSchemaGetWhiteSpaceFacetValue(seq
[i
]->type
),
22651 *buf
= xmlStrcat(*buf
, BAD_CAST value
);
22653 VERROR_INT("xmlSchemaFormatIDCKeySequence",
22654 "failed to compute a canonical value");
22655 *buf
= xmlStrcat(*buf
, BAD_CAST
"???");
22658 *buf
= xmlStrcat(*buf
, BAD_CAST
"', ");
22660 *buf
= xmlStrcat(*buf
, BAD_CAST
"'");
22661 if (value
!= NULL
) {
22666 *buf
= xmlStrcat(*buf
, BAD_CAST
"]");
22668 return (BAD_CAST
*buf
);
22672 * xmlSchemaXPathPop:
22673 * @vctxt: the WXS validation context
22675 * Pops all XPath states.
22677 * Returns 0 on success and -1 on internal errors.
22680 xmlSchemaXPathPop(xmlSchemaValidCtxtPtr vctxt
)
22682 xmlSchemaIDCStateObjPtr sto
;
22685 if (vctxt
->xpathStates
== NULL
)
22687 sto
= vctxt
->xpathStates
;
22689 res
= xmlStreamPop((xmlStreamCtxtPtr
) sto
->xpathCtxt
);
22693 } while (sto
!= NULL
);
22698 * xmlSchemaXPathProcessHistory:
22699 * @vctxt: the WXS validation context
22700 * @type: the simple/complex type of the current node if any at all
22701 * @val: the precompiled value
22703 * Processes and pops the history items of the IDC state objects.
22704 * IDC key-sequences are validated/created on IDC bindings.
22706 * Returns 0 on success and -1 on internal errors.
22709 xmlSchemaXPathProcessHistory(xmlSchemaValidCtxtPtr vctxt
,
22712 xmlSchemaIDCStateObjPtr sto
, nextsto
;
22713 int res
, matchDepth
;
22714 xmlSchemaPSVIIDCKeyPtr key
= NULL
;
22715 xmlSchemaTypePtr type
= vctxt
->inode
->typeDef
, simpleType
= NULL
;
22717 if (vctxt
->xpathStates
== NULL
)
22719 sto
= vctxt
->xpathStates
;
22723 xmlChar
*str
= NULL
;
22724 xmlGenericError(xmlGenericErrorContext
,
22725 "IDC: BACK on %s, depth %d\n",
22726 xmlSchemaFormatQName(&str
, vctxt
->inode
->nsName
,
22727 vctxt
->inode
->localName
), vctxt
->depth
);
22732 * Evaluate the state objects.
22734 while (sto
!= NULL
) {
22735 res
= xmlStreamPop((xmlStreamCtxtPtr
) sto
->xpathCtxt
);
22737 VERROR_INT("xmlSchemaXPathProcessHistory",
22738 "calling xmlStreamPop()");
22742 xmlGenericError(xmlGenericErrorContext
, "IDC: stream pop '%s'\n",
22745 if (sto
->nbHistory
== 0)
22746 goto deregister_check
;
22748 matchDepth
= sto
->history
[sto
->nbHistory
-1];
22751 * Only matches at the current depth are of interest.
22753 if (matchDepth
!= depth
) {
22757 if (sto
->type
== XPATH_STATE_OBJ_TYPE_IDC_FIELD
) {
22759 * NOTE: According to
22760 * http://www.w3.org/Bugs/Public/show_bug.cgi?id=2198
22761 * ... the simple-content of complex types is also allowed.
22764 if (WXS_IS_COMPLEX(type
)) {
22765 if (WXS_HAS_SIMPLE_CONTENT(type
)) {
22767 * Sanity check for complex types with simple content.
22769 simpleType
= type
->contentTypeDef
;
22770 if (simpleType
== NULL
) {
22771 VERROR_INT("xmlSchemaXPathProcessHistory",
22772 "field resolves to a CT with simple content "
22773 "but the CT is missing the ST definition");
22780 if (simpleType
== NULL
) {
22781 xmlChar
*str
= NULL
;
22784 * Not qualified if the field resolves to a node of non
22787 xmlSchemaCustomErr(ACTXT_CAST vctxt
,
22788 XML_SCHEMAV_CVC_IDC
, NULL
,
22789 WXS_BASIC_CAST sto
->matcher
->aidc
->def
,
22790 "The XPath '%s' of a field of %s does evaluate to a node of "
22793 xmlSchemaGetIDCDesignation(&str
, sto
->matcher
->aidc
->def
));
22794 FREE_AND_NULL(str
);
22796 goto deregister_check
;
22799 if ((key
== NULL
) && (vctxt
->inode
->val
== NULL
)) {
22801 * Failed to provide the normalized value; maybe
22802 * the value was invalid.
22804 VERROR(XML_SCHEMAV_CVC_IDC
,
22805 WXS_BASIC_CAST sto
->matcher
->aidc
->def
,
22806 "Warning: No precomputed value available, the value "
22807 "was either invalid or something strange happend");
22809 goto deregister_check
;
22811 xmlSchemaIDCMatcherPtr matcher
= sto
->matcher
;
22812 xmlSchemaPSVIIDCKeyPtr
*keySeq
;
22816 * The key will be anchored on the matcher's list of
22817 * key-sequences. The position in this list is determined
22818 * by the target node's depth relative to the matcher's
22819 * depth of creation (i.e. the depth of the scope element).
22821 * Element Depth Pos List-entries
22824 * <target/> 2 2 target
22828 * The size of the list is only dependant on the depth of
22830 * An entry will be NULLed in selector_leave, i.e. when
22831 * we hit the target's
22833 pos
= sto
->depth
- matcher
->depth
;
22834 idx
= sto
->sel
->index
;
22837 * Create/grow the array of key-sequences.
22839 if (matcher
->keySeqs
== NULL
) {
22841 matcher
->sizeKeySeqs
= pos
* 2;
22843 matcher
->sizeKeySeqs
= 10;
22844 matcher
->keySeqs
= (xmlSchemaPSVIIDCKeyPtr
**)
22845 xmlMalloc(matcher
->sizeKeySeqs
*
22846 sizeof(xmlSchemaPSVIIDCKeyPtr
*));
22847 if (matcher
->keySeqs
== NULL
) {
22848 xmlSchemaVErrMemory(NULL
,
22849 "allocating an array of key-sequences",
22853 memset(matcher
->keySeqs
, 0,
22854 matcher
->sizeKeySeqs
*
22855 sizeof(xmlSchemaPSVIIDCKeyPtr
*));
22856 } else if (pos
>= matcher
->sizeKeySeqs
) {
22857 int i
= matcher
->sizeKeySeqs
;
22859 matcher
->sizeKeySeqs
*= 2;
22860 matcher
->keySeqs
= (xmlSchemaPSVIIDCKeyPtr
**)
22861 xmlRealloc(matcher
->keySeqs
,
22862 matcher
->sizeKeySeqs
*
22863 sizeof(xmlSchemaPSVIIDCKeyPtr
*));
22864 if (matcher
->keySeqs
== NULL
) {
22865 xmlSchemaVErrMemory(NULL
,
22866 "reallocating an array of key-sequences",
22871 * The array needs to be NULLed.
22872 * TODO: Use memset?
22874 for (; i
< matcher
->sizeKeySeqs
; i
++)
22875 matcher
->keySeqs
[i
] = NULL
;
22879 * Get/create the key-sequence.
22881 keySeq
= matcher
->keySeqs
[pos
];
22882 if (keySeq
== NULL
) {
22883 goto create_sequence
;
22884 } else if (keySeq
[idx
] != NULL
) {
22885 xmlChar
*str
= NULL
;
22887 * cvc-identity-constraint:
22888 * 3 For each node in the `target node set` all
22889 * of the {fields}, with that node as the context
22890 * node, evaluate to either an empty node-set or
22891 * a node-set with exactly one member, which must
22892 * have a simple type.
22894 * The key was already set; report an error.
22896 xmlSchemaCustomErr(ACTXT_CAST vctxt
,
22897 XML_SCHEMAV_CVC_IDC
, NULL
,
22898 WXS_BASIC_CAST matcher
->aidc
->def
,
22899 "The XPath '%s' of a field of %s evaluates to a "
22900 "node-set with more than one member",
22902 xmlSchemaGetIDCDesignation(&str
, matcher
->aidc
->def
));
22903 FREE_AND_NULL(str
);
22905 goto deregister_check
;
22911 * Create a key-sequence.
22913 keySeq
= (xmlSchemaPSVIIDCKeyPtr
*) xmlMalloc(
22914 matcher
->aidc
->def
->nbFields
*
22915 sizeof(xmlSchemaPSVIIDCKeyPtr
));
22916 if (keySeq
== NULL
) {
22917 xmlSchemaVErrMemory(NULL
,
22918 "allocating an IDC key-sequence", NULL
);
22921 memset(keySeq
, 0, matcher
->aidc
->def
->nbFields
*
22922 sizeof(xmlSchemaPSVIIDCKeyPtr
));
22923 matcher
->keySeqs
[pos
] = keySeq
;
22926 * Create a key once per node only.
22929 key
= (xmlSchemaPSVIIDCKeyPtr
) xmlMalloc(
22930 sizeof(xmlSchemaPSVIIDCKey
));
22932 xmlSchemaVErrMemory(NULL
,
22933 "allocating a IDC key", NULL
);
22935 matcher
->keySeqs
[pos
] = NULL
;
22939 * Consume the compiled value.
22941 key
->type
= simpleType
;
22942 key
->val
= vctxt
->inode
->val
;
22943 vctxt
->inode
->val
= NULL
;
22945 * Store the key in a global list.
22947 if (xmlSchemaIDCStoreKey(vctxt
, key
) == -1) {
22948 xmlSchemaIDCFreeKey(key
);
22954 } else if (sto
->type
== XPATH_STATE_OBJ_TYPE_IDC_SELECTOR
) {
22956 xmlSchemaPSVIIDCKeyPtr
**keySeq
= NULL
;
22957 /* xmlSchemaPSVIIDCBindingPtr bind; */
22958 xmlSchemaPSVIIDCNodePtr ntItem
;
22959 xmlSchemaIDCMatcherPtr matcher
;
22960 xmlSchemaIDCPtr idc
;
22961 xmlSchemaItemListPtr targets
;
22962 int pos
, i
, j
, nbKeys
;
22964 * Here we have the following scenario:
22965 * An IDC 'selector' state object resolved to a target node,
22966 * during the time this target node was in the
22967 * ancestor-or-self axis, the 'field' state object(s) looked
22968 * out for matching nodes to create a key-sequence for this
22969 * target node. Now we are back to this target node and need
22970 * to put the key-sequence, together with the target node
22971 * itself, into the node-table of the corresponding IDC
22974 matcher
= sto
->matcher
;
22975 idc
= matcher
->aidc
->def
;
22976 nbKeys
= idc
->nbFields
;
22977 pos
= depth
- matcher
->depth
;
22979 * Check if the matcher has any key-sequences at all, plus
22980 * if it has a key-sequence for the current target node.
22982 if ((matcher
->keySeqs
== NULL
) ||
22983 (matcher
->sizeKeySeqs
<= pos
)) {
22984 if (idc
->type
== XML_SCHEMA_TYPE_IDC_KEY
)
22985 goto selector_key_error
;
22987 goto selector_leave
;
22990 keySeq
= &(matcher
->keySeqs
[pos
]);
22991 if (*keySeq
== NULL
) {
22992 if (idc
->type
== XML_SCHEMA_TYPE_IDC_KEY
)
22993 goto selector_key_error
;
22995 goto selector_leave
;
22998 for (i
= 0; i
< nbKeys
; i
++) {
22999 if ((*keySeq
)[i
] == NULL
) {
23001 * Not qualified, if not all fields did resolve.
23003 if (idc
->type
== XML_SCHEMA_TYPE_IDC_KEY
) {
23005 * All fields of a "key" IDC must resolve.
23007 goto selector_key_error
;
23009 goto selector_leave
;
23013 * All fields did resolve.
23017 * 4.1 If the {identity-constraint category} is unique(/key),
23018 * then no two members of the `qualified node set` have
23019 * `key-sequences` whose members are pairwise equal, as
23020 * defined by Equal in [XML Schemas: Datatypes].
23022 * Get the IDC binding from the matcher and check for
23023 * duplicate key-sequences.
23026 bind
= xmlSchemaIDCAcquireBinding(vctxt
, matcher
);
23028 targets
= xmlSchemaIDCAcquireTargetList(vctxt
, matcher
);
23029 if ((idc
->type
!= XML_SCHEMA_TYPE_IDC_KEYREF
) &&
23030 (targets
->nbItems
!= 0)) {
23031 xmlSchemaPSVIIDCKeyPtr ckey
, bkey
, *bkeySeq
;
23036 * Compare the key-sequences, key by key.
23040 ((xmlSchemaPSVIIDCNodePtr
) targets
->items
[i
])->keys
;
23041 for (j
= 0; j
< nbKeys
; j
++) {
23042 ckey
= (*keySeq
)[j
];
23044 res
= xmlSchemaAreValuesEqual(ckey
->val
, bkey
->val
);
23047 } else if (res
== 0) {
23049 * One of the keys differs, so the key-sequence
23050 * won't be equal; get out.
23057 * Duplicate key-sequence found.
23062 } while (i
< targets
->nbItems
);
23063 if (i
!= targets
->nbItems
) {
23064 xmlChar
*str
= NULL
, *strB
= NULL
;
23066 * TODO: Try to report the key-sequence.
23068 xmlSchemaCustomErr(ACTXT_CAST vctxt
,
23069 XML_SCHEMAV_CVC_IDC
, NULL
,
23070 WXS_BASIC_CAST idc
,
23071 "Duplicate key-sequence %s in %s",
23072 xmlSchemaFormatIDCKeySequence(vctxt
, &str
,
23073 (*keySeq
), nbKeys
),
23074 xmlSchemaGetIDCDesignation(&strB
, idc
));
23075 FREE_AND_NULL(str
);
23076 FREE_AND_NULL(strB
);
23077 goto selector_leave
;
23081 * Add a node-table item to the IDC binding.
23083 ntItem
= (xmlSchemaPSVIIDCNodePtr
) xmlMalloc(
23084 sizeof(xmlSchemaPSVIIDCNode
));
23085 if (ntItem
== NULL
) {
23086 xmlSchemaVErrMemory(NULL
,
23087 "allocating an IDC node-table item", NULL
);
23092 memset(ntItem
, 0, sizeof(xmlSchemaPSVIIDCNode
));
23095 * Store the node-table item in a global list.
23097 if (idc
->type
!= XML_SCHEMA_TYPE_IDC_KEYREF
) {
23098 if (xmlSchemaIDCStoreNodeTableItem(vctxt
, ntItem
) == -1) {
23104 ntItem
->nodeQNameID
= -1;
23107 * Save a cached QName for this node on the IDC node, to be
23108 * able to report it, even if the node is not saved.
23110 ntItem
->nodeQNameID
= xmlSchemaVAddNodeQName(vctxt
,
23111 vctxt
->inode
->localName
, vctxt
->inode
->nsName
);
23112 if (ntItem
->nodeQNameID
== -1) {
23120 * Init the node-table item: Save the node, position and
23121 * consume the key-sequence.
23123 ntItem
->node
= vctxt
->node
;
23124 ntItem
->nodeLine
= vctxt
->inode
->nodeLine
;
23125 ntItem
->keys
= *keySeq
;
23128 if (xmlSchemaIDCAppendNodeTableItem(bind
, ntItem
) == -1)
23130 if (xmlSchemaItemListAdd(targets
, ntItem
) == -1) {
23131 if (idc
->type
== XML_SCHEMA_TYPE_IDC_KEYREF
) {
23133 * Free the item, since keyref items won't be
23134 * put on a global list.
23136 xmlFree(ntItem
->keys
);
23142 goto selector_leave
;
23143 selector_key_error
:
23145 xmlChar
*str
= NULL
;
23147 * 4.2.1 (KEY) The `target node set` and the
23148 * `qualified node set` are equal, that is, every
23149 * member of the `target node set` is also a member
23150 * of the `qualified node set` and vice versa.
23152 xmlSchemaCustomErr(ACTXT_CAST vctxt
,
23153 XML_SCHEMAV_CVC_IDC
, NULL
,
23154 WXS_BASIC_CAST idc
,
23155 "Not all fields of %s evaluate to a node",
23156 xmlSchemaGetIDCDesignation(&str
, idc
), NULL
);
23157 FREE_AND_NULL(str
);
23161 * Free the key-sequence if not added to the IDC table.
23163 if ((keySeq
!= NULL
) && (*keySeq
!= NULL
)) {
23167 } /* if selector */
23173 * Deregister state objects if they reach the depth of creation.
23175 if ((sto
->nbHistory
== 0) && (sto
->depth
== depth
)) {
23177 xmlGenericError(xmlGenericErrorContext
, "IDC: STO pop '%s'\n",
23180 if (vctxt
->xpathStates
!= sto
) {
23181 VERROR_INT("xmlSchemaXPathProcessHistory",
23182 "The state object to be removed is not the first "
23185 nextsto
= sto
->next
;
23187 * Unlink from the list of active XPath state objects.
23189 vctxt
->xpathStates
= sto
->next
;
23190 sto
->next
= vctxt
->xpathStatePool
;
23192 * Link it to the pool of reusable state objects.
23194 vctxt
->xpathStatePool
= sto
;
23198 } /* while (sto != NULL) */
23203 * xmlSchemaIDCRegisterMatchers:
23204 * @vctxt: the WXS validation context
23205 * @elemDecl: the element declaration
23207 * Creates helper objects to evaluate IDC selectors/fields
23210 * Returns 0 if OK and -1 on internal errors.
23213 xmlSchemaIDCRegisterMatchers(xmlSchemaValidCtxtPtr vctxt
,
23214 xmlSchemaElementPtr elemDecl
)
23216 xmlSchemaIDCMatcherPtr matcher
, last
= NULL
;
23217 xmlSchemaIDCPtr idc
, refIdc
;
23218 xmlSchemaIDCAugPtr aidc
;
23220 idc
= (xmlSchemaIDCPtr
) elemDecl
->idcs
;
23226 xmlChar
*str
= NULL
;
23227 xmlGenericError(xmlGenericErrorContext
,
23228 "IDC: REGISTER on %s, depth %d\n",
23229 (char *) xmlSchemaFormatQName(&str
, vctxt
->inode
->nsName
,
23230 vctxt
->inode
->localName
), vctxt
->depth
);
23234 if (vctxt
->inode
->idcMatchers
!= NULL
) {
23235 VERROR_INT("xmlSchemaIDCRegisterMatchers",
23236 "The chain of IDC matchers is expected to be empty");
23240 if (idc
->type
== XML_SCHEMA_TYPE_IDC_KEYREF
) {
23242 * Since IDCs bubbles are expensive we need to know the
23243 * depth at which the bubbles should stop; this will be
23244 * the depth of the top-most keyref IDC. If no keyref
23245 * references a key/unique IDC, the keyrefDepth will
23246 * be -1, indicating that no bubbles are needed.
23248 refIdc
= (xmlSchemaIDCPtr
) idc
->ref
->item
;
23249 if (refIdc
!= NULL
) {
23251 * Remember that we have keyrefs on this node.
23253 vctxt
->inode
->hasKeyrefs
= 1;
23255 * Lookup the referenced augmented IDC info.
23257 aidc
= vctxt
->aidcs
;
23258 while (aidc
!= NULL
) {
23259 if (aidc
->def
== refIdc
)
23263 if (aidc
== NULL
) {
23264 VERROR_INT("xmlSchemaIDCRegisterMatchers",
23265 "Could not find an augmented IDC item for an IDC "
23269 if ((aidc
->keyrefDepth
== -1) ||
23270 (vctxt
->depth
< aidc
->keyrefDepth
))
23271 aidc
->keyrefDepth
= vctxt
->depth
;
23275 * Lookup the augmented IDC item for the IDC definition.
23277 aidc
= vctxt
->aidcs
;
23278 while (aidc
!= NULL
) {
23279 if (aidc
->def
== idc
)
23283 if (aidc
== NULL
) {
23284 VERROR_INT("xmlSchemaIDCRegisterMatchers",
23285 "Could not find an augmented IDC item for an IDC definition");
23289 * Create an IDC matcher for every IDC definition.
23291 if (vctxt
->idcMatcherCache
!= NULL
) {
23293 * Reuse a cached matcher.
23295 matcher
= vctxt
->idcMatcherCache
;
23296 vctxt
->idcMatcherCache
= matcher
->nextCached
;
23297 matcher
->nextCached
= NULL
;
23299 matcher
= (xmlSchemaIDCMatcherPtr
)
23300 xmlMalloc(sizeof(xmlSchemaIDCMatcher
));
23301 if (matcher
== NULL
) {
23302 xmlSchemaVErrMemory(vctxt
,
23303 "allocating an IDC matcher", NULL
);
23306 memset(matcher
, 0, sizeof(xmlSchemaIDCMatcher
));
23309 vctxt
->inode
->idcMatchers
= matcher
;
23311 last
->next
= matcher
;
23314 matcher
->type
= IDC_MATCHER
;
23315 matcher
->depth
= vctxt
->depth
;
23316 matcher
->aidc
= aidc
;
23317 matcher
->idcType
= aidc
->def
->type
;
23319 xmlGenericError(xmlGenericErrorContext
, "IDC: register matcher\n");
23322 * Init the automaton state object.
23324 if (xmlSchemaIDCAddStateObject(vctxt
, matcher
,
23325 idc
->selector
, XPATH_STATE_OBJ_TYPE_IDC_SELECTOR
) == -1)
23329 } while (idc
!= NULL
);
23334 xmlSchemaIDCFillNodeTables(xmlSchemaValidCtxtPtr vctxt
,
23335 xmlSchemaNodeInfoPtr ielem
)
23337 xmlSchemaPSVIIDCBindingPtr bind
;
23338 int res
, i
, j
, k
, nbTargets
, nbFields
, nbDupls
, nbNodeTable
;
23339 xmlSchemaPSVIIDCKeyPtr
*keys
, *ntkeys
;
23340 xmlSchemaPSVIIDCNodePtr
*targets
, *dupls
;
23342 xmlSchemaIDCMatcherPtr matcher
= ielem
->idcMatchers
;
23343 /* vctxt->createIDCNodeTables */
23344 while (matcher
!= NULL
) {
23346 * Skip keyref IDCs and empty IDC target-lists.
23348 if ((matcher
->aidc
->def
->type
== XML_SCHEMA_TYPE_IDC_KEYREF
) ||
23349 WXS_ILIST_IS_EMPTY(matcher
->targets
))
23351 matcher
= matcher
->next
;
23355 * If we _want_ the IDC node-table to be created in any case
23356 * then do so. Otherwise create them only if keyrefs need them.
23358 if ((! vctxt
->createIDCNodeTables
) &&
23359 ((matcher
->aidc
->keyrefDepth
== -1) ||
23360 (matcher
->aidc
->keyrefDepth
> vctxt
->depth
)))
23362 matcher
= matcher
->next
;
23366 * Get/create the IDC binding on this element for the IDC definition.
23368 bind
= xmlSchemaIDCAcquireBinding(vctxt
, matcher
);
23370 if (! WXS_ILIST_IS_EMPTY(bind
->dupls
)) {
23371 dupls
= (xmlSchemaPSVIIDCNodePtr
*) bind
->dupls
->items
;
23372 nbDupls
= bind
->dupls
->nbItems
;
23377 if (bind
->nodeTable
!= NULL
) {
23378 nbNodeTable
= bind
->nbNodes
;
23383 if ((nbNodeTable
== 0) && (nbDupls
== 0)) {
23385 * Transfer all IDC target-nodes to the IDC node-table.
23388 (xmlSchemaPSVIIDCNodePtr
*) matcher
->targets
->items
;
23389 bind
->sizeNodes
= matcher
->targets
->sizeItems
;
23390 bind
->nbNodes
= matcher
->targets
->nbItems
;
23392 matcher
->targets
->items
= NULL
;
23393 matcher
->targets
->sizeItems
= 0;
23394 matcher
->targets
->nbItems
= 0;
23397 * Compare the key-sequences and add to the IDC node-table.
23399 nbTargets
= matcher
->targets
->nbItems
;
23400 targets
= (xmlSchemaPSVIIDCNodePtr
*) matcher
->targets
->items
;
23401 nbFields
= matcher
->aidc
->def
->nbFields
;
23404 keys
= targets
[i
]->keys
;
23407 * Search in already found duplicates first.
23411 if (nbFields
== 1) {
23412 res
= xmlSchemaAreValuesEqual(keys
[0]->val
,
23413 dupls
[j
]->keys
[0]->val
);
23415 goto internal_error
;
23418 * Equal key-sequence.
23424 ntkeys
= dupls
[j
]->keys
;
23425 for (k
= 0; k
< nbFields
; k
++) {
23426 res
= xmlSchemaAreValuesEqual(keys
[k
]->val
,
23429 goto internal_error
;
23432 * One of the keys differs.
23439 * Equal key-sequence found.
23445 } while (j
< nbDupls
);
23450 if (nbFields
== 1) {
23451 res
= xmlSchemaAreValuesEqual(keys
[0]->val
,
23452 bind
->nodeTable
[j
]->keys
[0]->val
);
23454 goto internal_error
;
23457 * The key-sequence differs.
23459 goto next_node_table_entry
;
23463 ntkeys
= bind
->nodeTable
[j
]->keys
;
23464 for (k
= 0; k
< nbFields
; k
++) {
23465 res
= xmlSchemaAreValuesEqual(keys
[k
]->val
,
23468 goto internal_error
;
23471 * One of the keys differs.
23473 goto next_node_table_entry
;
23478 * Add the duplicate to the list of duplicates.
23480 if (bind
->dupls
== NULL
) {
23481 bind
->dupls
= xmlSchemaItemListCreate();
23482 if (bind
->dupls
== NULL
)
23483 goto internal_error
;
23485 if (xmlSchemaItemListAdd(bind
->dupls
, bind
->nodeTable
[j
]) == -1)
23486 goto internal_error
;
23488 * Remove the duplicate entry from the IDC node-table.
23490 bind
->nodeTable
[j
] = bind
->nodeTable
[bind
->nbNodes
-1];
23495 next_node_table_entry
:
23497 } while (j
< nbNodeTable
);
23500 * If everything is fine, then add the IDC target-node to
23501 * the IDC node-table.
23503 if (xmlSchemaIDCAppendNodeTableItem(bind
, targets
[i
]) == -1)
23504 goto internal_error
;
23508 } while (i
< nbTargets
);
23510 matcher
= matcher
->next
;
23519 * xmlSchemaBubbleIDCNodeTables:
23520 * @depth: the current tree depth
23522 * Merges IDC bindings of an element at @depth into the corresponding IDC
23523 * bindings of its parent element. If a duplicate note-table entry is found,
23524 * both, the parent node-table entry and child entry are discarded from the
23525 * node-table of the parent.
23527 * Returns 0 if OK and -1 on internal errors.
23530 xmlSchemaBubbleIDCNodeTables(xmlSchemaValidCtxtPtr vctxt
)
23532 xmlSchemaPSVIIDCBindingPtr bind
; /* IDC bindings of the current node. */
23533 xmlSchemaPSVIIDCBindingPtr
*parTable
, parBind
= NULL
; /* parent IDC bindings. */
23534 xmlSchemaPSVIIDCNodePtr node
, parNode
= NULL
, *dupls
, *parNodes
; /* node-table entries. */
23535 xmlSchemaIDCAugPtr aidc
;
23536 int i
, j
, k
, ret
= 0, nbFields
, oldNum
, oldDupls
;
23538 bind
= vctxt
->inode
->idcTable
;
23539 if (bind
== NULL
) {
23540 /* Fine, no table, no bubbles. */
23544 parTable
= &(vctxt
->elemInfos
[vctxt
->depth
-1]->idcTable
);
23546 * Walk all bindings; create new or add to existing bindings.
23547 * Remove duplicate key-sequences.
23549 while (bind
!= NULL
) {
23551 if ((bind
->nbNodes
== 0) && WXS_ILIST_IS_EMPTY(bind
->dupls
))
23554 * Check if the key/unique IDC table needs to be bubbled.
23556 if (! vctxt
->createIDCNodeTables
) {
23557 aidc
= vctxt
->aidcs
;
23559 if (aidc
->def
== bind
->definition
) {
23560 if ((aidc
->keyrefDepth
== -1) ||
23561 (aidc
->keyrefDepth
>= vctxt
->depth
)) {
23567 } while (aidc
!= NULL
);
23570 if (parTable
!= NULL
)
23571 parBind
= *parTable
;
23573 * Search a matching parent binding for the
23576 while (parBind
!= NULL
) {
23577 if (parBind
->definition
== bind
->definition
)
23579 parBind
= parBind
->next
;
23582 if (parBind
!= NULL
) {
23584 * Compare every node-table entry of the child node,
23585 * i.e. the key-sequence within, ...
23587 oldNum
= parBind
->nbNodes
; /* Skip newly added items. */
23589 if (! WXS_ILIST_IS_EMPTY(parBind
->dupls
)) {
23590 oldDupls
= parBind
->dupls
->nbItems
;
23591 dupls
= (xmlSchemaPSVIIDCNodePtr
*) parBind
->dupls
->items
;
23597 parNodes
= parBind
->nodeTable
;
23598 nbFields
= bind
->definition
->nbFields
;
23600 for (i
= 0; i
< bind
->nbNodes
; i
++) {
23601 node
= bind
->nodeTable
[i
];
23605 * ...with every key-sequence of the parent node, already
23606 * evaluated to be a duplicate key-sequence.
23610 while (j
< oldDupls
) {
23611 if (nbFields
== 1) {
23612 ret
= xmlSchemaAreValuesEqual(
23613 node
->keys
[0]->val
,
23614 dupls
[j
]->keys
[0]->val
);
23616 goto internal_error
;
23622 parNode
= dupls
[j
];
23623 for (k
= 0; k
< nbFields
; k
++) {
23624 ret
= xmlSchemaAreValuesEqual(
23625 node
->keys
[k
]->val
,
23626 parNode
->keys
[k
]->val
);
23628 goto internal_error
;
23634 /* Duplicate found. */
23638 if (j
!= oldDupls
) {
23639 /* Duplicate found. Skip this entry. */
23644 * ... and with every key-sequence of the parent node.
23648 while (j
< oldNum
) {
23649 parNode
= parNodes
[j
];
23650 if (nbFields
== 1) {
23651 ret
= xmlSchemaAreValuesEqual(
23652 node
->keys
[0]->val
,
23653 parNode
->keys
[0]->val
);
23655 goto internal_error
;
23661 for (k
= 0; k
< nbFields
; k
++) {
23662 ret
= xmlSchemaAreValuesEqual(
23663 node
->keys
[k
]->val
,
23664 parNode
->keys
[k
]->val
);
23666 goto internal_error
;
23672 /* Duplicate found. */
23678 * Handle duplicates. Move the duplicate in
23679 * the parent's node-table to the list of
23683 parBind
->nbNodes
--;
23685 * Move last old item to pos of duplicate.
23687 parNodes
[j
] = parNodes
[oldNum
];
23689 if (parBind
->nbNodes
!= oldNum
) {
23691 * If new items exist, move last new item to
23692 * last of old items.
23695 parNodes
[parBind
->nbNodes
];
23697 if (parBind
->dupls
== NULL
) {
23698 parBind
->dupls
= xmlSchemaItemListCreate();
23699 if (parBind
->dupls
== NULL
)
23700 goto internal_error
;
23702 xmlSchemaItemListAdd(parBind
->dupls
, parNode
);
23705 * Add the node-table entry (node and key-sequence) of
23706 * the child node to the node table of the parent node.
23708 if (parBind
->nodeTable
== NULL
) {
23709 parBind
->nodeTable
= (xmlSchemaPSVIIDCNodePtr
*)
23710 xmlMalloc(10 * sizeof(xmlSchemaPSVIIDCNodePtr
));
23711 if (parBind
->nodeTable
== NULL
) {
23712 xmlSchemaVErrMemory(NULL
,
23713 "allocating IDC list of node-table items", NULL
);
23714 goto internal_error
;
23716 parBind
->sizeNodes
= 1;
23717 } else if (parBind
->nbNodes
>= parBind
->sizeNodes
) {
23718 parBind
->sizeNodes
*= 2;
23719 parBind
->nodeTable
= (xmlSchemaPSVIIDCNodePtr
*)
23720 xmlRealloc(parBind
->nodeTable
, parBind
->sizeNodes
*
23721 sizeof(xmlSchemaPSVIIDCNodePtr
));
23722 if (parBind
->nodeTable
== NULL
) {
23723 xmlSchemaVErrMemory(NULL
,
23724 "re-allocating IDC list of node-table items", NULL
);
23725 goto internal_error
;
23728 parNodes
= parBind
->nodeTable
;
23730 * Append the new node-table entry to the 'new node-table
23731 * entries' section.
23733 parNodes
[parBind
->nbNodes
++] = node
;
23741 * No binding for the IDC was found: create a new one and
23742 * copy all node-tables.
23744 parBind
= xmlSchemaIDCNewBinding(bind
->definition
);
23745 if (parBind
== NULL
)
23746 goto internal_error
;
23749 * TODO: Hmm, how to optimize the initial number of
23750 * allocated entries?
23752 if (bind
->nbNodes
!= 0) {
23754 * Add all IDC node-table entries.
23756 if (! vctxt
->psviExposeIDCNodeTables
) {
23758 * Just move the entries.
23759 * NOTE: this is quite save here, since
23760 * all the keyref lookups have already been
23763 parBind
->nodeTable
= bind
->nodeTable
;
23764 bind
->nodeTable
= NULL
;
23765 parBind
->sizeNodes
= bind
->sizeNodes
;
23766 bind
->sizeNodes
= 0;
23767 parBind
->nbNodes
= bind
->nbNodes
;
23771 * Copy the entries.
23773 parBind
->nodeTable
= (xmlSchemaPSVIIDCNodePtr
*)
23774 xmlMalloc(bind
->nbNodes
*
23775 sizeof(xmlSchemaPSVIIDCNodePtr
));
23776 if (parBind
->nodeTable
== NULL
) {
23777 xmlSchemaVErrMemory(NULL
,
23778 "allocating an array of IDC node-table "
23780 xmlSchemaIDCFreeBinding(parBind
);
23781 goto internal_error
;
23783 parBind
->sizeNodes
= bind
->nbNodes
;
23784 parBind
->nbNodes
= bind
->nbNodes
;
23785 memcpy(parBind
->nodeTable
, bind
->nodeTable
,
23786 bind
->nbNodes
* sizeof(xmlSchemaPSVIIDCNodePtr
));
23791 * Move the duplicates.
23793 if (parBind
->dupls
!= NULL
)
23794 xmlSchemaItemListFree(parBind
->dupls
);
23795 parBind
->dupls
= bind
->dupls
;
23796 bind
->dupls
= NULL
;
23798 if (parTable
!= NULL
) {
23799 if (*parTable
== NULL
)
23800 *parTable
= parBind
;
23802 parBind
->next
= *parTable
;
23803 *parTable
= parBind
;
23818 * xmlSchemaCheckCVCIDCKeyRef:
23819 * @vctxt: the WXS validation context
23820 * @elemDecl: the element declaration
23822 * Check the cvc-idc-keyref constraints.
23825 xmlSchemaCheckCVCIDCKeyRef(xmlSchemaValidCtxtPtr vctxt
)
23827 xmlSchemaIDCMatcherPtr matcher
;
23828 xmlSchemaPSVIIDCBindingPtr bind
;
23830 matcher
= vctxt
->inode
->idcMatchers
;
23834 while (matcher
!= NULL
) {
23835 if ((matcher
->idcType
== XML_SCHEMA_TYPE_IDC_KEYREF
) &&
23836 matcher
->targets
&&
23837 matcher
->targets
->nbItems
)
23839 int i
, j
, k
, res
, nbFields
, hasDupls
;
23840 xmlSchemaPSVIIDCKeyPtr
*refKeys
, *keys
;
23841 xmlSchemaPSVIIDCNodePtr refNode
= NULL
;
23843 nbFields
= matcher
->aidc
->def
->nbFields
;
23846 * Find the IDC node-table for the referenced IDC key/unique.
23848 bind
= vctxt
->inode
->idcTable
;
23849 while (bind
!= NULL
) {
23850 if ((xmlSchemaIDCPtr
) matcher
->aidc
->def
->ref
->item
==
23855 hasDupls
= (bind
&& bind
->dupls
&& bind
->dupls
->nbItems
) ? 1 : 0;
23857 * Search for a matching key-sequences.
23859 for (i
= 0; i
< matcher
->targets
->nbItems
; i
++) {
23861 refNode
= matcher
->targets
->items
[i
];
23862 if (bind
!= NULL
) {
23863 refKeys
= refNode
->keys
;
23864 for (j
= 0; j
< bind
->nbNodes
; j
++) {
23865 keys
= bind
->nodeTable
[j
]->keys
;
23866 for (k
= 0; k
< nbFields
; k
++) {
23867 res
= xmlSchemaAreValuesEqual(keys
[k
]->val
,
23871 else if (res
== -1) {
23882 if ((res
== 0) && hasDupls
) {
23884 * Search in duplicates
23886 for (j
= 0; j
< bind
->dupls
->nbItems
; j
++) {
23887 keys
= ((xmlSchemaPSVIIDCNodePtr
)
23888 bind
->dupls
->items
[j
])->keys
;
23889 for (k
= 0; k
< nbFields
; k
++) {
23890 res
= xmlSchemaAreValuesEqual(keys
[k
]->val
,
23894 else if (res
== -1) {
23900 * Match in duplicates found.
23902 xmlChar
*str
= NULL
, *strB
= NULL
;
23903 xmlSchemaKeyrefErr(vctxt
,
23904 XML_SCHEMAV_CVC_IDC
, refNode
,
23905 (xmlSchemaTypePtr
) matcher
->aidc
->def
,
23906 "More than one match found for "
23907 "key-sequence %s of keyref '%s'",
23908 xmlSchemaFormatIDCKeySequence(vctxt
, &str
,
23909 refNode
->keys
, nbFields
),
23910 xmlSchemaGetComponentQName(&strB
,
23911 matcher
->aidc
->def
));
23912 FREE_AND_NULL(str
);
23913 FREE_AND_NULL(strB
);
23921 xmlChar
*str
= NULL
, *strB
= NULL
;
23922 xmlSchemaKeyrefErr(vctxt
,
23923 XML_SCHEMAV_CVC_IDC
, refNode
,
23924 (xmlSchemaTypePtr
) matcher
->aidc
->def
,
23925 "No match found for key-sequence %s of keyref '%s'",
23926 xmlSchemaFormatIDCKeySequence(vctxt
, &str
,
23927 refNode
->keys
, nbFields
),
23928 xmlSchemaGetComponentQName(&strB
, matcher
->aidc
->def
));
23929 FREE_AND_NULL(str
);
23930 FREE_AND_NULL(strB
);
23934 matcher
= matcher
->next
;
23936 /* TODO: Return an error if any error encountered. */
23940 /************************************************************************
23942 * XML Reader validation code *
23944 ************************************************************************/
23946 static xmlSchemaAttrInfoPtr
23947 xmlSchemaGetFreshAttrInfo(xmlSchemaValidCtxtPtr vctxt
)
23949 xmlSchemaAttrInfoPtr iattr
;
23951 * Grow/create list of attribute infos.
23953 if (vctxt
->attrInfos
== NULL
) {
23954 vctxt
->attrInfos
= (xmlSchemaAttrInfoPtr
*)
23955 xmlMalloc(sizeof(xmlSchemaAttrInfoPtr
));
23956 vctxt
->sizeAttrInfos
= 1;
23957 if (vctxt
->attrInfos
== NULL
) {
23958 xmlSchemaVErrMemory(vctxt
,
23959 "allocating attribute info list", NULL
);
23962 } else if (vctxt
->sizeAttrInfos
<= vctxt
->nbAttrInfos
) {
23963 vctxt
->sizeAttrInfos
++;
23964 vctxt
->attrInfos
= (xmlSchemaAttrInfoPtr
*)
23965 xmlRealloc(vctxt
->attrInfos
,
23966 vctxt
->sizeAttrInfos
* sizeof(xmlSchemaAttrInfoPtr
));
23967 if (vctxt
->attrInfos
== NULL
) {
23968 xmlSchemaVErrMemory(vctxt
,
23969 "re-allocating attribute info list", NULL
);
23973 iattr
= vctxt
->attrInfos
[vctxt
->nbAttrInfos
++];
23974 if (iattr
->localName
!= NULL
) {
23975 VERROR_INT("xmlSchemaGetFreshAttrInfo",
23976 "attr info not cleared");
23979 iattr
->nodeType
= XML_ATTRIBUTE_NODE
;
23983 * Create an attribute info.
23985 iattr
= (xmlSchemaAttrInfoPtr
)
23986 xmlMalloc(sizeof(xmlSchemaAttrInfo
));
23987 if (iattr
== NULL
) {
23988 xmlSchemaVErrMemory(vctxt
, "creating new attribute info", NULL
);
23991 memset(iattr
, 0, sizeof(xmlSchemaAttrInfo
));
23992 iattr
->nodeType
= XML_ATTRIBUTE_NODE
;
23993 vctxt
->attrInfos
[vctxt
->nbAttrInfos
++] = iattr
;
23999 xmlSchemaValidatorPushAttribute(xmlSchemaValidCtxtPtr vctxt
,
24000 xmlNodePtr attrNode
,
24002 const xmlChar
*localName
,
24003 const xmlChar
*nsName
,
24008 xmlSchemaAttrInfoPtr attr
;
24010 attr
= xmlSchemaGetFreshAttrInfo(vctxt
);
24011 if (attr
== NULL
) {
24012 VERROR_INT("xmlSchemaPushAttribute",
24013 "calling xmlSchemaGetFreshAttrInfo()");
24016 attr
->node
= attrNode
;
24017 attr
->nodeLine
= nodeLine
;
24018 attr
->state
= XML_SCHEMAS_ATTR_UNKNOWN
;
24019 attr
->localName
= localName
;
24020 attr
->nsName
= nsName
;
24022 attr
->flags
|= XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES
;
24024 * Evaluate if it's an XSI attribute.
24026 if (nsName
!= NULL
) {
24027 if (xmlStrEqual(localName
, BAD_CAST
"nil")) {
24028 if (xmlStrEqual(attr
->nsName
, xmlSchemaInstanceNs
)) {
24029 attr
->metaType
= XML_SCHEMA_ATTR_INFO_META_XSI_NIL
;
24031 } else if (xmlStrEqual(localName
, BAD_CAST
"type")) {
24032 if (xmlStrEqual(attr
->nsName
, xmlSchemaInstanceNs
)) {
24033 attr
->metaType
= XML_SCHEMA_ATTR_INFO_META_XSI_TYPE
;
24035 } else if (xmlStrEqual(localName
, BAD_CAST
"schemaLocation")) {
24036 if (xmlStrEqual(attr
->nsName
, xmlSchemaInstanceNs
)) {
24037 attr
->metaType
= XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC
;
24039 } else if (xmlStrEqual(localName
, BAD_CAST
"noNamespaceSchemaLocation")) {
24040 if (xmlStrEqual(attr
->nsName
, xmlSchemaInstanceNs
)) {
24041 attr
->metaType
= XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC
;
24043 } else if (xmlStrEqual(attr
->nsName
, xmlNamespaceNs
)) {
24044 attr
->metaType
= XML_SCHEMA_ATTR_INFO_META_XMLNS
;
24047 attr
->value
= value
;
24049 attr
->flags
|= XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES
;
24050 if (attr
->metaType
!= 0)
24051 attr
->state
= XML_SCHEMAS_ATTR_META
;
24056 * xmlSchemaClearElemInfo:
24057 * @vctxt: the WXS validation context
24058 * @ielem: the element information item
24061 xmlSchemaClearElemInfo(xmlSchemaValidCtxtPtr vctxt
,
24062 xmlSchemaNodeInfoPtr ielem
)
24064 ielem
->hasKeyrefs
= 0;
24065 ielem
->appliedXPath
= 0;
24066 if (ielem
->flags
& XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES
) {
24067 FREE_AND_NULL(ielem
->localName
);
24068 FREE_AND_NULL(ielem
->nsName
);
24070 ielem
->localName
= NULL
;
24071 ielem
->nsName
= NULL
;
24073 if (ielem
->flags
& XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES
) {
24074 FREE_AND_NULL(ielem
->value
);
24076 ielem
->value
= NULL
;
24078 if (ielem
->val
!= NULL
) {
24080 * PSVI TODO: Be careful not to free it when the value is
24081 * exposed via PSVI.
24083 xmlSchemaFreeValue(ielem
->val
);
24086 if (ielem
->idcMatchers
!= NULL
) {
24088 * REVISIT OPTIMIZE TODO: Use a pool of IDC matchers.
24091 xmlSchemaIDCReleaseMatcherList(vctxt
, ielem
->idcMatchers
);
24093 xmlSchemaIDCFreeMatcherList(ielem
->idcMatchers
);
24095 ielem
->idcMatchers
= NULL
;
24097 if (ielem
->idcTable
!= NULL
) {
24099 * OPTIMIZE TODO: Use a pool of IDC tables??.
24101 xmlSchemaIDCFreeIDCTable(ielem
->idcTable
);
24102 ielem
->idcTable
= NULL
;
24104 if (ielem
->regexCtxt
!= NULL
) {
24105 xmlRegFreeExecCtxt(ielem
->regexCtxt
);
24106 ielem
->regexCtxt
= NULL
;
24108 if (ielem
->nsBindings
!= NULL
) {
24109 xmlFree((xmlChar
**)ielem
->nsBindings
);
24110 ielem
->nsBindings
= NULL
;
24111 ielem
->nbNsBindings
= 0;
24112 ielem
->sizeNsBindings
= 0;
24117 * xmlSchemaGetFreshElemInfo:
24118 * @vctxt: the schema validation context
24120 * Creates/reuses and initializes the element info item for
24121 * the currect tree depth.
24123 * Returns the element info item or NULL on API or internal errors.
24125 static xmlSchemaNodeInfoPtr
24126 xmlSchemaGetFreshElemInfo(xmlSchemaValidCtxtPtr vctxt
)
24128 xmlSchemaNodeInfoPtr info
= NULL
;
24130 if (vctxt
->depth
> vctxt
->sizeElemInfos
) {
24131 VERROR_INT("xmlSchemaGetFreshElemInfo",
24132 "inconsistent depth encountered");
24135 if (vctxt
->elemInfos
== NULL
) {
24136 vctxt
->elemInfos
= (xmlSchemaNodeInfoPtr
*)
24137 xmlMalloc(10 * sizeof(xmlSchemaNodeInfoPtr
));
24138 if (vctxt
->elemInfos
== NULL
) {
24139 xmlSchemaVErrMemory(vctxt
,
24140 "allocating the element info array", NULL
);
24143 memset(vctxt
->elemInfos
, 0, 10 * sizeof(xmlSchemaNodeInfoPtr
));
24144 vctxt
->sizeElemInfos
= 10;
24145 } else if (vctxt
->sizeElemInfos
<= vctxt
->depth
) {
24146 int i
= vctxt
->sizeElemInfos
;
24148 vctxt
->sizeElemInfos
*= 2;
24149 vctxt
->elemInfos
= (xmlSchemaNodeInfoPtr
*)
24150 xmlRealloc(vctxt
->elemInfos
, vctxt
->sizeElemInfos
*
24151 sizeof(xmlSchemaNodeInfoPtr
));
24152 if (vctxt
->elemInfos
== NULL
) {
24153 xmlSchemaVErrMemory(vctxt
,
24154 "re-allocating the element info array", NULL
);
24158 * We need the new memory to be NULLed.
24159 * TODO: Use memset instead?
24161 for (; i
< vctxt
->sizeElemInfos
; i
++)
24162 vctxt
->elemInfos
[i
] = NULL
;
24164 info
= vctxt
->elemInfos
[vctxt
->depth
];
24166 if (info
== NULL
) {
24167 info
= (xmlSchemaNodeInfoPtr
)
24168 xmlMalloc(sizeof(xmlSchemaNodeInfo
));
24169 if (info
== NULL
) {
24170 xmlSchemaVErrMemory(vctxt
,
24171 "allocating an element info", NULL
);
24174 vctxt
->elemInfos
[vctxt
->depth
] = info
;
24176 if (info
->localName
!= NULL
) {
24177 VERROR_INT("xmlSchemaGetFreshElemInfo",
24178 "elem info has not been cleared");
24182 memset(info
, 0, sizeof(xmlSchemaNodeInfo
));
24183 info
->nodeType
= XML_ELEMENT_NODE
;
24184 info
->depth
= vctxt
->depth
;
24189 #define ACTIVATE_ATTRIBUTE(item) vctxt->inode = (xmlSchemaNodeInfoPtr) item;
24190 #define ACTIVATE_ELEM vctxt->inode = vctxt->elemInfos[vctxt->depth];
24191 #define ACTIVATE_PARENT_ELEM vctxt->inode = vctxt->elemInfos[vctxt->depth -1];
24194 xmlSchemaValidateFacets(xmlSchemaAbstractCtxtPtr actxt
,
24196 xmlSchemaTypePtr type
,
24197 xmlSchemaValType valType
,
24198 const xmlChar
* value
,
24199 xmlSchemaValPtr val
,
24200 unsigned long length
,
24203 int ret
, error
= 0;
24205 xmlSchemaTypePtr tmpType
;
24206 xmlSchemaFacetLinkPtr facetLink
;
24207 xmlSchemaFacetPtr facet
;
24208 unsigned long len
= 0;
24209 xmlSchemaWhitespaceValueType ws
;
24212 * In Libxml2, derived built-in types have currently no explicit facets.
24214 if (type
->type
== XML_SCHEMA_TYPE_BASIC
)
24218 * NOTE: Do not jump away, if the facetSet of the given type is
24219 * empty: until now, "pattern" and "enumeration" facets of the
24220 * *base types* need to be checked as well.
24222 if (type
->facetSet
== NULL
)
24223 goto pattern_and_enum
;
24225 if (! WXS_IS_ATOMIC(type
)) {
24226 if (WXS_IS_LIST(type
))
24229 goto pattern_and_enum
;
24233 * Whitespace handling is only of importance for string-based
24236 tmpType
= xmlSchemaGetPrimitiveType(type
);
24237 if ((tmpType
->builtInType
== XML_SCHEMAS_STRING
) ||
24238 WXS_IS_ANY_SIMPLE_TYPE(tmpType
)) {
24239 ws
= xmlSchemaGetWhiteSpaceFacetValue(type
);
24241 ws
= XML_SCHEMA_WHITESPACE_COLLAPSE
;
24244 * If the value was not computed (for string or
24245 * anySimpleType based types), then use the provided
24249 valType
= xmlSchemaGetValType(val
);
24252 for (facetLink
= type
->facetSet
; facetLink
!= NULL
;
24253 facetLink
= facetLink
->next
) {
24255 * Skip the pattern "whiteSpace": it is used to
24256 * format the character content beforehand.
24258 switch (facetLink
->facet
->type
) {
24259 case XML_SCHEMA_FACET_WHITESPACE
:
24260 case XML_SCHEMA_FACET_PATTERN
:
24261 case XML_SCHEMA_FACET_ENUMERATION
:
24263 case XML_SCHEMA_FACET_LENGTH
:
24264 case XML_SCHEMA_FACET_MINLENGTH
:
24265 case XML_SCHEMA_FACET_MAXLENGTH
:
24266 ret
= xmlSchemaValidateLengthFacetWhtsp(facetLink
->facet
,
24267 valType
, value
, val
, &len
, ws
);
24270 ret
= xmlSchemaValidateFacetWhtsp(facetLink
->facet
, ws
,
24271 valType
, value
, val
, ws
);
24275 AERROR_INT("xmlSchemaValidateFacets",
24276 "validating against a atomic type facet");
24278 } else if (ret
> 0) {
24280 xmlSchemaFacetErr(actxt
, ret
, node
,
24281 value
, len
, type
, facetLink
->facet
, NULL
, NULL
, NULL
);
24291 if (! WXS_IS_LIST(type
))
24292 goto pattern_and_enum
;
24294 * "length", "minLength" and "maxLength" of list types.
24297 for (facetLink
= type
->facetSet
; facetLink
!= NULL
;
24298 facetLink
= facetLink
->next
) {
24300 switch (facetLink
->facet
->type
) {
24301 case XML_SCHEMA_FACET_LENGTH
:
24302 case XML_SCHEMA_FACET_MINLENGTH
:
24303 case XML_SCHEMA_FACET_MAXLENGTH
:
24304 ret
= xmlSchemaValidateListSimpleTypeFacet(facetLink
->facet
,
24305 value
, length
, NULL
);
24311 AERROR_INT("xmlSchemaValidateFacets",
24312 "validating against a list type facet");
24314 } else if (ret
> 0) {
24316 xmlSchemaFacetErr(actxt
, ret
, node
,
24317 value
, length
, type
, facetLink
->facet
, NULL
, NULL
, NULL
);
24330 * Process enumerations. Facet values are in the value space
24331 * of the defining type's base type. This seems to be a bug in the
24332 * XML Schema 1.0 spec. Use the whitespace type of the base type.
24333 * Only the first set of enumerations in the ancestor-or-self axis
24334 * is used for validation.
24339 for (facet
= tmpType
->facets
; facet
!= NULL
; facet
= facet
->next
) {
24340 if (facet
->type
!= XML_SCHEMA_FACET_ENUMERATION
)
24343 ret
= xmlSchemaAreValuesEqual(facet
->val
, val
);
24346 else if (ret
< 0) {
24347 AERROR_INT("xmlSchemaValidateFacets",
24348 "validating against an enumeration facet");
24355 * Break on the first set of enumerations. Any additional
24356 * enumerations which might be existent on the ancestors
24357 * of the current type are restricted by this set; thus
24358 * *must* *not* be taken into account.
24362 tmpType
= tmpType
->baseType
;
24363 } while ((tmpType
!= NULL
) &&
24364 (tmpType
->type
!= XML_SCHEMA_TYPE_BASIC
));
24365 if (found
&& (ret
== 0)) {
24366 ret
= XML_SCHEMAV_CVC_ENUMERATION_VALID
;
24368 xmlSchemaFacetErr(actxt
, ret
, node
,
24369 value
, 0, type
, NULL
, NULL
, NULL
, NULL
);
24380 * Process patters. Pattern facets are ORed at type level
24381 * and ANDed if derived. Walk the base type axis.
24387 for (facetLink
= tmpType
->facetSet
; facetLink
!= NULL
;
24388 facetLink
= facetLink
->next
) {
24389 if (facetLink
->facet
->type
!= XML_SCHEMA_FACET_PATTERN
)
24393 * NOTE that for patterns, @value needs to be the
24394 * normalized vaule.
24396 ret
= xmlRegexpExec(facetLink
->facet
->regexp
, value
);
24399 else if (ret
< 0) {
24400 AERROR_INT("xmlSchemaValidateFacets",
24401 "validating against a pattern facet");
24405 * Save the last non-validating facet.
24407 facet
= facetLink
->facet
;
24410 if (found
&& (ret
!= 1)) {
24411 ret
= XML_SCHEMAV_CVC_PATTERN_VALID
;
24413 xmlSchemaFacetErr(actxt
, ret
, node
,
24414 value
, 0, type
, facet
, NULL
, NULL
, NULL
);
24421 tmpType
= tmpType
->baseType
;
24422 } while ((tmpType
!= NULL
) && (tmpType
->type
!= XML_SCHEMA_TYPE_BASIC
));
24429 xmlSchemaNormalizeValue(xmlSchemaTypePtr type
,
24430 const xmlChar
*value
)
24432 switch (xmlSchemaGetWhiteSpaceFacetValue(type
)) {
24433 case XML_SCHEMA_WHITESPACE_COLLAPSE
:
24434 return (xmlSchemaCollapseString(value
));
24435 case XML_SCHEMA_WHITESPACE_REPLACE
:
24436 return (xmlSchemaWhiteSpaceReplace(value
));
24443 xmlSchemaValidateQName(xmlSchemaValidCtxtPtr vctxt
,
24444 const xmlChar
*value
,
24445 xmlSchemaValPtr
*val
,
24449 const xmlChar
*nsName
;
24450 xmlChar
*local
, *prefix
= NULL
;
24452 ret
= xmlValidateQName(value
, 1);
24455 VERROR_INT("xmlSchemaValidateQName",
24456 "calling xmlValidateQName()");
24459 return( XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1
);
24462 * NOTE: xmlSplitQName2 will always return a duplicated
24465 local
= xmlSplitQName2(value
, &prefix
);
24467 local
= xmlStrdup(value
);
24469 * OPTIMIZE TODO: Use flags for:
24470 * - is there any namespace binding?
24471 * - is there a default namespace?
24473 nsName
= xmlSchemaLookupNamespace(vctxt
, prefix
);
24475 if (prefix
!= NULL
) {
24478 * A namespace must be found if the prefix is
24481 if (nsName
== NULL
) {
24482 ret
= XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1
;
24483 xmlSchemaCustomErr(ACTXT_CAST vctxt
, ret
, NULL
,
24484 WXS_BASIC_CAST
xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME
),
24485 "The QName value '%s' has no "
24486 "corresponding namespace declaration in "
24487 "scope", value
, NULL
);
24493 if (valNeeded
&& val
) {
24494 if (nsName
!= NULL
)
24495 *val
= xmlSchemaNewQNameValue(
24496 BAD_CAST
xmlStrdup(nsName
), BAD_CAST local
);
24498 *val
= xmlSchemaNewQNameValue(NULL
,
24509 xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt
,
24511 xmlSchemaTypePtr type
,
24512 const xmlChar
*value
,
24513 xmlSchemaValPtr
*retVal
,
24518 int ret
= 0, valNeeded
= (retVal
) ? 1 : 0;
24519 xmlSchemaValPtr val
= NULL
;
24520 /* xmlSchemaWhitespaceValueType ws; */
24521 xmlChar
*normValue
= NULL
;
24523 #define NORMALIZE(atype) \
24524 if ((! isNormalized) && \
24525 (normalize || (type->flags & XML_SCHEMAS_TYPE_NORMVALUENEEDED))) { \
24526 normValue = xmlSchemaNormalizeValue(atype, value); \
24527 if (normValue != NULL) \
24528 value = normValue; \
24529 isNormalized = 1; \
24532 if ((retVal
!= NULL
) && (*retVal
!= NULL
)) {
24533 xmlSchemaFreeValue(*retVal
);
24537 * 3.14.4 Simple Type Definition Validation Rules
24538 * Validation Rule: String Valid
24541 * 1 It is schema-valid with respect to that definition as defined
24542 * by Datatype Valid in [XML Schemas: Datatypes].
24545 * 2.1 If The definition is ENTITY or is validly derived from ENTITY given
24546 * the empty set, as defined in Type Derivation OK (Simple) ($3.14.6), then
24547 * the string must be a `declared entity name`.
24550 * 2.2 If The definition is ENTITIES or is validly derived from ENTITIES
24551 * given the empty set, as defined in Type Derivation OK (Simple) ($3.14.6),
24552 * then every whitespace-delimited substring of the string must be a `declared
24556 * 2.3 otherwise no further condition applies.
24558 if ((! valNeeded
) && (type
->flags
& XML_SCHEMAS_TYPE_FACETSNEEDVALUE
))
24561 value
= BAD_CAST
"";
24562 if (WXS_IS_ANY_SIMPLE_TYPE(type
) || WXS_IS_ATOMIC(type
)) {
24563 xmlSchemaTypePtr biType
; /* The built-in type. */
24565 * SPEC (1.2.1) "if {variety} is `atomic` then the string must `match`
24566 * a literal in the `lexical space` of {base type definition}"
24569 * Whitespace-normalize.
24572 if (type
->type
!= XML_SCHEMA_TYPE_BASIC
) {
24574 * Get the built-in type.
24576 biType
= type
->baseType
;
24577 while ((biType
!= NULL
) &&
24578 (biType
->type
!= XML_SCHEMA_TYPE_BASIC
))
24579 biType
= biType
->baseType
;
24581 if (biType
== NULL
) {
24582 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24583 "could not get the built-in type");
24584 goto internal_error
;
24589 * NOTATIONs need to be processed here, since they need
24590 * to lookup in the hashtable of NOTATION declarations of the schema.
24592 if (actxt
->type
== XML_SCHEMA_CTXT_VALIDATOR
) {
24593 switch (biType
->builtInType
) {
24594 case XML_SCHEMAS_NOTATION
:
24595 ret
= xmlSchemaValidateNotation(
24596 (xmlSchemaValidCtxtPtr
) actxt
,
24597 ((xmlSchemaValidCtxtPtr
) actxt
)->schema
,
24598 NULL
, value
, &val
, valNeeded
);
24600 case XML_SCHEMAS_QNAME
:
24601 ret
= xmlSchemaValidateQName((xmlSchemaValidCtxtPtr
) actxt
,
24602 value
, &val
, valNeeded
);
24605 /* ws = xmlSchemaGetWhiteSpaceFacetValue(type); */
24607 ret
= xmlSchemaValPredefTypeNodeNoNorm(biType
,
24608 value
, &val
, node
);
24610 ret
= xmlSchemaValPredefTypeNodeNoNorm(biType
,
24611 value
, NULL
, node
);
24614 } else if (actxt
->type
== XML_SCHEMA_CTXT_PARSER
) {
24615 switch (biType
->builtInType
) {
24616 case XML_SCHEMAS_NOTATION
:
24617 ret
= xmlSchemaValidateNotation(NULL
,
24618 ((xmlSchemaParserCtxtPtr
) actxt
)->schema
, node
,
24619 value
, &val
, valNeeded
);
24622 /* ws = xmlSchemaGetWhiteSpaceFacetValue(type); */
24624 ret
= xmlSchemaValPredefTypeNodeNoNorm(biType
,
24625 value
, &val
, node
);
24627 ret
= xmlSchemaValPredefTypeNodeNoNorm(biType
,
24628 value
, NULL
, node
);
24633 * Validation via a public API is not implemented yet.
24636 goto internal_error
;
24640 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24641 "validating against a built-in type");
24642 goto internal_error
;
24644 if (WXS_IS_LIST(type
))
24645 ret
= XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2
;
24647 ret
= XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1
;
24649 if ((ret
== 0) && (type
->flags
& XML_SCHEMAS_TYPE_HAS_FACETS
)) {
24653 ret
= xmlSchemaValidateFacets(actxt
, node
, type
,
24654 (xmlSchemaValType
) biType
->builtInType
, value
, val
,
24658 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24659 "validating facets of atomic simple type");
24660 goto internal_error
;
24662 if (WXS_IS_LIST(type
))
24663 ret
= XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2
;
24665 ret
= XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1
;
24668 if (fireErrors
&& (ret
> 0))
24669 xmlSchemaSimpleTypeErr(actxt
, ret
, node
, value
, type
, 1);
24670 } else if (WXS_IS_LIST(type
)) {
24672 xmlSchemaTypePtr itemType
;
24673 const xmlChar
*cur
, *end
;
24674 xmlChar
*tmpValue
= NULL
;
24675 unsigned long len
= 0;
24676 xmlSchemaValPtr prevVal
= NULL
, curVal
= NULL
;
24677 /* 1.2.2 if {variety} is `list` then the string must be a sequence
24678 * of white space separated tokens, each of which `match`es a literal
24679 * in the `lexical space` of {item type definition}
24682 * Note that XML_SCHEMAS_TYPE_NORMVALUENEEDED will be set if
24683 * the list type has an enum or pattern facet.
24687 * VAL TODO: Optimize validation of empty values.
24688 * VAL TODO: We do not have computed values for lists.
24690 itemType
= WXS_LIST_ITEMTYPE(type
);
24693 while (IS_BLANK_CH(*cur
))
24696 while ((*end
!= 0) && (!(IS_BLANK_CH(*end
))))
24700 tmpValue
= xmlStrndup(cur
, end
- cur
);
24704 ret
= xmlSchemaVCheckCVCSimpleType(actxt
, node
, itemType
,
24705 tmpValue
, &curVal
, fireErrors
, 0, 1);
24707 ret
= xmlSchemaVCheckCVCSimpleType(actxt
, node
, itemType
,
24708 tmpValue
, NULL
, fireErrors
, 0, 1);
24709 FREE_AND_NULL(tmpValue
);
24710 if (curVal
!= NULL
) {
24712 * Add to list of computed values.
24717 xmlSchemaValueAppend(prevVal
, curVal
);
24723 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24724 "validating an item of list simple type");
24725 goto internal_error
;
24727 ret
= XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2
;
24731 } while (*cur
!= 0);
24732 FREE_AND_NULL(tmpValue
);
24733 if ((ret
== 0) && (type
->flags
& XML_SCHEMAS_TYPE_HAS_FACETS
)) {
24735 * Apply facets (pattern, enumeration).
24737 ret
= xmlSchemaValidateFacets(actxt
, node
, type
,
24738 XML_SCHEMAS_UNKNOWN
, value
, val
,
24742 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24743 "validating facets of list simple type");
24744 goto internal_error
;
24746 ret
= XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2
;
24749 if (fireErrors
&& (ret
> 0)) {
24751 * Report the normalized value.
24755 xmlSchemaSimpleTypeErr(actxt
, ret
, node
, value
, type
, 1);
24757 } else if (WXS_IS_UNION(type
)) {
24758 xmlSchemaTypeLinkPtr memberLink
;
24760 * TODO: For all datatypes `derived` by `union` whiteSpace does
24761 * not apply directly; however, the normalization behavior of `union`
24762 * types is controlled by the value of whiteSpace on that one of the
24763 * `memberTypes` against which the `union` is successfully validated.
24765 * This means that the value is normalized by the first validating
24766 * member type, then the facets of the union type are applied. This
24767 * needs changing of the value!
24771 * 1.2.3 if {variety} is `union` then the string must `match` a
24772 * literal in the `lexical space` of at least one member of
24773 * {member type definitions}
24775 memberLink
= xmlSchemaGetUnionSimpleTypeMemberTypes(type
);
24776 if (memberLink
== NULL
) {
24777 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24778 "union simple type has no member types");
24779 goto internal_error
;
24782 * Always normalize union type values, since we currently
24783 * cannot store the whitespace information with the value
24784 * itself; otherwise a later value-comparison would be
24787 while (memberLink
!= NULL
) {
24789 ret
= xmlSchemaVCheckCVCSimpleType(actxt
, node
,
24790 memberLink
->type
, value
, &val
, 0, 1, 0);
24792 ret
= xmlSchemaVCheckCVCSimpleType(actxt
, node
,
24793 memberLink
->type
, value
, NULL
, 0, 1, 0);
24796 memberLink
= memberLink
->next
;
24800 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24801 "validating members of union simple type");
24802 goto internal_error
;
24804 ret
= XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3
;
24807 * Apply facets (pattern, enumeration).
24809 if ((ret
== 0) && (type
->flags
& XML_SCHEMAS_TYPE_HAS_FACETS
)) {
24811 * The normalization behavior of `union` types is controlled by
24812 * the value of whiteSpace on that one of the `memberTypes`
24813 * against which the `union` is successfully validated.
24815 NORMALIZE(memberLink
->type
);
24816 ret
= xmlSchemaValidateFacets(actxt
, node
, type
,
24817 XML_SCHEMAS_UNKNOWN
, value
, val
,
24821 AERROR_INT("xmlSchemaVCheckCVCSimpleType",
24822 "validating facets of union simple type");
24823 goto internal_error
;
24825 ret
= XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3
;
24828 if (fireErrors
&& (ret
> 0))
24829 xmlSchemaSimpleTypeErr(actxt
, ret
, node
, value
, type
, 1);
24832 if (normValue
!= NULL
)
24833 xmlFree(normValue
);
24835 if (retVal
!= NULL
)
24837 else if (val
!= NULL
)
24838 xmlSchemaFreeValue(val
);
24839 } else if (val
!= NULL
)
24840 xmlSchemaFreeValue(val
);
24843 if (normValue
!= NULL
)
24844 xmlFree(normValue
);
24846 xmlSchemaFreeValue(val
);
24851 xmlSchemaVExpandQName(xmlSchemaValidCtxtPtr vctxt
,
24852 const xmlChar
*value
,
24853 const xmlChar
**nsName
,
24854 const xmlChar
**localName
)
24858 if ((nsName
== NULL
) || (localName
== NULL
))
24863 ret
= xmlValidateQName(value
, 1);
24867 xmlSchemaSimpleTypeErr(ACTXT_CAST vctxt
,
24868 XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1
, NULL
,
24869 value
, xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME
), 1);
24873 xmlChar
*local
= NULL
;
24877 * NOTE: xmlSplitQName2 will return a duplicated
24880 local
= xmlSplitQName2(value
, &prefix
);
24882 *localName
= xmlDictLookup(vctxt
->dict
, value
, -1);
24884 *localName
= xmlDictLookup(vctxt
->dict
, local
, -1);
24888 *nsName
= xmlSchemaLookupNamespace(vctxt
, prefix
);
24890 if (prefix
!= NULL
) {
24893 * A namespace must be found if the prefix is NOT NULL.
24895 if (*nsName
== NULL
) {
24896 xmlSchemaCustomErr(ACTXT_CAST vctxt
,
24897 XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1
, NULL
,
24898 WXS_BASIC_CAST
xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME
),
24899 "The QName value '%s' has no "
24900 "corresponding namespace declaration in scope",
24910 xmlSchemaProcessXSIType(xmlSchemaValidCtxtPtr vctxt
,
24911 xmlSchemaAttrInfoPtr iattr
,
24912 xmlSchemaTypePtr
*localType
,
24913 xmlSchemaElementPtr elemDecl
)
24917 * cvc-elt (3.3.4) : (4)
24919 * Schema-Validity Assessment (Element) (cvc-assess-elt)
24920 * (1.2.1.2.1) - (1.2.1.2.4)
24921 * Handle 'xsi:type'.
24923 if (localType
== NULL
)
24929 const xmlChar
*nsName
= NULL
, *local
= NULL
;
24931 * TODO: We should report a *warning* that the type was overriden
24934 ACTIVATE_ATTRIBUTE(iattr
);
24936 * (cvc-elt) (3.3.4) : (4.1)
24937 * (cvc-assess-elt) (1.2.1.2.2)
24939 ret
= xmlSchemaVExpandQName(vctxt
, iattr
->value
,
24943 VERROR_INT("xmlSchemaValidateElementByDeclaration",
24944 "calling xmlSchemaQNameExpand() to validate the "
24945 "attribute 'xsi:type'");
24946 goto internal_error
;
24951 * (cvc-elt) (3.3.4) : (4.2)
24952 * (cvc-assess-elt) (1.2.1.2.3)
24954 *localType
= xmlSchemaGetType(vctxt
->schema
, local
, nsName
);
24955 if (*localType
== NULL
) {
24956 xmlChar
*str
= NULL
;
24958 xmlSchemaCustomErr(ACTXT_CAST vctxt
,
24959 XML_SCHEMAV_CVC_ELT_4_2
, NULL
,
24960 WXS_BASIC_CAST
xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME
),
24961 "The QName value '%s' of the xsi:type attribute does not "
24962 "resolve to a type definition",
24963 xmlSchemaFormatQName(&str
, nsName
, local
), NULL
);
24964 FREE_AND_NULL(str
);
24968 if (elemDecl
!= NULL
) {
24972 * SPEC cvc-elt (3.3.4) : (4.3) (Type Derivation OK)
24973 * "The `local type definition` must be validly
24974 * derived from the {type definition} given the union of
24975 * the {disallowed substitutions} and the {type definition}'s
24976 * {prohibited substitutions}, as defined in
24977 * Type Derivation OK (Complex) ($3.4.6)
24978 * (if it is a complex type definition),
24979 * or given {disallowed substitutions} as defined in Type
24980 * Derivation OK (Simple) ($3.14.6) (if it is a simple type
24983 * {disallowed substitutions}: the "block" on the element decl.
24984 * {prohibited substitutions}: the "block" on the type def.
24987 * OPTIMIZE TODO: We could map types already evaluated
24988 * to be validly derived from other types to avoid checking
24989 * this over and over for the same types.
24991 if ((elemDecl
->flags
& XML_SCHEMAS_ELEM_BLOCK_EXTENSION
) ||
24992 (elemDecl
->subtypes
->flags
&
24993 XML_SCHEMAS_TYPE_BLOCK_EXTENSION
))
24994 set
|= SUBSET_EXTENSION
;
24996 if ((elemDecl
->flags
& XML_SCHEMAS_ELEM_BLOCK_RESTRICTION
) ||
24997 (elemDecl
->subtypes
->flags
&
24998 XML_SCHEMAS_TYPE_BLOCK_RESTRICTION
))
24999 set
|= SUBSET_RESTRICTION
;
25002 * REMOVED and CHANGED since this produced a parser context
25003 * which adds to the string dict of the schema. So this would
25004 * change the schema and we don't want this. We don't need
25005 * the parser context anymore.
25007 * if ((vctxt->pctxt == NULL) &&
25008 * (xmlSchemaCreatePCtxtOnVCtxt(vctxt) == -1))
25012 if (xmlSchemaCheckCOSDerivedOK(ACTXT_CAST vctxt
, *localType
,
25013 elemDecl
->subtypes
, set
) != 0) {
25014 xmlChar
*str
= NULL
;
25016 xmlSchemaCustomErr(ACTXT_CAST vctxt
,
25017 XML_SCHEMAV_CVC_ELT_4_3
, NULL
, NULL
,
25018 "The type definition '%s', specified by xsi:type, is "
25019 "blocked or not validly derived from the type definition "
25020 "of the element declaration",
25021 xmlSchemaFormatQName(&str
,
25022 (*localType
)->targetNamespace
,
25023 (*localType
)->name
),
25025 FREE_AND_NULL(str
);
25040 xmlSchemaValidateElemDecl(xmlSchemaValidCtxtPtr vctxt
)
25042 xmlSchemaElementPtr elemDecl
= vctxt
->inode
->decl
;
25043 xmlSchemaTypePtr actualType
;
25046 * cvc-elt (3.3.4) : 1
25048 if (elemDecl
== NULL
) {
25049 VERROR(XML_SCHEMAV_CVC_ELT_1
, NULL
,
25050 "No matching declaration available");
25051 return (vctxt
->err
);
25053 actualType
= WXS_ELEM_TYPEDEF(elemDecl
);
25055 * cvc-elt (3.3.4) : 2
25057 if (elemDecl
->flags
& XML_SCHEMAS_ELEM_ABSTRACT
) {
25058 VERROR(XML_SCHEMAV_CVC_ELT_2
, NULL
,
25059 "The element declaration is abstract");
25060 return (vctxt
->err
);
25062 if (actualType
== NULL
) {
25063 VERROR(XML_SCHEMAV_CVC_TYPE_1
, NULL
,
25064 "The type definition is absent");
25065 return (XML_SCHEMAV_CVC_TYPE_1
);
25067 if (vctxt
->nbAttrInfos
!= 0) {
25069 xmlSchemaAttrInfoPtr iattr
;
25071 * cvc-elt (3.3.4) : 3
25072 * Handle 'xsi:nil'.
25074 iattr
= xmlSchemaGetMetaAttrInfo(vctxt
,
25075 XML_SCHEMA_ATTR_INFO_META_XSI_NIL
);
25077 ACTIVATE_ATTRIBUTE(iattr
);
25079 * Validate the value.
25081 ret
= xmlSchemaVCheckCVCSimpleType(
25082 ACTXT_CAST vctxt
, NULL
,
25083 xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN
),
25084 iattr
->value
, &(iattr
->val
), 1, 0, 0);
25087 VERROR_INT("xmlSchemaValidateElemDecl",
25088 "calling xmlSchemaVCheckCVCSimpleType() to "
25089 "validate the attribute 'xsi:nil'");
25093 if ((elemDecl
->flags
& XML_SCHEMAS_ELEM_NILLABLE
) == 0) {
25095 * cvc-elt (3.3.4) : 3.1
25097 VERROR(XML_SCHEMAV_CVC_ELT_3_1
, NULL
,
25098 "The element is not 'nillable'");
25099 /* Does not return an error on purpose. */
25101 if (xmlSchemaValueGetAsBoolean(iattr
->val
)) {
25103 * cvc-elt (3.3.4) : 3.2.2
25105 if ((elemDecl
->flags
& XML_SCHEMAS_ELEM_FIXED
) &&
25106 (elemDecl
->value
!= NULL
)) {
25107 VERROR(XML_SCHEMAV_CVC_ELT_3_2_2
, NULL
,
25108 "The element cannot be 'nilled' because "
25109 "there is a fixed value constraint defined "
25111 /* Does not return an error on purpose. */
25113 vctxt
->inode
->flags
|=
25114 XML_SCHEMA_ELEM_INFO_NILLED
;
25120 * cvc-elt (3.3.4) : 4
25121 * Handle 'xsi:type'.
25123 iattr
= xmlSchemaGetMetaAttrInfo(vctxt
,
25124 XML_SCHEMA_ATTR_INFO_META_XSI_TYPE
);
25126 xmlSchemaTypePtr localType
= NULL
;
25128 ret
= xmlSchemaProcessXSIType(vctxt
, iattr
, &localType
,
25132 VERROR_INT("xmlSchemaValidateElemDecl",
25133 "calling xmlSchemaProcessXSIType() to "
25134 "process the attribute 'xsi:type'");
25137 /* Does not return an error on purpose. */
25139 if (localType
!= NULL
) {
25140 vctxt
->inode
->flags
|= XML_SCHEMA_ELEM_INFO_LOCAL_TYPE
;
25141 actualType
= localType
;
25146 * IDC: Register identity-constraint XPath matchers.
25148 if ((elemDecl
->idcs
!= NULL
) &&
25149 (xmlSchemaIDCRegisterMatchers(vctxt
, elemDecl
) == -1))
25152 * No actual type definition.
25154 if (actualType
== NULL
) {
25155 VERROR(XML_SCHEMAV_CVC_TYPE_1
, NULL
,
25156 "The type definition is absent");
25157 return (XML_SCHEMAV_CVC_TYPE_1
);
25160 * Remember the actual type definition.
25162 vctxt
->inode
->typeDef
= actualType
;
25168 xmlSchemaVAttributesSimple(xmlSchemaValidCtxtPtr vctxt
)
25170 xmlSchemaAttrInfoPtr iattr
;
25174 * SPEC cvc-type (3.1.1)
25175 * "The attributes of must be empty, excepting those whose namespace
25176 * name is identical to http://www.w3.org/2001/XMLSchema-instance and
25177 * whose local name is one of type, nil, schemaLocation or
25178 * noNamespaceSchemaLocation."
25180 if (vctxt
->nbAttrInfos
== 0)
25182 for (i
= 0; i
< vctxt
->nbAttrInfos
; i
++) {
25183 iattr
= vctxt
->attrInfos
[i
];
25184 if (! iattr
->metaType
) {
25185 ACTIVATE_ATTRIBUTE(iattr
)
25186 xmlSchemaIllegalAttrErr(ACTXT_CAST vctxt
,
25187 XML_SCHEMAV_CVC_TYPE_3_1_1
, iattr
, NULL
);
25188 ret
= XML_SCHEMAV_CVC_TYPE_3_1_1
;
25196 * Cleanup currently used attribute infos.
25199 xmlSchemaClearAttrInfos(xmlSchemaValidCtxtPtr vctxt
)
25202 xmlSchemaAttrInfoPtr attr
;
25204 if (vctxt
->nbAttrInfos
== 0)
25206 for (i
= 0; i
< vctxt
->nbAttrInfos
; i
++) {
25207 attr
= vctxt
->attrInfos
[i
];
25208 if (attr
->flags
& XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES
) {
25209 if (attr
->localName
!= NULL
)
25210 xmlFree((xmlChar
*) attr
->localName
);
25211 if (attr
->nsName
!= NULL
)
25212 xmlFree((xmlChar
*) attr
->nsName
);
25214 if (attr
->flags
& XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES
) {
25215 if (attr
->value
!= NULL
)
25216 xmlFree((xmlChar
*) attr
->value
);
25218 if (attr
->val
!= NULL
) {
25219 xmlSchemaFreeValue(attr
->val
);
25222 memset(attr
, 0, sizeof(xmlSchemaAttrInfo
));
25224 vctxt
->nbAttrInfos
= 0;
25228 * 3.4.4 Complex Type Definition Validation Rules
25229 * Element Locally Valid (Complex Type) (cvc-complex-type)
25230 * 3.2.4 Attribute Declaration Validation Rules
25231 * Validation Rule: Attribute Locally Valid (cvc-attribute)
25232 * Attribute Locally Valid (Use) (cvc-au)
25234 * Only "assessed" attribute information items will be visible to
25235 * IDCs. I.e. not "lax" (without declaration) and "skip" wild attributes.
25238 xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt
)
25240 xmlSchemaTypePtr type
= vctxt
->inode
->typeDef
;
25241 xmlSchemaItemListPtr attrUseList
;
25242 xmlSchemaAttributeUsePtr attrUse
= NULL
;
25243 xmlSchemaAttributePtr attrDecl
= NULL
;
25244 xmlSchemaAttrInfoPtr iattr
, tmpiattr
;
25245 int i
, j
, found
, nbAttrs
, nbUses
;
25246 int xpathRes
= 0, res
, wildIDs
= 0, fixed
;
25247 xmlNodePtr defAttrOwnerElem
= NULL
;
25250 * SPEC (cvc-attribute)
25251 * (1) "The declaration must not be `absent` (see Missing
25252 * Sub-components ($5.3) for how this can fail to be
25254 * (2) "Its {type definition} must not be absent."
25256 * NOTE (1) + (2): This is not handled here, since we currently do not
25257 * allow validation against schemas which have missing sub-components.
25259 * SPEC (cvc-complex-type)
25260 * (3) "For each attribute information item in the element information
25261 * item's [attributes] excepting those whose [namespace name] is
25262 * identical to http://www.w3.org/2001/XMLSchema-instance and whose
25263 * [local name] is one of type, nil, schemaLocation or
25264 * noNamespaceSchemaLocation, the appropriate case among the following
25268 attrUseList
= (xmlSchemaItemListPtr
) type
->attrUses
;
25270 * @nbAttrs is the number of attributes present in the instance.
25272 nbAttrs
= vctxt
->nbAttrInfos
;
25273 if (attrUseList
!= NULL
)
25274 nbUses
= attrUseList
->nbItems
;
25277 for (i
= 0; i
< nbUses
; i
++) {
25279 attrUse
= attrUseList
->items
[i
];
25280 attrDecl
= WXS_ATTRUSE_DECL(attrUse
);
25281 for (j
= 0; j
< nbAttrs
; j
++) {
25282 iattr
= vctxt
->attrInfos
[j
];
25284 * SPEC (cvc-complex-type) (3)
25285 * Skip meta attributes.
25287 if (iattr
->metaType
)
25289 if (iattr
->localName
[0] != attrDecl
->name
[0])
25291 if (!xmlStrEqual(iattr
->localName
, attrDecl
->name
))
25293 if (!xmlStrEqual(iattr
->nsName
, attrDecl
->targetNamespace
))
25297 * SPEC (cvc-complex-type)
25298 * (3.1) "If there is among the {attribute uses} an attribute
25299 * use with an {attribute declaration} whose {name} matches
25300 * the attribute information item's [local name] and whose
25301 * {target namespace} is identical to the attribute information
25302 * item's [namespace name] (where an `absent` {target namespace}
25303 * is taken to be identical to a [namespace name] with no value),
25304 * then the attribute information must be `valid` with respect
25305 * to that attribute use as per Attribute Locally Valid (Use)
25306 * ($3.5.4). In this case the {attribute declaration} of that
25307 * attribute use is the `context-determined declaration` for the
25308 * attribute information item with respect to Schema-Validity
25309 * Assessment (Attribute) ($3.2.4) and
25310 * Assessment Outcome (Attribute) ($3.2.5).
25312 iattr
->state
= XML_SCHEMAS_ATTR_ASSESSED
;
25313 iattr
->use
= attrUse
;
25315 * Context-determined declaration.
25317 iattr
->decl
= attrDecl
;
25318 iattr
->typeDef
= attrDecl
->subtypes
;
25325 if (attrUse
->occurs
== XML_SCHEMAS_ATTR_USE_REQUIRED
) {
25327 * Handle non-existent, required attributes.
25329 * SPEC (cvc-complex-type)
25330 * (4) "The {attribute declaration} of each attribute use in
25331 * the {attribute uses} whose {required} is true matches one
25332 * of the attribute information items in the element information
25333 * item's [attributes] as per clause 3.1 above."
25335 tmpiattr
= xmlSchemaGetFreshAttrInfo(vctxt
);
25336 if (tmpiattr
== NULL
) {
25338 "xmlSchemaVAttributesComplex",
25339 "calling xmlSchemaGetFreshAttrInfo()");
25342 tmpiattr
->state
= XML_SCHEMAS_ATTR_ERR_MISSING
;
25343 tmpiattr
->use
= attrUse
;
25344 tmpiattr
->decl
= attrDecl
;
25345 } else if ((attrUse
->occurs
== XML_SCHEMAS_ATTR_USE_OPTIONAL
) &&
25346 ((attrUse
->defValue
!= NULL
) ||
25347 (attrDecl
->defValue
!= NULL
))) {
25349 * Handle non-existent, optional, default/fixed attributes.
25351 tmpiattr
= xmlSchemaGetFreshAttrInfo(vctxt
);
25352 if (tmpiattr
== NULL
) {
25354 "xmlSchemaVAttributesComplex",
25355 "calling xmlSchemaGetFreshAttrInfo()");
25358 tmpiattr
->state
= XML_SCHEMAS_ATTR_DEFAULT
;
25359 tmpiattr
->use
= attrUse
;
25360 tmpiattr
->decl
= attrDecl
;
25361 tmpiattr
->typeDef
= attrDecl
->subtypes
;
25362 tmpiattr
->localName
= attrDecl
->name
;
25363 tmpiattr
->nsName
= attrDecl
->targetNamespace
;
25367 if (vctxt
->nbAttrInfos
== 0)
25370 * Validate against the wildcard.
25372 if (type
->attributeWildcard
!= NULL
) {
25374 * SPEC (cvc-complex-type)
25375 * (3.2.1) "There must be an {attribute wildcard}."
25377 for (i
= 0; i
< nbAttrs
; i
++) {
25378 iattr
= vctxt
->attrInfos
[i
];
25380 * SPEC (cvc-complex-type) (3)
25381 * Skip meta attributes.
25383 if (iattr
->state
!= XML_SCHEMAS_ATTR_UNKNOWN
)
25386 * SPEC (cvc-complex-type)
25387 * (3.2.2) "The attribute information item must be `valid` with
25388 * respect to it as defined in Item Valid (Wildcard) ($3.10.4)."
25390 * SPEC Item Valid (Wildcard) (cvc-wildcard)
25391 * "... its [namespace name] must be `valid` with respect to
25392 * the wildcard constraint, as defined in Wildcard allows
25393 * Namespace Name ($3.10.4)."
25395 if (xmlSchemaCheckCVCWildcardNamespace(type
->attributeWildcard
,
25396 iattr
->nsName
) == 0) {
25398 * Handle processContents.
25400 * SPEC (cvc-wildcard):
25401 * processContents | context-determined declaration:
25402 * "strict" "mustFind"
25406 if (type
->attributeWildcard
->processContents
==
25407 XML_SCHEMAS_ANY_SKIP
) {
25409 * context-determined declaration = "skip"
25411 * SPEC PSVI Assessment Outcome (Attribute)
25412 * [validity] = "notKnown"
25413 * [validation attempted] = "none"
25415 iattr
->state
= XML_SCHEMAS_ATTR_WILD_SKIP
;
25419 * Find an attribute declaration.
25421 iattr
->decl
= xmlSchemaGetAttributeDecl(vctxt
->schema
,
25422 iattr
->localName
, iattr
->nsName
);
25423 if (iattr
->decl
!= NULL
) {
25424 iattr
->state
= XML_SCHEMAS_ATTR_ASSESSED
;
25426 * SPEC (cvc-complex-type)
25427 * (5) "Let [Definition:] the wild IDs be the set of
25428 * all attribute information item to which clause 3.2
25429 * applied and whose `validation` resulted in a
25430 * `context-determined declaration` of mustFind or no
25431 * `context-determined declaration` at all, and whose
25432 * [local name] and [namespace name] resolve (as
25433 * defined by QName resolution (Instance) ($3.15.4)) to
25434 * an attribute declaration whose {type definition} is
25435 * or is derived from ID. Then all of the following
25438 iattr
->typeDef
= WXS_ATTR_TYPEDEF(iattr
->decl
);
25439 if (xmlSchemaIsDerivedFromBuiltInType(
25440 iattr
->typeDef
, XML_SCHEMAS_ID
)) {
25442 * SPEC (5.1) "There must be no more than one
25443 * item in `wild IDs`."
25445 if (wildIDs
!= 0) {
25447 iattr
->state
= XML_SCHEMAS_ATTR_ERR_WILD_DUPLICATE_ID
;
25453 * SPEC (cvc-complex-type)
25454 * (5.2) "If `wild IDs` is non-empty, there must not
25455 * be any attribute uses among the {attribute uses}
25456 * whose {attribute declaration}'s {type definition}
25457 * is or is derived from ID."
25459 if (attrUseList
!= NULL
) {
25460 for (j
= 0; j
< attrUseList
->nbItems
; j
++) {
25461 if (xmlSchemaIsDerivedFromBuiltInType(
25462 WXS_ATTRUSE_TYPEDEF(attrUseList
->items
[j
]),
25464 /* URGENT VAL TODO: implement */
25465 iattr
->state
= XML_SCHEMAS_ATTR_ERR_WILD_AND_USE_ID
;
25472 } else if (type
->attributeWildcard
->processContents
==
25473 XML_SCHEMAS_ANY_LAX
) {
25474 iattr
->state
= XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL
;
25476 * SPEC PSVI Assessment Outcome (Attribute)
25477 * [validity] = "notKnown"
25478 * [validation attempted] = "none"
25481 iattr
->state
= XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL
;
25487 if (vctxt
->nbAttrInfos
== 0)
25491 * Get the owner element; needed for creation of default attributes.
25492 * This fixes bug #341337, reported by David Grohmann.
25494 if (vctxt
->options
& XML_SCHEMA_VAL_VC_I_CREATE
) {
25495 xmlSchemaNodeInfoPtr ielem
= vctxt
->elemInfos
[vctxt
->depth
];
25496 if (ielem
&& ielem
->node
&& ielem
->node
->doc
)
25497 defAttrOwnerElem
= ielem
->node
;
25500 * Validate values, create default attributes, evaluate IDCs.
25502 for (i
= 0; i
< vctxt
->nbAttrInfos
; i
++) {
25503 iattr
= vctxt
->attrInfos
[i
];
25505 * VAL TODO: Note that we won't try to resolve IDCs to
25506 * "lax" and "skip" validated attributes. Check what to
25509 if ((iattr
->state
!= XML_SCHEMAS_ATTR_ASSESSED
) &&
25510 (iattr
->state
!= XML_SCHEMAS_ATTR_DEFAULT
))
25513 * VAL TODO: What to do if the type definition is missing?
25515 if (iattr
->typeDef
== NULL
) {
25516 iattr
->state
= XML_SCHEMAS_ATTR_ERR_NO_TYPE
;
25520 ACTIVATE_ATTRIBUTE(iattr
);
25524 if (vctxt
->xpathStates
!= NULL
) {
25528 xpathRes
= xmlSchemaXPathEvaluate(vctxt
,
25529 XML_ATTRIBUTE_NODE
);
25530 if (xpathRes
== -1) {
25531 VERROR_INT("xmlSchemaVAttributesComplex",
25532 "calling xmlSchemaXPathEvaluate()");
25533 goto internal_error
;
25537 if (iattr
->state
== XML_SCHEMAS_ATTR_DEFAULT
) {
25539 * Default/fixed attributes.
25540 * We need the value only if we need to resolve IDCs or
25541 * will create default attributes.
25543 if ((xpathRes
) || (defAttrOwnerElem
)) {
25544 if (iattr
->use
->defValue
!= NULL
) {
25545 iattr
->value
= (xmlChar
*) iattr
->use
->defValue
;
25546 iattr
->val
= iattr
->use
->defVal
;
25548 iattr
->value
= (xmlChar
*) iattr
->decl
->defValue
;
25549 iattr
->val
= iattr
->decl
->defVal
;
25552 * IDCs will consume the precomputed default value,
25553 * so we need to clone it.
25555 if (iattr
->val
== NULL
) {
25556 VERROR_INT("xmlSchemaVAttributesComplex",
25557 "default/fixed value on an attribute use was "
25558 "not precomputed");
25559 goto internal_error
;
25561 iattr
->val
= xmlSchemaCopyValue(iattr
->val
);
25562 if (iattr
->val
== NULL
) {
25563 VERROR_INT("xmlSchemaVAttributesComplex",
25564 "calling xmlSchemaCopyValue()");
25565 goto internal_error
;
25569 * PSVI: Add the default attribute to the current element.
25570 * VAL TODO: Should we use the *normalized* value? This currently
25571 * uses the *initial* value.
25574 if (defAttrOwnerElem
) {
25575 xmlChar
*normValue
;
25576 const xmlChar
*value
;
25578 value
= iattr
->value
;
25580 * Normalize the value.
25582 normValue
= xmlSchemaNormalizeValue(iattr
->typeDef
,
25584 if (normValue
!= NULL
)
25585 value
= BAD_CAST normValue
;
25587 if (iattr
->nsName
== NULL
) {
25588 if (xmlNewProp(defAttrOwnerElem
,
25589 iattr
->localName
, value
) == NULL
) {
25590 VERROR_INT("xmlSchemaVAttributesComplex",
25591 "calling xmlNewProp()");
25592 if (normValue
!= NULL
)
25593 xmlFree(normValue
);
25594 goto internal_error
;
25599 ns
= xmlSearchNsByHref(defAttrOwnerElem
->doc
,
25600 defAttrOwnerElem
, iattr
->nsName
);
25602 xmlChar prefix
[12];
25606 * Create a namespace declaration on the validation
25607 * root node if no namespace declaration is in scope.
25610 snprintf((char *) prefix
, 12, "p%d", counter
++);
25611 ns
= xmlSearchNs(defAttrOwnerElem
->doc
,
25612 defAttrOwnerElem
, BAD_CAST prefix
);
25613 if (counter
> 1000) {
25615 "xmlSchemaVAttributesComplex",
25616 "could not compute a ns prefix for a "
25617 "default/fixed attribute");
25618 if (normValue
!= NULL
)
25619 xmlFree(normValue
);
25620 goto internal_error
;
25622 } while (ns
!= NULL
);
25623 ns
= xmlNewNs(vctxt
->validationRoot
,
25624 iattr
->nsName
, BAD_CAST prefix
);
25628 * http://lists.w3.org/Archives/Public/www-xml-schema-comments/2005JulSep/0406.html
25629 * If we have QNames: do we need to ensure there's a
25630 * prefix defined for the QName?
25632 xmlNewNsProp(defAttrOwnerElem
, ns
, iattr
->localName
, value
);
25634 if (normValue
!= NULL
)
25635 xmlFree(normValue
);
25638 * Go directly to IDC evaluation.
25643 * Validate the value.
25645 if (vctxt
->value
!= NULL
) {
25647 * Free last computed value; just for safety reasons.
25649 xmlSchemaFreeValue(vctxt
->value
);
25650 vctxt
->value
= NULL
;
25653 * Note that the attribute *use* can be unavailable, if
25654 * the attribute was a wild attribute.
25656 if ((iattr
->decl
->flags
& XML_SCHEMAS_ATTR_FIXED
) ||
25657 ((iattr
->use
!= NULL
) &&
25658 (iattr
->use
->flags
& XML_SCHEMAS_ATTR_FIXED
)))
25663 * SPEC (cvc-attribute)
25664 * (3) "The item's `normalized value` must be locally `valid`
25665 * with respect to that {type definition} as per
25666 * String Valid ($3.14.4)."
25668 * VAL TODO: Do we already have the
25669 * "normalized attribute value" here?
25671 if (xpathRes
|| fixed
) {
25672 iattr
->flags
|= XML_SCHEMA_NODE_INFO_VALUE_NEEDED
;
25674 * Request a computed value.
25676 res
= xmlSchemaVCheckCVCSimpleType(
25678 iattr
->node
, iattr
->typeDef
, iattr
->value
, &(iattr
->val
),
25681 res
= xmlSchemaVCheckCVCSimpleType(
25683 iattr
->node
, iattr
->typeDef
, iattr
->value
, NULL
,
25689 VERROR_INT("xmlSchemaVAttributesComplex",
25690 "calling xmlSchemaStreamValidateSimpleTypeValue()");
25691 goto internal_error
;
25693 iattr
->state
= XML_SCHEMAS_ATTR_INVALID_VALUE
;
25695 * SPEC PSVI Assessment Outcome (Attribute)
25696 * [validity] = "invalid"
25703 * SPEC Attribute Locally Valid (Use) (cvc-au)
25704 * "For an attribute information item to be `valid`
25705 * with respect to an attribute use its *normalized*
25706 * value must match the *canonical* lexical
25707 * representation of the attribute use's {value
25708 * constraint}value, if it is present and fixed."
25710 * VAL TODO: The requirement for the *canonical* value
25711 * will be removed in XML Schema 1.1.
25714 * SPEC Attribute Locally Valid (cvc-attribute)
25715 * (4) "The item's *actual* value must match the *value* of
25716 * the {value constraint}, if it is present and fixed."
25718 if (iattr
->val
== NULL
) {
25719 /* VAL TODO: A value was not precomputed. */
25723 if ((iattr
->use
!= NULL
) &&
25724 (iattr
->use
->defValue
!= NULL
)) {
25725 if (iattr
->use
->defVal
== NULL
) {
25726 /* VAL TODO: A default value was not precomputed. */
25730 iattr
->vcValue
= iattr
->use
->defValue
;
25732 if (xmlSchemaCompareValuesWhtsp(attr->val,
25733 (xmlSchemaWhitespaceValueType) ws,
25735 (xmlSchemaWhitespaceValueType) ws) != 0) {
25737 if (! xmlSchemaAreValuesEqual(iattr
->val
, iattr
->use
->defVal
))
25738 iattr
->state
= XML_SCHEMAS_ATTR_ERR_FIXED_VALUE
;
25740 if (iattr
->decl
->defVal
== NULL
) {
25741 /* VAL TODO: A default value was not precomputed. */
25745 iattr
->vcValue
= iattr
->decl
->defValue
;
25747 if (xmlSchemaCompareValuesWhtsp(attr->val,
25748 (xmlSchemaWhitespaceValueType) ws,
25750 (xmlSchemaWhitespaceValueType) ws) != 0) {
25752 if (! xmlSchemaAreValuesEqual(iattr
->val
, iattr
->decl
->defVal
))
25753 iattr
->state
= XML_SCHEMAS_ATTR_ERR_FIXED_VALUE
;
25756 * [validity] = "valid"
25764 if (xmlSchemaXPathProcessHistory(vctxt
,
25765 vctxt
->depth
+1) == -1) {
25766 VERROR_INT("xmlSchemaVAttributesComplex",
25767 "calling xmlSchemaXPathEvaluate()");
25768 goto internal_error
;
25770 } else if (vctxt
->xpathStates
!= NULL
)
25771 xmlSchemaXPathPop(vctxt
);
25777 for (i
= 0; i
< vctxt
->nbAttrInfos
; i
++) {
25778 iattr
= vctxt
->attrInfos
[i
];
25779 if ((iattr
->state
== XML_SCHEMAS_ATTR_META
) ||
25780 (iattr
->state
== XML_SCHEMAS_ATTR_ASSESSED
) ||
25781 (iattr
->state
== XML_SCHEMAS_ATTR_WILD_SKIP
) ||
25782 (iattr
->state
== XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL
))
25784 ACTIVATE_ATTRIBUTE(iattr
);
25785 switch (iattr
->state
) {
25786 case XML_SCHEMAS_ATTR_ERR_MISSING
: {
25787 xmlChar
*str
= NULL
;
25789 xmlSchemaCustomErr(ACTXT_CAST vctxt
,
25790 XML_SCHEMAV_CVC_COMPLEX_TYPE_4
, NULL
, NULL
,
25791 "The attribute '%s' is required but missing",
25792 xmlSchemaFormatQName(&str
,
25793 iattr
->decl
->targetNamespace
,
25794 iattr
->decl
->name
),
25799 case XML_SCHEMAS_ATTR_ERR_NO_TYPE
:
25800 VERROR(XML_SCHEMAV_CVC_ATTRIBUTE_2
, NULL
,
25801 "The type definition is absent");
25803 case XML_SCHEMAS_ATTR_ERR_FIXED_VALUE
:
25804 xmlSchemaCustomErr(ACTXT_CAST vctxt
,
25805 XML_SCHEMAV_CVC_AU
, NULL
, NULL
,
25806 "The value '%s' does not match the fixed "
25807 "value constraint '%s'",
25808 iattr
->value
, iattr
->vcValue
);
25810 case XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL
:
25811 VERROR(XML_SCHEMAV_CVC_WILDCARD
, NULL
,
25812 "No matching global attribute declaration available, but "
25813 "demanded by the strict wildcard");
25815 case XML_SCHEMAS_ATTR_UNKNOWN
:
25816 if (iattr
->metaType
)
25819 * MAYBE VAL TODO: One might report different error messages
25820 * for the following errors.
25822 if (type
->attributeWildcard
== NULL
) {
25823 xmlSchemaIllegalAttrErr(ACTXT_CAST vctxt
,
25824 XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_1
, iattr
, NULL
);
25826 xmlSchemaIllegalAttrErr(ACTXT_CAST vctxt
,
25827 XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_2
, iattr
, NULL
);
25843 xmlSchemaValidateElemWildcard(xmlSchemaValidCtxtPtr vctxt
,
25846 xmlSchemaWildcardPtr wild
= (xmlSchemaWildcardPtr
) vctxt
->inode
->decl
;
25848 * The namespace of the element was already identified to be
25849 * matching the wildcard.
25851 if ((skip
== NULL
) || (wild
== NULL
) ||
25852 (wild
->type
!= XML_SCHEMA_TYPE_ANY
)) {
25853 VERROR_INT("xmlSchemaValidateElemWildcard",
25858 if (wild
->processContents
== XML_SCHEMAS_ANY_SKIP
) {
25860 * URGENT VAL TODO: Either we need to position the stream to the
25861 * next sibling, or walk the whole subtree.
25867 xmlSchemaElementPtr decl
= NULL
;
25869 decl
= xmlSchemaGetElem(vctxt
->schema
,
25870 vctxt
->inode
->localName
, vctxt
->inode
->nsName
);
25871 if (decl
!= NULL
) {
25872 vctxt
->inode
->decl
= decl
;
25876 if (wild
->processContents
== XML_SCHEMAS_ANY_STRICT
) {
25877 /* VAL TODO: Change to proper error code. */
25878 VERROR(XML_SCHEMAV_CVC_ELT_1
, NULL
, /* WXS_BASIC_CAST wild */
25879 "No matching global element declaration available, but "
25880 "demanded by the strict wildcard");
25881 return (vctxt
->err
);
25883 if (vctxt
->nbAttrInfos
!= 0) {
25884 xmlSchemaAttrInfoPtr iattr
;
25886 * SPEC Validation Rule: Schema-Validity Assessment (Element)
25887 * (1.2.1.2.1) - (1.2.1.2.3 )
25889 * Use the xsi:type attribute for the type definition.
25891 iattr
= xmlSchemaGetMetaAttrInfo(vctxt
,
25892 XML_SCHEMA_ATTR_INFO_META_XSI_TYPE
);
25893 if (iattr
!= NULL
) {
25894 if (xmlSchemaProcessXSIType(vctxt
, iattr
,
25895 &(vctxt
->inode
->typeDef
), NULL
) == -1) {
25896 VERROR_INT("xmlSchemaValidateElemWildcard",
25897 "calling xmlSchemaProcessXSIType() to "
25898 "process the attribute 'xsi:nil'");
25902 * Don't return an error on purpose.
25908 * SPEC Validation Rule: Schema-Validity Assessment (Element)
25910 * Fallback to "anyType".
25912 vctxt
->inode
->typeDef
=
25913 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE
);
25918 * xmlSchemaCheckCOSValidDefault:
25920 * This will be called if: not nilled, no content and a default/fixed
25921 * value is provided.
25925 xmlSchemaCheckCOSValidDefault(xmlSchemaValidCtxtPtr vctxt
,
25926 const xmlChar
*value
,
25927 xmlSchemaValPtr
*val
)
25930 xmlSchemaNodeInfoPtr inode
= vctxt
->inode
;
25933 * cos-valid-default:
25934 * Schema Component Constraint: Element Default Valid (Immediate)
25935 * For a string to be a valid default with respect to a type
25936 * definition the appropriate case among the following must be true:
25938 if WXS_IS_COMPLEX(inode
->typeDef
) {
25942 * SPEC (2.1) "its {content type} must be a simple type definition
25944 * SPEC (2.2.2) "If the {content type} is mixed, then the {content
25945 * type}'s particle must be `emptiable` as defined by
25946 * Particle Emptiable ($3.9.6)."
25948 if ((! WXS_HAS_SIMPLE_CONTENT(inode
->typeDef
)) &&
25949 ((! WXS_HAS_MIXED_CONTENT(inode
->typeDef
)) ||
25950 (! WXS_EMPTIABLE(inode
->typeDef
)))) {
25951 ret
= XML_SCHEMAP_COS_VALID_DEFAULT_2_1
;
25952 /* NOTE that this covers (2.2.2) as well. */
25954 "For a string to be a valid default, the type definition "
25955 "must be a simple type or a complex type with simple content "
25956 "or mixed content and a particle emptiable");
25961 * 1 If the type definition is a simple type definition, then the string
25962 * must be `valid` with respect to that definition as defined by String
25967 * 2.2.1 If the {content type} is a simple type definition, then the
25968 * string must be `valid` with respect to that simple type definition
25969 * as defined by String Valid ($3.14.4).
25971 if (WXS_IS_SIMPLE(inode
->typeDef
)) {
25973 ret
= xmlSchemaVCheckCVCSimpleType(ACTXT_CAST vctxt
,
25974 NULL
, inode
->typeDef
, value
, val
, 1, 1, 0);
25976 } else if (WXS_HAS_SIMPLE_CONTENT(inode
->typeDef
)) {
25978 ret
= xmlSchemaVCheckCVCSimpleType(ACTXT_CAST vctxt
,
25979 NULL
, inode
->typeDef
->contentTypeDef
, value
, val
, 1, 1, 0);
25982 VERROR_INT("xmlSchemaCheckCOSValidDefault",
25983 "calling xmlSchemaVCheckCVCSimpleType()");
25989 xmlSchemaVContentModelCallback(xmlRegExecCtxtPtr exec ATTRIBUTE_UNUSED
,
25990 const xmlChar
* name ATTRIBUTE_UNUSED
,
25991 void *transdata
, void *inputdata
)
25993 xmlSchemaElementPtr item
= (xmlSchemaElementPtr
) transdata
;
25994 xmlSchemaNodeInfoPtr inode
= (xmlSchemaNodeInfoPtr
) inputdata
;
25995 inode
->decl
= item
;
25996 #ifdef DEBUG_CONTENT
25998 xmlChar
*str
= NULL
;
26000 if (item
->type
== XML_SCHEMA_TYPE_ELEMENT
) {
26001 xmlGenericError(xmlGenericErrorContext
,
26002 "AUTOMATON callback for '%s' [declaration]\n",
26003 xmlSchemaFormatQName(&str
,
26004 inode
->localName
, inode
->nsName
));
26006 xmlGenericError(xmlGenericErrorContext
,
26007 "AUTOMATON callback for '%s' [wildcard]\n",
26008 xmlSchemaFormatQName(&str
,
26009 inode
->localName
, inode
->nsName
));
26018 xmlSchemaValidatorPushElem(xmlSchemaValidCtxtPtr vctxt
)
26020 vctxt
->inode
= xmlSchemaGetFreshElemInfo(vctxt
);
26021 if (vctxt
->inode
== NULL
) {
26022 VERROR_INT("xmlSchemaValidatorPushElem",
26023 "calling xmlSchemaGetFreshElemInfo()");
26026 vctxt
->nbAttrInfos
= 0;
26031 xmlSchemaVCheckINodeDataType(xmlSchemaValidCtxtPtr vctxt
,
26032 xmlSchemaNodeInfoPtr inode
,
26033 xmlSchemaTypePtr type
,
26034 const xmlChar
*value
)
26036 if (inode
->flags
& XML_SCHEMA_NODE_INFO_VALUE_NEEDED
)
26037 return (xmlSchemaVCheckCVCSimpleType(
26038 ACTXT_CAST vctxt
, NULL
,
26039 type
, value
, &(inode
->val
), 1, 1, 0));
26041 return (xmlSchemaVCheckCVCSimpleType(
26042 ACTXT_CAST vctxt
, NULL
,
26043 type
, value
, NULL
, 1, 0, 0));
26049 * Process END of element.
26052 xmlSchemaValidatorPopElem(xmlSchemaValidCtxtPtr vctxt
)
26055 xmlSchemaNodeInfoPtr inode
= vctxt
->inode
;
26057 if (vctxt
->nbAttrInfos
!= 0)
26058 xmlSchemaClearAttrInfos(vctxt
);
26059 if (inode
->flags
& XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED
) {
26061 * This element was not expected;
26062 * we will not validate child elements of broken parents.
26063 * Skip validation of all content of the parent.
26065 vctxt
->skipDepth
= vctxt
->depth
-1;
26068 if ((inode
->typeDef
== NULL
) ||
26069 (inode
->flags
& XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE
)) {
26071 * 1. the type definition might be missing if the element was
26073 * 2. it might be abstract.
26078 * Check the content model.
26080 if ((inode
->typeDef
->contentType
== XML_SCHEMA_CONTENT_MIXED
) ||
26081 (inode
->typeDef
->contentType
== XML_SCHEMA_CONTENT_ELEMENTS
)) {
26084 * Workaround for "anyType".
26086 if (inode
->typeDef
->builtInType
== XML_SCHEMAS_ANYTYPE
)
26087 goto character_content
;
26089 if ((inode
->flags
& XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT
) == 0) {
26090 xmlChar
*values
[10];
26091 int terminal
, nbval
= 10, nbneg
;
26093 if (inode
->regexCtxt
== NULL
) {
26095 * Create the regex context.
26098 xmlRegNewExecCtxt(inode
->typeDef
->contModel
,
26099 xmlSchemaVContentModelCallback
, vctxt
);
26100 if (inode
->regexCtxt
== NULL
) {
26101 VERROR_INT("xmlSchemaValidatorPopElem",
26102 "failed to create a regex context");
26103 goto internal_error
;
26105 #ifdef DEBUG_AUTOMATA
26106 xmlGenericError(xmlGenericErrorContext
,
26107 "AUTOMATON create on '%s'\n", inode
->localName
);
26112 * Do not check further content if the node has been nilled
26114 if (INODE_NILLED(inode
)) {
26116 #ifdef DEBUG_AUTOMATA
26117 xmlGenericError(xmlGenericErrorContext
,
26118 "AUTOMATON succeeded on nilled '%s'\n",
26125 * Get hold of the still expected content, since a further
26126 * call to xmlRegExecPushString() will lose this information.
26128 xmlRegExecNextValues(inode
->regexCtxt
,
26129 &nbval
, &nbneg
, &values
[0], &terminal
);
26130 ret
= xmlRegExecPushString(inode
->regexCtxt
, NULL
, NULL
);
26131 if ((ret
<0) || ((ret
==0) && (!INODE_NILLED(inode
)))) {
26133 * Still missing something.
26137 XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT
;
26138 xmlSchemaComplexTypeErr(ACTXT_CAST vctxt
,
26139 XML_SCHEMAV_ELEMENT_CONTENT
, NULL
, NULL
,
26140 "Missing child element(s)",
26141 nbval
, nbneg
, values
);
26142 #ifdef DEBUG_AUTOMATA
26143 xmlGenericError(xmlGenericErrorContext
,
26144 "AUTOMATON missing ERROR on '%s'\n",
26149 * Content model is satisfied.
26152 #ifdef DEBUG_AUTOMATA
26153 xmlGenericError(xmlGenericErrorContext
,
26154 "AUTOMATON succeeded on '%s'\n",
26164 if (inode
->typeDef
->contentType
== XML_SCHEMA_CONTENT_ELEMENTS
)
26169 if (vctxt
->value
!= NULL
) {
26170 xmlSchemaFreeValue(vctxt
->value
);
26171 vctxt
->value
= NULL
;
26174 * Check character content.
26176 if (inode
->decl
== NULL
) {
26178 * Speedup if no declaration exists.
26180 if (WXS_IS_SIMPLE(inode
->typeDef
)) {
26181 ret
= xmlSchemaVCheckINodeDataType(vctxt
,
26182 inode
, inode
->typeDef
, inode
->value
);
26183 } else if (WXS_HAS_SIMPLE_CONTENT(inode
->typeDef
)) {
26184 ret
= xmlSchemaVCheckINodeDataType(vctxt
,
26185 inode
, inode
->typeDef
->contentTypeDef
,
26189 VERROR_INT("xmlSchemaValidatorPopElem",
26190 "calling xmlSchemaVCheckCVCSimpleType()");
26191 goto internal_error
;
26196 * cvc-elt (3.3.4) : 5
26197 * The appropriate case among the following must be true:
26200 * cvc-elt (3.3.4) : 5.1
26201 * If the declaration has a {value constraint},
26202 * the item has neither element nor character [children] and
26203 * clause 3.2 has not applied, then all of the following must be true:
26205 if ((inode
->decl
->value
!= NULL
) &&
26206 (inode
->flags
& XML_SCHEMA_ELEM_INFO_EMPTY
) &&
26207 (! INODE_NILLED(inode
))) {
26209 * cvc-elt (3.3.4) : 5.1.1
26210 * If the `actual type definition` is a `local type definition`
26211 * then the canonical lexical representation of the {value constraint}
26212 * value must be a valid default for the `actual type definition` as
26213 * defined in Element Default Valid (Immediate) ($3.3.6).
26216 * NOTE: 'local' above means types acquired by xsi:type.
26217 * NOTE: Although the *canonical* value is stated, it is not
26218 * relevant if canonical or not. Additionally XML Schema 1.1
26219 * will removed this requirement as well.
26221 if (inode
->flags
& XML_SCHEMA_ELEM_INFO_LOCAL_TYPE
) {
26223 ret
= xmlSchemaCheckCOSValidDefault(vctxt
,
26224 inode
->decl
->value
, &(inode
->val
));
26227 VERROR_INT("xmlSchemaValidatorPopElem",
26228 "calling xmlSchemaCheckCOSValidDefault()");
26229 goto internal_error
;
26234 * Stop here, to avoid redundant validation of the value
26240 * cvc-elt (3.3.4) : 5.1.2
26241 * The element information item with the canonical lexical
26242 * representation of the {value constraint} value used as its
26243 * `normalized value` must be `valid` with respect to the
26244 * `actual type definition` as defined by Element Locally Valid (Type)
26247 if (WXS_IS_SIMPLE(inode
->typeDef
)) {
26248 ret
= xmlSchemaVCheckINodeDataType(vctxt
,
26249 inode
, inode
->typeDef
, inode
->decl
->value
);
26250 } else if (WXS_HAS_SIMPLE_CONTENT(inode
->typeDef
)) {
26251 ret
= xmlSchemaVCheckINodeDataType(vctxt
,
26252 inode
, inode
->typeDef
->contentTypeDef
,
26253 inode
->decl
->value
);
26257 VERROR_INT("xmlSchemaValidatorPopElem",
26258 "calling xmlSchemaVCheckCVCSimpleType()");
26259 goto internal_error
;
26266 * PSVI: Create a text node on the instance element.
26268 if ((vctxt
->options
& XML_SCHEMA_VAL_VC_I_CREATE
) &&
26269 (inode
->node
!= NULL
)) {
26270 xmlNodePtr textChild
;
26271 xmlChar
*normValue
;
26273 * VAL TODO: Normalize the value.
26275 normValue
= xmlSchemaNormalizeValue(inode
->typeDef
,
26276 inode
->decl
->value
);
26277 if (normValue
!= NULL
) {
26278 textChild
= xmlNewText(BAD_CAST normValue
);
26279 xmlFree(normValue
);
26281 textChild
= xmlNewText(inode
->decl
->value
);
26282 if (textChild
== NULL
) {
26283 VERROR_INT("xmlSchemaValidatorPopElem",
26284 "calling xmlNewText()");
26285 goto internal_error
;
26287 xmlAddChild(inode
->node
, textChild
);
26290 } else if (! INODE_NILLED(inode
)) {
26292 * 5.2.1 The element information item must be `valid` with respect
26293 * to the `actual type definition` as defined by Element Locally
26294 * Valid (Type) ($3.3.4).
26296 if (WXS_IS_SIMPLE(inode
->typeDef
)) {
26298 * SPEC (cvc-type) (3.1)
26299 * "If the type definition is a simple type definition, ..."
26300 * (3.1.3) "If clause 3.2 of Element Locally Valid
26301 * (Element) ($3.3.4) did not apply, then the `normalized value`
26302 * must be `valid` with respect to the type definition as defined
26303 * by String Valid ($3.14.4).
26305 ret
= xmlSchemaVCheckINodeDataType(vctxt
,
26306 inode
, inode
->typeDef
, inode
->value
);
26307 } else if (WXS_HAS_SIMPLE_CONTENT(inode
->typeDef
)) {
26309 * SPEC (cvc-type) (3.2) "If the type definition is a complex type
26310 * definition, then the element information item must be
26311 * `valid` with respect to the type definition as per
26312 * Element Locally Valid (Complex Type) ($3.4.4);"
26314 * SPEC (cvc-complex-type) (2.2)
26315 * "If the {content type} is a simple type definition, ...
26316 * the `normalized value` of the element information item is
26317 * `valid` with respect to that simple type definition as
26318 * defined by String Valid ($3.14.4)."
26320 ret
= xmlSchemaVCheckINodeDataType(vctxt
,
26321 inode
, inode
->typeDef
->contentTypeDef
, inode
->value
);
26325 VERROR_INT("xmlSchemaValidatorPopElem",
26326 "calling xmlSchemaVCheckCVCSimpleType()");
26327 goto internal_error
;
26332 * 5.2.2 If there is a fixed {value constraint} and clause 3.2 has
26333 * not applied, all of the following must be true:
26335 if ((inode
->decl
->value
!= NULL
) &&
26336 (inode
->decl
->flags
& XML_SCHEMAS_ELEM_FIXED
)) {
26339 * TODO: We will need a computed value, when comparison is
26340 * done on computed values.
26343 * 5.2.2.1 The element information item must have no element
26344 * information item [children].
26347 XML_SCHEMA_ELEM_INFO_HAS_ELEM_CONTENT
) {
26348 ret
= XML_SCHEMAV_CVC_ELT_5_2_2_1
;
26350 "The content must not containt element nodes since "
26351 "there is a fixed value constraint");
26355 * 5.2.2.2 The appropriate case among the following must
26358 if (WXS_HAS_MIXED_CONTENT(inode
->typeDef
)) {
26360 * 5.2.2.2.1 If the {content type} of the `actual type
26361 * definition` is mixed, then the *initial value* of the
26362 * item must match the canonical lexical representation
26363 * of the {value constraint} value.
26365 * ... the *initial value* of an element information
26366 * item is the string composed of, in order, the
26367 * [character code] of each character information item in
26368 * the [children] of that element information item.
26370 if (! xmlStrEqual(inode
->value
, inode
->decl
->value
)){
26372 * VAL TODO: Report invalid & expected values as well.
26373 * VAL TODO: Implement the canonical stuff.
26375 ret
= XML_SCHEMAV_CVC_ELT_5_2_2_2_1
;
26376 xmlSchemaCustomErr(ACTXT_CAST vctxt
,
26378 "The initial value '%s' does not match the fixed "
26379 "value constraint '%s'",
26380 inode
->value
, inode
->decl
->value
);
26383 } else if (WXS_HAS_SIMPLE_CONTENT(inode
->typeDef
)) {
26385 * 5.2.2.2.2 If the {content type} of the `actual type
26386 * definition` is a simple type definition, then the
26387 * *actual value* of the item must match the canonical
26388 * lexical representation of the {value constraint} value.
26391 * VAL TODO: *actual value* is the normalized value, impl.
26393 * VAL TODO: Report invalid & expected values as well.
26394 * VAL TODO: Implement a comparison with the computed values.
26396 if (! xmlStrEqual(inode
->value
,
26397 inode
->decl
->value
)) {
26398 ret
= XML_SCHEMAV_CVC_ELT_5_2_2_2_2
;
26399 xmlSchemaCustomErr(ACTXT_CAST vctxt
,
26401 "The actual value '%s' does not match the fixed "
26402 "value constraint '%s'",
26404 inode
->decl
->value
);
26413 if (vctxt
->depth
< 0) {
26414 /* TODO: raise error? */
26417 if (vctxt
->depth
== vctxt
->skipDepth
)
26418 vctxt
->skipDepth
= -1;
26420 * Evaluate the history of XPath state objects.
26422 if (inode
->appliedXPath
&&
26423 (xmlSchemaXPathProcessHistory(vctxt
, vctxt
->depth
) == -1))
26424 goto internal_error
;
26427 * SPEC (6) "The element information item must be `valid` with
26428 * respect to each of the {identity-constraint definitions} as per
26429 * Identity-constraint Satisfied ($3.11.4)."
26432 * PSVI TODO: If we expose IDC node-tables via PSVI then the tables
26433 * need to be built in any case.
26434 * We will currently build IDC node-tables and bubble them only if
26435 * keyrefs do exist.
26439 * Add the current IDC target-nodes to the IDC node-tables.
26441 if ((inode
->idcMatchers
!= NULL
) &&
26442 (vctxt
->hasKeyrefs
|| vctxt
->createIDCNodeTables
))
26444 if (xmlSchemaIDCFillNodeTables(vctxt
, inode
) == -1)
26445 goto internal_error
;
26448 * Validate IDC keyrefs.
26450 if (vctxt
->inode
->hasKeyrefs
)
26451 if (xmlSchemaCheckCVCIDCKeyRef(vctxt
) == -1)
26452 goto internal_error
;
26454 * Merge/free the IDC table.
26456 if (inode
->idcTable
!= NULL
) {
26457 #ifdef DEBUG_IDC_NODE_TABLE
26458 xmlSchemaDebugDumpIDCTable(stdout
,
26463 if ((vctxt
->depth
> 0) &&
26464 (vctxt
->hasKeyrefs
|| vctxt
->createIDCNodeTables
))
26467 * Merge the IDC node table with the table of the parent node.
26469 if (xmlSchemaBubbleIDCNodeTables(vctxt
) == -1)
26470 goto internal_error
;
26474 * Clear the current ielem.
26475 * VAL TODO: Don't free the PSVI IDC tables if they are
26476 * requested for the PSVI.
26478 xmlSchemaClearElemInfo(vctxt
, inode
);
26480 * Skip further processing if we are on the validation root.
26482 if (vctxt
->depth
== 0) {
26484 vctxt
->inode
= NULL
;
26488 * Reset the keyrefDepth if needed.
26490 if (vctxt
->aidcs
!= NULL
) {
26491 xmlSchemaIDCAugPtr aidc
= vctxt
->aidcs
;
26493 if (aidc
->keyrefDepth
== vctxt
->depth
) {
26495 * A 'keyrefDepth' of a key/unique IDC matches the current
26496 * depth, this means that we are leaving the scope of the
26497 * top-most keyref IDC which refers to this IDC.
26499 aidc
->keyrefDepth
= -1;
26502 } while (aidc
!= NULL
);
26505 vctxt
->inode
= vctxt
->elemInfos
[vctxt
->depth
];
26507 * VAL TODO: 7 If the element information item is the `validation root`, it must be
26508 * `valid` per Validation Root Valid (ID/IDREF) ($3.3.4).
26518 * 3.4.4 Complex Type Definition Validation Rules
26519 * Validation Rule: Element Locally Valid (Complex Type) (cvc-complex-type)
26522 xmlSchemaValidateChildElem(xmlSchemaValidCtxtPtr vctxt
)
26524 xmlSchemaNodeInfoPtr pielem
;
26525 xmlSchemaTypePtr ptype
;
26528 if (vctxt
->depth
<= 0) {
26529 VERROR_INT("xmlSchemaValidateChildElem",
26530 "not intended for the validation root");
26533 pielem
= vctxt
->elemInfos
[vctxt
->depth
-1];
26534 if (pielem
->flags
& XML_SCHEMA_ELEM_INFO_EMPTY
)
26535 pielem
->flags
^= XML_SCHEMA_ELEM_INFO_EMPTY
;
26537 * Handle 'nilled' elements.
26539 if (INODE_NILLED(pielem
)) {
26541 * SPEC (cvc-elt) (3.3.4) : (3.2.1)
26543 ACTIVATE_PARENT_ELEM
;
26544 ret
= XML_SCHEMAV_CVC_ELT_3_2_1
;
26546 "Neither character nor element content is allowed, "
26547 "because the element was 'nilled'");
26549 goto unexpected_elem
;
26552 ptype
= pielem
->typeDef
;
26554 if (ptype
->builtInType
== XML_SCHEMAS_ANYTYPE
) {
26556 * Workaround for "anyType": we have currently no content model
26557 * assigned for "anyType", so handle it explicitely.
26558 * "anyType" has an unbounded, lax "any" wildcard.
26560 vctxt
->inode
->decl
= xmlSchemaGetElem(vctxt
->schema
,
26561 vctxt
->inode
->localName
,
26562 vctxt
->inode
->nsName
);
26564 if (vctxt
->inode
->decl
== NULL
) {
26565 xmlSchemaAttrInfoPtr iattr
;
26567 * Process "xsi:type".
26568 * SPEC (cvc-assess-elt) (1.2.1.2.1) - (1.2.1.2.3)
26570 iattr
= xmlSchemaGetMetaAttrInfo(vctxt
,
26571 XML_SCHEMA_ATTR_INFO_META_XSI_TYPE
);
26572 if (iattr
!= NULL
) {
26573 ret
= xmlSchemaProcessXSIType(vctxt
, iattr
,
26574 &(vctxt
->inode
->typeDef
), NULL
);
26577 VERROR_INT("xmlSchemaValidateChildElem",
26578 "calling xmlSchemaProcessXSIType() to "
26579 "process the attribute 'xsi:nil'");
26586 * Fallback to "anyType".
26588 * SPEC (cvc-assess-elt)
26589 * "If the item cannot be `strictly assessed`, [...]
26590 * an element information item's schema validity may be laxly
26591 * assessed if its `context-determined declaration` is not
26592 * skip by `validating` with respect to the `ur-type
26593 * definition` as per Element Locally Valid (Type) ($3.3.4)."
26595 vctxt
->inode
->typeDef
=
26596 xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE
);
26602 switch (ptype
->contentType
) {
26603 case XML_SCHEMA_CONTENT_EMPTY
:
26605 * SPEC (2.1) "If the {content type} is empty, then the
26606 * element information item has no character or element
26607 * information item [children]."
26609 ACTIVATE_PARENT_ELEM
26610 ret
= XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1
;
26612 "Element content is not allowed, "
26613 "because the content type is empty");
26615 goto unexpected_elem
;
26618 case XML_SCHEMA_CONTENT_MIXED
:
26619 case XML_SCHEMA_CONTENT_ELEMENTS
: {
26620 xmlRegExecCtxtPtr regexCtxt
;
26621 xmlChar
*values
[10];
26622 int terminal
, nbval
= 10, nbneg
;
26624 /* VAL TODO: Optimized "anyType" validation.*/
26626 if (ptype
->contModel
== NULL
) {
26627 VERROR_INT("xmlSchemaValidateChildElem",
26628 "type has elem content but no content model");
26632 * Safety belf for evaluation if the cont. model was already
26633 * examined to be invalid.
26635 if (pielem
->flags
& XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT
) {
26636 VERROR_INT("xmlSchemaValidateChildElem",
26637 "validating elem, but elem content is already invalid");
26641 regexCtxt
= pielem
->regexCtxt
;
26642 if (regexCtxt
== NULL
) {
26644 * Create the regex context.
26646 regexCtxt
= xmlRegNewExecCtxt(ptype
->contModel
,
26647 xmlSchemaVContentModelCallback
, vctxt
);
26648 if (regexCtxt
== NULL
) {
26649 VERROR_INT("xmlSchemaValidateChildElem",
26650 "failed to create a regex context");
26653 pielem
->regexCtxt
= regexCtxt
;
26654 #ifdef DEBUG_AUTOMATA
26655 xmlGenericError(xmlGenericErrorContext
, "AUTOMATA create on '%s'\n",
26656 pielem
->localName
);
26661 * SPEC (2.4) "If the {content type} is element-only or mixed,
26662 * then the sequence of the element information item's
26663 * element information item [children], if any, taken in
26664 * order, is `valid` with respect to the {content type}'s
26665 * particle, as defined in Element Sequence Locally Valid
26666 * (Particle) ($3.9.4)."
26668 ret
= xmlRegExecPushString2(regexCtxt
,
26669 vctxt
->inode
->localName
,
26670 vctxt
->inode
->nsName
,
26672 #ifdef DEBUG_AUTOMATA
26674 xmlGenericError(xmlGenericErrorContext
,
26675 "AUTOMATON push ERROR for '%s' on '%s'\n",
26676 vctxt
->inode
->localName
, pielem
->localName
);
26678 xmlGenericError(xmlGenericErrorContext
,
26679 "AUTOMATON push OK for '%s' on '%s'\n",
26680 vctxt
->inode
->localName
, pielem
->localName
);
26682 if (vctxt
->err
== XML_SCHEMAV_INTERNAL
) {
26683 VERROR_INT("xmlSchemaValidateChildElem",
26684 "calling xmlRegExecPushString2()");
26688 xmlRegExecErrInfo(regexCtxt
, NULL
, &nbval
, &nbneg
,
26689 &values
[0], &terminal
);
26690 xmlSchemaComplexTypeErr(ACTXT_CAST vctxt
,
26691 XML_SCHEMAV_ELEMENT_CONTENT
, NULL
,NULL
,
26692 "This element is not expected",
26693 nbval
, nbneg
, values
);
26695 goto unexpected_elem
;
26700 case XML_SCHEMA_CONTENT_SIMPLE
:
26701 case XML_SCHEMA_CONTENT_BASIC
:
26702 ACTIVATE_PARENT_ELEM
26703 if (WXS_IS_COMPLEX(ptype
)) {
26705 * SPEC (cvc-complex-type) (2.2)
26706 * "If the {content type} is a simple type definition, then
26707 * the element information item has no element information
26708 * item [children], ..."
26710 ret
= XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2
;
26711 VERROR(ret
, NULL
, "Element content is not allowed, "
26712 "because the content type is a simple type definition");
26715 * SPEC (cvc-type) (3.1.2) "The element information item must
26716 * have no element information item [children]."
26718 ret
= XML_SCHEMAV_CVC_TYPE_3_1_2
;
26719 VERROR(ret
, NULL
, "Element content is not allowed, "
26720 "because the type definition is simple");
26724 goto unexpected_elem
;
26733 * Pop this element and set the skipDepth to skip
26734 * all further content of the parent element.
26736 vctxt
->skipDepth
= vctxt
->depth
;
26737 vctxt
->inode
->flags
|= XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED
;
26738 pielem
->flags
|= XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT
;
26742 #define XML_SCHEMA_PUSH_TEXT_PERSIST 1
26743 #define XML_SCHEMA_PUSH_TEXT_CREATED 2
26744 #define XML_SCHEMA_PUSH_TEXT_VOLATILE 3
26747 xmlSchemaVPushText(xmlSchemaValidCtxtPtr vctxt
,
26748 int nodeType
, const xmlChar
*value
, int len
,
26749 int mode
, int *consumed
)
26752 * Unfortunately we have to duplicate the text sometimes.
26753 * OPTIMIZE: Maybe we could skip it, if:
26754 * 1. content type is simple
26755 * 2. whitespace is "collapse"
26756 * 3. it consists of whitespace only
26758 * Process character content.
26760 if (consumed
!= NULL
)
26762 if (INODE_NILLED(vctxt
->inode
)) {
26764 * SPEC cvc-elt (3.3.4 - 3.2.1)
26765 * "The element information item must have no character or
26766 * element information item [children]."
26768 VERROR(XML_SCHEMAV_CVC_ELT_3_2_1
, NULL
,
26769 "Neither character nor element content is allowed "
26770 "because the element is 'nilled'");
26771 return (vctxt
->err
);
26774 * SPEC (2.1) "If the {content type} is empty, then the
26775 * element information item has no character or element
26776 * information item [children]."
26778 if (vctxt
->inode
->typeDef
->contentType
==
26779 XML_SCHEMA_CONTENT_EMPTY
) {
26780 VERROR(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1
, NULL
,
26781 "Character content is not allowed, "
26782 "because the content type is empty");
26783 return (vctxt
->err
);
26786 if (vctxt
->inode
->typeDef
->contentType
==
26787 XML_SCHEMA_CONTENT_ELEMENTS
) {
26788 if ((nodeType
!= XML_TEXT_NODE
) ||
26789 (! xmlSchemaIsBlank((xmlChar
*) value
, len
))) {
26791 * SPEC cvc-complex-type (2.3)
26792 * "If the {content type} is element-only, then the
26793 * element information item has no character information
26794 * item [children] other than those whose [character
26795 * code] is defined as a white space in [XML 1.0 (Second
26798 VERROR(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_3
, NULL
,
26799 "Character content other than whitespace is not allowed "
26800 "because the content type is 'element-only'");
26801 return (vctxt
->err
);
26806 if ((value
== NULL
) || (value
[0] == 0))
26810 * NOTE that even if the content type is *mixed*, we need the
26811 * *initial value* for default/fixed value constraints.
26813 if ((vctxt
->inode
->typeDef
->contentType
== XML_SCHEMA_CONTENT_MIXED
) &&
26814 ((vctxt
->inode
->decl
== NULL
) ||
26815 (vctxt
->inode
->decl
->value
== NULL
)))
26818 if (vctxt
->inode
->value
== NULL
) {
26823 case XML_SCHEMA_PUSH_TEXT_PERSIST
:
26825 * When working on a tree.
26827 vctxt
->inode
->value
= value
;
26829 case XML_SCHEMA_PUSH_TEXT_CREATED
:
26831 * When working with the reader.
26832 * The value will be freed by the element info.
26834 vctxt
->inode
->value
= value
;
26835 if (consumed
!= NULL
)
26837 vctxt
->inode
->flags
|=
26838 XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES
;
26840 case XML_SCHEMA_PUSH_TEXT_VOLATILE
:
26842 * When working with SAX.
26843 * The value will be freed by the element info.
26846 vctxt
->inode
->value
= BAD_CAST
xmlStrndup(value
, len
);
26848 vctxt
->inode
->value
= BAD_CAST
xmlStrdup(value
);
26849 vctxt
->inode
->flags
|=
26850 XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES
;
26857 len
= xmlStrlen(value
);
26859 * Concat the value.
26861 if (vctxt
->inode
->flags
& XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES
) {
26862 vctxt
->inode
->value
= BAD_CAST
xmlStrncat(
26863 (xmlChar
*) vctxt
->inode
->value
, value
, len
);
26865 vctxt
->inode
->value
=
26866 BAD_CAST
xmlStrncatNew(vctxt
->inode
->value
, value
, len
);
26867 vctxt
->inode
->flags
|= XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES
;
26875 xmlSchemaValidateElem(xmlSchemaValidCtxtPtr vctxt
)
26879 if ((vctxt
->skipDepth
!= -1) &&
26880 (vctxt
->depth
>= vctxt
->skipDepth
)) {
26881 VERROR_INT("xmlSchemaValidateElem",
26883 goto internal_error
;
26885 if (vctxt
->xsiAssemble
) {
26887 * We will stop validation if there was an error during
26888 * dynamic schema construction.
26889 * Note that we simply set @skipDepth to 0, this could
26890 * mean that a streaming document via SAX would be
26891 * still read to the end but it won't be validated any more.
26892 * TODO: If we are sure how to stop the validation at once
26893 * for all input scenarios, then this should be changed to
26894 * instantly stop the validation.
26896 ret
= xmlSchemaAssembleByXSI(vctxt
);
26899 goto internal_error
;
26900 vctxt
->skipDepth
= 0;
26904 * Augment the IDC definitions for the main schema and all imported ones
26905 * NOTE: main schema is the first in the imported list
26907 xmlHashScan(vctxt
->schema
->schemasImports
, xmlSchemaAugmentImportedIDC
,
26910 if (vctxt
->depth
> 0) {
26912 * Validate this element against the content model
26915 ret
= xmlSchemaValidateChildElem(vctxt
);
26918 VERROR_INT("xmlSchemaValidateElem",
26919 "calling xmlSchemaStreamValidateChildElement()");
26920 goto internal_error
;
26924 if (vctxt
->depth
== vctxt
->skipDepth
)
26926 if ((vctxt
->inode
->decl
== NULL
) &&
26927 (vctxt
->inode
->typeDef
== NULL
)) {
26928 VERROR_INT("xmlSchemaValidateElem",
26929 "the child element was valid but neither the "
26930 "declaration nor the type was set");
26931 goto internal_error
;
26935 * Get the declaration of the validation root.
26937 vctxt
->inode
->decl
= xmlSchemaGetElem(vctxt
->schema
,
26938 vctxt
->inode
->localName
,
26939 vctxt
->inode
->nsName
);
26940 if (vctxt
->inode
->decl
== NULL
) {
26941 ret
= XML_SCHEMAV_CVC_ELT_1
;
26943 "No matching global declaration available "
26944 "for the validation root");
26949 if (vctxt
->inode
->decl
== NULL
)
26950 goto type_validation
;
26952 if (vctxt
->inode
->decl
->type
== XML_SCHEMA_TYPE_ANY
) {
26957 ret
= xmlSchemaValidateElemWildcard(vctxt
, &skip
);
26960 VERROR_INT("xmlSchemaValidateElem",
26961 "calling xmlSchemaValidateElemWildcard()");
26962 goto internal_error
;
26967 vctxt
->skipDepth
= vctxt
->depth
;
26971 * The declaration might be set by the wildcard validation,
26972 * when the processContents is "lax" or "strict".
26974 if (vctxt
->inode
->decl
->type
!= XML_SCHEMA_TYPE_ELEMENT
) {
26976 * Clear the "decl" field to not confuse further processing.
26978 vctxt
->inode
->decl
= NULL
;
26979 goto type_validation
;
26983 * Validate against the declaration.
26985 ret
= xmlSchemaValidateElemDecl(vctxt
);
26988 VERROR_INT("xmlSchemaValidateElem",
26989 "calling xmlSchemaValidateElemDecl()");
26990 goto internal_error
;
26995 * Validate against the type definition.
26999 if (vctxt
->inode
->typeDef
== NULL
) {
27000 vctxt
->inode
->flags
|= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE
;
27001 ret
= XML_SCHEMAV_CVC_TYPE_1
;
27003 "The type definition is absent");
27006 if (vctxt
->inode
->typeDef
->flags
& XML_SCHEMAS_TYPE_ABSTRACT
) {
27007 vctxt
->inode
->flags
|= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE
;
27008 ret
= XML_SCHEMAV_CVC_TYPE_2
;
27010 "The type definition is abstract");
27014 * Evaluate IDCs. Do it here, since new IDC matchers are registered
27015 * during validation against the declaration. This must be done
27016 * _before_ attribute validation.
27018 if (vctxt
->xpathStates
!= NULL
) {
27019 ret
= xmlSchemaXPathEvaluate(vctxt
, XML_ELEMENT_NODE
);
27020 vctxt
->inode
->appliedXPath
= 1;
27022 VERROR_INT("xmlSchemaValidateElem",
27023 "calling xmlSchemaXPathEvaluate()");
27024 goto internal_error
;
27028 * Validate attributes.
27030 if (WXS_IS_COMPLEX(vctxt
->inode
->typeDef
)) {
27031 if ((vctxt
->nbAttrInfos
!= 0) ||
27032 (vctxt
->inode
->typeDef
->attrUses
!= NULL
)) {
27034 ret
= xmlSchemaVAttributesComplex(vctxt
);
27036 } else if (vctxt
->nbAttrInfos
!= 0) {
27038 ret
= xmlSchemaVAttributesSimple(vctxt
);
27041 * Clear registered attributes.
27043 if (vctxt
->nbAttrInfos
!= 0)
27044 xmlSchemaClearAttrInfos(vctxt
);
27046 VERROR_INT("xmlSchemaValidateElem",
27047 "calling attributes validation");
27048 goto internal_error
;
27051 * Don't return an error if attributes are invalid on purpose.
27057 vctxt
->skipDepth
= vctxt
->depth
;
27063 #ifdef XML_SCHEMA_READER_ENABLED
27065 xmlSchemaVReaderWalk(xmlSchemaValidCtxtPtr vctxt
)
27067 const int WHTSP
= 13, SIGN_WHTSP
= 14, END_ELEM
= 15;
27068 int depth
, nodeType
, ret
= 0, consumed
;
27069 xmlSchemaNodeInfoPtr ielem
;
27072 ret
= xmlTextReaderRead(vctxt
->reader
);
27074 * Move to the document element.
27077 nodeType
= xmlTextReaderNodeType(vctxt
->reader
);
27078 if (nodeType
== XML_ELEMENT_NODE
)
27080 ret
= xmlTextReaderRead(vctxt
->reader
);
27087 depth
= xmlTextReaderDepth(vctxt
->reader
);
27088 nodeType
= xmlTextReaderNodeType(vctxt
->reader
);
27090 if (nodeType
== XML_ELEMENT_NODE
) {
27093 if (xmlSchemaValidatorPushElem(vctxt
) == -1) {
27094 VERROR_INT("xmlSchemaVReaderWalk",
27095 "calling xmlSchemaValidatorPushElem()");
27096 goto internal_error
;
27098 ielem
= vctxt
->inode
;
27099 ielem
->localName
= xmlTextReaderLocalName(vctxt
->reader
);
27100 ielem
->nsName
= xmlTextReaderNamespaceUri(vctxt
->reader
);
27101 ielem
->flags
|= XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES
;
27103 * Is the element empty?
27105 ret
= xmlTextReaderIsEmptyElement(vctxt
->reader
);
27107 VERROR_INT("xmlSchemaVReaderWalk",
27108 "calling xmlTextReaderIsEmptyElement()");
27109 goto internal_error
;
27112 ielem
->flags
|= XML_SCHEMA_ELEM_INFO_EMPTY
;
27115 * Register attributes.
27117 vctxt
->nbAttrInfos
= 0;
27118 ret
= xmlTextReaderMoveToFirstAttribute(vctxt
->reader
);
27120 VERROR_INT("xmlSchemaVReaderWalk",
27121 "calling xmlTextReaderMoveToFirstAttribute()");
27122 goto internal_error
;
27127 * VAL TODO: How do we know that the reader works on a
27128 * node tree, to be able to pass a node here?
27130 if (xmlSchemaValidatorPushAttribute(vctxt
, NULL
,
27131 (const xmlChar
*) xmlTextReaderLocalName(vctxt
->reader
),
27132 xmlTextReaderNamespaceUri(vctxt
->reader
), 1,
27133 xmlTextReaderValue(vctxt
->reader
), 1) == -1) {
27135 VERROR_INT("xmlSchemaVReaderWalk",
27136 "calling xmlSchemaValidatorPushAttribute()");
27137 goto internal_error
;
27139 ret
= xmlTextReaderMoveToNextAttribute(vctxt
->reader
);
27141 VERROR_INT("xmlSchemaVReaderWalk",
27142 "calling xmlTextReaderMoveToFirstAttribute()");
27143 goto internal_error
;
27145 } while (ret
== 1);
27147 * Back to element position.
27149 ret
= xmlTextReaderMoveToElement(vctxt
->reader
);
27151 VERROR_INT("xmlSchemaVReaderWalk",
27152 "calling xmlTextReaderMoveToElement()");
27153 goto internal_error
;
27157 * Validate the element.
27159 ret
= xmlSchemaValidateElem(vctxt
);
27162 VERROR_INT("xmlSchemaVReaderWalk",
27163 "calling xmlSchemaValidateElem()");
27164 goto internal_error
;
27168 if (vctxt
->depth
== vctxt
->skipDepth
) {
27171 * Skip all content.
27173 if ((ielem
->flags
& XML_SCHEMA_ELEM_INFO_EMPTY
) == 0) {
27174 ret
= xmlTextReaderRead(vctxt
->reader
);
27175 curDepth
= xmlTextReaderDepth(vctxt
->reader
);
27176 while ((ret
== 1) && (curDepth
!= depth
)) {
27177 ret
= xmlTextReaderRead(vctxt
->reader
);
27178 curDepth
= xmlTextReaderDepth(vctxt
->reader
);
27182 * VAL TODO: A reader error occurred; what to do here?
27191 * READER VAL TODO: Is an END_ELEM really never called
27192 * if the elem is empty?
27194 if (ielem
->flags
& XML_SCHEMA_ELEM_INFO_EMPTY
)
27196 } else if (nodeType
== END_ELEM
) {
27198 * Process END of element.
27201 ret
= xmlSchemaValidatorPopElem(vctxt
);
27204 VERROR_INT("xmlSchemaVReaderWalk",
27205 "calling xmlSchemaValidatorPopElem()");
27206 goto internal_error
;
27210 if (vctxt
->depth
>= 0)
27211 ielem
= vctxt
->inode
;
27214 } else if ((nodeType
== XML_TEXT_NODE
) ||
27215 (nodeType
== XML_CDATA_SECTION_NODE
) ||
27216 (nodeType
== WHTSP
) ||
27217 (nodeType
== SIGN_WHTSP
)) {
27219 * Process character content.
27223 if ((nodeType
== WHTSP
) || (nodeType
== SIGN_WHTSP
))
27224 nodeType
= XML_TEXT_NODE
;
27226 value
= xmlTextReaderValue(vctxt
->reader
);
27227 ret
= xmlSchemaVPushText(vctxt
, nodeType
, BAD_CAST value
,
27228 -1, XML_SCHEMA_PUSH_TEXT_CREATED
, &consumed
);
27232 VERROR_INT("xmlSchemaVReaderWalk",
27233 "calling xmlSchemaVPushText()");
27234 goto internal_error
;
27236 } else if ((nodeType
== XML_ENTITY_NODE
) ||
27237 (nodeType
== XML_ENTITY_REF_NODE
)) {
27239 * VAL TODO: What to do with entities?
27246 ret
= xmlTextReaderRead(vctxt
->reader
);
27247 } while (ret
== 1);
27256 /************************************************************************
27258 * SAX validation handlers *
27260 ************************************************************************/
27263 * Process text content.
27266 xmlSchemaSAXHandleText(void *ctx
,
27267 const xmlChar
* ch
,
27270 xmlSchemaValidCtxtPtr vctxt
= (xmlSchemaValidCtxtPtr
) ctx
;
27272 if (vctxt
->depth
< 0)
27274 if ((vctxt
->skipDepth
!= -1) && (vctxt
->depth
>= vctxt
->skipDepth
))
27276 if (vctxt
->inode
->flags
& XML_SCHEMA_ELEM_INFO_EMPTY
)
27277 vctxt
->inode
->flags
^= XML_SCHEMA_ELEM_INFO_EMPTY
;
27278 if (xmlSchemaVPushText(vctxt
, XML_TEXT_NODE
, ch
, len
,
27279 XML_SCHEMA_PUSH_TEXT_VOLATILE
, NULL
) == -1) {
27280 VERROR_INT("xmlSchemaSAXHandleCDataSection",
27281 "calling xmlSchemaVPushText()");
27283 xmlStopParser(vctxt
->parserCtxt
);
27288 * Process CDATA content.
27291 xmlSchemaSAXHandleCDataSection(void *ctx
,
27292 const xmlChar
* ch
,
27295 xmlSchemaValidCtxtPtr vctxt
= (xmlSchemaValidCtxtPtr
) ctx
;
27297 if (vctxt
->depth
< 0)
27299 if ((vctxt
->skipDepth
!= -1) && (vctxt
->depth
>= vctxt
->skipDepth
))
27301 if (vctxt
->inode
->flags
& XML_SCHEMA_ELEM_INFO_EMPTY
)
27302 vctxt
->inode
->flags
^= XML_SCHEMA_ELEM_INFO_EMPTY
;
27303 if (xmlSchemaVPushText(vctxt
, XML_CDATA_SECTION_NODE
, ch
, len
,
27304 XML_SCHEMA_PUSH_TEXT_VOLATILE
, NULL
) == -1) {
27305 VERROR_INT("xmlSchemaSAXHandleCDataSection",
27306 "calling xmlSchemaVPushText()");
27308 xmlStopParser(vctxt
->parserCtxt
);
27313 xmlSchemaSAXHandleReference(void *ctx ATTRIBUTE_UNUSED
,
27314 const xmlChar
* name ATTRIBUTE_UNUSED
)
27316 xmlSchemaValidCtxtPtr vctxt
= (xmlSchemaValidCtxtPtr
) ctx
;
27318 if (vctxt
->depth
< 0)
27320 if ((vctxt
->skipDepth
!= -1) && (vctxt
->depth
>= vctxt
->skipDepth
))
27322 /* SAX VAL TODO: What to do here? */
27327 xmlSchemaSAXHandleStartElementNs(void *ctx
,
27328 const xmlChar
* localname
,
27329 const xmlChar
* prefix ATTRIBUTE_UNUSED
,
27330 const xmlChar
* URI
,
27332 const xmlChar
** namespaces
,
27334 int nb_defaulted ATTRIBUTE_UNUSED
,
27335 const xmlChar
** attributes
)
27337 xmlSchemaValidCtxtPtr vctxt
= (xmlSchemaValidCtxtPtr
) ctx
;
27339 xmlSchemaNodeInfoPtr ielem
;
27343 * SAX VAL TODO: What to do with nb_defaulted?
27346 * Skip elements if inside a "skip" wildcard or invalid.
27349 if ((vctxt
->skipDepth
!= -1) && (vctxt
->depth
>= vctxt
->skipDepth
))
27352 * Push the element.
27354 if (xmlSchemaValidatorPushElem(vctxt
) == -1) {
27355 VERROR_INT("xmlSchemaSAXHandleStartElementNs",
27356 "calling xmlSchemaValidatorPushElem()");
27357 goto internal_error
;
27359 ielem
= vctxt
->inode
;
27361 * TODO: Is this OK?
27363 ielem
->nodeLine
= xmlSAX2GetLineNumber(vctxt
->parserCtxt
);
27364 ielem
->localName
= localname
;
27365 ielem
->nsName
= URI
;
27366 ielem
->flags
|= XML_SCHEMA_ELEM_INFO_EMPTY
;
27368 * Register namespaces on the elem info.
27370 if (nb_namespaces
!= 0) {
27372 * Although the parser builds its own namespace list,
27373 * we have no access to it, so we'll use an own one.
27375 for (i
= 0, j
= 0; i
< nb_namespaces
; i
++, j
+= 2) {
27377 * Store prefix and namespace name.
27379 if (ielem
->nsBindings
== NULL
) {
27380 ielem
->nsBindings
=
27381 (const xmlChar
**) xmlMalloc(10 *
27382 sizeof(const xmlChar
*));
27383 if (ielem
->nsBindings
== NULL
) {
27384 xmlSchemaVErrMemory(vctxt
,
27385 "allocating namespace bindings for SAX validation",
27387 goto internal_error
;
27389 ielem
->nbNsBindings
= 0;
27390 ielem
->sizeNsBindings
= 5;
27391 } else if (ielem
->sizeNsBindings
<= ielem
->nbNsBindings
) {
27392 ielem
->sizeNsBindings
*= 2;
27393 ielem
->nsBindings
=
27394 (const xmlChar
**) xmlRealloc(
27395 (void *) ielem
->nsBindings
,
27396 ielem
->sizeNsBindings
* 2 * sizeof(const xmlChar
*));
27397 if (ielem
->nsBindings
== NULL
) {
27398 xmlSchemaVErrMemory(vctxt
,
27399 "re-allocating namespace bindings for SAX validation",
27401 goto internal_error
;
27405 ielem
->nsBindings
[ielem
->nbNsBindings
* 2] = namespaces
[j
];
27406 if (namespaces
[j
+1][0] == 0) {
27410 ielem
->nsBindings
[ielem
->nbNsBindings
* 2 + 1] = NULL
;
27412 ielem
->nsBindings
[ielem
->nbNsBindings
* 2 + 1] =
27414 ielem
->nbNsBindings
++;
27418 * Register attributes.
27419 * SAX VAL TODO: We are not adding namespace declaration
27422 if (nb_attributes
!= 0) {
27423 int valueLen
, k
, l
;
27426 for (j
= 0, i
= 0; i
< nb_attributes
; i
++, j
+= 5) {
27428 * Duplicate the value, changing any & to a literal ampersand.
27430 * libxml2 differs from normal SAX here in that it escapes all ampersands
27431 * as & instead of delivering the raw converted string. Changing the
27432 * behavior at this point would break applications that use this API, so
27433 * we are forced to work around it.
27435 valueLen
= attributes
[j
+4] - attributes
[j
+3];
27436 value
= xmlMallocAtomic(valueLen
+ 1);
27437 if (value
== NULL
) {
27438 xmlSchemaVErrMemory(vctxt
,
27439 "allocating string for decoded attribute",
27441 goto internal_error
;
27443 for (k
= 0, l
= 0; k
< valueLen
; l
++) {
27444 if (k
< valueLen
- 4 &&
27445 attributes
[j
+3][k
+0] == '&' &&
27446 attributes
[j
+3][k
+1] == '#' &&
27447 attributes
[j
+3][k
+2] == '3' &&
27448 attributes
[j
+3][k
+3] == '8' &&
27449 attributes
[j
+3][k
+4] == ';') {
27453 value
[l
] = attributes
[j
+3][k
];
27459 * TODO: Set the node line.
27461 ret
= xmlSchemaValidatorPushAttribute(vctxt
,
27462 NULL
, ielem
->nodeLine
, attributes
[j
], attributes
[j
+2], 0,
27465 VERROR_INT("xmlSchemaSAXHandleStartElementNs",
27466 "calling xmlSchemaValidatorPushAttribute()");
27467 goto internal_error
;
27472 * Validate the element.
27474 ret
= xmlSchemaValidateElem(vctxt
);
27477 VERROR_INT("xmlSchemaSAXHandleStartElementNs",
27478 "calling xmlSchemaValidateElem()");
27479 goto internal_error
;
27488 xmlStopParser(vctxt
->parserCtxt
);
27493 xmlSchemaSAXHandleEndElementNs(void *ctx
,
27494 const xmlChar
* localname ATTRIBUTE_UNUSED
,
27495 const xmlChar
* prefix ATTRIBUTE_UNUSED
,
27496 const xmlChar
* URI ATTRIBUTE_UNUSED
)
27498 xmlSchemaValidCtxtPtr vctxt
= (xmlSchemaValidCtxtPtr
) ctx
;
27502 * Skip elements if inside a "skip" wildcard or if invalid.
27504 if (vctxt
->skipDepth
!= -1) {
27505 if (vctxt
->depth
> vctxt
->skipDepth
) {
27509 vctxt
->skipDepth
= -1;
27512 * SAX VAL TODO: Just a temporary check.
27514 if ((!xmlStrEqual(vctxt
->inode
->localName
, localname
)) ||
27515 (!xmlStrEqual(vctxt
->inode
->nsName
, URI
))) {
27516 VERROR_INT("xmlSchemaSAXHandleEndElementNs",
27517 "elem pop mismatch");
27519 res
= xmlSchemaValidatorPopElem(vctxt
);
27522 VERROR_INT("xmlSchemaSAXHandleEndElementNs",
27523 "calling xmlSchemaValidatorPopElem()");
27524 goto internal_error
;
27532 xmlStopParser(vctxt
->parserCtxt
);
27536 /************************************************************************
27538 * Validation interfaces *
27540 ************************************************************************/
27543 * xmlSchemaNewValidCtxt:
27544 * @schema: a precompiled XML Schemas
27546 * Create an XML Schemas validation context based on the given schema.
27548 * Returns the validation context or NULL in case of error
27550 xmlSchemaValidCtxtPtr
27551 xmlSchemaNewValidCtxt(xmlSchemaPtr schema
)
27553 xmlSchemaValidCtxtPtr ret
;
27555 ret
= (xmlSchemaValidCtxtPtr
) xmlMalloc(sizeof(xmlSchemaValidCtxt
));
27557 xmlSchemaVErrMemory(NULL
, "allocating validation context", NULL
);
27560 memset(ret
, 0, sizeof(xmlSchemaValidCtxt
));
27561 ret
->type
= XML_SCHEMA_CTXT_VALIDATOR
;
27562 ret
->dict
= xmlDictCreate();
27563 ret
->nodeQNames
= xmlSchemaItemListCreate();
27564 ret
->schema
= schema
;
27569 * xmlSchemaValidateSetFilename:
27570 * @vctxt: the schema validation context
27571 * @filename: the file name
27573 * Workaround to provide file error reporting information when this is
27574 * not provided by current APIs
27577 xmlSchemaValidateSetFilename(xmlSchemaValidCtxtPtr vctxt
, const char *filename
) {
27580 if (vctxt
->filename
!= NULL
)
27581 xmlFree(vctxt
->filename
);
27582 if (filename
!= NULL
)
27583 vctxt
->filename
= (char *) xmlStrdup((const xmlChar
*) filename
);
27585 vctxt
->filename
= NULL
;
27589 * xmlSchemaClearValidCtxt:
27590 * @vctxt: the schema validation context
27592 * Free the resources associated to the schema validation context;
27593 * leaves some fields alive intended for reuse of the context.
27596 xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt
)
27602 * TODO: Should we clear the flags?
27603 * Might be problematic if one reuses the context
27604 * and assumes that the options remain the same.
27607 vctxt
->validationRoot
= NULL
;
27609 #ifdef LIBXML_READER_ENABLED
27610 vctxt
->reader
= NULL
;
27612 vctxt
->hasKeyrefs
= 0;
27614 if (vctxt
->value
!= NULL
) {
27615 xmlSchemaFreeValue(vctxt
->value
);
27616 vctxt
->value
= NULL
;
27619 * Augmented IDC information.
27621 if (vctxt
->aidcs
!= NULL
) {
27622 xmlSchemaIDCAugPtr cur
= vctxt
->aidcs
, next
;
27627 } while (cur
!= NULL
);
27628 vctxt
->aidcs
= NULL
;
27630 if (vctxt
->idcMatcherCache
!= NULL
) {
27631 xmlSchemaIDCMatcherPtr matcher
= vctxt
->idcMatcherCache
, tmp
;
27635 matcher
= matcher
->nextCached
;
27636 xmlSchemaIDCFreeMatcherList(tmp
);
27638 vctxt
->idcMatcherCache
= NULL
;
27642 if (vctxt
->idcNodes
!= NULL
) {
27644 xmlSchemaPSVIIDCNodePtr item
;
27646 for (i
= 0; i
< vctxt
->nbIdcNodes
; i
++) {
27647 item
= vctxt
->idcNodes
[i
];
27648 xmlFree(item
->keys
);
27651 xmlFree(vctxt
->idcNodes
);
27652 vctxt
->idcNodes
= NULL
;
27653 vctxt
->nbIdcNodes
= 0;
27654 vctxt
->sizeIdcNodes
= 0;
27657 if (vctxt
->idcKeys
!= NULL
) {
27659 for (i
= 0; i
< vctxt
->nbIdcKeys
; i
++)
27660 xmlSchemaIDCFreeKey(vctxt
->idcKeys
[i
]);
27661 xmlFree(vctxt
->idcKeys
);
27662 vctxt
->idcKeys
= NULL
;
27663 vctxt
->nbIdcKeys
= 0;
27664 vctxt
->sizeIdcKeys
= 0;
27668 * Note that we won't delete the XPath state pool here.
27670 if (vctxt
->xpathStates
!= NULL
) {
27671 xmlSchemaFreeIDCStateObjList(vctxt
->xpathStates
);
27672 vctxt
->xpathStates
= NULL
;
27677 if (vctxt
->nbAttrInfos
!= 0) {
27678 xmlSchemaClearAttrInfos(vctxt
);
27683 if (vctxt
->elemInfos
!= NULL
) {
27685 xmlSchemaNodeInfoPtr ei
;
27687 for (i
= 0; i
< vctxt
->sizeElemInfos
; i
++) {
27688 ei
= vctxt
->elemInfos
[i
];
27691 xmlSchemaClearElemInfo(vctxt
, ei
);
27694 xmlSchemaItemListClear(vctxt
->nodeQNames
);
27695 /* Recreate the dict. */
27696 xmlDictFree(vctxt
->dict
);
27698 * TODO: Is is save to recreate it? Do we have a scenario
27699 * where the user provides the dict?
27701 vctxt
->dict
= xmlDictCreate();
27703 if (vctxt
->filename
!= NULL
) {
27704 xmlFree(vctxt
->filename
);
27705 vctxt
->filename
= NULL
;
27710 * xmlSchemaFreeValidCtxt:
27711 * @ctxt: the schema validation context
27713 * Free the resources associated to the schema validation context
27716 xmlSchemaFreeValidCtxt(xmlSchemaValidCtxtPtr ctxt
)
27720 if (ctxt
->value
!= NULL
)
27721 xmlSchemaFreeValue(ctxt
->value
);
27722 if (ctxt
->pctxt
!= NULL
)
27723 xmlSchemaFreeParserCtxt(ctxt
->pctxt
);
27724 if (ctxt
->idcNodes
!= NULL
) {
27726 xmlSchemaPSVIIDCNodePtr item
;
27728 for (i
= 0; i
< ctxt
->nbIdcNodes
; i
++) {
27729 item
= ctxt
->idcNodes
[i
];
27730 xmlFree(item
->keys
);
27733 xmlFree(ctxt
->idcNodes
);
27735 if (ctxt
->idcKeys
!= NULL
) {
27737 for (i
= 0; i
< ctxt
->nbIdcKeys
; i
++)
27738 xmlSchemaIDCFreeKey(ctxt
->idcKeys
[i
]);
27739 xmlFree(ctxt
->idcKeys
);
27742 if (ctxt
->xpathStates
!= NULL
) {
27743 xmlSchemaFreeIDCStateObjList(ctxt
->xpathStates
);
27744 ctxt
->xpathStates
= NULL
;
27746 if (ctxt
->xpathStatePool
!= NULL
) {
27747 xmlSchemaFreeIDCStateObjList(ctxt
->xpathStatePool
);
27748 ctxt
->xpathStatePool
= NULL
;
27752 * Augmented IDC information.
27754 if (ctxt
->aidcs
!= NULL
) {
27755 xmlSchemaIDCAugPtr cur
= ctxt
->aidcs
, next
;
27760 } while (cur
!= NULL
);
27762 if (ctxt
->attrInfos
!= NULL
) {
27764 xmlSchemaAttrInfoPtr attr
;
27766 /* Just a paranoid call to the cleanup. */
27767 if (ctxt
->nbAttrInfos
!= 0)
27768 xmlSchemaClearAttrInfos(ctxt
);
27769 for (i
= 0; i
< ctxt
->sizeAttrInfos
; i
++) {
27770 attr
= ctxt
->attrInfos
[i
];
27773 xmlFree(ctxt
->attrInfos
);
27775 if (ctxt
->elemInfos
!= NULL
) {
27777 xmlSchemaNodeInfoPtr ei
;
27779 for (i
= 0; i
< ctxt
->sizeElemInfos
; i
++) {
27780 ei
= ctxt
->elemInfos
[i
];
27783 xmlSchemaClearElemInfo(ctxt
, ei
);
27786 xmlFree(ctxt
->elemInfos
);
27788 if (ctxt
->nodeQNames
!= NULL
)
27789 xmlSchemaItemListFree(ctxt
->nodeQNames
);
27790 if (ctxt
->dict
!= NULL
)
27791 xmlDictFree(ctxt
->dict
);
27792 if (ctxt
->filename
!= NULL
)
27793 xmlFree(ctxt
->filename
);
27798 * xmlSchemaIsValid:
27799 * @ctxt: the schema validation context
27801 * Check if any error was detected during validation.
27803 * Returns 1 if valid so far, 0 if errors were detected, and -1 in case
27804 * of internal error.
27807 xmlSchemaIsValid(xmlSchemaValidCtxtPtr ctxt
)
27811 return(ctxt
->err
== 0);
27815 * xmlSchemaSetValidErrors:
27816 * @ctxt: a schema validation context
27817 * @err: the error function
27818 * @warn: the warning function
27819 * @ctx: the functions context
27821 * Set the error and warning callback informations
27824 xmlSchemaSetValidErrors(xmlSchemaValidCtxtPtr ctxt
,
27825 xmlSchemaValidityErrorFunc err
,
27826 xmlSchemaValidityWarningFunc warn
, void *ctx
)
27831 ctxt
->warning
= warn
;
27832 ctxt
->errCtxt
= ctx
;
27833 if (ctxt
->pctxt
!= NULL
)
27834 xmlSchemaSetParserErrors(ctxt
->pctxt
, err
, warn
, ctx
);
27838 * xmlSchemaSetValidStructuredErrors:
27839 * @ctxt: a schema validation context
27840 * @serror: the structured error function
27841 * @ctx: the functions context
27843 * Set the structured error callback
27846 xmlSchemaSetValidStructuredErrors(xmlSchemaValidCtxtPtr ctxt
,
27847 xmlStructuredErrorFunc serror
, void *ctx
)
27851 ctxt
->serror
= serror
;
27852 ctxt
->error
= NULL
;
27853 ctxt
->warning
= NULL
;
27854 ctxt
->errCtxt
= ctx
;
27855 if (ctxt
->pctxt
!= NULL
)
27856 xmlSchemaSetParserStructuredErrors(ctxt
->pctxt
, serror
, ctx
);
27860 * xmlSchemaGetValidErrors:
27861 * @ctxt: a XML-Schema validation context
27862 * @err: the error function result
27863 * @warn: the warning function result
27864 * @ctx: the functions context result
27866 * Get the error and warning callback informations
27868 * Returns -1 in case of error and 0 otherwise
27871 xmlSchemaGetValidErrors(xmlSchemaValidCtxtPtr ctxt
,
27872 xmlSchemaValidityErrorFunc
* err
,
27873 xmlSchemaValidityWarningFunc
* warn
, void **ctx
)
27878 *err
= ctxt
->error
;
27880 *warn
= ctxt
->warning
;
27882 *ctx
= ctxt
->errCtxt
;
27888 * xmlSchemaSetValidOptions:
27889 * @ctxt: a schema validation context
27890 * @options: a combination of xmlSchemaValidOption
27892 * Sets the options to be used during the validation.
27894 * Returns 0 in case of success, -1 in case of an
27898 xmlSchemaSetValidOptions(xmlSchemaValidCtxtPtr ctxt
,
27907 * WARNING: Change the start value if adding to the
27908 * xmlSchemaValidOption.
27909 * TODO: Is there an other, more easy to maintain,
27912 for (i
= 1; i
< (int) sizeof(int) * 8; i
++) {
27913 if (options
& 1<<i
)
27916 ctxt
->options
= options
;
27921 * xmlSchemaValidCtxtGetOptions:
27922 * @ctxt: a schema validation context
27924 * Get the validation context options.
27926 * Returns the option combination or -1 on error.
27929 xmlSchemaValidCtxtGetOptions(xmlSchemaValidCtxtPtr ctxt
)
27935 return (ctxt
->options
);
27939 xmlSchemaVDocWalk(xmlSchemaValidCtxtPtr vctxt
)
27943 xmlSchemaNodeInfoPtr ielem
= NULL
;
27944 xmlNodePtr node
, valRoot
;
27945 const xmlChar
*nsName
;
27947 /* DOC VAL TODO: Move this to the start function. */
27948 if (vctxt
->validationRoot
!= NULL
)
27949 valRoot
= vctxt
->validationRoot
;
27951 valRoot
= xmlDocGetRootElement(vctxt
->doc
);
27952 if (valRoot
== NULL
) {
27953 /* VAL TODO: Error code? */
27954 VERROR(1, NULL
, "The document has no document element");
27958 vctxt
->validationRoot
= valRoot
;
27960 while (node
!= NULL
) {
27961 if ((vctxt
->skipDepth
!= -1) && (vctxt
->depth
>= vctxt
->skipDepth
))
27963 if (node
->type
== XML_ELEMENT_NODE
) {
27966 * Init the node-info.
27969 if (xmlSchemaValidatorPushElem(vctxt
) == -1)
27970 goto internal_error
;
27971 ielem
= vctxt
->inode
;
27972 ielem
->node
= node
;
27973 ielem
->nodeLine
= node
->line
;
27974 ielem
->localName
= node
->name
;
27975 if (node
->ns
!= NULL
)
27976 ielem
->nsName
= node
->ns
->href
;
27977 ielem
->flags
|= XML_SCHEMA_ELEM_INFO_EMPTY
;
27979 * Register attributes.
27980 * DOC VAL TODO: We do not register namespace declaration
27983 vctxt
->nbAttrInfos
= 0;
27984 if (node
->properties
!= NULL
) {
27985 attr
= node
->properties
;
27987 if (attr
->ns
!= NULL
)
27988 nsName
= attr
->ns
->href
;
27991 ret
= xmlSchemaValidatorPushAttribute(vctxt
,
27994 * Note that we give it the line number of the
27998 attr
->name
, nsName
, 0,
27999 xmlNodeListGetString(attr
->doc
, attr
->children
, 1), 1);
28001 VERROR_INT("xmlSchemaDocWalk",
28002 "calling xmlSchemaValidatorPushAttribute()");
28003 goto internal_error
;
28009 * Validate the element.
28011 ret
= xmlSchemaValidateElem(vctxt
);
28014 VERROR_INT("xmlSchemaDocWalk",
28015 "calling xmlSchemaValidateElem()");
28016 goto internal_error
;
28019 * Don't stop validation; just skip the content
28024 if ((vctxt
->skipDepth
!= -1) &&
28025 (vctxt
->depth
>= vctxt
->skipDepth
))
28027 } else if ((node
->type
== XML_TEXT_NODE
) ||
28028 (node
->type
== XML_CDATA_SECTION_NODE
)) {
28030 * Process character content.
28032 if ((ielem
!= NULL
) && (ielem
->flags
& XML_SCHEMA_ELEM_INFO_EMPTY
))
28033 ielem
->flags
^= XML_SCHEMA_ELEM_INFO_EMPTY
;
28034 ret
= xmlSchemaVPushText(vctxt
, node
->type
, node
->content
,
28035 -1, XML_SCHEMA_PUSH_TEXT_PERSIST
, NULL
);
28037 VERROR_INT("xmlSchemaVDocWalk",
28038 "calling xmlSchemaVPushText()");
28039 goto internal_error
;
28042 * DOC VAL TODO: Should we skip further validation of the
28043 * element content here?
28045 } else if ((node
->type
== XML_ENTITY_NODE
) ||
28046 (node
->type
== XML_ENTITY_REF_NODE
)) {
28048 * DOC VAL TODO: What to do with entities?
28050 VERROR_INT("xmlSchemaVDocWalk",
28051 "there is at least one entity reference in the node-tree "
28052 "currently being validated. Processing of entities with "
28053 "this XML Schema processor is not supported (yet). Please "
28054 "substitute entities before validation.");
28055 goto internal_error
;
28059 * DOC VAL TODO: XInclude nodes, etc.
28065 if (node
->children
!= NULL
) {
28066 node
= node
->children
;
28070 if (node
->type
== XML_ELEMENT_NODE
) {
28072 * Leaving the scope of an element.
28074 if (node
!= vctxt
->inode
->node
) {
28075 VERROR_INT("xmlSchemaVDocWalk",
28076 "element position mismatch");
28077 goto internal_error
;
28079 ret
= xmlSchemaValidatorPopElem(vctxt
);
28082 VERROR_INT("xmlSchemaVDocWalk",
28083 "calling xmlSchemaValidatorPopElem()");
28084 goto internal_error
;
28087 if (node
== valRoot
)
28091 if (node
->next
!= NULL
)
28094 node
= node
->parent
;
28106 xmlSchemaPreRun(xmlSchemaValidCtxtPtr vctxt
) {
28108 * Some initialization.
28111 vctxt
->nberrors
= 0;
28113 vctxt
->skipDepth
= -1;
28114 vctxt
->xsiAssemble
= 0;
28115 vctxt
->hasKeyrefs
= 0;
28116 #ifdef ENABLE_IDC_NODE_TABLES_TEST
28117 vctxt
->createIDCNodeTables
= 1;
28119 vctxt
->createIDCNodeTables
= 0;
28122 * Create a schema + parser if necessary.
28124 if (vctxt
->schema
== NULL
) {
28125 xmlSchemaParserCtxtPtr pctxt
;
28127 vctxt
->xsiAssemble
= 1;
28129 * If not schema was given then we will create a schema
28130 * dynamically using XSI schema locations.
28132 * Create the schema parser context.
28134 if ((vctxt
->pctxt
== NULL
) &&
28135 (xmlSchemaCreatePCtxtOnVCtxt(vctxt
) == -1))
28137 pctxt
= vctxt
->pctxt
;
28138 pctxt
->xsiAssemble
= 1;
28140 * Create the schema.
28142 vctxt
->schema
= xmlSchemaNewSchema(pctxt
);
28143 if (vctxt
->schema
== NULL
)
28146 * Create the schema construction context.
28148 pctxt
->constructor
= xmlSchemaConstructionCtxtCreate(pctxt
->dict
);
28149 if (pctxt
->constructor
== NULL
)
28151 pctxt
->constructor
->mainSchema
= vctxt
->schema
;
28153 * Take ownership of the constructor to be able to free it.
28155 pctxt
->ownsConstructor
= 1;
28158 * Augment the IDC definitions for the main schema and all imported ones
28159 * NOTE: main schema if the first in the imported list
28161 xmlHashScan(vctxt
->schema
->schemasImports
, xmlSchemaAugmentImportedIDC
,
28168 xmlSchemaPostRun(xmlSchemaValidCtxtPtr vctxt
) {
28169 if (vctxt
->xsiAssemble
) {
28170 if (vctxt
->schema
!= NULL
) {
28171 xmlSchemaFree(vctxt
->schema
);
28172 vctxt
->schema
= NULL
;
28175 xmlSchemaClearValidCtxt(vctxt
);
28179 xmlSchemaVStart(xmlSchemaValidCtxtPtr vctxt
)
28183 if (xmlSchemaPreRun(vctxt
) < 0)
28186 if (vctxt
->doc
!= NULL
) {
28190 ret
= xmlSchemaVDocWalk(vctxt
);
28191 #ifdef LIBXML_READER_ENABLED
28192 } else if (vctxt
->reader
!= NULL
) {
28194 * XML Reader validation.
28196 #ifdef XML_SCHEMA_READER_ENABLED
28197 ret
= xmlSchemaVReaderWalk(vctxt
);
28200 } else if ((vctxt
->sax
!= NULL
) && (vctxt
->parserCtxt
!= NULL
)) {
28204 ret
= xmlParseDocument(vctxt
->parserCtxt
);
28206 VERROR_INT("xmlSchemaVStart",
28207 "no instance to validate");
28211 xmlSchemaPostRun(vctxt
);
28218 * xmlSchemaValidateOneElement:
28219 * @ctxt: a schema validation context
28220 * @elem: an element node
28222 * Validate a branch of a tree, starting with the given @elem.
28224 * Returns 0 if the element and its subtree is valid, a positive error
28225 * code number otherwise and -1 in case of an internal or API error.
28228 xmlSchemaValidateOneElement(xmlSchemaValidCtxtPtr ctxt
, xmlNodePtr elem
)
28230 if ((ctxt
== NULL
) || (elem
== NULL
) || (elem
->type
!= XML_ELEMENT_NODE
))
28233 if (ctxt
->schema
== NULL
)
28236 ctxt
->doc
= elem
->doc
;
28238 ctxt
->validationRoot
= elem
;
28239 return(xmlSchemaVStart(ctxt
));
28243 * xmlSchemaValidateDoc:
28244 * @ctxt: a schema validation context
28245 * @doc: a parsed document tree
28247 * Validate a document tree in memory.
28249 * Returns 0 if the document is schemas valid, a positive error code
28250 * number otherwise and -1 in case of internal or API error.
28253 xmlSchemaValidateDoc(xmlSchemaValidCtxtPtr ctxt
, xmlDocPtr doc
)
28255 if ((ctxt
== NULL
) || (doc
== NULL
))
28259 ctxt
->node
= xmlDocGetRootElement(doc
);
28260 if (ctxt
->node
== NULL
) {
28261 xmlSchemaCustomErr(ACTXT_CAST ctxt
,
28262 XML_SCHEMAV_DOCUMENT_ELEMENT_MISSING
,
28263 (xmlNodePtr
) doc
, NULL
,
28264 "The document has no document element", NULL
, NULL
);
28265 return (ctxt
->err
);
28267 ctxt
->validationRoot
= ctxt
->node
;
28268 return (xmlSchemaVStart(ctxt
));
28272 /************************************************************************
28274 * Function and data for SAX streaming API *
28276 ************************************************************************/
28277 typedef struct _xmlSchemaSplitSAXData xmlSchemaSplitSAXData
;
28278 typedef xmlSchemaSplitSAXData
*xmlSchemaSplitSAXDataPtr
;
28280 struct _xmlSchemaSplitSAXData
{
28281 xmlSAXHandlerPtr user_sax
;
28283 xmlSchemaValidCtxtPtr ctxt
;
28284 xmlSAXHandlerPtr schemas_sax
;
28287 #define XML_SAX_PLUG_MAGIC 0xdc43ba21
28289 struct _xmlSchemaSAXPlug
{
28290 unsigned int magic
;
28292 /* the original callbacks informations */
28293 xmlSAXHandlerPtr
*user_sax_ptr
;
28294 xmlSAXHandlerPtr user_sax
;
28295 void **user_data_ptr
;
28298 /* the block plugged back and validation informations */
28299 xmlSAXHandler schemas_sax
;
28300 xmlSchemaValidCtxtPtr ctxt
;
28303 /* All those functions just bounces to the user provided SAX handlers */
28305 internalSubsetSplit(void *ctx
, const xmlChar
*name
,
28306 const xmlChar
*ExternalID
, const xmlChar
*SystemID
)
28308 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28309 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28310 (ctxt
->user_sax
->internalSubset
!= NULL
))
28311 ctxt
->user_sax
->internalSubset(ctxt
->user_data
, name
, ExternalID
,
28316 isStandaloneSplit(void *ctx
)
28318 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28319 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28320 (ctxt
->user_sax
->isStandalone
!= NULL
))
28321 return(ctxt
->user_sax
->isStandalone(ctxt
->user_data
));
28326 hasInternalSubsetSplit(void *ctx
)
28328 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28329 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28330 (ctxt
->user_sax
->hasInternalSubset
!= NULL
))
28331 return(ctxt
->user_sax
->hasInternalSubset(ctxt
->user_data
));
28336 hasExternalSubsetSplit(void *ctx
)
28338 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28339 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28340 (ctxt
->user_sax
->hasExternalSubset
!= NULL
))
28341 return(ctxt
->user_sax
->hasExternalSubset(ctxt
->user_data
));
28346 externalSubsetSplit(void *ctx
, const xmlChar
*name
,
28347 const xmlChar
*ExternalID
, const xmlChar
*SystemID
)
28349 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28350 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28351 (ctxt
->user_sax
->externalSubset
!= NULL
))
28352 ctxt
->user_sax
->externalSubset(ctxt
->user_data
, name
, ExternalID
,
28356 static xmlParserInputPtr
28357 resolveEntitySplit(void *ctx
, const xmlChar
*publicId
, const xmlChar
*systemId
)
28359 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28360 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28361 (ctxt
->user_sax
->resolveEntity
!= NULL
))
28362 return(ctxt
->user_sax
->resolveEntity(ctxt
->user_data
, publicId
,
28367 static xmlEntityPtr
28368 getEntitySplit(void *ctx
, const xmlChar
*name
)
28370 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28371 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28372 (ctxt
->user_sax
->getEntity
!= NULL
))
28373 return(ctxt
->user_sax
->getEntity(ctxt
->user_data
, name
));
28377 static xmlEntityPtr
28378 getParameterEntitySplit(void *ctx
, const xmlChar
*name
)
28380 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28381 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28382 (ctxt
->user_sax
->getParameterEntity
!= NULL
))
28383 return(ctxt
->user_sax
->getParameterEntity(ctxt
->user_data
, name
));
28389 entityDeclSplit(void *ctx
, const xmlChar
*name
, int type
,
28390 const xmlChar
*publicId
, const xmlChar
*systemId
, xmlChar
*content
)
28392 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28393 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28394 (ctxt
->user_sax
->entityDecl
!= NULL
))
28395 ctxt
->user_sax
->entityDecl(ctxt
->user_data
, name
, type
, publicId
,
28396 systemId
, content
);
28400 attributeDeclSplit(void *ctx
, const xmlChar
* elem
,
28401 const xmlChar
* name
, int type
, int def
,
28402 const xmlChar
* defaultValue
, xmlEnumerationPtr tree
)
28404 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28405 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28406 (ctxt
->user_sax
->attributeDecl
!= NULL
)) {
28407 ctxt
->user_sax
->attributeDecl(ctxt
->user_data
, elem
, name
, type
,
28408 def
, defaultValue
, tree
);
28410 xmlFreeEnumeration(tree
);
28415 elementDeclSplit(void *ctx
, const xmlChar
*name
, int type
,
28416 xmlElementContentPtr content
)
28418 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28419 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28420 (ctxt
->user_sax
->elementDecl
!= NULL
))
28421 ctxt
->user_sax
->elementDecl(ctxt
->user_data
, name
, type
, content
);
28425 notationDeclSplit(void *ctx
, const xmlChar
*name
,
28426 const xmlChar
*publicId
, const xmlChar
*systemId
)
28428 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28429 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28430 (ctxt
->user_sax
->notationDecl
!= NULL
))
28431 ctxt
->user_sax
->notationDecl(ctxt
->user_data
, name
, publicId
,
28436 unparsedEntityDeclSplit(void *ctx
, const xmlChar
*name
,
28437 const xmlChar
*publicId
, const xmlChar
*systemId
,
28438 const xmlChar
*notationName
)
28440 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28441 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28442 (ctxt
->user_sax
->unparsedEntityDecl
!= NULL
))
28443 ctxt
->user_sax
->unparsedEntityDecl(ctxt
->user_data
, name
, publicId
,
28444 systemId
, notationName
);
28448 setDocumentLocatorSplit(void *ctx
, xmlSAXLocatorPtr loc
)
28450 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28451 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28452 (ctxt
->user_sax
->setDocumentLocator
!= NULL
))
28453 ctxt
->user_sax
->setDocumentLocator(ctxt
->user_data
, loc
);
28457 startDocumentSplit(void *ctx
)
28459 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28460 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28461 (ctxt
->user_sax
->startDocument
!= NULL
))
28462 ctxt
->user_sax
->startDocument(ctxt
->user_data
);
28466 endDocumentSplit(void *ctx
)
28468 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28469 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28470 (ctxt
->user_sax
->endDocument
!= NULL
))
28471 ctxt
->user_sax
->endDocument(ctxt
->user_data
);
28475 processingInstructionSplit(void *ctx
, const xmlChar
*target
,
28476 const xmlChar
*data
)
28478 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28479 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28480 (ctxt
->user_sax
->processingInstruction
!= NULL
))
28481 ctxt
->user_sax
->processingInstruction(ctxt
->user_data
, target
, data
);
28485 commentSplit(void *ctx
, const xmlChar
*value
)
28487 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28488 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28489 (ctxt
->user_sax
->comment
!= NULL
))
28490 ctxt
->user_sax
->comment(ctxt
->user_data
, value
);
28494 * Varargs error callbacks to the user application, harder ...
28497 static void XMLCDECL
28498 warningSplit(void *ctx
, const char *msg ATTRIBUTE_UNUSED
, ...) {
28499 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28500 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28501 (ctxt
->user_sax
->warning
!= NULL
)) {
28505 static void XMLCDECL
28506 errorSplit(void *ctx
, const char *msg ATTRIBUTE_UNUSED
, ...) {
28507 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28508 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28509 (ctxt
->user_sax
->error
!= NULL
)) {
28513 static void XMLCDECL
28514 fatalErrorSplit(void *ctx
, const char *msg ATTRIBUTE_UNUSED
, ...) {
28515 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28516 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28517 (ctxt
->user_sax
->fatalError
!= NULL
)) {
28523 * Those are function where both the user handler and the schemas handler
28524 * need to be called.
28527 charactersSplit(void *ctx
, const xmlChar
*ch
, int len
)
28529 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28532 if ((ctxt
->user_sax
!= NULL
) && (ctxt
->user_sax
->characters
!= NULL
))
28533 ctxt
->user_sax
->characters(ctxt
->user_data
, ch
, len
);
28534 if (ctxt
->ctxt
!= NULL
)
28535 xmlSchemaSAXHandleText(ctxt
->ctxt
, ch
, len
);
28539 ignorableWhitespaceSplit(void *ctx
, const xmlChar
*ch
, int len
)
28541 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28544 if ((ctxt
->user_sax
!= NULL
) &&
28545 (ctxt
->user_sax
->ignorableWhitespace
!= NULL
))
28546 ctxt
->user_sax
->ignorableWhitespace(ctxt
->user_data
, ch
, len
);
28547 if (ctxt
->ctxt
!= NULL
)
28548 xmlSchemaSAXHandleText(ctxt
->ctxt
, ch
, len
);
28552 cdataBlockSplit(void *ctx
, const xmlChar
*value
, int len
)
28554 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28557 if ((ctxt
->user_sax
!= NULL
) &&
28558 (ctxt
->user_sax
->cdataBlock
!= NULL
))
28559 ctxt
->user_sax
->cdataBlock(ctxt
->user_data
, value
, len
);
28560 if (ctxt
->ctxt
!= NULL
)
28561 xmlSchemaSAXHandleCDataSection(ctxt
->ctxt
, value
, len
);
28565 referenceSplit(void *ctx
, const xmlChar
*name
)
28567 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28570 if ((ctxt
!= NULL
) && (ctxt
->user_sax
!= NULL
) &&
28571 (ctxt
->user_sax
->reference
!= NULL
))
28572 ctxt
->user_sax
->reference(ctxt
->user_data
, name
);
28573 if (ctxt
->ctxt
!= NULL
)
28574 xmlSchemaSAXHandleReference(ctxt
->user_data
, name
);
28578 startElementNsSplit(void *ctx
, const xmlChar
* localname
,
28579 const xmlChar
* prefix
, const xmlChar
* URI
,
28580 int nb_namespaces
, const xmlChar
** namespaces
,
28581 int nb_attributes
, int nb_defaulted
,
28582 const xmlChar
** attributes
) {
28583 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28586 if ((ctxt
->user_sax
!= NULL
) &&
28587 (ctxt
->user_sax
->startElementNs
!= NULL
))
28588 ctxt
->user_sax
->startElementNs(ctxt
->user_data
, localname
, prefix
,
28589 URI
, nb_namespaces
, namespaces
,
28590 nb_attributes
, nb_defaulted
,
28592 if (ctxt
->ctxt
!= NULL
)
28593 xmlSchemaSAXHandleStartElementNs(ctxt
->ctxt
, localname
, prefix
,
28594 URI
, nb_namespaces
, namespaces
,
28595 nb_attributes
, nb_defaulted
,
28600 endElementNsSplit(void *ctx
, const xmlChar
* localname
,
28601 const xmlChar
* prefix
, const xmlChar
* URI
) {
28602 xmlSchemaSAXPlugPtr ctxt
= (xmlSchemaSAXPlugPtr
) ctx
;
28605 if ((ctxt
->user_sax
!= NULL
) &&
28606 (ctxt
->user_sax
->endElementNs
!= NULL
))
28607 ctxt
->user_sax
->endElementNs(ctxt
->user_data
, localname
, prefix
, URI
);
28608 if (ctxt
->ctxt
!= NULL
)
28609 xmlSchemaSAXHandleEndElementNs(ctxt
->ctxt
, localname
, prefix
, URI
);
28613 * xmlSchemaSAXPlug:
28614 * @ctxt: a schema validation context
28615 * @sax: a pointer to the original xmlSAXHandlerPtr
28616 * @user_data: a pointer to the original SAX user data pointer
28618 * Plug a SAX based validation layer in a SAX parsing event flow.
28619 * The original @saxptr and @dataptr data are replaced by new pointers
28620 * but the calls to the original will be maintained.
28622 * Returns a pointer to a data structure needed to unplug the validation layer
28623 * or NULL in case of errors.
28625 xmlSchemaSAXPlugPtr
28626 xmlSchemaSAXPlug(xmlSchemaValidCtxtPtr ctxt
,
28627 xmlSAXHandlerPtr
*sax
, void **user_data
)
28629 xmlSchemaSAXPlugPtr ret
;
28630 xmlSAXHandlerPtr old_sax
;
28632 if ((ctxt
== NULL
) || (sax
== NULL
) || (user_data
== NULL
))
28636 * We only allow to plug into SAX2 event streams
28639 if ((old_sax
!= NULL
) && (old_sax
->initialized
!= XML_SAX2_MAGIC
))
28641 if ((old_sax
!= NULL
) &&
28642 (old_sax
->startElementNs
== NULL
) && (old_sax
->endElementNs
== NULL
) &&
28643 ((old_sax
->startElement
!= NULL
) || (old_sax
->endElement
!= NULL
)))
28647 * everything seems right allocate the local data needed for that layer
28649 ret
= (xmlSchemaSAXPlugPtr
) xmlMalloc(sizeof(xmlSchemaSAXPlugStruct
));
28653 memset(ret
, 0, sizeof(xmlSchemaSAXPlugStruct
));
28654 ret
->magic
= XML_SAX_PLUG_MAGIC
;
28655 ret
->schemas_sax
.initialized
= XML_SAX2_MAGIC
;
28657 ret
->user_sax_ptr
= sax
;
28658 ret
->user_sax
= old_sax
;
28659 if (old_sax
== NULL
) {
28661 * go direct, no need for the split block and functions.
28663 ret
->schemas_sax
.startElementNs
= xmlSchemaSAXHandleStartElementNs
;
28664 ret
->schemas_sax
.endElementNs
= xmlSchemaSAXHandleEndElementNs
;
28666 * Note that we use the same text-function for both, to prevent
28667 * the parser from testing for ignorable whitespace.
28669 ret
->schemas_sax
.ignorableWhitespace
= xmlSchemaSAXHandleText
;
28670 ret
->schemas_sax
.characters
= xmlSchemaSAXHandleText
;
28672 ret
->schemas_sax
.cdataBlock
= xmlSchemaSAXHandleCDataSection
;
28673 ret
->schemas_sax
.reference
= xmlSchemaSAXHandleReference
;
28675 ret
->user_data
= ctxt
;
28679 * for each callback unused by Schemas initialize it to the Split
28680 * routine only if non NULL in the user block, this can speed up
28681 * things at the SAX level.
28683 if (old_sax
->internalSubset
!= NULL
)
28684 ret
->schemas_sax
.internalSubset
= internalSubsetSplit
;
28685 if (old_sax
->isStandalone
!= NULL
)
28686 ret
->schemas_sax
.isStandalone
= isStandaloneSplit
;
28687 if (old_sax
->hasInternalSubset
!= NULL
)
28688 ret
->schemas_sax
.hasInternalSubset
= hasInternalSubsetSplit
;
28689 if (old_sax
->hasExternalSubset
!= NULL
)
28690 ret
->schemas_sax
.hasExternalSubset
= hasExternalSubsetSplit
;
28691 if (old_sax
->resolveEntity
!= NULL
)
28692 ret
->schemas_sax
.resolveEntity
= resolveEntitySplit
;
28693 if (old_sax
->getEntity
!= NULL
)
28694 ret
->schemas_sax
.getEntity
= getEntitySplit
;
28695 if (old_sax
->entityDecl
!= NULL
)
28696 ret
->schemas_sax
.entityDecl
= entityDeclSplit
;
28697 if (old_sax
->notationDecl
!= NULL
)
28698 ret
->schemas_sax
.notationDecl
= notationDeclSplit
;
28699 if (old_sax
->attributeDecl
!= NULL
)
28700 ret
->schemas_sax
.attributeDecl
= attributeDeclSplit
;
28701 if (old_sax
->elementDecl
!= NULL
)
28702 ret
->schemas_sax
.elementDecl
= elementDeclSplit
;
28703 if (old_sax
->unparsedEntityDecl
!= NULL
)
28704 ret
->schemas_sax
.unparsedEntityDecl
= unparsedEntityDeclSplit
;
28705 if (old_sax
->setDocumentLocator
!= NULL
)
28706 ret
->schemas_sax
.setDocumentLocator
= setDocumentLocatorSplit
;
28707 if (old_sax
->startDocument
!= NULL
)
28708 ret
->schemas_sax
.startDocument
= startDocumentSplit
;
28709 if (old_sax
->endDocument
!= NULL
)
28710 ret
->schemas_sax
.endDocument
= endDocumentSplit
;
28711 if (old_sax
->processingInstruction
!= NULL
)
28712 ret
->schemas_sax
.processingInstruction
= processingInstructionSplit
;
28713 if (old_sax
->comment
!= NULL
)
28714 ret
->schemas_sax
.comment
= commentSplit
;
28715 if (old_sax
->warning
!= NULL
)
28716 ret
->schemas_sax
.warning
= warningSplit
;
28717 if (old_sax
->error
!= NULL
)
28718 ret
->schemas_sax
.error
= errorSplit
;
28719 if (old_sax
->fatalError
!= NULL
)
28720 ret
->schemas_sax
.fatalError
= fatalErrorSplit
;
28721 if (old_sax
->getParameterEntity
!= NULL
)
28722 ret
->schemas_sax
.getParameterEntity
= getParameterEntitySplit
;
28723 if (old_sax
->externalSubset
!= NULL
)
28724 ret
->schemas_sax
.externalSubset
= externalSubsetSplit
;
28727 * the 6 schemas callback have to go to the splitter functions
28728 * Note that we use the same text-function for ignorableWhitespace
28729 * if possible, to prevent the parser from testing for ignorable
28732 ret
->schemas_sax
.characters
= charactersSplit
;
28733 if ((old_sax
->ignorableWhitespace
!= NULL
) &&
28734 (old_sax
->ignorableWhitespace
!= old_sax
->characters
))
28735 ret
->schemas_sax
.ignorableWhitespace
= ignorableWhitespaceSplit
;
28737 ret
->schemas_sax
.ignorableWhitespace
= charactersSplit
;
28738 ret
->schemas_sax
.cdataBlock
= cdataBlockSplit
;
28739 ret
->schemas_sax
.reference
= referenceSplit
;
28740 ret
->schemas_sax
.startElementNs
= startElementNsSplit
;
28741 ret
->schemas_sax
.endElementNs
= endElementNsSplit
;
28743 ret
->user_data_ptr
= user_data
;
28744 ret
->user_data
= *user_data
;
28749 * plug the pointers back.
28751 *sax
= &(ret
->schemas_sax
);
28753 ctxt
->flags
|= XML_SCHEMA_VALID_CTXT_FLAG_STREAM
;
28754 xmlSchemaPreRun(ctxt
);
28759 * xmlSchemaSAXUnplug:
28760 * @plug: a data structure returned by xmlSchemaSAXPlug
28762 * Unplug a SAX based validation layer in a SAX parsing event flow.
28763 * The original pointers used in the call are restored.
28765 * Returns 0 in case of success and -1 in case of failure.
28768 xmlSchemaSAXUnplug(xmlSchemaSAXPlugPtr plug
)
28770 xmlSAXHandlerPtr
*sax
;
28773 if ((plug
== NULL
) || (plug
->magic
!= XML_SAX_PLUG_MAGIC
))
28777 xmlSchemaPostRun(plug
->ctxt
);
28778 /* restore the data */
28779 sax
= plug
->user_sax_ptr
;
28780 *sax
= plug
->user_sax
;
28781 if (plug
->user_sax
!= NULL
) {
28782 user_data
= plug
->user_data_ptr
;
28783 *user_data
= plug
->user_data
;
28786 /* free and return */
28792 * xmlSchemaValidateSetLocator:
28793 * @vctxt: a schema validation context
28794 * @f: the locator function pointer
28795 * @ctxt: the locator context
28797 * Allows to set a locator function to the validation context,
28798 * which will be used to provide file and line information since
28799 * those are not provided as part of the SAX validation flow
28800 * Setting @f to NULL disable the locator.
28804 xmlSchemaValidateSetLocator(xmlSchemaValidCtxtPtr vctxt
,
28805 xmlSchemaValidityLocatorFunc f
,
28808 if (vctxt
== NULL
) return;
28809 vctxt
->locFunc
= f
;
28810 vctxt
->locCtxt
= ctxt
;
28814 * xmlSchemaValidateStreamLocator:
28815 * @ctx: the xmlTextReaderPtr used
28816 * @file: returned file information
28817 * @line: returned line information
28819 * Internal locator function for the readers
28821 * Returns 0 in case the Schema validation could be (des)activated and
28822 * -1 in case of error.
28825 xmlSchemaValidateStreamLocator(void *ctx
, const char **file
,
28826 unsigned long *line
) {
28827 xmlParserCtxtPtr ctxt
;
28829 if ((ctx
== NULL
) || ((file
== NULL
) && (line
== NULL
)))
28837 ctxt
= (xmlParserCtxtPtr
) ctx
;
28838 if (ctxt
->input
!= NULL
) {
28840 *file
= ctxt
->input
->filename
;
28842 *line
= ctxt
->input
->line
;
28849 * xmlSchemaValidateStream:
28850 * @ctxt: a schema validation context
28851 * @input: the input to use for reading the data
28852 * @enc: an optional encoding information
28853 * @sax: a SAX handler for the resulting events
28854 * @user_data: the context to provide to the SAX handler.
28856 * Validate an input based on a flow of SAX event from the parser
28857 * and forward the events to the @sax handler with the provided @user_data
28858 * the user provided @sax handler must be a SAX2 one.
28860 * Returns 0 if the document is schemas valid, a positive error code
28861 * number otherwise and -1 in case of internal or API error.
28864 xmlSchemaValidateStream(xmlSchemaValidCtxtPtr ctxt
,
28865 xmlParserInputBufferPtr input
, xmlCharEncoding enc
,
28866 xmlSAXHandlerPtr sax
, void *user_data
)
28868 xmlSchemaSAXPlugPtr plug
= NULL
;
28869 xmlSAXHandlerPtr old_sax
= NULL
;
28870 xmlParserCtxtPtr pctxt
= NULL
;
28871 xmlParserInputPtr inputStream
= NULL
;
28874 if ((ctxt
== NULL
) || (input
== NULL
))
28878 * prepare the parser
28880 pctxt
= xmlNewParserCtxt();
28883 old_sax
= pctxt
->sax
;
28885 pctxt
->userData
= user_data
;
28888 xmlCtxtUseOptions(pctxt
, options
);
28890 pctxt
->linenumbers
= 1;
28891 xmlSchemaValidateSetLocator(ctxt
, xmlSchemaValidateStreamLocator
, pctxt
);
28893 inputStream
= xmlNewIOInputStream(pctxt
, input
, enc
);;
28894 if (inputStream
== NULL
) {
28898 inputPush(pctxt
, inputStream
);
28899 ctxt
->parserCtxt
= pctxt
;
28900 ctxt
->input
= input
;
28903 * Plug the validation and launch the parsing
28905 plug
= xmlSchemaSAXPlug(ctxt
, &(pctxt
->sax
), &(pctxt
->userData
));
28906 if (plug
== NULL
) {
28910 ctxt
->input
= input
;
28912 ctxt
->sax
= pctxt
->sax
;
28913 ctxt
->flags
|= XML_SCHEMA_VALID_CTXT_FLAG_STREAM
;
28914 ret
= xmlSchemaVStart(ctxt
);
28916 if ((ret
== 0) && (! ctxt
->parserCtxt
->wellFormed
)) {
28917 ret
= ctxt
->parserCtxt
->errNo
;
28923 ctxt
->parserCtxt
= NULL
;
28925 ctxt
->input
= NULL
;
28926 if (plug
!= NULL
) {
28927 xmlSchemaSAXUnplug(plug
);
28930 if (pctxt
!= NULL
) {
28931 pctxt
->sax
= old_sax
;
28932 xmlFreeParserCtxt(pctxt
);
28938 * xmlSchemaValidateFile:
28939 * @ctxt: a schema validation context
28940 * @filename: the URI of the instance
28941 * @options: a future set of options, currently unused
28943 * Do a schemas validation of the given resource, it will use the
28944 * SAX streamable validation internally.
28946 * Returns 0 if the document is valid, a positive error code
28947 * number otherwise and -1 in case of an internal or API error.
28950 xmlSchemaValidateFile(xmlSchemaValidCtxtPtr ctxt
,
28951 const char * filename
,
28952 int options ATTRIBUTE_UNUSED
)
28955 xmlParserInputBufferPtr input
;
28957 if ((ctxt
== NULL
) || (filename
== NULL
))
28960 input
= xmlParserInputBufferCreateFilename(filename
,
28961 XML_CHAR_ENCODING_NONE
);
28964 ret
= xmlSchemaValidateStream(ctxt
, input
, XML_CHAR_ENCODING_NONE
,
28970 * xmlSchemaValidCtxtGetParserCtxt:
28971 * @ctxt: a schema validation context
28973 * allow access to the parser context of the schema validation context
28975 * Returns the parser context of the schema validation context or NULL
28976 * in case of error.
28979 xmlSchemaValidCtxtGetParserCtxt(xmlSchemaValidCtxtPtr ctxt
)
28983 return (ctxt
->parserCtxt
);
28986 #define bottom_xmlschemas
28987 #include "elfgcchack.h"
28988 #endif /* LIBXML_SCHEMAS_ENABLED */