3.2. xml - XML serialization and deserialization
This package contains functionality for serialization and deserialization of BaSyx Python SDK objects into/from XML.
xml_serialization: The module offers a function to write an
ObjectStore to a given file.
xml_deserialization: The module offers a function to create an
ObjectStore from a given xml document.
3.2.1. xml.xml_serialization - Serialization from AAS-objects to XML
Module for serializing Asset Administration Shell data to the official XML format
How to use:
For generating an XML-File from a
AbstractObjectStore, check out the functionwrite_aas_xml_file().For serializing any object to an XML fragment, that fits the XML specification from ‘Details of the Asset Administration Shell’, chapter 5.4, you can either use
object_to_xml_element(), which serializes a given object and returns it as_Element, orwrite_aas_xml_element(), which does the same thing, but writes the_Elementto a file instead of returning it. As a third alternative, you can also use the functions<class_name>_to_xml()directly.
Attention
Unlike the XML deserialization and the JSON (de-)serialization, the XML serialization only supports
BinaryIO and not TextIO. Thus, if you open files by yourself, you have to open
them in binary mode, see the mode table of open().
# wb = open for writing + binary mode
with open("example.xml", "wb") as fp:
write_aas_xml_file(fp, object_store)
- abstract_classes_to_xml(tag: str, obj: object) _Element
Generates an XML element and adds attributes of abstract base classes of
obj.If the object obj is inheriting from any abstract AAS class, this function adds all the serialized information of those abstract classes to the generated element.
- Parameters:
tag – Tag of the element
obj – An object of the AAS
- Returns:
Parent element with the serialized information from the abstract classes
- administrative_information_to_xml(obj: AdministrativeInformation, tag: str = '{https://admin-shell.io/aas/3/0}administration') _Element
Serialization of objects of class
AdministrativeInformationto XML- Parameters:
obj – Object of class
AdministrativeInformationtag – Namespace+Tag of the serialized element. Default is
aas:administration
- Returns:
Serialized
_Elementobject
- annotated_relationship_element_to_xml(obj: AnnotatedRelationshipElement, tag: str = '{https://admin-shell.io/aas/3/0}annotatedRelationshipElement') _Element
Serialization of objects of class
AnnotatedRelationshipElementto XML- Parameters:
obj – Object of class
AnnotatedRelationshipElementtag – Namespace+Tag of the serialized element (optional): Default is
aas:annotatedRelationshipElement
- Returns:
Serialized
_Elementobject
- asset_administration_shell_to_xml(obj: AssetAdministrationShell, tag: str = '{https://admin-shell.io/aas/3/0}assetAdministrationShell') _Element
Serialization of objects of class
AssetAdministrationShellto XML- Parameters:
obj – Object of class
AssetAdministrationShelltag – Namespace+Tag of the ElementTree object. Default is
aas:assetAdministrationShell
- Returns:
Serialized
_Elementobject
- asset_information_to_xml(obj: AssetInformation, tag: str = '{https://admin-shell.io/aas/3/0}assetInformation') _Element
Serialization of objects of class
AssetInformationto XML- Parameters:
obj – Object of class
AssetInformationtag – Namespace+Tag of the ElementTree object. Default is
aas:assetInformation
- Returns:
Serialized
_Elementobject
- basic_event_element_to_xml(obj: BasicEventElement, tag: str = '{https://admin-shell.io/aas/3/0}basicEventElement') _Element
Serialization of objects of class
BasicEventElementto XML- Parameters:
obj – Object of class
BasicEventElementtag – Namespace+Tag of the serialized element (optional). Default is
aas:basicEventElement
- Returns:
Serialized
_Elementobject
- blob_to_xml(obj: Blob, tag: str = '{https://admin-shell.io/aas/3/0}blob') _Element
Serialization of objects of class
Blobto XML
- boolean_to_xml(obj: bool) str
Serialize a boolean to XML
- Parameters:
obj – Boolean (
True,False)- Returns:
String in the XML accepted form (
true,false)
- capability_to_xml(obj: Capability, tag: str = '{https://admin-shell.io/aas/3/0}capability') _Element
Serialization of objects of class
Capabilityto XML- Parameters:
obj – Object of class
Capabilitytag – Namespace+Tag of the serialized element, default is
aas:capability
- Returns:
Serialized
_Elementobject
- concept_description_to_xml(obj: ConceptDescription, tag: str = '{https://admin-shell.io/aas/3/0}conceptDescription') _Element
Serialization of objects of class
ConceptDescriptionto XML- Parameters:
obj – Object of class
ConceptDescriptiontag – Namespace+Tag of the ElementTree object. Default is
aas:conceptDescription
- Returns:
Serialized
_Elementobject
- data_element_to_xml(obj: DataElement) _Element
Serialization of objects of class
DataElementto XML- Parameters:
obj – Object of class
DataElement- Returns:
Serialized
_Elementobject
- data_specification_content_to_xml(obj: DataSpecificationContent, tag: str = '{https://admin-shell.io/aas/3/0}dataSpecificationContent') _Element
Serialization of objects of class
DataSpecificationContentto XML- Parameters:
obj – Object of class
DataSpecificationContenttag – Namespace+Tag of the ElementTree object. Default is
aas:dataSpecificationContent
- Returns:
Serialized
_Elementobject
- data_specification_iec61360_to_xml(obj: DataSpecificationIEC61360, tag: str = '{https://admin-shell.io/aas/3/0}dataSpecificationIec61360') _Element
Serialization of objects of class
DataSpecificationIEC61360to XML- Parameters:
obj – Object of class
DataSpecificationIEC61360tag – Namespace+Tag of the ElementTree object. Default is
aas:dataSpecificationIec61360
- Returns:
Serialized
_Elementobject
- embedded_data_specification_to_xml(obj: EmbeddedDataSpecification, tag: str = '{https://admin-shell.io/aas/3/0}embeddedDataSpecification') _Element
Serialization of objects of class
EmbeddedDataSpecificationto XML- Parameters:
obj – Object of class
EmbeddedDataSpecificationtag – Namespace+Tag of the ElementTree object. Default is
aas:embeddedDataSpecification
- Returns:
Serialized
_Elementobject
- entity_to_xml(obj: Entity, tag: str = '{https://admin-shell.io/aas/3/0}entity') _Element
Serialization of objects of class
Entityto XML
- extension_to_xml(obj: Extension, tag: str = '{https://admin-shell.io/aas/3/0}extension') _Element
Serialization of objects of class
Extensionto XML
- file_to_xml(obj: File, tag: str = '{https://admin-shell.io/aas/3/0}file') _Element
Serialization of objects of class
Fileto XML
- key_to_xml(obj: Key, tag: str = '{https://admin-shell.io/aas/3/0}key') _Element
Serialization of objects of class
Keyto XML
- lang_string_set_to_xml(obj: LangStringSet, tag: str) _Element
Serialization of objects of class
LangStringSetto XML- Parameters:
obj – Object of class
LangStringSettag – Namespace+Tag name of the returned XML element.
- Returns:
Serialized
_Elementobject
- multi_language_property_to_xml(obj: MultiLanguageProperty, tag: str = '{https://admin-shell.io/aas/3/0}multiLanguageProperty') _Element
Serialization of objects of class
MultiLanguagePropertyto XML- Parameters:
obj – Object of class
MultiLanguagePropertytag – Namespace+Tag of the serialized element (optional). Default is
aas:multiLanguageProperty
- Returns:
Serialized
_Elementobject
- object_store_to_xml_element(data: AbstractObjectStore) _Element
Serialize a set of AAS objects to an Asset Administration Shell as
_Element. This function is used internally bywrite_aas_xml_file()and shouldn’t be called directly for most use-cases.- Parameters:
data –
ObjectStorewhich contains different objects of the AAS meta model which should be serialized to an XML file
- object_to_xml_element(obj: object) _Element
Serialize a single object to an
_Element.- Parameters:
obj – The object to serialize
- operation_to_xml(obj: Operation, tag: str = '{https://admin-shell.io/aas/3/0}operation') _Element
Serialization of objects of class
Operationto XML
- operation_variable_to_xml(obj: SubmodelElement, tag: str = '{https://admin-shell.io/aas/3/0}operationVariable') _Element
Serialization of
SubmodelElementto the XML OperationVariable representation Since we don’t implement theOperationVariableclass, which is just a wrapper for a singleSubmodelElement, elements are serialized as theaas:valuechild of anaas:operationVariableelement.- Parameters:
obj – Object of class
SubmodelElementtag – Namespace+Tag of the serialized element (optional). Default is
aas:operationVariable
- Returns:
Serialized
_Elementobject
- property_to_xml(obj: Property, tag: str = '{https://admin-shell.io/aas/3/0}property') _Element
Serialization of objects of class
Propertyto XML
- qualifier_to_xml(obj: Qualifier, tag: str = '{https://admin-shell.io/aas/3/0}qualifier') _Element
Serialization of objects of class
Qualifierto XML
- range_to_xml(obj: Range, tag: str = '{https://admin-shell.io/aas/3/0}range') _Element
Serialization of objects of class
Rangeto XML
- reference_element_to_xml(obj: ReferenceElement, tag: str = '{https://admin-shell.io/aas/3/0}referenceElement') _Element
Serialization of objects of class
ReferenceElementto XMl- Parameters:
obj – Object of class
ReferenceElementtag – Namespace+Tag of the serialized element (optional). Default is
aas:referenceElement
- Returns:
Serialized
_Elementobject
- reference_to_xml(obj: Reference, tag: str = '{https://admin-shell.io/aas/3/0}reference') _Element
Serialization of objects of class
Referenceto XML
- relationship_element_to_xml(obj: RelationshipElement, tag: str = '{https://admin-shell.io/aas/3/0}relationshipElement') _Element
Serialization of objects of class
RelationshipElementto XML- Parameters:
obj – Object of class
RelationshipElementtag – Namespace+Tag of the serialized element (optional). Default is
aas:relationshipElement
- Returns:
Serialized
_Elementobject
- resource_to_xml(obj: Resource, tag: str = '{https://admin-shell.io/aas/3/0}resource') _Element
Serialization of objects of class
Resourceto XML
- specific_asset_id_to_xml(obj: SpecificAssetId, tag: str = '{https://admin-shell.io/aas/3/0}specifidAssetId') _Element
Serialization of objects of class
SpecificAssetIdto XML- Parameters:
obj – Object of class
SpecificAssetIdtag – Namespace+Tag of the ElementTree object. Default is
aas:identifierKeyValuePair
- Returns:
Serialized
_Elementobject
- submodel_element_collection_to_xml(obj: SubmodelElementCollection, tag: str = '{https://admin-shell.io/aas/3/0}submodelElementCollection') _Element
Serialization of objects of class
SubmodelElementCollectionto XML- Parameters:
obj – Object of class
SubmodelElementCollectiontag – Namespace+Tag of the serialized element (optional). Default is
aas:submodelElementCollection
- Returns:
Serialized
_Elementobject
- submodel_element_list_to_xml(obj: SubmodelElementList, tag: str = '{https://admin-shell.io/aas/3/0}submodelElementList') _Element
Serialization of objects of class
SubmodelElementListto XML- Parameters:
obj – Object of class
SubmodelElementListtag – Namespace+Tag of the serialized element (optional). Default is
aas:submodelElementList
- Returns:
Serialized
_Elementobject
- submodel_element_to_xml(obj: SubmodelElement) _Element
Serialization of objects of class
SubmodelElementto XML- Parameters:
obj – Object of class
SubmodelElement- Returns:
Serialized
_Elementobject
- submodel_to_xml(obj: Submodel, tag: str = '{https://admin-shell.io/aas/3/0}submodel') _Element
Serialization of objects of class
Submodelto XML
- value_list_to_xml(obj: Set[ValueReferencePair], tag: str = '{https://admin-shell.io/aas/3/0}valueList') _Element
Serialization of objects of class
ValueListto XMLtodo: couldn’t find it in the official schema, so guessing how to implement serialization
- value_reference_pair_to_xml(obj: ValueReferencePair, tag: str = '{https://admin-shell.io/aas/3/0}valueReferencePair') _Element
Serialization of objects of class
ValueReferencePairto XML- Parameters:
obj – Object of class
ValueReferencePairtag – Namespace+Tag of the serialized element. Default is
aas:valueReferencePair
- Returns:
Serialized
_Elementobject
- write_aas_xml_element(file: str | bytes | PathLike | BinaryIO, obj: object, **kwargs) None
Serialize a single object to XML. Namespace declarations are added to the object itself, as there is no surrounding environment element.
- Parameters:
file – A filename or file-like object to write the XML-serialized data to
obj – The object to serialize
kwargs – Additional keyword arguments to be passed to
write()
- write_aas_xml_file(file: str | bytes | PathLike | BinaryIO, data: AbstractObjectStore, **kwargs) None
Write a set of AAS objects to an Asset Administration Shell XML file according to ‘Details of the Asset Administration Shell’, chapter 5.4
- Parameters:
file – A filename or file-like object to write the XML-serialized data to
data –
ObjectStorewhich contains different objects of the AAS meta model which should be serialized to an XML filekwargs – Additional keyword arguments to be passed to
write()
3.2.2. xml.xml_deserialization - Deserialization from XML to AAS-objects
Module for deserializing Asset Administration Shell data from the official XML format
This module provides the following functions for parsing XML documents:
read_aas_xml_element()constructs a single object from an XML document containing a single elementread_aas_xml_file_into()constructs all elements of an XML document and stores them in a givenObjectStoreread_aas_xml_file()constructs all elements of an XML document and returns them in aDictObjectStore
These functions take a decoder class as keyword argument, which allows parsing in failsafe (default) or non-failsafe mode. Parsing stripped elements - used in the HTTP adapter - is also possible. It is also possible to subclass the default decoder class and provide an own decoder.
In failsafe mode errors regarding missing attributes and elements or invalid values are caught and logged.
In non-failsafe mode any error would abort parsing.
Error handling is done only by _failsafe_construct() in this module. Nearly all constructor functions are called
by other constructor functions via _failsafe_construct(), so an error chain is constructed in the error case,
which allows printing stacktrace-like error messages like the following in the error case (in failsafe mode of course):
KeyError: aas:id on line 252 has no attribute with name idType!
-> Failed to construct aas:id on line 252 using construct_identifier!
-> Failed to construct aas:conceptDescription on line 247 using construct_concept_description!
Unlike the JSON deserialization, parsing is done top-down. Elements with a specific tag are searched on the level directly below the level of the current xml element (in terms of parent and child relation) and parsed when found. Constructor functions of these elements will then again search for mandatory and optional child elements and construct them if available, and so on.
- class AASFromXmlDecoder
The default XML decoder class.
It parses XML documents in a failsafe manner, meaning any errors encountered will be logged and invalid XML elements will be skipped. Most member functions support the
object_classparameter. It was introduced so they can be overwritten in subclasses, which allows constructing instances of subtypes.- classmethod construct_administrative_information(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.base.AdministrativeInformation'>, **_kwargs: ~typing.Any) AdministrativeInformation
- classmethod construct_annotated_relationship_element(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.submodel.AnnotatedRelationshipElement'>, **_kwargs: ~typing.Any) AnnotatedRelationshipElement
- classmethod construct_asset_administration_shell(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.aas.AssetAdministrationShell'>, **_kwargs: ~typing.Any) AssetAdministrationShell
- classmethod construct_asset_information(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.aas.AssetInformation'>, **_kwargs: ~typing.Any) AssetInformation
- classmethod construct_basic_event_element(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.submodel.BasicEventElement'>, **_kwargs: ~typing.Any) BasicEventElement
- classmethod construct_blob(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.submodel.Blob'>, **_kwargs: ~typing.Any) Blob
- classmethod construct_capability(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.submodel.Capability'>, **_kwargs: ~typing.Any) Capability
- classmethod construct_concept_description(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.concept.ConceptDescription'>, **_kwargs: ~typing.Any) ConceptDescription
- classmethod construct_data_element(element: _Element, abstract_class_name: str = 'DataElement', **kwargs: Any) DataElement
This function does not support the object_class parameter. Overwrite each individual DataElement constructor function instead.
- classmethod construct_data_specification_content(element: _Element, **kwargs: Any) DataSpecificationContent
This function doesn’t support the object_class parameter. Overwrite each individual DataSpecificationContent constructor function instead.
- classmethod construct_data_specification_iec61360(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.base.DataSpecificationIEC61360'>, **_kwargs: ~typing.Any) DataSpecificationIEC61360
- classmethod construct_definition_type_iec61360(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.base.DefinitionTypeIEC61360'>, **kwargs: ~typing.Any) DefinitionTypeIEC61360
- classmethod construct_embedded_data_specification(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.base.EmbeddedDataSpecification'>, **_kwargs: ~typing.Any) EmbeddedDataSpecification
- classmethod construct_entity(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.submodel.Entity'>, **_kwargs: ~typing.Any) Entity
- classmethod construct_extension(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.base.Extension'>, **_kwargs: ~typing.Any) Extension
- classmethod construct_external_reference(element: ~lxml.etree._Element, namespace: str = '{https://admin-shell.io/aas/3/0}', object_class=<class 'basyx.aas.model.base.ExternalReference'>, **_kwargs: ~typing.Any) ExternalReference
- classmethod construct_file(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.submodel.File'>, **_kwargs: ~typing.Any) File
- classmethod construct_key(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.base.Key'>, **_kwargs: ~typing.Any) Key
- classmethod construct_lang_string_set(element: _Element, expected_tag: str, object_class: Type[LSS], **_kwargs: Any) LSS
- classmethod construct_model_reference(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.base.ModelReference'>, **_kwargs: ~typing.Any) ModelReference
This constructor for ModelReference determines the type of the ModelReference by its keys. If no keys are present, it will default to the type Referable. This behaviour is wanted in read_aas_xml_element().
- classmethod construct_model_reference_expect_type(element: ~lxml.etree._Element, type_: ~typing.Type[~basyx.aas.model.base._RT], object_class=<class 'basyx.aas.model.base.ModelReference'>, **_kwargs: ~typing.Any) ModelReference[_RT]
This constructor for ModelReference allows passing an expected type, which is checked against the type of the last key of the reference. This constructor function is used by other constructor functions, since all expect a specific target type.
- classmethod construct_multi_language_name_type(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.base.MultiLanguageNameType'>, **kwargs: ~typing.Any) MultiLanguageNameType
- classmethod construct_multi_language_property(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.submodel.MultiLanguageProperty'>, **_kwargs: ~typing.Any) MultiLanguageProperty
- classmethod construct_multi_language_text_type(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.base.MultiLanguageTextType'>, **kwargs: ~typing.Any) MultiLanguageTextType
- classmethod construct_operation(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.submodel.Operation'>, **_kwargs: ~typing.Any) Operation
- classmethod construct_preferred_name_type_iec61360(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.base.PreferredNameTypeIEC61360'>, **kwargs: ~typing.Any) PreferredNameTypeIEC61360
- classmethod construct_property(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.submodel.Property'>, **_kwargs: ~typing.Any) Property
- classmethod construct_qualifier(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.base.Qualifier'>, **_kwargs: ~typing.Any) Qualifier
- classmethod construct_range(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.submodel.Range'>, **_kwargs: ~typing.Any) Range
- classmethod construct_reference(element: _Element, namespace: str = '{https://admin-shell.io/aas/3/0}', **kwargs: Any) Reference
- classmethod construct_reference_element(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.submodel.ReferenceElement'>, **_kwargs: ~typing.Any) ReferenceElement
- classmethod construct_relationship_element(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.submodel.RelationshipElement'>, **_kwargs: ~typing.Any) RelationshipElement
- classmethod construct_resource(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.base.Resource'>, **_kwargs: ~typing.Any) Resource
- classmethod construct_short_name_type_iec61360(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.base.ShortNameTypeIEC61360'>, **kwargs: ~typing.Any) ShortNameTypeIEC61360
- classmethod construct_specific_asset_id(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.base.SpecificAssetId'>, **_kwargs: ~typing.Any) SpecificAssetId
- classmethod construct_submodel(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.submodel.Submodel'>, **_kwargs: ~typing.Any) Submodel
- classmethod construct_submodel_element(element: _Element, **kwargs: Any) SubmodelElement
This function doesn’t support the object_class parameter. Overwrite each individual SubmodelElement/DataElement constructor function instead.
- classmethod construct_submodel_element_collection(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.submodel.SubmodelElementCollection'>, **_kwargs: ~typing.Any) SubmodelElementCollection
- classmethod construct_submodel_element_list(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.submodel.SubmodelElementList'>, **_kwargs: ~typing.Any) SubmodelElementList
- classmethod construct_value_list(element: _Element, **_kwargs: Any) Set[ValueReferencePair]
This function doesn’t support the object_class parameter, because ValueList is just a generic type alias.
- classmethod construct_value_reference_pair(element: ~lxml.etree._Element, object_class=<class 'basyx.aas.model.base.ValueReferencePair'>, **_kwargs: ~typing.Any) ValueReferencePair
- failsafe = True
- stripped = False
- class StrictAASFromXmlDecoder
Non-failsafe XML decoder. Encountered errors won’t be caught and abort parsing.
- failsafe = False
- class StrictStrippedAASFromXmlDecoder
Non-failsafe decoder for stripped XML elements.
- class StrippedAASFromXmlDecoder
Decoder for stripped XML elements. Used in the HTTP adapter.
- stripped = True
- class XMLConstructables(value)
This enum is used to specify which type to construct in read_aas_xml_element().
- ADMINISTRATIVE_INFORMATION = 5
- ANNOTATED_RELATIONSHIP_ELEMENT = 8
- ASSET_ADMINISTRATION_SHELL = 24
- ASSET_INFORMATION = 25
- BASIC_EVENT_ELEMENT = 9
- BLOB = 10
- CAPABILITY = 11
- CONCEPT_DESCRIPTION = 30
- DATA_ELEMENT = 31
- DATA_SPECIFICATION_CONTENT = 40
- DATA_SPECIFICATION_IEC61360 = 41
- DEFINITION_TYPE_IEC61360 = 36
- EMBEDDED_DATA_SPECIFICATION = 39
- ENTITY = 12
- EXTENSION = 13
- EXTERNAL_REFERENCE = 4
- FILE = 14
- IEC61360_CONCEPT_DESCRIPTION = 29
- KEY = 1
- MODEL_REFERENCE = 3
- MULTI_LANGUAGE_NAME_TYPE = 34
- MULTI_LANGUAGE_PROPERTY = 16
- MULTI_LANGUAGE_TEXT_TYPE = 35
- OPERATION = 17
- PREFERRED_NAME_TYPE_IEC61360 = 37
- PROPERTY = 18
- QUALIFIER = 6
- RANGE = 19
- REFERENCE = 2
- REFERENCE_ELEMENT = 20
- RELATIONSHIP_ELEMENT = 21
- RESOURCE = 15
- SECURITY = 7
- SHORT_NAME_TYPE_IEC61360 = 38
- SPECIFIC_ASSET_ID = 26
- SUBMODEL = 27
- SUBMODEL_ELEMENT = 32
- SUBMODEL_ELEMENT_COLLECTION = 22
- SUBMODEL_ELEMENT_LIST = 23
- VALUE_LIST = 33
- VALUE_REFERENCE_PAIR = 28
- read_aas_xml_element(file: str | bytes | PathLike | IO, construct: XMLConstructables, failsafe: bool = True, stripped: bool = False, decoder: Type[AASFromXmlDecoder] | None = None, **constructor_kwargs) object | None
Construct a single object from an XML string. The namespaces have to be declared on the object itself, since there is no surrounding environment element.
- Parameters:
file – A filename or file-like object to read the XML-serialized data from
construct – A member of the enum
XMLConstructables, specifying which type to construct.failsafe – If true, the document is parsed in a failsafe way: missing attributes and elements are logged instead of causing exceptions. Defect objects are skipped. This parameter is ignored if a decoder class is specified.
stripped – If true, stripped XML elements are parsed. See https://git.rwth-aachen.de/acplt/pyi40aas/-/issues/91 This parameter is ignored if a decoder class is specified.
decoder – The decoder class used to decode the XML elements
constructor_kwargs – Keyword arguments passed to the constructor function
- Raises:
XMLSyntaxError – Non-failsafe: If the given file(-handle) has invalid XML
KeyError – Non-failsafe: If a required namespace has not been declared on the XML document
(AASConstraintViolation, KeyError, ValueError) – Non-failsafe: Errors during construction of the objects
- Returns:
The constructed object or None, if an error occurred in failsafe mode.
- read_aas_xml_file(file: str | bytes | PathLike | IO, **kwargs: Any) DictObjectStore[Identifiable]
A wrapper of
read_aas_xml_file_into(), that reads all objects in an emptyDictObjectStore. This function supports the same keyword arguments asread_aas_xml_file_into().- Parameters:
file – A filename or file-like object to read the XML-serialized data from
kwargs – Keyword arguments passed to
read_aas_xml_file_into()
- Raises:
XMLSyntaxError – Non-failsafe: If the given file(-handle) has invalid XML
KeyError – Non-failsafe: If a required namespace has not been declared on the XML document
KeyError – Non-failsafe: Encountered a duplicate identifier
(AASConstraintViolation, KeyError, ValueError) – Non-failsafe: Errors during construction of the objects
TypeError – Non-failsafe: Encountered an undefined top-level list (e.g.
<aas:submodels1>)
- Returns:
A
DictObjectStorecontaining all AAS objects from the XML file
- read_aas_xml_file_into(object_store: AbstractObjectStore[Identifiable], file: str | bytes | PathLike | IO, replace_existing: bool = False, ignore_existing: bool = False, failsafe: bool = True, stripped: bool = False, decoder: Type[AASFromXmlDecoder] | None = None, **parser_kwargs: Any) Set[str]
Read an Asset Administration Shell XML file according to ‘Details of the Asset Administration Shell’, chapter 5.4 into a given
ObjectStore.- Parameters:
object_store – The
ObjectStorein which theIdentifiableobjects should be storedfile – A filename or file-like object to read the XML-serialized data from
replace_existing – Whether to replace existing objects with the same identifier in the object store or not
ignore_existing – Whether to ignore existing objects (e.g. log a message) or raise an error. This parameter is ignored if replace_existing is True.
failsafe – If
True, the document is parsed in a failsafe way: missing attributes and elements are logged instead of causing exceptions. Defect objects are skipped. This parameter is ignored if a decoder class is specified.stripped – If
True, stripped XML elements are parsed. See https://git.rwth-aachen.de/acplt/pyi40aas/-/issues/91 This parameter is ignored if a decoder class is specified.decoder – The decoder class used to decode the XML elements
parser_kwargs – Keyword arguments passed to the XMLParser constructor
- Raises:
XMLSyntaxError – Non-failsafe: If the given file(-handle) has invalid XML
KeyError – Non-failsafe: If a required namespace has not been declared on the XML document
KeyError – Non-failsafe: Encountered a duplicate identifier
KeyError – Encountered an identifier that already exists in the given
object_storewith bothreplace_existingandignore_existingset toFalse(AASConstraintViolation, KeyError, ValueError) – Non-failsafe: Errors during construction of the objects
TypeError – Non-failsafe: Encountered an undefined top-level list (e.g.
<aas:submodels1>)
- Returns:
A set of
Identifiersthat were added to object_store
- class LSS
alias of TypeVar(‘LSS’, bound=
LangStringSet)