ND2: fix XML trimming to prevent too much from being removed

Fixes #11998.
Fix loop state parsing

Each loop has a separate valid state flag, so rather than using a global
flag we now set and query each individual loop's flag.
Additional 0-size checking

Fixes #10939
ND2: one more adjustment to loop state parsing

Fixes #10939.
Remove loop state check from FramesBefore/FramesAfter logic
Make private class in DV reader public (see #12358)

In order to be able to handle the DVExtHdrFields as anything
other than a string, the object will either need to be made
public or be made to implement some public API (e.g. Map).
Re-hide and flatten DVExtHdrFields

Rather than expose the inner class, we flatten
its contents into the metadata table so that consumers
need not know of its existence.
One more fix to position dimension detection

If no stage positions are recorded, assume position count is 1.
Fix stage position check to include non-XML metadata
Prevent NumberFormatException that caused TextInfo dimensions to be ignored
Fix import error
Correct for off-by-ones in SizeZ reporting
Merge pull request #1160 from joshmoore/rebased/dev_5_0/12358-dv-metadata

Make private class in DV reader public (see #12358) (rebased onto dev_5_0)
Merge pull request #1159 from melissalinkert/nd2

First round of Nikon ND2 fixes