CompositeNodeHasChildNodes Property
Returns true if this node has any child nodes.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 20.1
Syntax
public bool HasChildNodes { get; }

Property Value

Type: Boolean
Examples
Demonstrates how to use the InsertDocument method to insert a document into a merge field during mail merge.
public void InsertDocumentAtMailMerge()
{
    // Open the main document
    Document mainDoc = new Document(MyDir + "InsertDocument1.doc");

    // Add a handler to MergeField event
    mainDoc.MailMerge.FieldMergingCallback = new InsertDocumentAtMailMergeHandler();

    // The main document has a merge field in it called "Document_1"
    // The corresponding data for this field contains fully qualified path to the document
    // that should be inserted to this field
    mainDoc.MailMerge.Execute(new string[] { "Document_1" }, new object[] { MyDir + "InsertDocument2.doc" });

    mainDoc.Save(ArtifactsDir + "InsertDocumentAtMailMerge.doc");
}

private class InsertDocumentAtMailMergeHandler : IFieldMergingCallback
{
    /// <summary>
    /// This handler makes special processing for the "Document_1" field.
    /// The field value contains the path to load the document. 
    /// We load the document and insert it into the current merge field.
    /// </summary>
    void IFieldMergingCallback.FieldMerging(FieldMergingArgs args)
    {
        if (args.DocumentFieldName == "Document_1")
        {
            // Use document builder to navigate to the merge field with the specified name
            DocumentBuilder builder = new DocumentBuilder(args.Document);
            builder.MoveToMergeField(args.DocumentFieldName);

            // The name of the document to load and insert is stored in the field value
            Document subDoc = new Document((string) args.FieldValue);

            // Insert the document
            InsertDocument(builder.CurrentParagraph, subDoc);

            // The paragraph that contained the merge field might be empty now and you probably want to delete it
            if (!builder.CurrentParagraph.HasChildNodes)
                builder.CurrentParagraph.Remove();

            // Indicate to the mail merge engine that we have inserted what we wanted
            args.Text = null;
        }
    }

    void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args)
    {
        // Do nothing
    }
}
See Also