FlatFile Schema logic

Im looking for some understanding of FF logic

I have just made changes to a flat file schema to allow iteration to work properly. I have a potentially large structure where I may have multiple header in a file and an unlimited number of details that could quite easily take up all my available memory if loaded all at once. I want to ID the header and then read each detail one by one. Then start over when I see the next header.
I was constantly getting the first iteration correct, but each subsequent detail was putting the header of the next iteration as children of the details of the previous even though the header was clearly defined as a top level. The schema I was using worked perfectly converting the doctype into a string, but not in parsing it into values from a stream. The records are consistant in ending with a CRLF

My question is why is the below valid, or did I perform a lucky hack.

File structure
1-2-6-6…9–1-2-6-6…9 Etc where 1 records may repeat a dozen or more times and where there are an unlimited number of 6s each

The schema was:
1

2

6(unlimited)
9

My schema looks like this now:

1

2

6(single iteration)
9
6(unlimited)

This works perfectly, but I dont see why
Correct or hack? If its correct, whats the logic?

Are you getting record 6 in sequence , once before 9 and all others after 9?
-Sri

upon further review, I must reverse my earlier statement. I would have sworn that it was working properly before, but it was a quick observance.

what I am getting is
1

2
6
6.6.6.6 where each 6 is a new iteration. (desired)
9
1

2

6.6.6.6.6.6.6.6.6.etc where the 1,2 and 6s all load at once.

where iterations of the 6 are desired, but the remainder of the data is made a child of the 9 record.

The reason for wanting to read each 6 one at a time is because of the occasional possibility of many thousands of 6 records. I dont want to load them into memory all at once.

At the top level of the schema is a setting Ordered. When set to false, the parsing is like clockwork. I am getting my header and account information in one pass, then each of the details in the next X number of passes. then when it gets back to the next header, it once again grabs that header and continues on its way.

So, if you see this same behavior in an x12 or flat file, look at the “Ordered” property at the top level of the schema…