Example #1
0
        private static XElement FindEndTag(XElement startTag, string startTagName, string endTagName)
        {
            var startTagsOpened = 1;
            var current         = startTag;

            while (startTagsOpened > 0 && current != null)
            {
                var nextTagElements = TraverseUtils.NextTagElements(current, new Collection <string> {
                    startTagName, endTagName
                }).ToList();
                var index = -1;
                while ((index < nextTagElements.Count) && (startTagsOpened != 0))
                {
                    index++;
                    if (nextTagElements[index].IsTag(startTagName))
                    {
                        startTagsOpened++;
                    }
                    else
                    {
                        startTagsOpened--;
                    }
                }
                current = nextTagElements[index];
            }
            if (current == null)
            {
                throw new Exception(string.Format(MessageStrings.TagNotFoundOrEmpty, endTagName));
            }
            return(current);
        }
Example #2
0
        private XElement FindEndTag(XElement startTag)
        {
            var ifTagsOpened = 1;
            var current      = startTag;

            while (ifTagsOpened > 0 && current != null)
            {
                var nextTagElements = TraverseUtils.NextTagElements(current, new Collection <string> {
                    "if", "endif"
                }).ToList();
                foreach (var nextTagElement in nextTagElements)
                {
                    if (nextTagElement.IsTag("if"))
                    {
                        ifTagsOpened++;
                    }
                    else
                    {
                        if (--ifTagsOpened == 0)
                        {
                            return(nextTagElement);
                        }
                    }
                }
            }
            if (current == null)
            {
                throw new Exception(string.Format(MessageStrings.TagNotFoundOrEmpty, "EndIf"));
            }
            return(current);
        }
        protected ICollection <XElement> TryGetRequiredTags(XElement startElement, string tagName)
        {
            var tags = TraverseUtils.NextTagElements(startElement, tagName).ToList();

            if (!tags.Any())
            {
                throw new Exception(string.Format(MessageStrings.TagNotFoundOrEmpty, tagName));
            }
            return(tags);
        }
        protected XElement TryGetRequiredTag(XElement startElement, string tagName)
        {
            var tag = TraverseUtils.NextTagElements(startElement, tagName).FirstOrDefault();

            if (tag == null)
            {
                throw new Exception(string.Format(MessageStrings.TagNotFoundOrEmpty, tagName));
            }
            return(tag);
        }
        public virtual XElement Parse(ITagProcessor parentProcessor, XElement startElement)
        {
            var sdtElement = startElement.Descendants(WordMl.SdtName).FirstOrDefault();

            while (sdtElement != null)
            {
                sdtElement = this.ParseSdt(parentProcessor, sdtElement);
                sdtElement = TraverseUtils.NextTagElements(sdtElement).FirstOrDefault();
            }
            return(startElement);
        }
Example #6
0
        private static IEnumerable <TableElement> MakeTableElement(XElement startElement, XElement endElement)
        {
            ICollection <TableElement> tableElements = new Collection <TableElement>();
            var currentTagElement = TraverseUtils.NextTagElements(startElement).FirstOrDefault();

            while (currentTagElement != null && currentTagElement.IsBefore(endElement))
            {
                var tableElement = ToTableElement(currentTagElement);

                if (tableElement.IsItem || tableElement.IsIndex || tableElement.IsItemIf || tableElement.IsItemRepeater || tableElement.IsItemHtmlContent || tableElement.IsCellColor)
                {
                    tableElements.Add(tableElement);
                }
                if (tableElement.IsItemIf || tableElement.IsItemRepeater)
                {
                    currentTagElement = tableElement.EndTag;
                }
                currentTagElement = TraverseUtils.NextTagElements(currentTagElement).FirstOrDefault();
            }
            return(tableElements);
        }