hed_schema_io

Utilities for loading and outputting HED schema.

Functions

from_string(schema_string[, schema_format, ...])

Create a schema from the given string.

get_hed_xml_version(xml_file_path)

Get the version number from a HED XML file.

load_schema([hed_path, schema_namespace])

Load a schema from the given file or URL path.

load_schema_version([xml_version, xml_folder])

Return a HedSchema or HedSchemaGroup extracted from xml_version field.

from_string(schema_string, schema_format='.xml', schema_namespace=None)[source]

Create a schema from the given string.

Parameters:
  • schema_string (str) – An XML or mediawiki file as a single long string.

  • schema_format (str) – The schema format of the source schema string.

  • schema_namespace (str, None) – The name_prefix all tags in this schema will accept.

Returns:

The loaded schema.

Return type:

(HedSchema)

Raises:

HedFileError

  • If empty string or invalid extension is passed.

  • Other fatal formatting issues with file

Notes

  • The loading is determined by file type.

get_hed_xml_version(xml_file_path)[source]

Get the version number from a HED XML file.

Parameters:

xml_file_path (str) – The path to a HED XML file.

Returns:

The version number of the HED XML file.

Return type:

str

Raises:

HedFileError

  • There is an issue loading the schema

load_schema(hed_path=None, schema_namespace=None)[source]

Load a schema from the given file or URL path.

Parameters:
  • hed_path (str or None) – A filepath or url to open a schema from.

  • schema_namespace (str or None) – The name_prefix all tags in this schema will accept.

Returns:

The loaded schema.

Return type:

HedSchema

Raises:

HedFileError

  • Empty path passed

  • Unknown extension

  • Any fatal issues when loading the schema.

load_schema_version(xml_version=None, xml_folder=None)[source]

Return a HedSchema or HedSchemaGroup extracted from xml_version field.

Parameters:
  • xml_version (str or list or None) – List or str specifying which official HED schemas to use. An empty string returns the latest version A json str format is also supported, based on the output of HedSchema.get_formatted_version Basic format: ‘[schema_namespace:][library_name_]X.Y.Z’.

  • xml_folder (str) – Path to a folder containing schema.

Returns:

The schema or schema group extracted.

Return type:

HedSchema or HedSchemaGroup

Raises:

HedFileError

  • The xml_version is not valid.

  • The specified version cannot be found or loaded

  • Other fatal errors loading the schema (These are unlikely if you are not editing them locally)

  • The prefix is invalid