From 057ac2f74771246d252d8764d0e307c861823173 Mon Sep 17 00:00:00 2001 From: dmadsen Date: Thu, 13 Jun 2024 12:47:53 -0600 Subject: [PATCH 1/2] Handle parsing of xs:group parts of XML schema (fixes ReferenceGeometry.Monostatic in CPHD xml) --- IO/complex/sicd/parse_sicd_schema.m | 45 +++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/IO/complex/sicd/parse_sicd_schema.m b/IO/complex/sicd/parse_sicd_schema.m index 8a64e30..4d689fb 100644 --- a/IO/complex/sicd/parse_sicd_schema.m +++ b/IO/complex/sicd/parse_sicd_schema.m @@ -20,8 +20,10 @@ child=schema_root.item(i-1); if child.getNodeType == child.ELEMENT_NODE switch char(child.getNodeName) - case {'xs:simpleType','xs:complexType','xs:group'} % Type definitions + case {'xs:simpleType','xs:complexType'} % Type definitions schema_struct.types.(char(child.getAttribute('name'))) = recursfun_schema(child); + case 'xs:group' + schema_struct.groups.(char(child.getAttribute('name'))) = recursfun_schema(child); case 'xs:element' % Master node (should be onle one) schema_struct.master = recursfun_schema(child); otherwise @@ -31,6 +33,8 @@ end end +schema_struct.types = recursfun_group(schema_struct.types, schema_struct.groups); + function output_struct = recursfun_schema(current_node) output_struct = struct(); for j=1:current_node.getLength @@ -49,8 +53,11 @@ output_struct = recursfun_schema(current_child); % Adds any attributes output_struct.SCHEMA_type = char(current_child.getAttribute('base')); case {'xs:simpleType','xs:simpleContent',... - 'xs:complexType','xs:complexContent','xs:group'} + 'xs:complexType','xs:complexContent'} output_struct = recursfun_schema(current_child); + case {'xs:group'} + ref_str = char(current_child.getAttribute('ref')); + output_struct.(ref_str).SCHEMA_group = ref_str; case {'xs:sequence','xs:choice','xs:all'} output_struct = setstructfields(output_struct, recursfun_schema(current_child)); case {'xs:attribute'} @@ -75,6 +82,40 @@ end end +function current_struct = recursfun_group(current_struct, groups) + fields = fieldnames(current_struct); + for f = 1:numel(fields) + current_field = current_struct.(fields{f}); + if isfield(current_field, "SCHEMA_group") + current_struct = assign_group(current_struct, groups); + current_struct = recursfun_group(current_struct); + break; + elseif isfield(current_field, "SCHEMA_type") || isfield(current_field, "SCHEMA_attributes") + continue; + elseif ~isempty(fieldnames(current_field)) + current_struct.(fields{f}) = recursfun_group(current_field, groups); + else + error('SICDXML2STRUCT:UNEXPECTED_SCHEMA_TYPE','Unexpected schema node type in XSD after initial parsing.') + end + end +end + +function new_struct = assign_group(current_struct, groups) + fields = fieldnames(current_struct); + for f = 1:numel(fields) + current_field = current_struct.(fields{f}); + if isfield(current_field, "SCHEMA_group") + current_group = groups.(current_field.SCHEMA_group); + group_fields = fieldnames(current_group); + for gf = 1:numel(group_fields) + new_struct.(group_fields{gf}) = current_group.(group_fields{gf}); + end + else + new_struct.(fields{f}) = current_field; + end + end +end + % ////////////////////////////////////////// % /// CLASSIFICATION: UNCLASSIFIED /// % ////////////////////////////////////////// \ No newline at end of file From fa747db5b35c55fc66e29d039c6163930b6f3aa5 Mon Sep 17 00:00:00 2001 From: dmadsen Date: Thu, 15 Aug 2024 10:06:59 -0600 Subject: [PATCH 2/2] Previous fix for groups in CPHD schema caused an error for the SICD schema which didn't have any groups. --- IO/complex/sicd/parse_sicd_schema.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/IO/complex/sicd/parse_sicd_schema.m b/IO/complex/sicd/parse_sicd_schema.m index 4d689fb..da52ef2 100644 --- a/IO/complex/sicd/parse_sicd_schema.m +++ b/IO/complex/sicd/parse_sicd_schema.m @@ -33,6 +33,9 @@ end end +if ~isfield(schema_struct, "groups") + schema_struct.groups = []; +end schema_struct.types = recursfun_group(schema_struct.types, schema_struct.groups); function output_struct = recursfun_schema(current_node)