|
zxsd 0.20.0
Embedded XML Schema validation for C
|
Validate XML documents with generated XSD descriptors. More...
Data Structures | |
| struct | zxsd_result_t |
| Structured result returned by every generated validator. More... | |
| struct | zxsd_allocator_t |
| Optional allocator used by validation features requiring scratch storage. More... | |
| struct | zxsd_simple_ref_t |
| Reference to a built-in or generated simple type. More... | |
| struct | zxsd_simple |
| Generated descriptor for a restricted, list or union simple type. More... | |
| struct | zxsd_element_t |
| Generated descriptor for an element particle. More... | |
| struct | zxsd_attribute_t |
| Generated descriptor for an XML attribute. More... | |
| struct | zxsd_wildcard_t |
| XML Schema element or attribute wildcard. More... | |
| struct | zxsd_particle |
| Recursive descriptor for a compiled content-model particle. More... | |
| struct | zxsd_complex |
| Generated descriptor for a complex XML Schema type. More... | |
| struct | zxsd_xpath_step_t |
| One expanded-name step in the restricted identity XPath subset. More... | |
| struct | zxsd_xpath |
| Compiled restricted XPath used by identity constraints. More... | |
| struct | zxsd_identity_t |
| Compiled xs:unique, xs:key or xs:keyref descriptor. More... | |
| struct | zxsd_global_element_t |
| Global element declaration available to strict/lax wildcards. More... | |
| struct | zxsd_global_attribute_t |
| Global attribute declaration available to strict/lax wildcards. More... | |
| struct | zxsd_named_type_t |
| Named type entry used to resolve runtime xsi:type values. More... | |
| struct | zxsd_notation_t |
| Global XML Schema notation declaration. More... | |
| struct | zxsd_schema_t |
| Root descriptor consumed by the generic validation runtime. More... | |
| struct | zxsd_stream_model_node_t |
| Internal immutable continuation or frontier entry, for static allocation only. More... | |
| struct | zxsd_stream_frame_t |
| Internal per-element state exposed only to permit static allocation. More... | |
| struct | zxsd_stream_namespace_t |
| Internal namespace binding retained by the event-driven validator. More... | |
| struct | zxsd_stream_t |
| Bounded state for the event-driven validator. More... | |
| struct | zxsd_xml_reader_t |
| Bounded raw-XML reader feeding an event-driven validator. More... | |
| struct | zxsd_runtime_config_t |
| Caller configuration stamp for a same-toolchain runtime boundary. More... | |
Macros | |
| #define | ZXSD_MAX_INPUT (1024u * 1024u) |
| Maximum accepted XML input size, in bytes. | |
| #define | ZXSD_MAX_DEPTH 32u |
| Maximum nesting depth accepted by the embedded XML parser. | |
| #define | ZXSD_MAX_PARTICLES 32u |
| Maximum number of child particles in one complex type. | |
| #define | ZXSD_MAX_ATTRIBUTES 32u |
| Maximum number of attributes in one element. | |
| #define | ZXSD_MAX_NAMESPACES 16u |
| Maximum number of simultaneously active namespace bindings. | |
| #define | ZXSD_MAX_IDENTITY_ROWS 64u |
| Maximum stored tuples per identity constraint. | |
| #define | ZXSD_MAX_IDENTITY_VALUES ZXSD_MAX_IDENTITY_ROWS |
| Maximum identity values, retained as a compatibility alias for rows. | |
| #define | ZXSD_MAX_IDENTITY_TEXT 4096u |
| Maximum total UTF-8 bytes retained for document ID and IDREF values. | |
| #define | ZXSD_MAX_IDENTITY_CONSTRAINTS 16u |
| Maximum identity constraints attached to one root declaration. | |
| #define | ZXSD_MAX_IDENTITY_FIELDS 8u |
| Maximum fields in one identity-constraint tuple. | |
| #define | ZXSD_MAX_XPATH_DEPTH 8u |
| Maximum number of steps in a compiled identity XPath. | |
| #define | ZXSD_MAX_XPATH_ALTERNATIVES 8u |
| Maximum union branches in one compiled identity XPath. | |
| #define | ZXSD_STREAM_TEXT_CAPACITY ZXSD_MAX_TEXT_LENGTH |
| Maximum decoded character data retained for one streamed element. | |
| #define | ZXSD_MAX_TEXT_LENGTH 1024u |
| Maximum lexical length of one element or attribute value. | |
| #define | ZXSD_MAX_PATTERN_LENGTH 4096u |
| Maximum UTF-8 byte length of one generated XSD regular expression. | |
| #define | ZXSD_MAX_REGEX_NODES 512u |
| Maximum parsed expression nodes used by the allocation-free regex engine. | |
| #define | ZXSD_MAX_REGEX_DEPTH 32u |
| Maximum parenthesis and character-class subtraction nesting depth. | |
| #define | ZXSD_MAX_SCHEMA_COMPLEXITY 4096u |
| Maximum aggregate descriptor count accepted by the runtime. | |
| #define | ZXSD_STREAM_NAME_CAPACITY 128u |
| Maximum local-name or namespace-URI length accepted by streaming calls. | |
| #define | ZXSD_STREAM_CHILD_CAPACITY 64u |
| Maximum child tokens retained for a streamed model requiring history. | |
| #define | ZXSD_STREAM_MODEL_CAPACITY 128u |
| Shared continuation/state slots for nested streaming content models. | |
| #define | ZXSD_XML_TOKEN_CAPACITY 4096u |
| Maximum bytes retained for one incomplete XML tag, comment, PI, or CDATA section. | |
| #define | ZXSD_RUNTIME_CONFIG_INIT |
| Initialize a runtime stamp using the including translation unit's configuration. | |
Typedefs | |
| typedef void *(* | zxsd_allocate_fn) (void *context, size_t size) |
| Allocate runtime scratch storage. | |
| typedef void(* | zxsd_deallocate_fn) (void *context, void *pointer) |
| Release runtime scratch storage. | |
| typedef struct zxsd_simple | zxsd_simple_t |
| Generated descriptor for a restricted, list or union simple type. | |
| typedef struct zxsd_particle | zxsd_particle_t |
| Recursive descriptor for a compiled content-model particle. | |
| typedef struct zxsd_complex | zxsd_complex_t |
| Generated descriptor for a complex XML Schema type. | |
| typedef struct zxsd_xpath | zxsd_xpath_t |
| Compiled restricted XPath used by identity constraints. | |
| typedef void(* | zxsd_xml_event_fn) (void *user_data, zxsd_xml_event_t event, const char *namespace_uri, const char *local_name, const char *value, size_t value_length) |
| Observe one decoded event accepted by the incremental validator. | |
Functions | |
| zxsd_result_t | zxsd_check_runtime (const zxsd_runtime_config_t *expected) |
| Check application limits and layouts before using runtime-owned code. | |
| zxsd_result_t | zxsd_validate (const zxsd_schema_t *schema, const char *xml) |
| Validate an XML document against a generated schema descriptor. | |
| zxsd_result_t | zxsd_validate_with_allocator (const zxsd_schema_t *schema, const char *xml, const zxsd_allocator_t *allocator) |
| Validate using an application-provided scratch allocator. | |
| zxsd_result_t | zxsd_stream_init (zxsd_stream_t *stream, const zxsd_schema_t *schema) |
| Initialize an event-driven validation context. | |
| zxsd_result_t | zxsd_stream_init_with_allocator (zxsd_stream_t *stream, const zxsd_schema_t *schema, const zxsd_allocator_t *allocator) |
| Initialize streaming validation with identity-constraint scratch allocation. | |
| void | zxsd_stream_dispose (zxsd_stream_t *stream) |
| Release optional streaming scratch storage. | |
| zxsd_result_t | zxsd_start_element (zxsd_stream_t *stream, const char *namespace_uri, const char *local_name) |
| Begin an element identified by its expanded name. | |
| zxsd_result_t | zxsd_namespace (zxsd_stream_t *stream, const char *prefix, const char *namespace_uri) |
| Add an in-scope namespace declaration to the current start tag. | |
| zxsd_result_t | zxsd_attribute (zxsd_stream_t *stream, const char *namespace_uri, const char *local_name, const char *value) |
| Add an attribute to the current start tag using its expanded name. | |
| zxsd_result_t | zxsd_xsi_type (zxsd_stream_t *stream, const char *type_namespace_uri, const char *type_local_name) |
Apply a namespace-resolved xsi:type to the current element. | |
| zxsd_result_t | zxsd_start_content (zxsd_stream_t *stream) |
| Close the attribute phase of the current start tag. | |
| zxsd_result_t | zxsd_text (zxsd_stream_t *stream, const char *text, size_t length) |
| Supply decoded character data for the current element. | |
| zxsd_result_t | zxsd_end_element (zxsd_stream_t *stream, const char *namespace_uri, const char *local_name) |
| End the current element and check its expanded name and content. | |
| zxsd_result_t | zxsd_stream_finish (zxsd_stream_t *stream) |
| Verify that exactly one complete root element was supplied. | |
| zxsd_result_t | zxsd_xml_reader_init (zxsd_xml_reader_t *reader, const zxsd_schema_t *schema) |
| Initialize a raw, incrementally fed XML validator. | |
| zxsd_result_t | zxsd_xml_reader_init_with_allocator (zxsd_xml_reader_t *reader, const zxsd_schema_t *schema, const zxsd_allocator_t *allocator) |
| Initialize a raw XML reader with identity-constraint scratch allocation. | |
| void | zxsd_xml_reader_set_event_callback (zxsd_xml_reader_t *reader, zxsd_xml_event_fn callback, void *user_data) |
| Install an optional decoded-event observer. | |
| zxsd_result_t | zxsd_xml_reader_feed (zxsd_xml_reader_t *reader, const void *data, size_t length) |
| Feed one arbitrary fragment of an XML document. | |
| zxsd_result_t | zxsd_xml_reader_finish (zxsd_xml_reader_t *reader) |
| Finish an incrementally supplied XML document. | |
| void | zxsd_xml_reader_dispose (zxsd_xml_reader_t *reader) |
| Release optional scratch storage owned by a raw XML reader. | |
| const char * | zxsd_error_string (zxsd_error_t error) |
| Get a stable human-readable description of an error code. | |
Validate XML documents with generated XSD descriptors.
| #define ZXSD_MAX_ATTRIBUTES 32u |
| #define ZXSD_MAX_DEPTH 32u |
| #define ZXSD_MAX_IDENTITY_CONSTRAINTS 16u |
| #define ZXSD_MAX_IDENTITY_FIELDS 8u |
| #define ZXSD_MAX_IDENTITY_ROWS 64u |
| #define ZXSD_MAX_IDENTITY_TEXT 4096u |
| #define ZXSD_MAX_IDENTITY_VALUES ZXSD_MAX_IDENTITY_ROWS |
| #define ZXSD_MAX_INPUT (1024u * 1024u) |
| #define ZXSD_MAX_NAMESPACES 16u |
| #define ZXSD_MAX_PARTICLES 32u |
| #define ZXSD_MAX_PATTERN_LENGTH 4096u |
| #define ZXSD_MAX_REGEX_DEPTH 32u |
| #define ZXSD_MAX_REGEX_NODES 512u |
| #define ZXSD_MAX_SCHEMA_COMPLEXITY 4096u |
| #define ZXSD_MAX_TEXT_LENGTH 1024u |
| #define ZXSD_MAX_XPATH_ALTERNATIVES 8u |
| #define ZXSD_MAX_XPATH_DEPTH 8u |
| #define ZXSD_RUNTIME_CONFIG_INIT |
| #define ZXSD_STREAM_CHILD_CAPACITY 64u |
| #define ZXSD_STREAM_MODEL_CAPACITY 128u |
Shared continuation/state slots for nested streaming content models.
Storage is shared by all open elements, not multiplied by XML depth. Exhaustion returns ZXSD_ERR_STREAM_LIMIT. Zero selects child history instead; flat models always retain their allocation-free fast path.
| #define ZXSD_STREAM_NAME_CAPACITY 128u |
| #define ZXSD_STREAM_TEXT_CAPACITY ZXSD_MAX_TEXT_LENGTH |
| #define ZXSD_XML_TOKEN_CAPACITY 4096u |
| typedef void *(* zxsd_allocate_fn) (void *context, size_t size) |
| typedef void(* zxsd_deallocate_fn) (void *context, void *pointer) |
Release runtime scratch storage.
| [in] | context | Opaque allocator context. |
| [in] | pointer | Storage previously returned by zxsd_allocate_fn. |
| typedef void(* zxsd_xml_event_fn) (void *user_data, zxsd_xml_event_t event, const char *namespace_uri, const char *local_name, const char *value, size_t value_length) |
Observe one decoded event accepted by the incremental validator.
All strings are transient and valid only for the duration of the callback. value is set only for attribute and text events. Text can contain embedded NUL bytes and must be consumed using value_length.
| [in] | user_data | Opaque value supplied by the application. |
| [in] | event | Event category. |
| [in] | namespace_uri | Namespace URI, or an empty string. |
| [in] | local_name | Local element or attribute name, or NULL for text. |
| [in] | value | Attribute value or character data, otherwise NULL. |
| [in] | value_length | Number of bytes in value. |
| anonymous enum |
Simple-type facet flags used by zxsd_simple_t.
| anonymous enum |
Type-derivation methods used by block and final.
| enum zxsd_error_t |
Validation status and error codes.
| Enumerator | |
|---|---|
| ZXSD_OK | Validation succeeded. |
| ZXSD_ERR_ARGUMENT | A required argument is invalid. |
| ZXSD_ERR_INPUT_TOO_LARGE | XML exceeds ZXSD_MAX_INPUT. |
| ZXSD_ERR_MALFORMED_XML | XML syntax is malformed. |
| ZXSD_ERR_EXCESSIVE_NESTING | XML nesting exceeds the limit. |
| ZXSD_ERR_WRONG_ROOT | The document root does not match. |
| ZXSD_ERR_MISSING_ELEMENT | A required child element is absent. |
| ZXSD_ERR_UNEXPECTED_ELEMENT | A child element is not permitted. |
| ZXSD_ERR_ELEMENT_ORDER | Sequence order is incorrect. |
| ZXSD_ERR_OCCURRENCE | An occurrence bound was violated. |
| ZXSD_ERR_MISSING_ATTRIBUTE | A required attribute is absent. |
| ZXSD_ERR_UNEXPECTED_ATTRIBUTE | An attribute is not permitted. |
| ZXSD_ERR_INVALID_VALUE | A primitive or restricted value is invalid. |
| ZXSD_ERR_TEXT_NOT_ALLOWED | Text occurred in element-only content. |
| ZXSD_ERR_IDENTITY_CONSTRAINT | A unique, key or keyref rule failed. |
| ZXSD_ERR_STREAM_LIMIT | A fixed streaming buffer was exceeded. |
| ZXSD_ERR_RESOURCE_LIMIT | A configured resource limit was exceeded. |
| ZXSD_ERR_OUTPUT | A binding output sink or buffer failed. |
| ZXSD_ERR_UNSUPPORTED | A valid document cannot be represented by a binding. |
| ZXSD_ERR_INCOMPATIBLE_ABI | Runtime epochs, limits, or public layouts differ. |
| enum zxsd_identity_kind_t |
| enum zxsd_model_t |
| enum zxsd_particle_kind_t |
| enum zxsd_process_t |
| enum zxsd_type_t |
Primitive and compound value kinds understood by the runtime.
| enum zxsd_whitespace_t |
| enum zxsd_xml_event_t |
| zxsd_result_t zxsd_attribute | ( | zxsd_stream_t * | stream, |
| const char * | namespace_uri, | ||
| const char * | local_name, | ||
| const char * | value | ||
| ) |
Add an attribute to the current start tag using its expanded name.
| [in,out] | stream | Initialized validation context. |
| [in] | namespace_uri | Namespace URI, or NULL for no namespace. |
| [in] | local_name | Attribute local name. |
| [in] | value | Decoded attribute value. |
| zxsd_result_t zxsd_check_runtime | ( | const zxsd_runtime_config_t * | expected | ) |
Check application limits and layouts before using runtime-owned code.
Call once before validation or initializing caller-owned contexts when linking a separately built runtime. No context or descriptor is accessed. Matching stamps are necessary, not sufficient, for binary compatibility: architecture, calling convention, packing, and compiler ABI options must also match.
| [in] | expected | Application stamp initialized with ZXSD_RUNTIME_CONFIG_INIT. |
| ZXSD_OK | Epochs, resource limits, and recorded layout sizes match. |
| ZXSD_ERR_ARGUMENT | The stamp is NULL. |
| ZXSD_ERR_INCOMPATIBLE_ABI | The runtime configuration differs. |
| zxsd_result_t zxsd_end_element | ( | zxsd_stream_t * | stream, |
| const char * | namespace_uri, | ||
| const char * | local_name | ||
| ) |
End the current element and check its expanded name and content.
| [in,out] | stream | Initialized validation context. |
| [in] | namespace_uri | Namespace URI, or NULL for no namespace. |
| [in] | local_name | Element local name. |
| const char * zxsd_error_string | ( | zxsd_error_t | error | ) |
Get a stable human-readable description of an error code.
| [in] | error | Error code to describe. |
| zxsd_result_t zxsd_namespace | ( | zxsd_stream_t * | stream, |
| const char * | prefix, | ||
| const char * | namespace_uri | ||
| ) |
Add an in-scope namespace declaration to the current start tag.
Call this for bindings used by QName- or NOTATION-valued attributes/text.
| [in,out] | stream | Initialized validation context. |
| [in] | prefix | Namespace prefix, or an empty string for the default namespace. |
| [in] | namespace_uri | Namespace URI bound to prefix. |
| zxsd_result_t zxsd_start_content | ( | zxsd_stream_t * | stream | ) |
Close the attribute phase of the current start tag.
| [in,out] | stream | Initialized validation context. |
| zxsd_result_t zxsd_start_element | ( | zxsd_stream_t * | stream, |
| const char * | namespace_uri, | ||
| const char * | local_name | ||
| ) |
Begin an element identified by its expanded name.
| [in,out] | stream | Initialized validation context. |
| [in] | namespace_uri | Namespace URI, or NULL for no namespace. |
| [in] | local_name | Element local name. |
| void zxsd_stream_dispose | ( | zxsd_stream_t * | stream | ) |
Release optional streaming scratch storage.
Call this after an application aborts an event sequence. Calling it on an initialized context that owns no scratch storage is safe.
| [in,out] | stream | Validation context to dispose. |
| zxsd_result_t zxsd_stream_finish | ( | zxsd_stream_t * | stream | ) |
Verify that exactly one complete root element was supplied.
| [in,out] | stream | Initialized validation context. |
| zxsd_result_t zxsd_stream_init | ( | zxsd_stream_t * | stream, |
| const zxsd_schema_t * | schema | ||
| ) |
Initialize an event-driven validation context.
| [out] | stream | Validation context to initialize. |
| [in] | schema | Generated schema descriptor. |
| ZXSD_OK | The context was initialized. |
| ZXSD_ERR_ARGUMENT | An argument is invalid. |
| ZXSD_ERR_RESOURCE_LIMIT | The schema requires explicit scratch storage. |
| zxsd_result_t zxsd_stream_init_with_allocator | ( | zxsd_stream_t * | stream, |
| const zxsd_schema_t * | schema, | ||
| const zxsd_allocator_t * | allocator | ||
| ) |
Initialize streaming validation with identity-constraint scratch allocation.
The allocator is used only when the schema contains identity constraints. Passing NULL is valid for schemas without them and otherwise returns ZXSD_ERR_RESOURCE_LIMIT.
| [out] | stream | Validation context to initialize. |
| [in] | schema | Generated schema descriptor. |
| [in] | allocator | Scratch allocator, or NULL. |
| ZXSD_OK | The context was initialized. |
| ZXSD_ERR_ARGUMENT | An argument is invalid. |
| ZXSD_ERR_RESOURCE_LIMIT | Scratch storage could not be allocated. |
| zxsd_result_t zxsd_text | ( | zxsd_stream_t * | stream, |
| const char * | text, | ||
| size_t | length | ||
| ) |
Supply decoded character data for the current element.
| [in,out] | stream | Initialized validation context. |
| [in] | text | Decoded character data; it need not be NUL-terminated. |
| [in] | length | Number of bytes in text. |
| zxsd_result_t zxsd_validate | ( | const zxsd_schema_t * | schema, |
| const char * | xml | ||
| ) |
Validate an XML document against a generated schema descriptor.
| [in] | schema | Generated schema descriptor. |
| [in] | xml | NUL-terminated XML document. |
| ZXSD_OK | The document is valid. |
| ZXSD_ERR_ARGUMENT | An argument is invalid. |
| zxsd_result_t zxsd_validate_with_allocator | ( | const zxsd_schema_t * | schema, |
| const char * | xml, | ||
| const zxsd_allocator_t * | allocator | ||
| ) |
Validate using an application-provided scratch allocator.
Pass NULL as allocator to select zero-heap operation. Schemas with identity constraints then return ZXSD_ERR_RESOURCE_LIMIT.
| [in] | schema | Generated schema descriptor. |
| [in] | xml | NUL-terminated XML document. |
| [in] | allocator | Scratch allocator, or NULL. |
| ZXSD_OK | The document is valid. |
| ZXSD_ERR_ARGUMENT | An argument is invalid. |
| ZXSD_ERR_RESOURCE_LIMIT | Scratch storage is required but unavailable. |
| void zxsd_xml_reader_dispose | ( | zxsd_xml_reader_t * | reader | ) |
Release optional scratch storage owned by a raw XML reader.
| [in,out] | reader | Initialized reader to dispose. |
| zxsd_result_t zxsd_xml_reader_feed | ( | zxsd_xml_reader_t * | reader, |
| const void * | data, | ||
| size_t | length | ||
| ) |
Feed one arbitrary fragment of an XML document.
Fragments need not be NUL-terminated and may end inside UTF-8 sequences, entity references, tags, attributes, comments, processing instructions, or CDATA sections. Input storage may be reused as soon as this function returns.
| [in,out] | reader | Initialized reader. |
| [in] | data | Input bytes; may be NULL only when length is zero. |
| [in] | length | Number of bytes in data. |
| zxsd_result_t zxsd_xml_reader_finish | ( | zxsd_xml_reader_t * | reader | ) |
Finish an incrementally supplied XML document.
| [in,out] | reader | Initialized reader. |
| ZXSD_OK | The complete document is well formed and schema-valid. |
| ZXSD_ERR_MALFORMED_XML | The document ends in an incomplete token. |
| zxsd_result_t zxsd_xml_reader_init | ( | zxsd_xml_reader_t * | reader, |
| const zxsd_schema_t * | schema | ||
| ) |
Initialize a raw, incrementally fed XML validator.
| [out] | reader | Reader context to initialize. |
| [in] | schema | Generated schema descriptor. |
| zxsd_result_t zxsd_xml_reader_init_with_allocator | ( | zxsd_xml_reader_t * | reader, |
| const zxsd_schema_t * | schema, | ||
| const zxsd_allocator_t * | allocator | ||
| ) |
Initialize a raw XML reader with identity-constraint scratch allocation.
| [out] | reader | Reader context to initialize. |
| [in] | schema | Generated schema descriptor. |
| [in] | allocator | Scratch allocator, or NULL. |
| void zxsd_xml_reader_set_event_callback | ( | zxsd_xml_reader_t * | reader, |
| zxsd_xml_event_fn | callback, | ||
| void * | user_data | ||
| ) |
Install an optional decoded-event observer.
The observer runs synchronously after the validator accepts each event. It may copy selected values but must not retain the supplied string pointers.
| [in,out] | reader | Initialized reader. |
| [in] | callback | Observer callback, or NULL to disable observation. |
| [in] | user_data | Opaque value passed to callback. |
| zxsd_result_t zxsd_xsi_type | ( | zxsd_stream_t * | stream, |
| const char * | type_namespace_uri, | ||
| const char * | type_local_name | ||
| ) |
Apply a namespace-resolved xsi:type to the current element.
| [in,out] | stream | Initialized validation context. |
| [in] | type_namespace_uri | Type namespace URI, or NULL for no namespace. |
| [in] | type_local_name | Type local name. |