Exemplo n.º 1
0
        public static string GetOutterText(string html, Match startTagMatch)
        {
            StringBuilder sb = new StringBuilder(5000);

            //Start searching at the end of the start tag
            int index = startTagMatch.Index + startTagMatch.Length;

            //Get the string version of the tag
            string startTagName = GetTagName(startTagMatch);
            string endTag       = "";

            //loop thru the bml text
            while (index < html.Length)
            {
                Match m = null;

                //search out the next ending type of tag
                EndTagRegex bmlEndTag = new EndTagRegex();
                m = bmlEndTag.Match(html, index);
                //check if we find a match
                if (m.Success)
                {
                    //verify the tagnames match
                    endTag = GetTagName(m);
                    if (endTag == startTagName)
                    {                     //match
                        //return the outertext of the match.
                        int endindex = m.Index + m.Length;
                        int stLength = endindex - startTagMatch.Index;
                        return(html.Substring(startTagMatch.Index, stLength));
                    }
                    {                     //No Match, increment index
                        index = m.Index + m.Length;
                        continue;
                    }
                }
                index++;
            }
            //TODO: Throw error?
            throw new ApplicationException(
                      string.Format("No end tag match found for tag {0} at position {1}", startTagMatch.Value, startTagMatch.Index));
            //return "";
        }