Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Private Attributes | List of all members
CellMLToNektar.validator.LxmlRelaxngValidator Class Reference
Inheritance diagram for CellMLToNektar.validator.LxmlRelaxngValidator:
Inheritance graph
[legend]
Collaboration diagram for CellMLToNektar.validator.LxmlRelaxngValidator:
Collaboration graph
[legend]

Public Member Functions

def __init__
 
def validate
 
def quit
 

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

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.

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

Member Function Documentation

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

Definition at line 248 of file validator.py.

249  def quit(self):
250  """Providing for compatibility with RvpRelaxngValidator; does nothing."""
251  pass
252 
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.

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

Member Data Documentation

CellMLToNektar.validator.LxmlRelaxngValidator._validator
private

Definition at line 232 of file validator.py.