19#ifndef DESCENT_XML_VALIDATE
20#define DESCENT_XML_VALIDATE
28#include <libadt/lptr.h>
29#include <libadt/str.h>
39 struct libadt_const_lptr element_name,
40 struct libadt_const_lptr attributes,
49 } *context = context_p;
50 if (context->depth == 0) {
51 context->valid =
false;
56 const struct libadt_const_lptr xmldecl = libadt_str_literal(
"?xml");
58 if (libadt_const_lptr_equal(element_name, xmldecl)) {
59 context->valid =
false;
66 while (token.type != descent_xml_classifier_element_close_name) {
70 || token.type == descent_xml_lex_xmldecl
71 || token.type == descent_xml_lex_doctype
74 context->valid =
false;
79 _descent_xml_validate_element_handler,
85 context->valid = libadt_const_lptr_equal(
94inline bool descent_xml_validate_element_depth(
102 } context = {
true, depth };
103 while (token.
type != descent_xml_classifier_element) {
113 _descent_xml_validate_element_handler,
128 return descent_xml_validate_element_depth(token, 10000);
133 return token.
type == descent_xml_classifier_text
134 || token.
type == descent_xml_classifier_text_entity_start
135 || token.
type == descent_xml_classifier_text_entity
136 || token.
type == descent_xml_lex_cdata;
139inline struct descent_xml_lex _descent_xml_validate_prolog_goto_element(
143 while (token.
type != descent_xml_classifier_element) {
147 || _descent_xml_non_space_text(token)
159 if (token.
type != descent_xml_classifier_element) {
165 if (next.
type == descent_xml_lex_comment) {
166 token = descent_xml_lex_then(
168 _descent_xml_validate_prolog_goto_element
170 token = descent_xml_lex_optional(
172 _descent_xml_validate_prolog_comments
184 if (next.
type == descent_xml_lex_xmldecl) {
185 token = descent_xml_lex_then(
187 _descent_xml_validate_prolog_goto_element
200 if (next.
type == descent_xml_lex_doctype) {
201 token = descent_xml_lex_then(
203 _descent_xml_validate_prolog_goto_element
214 token = descent_xml_lex_then(
216 _descent_xml_validate_prolog_goto_element
218 token = descent_xml_lex_optional(
220 _descent_xml_validate_xmldecl
222 token = descent_xml_lex_optional(
224 _descent_xml_validate_prolog_comments
226 token = descent_xml_lex_optional(
228 _descent_xml_validate_doctype
230 token = descent_xml_lex_optional(
232 _descent_xml_validate_prolog_comments
237inline bool descent_xml_validate_document_depth(
245 } context = {
true, depth};
247 token = _descent_xml_validate_parse_prolog(token);
256 _descent_xml_validate_element_handler,
265 while (token.
type != descent_xml_classifier_element) {
270 if (token.
type == descent_xml_classifier_text)
278inline bool descent_xml_validate_document(
282 return descent_xml_validate_document_depth(token, 1000);
descent_xml_classifier_fn *const descent_xml_classifier_unexpected
descent_xml_classifier_fn *const descent_xml_classifier_eof
struct descent_xml_lex descent_xml_lex_next_raw(struct descent_xml_lex token)
Returns the next, raw token in the script referred to by previous.
Definition lex.h:608
struct descent_xml_lex descent_xml_parse(struct descent_xml_lex xml, descent_xml_parse_element_fn *element_handler, descent_xml_parse_text_fn *text_handler, void *context)
Function for parsing an XML document.
Definition parse.h:319
Represents a single token.
Definition lex.h:42
descent_xml_classifier_fn * type
Represents the type of token classifiered.
Definition lex.h:46