Esempio n. 1
0
        /// <summary>  Indicates whether or not whitespace should be preserved for this element.
        /// If an <code>xml:space</code> attribute is found, then if the attribute value is
        /// <code>preserve</code>, returns <code>true</code>.  For any other value, returns
        /// <code>false</code>.  If an <code>xml:space</code> attribute was <em>not</em>
        /// found, then the following element names result in a return value of <code>true:
        /// pre, script, style,</code> and <code>xsl:text</code>.  Finally, if a
        /// <code>TagTable</code> was passed in and the element appears as the "pre" element
        /// in the <code>TagTable</code>, then <code>true</code> will be returned.
        /// Otherwise, <code>false</code> is returned.
        /// </summary>
        /// <param name="element">The <code>Node</code> to test to see if whitespace should be
        /// preserved.
        /// </param>
        /// <param name="tt">The <code>TagTable</code> to test for the <code>getNodePre()</code>
        /// function.  This may be <code>null</code>, in which case this test
        /// is bypassed.
        /// </param>
        /// <returns> <code>true</code> or <code>false</code>, as explained above.
        /// </returns>

        public static bool XMLPreserveWhiteSpace(Node element, TagTable tt)
        {
            AttVal attribute;

            /* search attributes for xml:space */
            for (attribute = element.attributes; attribute != null; attribute = attribute.next)
            {
                if (attribute.attribute.Equals("xml:space"))
                {
                    if (attribute.value_Renamed.Equals("preserve"))
                    {
                        return(true);
                    }

                    return(false);
                }
            }

            /* kludge for html docs without explicit xml:space attribute */
            if (Lexer.wstrcasecmp(element.element, "pre") == 0 || Lexer.wstrcasecmp(element.element, "script") == 0 || Lexer.wstrcasecmp(element.element, "style") == 0)
            {
                return(true);
            }

            if ((tt != null) && (tt.findParser(element) == ParsePre))
            {
                return(true);
            }

            /* kludge for XSL docs */
            if (Lexer.wstrcasecmp(element.element, "xsl:text") == 0)
            {
                return(true);
            }

            return(false);
        }