If you have Header tags <H#

why not use the TOC tool?
At least as a starting point.

The NCX will start out valid
The HTML TOC tool uses the NCX as its basis
Warning: SAVE your work BEFORE launching that tool. That tool frequently Crashes Sigil on my systems (XP and W7)