Click or drag to resize

ElementGetChildElements Method (Boolean)

Gets the child elements.

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

Parameters

recursively
Type: SystemBoolean
true to get all descendants elements; otherwise false to get just child elements.

Return Value

Type: IEnumerableElement
Sequence of child elements.
Examples
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)
        {
            IterationElement();
        }

        /// <summary>
        /// Calculate sections, paragraphs, inlines, runs and fields in DOCX document.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/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

    ''' <summary>
    ''' Calculate sections, paragraphs, inlines, runs and fields in DOCX document.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/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