pygcam.XMLFile¶
This module contains the XMLFile class, which provides support for
Conditional XML, XML schema validation, as well as defining the
McsValues class, a subclass of XMLFile.
API¶
- class pygcam.XMLFile.McsValues(filename)¶
- regions()¶
Get the regions used in this file.
- Returns
(list of str) region names
- values(region)¶
Get the values associated with the region.
- Parameters
region – (str) the name of a GCAM region
- Returns
(dict) keys are names of value elements and values are floats. Returns None if the region is not found
- class pygcam.XMLFile.XMLFile(filename, load=True, schemaPath=None, removeComments=True, conditionalXML=False, varDict=None)¶
Stores information about an XML file; provides wrapper to parse and access the file tree, and handle “conditional XML”.
- Parameters
filename – (str) The pathname to the XML file
load – (bool) If True, the file is loaded, otherwise, the instance is set up, but the file is not read.
schemaPath – (str) If not None, the path relative to the root of the package to the .xsd (schema definition) file to use to validate the XML file.
removeComments – (bool) If True, comments are discarded upon reading the file.
conditionalXML – (bool) If True, the XML is processed using Conditional XML prior to validation.
varDict – (dict) A dictionary to use in place of the configuration dictionary when processing Conditional XML.
- getFilename()¶
Return the filename for this
XMLFile
- getRoot()¶
Return the root node of the parse tree
- getTree()¶
Return XML parse tree.
- read()¶
Read the XML file, and if validate if
self.schemaFileis not None.
- validate(raiseOnError=True)¶
Validate a ParameterList against
self.schemaFile. Optionally raises an error on failure, else return boolean validity status. If no schema file is defined, returnTrue.