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