2 // System.Xml.XmlDeclaration
5 // Duncan Mak (duncan@ximian.com)
14 public class XmlDeclaration : XmlLinkedNode
16 string encoding = "UTF-8"; // defaults to UTF-8
20 protected internal XmlDeclaration (string version, string encoding,
21 string standalone, XmlDocument doc)
27 if (standalone == null)
30 this.version = version;
31 this.encoding = encoding;
32 this.standalone = standalone;
35 public string Encoding {
36 get { return encoding; }
37 set { encoding = (value == null) ? String.Empty : value; }
40 public override string InnerText {
42 set { ParseInput (value); }
45 public override string LocalName {
49 public override string Name {
53 public override XmlNodeType NodeType {
54 get { return XmlNodeType.XmlDeclaration; }
57 public string Standalone {
58 get { return standalone; }
60 if (value.ToUpper() == "YES")
62 if (value.ToUpper() == "NO")
67 public override string Value {
69 string formatEncoding = "";
70 string formatStandalone = "";
72 if (encoding != String.Empty)
73 formatEncoding = String.Format (" encoding=\"{0}\"", encoding);
75 if (standalone != String.Empty)
76 formatStandalone = String.Format (" standalone=\"{0}\"", standalone);
78 return String.Format ("version=\"{0}\"{1}{2}", Version, formatEncoding, formatStandalone);
80 set { ParseInput (value); }
83 public string Version {
84 get { return version; }
87 public override XmlNode CloneNode (bool deep)
89 return new XmlDeclaration (Version, Encoding, standalone, OwnerDocument);
92 public override void WriteContentTo (XmlWriter w) {}
94 public override void WriteTo (XmlWriter w)
96 // This doesn't seem to match up very well with w.WriteStartDocument()
97 // so writing out custom here.
98 w.WriteRaw (String.Format ("<?xml {0}?>", Value));
101 void ParseInput (string input)
103 Encoding = input.Split (new char [] { ' ' }) [1].Split (new char [] { '=' }) [1];
104 Standalone = input.Split (new char [] { ' ' }) [2].Split (new char [] { '=' }) [1];