Ejemplo n.º 1
0
        /// <summary>
        /// Method which determines if the tag needs alternative closing, like <img />, <br />, <hr />
        /// </summary>
        /// <param name="element">Element to check</param>
        /// <returns>True if empty element, otherwise false</returns>
        private bool IsEmptyElement(XHTMLElement element)
        {
            //Check if element has childs, if not it's empty
            if (element.GetChildren().Count == 0 && !element.IsGenerated())
            {
                return(true);
            }

            //Generated elements like html in empty file should not be shortened in ending
            if (element.IsGenerated())
            {
                return(false);
            }

            //Some elements are always empty
            String[] xhtmlEmptyTags = Enum.GetNames(typeof(EmptyXHTMLElement));
            String   tag            = element.GetTag();

            foreach (String item in xhtmlEmptyTags)
            {
                if (item.Equals(tag.ToUpper()))
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Visit XHTMLElement and write it to stream
        /// </summary>
        /// <param name="element">Element to visit</param>
        public void Visit(XHTMLElement element)
        {
            if (element.GetTag() == "cdata")
            {   //CData need different handling
                WriteCData(element);
            }
            else if (element.GetTag() == "comment")
            {   //Write comment
                WriteComment(element);
            }
            else
            {   //Normal XHTML tag handling
                XhtmlWriter.BeginRender();

                //Check if element is tag, if not write tag, otherwise handle as XHTML tag
                if (!element.GetTagState())
                {
                    XhtmlWriter.BeginRender();

                    //Get escape chars out of this tag
                    CharIterator charIterator = new CharIterator();
                    String       tag          = charIterator.ParseText(element.GetTag());
                    XhtmlWriter.Write(tag);
                    XhtmlWriter.EndRender();
                    XhtmlWriter.Flush();
                    return;
                }

                XhtmlWriter.WriteBeginTag(element.GetTag());
                foreach (KeyValuePair <String, String> pair in element.GetAttributes())
                {
                    XhtmlWriter.WriteAttribute(pair.Key, pair.Value, false);
                }

                if (IsEmptyElement(element))
                {   //Nothing inside element, so write tag end
                    XhtmlWriter.Write(XhtmlTextWriter.SelfClosingTagEnd);
                }
                else if (IsXHTMLTag(element.GetTag()))
                {
                    //Write tag opening closing
                    XhtmlWriter.Write(XhtmlTextWriter.TagRightChar);

                    //Write content
                    XhtmlWriter.Write(element.GetContent());

                    //Visit children
                    foreach (XHTMLElement child in element.GetChildren())
                    {
                        Visit(child);
                    }

                    //Write closing tag
                    XhtmlWriter.WriteEndTag(element.GetTag());
                    XhtmlWriter.Flush();
                }
                else
                {
                    //Just write it
                    XhtmlWriter.Write(element.GetTag());
                    XhtmlWriter.EndRender();
                    XhtmlWriter.Flush();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Visit XHTMLElement and write it to stream
        /// </summary>
        /// <param name="element">Element to visit</param>
        public void Visit(XHTMLElement element)
        {
            if (element.GetTag() == "cdata")
            {   //CData need different handling
                WriteCData(element);
            }
            else if (element.GetTag() == "comment")
            {   //Write comment
                WriteComment(element);
            }
            else
            {   //Normal XHTML tag handling

                XhtmlWriter.BeginRender();

                //Check if element is tag, if not write tag, otherwise handle as XHTML tag
                if (!element.GetTagState())
                {
                    XhtmlWriter.BeginRender();

                    //Get escape chars out of this tag
                    CharIterator charIterator = new CharIterator();
                    String tag = charIterator.ParseText(element.GetTag());
                    XhtmlWriter.Write(tag);
                    XhtmlWriter.EndRender();
                    XhtmlWriter.Flush();
                    return;
                }

                XhtmlWriter.WriteBeginTag(element.GetTag());
                foreach (KeyValuePair<String, String> pair in element.GetAttributes())
                {
                    XhtmlWriter.WriteAttribute(pair.Key, pair.Value, false);
                }

                if (IsEmptyElement(element))
                {   //Nothing inside element, so write tag end
                    XhtmlWriter.Write(XhtmlTextWriter.SelfClosingTagEnd);
                }
                else if (IsXHTMLTag(element.GetTag()))
                {
                    //Write tag opening closing
                    XhtmlWriter.Write(XhtmlTextWriter.TagRightChar);

                    //Write content
                    XhtmlWriter.Write(element.GetContent());

                    //Visit children
                    foreach (XHTMLElement child in element.GetChildren())
                    {
                        Visit(child);
                    }

                    //Write closing tag
                    XhtmlWriter.WriteEndTag(element.GetTag());
                    XhtmlWriter.Flush();
                }
                else
                {
                    //Just write it
                    XhtmlWriter.Write(element.GetTag());
                    XhtmlWriter.EndRender();
                    XhtmlWriter.Flush();
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Method which determines if the tag needs alternative closing, like <img />, <br />, <hr />
        /// </summary>
        /// <param name="element">Element to check</param>
        /// <returns>True if empty element, otherwise false</returns>
        private bool IsEmptyElement(XHTMLElement element)
        {
            //Check if element has childs, if not it's empty
            if (element.GetChildren().Count == 0 && !element.IsGenerated())
            {
                return true;
            }

            //Generated elements like html in empty file should not be shortened in ending
            if (element.IsGenerated())
            {
                return false;
            }

            //Some elements are always empty
            String[] xhtmlEmptyTags = Enum.GetNames(typeof(EmptyXHTMLElement));
            String tag = element.GetTag();
            foreach (String item in xhtmlEmptyTags)
            {
                if (item.Equals(tag.ToUpper()))
                {
                    return true;
                }
            }
            return false;
        }