Script for exporting and importing matrix (meta-model) to the XML and from the XML Public functions (the only functions that user of the library should call):
Export
ExportMatrixXml( filename, export_trees=True, export_unchecked_rules=False ):
Exports matrix (meta-model) to the XML file with specified name. If export_trees flag is True, tree information also exported. Otherwise, trees are not exported. The export_unchecked_rules flags defines, whether rules, that are not checked in the tree, are exported, when tree is exported. Setting it to True can produce significantly bigger xml. Currently, there is no need to use this flag, and it should be considered as deprecated.
Import
ImportMatrixXml( fname, rename_rules=True, delete_rules=True, delete_attribs=True, import_trees=True, preserve_rules=None, preserve_attrs=None, really_import=True )
Works only with
Imports matrix and optionally trees from the XML file generated by the ExportMatrixXml. When matrix is empty, script simply creates new rules and attributes, according to the information in the XML file.
When matrix already contains some rules, this script tries to update it by renaming/adding/removing new rules and by adding/deleting attributes. To determine renamed rules, heuristic algorithm is used. This algorithm takes in account differences between names, child and parent types and attributes and searches for the best guess.
Rules from matrix, that were not found in the XML, and were not detected as the renamed, are removed.
Arguments:
- fname - path to the XML file to import
- rename_rules - if True, algorithm tries to use heuristic algorithm to guess renamed rules. Used for updating matrix.
- delete_rules - if True, algorithm would delete rules, that were not found in the XML.
- delete_attribs - if True, algorithm would delete attributes, that were not found in the XML.
- preserve_rules - Can be None or list of strings. All the rules in this list will not be deleted, even if delete_rules is True.
- preserve_attribs - Can be None or list of strings. All attributes in this list will not be deleted, even is delete_attribs is True.
- really_import - if False, script performs "dry run", without really modifying the matrix. The library 'arkisubstitute.py' must be available to use this option. If this library is not available, exception would be raised.