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.
merge dev_5_0 -D org: PR 1139 (Fix for BH .Sdt meas mode 0 & 1 single pixel files & (unrelated) problem with dividing by increment count.)
merge dev_5_0 -D org: PR 1146 (bfsave: metadata improvements)
merge dev_5_0 -D org: PR 1150 (Allow dist-matlab to run on Windows (rebased onto dev_5_0))
merge dev_5_0 -D org: PR 1153 (CZI: prevent AIOOB exception when populating position metadata)
merge dev_5_0 -D org: PR 1159 (First round of Nikon ND2 fixes)
merge dev_5_0 -D org

Repository: openmicroscopy/bioformats
Updating 623cd6d..34b6aca
Merged PRs (fast-forward):
  # PR 1157 hflynn 'Removing dead link from Minolta-MRW format page'
  # PR 1144 hflynn 'Updating Zeiss links'
  # PR 1151 hflynn 'Comstat2 link'
  # PR 1134 sbesson 'Add prefix to zip file produced by dist-bftools target'
  # PR 1140 hflynn 'Add 'show and edit on Github' to docs side menu'
  # PR 1143 joshmoore 'Memoizer errs'

Merged PRs:
  # PR 1139 imunro 'Fix for BH .Sdt meas mode 0 & 1 single pixel files & (unrelated) problem with dividing by increment count.'
  # PR 1146 sbesson 'bfsave: metadata improvements'
  # PR 1150 melissalinkert 'Allow dist-matlab to run on Windows (rebased onto dev_5_0)'
  # PR 1153 melissalinkert 'CZI: prevent AIOOB exception when populating position metadata'
  # PR 1159 melissalinkert 'First round of Nikon ND2 fixes'

Generated by OMERO-5.0-merge-push#27 (http://ci.openmicroscopy.org/job/OMERO-5.0-merge-push/27/)