Пример #1
0
        public static IEnumerable <XElement> getNonEmptyParagraphsOfHeaderType(XElement root,
                                                                               Constants.WordProcessingMLDefines.HeadingLevel headerLevel)
        {
            var parasWithHeading = WordProcessingMLUtils.getParagraphsOfHeaderType(root,
                                                                                   headerLevel);

            var query =
                from el in parasWithHeading
                where el.Descendants(w + "t").Any()
                select el;

            return(query);
        }
Пример #2
0
        /// <summary>
        /// Finds the following sibling of type paragraph with a header level
        /// matching the input parameter.
        /// Returns the node that is the previous sibling of the matching
        /// node.
        /// Returns null on the error condition where there is no sibling
        /// nodes after the input Element.
        /// </summary>
        /// <param name="startElement"></param>
        /// <param name="headerLevel"></param>
        /// <returns></returns>
        private XElement findPrecursorOfNextMatchingSibling(XElement startElement,
                                                            Constants.WordProcessingMLDefines.HeadingLevel headerLevel)
        {
            var elem = XUtils.WordProcessingMLUtils.findNextParagraphHeaderAtLevel(startElement, headerLevel);

            if (elem == null)
            {
                return(null);
            }
            var prev = elem.PreviousNode;

            return((XElement)prev);
        } // end of findNextMatchingSiblingV2
Пример #3
0
        public static IEnumerable <XElement> getParagraphsOfHeaderType(XElement root,
                                                                       Constants.WordProcessingMLDefines.HeadingLevel headerLevel)
        {
            var allParas =
                from el in root.Elements()
                where el.Name.LocalName.Equals("p")
                select el;

            var hdrParas =
                from el in allParas.Elements(w + "pPr").Elements(w + "pStyle")
                where el.Attribute(w + "val").Value.Trim().
                Equals(Constants.WordProcessingMLDefines.Headings[headerLevel])
                select el.Parent.Parent; // we need the paragraph node, not its grandchild style property node

            return(hdrParas);
        }
Пример #4
0
        public static XElement findNextParagraphHeaderAtLevel(XElement startNode,
                                                              Constants.WordProcessingMLDefines.HeadingLevel headerLevel)
        {
            var restOfElems = startNode.ElementsAfterSelf();

            foreach (var elem in restOfElems)
            {
                var styleNodes = elem.Elements(w + "pPr")
                                 .Elements(w + "pStyle");
                var checkSyleNode =
                    from styleNode in styleNodes
                    where styleNode.Attribute(w + "val").Value.Trim().
                    Equals(Constants.WordProcessingMLDefines.Headings[headerLevel])
                    select styleNode;

                if (checkSyleNode.Count() > 0)
                {
                    return(elem);
                }
            }

            return(null);
        }