schema_parser classes¶
The ‘’OcxSchema’’ class¶
- class schema_parser.parser.OcxSchema(logger, local_folder='schema_versions\\\\')[source]¶
Bases:
objectThe OcxSchema provides functionality for parsing the OCX xsd schema and storing all the elements.
- Parameters
logger – The main python logger
- Variables
_namespace – The dict of all namespaces on the form (prefix, namespace) key-value pairs resulting from parsing all schema files, W3C.
_ocx_global_elements – Hash table as key-value pairs (tag, OcxSchemaElement) for all parsed schema elements
_is_parsed – True if a schema has been parsed, False otherwise
_schema_version – The version of the parsed schema
_local_folder – The local folder where any external schemas will be downloaded
_schema_changes – A list of all schema changes described by the tag SchemaChange contained in the xsd file.
_schema_types – The list of xsd types to be parsed. Only these types will be stored.
_default_schema – The default schema to be parsed
_builtin_xs_types – W3C primitive data types. www.w3.org. Defined in
config.yaml
- get_default_schema()[source]¶
Return the default schema to be parsed.
- Return type
str- Returns
The default schema url.
- get_namespaces()[source]¶
The parsed namespaces’
- Return type
Dict- Returns
The dict of namespaces as (namespace,prefix) key-value pairs
- get_ocx_element_from_type(schema_type)[source]¶
Method to retrieve the schema
element etree.Elementwith the key ‘type’- Parameters
schema_type – the ocx type on the form
prefix:name- Return type
Optional[OcxGlobalElement]- Returns
The
OcxGlobalElementinstance
- get_ocx_elements()[source]¶
All ocx
OcxGlobalElementelements- Return type
List- Returns
The list of all parsed
OcxGlobalElementinstances
- get_schema_changes()[source]¶
The OCX schema change history
- Return type
Dict- Returns
The schema changes for all schema versions
- get_schema_folder()[source]¶
Return the local folder where the schemas are stored. The local folder is relative to the project root.
- Return type
str- Returns
The relative path to the local schema folder.
- get_schema_version()[source]¶
The OCX schema version
- Return type
str- Returns
The coded version string of the OCX schema
- process_schema(schema_url='https://raw.githubusercontent.com/OCXStandard/OCX_Schema/working_draft/OCX_Schema.xsd')[source]¶
Process the XSD schema file and create all hash tables of global elements.
- Return type
bool- Returns
True of processed OK, False otherwise.
- put_default_schema(schema_url)[source]¶
Return the default schema to be parsed.
- Parameters
schema_url – The location of the schema
- put_schema_folder(local_folder)[source]¶
Set the local folder where the schemas are stored. The local folder is relative to the project root.
- tbl_attribute_groups()[source]¶
All parsed
attributeGrouptypes in the schema and any referenced schemas’- Return type
Dict- Returns
List of
SchemaTypedata class holdingattributeGroupattributes.
- tbl_attribute_types()[source]¶
The table of all parsed attribute elements in the schema and any referenced schemas’
- Return type
Dict- Returns
The
SchemaTypedata class attributes ofattributeType
- tbl_complex_types()[source]¶
The table of all parsed complexType elements in the schema and any referenced schemas’
- Return type
Dict- Returns
The
SchemaTypedata class attributes ofcomplexType
- tbl_element_types()[source]¶
The table of all parsed elements of type element in the schema and any referenced schemas’
- Return type
Dict- Returns
The
SchemaTypedata class attributes ofelement
- tbl_simple_types()[source]¶
The table of all parsed
simpleTypeelements in the schema and any referenced schemas’- Return type
Dict- Returns
The
SchemaTypedata class attributes ofsimpleType
The ‘’SchemaHelper’’ class¶
- class schema_parser.helpers.SchemaHelper[source]¶
Bases:
objectA utility class for retrieving OCX attributes and information from an OCX xsd element
- static find_schema_changes(root)[source]¶
Find any schema version changes with tag
SchemaChange- Parameters
root – The root element of the schema
- Return type
List[SchemaChange]- Returns
A list of
SchemaChangedataclasses
- classmethod get_reference(element)[source]¶
The element reference
- Return type
Optional[str]- Returns
The reference to a global element on the form
prefix:name. Returns None if the element is not a reference.
- static get_schema_version(root)[source]¶
Get the current OCX schema version
- Parameters
root – The root element of the schema
- Return type
str- Returns
The version of the OCX schema
- static get_type(element)[source]¶
The element type given by the element attribute or by its
complexContent- Return type
str- Returns
The global element type on the form
prefix:name. If the element has no type,untypedis returned.
- classmethod is_reference(element)[source]¶
Is a reference or not
- Return type
bool- Returns
True if the element is a reference, False otherwise
The ‘’SchemaType’’ class¶
- class schema_parser.data_classes.SchemaType(prefix, name, tag, source_line)[source]¶
Bases:
BaseDataClassClass for xsd schema type information
- Parameters
name – The schema type name
prefix – The schema type namespace prefix
source_line – The line number in the schema file where the type is defined
tag – The schema type tag
-
name:
str¶
-
prefix:
str¶
-
source_line:
int¶
-
tag:
str¶
The ‘’BaseDataClass’’ class¶
The ‘’SchemaSummary’’ class¶
- class schema_parser.data_classes.SchemaSummary(schema_version, schema_types, schema_namespaces)[source]¶
Bases:
objectClass for schema summary information
- Parameters
schema_version – The schema version
schema_types – Tuples of the number of schema types
schema_namespaces – Tuples of namespace prefixes
-
schema_namespaces:
List[Tuple]¶
-
schema_types:
List[Tuple]¶
-
schema_version:
List[Tuple]¶
The ‘’SchemaChange’’ class¶
- class schema_parser.data_classes.SchemaChange(version, author, date, description='')[source]¶
Bases:
BaseDataClassClass for keeping track of OCX schema changes
- Parameters
version – The schema version the change applies to
author – The author of the schem change
date – The date of the schema change
description – A description of the change
-
author:
str¶
-
date:
str¶
-
description:
str= ''¶
-
version:
str¶
The ‘’OcxGlobalElement’’ class¶
- class schema_parser.elements.OcxGlobalElement(xsd_element, unique_tag, logger)[source]¶
Bases:
objectGlobal schema element class capturing the xsd schema definition of a global
xs:element.- Parameters
xsd_element – The lxml.etree.Element class
logger – The main python logger
- Variables
log – The Python logger instance
_element – The
lxml.Elementinstance_attributes – The attributes of the global element including the attributes of all schema supertypes
_reference – The
OcxGlobalElementhase reference to a global schema element. ‘None’ if no reference_tag – The unique global tag of the
OcXGlobalElement_parents – Hash table of references to all parent schema types with tag as key
_children – List of references to all children schema types with tag as key. Includes also children of all super-types.
-assertions – List of any assertions associated with the
xs:element
- add_assertion(test)[source]¶
Add an assertion test associated to me’
- Parameters
test – The definition of the assertion represented as a string
- Returns
Nothing
- add_attribute(attribute)[source]¶
Add attributes to the global element
- Parameters
attribute – The
OcxAttributeinstance to be added
- add_child(child)[source]¶
Add a child of an OCX global element’
- Parameters
child – The added child instance of a
OcxChildElementclass- Returns
Nothing
- attributes_to_dict()[source]¶
A dictionary of all
OcxGlobalElementattribute values- Return type
Dict- Returns
A dictionary of attribute values with heading keys
Heading keys¶ Attribute
Type
Use
Default
Fixed
Description
- children_to_dict()[source]¶
A dictionary of all
OcxGlobalElementchildren values- Return type
Dict- Returns
table – A dictionary of attribute values with heading keys:
Heading keys¶ Child
Type
Use
Cardinality
Description
- get_annotation()[source]¶
The global element annotation or description
- Return type
str- Returns
The annotation string of the element
- get_assertion_tests()[source]¶
Get all my assertions
- Return type
List- Returns
Assertion tests in a list
- get_attributes()[source]¶
The global element attributes including also parent attributes
- Return type
List- Returns
A dict of all attributes including also parent attributes
- get_cardinality()[source]¶
Get the cardinality of the OcxGlobalElement
- Return type
str- Returns
The cardinality as sting represented by [lower, upper]
- get_children()[source]¶
Get all my children xsd types
- Return type
List- Returns
Return all children as a dict of key-value pairs
(tag, OCXChildElement)
- get_name()[source]¶
The global element name
- Return type
str- Returns
The name of the global schema element as a str
- get_namespace()[source]¶
The element _namespace
- Return type
str- Returns
The _namespace of the global schema element as a str
- get_parent_names()[source]¶
Get all my parent names
- Return type
List- Returns
Return all parents names in a list
- get_parents()[source]¶
Get all my attributes
- Return type
dict- Returns
Return all parents as a dict of key-value pairs
(tag, Element)
- get_prefix()[source]¶
The global element _namespace prefix
- Return type
str- Returns
The type of the global schema element as a str
- get_properties()[source]¶
A dictionary of all
OcxGlobalElementproperty values- Return type
Dict- Returns
table –
A dictionary of property values with heading keys:
Heading keys¶ Name
Type
Use
Cardinality
Fixed
Description
- get_reference()[source]¶
Get the reference to a global element
- Return type
str- Returns
tag – The unique tag to the global referenced element
- get_schema_element()[source]¶
Get the schema xsd element of the
OcxSchemeElementobject- Return type
Element- Returns
My xsd schema element
- get_substitution_group()[source]¶
Return the name of the substitutionGroup
- Return type
Optional[str]- Returns
The name of the
substitutionGroup, None otherwise
- get_tag()[source]¶
The global schema element unique tag
- Return type
str- Returns
The element tag on the form
{prefix}name
- get_type()[source]¶
The global element type
- Return type
str- Returns
The type of the global schema element as a str
- get_use()[source]¶
The element’s use, required or optional
- Return type
str- Returns
The element use –
req.if mandatory, elseopt
- has_assertion()[source]¶
Whether the element has assertions or not’
- Return type
bool- Returns
Tru if the global element as assertions, False otherwise
- is_abstract()[source]¶
Whether the element is abstract
- Return type
bool- Returns
True if the element is abstract, False otherwise
- is_choice()[source]¶
Whether the element is a choice or not
- Return type
bool- Returns
True if the element is a choice, False otherwise
- is_mandatory()[source]¶
Whether the element mandatory or not
- Return type
bool- Returns
Returns True if the element is mandatory, False otherwise
- is_reference()[source]¶
Whether the element has a reference or not
- Return type
bool- Returns
is_reference – True if the element has a reference, False otherwise
- is_substitution_group()[source]¶
Whether the element is part of a substitutionGroup
- Return type
bool- Returns
True if the element is a substitutionGroup, False otherwise
- put_cardinality(element)[source]¶
Override the cardinality of the OcxGlobalElement
- Parameters
element – the etree.Element node
- put_child(tag, child)[source]¶
Add a child element of type
OCxChildElement- Parameters
tag – The unique tag of the parent element
child – The child xsd schema element
- Returns
None
The ‘’OcxChildElement’’ class¶
- class schema_parser.elements.OcxChildElement(xs_element)[source]¶
Bases:
objectClass capturing the OCX xsd schema definition of a child or sub element
xs:element.- Parameters
xs_element – The lxml.etree.Element class
- Variables
_tag – The unique tag of th schema element
_element – The
xs:elementinstance_name – The attribute name
_type – The attribute type
_use – Whether the child is optional or required
_cardinality – The cardinality of the element
_annotation – The element description
_is_choice – The child element is a
xs:choice
- attributes_to_dict()[source]¶
A dictionary of the ‘’OcxChildElement’’ values
- Return type
Dict- Returns
table – dictionary of all OcxAttribute attribute values with columns:
Heading titles¶ Child
Cardinality
Choice
Global
Description
- get_cardinality()[source]¶
Get the cardinality of the
OcxChildElement- Return type
str- Returns
The cardinality as sting represented by
[lower, upper]
- get_description()[source]¶
The annotation text of the element
- Return type
str- Returns
The description of the element
- get_use()[source]¶
Mandatory or optional sub element
- Return type
str- Returns
The element use, either
req.oropt.
- is_choice()[source]¶
Whether the element is a choice or not
- Return type
bool- Returns
True if the element is a choice, False otherwise
- is_global()[source]¶
Whether the element is a global schema element
- Return type
bool- Returns
True if the element is global, False otherwise
The ‘’OcxAttribute’’ class¶
- class schema_parser.elements.OcxAttribute(xs_attribute)[source]¶
Bases:
objectGlobal schema attribute class capturing the xsd schema definition of a global xs:attribute.
- Parameters
xs_attribute – The lxml.etree.Element class
- Variables
_name – The attribute name
_type – The attribute type
_use – Whether the attribute is optional or required
_fixed – Whether the attribute has a fixed value if any
_default – The deaflalt value of the attribute if any
_annotation – The attribute description
_is_global – True if the element is global, False otherwise
- attributes_to_dict()[source]¶
A dictionary of the OcxAttribute values
- Return type
Dict- Returns
table – A dictionary of all
OcxAttributeattribute values with columns:Heading titles¶ Attribute
Type
Use
Default
Fixed
Description
- get_default()[source]¶
The default value of the xs:attribute
- Return type
str- Returns
Returns the default value of the attribute or an empty string if None
- get_description()[source]¶
The annotation string of the xs:attribute
- Return type
str- Returns
The attribute description text
- get_fixed()[source]¶
The fixed value of the xs:attribute
- Return type
str- Returns
Returns the fixed value of the attribute or an empty string if None