blob: d792587067da06d18f6e58b30d43fbfc26cbf2c2 [file] [log] [blame]
Daniel Veillard4255d502002-04-16 15:50:10 +00001/*
Daniel Veillardbe586972003-11-18 20:56:51 +00002 * Summary: internal interfaces for XML Schemas
3 * Description: internal interfaces for the XML Schemas handling
4 * and schema validity checking
Daniel Veillard4255d502002-04-16 15:50:10 +00005 *
Daniel Veillardbe586972003-11-18 20:56:51 +00006 * Copy: See Copyright for the status of this software.
Daniel Veillard4255d502002-04-16 15:50:10 +00007 *
Daniel Veillardbe586972003-11-18 20:56:51 +00008 * Author: Daniel Veillard
Daniel Veillard4255d502002-04-16 15:50:10 +00009 */
10
11
12#ifndef __XML_SCHEMA_INTERNALS_H__
13#define __XML_SCHEMA_INTERNALS_H__
14
Daniel Veillard4255d502002-04-16 15:50:10 +000015#include <libxml/xmlversion.h>
Igor Zlatkovic7ae91bc2002-11-08 17:18:52 +000016
Daniel Veillard4255d502002-04-16 15:50:10 +000017#ifdef LIBXML_SCHEMAS_ENABLED
18
19#include <libxml/xmlregexp.h>
Daniel Veillard8326e732003-01-07 00:19:07 +000020#include <libxml/hash.h>
Daniel Veillardbe9c6322003-11-22 20:37:51 +000021#include <libxml/dict.h>
Daniel Veillard4255d502002-04-16 15:50:10 +000022
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27
28/*
29 * XML Schemas defines multiple type of types.
30 */
31typedef enum {
32 XML_SCHEMA_TYPE_BASIC = 1,
33 XML_SCHEMA_TYPE_ANY,
34 XML_SCHEMA_TYPE_FACET,
35 XML_SCHEMA_TYPE_SIMPLE,
36 XML_SCHEMA_TYPE_COMPLEX,
37 XML_SCHEMA_TYPE_SEQUENCE,
38 XML_SCHEMA_TYPE_CHOICE,
39 XML_SCHEMA_TYPE_ALL,
40 XML_SCHEMA_TYPE_SIMPLE_CONTENT,
41 XML_SCHEMA_TYPE_COMPLEX_CONTENT,
42 XML_SCHEMA_TYPE_UR,
43 XML_SCHEMA_TYPE_RESTRICTION,
44 XML_SCHEMA_TYPE_EXTENSION,
45 XML_SCHEMA_TYPE_ELEMENT,
46 XML_SCHEMA_TYPE_ATTRIBUTE,
Daniel Veillard13e04c62002-04-23 17:51:29 +000047 XML_SCHEMA_TYPE_ATTRIBUTEGROUP,
Daniel Veillard4255d502002-04-16 15:50:10 +000048 XML_SCHEMA_TYPE_GROUP,
49 XML_SCHEMA_TYPE_NOTATION,
50 XML_SCHEMA_TYPE_LIST,
51 XML_SCHEMA_TYPE_UNION,
52 XML_SCHEMA_FACET_MININCLUSIVE = 1000,
53 XML_SCHEMA_FACET_MINEXCLUSIVE,
54 XML_SCHEMA_FACET_MAXINCLUSIVE,
55 XML_SCHEMA_FACET_MAXEXCLUSIVE,
56 XML_SCHEMA_FACET_TOTALDIGITS,
57 XML_SCHEMA_FACET_FRACTIONDIGITS,
58 XML_SCHEMA_FACET_PATTERN,
59 XML_SCHEMA_FACET_ENUMERATION,
60 XML_SCHEMA_FACET_WHITESPACE,
61 XML_SCHEMA_FACET_LENGTH,
62 XML_SCHEMA_FACET_MAXLENGTH,
63 XML_SCHEMA_FACET_MINLENGTH
64} xmlSchemaTypeType;
65
66typedef enum {
67 XML_SCHEMA_CONTENT_UNKNOWN = 0,
68 XML_SCHEMA_CONTENT_EMPTY = 1,
69 XML_SCHEMA_CONTENT_ELEMENTS,
70 XML_SCHEMA_CONTENT_MIXED,
71 XML_SCHEMA_CONTENT_SIMPLE,
72 XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS,
Daniel Veillard88c58912002-04-23 07:12:20 +000073 XML_SCHEMA_CONTENT_BASIC,
74 XML_SCHEMA_CONTENT_ANY
Daniel Veillard4255d502002-04-16 15:50:10 +000075} xmlSchemaContentType;
76
77typedef struct _xmlSchemaVal xmlSchemaVal;
78typedef xmlSchemaVal *xmlSchemaValPtr;
79
80typedef struct _xmlSchemaType xmlSchemaType;
81typedef xmlSchemaType *xmlSchemaTypePtr;
82
83typedef struct _xmlSchemaFacet xmlSchemaFacet;
84typedef xmlSchemaFacet *xmlSchemaFacetPtr;
85
86/**
87 * Annotation
88 */
89typedef struct _xmlSchemaAnnot xmlSchemaAnnot;
90typedef xmlSchemaAnnot *xmlSchemaAnnotPtr;
91struct _xmlSchemaAnnot {
92 struct _xmlSchemaAnnot *next;
93 xmlNodePtr content; /* the annotation */
94};
95
96/**
Daniel Veillard1e906612003-12-05 14:57:46 +000097 * XML_SCHEMAS_ANYATTR_SKIP:
98 *
99 * Skip unknown attribute from validation
Daniel Veillard4255d502002-04-16 15:50:10 +0000100 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000101#define XML_SCHEMAS_ANYATTR_SKIP 1
Daniel Veillard1e906612003-12-05 14:57:46 +0000102/**
103 * XML_SCHEMAS_ANYATTR_LAX:
104 *
105 * Ignore validation non definition on attributes
106 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000107#define XML_SCHEMAS_ANYATTR_LAX 2
Daniel Veillard1e906612003-12-05 14:57:46 +0000108/**
109 * XML_SCHEMAS_ANYATTR_STRICT:
110 *
111 * Apply strict validation rules on attributes
112 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000113#define XML_SCHEMAS_ANYATTR_STRICT 3
114
Daniel Veillardbe9c6322003-11-22 20:37:51 +0000115/**
116 * XML_SCHEMAS_ATTR_NSDEFAULT:
117 *
118 * allow elements in no namespace
119 */
120#define XML_SCHEMAS_ATTR_NSDEFAULT 1 << 7
121
Daniel Veillard1e906612003-12-05 14:57:46 +0000122/**
123 * xmlSchemaAttribute:
124 * An attribute definition.
125 */
126
Daniel Veillard4255d502002-04-16 15:50:10 +0000127typedef struct _xmlSchemaAttribute xmlSchemaAttribute;
128typedef xmlSchemaAttribute *xmlSchemaAttributePtr;
129struct _xmlSchemaAttribute {
130 xmlSchemaTypeType type; /* The kind of type */
131 struct _xmlSchemaAttribute *next;/* the next attribute if in a group ... */
Daniel Veillardbe9c6322003-11-22 20:37:51 +0000132 const xmlChar *name;
133 const xmlChar *id;
134 const xmlChar *ref;
135 const xmlChar *refNs;
136 const xmlChar *typeName;
137 const xmlChar *typeNs;
Daniel Veillard4255d502002-04-16 15:50:10 +0000138 xmlSchemaAnnotPtr annot;
139
140 xmlSchemaTypePtr base;
141 int occurs;
Daniel Veillardbe9c6322003-11-22 20:37:51 +0000142 const xmlChar *defValue;
Daniel Veillard4255d502002-04-16 15:50:10 +0000143 xmlSchemaTypePtr subtypes;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +0000144 xmlNodePtr node;
Daniel Veillardbe9c6322003-11-22 20:37:51 +0000145 const xmlChar *targetNamespace;
146 int flags;
Daniel Veillard4255d502002-04-16 15:50:10 +0000147};
148
149/**
150 * An attribute group definition.
151 *
152 * xmlSchemaAttribute and xmlSchemaAttributeGroup start of structures
153 * must be kept similar
154 */
155typedef struct _xmlSchemaAttributeGroup xmlSchemaAttributeGroup;
156typedef xmlSchemaAttributeGroup *xmlSchemaAttributeGroupPtr;
157struct _xmlSchemaAttributeGroup {
158 xmlSchemaTypeType type; /* The kind of type */
159 struct _xmlSchemaAttribute *next;/* the next attribute if in a group ... */
Daniel Veillardbe9c6322003-11-22 20:37:51 +0000160 const xmlChar *name;
161 const xmlChar *id;
162 const xmlChar *ref;
163 const xmlChar *refNs;
Daniel Veillard4255d502002-04-16 15:50:10 +0000164 xmlSchemaAnnotPtr annot;
165
166 xmlSchemaAttributePtr attributes;
Daniel Veillard75bb3bb2003-05-12 15:25:56 +0000167 xmlNodePtr node;
Daniel Veillard4255d502002-04-16 15:50:10 +0000168};
169
170
171/**
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000172 * XML_SCHEMAS_TYPE_MIXED:
173 *
174 * the element content type is mixed
Daniel Veillard4255d502002-04-16 15:50:10 +0000175 */
176#define XML_SCHEMAS_TYPE_MIXED 1 << 0
177
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000178/**
179 * _xmlSchemaType:
180 *
181 * Schemas type definition.
182 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000183struct _xmlSchemaType {
184 xmlSchemaTypeType type; /* The kind of type */
185 struct _xmlSchemaType *next;/* the next type if in a sequence ... */
Daniel Veillardbe9c6322003-11-22 20:37:51 +0000186 const xmlChar *name;
187 const xmlChar *id;
188 const xmlChar *ref;
189 const xmlChar *refNs;
Daniel Veillard4255d502002-04-16 15:50:10 +0000190 xmlSchemaAnnotPtr annot;
191 xmlSchemaTypePtr subtypes;
192 xmlSchemaAttributePtr attributes;
193 xmlNodePtr node;
194 int minOccurs;
195 int maxOccurs;
196
197 int flags;
198 xmlSchemaContentType contentType;
Daniel Veillardbe9c6322003-11-22 20:37:51 +0000199 const xmlChar *base;
200 const xmlChar *baseNs;
Daniel Veillard4255d502002-04-16 15:50:10 +0000201 xmlSchemaTypePtr baseType;
202 xmlSchemaFacetPtr facets;
203};
204
William M. Brack60f394e2003-11-16 06:25:42 +0000205/*
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000206 * xmlSchemaElement:
Daniel Veillard4255d502002-04-16 15:50:10 +0000207 * An element definition.
208 *
209 * xmlSchemaType, xmlSchemaFacet and xmlSchemaElement start of
210 * structures must be kept similar
211 */
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000212/**
213 * XML_SCHEMAS_ELEM_NILLABLE:
214 *
215 * the element is nillable
216 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000217#define XML_SCHEMAS_ELEM_NILLABLE 1 << 0
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000218/**
219 * XML_SCHEMAS_ELEM_GLOBAL:
220 *
221 * the element is global
222 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000223#define XML_SCHEMAS_ELEM_GLOBAL 1 << 1
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000224/**
225 * XML_SCHEMAS_ELEM_DEFAULT:
226 *
227 * the element has a default value
228 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000229#define XML_SCHEMAS_ELEM_DEFAULT 1 << 2
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000230/**
231 * XML_SCHEMAS_ELEM_FIXED:
232 *
233 * the element has a fixed value
234 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000235#define XML_SCHEMAS_ELEM_FIXED 1 << 3
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000236/**
237 * XML_SCHEMAS_ELEM_ABSTRACT:
238 *
239 * the element is abstract
240 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000241#define XML_SCHEMAS_ELEM_ABSTRACT 1 << 4
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000242/**
243 * XML_SCHEMAS_ELEM_TOPLEVEL:
244 *
245 * the element is top level
246 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000247#define XML_SCHEMAS_ELEM_TOPLEVEL 1 << 5
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000248/**
249 * XML_SCHEMAS_ELEM_REF:
250 *
251 * the element is a reference to a type
252 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000253#define XML_SCHEMAS_ELEM_REF 1 << 6
Daniel Veillardbe9c6322003-11-22 20:37:51 +0000254/**
255 * XML_SCHEMAS_ELEM_NSDEFAULT:
256 *
257 * allow elements in no namespace
258 */
259#define XML_SCHEMAS_ELEM_NSDEFAULT 1 << 7
Daniel Veillard4255d502002-04-16 15:50:10 +0000260
261typedef struct _xmlSchemaElement xmlSchemaElement;
262typedef xmlSchemaElement *xmlSchemaElementPtr;
263struct _xmlSchemaElement {
264 xmlSchemaTypeType type; /* The kind of type */
265 struct _xmlSchemaType *next;/* the next type if in a sequence ... */
Daniel Veillardbe9c6322003-11-22 20:37:51 +0000266 const xmlChar *name;
267 const xmlChar *id;
268 const xmlChar *ref;
269 const xmlChar *refNs;
Daniel Veillard4255d502002-04-16 15:50:10 +0000270 xmlSchemaAnnotPtr annot;
271 xmlSchemaTypePtr subtypes;
272 xmlSchemaAttributePtr attributes;
273 xmlNodePtr node;
274 int minOccurs;
275 int maxOccurs;
276
277 int flags;
Daniel Veillardbe9c6322003-11-22 20:37:51 +0000278 const xmlChar *targetNamespace;
279 const xmlChar *namedType;
280 const xmlChar *namedTypeNs;
281 const xmlChar *substGroup;
282 const xmlChar *substGroupNs;
283 const xmlChar *scope;
284 const xmlChar *value;
Daniel Veillard4255d502002-04-16 15:50:10 +0000285 struct _xmlSchemaElement *refDecl;
286 xmlRegexpPtr contModel;
Daniel Veillard88c58912002-04-23 07:12:20 +0000287 xmlSchemaContentType contentType;
Daniel Veillard4255d502002-04-16 15:50:10 +0000288};
289
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000290/*
291 * XML_SCHEMAS_FACET_UNKNOWN:
Daniel Veillard4255d502002-04-16 15:50:10 +0000292 *
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000293 * unknown facet handling
Daniel Veillard4255d502002-04-16 15:50:10 +0000294 */
295#define XML_SCHEMAS_FACET_UNKNOWN 0
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000296/*
297 * XML_SCHEMAS_FACET_PRESERVE:
298 *
299 * preserve the type of the facet
300 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000301#define XML_SCHEMAS_FACET_PRESERVE 1
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000302/*
303 * XML_SCHEMAS_FACET_REPLACE:
304 *
305 * replace the type of the facet
306 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000307#define XML_SCHEMAS_FACET_REPLACE 2
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000308/*
309 * XML_SCHEMAS_FACET_COLLAPSE:
310 *
311 * collapse the types of the facet
312 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000313#define XML_SCHEMAS_FACET_COLLAPSE 3
314
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000315/**
316 * A facet definition.
317 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000318struct _xmlSchemaFacet {
319 xmlSchemaTypeType type; /* The kind of type */
320 struct _xmlSchemaFacet *next;/* the next type if in a sequence ... */
Daniel Veillardbe9c6322003-11-22 20:37:51 +0000321 const xmlChar *value;
322 const xmlChar *id;
Daniel Veillard4255d502002-04-16 15:50:10 +0000323 xmlSchemaAnnotPtr annot;
324 xmlNodePtr node;
325 int fixed;
326 int whitespace;
327 xmlSchemaValPtr val;
328 xmlRegexpPtr regexp;
329};
330
331/**
332 * A notation definition.
333 */
334typedef struct _xmlSchemaNotation xmlSchemaNotation;
335typedef xmlSchemaNotation *xmlSchemaNotationPtr;
336struct _xmlSchemaNotation {
337 xmlSchemaTypeType type; /* The kind of type */
Daniel Veillardbe9c6322003-11-22 20:37:51 +0000338 const xmlChar *name;
Daniel Veillard4255d502002-04-16 15:50:10 +0000339 xmlSchemaAnnotPtr annot;
Daniel Veillardbe9c6322003-11-22 20:37:51 +0000340 const xmlChar *identifier;
Daniel Veillard4255d502002-04-16 15:50:10 +0000341};
342
343/**
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000344 * XML_SCHEMAS_QUALIF_ELEM:
345 *
346 * the shemas requires qualified elements
Daniel Veillard4255d502002-04-16 15:50:10 +0000347 */
348#define XML_SCHEMAS_QUALIF_ELEM 1 << 0
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000349/**
350 * XML_SCHEMAS_QUALIF_ATTR:
351 *
352 * the shemas requires qualified attributes
353 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000354#define XML_SCHEMAS_QUALIF_ATTR 1 << 1
Daniel Veillarda9b66d02002-12-11 14:23:49 +0000355/**
356 * _xmlSchema:
357 *
358 * A Schemas definition
359 */
Daniel Veillard4255d502002-04-16 15:50:10 +0000360struct _xmlSchema {
Daniel Veillardbe9c6322003-11-22 20:37:51 +0000361 const xmlChar *name; /* schema name */
362 const xmlChar *targetNamespace; /* the target namespace */
363 const xmlChar *version;
364 const xmlChar *id;
Daniel Veillard4255d502002-04-16 15:50:10 +0000365 xmlDocPtr doc;
366 xmlSchemaAnnotPtr annot;
367 int flags;
368
369 xmlHashTablePtr typeDecl;
370 xmlHashTablePtr attrDecl;
371 xmlHashTablePtr attrgrpDecl;
372 xmlHashTablePtr elemDecl;
373 xmlHashTablePtr notaDecl;
Daniel Veillard10b6da42002-05-18 07:55:20 +0000374
375 xmlHashTablePtr schemasImports;
Daniel Veillard5f7f9912002-06-17 17:03:00 +0000376
377 void *_private; /* unused by the library for users or bindings */
Daniel Veillarda84c0b32003-06-02 16:58:46 +0000378 xmlHashTablePtr groupDecl;
Daniel Veillardbe9c6322003-11-22 20:37:51 +0000379 xmlDictPtr dict;
Daniel Veillardbd2904b2003-11-25 15:38:59 +0000380 void *includes; /* the includes, this is opaque for now */
Daniel Veillard4255d502002-04-16 15:50:10 +0000381};
382
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000383XMLPUBFUN void XMLCALL xmlSchemaFreeType (xmlSchemaTypePtr type);
Daniel Veillard4255d502002-04-16 15:50:10 +0000384
385#ifdef __cplusplus
386}
387#endif
388
389#endif /* LIBXML_SCHEMAS_ENABLED */
390#endif /* __XML_SCHEMA_INTERNALS_H__ */
391
392