コード例 #1
0
        internal List <Paragraph> GetParagraphs()
        {
            // Need some memory that can be updated by the recursive search.
            int index      = 0;
            var paragraphs = new List <Paragraph>();

            var p = this.Xml.Descendants(XName.Get("p", DocX.w.NamespaceName));

            if (p != null)
            {
                foreach (XElement xElement in p)
                {
                    var paragraph = new Paragraph(this.Document, xElement, index);
                    paragraphs.Add(paragraph);
                    index += HelperFunctions.GetText(xElement).Length;
                }
            }

            return(paragraphs);
        }
コード例 #2
0
        internal void GetParagraphsRecursive(XElement xml, ref int index, ref List <Paragraph> paragraphs, bool isDeepSearch = false)
        {
            var keepSearching = true;

            if (xml.Name.LocalName == "p")
            {
                paragraphs.Add(new Paragraph(Document, xml, index));

                index += HelperFunctions.GetText(xml).Length;
                if (!isDeepSearch)
                {
                    keepSearching = false;
                }
            }

            if (keepSearching && xml.HasElements)
            {
                foreach (XElement e in xml.Elements())
                {
                    this.GetParagraphsRecursive(e, ref index, ref paragraphs, isDeepSearch);
                }
            }
        }