Nektar++
Public Member Functions | Private Attributes | List of all members
CellMLToNektar.validator.LxmlRelaxngValidator Class Reference
Inheritance diagram for CellMLToNektar.validator.LxmlRelaxngValidator:
[legend]

Public Member Functions

def __init__ (self, schemaBase)
 
def validate (self, stream)
 
def quit (self)
 

Private Attributes

 _validator
 

Detailed Description

A RELAX NG validator built on top of lxml (http://lxml.de/validation.html#relaxng).
Can validate against schemas written in the XML syntax.

Definition at line 215 of file validator.py.

Constructor & Destructor Documentation

◆ __init__()

def CellMLToNektar.validator.LxmlRelaxngValidator.__init__ (   self,
  schemaBase 
)
Initialise the RELAX NG validator.

Parses the schema into memory, and constructs lxml's validator object.
We are passed the path to the schema with no extension.

Definition at line 220 of file validator.py.

220 def __init__(self, schemaBase):
221 """Initialise the RELAX NG validator.
222
223 Parses the schema into memory, and constructs lxml's validator object.
224 We are passed the path to the schema with no extension.
225 """
226 try:
227 from lxml import etree
228 except ImportError, e:
229 raise ValidatorError("Unable to import lxml: " + str(e))
230 fp = open(schemaBase + '.rng', 'r')
231 schema_doc = etree.parse(fp)
232 self._validator = etree.RelaxNG(schema_doc)
233

Member Function Documentation

◆ quit()

def CellMLToNektar.validator.LxmlRelaxngValidator.quit (   self)
Providing for compatibility with RvpRelaxngValidator; does nothing.

Definition at line 248 of file validator.py.

248 def quit(self):
249 """Providing for compatibility with RvpRelaxngValidator; does nothing."""
250 pass
251
252
def quit(self)
def del(self): """ Tell our RVP process to quit.
Definition: validator.py:288

◆ validate()

def CellMLToNektar.validator.LxmlRelaxngValidator.validate (   self,
  stream 
)
Validate an XML document, returning a boolean.

stream should be a file-like object containing the document to be validated.
Returns True iff the document was valid.

Definition at line 234 of file validator.py.

234 def validate(self, stream):
235 """Validate an XML document, returning a boolean.
236
237 stream should be a file-like object containing the document to be validated.
238 Returns True iff the document was valid."""
239 from lxml import etree
240 doc = etree.parse(stream)
241 res = self._validator.validate(doc)
242 # Report error details via the logger
243 logger = logging.getLogger('validator')
244 for e in self._validator.error_log:
245 logger.error(e)
246 return res
247
def validate(self, stream)
Definition: validator.py:296

References CellMLToNektar.validator.LxmlRelaxngValidator._validator, and CellMLToNektar.validator.LxmlRelaxngValidator.validate().

Referenced by CellMLToNektar.validator.LxmlRelaxngValidator.validate().

Member Data Documentation

◆ _validator

CellMLToNektar.validator.LxmlRelaxngValidator._validator
private