diff --git a/pyx12/x12file.py b/pyx12/x12file.py index 86f8ca75..1d85ae24 100644 --- a/pyx12/x12file.py +++ b/pyx12/x12file.py @@ -341,6 +341,10 @@ def _parse_segment(self, seg_data): X12Base._parse_segment(self, seg_data) seg_id = seg_data.get_seg_id() if seg_id == 'IEA': + if not self.loops: + err_str = 'IEA loop with malformed preceding segment' + self._isa_error('000', err_str) # what is the correct code to use? + return # nothing to delete if self.loops[-1][0] != 'ISA': # Unterminated GS loop err_str = 'Unterminated Loop %s' % (self.loops[-1][0]) diff --git a/pyx12/x12xml_simple.py b/pyx12/x12xml_simple.py index 12894276..71ed6430 100644 --- a/pyx12/x12xml_simple.py +++ b/pyx12/x12xml_simple.py @@ -69,7 +69,7 @@ def seg(self, seg_node, seg_data): self.writer.push(xname, attrib) for i in range(len(seg_data)): child_node = seg_node.get_child_node_by_idx(i) - if child_node.usage == 'N' or seg_data.get('%02i' % (i + 1)).is_empty(): + if child_node is None or child_node.usage == 'N' or seg_data.get('%02i' % (i + 1)).is_empty(): pass # Do not try to ouput for invalid or empty elements elif child_node.is_composite(): (xname, attrib) = self._get_comp_info(seg_node_id)