コード例 #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.Val.Equals("preserve"))
					{
						return true;
					}
					
					return false;
				}
			}
			
			/* kludge for html docs without explicit xml:space attribute */
			if (String.Compare(element.Element, "pre") == 0 || String.Compare(element.Element, "script") == 0 || String.Compare(element.Element, "style") == 0)
			{
				return true;
			}
			
			if ((tt != null) && (tt.FindParser(element) == ParsePre))
			{
				return true;
			}
			
			/* kludge for XSL docs */
			if (String.Compare(element.Element, "xsl:text") == 0)
			{
				return true;
			}
			
			return false;
		}