1/**
2 * @file
3 *
4 * @brief incomplete XML Schemas structure implementation
5 *
6 * interface to the XML Schemas handling and schema validity
7 * checking, it is incomplete right now.
8 *
9 * @copyright See Copyright for the status of this software.
10 *
11 * @author Daniel Veillard
12 */
13
14
15#ifndef __XML_SCHEMA_H__
16#define __XML_SCHEMA_H__
17
18#include <libxml/xmlversion.h>
19
20#ifdef LIBXML_SCHEMAS_ENABLED
21
22#include <stdio.h>
23#include <libxml/encoding.h>
24#include <libxml/parser.h>
25#include <libxml/tree.h>
26#include <libxml/xmlerror.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/**
33 * This error codes are obsolete; not used any more.
34 */
35typedef enum {
36 XML_SCHEMAS_ERR_OK = 0,
37 XML_SCHEMAS_ERR_NOROOT = 1,
38 XML_SCHEMAS_ERR_UNDECLAREDELEM,
39 XML_SCHEMAS_ERR_NOTTOPLEVEL,
40 XML_SCHEMAS_ERR_MISSING,
41 XML_SCHEMAS_ERR_WRONGELEM,
42 XML_SCHEMAS_ERR_NOTYPE,
43 XML_SCHEMAS_ERR_NOROLLBACK,
44 XML_SCHEMAS_ERR_ISABSTRACT,
45 XML_SCHEMAS_ERR_NOTEMPTY,
46 XML_SCHEMAS_ERR_ELEMCONT,
47 XML_SCHEMAS_ERR_HAVEDEFAULT,
48 XML_SCHEMAS_ERR_NOTNILLABLE,
49 XML_SCHEMAS_ERR_EXTRACONTENT,
50 XML_SCHEMAS_ERR_INVALIDATTR,
51 XML_SCHEMAS_ERR_INVALIDELEM,
52 XML_SCHEMAS_ERR_NOTDETERMINIST,
53 XML_SCHEMAS_ERR_CONSTRUCT,
54 XML_SCHEMAS_ERR_INTERNAL,
55 XML_SCHEMAS_ERR_NOTSIMPLE,
56 XML_SCHEMAS_ERR_ATTRUNKNOWN,
57 XML_SCHEMAS_ERR_ATTRINVALID,
58 XML_SCHEMAS_ERR_VALUE,
59 XML_SCHEMAS_ERR_FACET,
60 XML_SCHEMAS_ERR_,
61 XML_SCHEMAS_ERR_XXX
62} xmlSchemaValidError;
63
64/*
65* ATTENTION: Change xmlSchemaSetValidOptions's check
66* for invalid values, if adding to the validation
67* options below.
68*/
69/**
70 * This is the set of XML Schema validation options.
71 */
72typedef enum {
73 XML_SCHEMA_VAL_VC_I_CREATE = 1<<0
74 /* Default/fixed: create an attribute node
75 * or an element's text node on the instance.
76 */
77} xmlSchemaValidOption;
78
79/*
80 XML_SCHEMA_VAL_XSI_ASSEMBLE = 1<<1,
81 * assemble schemata using
82 * xsi:schemaLocation and
83 * xsi:noNamespaceSchemaLocation
84*/
85
86/** XML schema */
87typedef struct _xmlSchema xmlSchema;
88typedef xmlSchema *xmlSchemaPtr;
89
90/**
91 * Signature of an error callback from an XSD validation
92 *
93 * @param ctx the validation context
94 * @param msg the message
95 * @param ... extra arguments
96 */
97typedef void (*xmlSchemaValidityErrorFunc)
98 (void *ctx, const char *msg, ...) LIBXML_ATTR_FORMAT(2,3);
99
100/**
101 * Signature of a warning callback from an XSD validation
102 *
103 * @param ctx the validation context
104 * @param msg the message
105 * @param ... extra arguments
106 */
107typedef void (*xmlSchemaValidityWarningFunc)
108 (void *ctx, const char *msg, ...) LIBXML_ATTR_FORMAT(2,3);
109
110/** Schema parser context */
111typedef struct _xmlSchemaParserCtxt xmlSchemaParserCtxt;
112typedef xmlSchemaParserCtxt *xmlSchemaParserCtxtPtr;
113
114/** Schema validation context */
115typedef struct _xmlSchemaValidCtxt xmlSchemaValidCtxt;
116typedef xmlSchemaValidCtxt *xmlSchemaValidCtxtPtr;
117
118/**
119 * A schemas validation locator, a callback called by the validator.
120 * This is used when file or node information are not available
121 * to find out what file and line number are affected
122 *
123 * @param ctx user provided context
124 * @param file returned file information
125 * @param line returned line information
126 * @returns 0 in case of success and -1 in case of error
127 */
128
129typedef int (*xmlSchemaValidityLocatorFunc) (void *ctx,
130 const char **file, unsigned long *line);
131
132/*
133 * Interfaces for parsing.
134 */
135XMLPUBFUN xmlSchemaParserCtxt *
136 xmlSchemaNewParserCtxt (const char *URL);
137XMLPUBFUN xmlSchemaParserCtxt *
138 xmlSchemaNewMemParserCtxt (const char *buffer,
139 int size);
140XMLPUBFUN xmlSchemaParserCtxt *
141 xmlSchemaNewDocParserCtxt (xmlDoc *doc);
142XMLPUBFUN void
143 xmlSchemaFreeParserCtxt (xmlSchemaParserCtxt *ctxt);
144XMLPUBFUN void
145 xmlSchemaSetParserErrors (xmlSchemaParserCtxt *ctxt,
146 xmlSchemaValidityErrorFunc err,
147 xmlSchemaValidityWarningFunc warn,
148 void *ctx);
149XMLPUBFUN void
150 xmlSchemaSetParserStructuredErrors(xmlSchemaParserCtxt *ctxt,
151 xmlStructuredErrorFunc serror,
152 void *ctx);
153XMLPUBFUN int
154 xmlSchemaGetParserErrors (xmlSchemaParserCtxt *ctxt,
155 xmlSchemaValidityErrorFunc * err,
156 xmlSchemaValidityWarningFunc * warn,
157 void **ctx);
158XMLPUBFUN void
159 xmlSchemaSetResourceLoader (xmlSchemaParserCtxt *ctxt,
160 xmlResourceLoader loader,
161 void *data);
162XMLPUBFUN int
163 xmlSchemaIsValid (xmlSchemaValidCtxt *ctxt);
164
165XMLPUBFUN xmlSchema *
166 xmlSchemaParse (xmlSchemaParserCtxt *ctxt);
167XMLPUBFUN void
168 xmlSchemaFree (xmlSchema *schema);
169#ifdef LIBXML_DEBUG_ENABLED
170XMLPUBFUN void
171 xmlSchemaDump (FILE *output,
172 xmlSchema *schema);
173#endif /* LIBXML_DEBUG_ENABLED */
174/*
175 * Interfaces for validating
176 */
177XMLPUBFUN void
178 xmlSchemaSetValidErrors (xmlSchemaValidCtxt *ctxt,
179 xmlSchemaValidityErrorFunc err,
180 xmlSchemaValidityWarningFunc warn,
181 void *ctx);
182XMLPUBFUN void
183 xmlSchemaSetValidStructuredErrors(xmlSchemaValidCtxt *ctxt,
184 xmlStructuredErrorFunc serror,
185 void *ctx);
186XMLPUBFUN int
187 xmlSchemaGetValidErrors (xmlSchemaValidCtxt *ctxt,
188 xmlSchemaValidityErrorFunc *err,
189 xmlSchemaValidityWarningFunc *warn,
190 void **ctx);
191XMLPUBFUN int
192 xmlSchemaSetValidOptions (xmlSchemaValidCtxt *ctxt,
193 int options);
194XMLPUBFUN void
195 xmlSchemaValidateSetFilename(xmlSchemaValidCtxt *vctxt,
196 const char *filename);
197XMLPUBFUN int
198 xmlSchemaValidCtxtGetOptions(xmlSchemaValidCtxt *ctxt);
199
200XMLPUBFUN xmlSchemaValidCtxt *
201 xmlSchemaNewValidCtxt (xmlSchema *schema);
202XMLPUBFUN void
203 xmlSchemaFreeValidCtxt (xmlSchemaValidCtxt *ctxt);
204XMLPUBFUN int
205 xmlSchemaValidateDoc (xmlSchemaValidCtxt *ctxt,
206 xmlDoc *instance);
207XMLPUBFUN int
208 xmlSchemaValidateOneElement (xmlSchemaValidCtxt *ctxt,
209 xmlNode *elem);
210XMLPUBFUN int
211 xmlSchemaValidateStream (xmlSchemaValidCtxt *ctxt,
212 xmlParserInputBuffer *input,
213 xmlCharEncoding enc,
214 const xmlSAXHandler *sax,
215 void *user_data);
216XMLPUBFUN int
217 xmlSchemaValidateFile (xmlSchemaValidCtxt *ctxt,
218 const char * filename,
219 int options);
220
221XMLPUBFUN xmlParserCtxt *
222 xmlSchemaValidCtxtGetParserCtxt(xmlSchemaValidCtxt *ctxt);
223
224/**
225 * Interface to insert Schemas SAX validation in a SAX stream
226 */
227typedef struct _xmlSchemaSAXPlug xmlSchemaSAXPlugStruct;
228typedef xmlSchemaSAXPlugStruct *xmlSchemaSAXPlugPtr;
229
230XMLPUBFUN xmlSchemaSAXPlugStruct *
231 xmlSchemaSAXPlug (xmlSchemaValidCtxt *ctxt,
232 xmlSAXHandler **sax,
233 void **user_data);
234XMLPUBFUN int
235 xmlSchemaSAXUnplug (xmlSchemaSAXPlugStruct *plug);
236
237
238XMLPUBFUN void
239 xmlSchemaValidateSetLocator (xmlSchemaValidCtxt *vctxt,
240 xmlSchemaValidityLocatorFunc f,
241 void *ctxt);
242
243#ifdef __cplusplus
244}
245#endif
246
247#endif /* LIBXML_SCHEMAS_ENABLED */
248#endif /* __XML_SCHEMA_H__ */
249