예제 #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);
        }