1

I am working with large xml files called .arxml, the schema for which can be seen here. When I parse an .arxml file and then serialize to a new file and compare the input and output, all UUID attributes are dropped. For example, the element

<AR-PACKAGE UUID="9cf6b2b6-a372-4379-a9c8-221de5abe4e1-ECUSystem">

is reduced to

<AR-PACKAGE>

Why is this? The UUID attributes might not be specified as mandatory in the xsd, but should they be dropped if they aren't? Examples of elements that lose their UUID elements are AR-PACKAGE, ECU-INSTANCE, SDG, SD, COUPLING-PORT.

Below are the steps that I have taken to arrive at my current problem.

xsdata "C:\<path_to_file>\AUTOSAR_4-2-2.xsd" --package autosar_classes

Followed by running the below python script

from pathlib import Path
from xsdata.formats.dataclass.parsers import XmlParser
from xsdata.formats.dataclass.serializers import XmlSerializer
from xsdata.formats.dataclass.serializers.config import SerializerConfig
import autosar_classes as ac

parser = XmlParser()
root = parser.from_path(Path("sample.arxml"), ac.Autosar)

serializer_config = SerializerConfig(pretty_print=True)
serializer = XmlSerializer(serializer_config)

path = Path("modified.arxml")
with path.open("w") as fp:
    serializer.write(fp, root, ns_map={"": "http://autosar.org/schema/r4.0"})
Magnus
  • 11
  • 4
  • Can you print the UUID for an element parsed by XmlParser? Just to make sure it is the serializer's issue. – Adam Horvath Aug 31 '22 at 14:36
  • No, I can't. I've combed through the objects in `root` that should contain a UUID, and they do not. So I suppose that the issue lies within the XmlParser as you say. – Magnus Aug 31 '22 at 19:40

2 Answers2

0

UUID does not have a semantic meaning and therefore AUTOSAR Tools are not required to load or persist it.

I haven't processed ARXML with Python yet but I assume there is an option to persist UUID or drop it.

If you are creating a new ARXML file from an input file(s) then you shouldn't even care about carrying over the UUID.

Adam Horvath
  • 1,249
  • 1
  • 10
  • 25
  • „UUID does not have a semantic meaning and therefore AUTOSAR Tools are not required to load or persist it.“ It is encouraged that AUTOSAR tools keep the UUIDs to enable round-trip-scenarios between different AUTOSAR tools. – Uwe Honekamp Aug 31 '22 at 10:42
  • Yes, I would also assume that there would be an option to provide to the parser that preserves all attributes, but if there is I can't find it. I am modifying existing files with elements that already have UUID attributes, and I want to keep them. – Magnus Aug 31 '22 at 10:51
  • @Magnus so are you updating a file's content and not creating a new one? That explains why you want to keep them unchanged. – Adam Horvath Aug 31 '22 at 12:06
  • @UweHonekamp in his case I think its not a good idea; if "sample.arxml" and "modified.arxml" gets loaded alongside in the same authoring tool that cares about UUIDs, then it could raise a warning for two different elements having the same UUID. I always thought of UUID as something completely unique assigned to XML element at time of introduction and never to be carried over to other archives. – Adam Horvath Aug 31 '22 at 12:17
  • @AdamHorvath, the UUID has been introduced to AUTOSAR for one (and only one purpose): round-trips. And BTW, two model elements having the same UUID should (by virtue of being a proper UUID) be an extremely rare condition. – Uwe Honekamp Aug 31 '22 at 18:16
0

I created an issue in the github repository of xsData, and it appears to have been a bug that caused the dropping of some attributes. The maintainer responded promptly and the fix is now on master.

https://github.com/tefra/xsdata/issues/701

Magnus
  • 11
  • 4