*** empty log message ***
[mono.git] / mcs / class / System.XML / System.Xml / XmlWhitespace.cs
1 //
2 // System.Xml.XmlWhitespace.cs
3 //
4 // Author:
5 //      Duncan Mak  (duncan@ximian.com)
6 //
7 // (C) Ximian, Inc. http://www.ximian.com
8 //
9
10 using System;
11 using System.Xml.XPath;
12
13 namespace System.Xml
14 {
15         public class XmlWhitespace : XmlCharacterData
16         {
17                 // Constructor
18                 protected internal XmlWhitespace (string strData, XmlDocument doc)
19                         : base (strData, doc)
20                 {
21                 }
22                 
23                 // Properties
24                 public override string LocalName {
25                         get { return "#whitespace"; }
26                 }
27
28                 public override string Name {
29                         get { return "#whitespace"; }
30                 }
31
32                 public override XmlNodeType NodeType {
33                         get { return XmlNodeType.Whitespace; }
34                 }
35
36                 internal override XPathNodeType XPathNodeType {
37                         get { return XPathNodeType.Whitespace; }
38                 }
39
40                 public override string Value {
41                         get { return Data; }
42                         set {
43                                 if (IsValidWhitespaceChar (value) == false)
44                                         throw new ArgumentException ("Invalid whitespace characters.");
45                                 Data = value;
46                         }
47                 }
48
49                 // Methods
50                 public override XmlNode CloneNode (bool deep)
51                 {
52                         // always return the data value
53                         return new XmlWhitespace (Data, OwnerDocument); 
54                 }
55
56                 public override void WriteContentTo (XmlWriter w) {}
57
58                 public override void WriteTo (XmlWriter w)
59                 {
60                         if(OwnerDocument.PreserveWhitespace)
61                                 w.WriteWhitespace (Data);
62                 }
63
64                 private bool IsValidWhitespaceChar (string text)
65                 {
66                         foreach (char c in text)
67                                 if ((c != ' ') && (c != '\r') && (c != '\n') && (c != '\t'))
68                                         return false;
69                         return true;
70                 }
71         }
72 }