I am trying to build a list of specific elements within a Word Document using the OpenXML SDL 2.0. I will open a template and scan the Word template for all “w:sdt” elements which I will use as a list of available document parts. I will display this list to the user so they can chose the desired parts/elements to build a new version/copy of the document from the template document.
So my list will need to grab the sequential element number (this is used by the DocumentBuilder classes) as well as the “w:alias” “val” or maybe the “w:tag” “val” which will be used to display the selection option to the user.
Once the user has reviewed the available template XML part/elements and made their selection I will use DocumentBuilder to add the identified parts by sequential number to a new document.
I have successfully used DocumentBuilder to explicitly identify document elements by sequential number to build a new document. This works beautifully.
I know I need to use recursion to iterate through the template document and add the qualified elements to a LIST. I’m just not savvy enough yet with C# or the OpenXML SDK to identify the most elegant way to recurse through the template document targeting the desired XML part/elements.
Can anyone point me to an applicable example for enumerating a list of parts/elements in a OpenXML document?