2121from .exceptions import odxraise , odxrequire
2222from .nameditemlist import NamedItemList
2323from .odxdoccontext import OdxDocContext
24- from .odxlink import OdxLinkDatabase , OdxLinkId
24+ from .odxlink import DocType , OdxDocFragment , OdxLinkDatabase , OdxLinkId
2525from .snrefcontext import SnRefContext
2626
2727
@@ -77,10 +77,6 @@ def add_auxiliary_file(self,
7777 self .auxiliary_files [str (aux_file_name )] = aux_file_obj
7878
7979 def _process_xml_tree (self , root : ElementTree .Element ) -> None :
80- dlcs : list [DiagLayerContainer ] = []
81- comparam_subsets : list [ComparamSubset ] = []
82- comparam_specs : list [ComparamSpec ] = []
83-
8480 # ODX spec version
8581 model_version = Version (root .attrib .get ("MODEL-VERSION" , "2.0" ))
8682 if self .model_version is not None and self .model_version != model_version :
@@ -89,31 +85,33 @@ def _process_xml_tree(self, root: ElementTree.Element) -> None:
8985
9086 self .model_version = model_version
9187
92- dlc = root .find ("DIAG-LAYER-CONTAINER" )
93- if dlc is not None :
94- dlcs .append (DiagLayerContainer .from_et (dlc , OdxDocContext (model_version , [])))
95-
96- # In ODX 2.0 there was only COMPARAM-SPEC. In ODX 2.2 the
97- # content of COMPARAM-SPEC was moved to COMPARAM-SUBSET
98- # and COMPARAM-SPEC became a container for PROT-STACKS and
99- # a PROT-STACK references a list of COMPARAM-SUBSET
100- cp_subset = root .find ("COMPARAM-SUBSET" )
101- if cp_subset is not None :
102- comparam_subsets .append (
103- ComparamSubset .from_et (cp_subset , OdxDocContext (model_version , [])))
104-
105- cp_spec = root .find ("COMPARAM-SPEC" )
106- if cp_spec is not None :
88+ child_elements = list (root )
89+ if len (child_elements ) != 1 :
90+ odxraise ("Each ODX document must contain exactly one category." )
91+
92+ category_et = child_elements [0 ]
93+ category_sn = odxrequire (category_et .findtext ("SHORT-NAME" ))
94+ category_tag = category_et .tag
95+
96+ if category_tag == "DIAG-LAYER-CONTAINER" :
97+ context = OdxDocContext (model_version ,
98+ (OdxDocFragment (category_sn , DocType .CONTAINER ),))
99+ self ._diag_layer_containers .append (DiagLayerContainer .from_et (category_et , context ))
100+ elif category_tag == "COMPARAM-SUBSET" :
101+ context = OdxDocContext (model_version ,
102+ (OdxDocFragment (category_sn , DocType .COMPARAM_SUBSET ),))
103+ self ._comparam_subsets .append (ComparamSubset .from_et (category_et , context ))
104+ elif category_tag == "COMPARAM-SPEC" :
105+ # In ODX 2.0 there was only COMPARAM-SPEC. In ODX 2.2 the
106+ # content of COMPARAM-SPEC was moved to COMPARAM-SUBSET
107+ # and COMPARAM-SPEC became a container for PROT-STACKS and
108+ # a PROT-STACK references a list of COMPARAM-SUBSET
109+ context = OdxDocContext (model_version ,
110+ (OdxDocFragment (category_sn , DocType .COMPARAM_SPEC ),))
107111 if model_version < Version ("2.2" ):
108- comparam_subsets .append (
109- ComparamSubset .from_et (cp_spec , OdxDocContext (model_version , [])))
110- else : # odx >= 2.2
111- comparam_specs .append (
112- ComparamSpec .from_et (cp_spec , OdxDocContext (model_version , [])))
113-
114- self ._diag_layer_containers .extend (dlcs )
115- self ._comparam_subsets .extend (comparam_subsets )
116- self ._comparam_specs .extend (comparam_specs )
112+ self ._comparam_subsets .append (ComparamSubset .from_et (category_et , context ))
113+ else :
114+ self ._comparam_specs .append (ComparamSpec .from_et (category_et , context ))
117115
118116 def refresh (self ) -> None :
119117 # Create wrapper objects
0 commit comments