Skip to content

Commit

Permalink
adapter.xml: improve element formatting in error messages
Browse files Browse the repository at this point in the history
Previously, the namespace of an element would always be replaced by its
prefix if the prefix is known. However, this turned out to mask errors
in case the namespace is different from the one used by our SDK.
Thus, the function `_element_pretty_identifier()` is adjusted such that
it only replaces the namespace if it matches one of the namespaces known
to our SDK.

Partially fix #190
See also: 79a8635
  • Loading branch information
jkhsjdhjs authored and s-heppner committed Dec 19, 2023
1 parent ae4a768 commit 6f3480a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions basyx/aas/adapter/xml/xml_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _element_pretty_identifier(element: etree.Element) -> str:
Returns a pretty element identifier for a given XML element.
If the prefix is known, the namespace in the element tag is replaced by the prefix.
If additionally also the sourceline is known, is is added as a suffix to name.
If additionally also the sourceline is known, it is added as a suffix to name.
For example, instead of "{https://admin-shell.io/aas/3/0}assetAdministrationShell" this function would return
"aas:assetAdministrationShell on line $line", if both, prefix and sourceline, are known.
Expand All @@ -107,7 +107,11 @@ def _element_pretty_identifier(element: etree.Element) -> str:
"""
identifier = element.tag
if element.prefix is not None:
identifier = element.prefix + ":" + element.tag.split("}")[1]
# Only replace the namespace by the prefix if it matches our known namespaces,
# so the replacement by the prefix doesn't mask errors such as incorrect namespaces.
namespace, tag = element.tag.split("}", 1)
if namespace[1:] in XML_NS_MAP.values():
identifier = element.prefix + ":" + tag
if element.sourceline is not None:
identifier += f" on line {element.sourceline}"
return identifier
Expand Down

0 comments on commit 6f3480a

Please sign in to comment.