@@ -76,7 +76,7 @@ export function getCdcValueFromDOIElement(doiElement: Element): string | null {
76
76
}
77
77
78
78
export function getCdcValueFromDOElement ( doElement : Element ) : string | null {
79
- const doType = doElement . getAttribute ( 'type' ) ;
79
+ const doType = getTypeAttribute ( doElement ) ;
80
80
const doTypeElement = doElement . ownerDocument . querySelector (
81
81
`DOType[id="${ doType } "]`
82
82
) ;
@@ -124,6 +124,16 @@ export function get104DetailsLine(
124
124
. join ( ', ' ) ;
125
125
}
126
126
127
+ /**
128
+ * Extract the 'type' attribute from the given XML element.
129
+ * @param element - The element to extract instance from.
130
+ * @returns the value, or undefined if there is no instance.
131
+ */
132
+ export function getTypeAttribute ( element : Element ) : string | undefined {
133
+ const type = element . getAttribute ( 'type' ) ;
134
+ return type ? type : undefined ;
135
+ }
136
+
127
137
/**
128
138
* Search for a DAI Element below the passed DOI Element.
129
139
*
@@ -132,7 +142,7 @@ export function get104DetailsLine(
132
142
* @returns The found DA Element or null, if not found.
133
143
*/
134
144
export function getDaElement ( doElement : Element , name : string ) : Element | null {
135
- const doType = doElement . getAttribute ( 'type' ) ;
145
+ const doType = getTypeAttribute ( doElement ) ;
136
146
if ( doType ) {
137
147
return doElement . ownerDocument . querySelector (
138
148
`DOType[id="${ doType } "] > DA[name="${ name } "]`
@@ -288,7 +298,7 @@ function buildTemplateChainFromInstanceElements(
288
298
templateChain . push ( doElement ) ;
289
299
290
300
// For the next element search the DOType that is linked to the DO Element.
291
- const typeId = doElement . getAttribute ( 'type' ) ?? '' ;
301
+ const typeId = getTypeAttribute ( doElement ) ?? '' ;
292
302
typeElement = doc . querySelector ( `DOType[id="${ typeId } "]` ) ;
293
303
} else {
294
304
typeElement = null ;
@@ -306,7 +316,7 @@ function buildTemplateChainFromInstanceElements(
306
316
307
317
if ( daElement . getAttribute ( 'bType' ) === 'Struct' ) {
308
318
// Only if the bType is a struct we need to search for the DAType for the next element.
309
- const typeId = element . getAttribute ( 'type' ) ?? '' ;
319
+ const typeId = getTypeAttribute ( element ) ?? '' ;
310
320
typeElement = doc . querySelector ( `DAType[id="${ typeId } "]` ) ;
311
321
} else {
312
322
typeElement = null ;
@@ -373,7 +383,7 @@ export function isEnumDataAttribute(daiElement: Element): boolean {
373
383
export function getEnumVal ( daiElement : Element , ord : string ) : string | null {
374
384
const daElement = getDaElementByDaiElement ( daiElement ) ;
375
385
if ( isEnumType ( daElement ) ) {
376
- const enumType = daElement ! . getAttribute ( 'type' ) ;
386
+ const enumType = getTypeAttribute ( daElement ! ) ;
377
387
const enumVal = daiElement . ownerDocument . querySelector (
378
388
`EnumType[id="${ enumType } "] > EnumVal[ord="${ ord } "]`
379
389
) ;
@@ -393,7 +403,7 @@ export function getEnumOrds(daiElement: Element): string[] {
393
403
const ords : string [ ] = [ ] ;
394
404
const daElement = getDaElementByDaiElement ( daiElement ) ;
395
405
if ( isEnumType ( daElement ) ) {
396
- const enumType = daElement ! . getAttribute ( 'type' ) ;
406
+ const enumType = getTypeAttribute ( daElement ! ) ;
397
407
const enumVals = daiElement . ownerDocument . querySelectorAll (
398
408
`EnumType[id="${ enumType } "] > EnumVal`
399
409
) ;
0 commit comments