View Source xmerl_xsd (xmerl v1.4)
Interface module for XML Schema validation. It handles the W3.org specifications of XML Schema second edition 28 october 2004. For an introduction to XML Schema study part 0. An XML structure is validated by xmerl_xsd:validate/[2,3].
Summary
Functions
Reads the schema state with all information of the processed schema from a file
created with state2file/[1,2]
. The format of this file is internal. The state
can then be used validating an XML document.
Formats error descriptions to human readable strings.
Equivalent to process_schema(Schema, []).
Reads the referenced XML schema and checks that it is valid. Returns the
global_state/0
with schema info or an error reason. The error reason may be
a list of several errors or a single error encountered during the processing.
Equivalent to process_schema(Schemas, []).
Reads the referenced XML schemas and controls they are valid. Returns the
global_state/0
with schema info or an error reason. The error reason may be
a list of several errors or a single error encountered during the processing.
Equivalent to process_validate(Schema, Xml, []).
Validates a parsed well-formed XML element towards an XML schema.
Same as state2file(State,SchemaName)
Saves the schema state with all information of the processed schema in a file.
You can provide the file name for the saved state. FileName is saved with the
.xss
extension added.
Equivalent to validate(Element, State, []).
Validates a parsed well-formed XML element (Element).
Types
-type filename() :: string().
-type global_state() :: #xsd_state{schema_name :: term(), vsn :: term(), schema_preprocessed :: term(), external_xsd_base :: term(), xsd_base :: term(), xml_options :: term(), scope :: term(), schemaLocations :: term(), elementFormDefault :: term(), attributeFormDefault :: term(), localElementsNamespace :: term(), targetNamespace :: term(), namespace_nodes :: term(), global_namespace_nodes :: term(), checked_namespace_nodes :: term(), table :: term(), tab2file :: term(), redefine :: term(), finalDefault :: term(), blockDefault :: term(), fetch_fun :: term(), fetch_path :: term(), num_el :: term(), global_element_source :: term(), keyrefs :: term(), 'IDs' :: term(), substitutionGroups :: term(), derived_types :: term(), unchecked_references :: term(), circularity_stack :: term(), circularity_disallowed :: term(), errors :: term()}.
Functions
Reads the schema state with all information of the processed schema from a file
created with state2file/[1,2]
. The format of this file is internal. The state
can then be used validating an XML document.
Formats error descriptions to human readable strings.
Equivalent to process_schema(Schema, []).
Reads the referenced XML schema and checks that it is valid. Returns the
global_state/0
with schema info or an error reason. The error reason may be
a list of several errors or a single error encountered during the processing.
Equivalent to process_schema(Schemas, []).
Reads the referenced XML schemas and controls they are valid. Returns the
global_state/0
with schema info or an error reason. The error reason may be
a list of several errors or a single error encountered during the processing.
Equivalent to process_validate(Schema, Xml, []).
Validates a parsed well-formed XML element towards an XML schema.
Validates in two steps. First it processes the schema, saves the type and structure info in an ets table and then validates the element towards the schema.
Usage example:
1>{E,_} = xmerl_scan:file("my_XML_document.xml").
2>{E2,_} = xmerl_xsd:process_validate("my_XML_Schema.xsd",E).
Observe that E2 may differ from E if for instance there are default values
defined in my_XML_Schema.xsd
.
Same as state2file(State,SchemaName)
The name of the saved file is the same as the name of the schema, but with
.xss
extension.
Saves the schema state with all information of the processed schema in a file.
You can provide the file name for the saved state. FileName is saved with the
.xss
extension added.
Equivalent to validate(Element, State, []).
-spec validate(Element, State, Options) -> Result when Element :: #xmlElement{name :: term(), expanded_name :: term(), nsinfo :: term(), namespace :: term(), parents :: term(), pos :: term(), attributes :: term(), content :: term(), language :: term(), xmlbase :: term(), elementdef :: term()}, Options :: option_list(), Result :: {ValidElement, global_state()} | {error, Reasons}, ValidElement :: #xmlElement{name :: term(), expanded_name :: term(), nsinfo :: term(), namespace :: term(), parents :: term(), pos :: term(), attributes :: term(), content :: term(), language :: term(), xmlbase :: term(), elementdef :: term()}, State :: global_state(), Reasons :: [ErrorReason] | ErrorReason, ErrorReason :: term().
Validates a parsed well-formed XML element (Element).
A call to validate/2 or validate/3 must provide a well formed parsed XML element
#xmlElement{}
and a State, global_state/0
, which holds necessary
information from an already processed schema. Thus validate enables reuse of the
schema information and therefore if one shall validate several times towards the
same schema it reduces time consumption.
The result, ValidElement, is the valid element that conforms to the post-schema-validation infoset. When the validator finds an error it tries to continue and reports a list of all errors found. In those cases an unexpected error is found it may cause a single error reason.
Usage example:
1>{E,_} = xmerl_scan:file("my_XML_document.xml").
2>{ok,S} = xmerl_xsd:process_schema("my_XML_Schema.xsd").
3>{E2,_} = xmerl_xsd:validate(E,S).
Observe that E2 may differ from E if for instance there are default values
defined in my_XML_Schema.xsd
.