dcclib.conversion

Convertible

Bases: ABC

Abstract base class for classes that can be converted.

convert abstractmethod

convert()

Convert the object.

JSONConverter

JSONConverter(xml: str, version: str)

Bases: Constructible, Convertible

JSONConverter class that converts DCC XML to JSON whilst being schema-aware.

Conversion is delegated to :class:dcc_json_toolkit.DccSchema, which loads and caches the released XSD schema for the detected version.

Constructor for JSONConverter class.

Parameters:
  • xml (str) –

    the DCC XML (complete document or subschema fragment) as a string.

  • version (str) –

    the DCC schema version string (e.g. "3.3.0") used to load the matching XSD schema.

convert

convert() -> str

Convert the DCC XML to JSON.

Returns:
  • str –

    the JSON representation of the DCC XML (or subtree)

from_file classmethod

from_file(path: str)

Create a JSONConverter from a DCC XML file path.

Parameters:
  • path (str) –

    the path to the DCC XML file

Returns:
  • –

    the JSONConverter

from_str classmethod

from_str(xml: str)

Create a JSONConverter from a DCC XML string.

Parameters:
  • xml (str) –

    the DCC XML string

Returns:
  • –

    the JSONConverter

from_tree classmethod

from_tree(tree: etree._Element | etree._ElementTree)

Create a JSONConverter from an etree.Element or etree.ElementTree. If a subtree element is passed, the schema version is derived from the enclosing document root.

Parameters:
  • tree (etree._Element | etree._ElementTree) –

    the etree.Element or etree.ElementTree

Returns:
  • –

    the JSONConverter

to_dict

to_dict() -> dict

Convert the DCC XML to a dictionary.

Returns:
  • dict –

    the dictionary representation of the DCC XML (or subtree)

convertible

Convertible

Bases: ABC

Abstract base class for classes that can be converted.

convert abstractmethod

convert()

Convert the object.

json_converter

JSONConverter

JSONConverter(xml: str, version: str)

Bases: Constructible, Convertible

JSONConverter class that converts DCC XML to JSON whilst being schema-aware.

Conversion is delegated to :class:dcc_json_toolkit.DccSchema, which loads and caches the released XSD schema for the detected version.

Constructor for JSONConverter class.

Parameters:
  • xml (str) –

    the DCC XML (complete document or subschema fragment) as a string.

  • version (str) –

    the DCC schema version string (e.g. "3.3.0") used to load the matching XSD schema.

convert

convert() -> str

Convert the DCC XML to JSON.

Returns:
  • str –

    the JSON representation of the DCC XML (or subtree)

from_file classmethod

from_file(path: str)

Create a JSONConverter from a DCC XML file path.

Parameters:
  • path (str) –

    the path to the DCC XML file

Returns:
  • –

    the JSONConverter

from_str classmethod

from_str(xml: str)

Create a JSONConverter from a DCC XML string.

Parameters:
  • xml (str) –

    the DCC XML string

Returns:
  • –

    the JSONConverter

from_tree classmethod

from_tree(tree: etree._Element | etree._ElementTree)

Create a JSONConverter from an etree.Element or etree.ElementTree. If a subtree element is passed, the schema version is derived from the enclosing document root.

Parameters:
  • tree (etree._Element | etree._ElementTree) –

    the etree.Element or etree.ElementTree

Returns:
  • –

    the JSONConverter

to_dict

to_dict() -> dict

Convert the DCC XML to a dictionary.

Returns:
  • dict –

    the dictionary representation of the DCC XML (or subtree)