I am looking to traverse all the fields on a document and list out the merge fields that are used in an IF statement. Let’s say I have a document with this merge field:
{ IF {MERGEFIELD firstname} = “John” “Billy” “{ IF {MERGEFIELD lastname} = “Pipe” “Fuller” “Baker”}”}
I want pull out the value “firstname” and “lastname”. I have some of the code, but I’m not sure where to go from here. Can you please help point me in the correct direction to pull out the MergeFields that are used in every IF statement in the document?
Aspose.Words.Document doc = new Aspose.Words.Document(wordDoc.FullName);
NodeCollection fieldStarts = doc.GetChildNodes(NodeType.FieldStart, true);
foreach (FieldStart fieldStart in fieldStarts)
{
if (fieldStart.FieldType.Equals(FieldType.FieldIf))
{
Run fieldCode = (Run)fieldStart.NextSibling;
}
}