libxml++  5.4.0
Public Member Functions | Protected Member Functions | List of all members
xmlpp::XsdValidator Class Reference

XSD schema validator. More...

#include <libxml++/validators/xsdvalidator.h>

Inheritance diagram for xmlpp::XsdValidator:
Inheritance graph
[legend]

Public Member Functions

 XsdValidator ()
 
 XsdValidator (const Document * document)
 Create a validator and parse a schema definition document. More...
 
 XsdValidator (const std::string & filename)
 Create a validator and parse a schema definition file. More...
 
 XsdValidator (XsdSchema * schema, bool take_ownership)
 Create a validator. More...
 
 ~XsdValidator () override
 
const XsdSchemaget_schema () const noexcept
 Get the schema. More...
 
XsdSchemaget_schema () noexcept
 Get the schema. More...
 
 operator bool () const noexcept override
 Test whether a schema has been parsed. More...
 
void parse_document (const Document * document) override
 Parse a schema definition from a document. More...
 
void parse_file (const std::string & filename) override
 Parse a schema definition file. More...
 
void parse_memory (const ustring & contents) override
 Parse a schema definition from a string. More...
 
void set_schema (XsdSchema * schema, bool take_ownership)
 Set a schema. More...
 
void validate (const Document * document) override
 Validate a document, using a previously parsed schema. More...
 
void validate (const std::string & filename) override
 Validate an XML file, using a previously parsed schema. More...
 
- Public Member Functions inherited from xmlpp::SchemaValidatorBase
 SchemaValidatorBase () noexcept
 
 ~SchemaValidatorBase () override
 
- Public Member Functions inherited from xmlpp::Validator
 Validator () noexcept
 
 ~Validator () override
 
- Public Member Functions inherited from xmlpp::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
 NonCopyable (NonCopyable &&)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
NonCopyableoperator= (NonCopyable &&)=delete
 

Protected Member Functions

void initialize_context () override
 
void release_underlying () override
 
- Protected Member Functions inherited from xmlpp::Validator
virtual void check_for_exception ()
 
virtual void check_for_validity_messages ()
 
virtual void handle_exception ()
 To be called in an exception handler. More...
 
virtual void on_validity_error (const ustring & message)
 
virtual void on_validity_warning (const ustring & message)
 
- Protected Member Functions inherited from xmlpp::NonCopyable
 NonCopyable () noexcept
 
virtual ~NonCopyable ()
 

Additional Inherited Members

- Static Protected Member Functions inherited from xmlpp::Validator
static void callback_error_or_warning (bool error, void * ctx, const char * msg, va_list var_args)
 
static void callback_validity_error (void * ctx, const char * msg,...)
 
static void callback_validity_warning (void * ctx, const char * msg,...)
 
static ValidatorCallbackCFuncType get_callback_validity_error_cfunc ()
 
static ValidatorCallbackCFuncType get_callback_validity_warning_cfunc ()
 
- Protected Attributes inherited from xmlpp::Validator
std::unique_ptr< exceptionexception_
 
ustring validate_error_
 
ustring validate_warning_
 

Detailed Description

XSD schema validator.

XSD = XML Schema Definition, a.k.a. XML Schema or W3C XML Schema

Since libxml++ 2.38:

Constructor & Destructor Documentation

◆ XsdValidator() [1/4]

xmlpp::XsdValidator::XsdValidator ( )

◆ XsdValidator() [2/4]

xmlpp::XsdValidator::XsdValidator ( const std::string filename)
explicit

Create a validator and parse a schema definition file.

Parameters
filenameThe URL of the schema.
Exceptions
xmlpp::parse_error

◆ XsdValidator() [3/4]

xmlpp::XsdValidator::XsdValidator ( const Document document)
explicit

Create a validator and parse a schema definition document.

Parameters
documentA preparsed document tree, containing the schema definition.
Exceptions
xmlpp::parse_error

◆ XsdValidator() [4/4]

xmlpp::XsdValidator::XsdValidator ( XsdSchema schema,
bool  take_ownership 
)
explicit

Create a validator.

Parameters
schemaA pointer to the schema to use when validating XML documents.
take_ownershipIf true, the validator takes ownership of the schema. The caller must not delete it.
If false, the validator does not take ownership of the schema. The caller must guarantee that the schema exists as long as the validator keeps a pointer to it. The caller is responsible for deleting the schema when it's no longer needed.

◆ ~XsdValidator()

xmlpp::XsdValidator::~XsdValidator ( )
override

Member Function Documentation

◆ get_schema() [1/2]

const XsdSchema* xmlpp::XsdValidator::get_schema ( ) const
noexcept

Get the schema.

Returns
A pointer to the schema, or nullptr.

◆ get_schema() [2/2]

XsdSchema* xmlpp::XsdValidator::get_schema ( )
noexcept

Get the schema.

Returns
A pointer to the schema, or nullptr.

◆ initialize_context()

void xmlpp::XsdValidator::initialize_context ( )
overrideprotectedvirtual

Reimplemented from xmlpp::SchemaValidatorBase.

◆ operator bool()

xmlpp::XsdValidator::operator bool ( ) const
explicitoverridevirtualnoexcept

Test whether a schema has been parsed.

For instance

if (xsd_validator)
do_something();

Implements xmlpp::SchemaValidatorBase.

◆ parse_document()

void xmlpp::XsdValidator::parse_document ( const Document document)
overridevirtual

Parse a schema definition from a document.

If the validator already contains a schema, that schema is released (deleted if the validator owns the schema).

Parameters
documentA preparsed document tree, containing the schema definition.
Exceptions
xmlpp::parse_error

Implements xmlpp::SchemaValidatorBase.

◆ parse_file()

void xmlpp::XsdValidator::parse_file ( const std::string filename)
overridevirtual

Parse a schema definition file.

If the validator already contains a schema, that schema is released (deleted if the validator owns the schema).

Parameters
filenameThe URL of the schema.
Exceptions
xmlpp::parse_error

Implements xmlpp::SchemaValidatorBase.

◆ parse_memory()

void xmlpp::XsdValidator::parse_memory ( const ustring contents)
overridevirtual

Parse a schema definition from a string.

If the validator already contains a schema, that schema is released (deleted if the validator owns the schema).

Parameters
contentsThe schema definition as a string.
Exceptions
xmlpp::parse_error

Implements xmlpp::SchemaValidatorBase.

◆ release_underlying()

void xmlpp::XsdValidator::release_underlying ( )
overrideprotectedvirtual

Reimplemented from xmlpp::SchemaValidatorBase.

◆ set_schema()

void xmlpp::XsdValidator::set_schema ( XsdSchema schema,
bool  take_ownership 
)

Set a schema.

If the validator already contains a schema, that schema is released (deleted if the validator owns the schema).

Parameters
schemaA pointer to the schema to use when validating XML documents.
take_ownershipIf true, the validator takes ownership of the schema. The caller must not delete it.
If false, the validator does not take ownership of the schema. The caller must guarantee that the schema exists as long as the validator keeps a pointer to it. The caller is responsible for deleting the schema when it's no longer needed.

◆ validate() [1/2]

void xmlpp::XsdValidator::validate ( const Document document)
overridevirtual

Validate a document, using a previously parsed schema.

Parameters
documentPointer to the document.
Exceptions
xmlpp::internal_error
xmlpp::validity_error

Implements xmlpp::SchemaValidatorBase.

◆ validate() [2/2]

void xmlpp::XsdValidator::validate ( const std::string filename)
overridevirtual

Validate an XML file, using a previously parsed schema.

Parameters
filenameThe URL of the XML file.
Exceptions
xmlpp::internal_error
xmlpp::validity_error

Implements xmlpp::SchemaValidatorBase.