Search code examples
xmlxsdpython-3.8autosar

Why is xsData dropping XML element attributes when parsing .arxml?


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"})

Solution

  • 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