Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle parsing of xs:group in XML schema #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions IO/complex/sicd/parse_sicd_schema.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,6 +33,11 @@
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)
output_struct = struct();
for j=1:current_node.getLength
Expand All @@ -49,8 +56,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'}
Expand All @@ -75,6 +85,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 ///
% //////////////////////////////////////////