Click or drag to resize

ElementGetChildElements(Boolean) Method

Gets the child elements.

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.4.24
Syntax
public IEnumerable<Element> GetChildElements(
	bool recursively
)

Parameters

recursively  Boolean
true to get all descendants elements; otherwise false to get just child elements.

Return Value

IEnumerableElement
Sequence of child elements.
Example

See Developer Guide: Calculate sections, paragraphs, inlines, runs and fields in DOCX document

Calculate sections, paragraphs, inlines, runs and fields in DOCX document in C#
using System;
using SautinSoft.Document;
using System.IO;
using System.Linq;
using System.Text;

namespace Sample
{
    class Sample
    {

        static void Main(string[] args)
        {
            // Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/

            IterationElement();
        }

        /// <summary>
        /// Calculate sections, paragraphs, inlines, runs and fields in DOCX document.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/iteration-in-element-collection-net-csharp-vb.php
        /// </remarks>
        static void IterationElement()
        {
            DocumentCore dc = DocumentCore.Load(@"..\..\..\Parsing.docx", LoadOptions.DocxDefault);
            int numberOfSections = dc.Sections.Count;
            int numberOfParagraphs = dc.GetChildElements(true, ElementType.Paragraph).Count();
            int numberOfRunsAndFields = dc.GetChildElements(true, ElementType.Run, ElementType.Field).Count();
            int numberOfInlines = dc.GetChildElements(true).OfType<Inline>().Count();
            int elements = dc.Sections[0].GetChildElements(true).Count();
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("File has:");
            sb.AppendLine(numberOfSections + " section");
            sb.AppendLine(numberOfParagraphs + " paragraphs");
            sb.AppendLine(numberOfRunsAndFields + " runs and fields");
            sb.AppendLine(numberOfInlines + " inlines");
            sb.AppendLine("First section contains " + elements + " elements");
            Console.WriteLine(sb.ToString());
            Console.ReadKey();
        }
    }
}
Calculate sections, paragraphs, inlines, runs and fields in DOCX document in VB.Net
Imports System
Imports SautinSoft.Document
Imports System.IO
Imports System.Linq
Imports System.Text

Module Sample
    Sub Main()
        IterationElement()
    End Sub
    ''' Get your free 30-day key here:   
    ''' https://sautinsoft.com/start-for-free/
    ''' <summary>
    ''' Calculate sections, paragraphs, inlines, runs and fields in DOCX document.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/iteration-in-element-collection-net-csharp-vb.php
    ''' </remarks>
    Sub IterationElement()
        Dim dc As DocumentCore = DocumentCore.Load("..\..\..\Parsing.docx", LoadOptions.DocxDefault)
        Dim numberOfSections As Integer = dc.Sections.Count
        Dim numberOfParagraphs As Integer = dc.GetChildElements(True, ElementType.Paragraph).Count()
        Dim numberOfRunsAndFields As Integer = dc.GetChildElements(True, ElementType.Run, ElementType.Field).Count()
        Dim numberOfInlines As Integer = dc.GetChildElements(True).OfType(Of Inline)().Count()
        Dim elements As Integer = dc.Sections(0).GetChildElements(True).Count()
        Dim sb As New StringBuilder()
        sb.AppendLine("File has:")
        sb.AppendLine(numberOfSections & " section")
        sb.AppendLine(numberOfParagraphs & " paragraphs")
        sb.AppendLine(numberOfRunsAndFields & " runs and fields")
        sb.AppendLine(numberOfInlines & " inlines")
        sb.AppendLine("First section contains " & elements & " elements")
        Console.WriteLine(sb.ToString())
        Console.ReadKey()
    End Sub
End Module
See Also