@@ -1214,6 +1214,29 @@ const ARRAY_ELEMENTS = new Set([
12141214 'operationVariable' ,
12151215] ) ;
12161216
1217+ function parseDataTypeDefXsd ( dataType : unknown ) : DataTypeDefXsd | undefined {
1218+ if ( dataType === undefined || dataType === null || dataType === '' ) {
1219+ return undefined ;
1220+ }
1221+
1222+ if ( typeof dataType !== 'string' || ! dataType . startsWith ( 'xs:' ) ) {
1223+ throw new Error ( `Invalid literal of DataTypeDefXsd: ${ String ( dataType ) } ` ) ;
1224+ }
1225+
1226+ const result = jsonization . dataTypeDefXsdFromJsonable ( dataType ) ;
1227+ if ( result . error !== null || result . value === null ) {
1228+ const errorMessage =
1229+ typeof result . error === 'string'
1230+ ? result . error
1231+ : typeof ( result . error as any ) ?. message === 'string'
1232+ ? ( result . error as any ) . message
1233+ : `Invalid literal of DataTypeDefXsd: ${ dataType } ` ;
1234+ throw new Error ( errorMessage ) ;
1235+ }
1236+
1237+ return result . value ;
1238+ }
1239+
12171240function parseAssetAdministrationShell ( data : any ) : AssetAdministrationShell {
12181241 return new AssetAdministrationShell (
12191242 data . id ,
@@ -1237,15 +1260,7 @@ function parseAssetAdministrationShell(data: any): AssetAdministrationShell {
12371260}
12381261
12391262function parseExtension ( data : any ) : Extension {
1240- // Map XML valueType string to DataTypeDefXsd enum
1241- let valueType = data . valueType || undefined ;
1242- if ( valueType && typeof valueType === 'string' && valueType . startsWith ( 'xs:' ) ) {
1243- // Extract the type after 'xs:' prefix and map to enum
1244- const typeValue = valueType . substring ( 3 ) ;
1245- const capitalizedType = typeValue . charAt ( 0 ) . toUpperCase ( ) + typeValue . slice ( 1 ) ;
1246- // Map string to DataTypeDefXsd enum value
1247- valueType = ( DataTypeDefXsd as any ) [ capitalizedType ] ;
1248- }
1263+ const valueType = parseDataTypeDefXsd ( data . valueType ) ;
12491264
12501265 return new Extension (
12511266 data . name ,
@@ -1451,15 +1466,7 @@ function parseSubmodel(data: any): Submodel {
14511466}
14521467
14531468function parseQualifier ( data : any ) : Qualifier {
1454- // Map XML valueType string to DataTypeDefXsd enum
1455- let valueType = data . valueType || undefined ;
1456- if ( valueType && typeof valueType === 'string' ) {
1457- // Convert string to enum value using jsonization (expects xs: prefix)
1458- const result = jsonization . dataTypeDefXsdFromJsonable ( valueType ) ;
1459- if ( result . error === null && result . value !== null ) {
1460- valueType = result . value ;
1461- }
1462- }
1469+ const valueType = parseDataTypeDefXsd ( data . valueType ) ;
14631470
14641471 return new Qualifier (
14651472 data . type ,
@@ -1506,15 +1513,7 @@ function parseSubmodelElements(data: any): any[] {
15061513}
15071514
15081515function parseProperty ( data : any ) : Property {
1509- // Map XML valueType string to DataTypeDefXsd enum
1510- let valueType = data . valueType || undefined ;
1511- if ( valueType && typeof valueType === 'string' ) {
1512- // Convert string to enum value using jsonization (expects xs: prefix)
1513- const result = jsonization . dataTypeDefXsdFromJsonable ( valueType ) ;
1514- if ( result . error === null && result . value !== null ) {
1515- valueType = result . value ;
1516- }
1517- }
1516+ const valueType = parseDataTypeDefXsd ( data . valueType ) ;
15181517
15191518 return new Property (
15201519 valueType as DataTypeDefXsd ,
@@ -1565,15 +1564,7 @@ function parseMultiLanguageProperty(data: any): MultiLanguageProperty {
15651564}
15661565
15671566function parseRange ( data : any ) : Range {
1568- // Map XML valueType string to DataTypeDefXsd enum
1569- let valueType = data . valueType || undefined ;
1570- if ( valueType && typeof valueType === 'string' ) {
1571- // Convert string to enum value using jsonization (expects xs: prefix)
1572- const result = jsonization . dataTypeDefXsdFromJsonable ( valueType ) ;
1573- if ( result . error === null && result . value !== null ) {
1574- valueType = result . value ;
1575- }
1576- }
1567+ const valueType = parseDataTypeDefXsd ( data . valueType ) ;
15771568
15781569 return new Range (
15791570 valueType as DataTypeDefXsd ,
@@ -1799,7 +1790,7 @@ function parseSubmodelElementList(data: any): SubmodelElementList {
17991790 : undefined ,
18001791 data . orderRelevant !== undefined ? data . orderRelevant === 'true' || data . orderRelevant === true : undefined ,
18011792 data . semanticIdListElement ? parseReference ( data . semanticIdListElement ) : undefined ,
1802- data . valueTypeListElement || undefined ,
1793+ parseDataTypeDefXsd ( data . valueTypeListElement ) ,
18031794 data . value ? parseSubmodelElements ( data . value ) : undefined
18041795 ) ;
18051796}
0 commit comments