Field MaxElementNestingDepth
The deepest XML element nesting this reader will admit in a part it parses.
public const int MaxElementNestingDepth = 256
Returns
- int
- The deepest XML element nesting this reader will admit in a part it parses.
Remarks
Why the reader checks this rather than the layers above it. Parsing is
streamed, so DocWright's own recursion stays shallow — but an element the parser does
not model is handed to OpenXmlReader.LoadCurrentElement(), and the SDK
materializes that subtree with one stack frame pair per level. A document nesting
roughly 700 elements therefore exhausts the stack **inside the SDK**, before any
DocWright limit is consulted, and a StackOverflowException cannot be
caught: the process dies. The only place to stop that is before the SDK is asked to
load anything, which is here.
256 is far past any real document — Word's own nesting rarely passes 30, and the deepest part in the test corpus is well inside it — while staying comfortably below the depth at which the SDK runs out of stack.