mscorlib(4.0.0.0) API with additions
XmlDeclaration.cs
1 using System.Text;
2 
3 namespace System.Xml
4 {
7  {
8  private const string YES = "yes";
9 
10  private const string NO = "no";
11 
12  private string version;
13 
14  private string encoding;
15 
16  private string standalone;
17 
20  public string Version
21  {
22  get
23  {
24  return version;
25  }
26  internal set
27  {
28  version = value;
29  }
30  }
31 
34  public string Encoding
35  {
36  get
37  {
38  return encoding;
39  }
40  set
41  {
42  encoding = ((value == null) ? string.Empty : value);
43  }
44  }
45 
48  public string Standalone
49  {
50  get
51  {
52  return standalone;
53  }
54  set
55  {
56  if (value == null)
57  {
58  standalone = string.Empty;
59  return;
60  }
61  if (value.Length == 0 || value == "yes" || value == "no")
62  {
63  standalone = value;
64  return;
65  }
66  throw new ArgumentException(Res.GetString("Xdom_standalone", value));
67  }
68  }
69 
72  public override string Value
73  {
74  get
75  {
76  return InnerText;
77  }
78  set
79  {
80  InnerText = value;
81  }
82  }
83 
86  public override string InnerText
87  {
88  get
89  {
90  StringBuilder stringBuilder = new StringBuilder("version=\"" + Version + "\"");
91  if (Encoding.Length > 0)
92  {
93  stringBuilder.Append(" encoding=\"");
94  stringBuilder.Append(Encoding);
95  stringBuilder.Append("\"");
96  }
97  if (Standalone.Length > 0)
98  {
99  stringBuilder.Append(" standalone=\"");
100  stringBuilder.Append(Standalone);
101  stringBuilder.Append("\"");
102  }
103  return stringBuilder.ToString();
104  }
105  set
106  {
107  string text = null;
108  string text2 = null;
109  string text3 = null;
110  string text4 = Encoding;
111  string text5 = Standalone;
112  string text6 = Version;
113  XmlLoader.ParseXmlDeclarationValue(value, out text, out text2, out text3);
114  try
115  {
116  if (text != null && !IsValidXmlVersion(text))
117  {
118  throw new ArgumentException(Res.GetString("Xdom_Version"));
119  }
120  Version = text;
121  if (text2 != null)
122  {
123  Encoding = text2;
124  }
125  if (text3 != null)
126  {
127  Standalone = text3;
128  }
129  }
130  catch
131  {
132  Encoding = text4;
133  Standalone = text5;
134  Version = text6;
135  throw;
136  }
137  }
138  }
139 
142  public override string Name => "xml";
143 
146  public override string LocalName => Name;
147 
150  public override XmlNodeType NodeType => XmlNodeType.XmlDeclaration;
151 
157  protected internal XmlDeclaration(string version, string encoding, string standalone, XmlDocument doc)
158  : base(doc)
159  {
160  if (!IsValidXmlVersion(version))
161  {
162  throw new ArgumentException(Res.GetString("Xdom_Version"));
163  }
164  if (standalone != null && standalone.Length > 0 && standalone != "yes" && standalone != "no")
165  {
166  throw new ArgumentException(Res.GetString("Xdom_standalone", standalone));
167  }
168  Encoding = encoding;
169  Standalone = standalone;
170  Version = version;
171  }
172 
177  public override XmlNode CloneNode(bool deep)
178  {
180  }
181 
184  public override void WriteTo(XmlWriter w)
185  {
187  }
188 
191  public override void WriteContentTo(XmlWriter w)
192  {
193  }
194 
195  private bool IsValidXmlVersion(string ver)
196  {
197  if (ver.Length >= 3 && ver[0] == '1' && ver[1] == '.')
198  {
199  return XmlCharType.IsOnlyDigits(ver, 2, ver.Length - 2);
200  }
201  return false;
202  }
203  }
204 }
Represents a character encoding.To browse the .NET Framework source code for this type,...
Definition: Encoding.cs:15
Represents an XML document. You can use this class to load, validate, edit, add, and position XML in ...
Definition: XmlDocument.cs:13
Represents the XML declaration node <?xml version='1.0'...?>.
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
virtual XmlDocument OwnerDocument
Gets the T:System.Xml.XmlDocument to which this node belongs.
Definition: XmlNode.cs:104
override void WriteTo(XmlWriter w)
Saves the node to the specified T:System.Xml.XmlWriter.
override string Value
Gets or sets the value of the XmlDeclaration.
internal XmlDeclaration(string version, string encoding, string standalone, XmlDocument doc)
Initializes a new instance of the T:System.Xml.XmlDeclaration class.
override string LocalName
Gets the local name of the node.
Definition: __Canon.cs:3
virtual XmlDeclaration CreateXmlDeclaration(string version, string encoding, string standalone)
Creates an T:System.Xml.XmlDeclaration node with the specified values.
Definition: XmlDocument.cs:934
XmlNodeType
Specifies the type of node.
Definition: XmlNodeType.cs:5
override void WriteContentTo(XmlWriter w)
Saves the children of the node to the specified T:System.Xml.XmlWriter. Because XmlDeclaration nodes ...
Represents a writer that provides a fast, non-cached, forward-only way to generate streams or files t...
Definition: XmlWriter.cs:12
string? Encoding
Gets or sets the encoding level of the XML document.
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
Gets the node immediately preceding or following this node.
Definition: XmlLinkedNode.cs:4
string Standalone
Gets or sets the value of the standalone attribute.
Represents the version number of an assembly, operating system, or the common language runtime....
Definition: Version.cs:11
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
The exception that is thrown when one of the arguments provided to a method is not valid.
string Version
Gets the XML version of the document.
override XmlNode CloneNode(bool deep)
Creates a duplicate of this node.
abstract void WriteProcessingInstruction(string name, string text)
When overridden in a derived class, writes out a processing instruction with a space between the name...
override string InnerText
Gets or sets the concatenated values of the XmlDeclaration.
override XmlNodeType NodeType
Gets the type of the current node.
override string Name
Gets the qualified name of the node.
Represents a single node in the XML document.
Definition: XmlNode.cs:13