2002-12-03 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
[mono.git] / mcs / class / System.XML / System.Xml / XmlDocument.cs
1 //
2 // System.Xml.XmlDocument
3 //
4 // Authors:
5 //   Daniel Weber (daniel-weber@austin.rr.com)
6 //   Kral Ferch <kral_ferch@hotmail.com>
7 //   Jason Diamond <jason@injektilo.org>
8 //   Miguel de Icaza (miguel@ximian.com)
9 //   Duncan Mak (duncan@ximian.com)
10 //   Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
11 //
12 // (C) 2001 Daniel Weber
13 // (C) 2002 Kral Ferch, Jason Diamond, Miguel de Icaza, Duncan Mak,
14 //   Atsushi Enomoto
15 //
16
17 using System;
18 using System.IO;
19 using System.Text;
20 using System.Xml.XPath;
21 using System.Diagnostics;
22 using System.Collections;
23
24 namespace System.Xml
25 {
26         public class XmlDocument : XmlNode
27         {
28                 #region Fields
29
30                 XmlLinkedNode lastLinkedChild;
31                 XmlNameTable nameTable;
32                 string baseURI = String.Empty;
33                 XmlImplementation implementation;
34                 bool preserveWhitespace = true; // Its true initial value is false.
35                 WeakReference reusableXmlTextReader;
36
37                 #endregion
38
39                 #region Constructors
40
41                 public XmlDocument () : this (null, null)
42                 {
43                 }
44
45                 protected internal XmlDocument (XmlImplementation imp) : this (imp, null)
46                 {
47                 }
48
49                 public XmlDocument (XmlNameTable nt) : this (null, nt)
50                 {
51                 }
52
53                 XmlDocument (XmlImplementation impl, XmlNameTable nt) : base (null)
54                 {
55                         implementation = (impl != null) ? impl : new XmlImplementation ();
56                         nameTable = (nt != null) ? nt : implementation.internalNameTable;
57                         AddDefaultNameTableKeys ();
58                 }
59                 #endregion
60
61                 #region Events
62
63                 public event XmlNodeChangedEventHandler NodeChanged;
64
65                 public event XmlNodeChangedEventHandler NodeChanging;
66
67                 public event XmlNodeChangedEventHandler NodeInserted;
68
69                 public event XmlNodeChangedEventHandler NodeInserting;
70
71                 public event XmlNodeChangedEventHandler NodeRemoved;
72
73                 public event XmlNodeChangedEventHandler NodeRemoving;
74
75                 #endregion
76
77                 #region Properties
78
79                 public override string BaseURI {
80                         get {
81                                 return baseURI;
82                         }
83                 }
84
85                 // Used to read 'InnerXml's for its descendants at any place.
86                 internal XmlTextReader ReusableReader {
87                         get {
88                                 if(reusableXmlTextReader == null)
89                                         reusableXmlTextReader = new WeakReference (null);
90                                 if(!reusableXmlTextReader.IsAlive) {
91                                         XmlTextReader reader = new XmlTextReader ((TextReader)null);
92                                         reusableXmlTextReader.Target = reader;
93                                 }
94                                 return (XmlTextReader)reusableXmlTextReader.Target;
95                         }
96                 }
97
98                 public XmlElement DocumentElement {
99                         get {
100                                 XmlNode node = FirstChild;
101
102                                 while (node != null) {
103                                         if (node is XmlElement)
104                                                 break;
105                                         node = node.NextSibling;
106                                 }
107
108                                 return node != null ? node as XmlElement : null;
109                         }
110                 }
111
112                 [MonoTODO("It doesn't have internal subset object model.")]
113                 public virtual XmlDocumentType DocumentType {
114                         get {
115                                 foreach(XmlNode n in this.ChildNodes) {
116                                         if(n.NodeType == XmlNodeType.DocumentType)
117                                                 return (XmlDocumentType)n;
118                                 }
119                                 return null;
120                         }
121                 }
122
123                 public XmlImplementation Implementation {
124                         get { return implementation; }
125                 }
126
127                 public override string InnerXml {
128                         get {
129                                 return base.InnerXml;
130                         }
131                         set {   // reason for overriding
132                                 this.LoadXml (value);
133                         }
134                 }
135
136                 public override bool IsReadOnly {
137                         get { return false; }
138                 }
139
140                 internal override XmlLinkedNode LastLinkedChild {
141                         get     {
142                                 return lastLinkedChild;
143                         }
144
145                         set {
146                                 lastLinkedChild = value;
147                         }
148                 }
149                 
150                 public override string LocalName {
151                         get { return "#document"; }
152                 }
153
154                 public override string Name {
155                         get { return "#document"; }
156                 }
157
158                 public XmlNameTable NameTable {
159                         get { return nameTable; }
160                 }
161
162                 public override XmlNodeType NodeType {
163                         get { return XmlNodeType.Document; }
164                 }
165
166                 internal override XPathNodeType XPathNodeType {
167                         get {
168                                 return XPathNodeType.Root;
169                         }
170                 }
171
172                 public override XmlDocument OwnerDocument {
173                         get { return null; }
174                 }
175
176                 [MonoTODO("check its behavior")]
177                 public bool PreserveWhitespace {
178                         get { return preserveWhitespace; }
179                         set { preserveWhitespace = value; }
180                 }
181
182                 internal override string XmlLang {
183                         get { return String.Empty; }
184                 }
185
186                 [MonoTODO]
187                 public virtual XmlResolver XmlResolver {
188                         set { throw new NotImplementedException (); }
189                 }
190
191                 internal override XmlSpace XmlSpace {
192                         get {
193                                 return XmlSpace.None;
194                         }
195                 }
196
197                 #endregion
198
199                 #region Methods
200
201                 [MonoTODO("Should BaseURI be cloned?")]
202                 public override XmlNode CloneNode (bool deep)
203                 {
204                         XmlDocument doc = implementation.CreateDocument ();
205                         doc.PreserveWhitespace = PreserveWhitespace;    // required?
206                         if(deep)
207                         {
208                                 foreach(XmlNode n in ChildNodes)
209                                         doc.AppendChild (doc.ImportNode (n, deep));
210                         }
211                         return doc;
212                 }
213
214                 public XmlAttribute CreateAttribute (string name)
215                 {
216                         return CreateAttribute (name, String.Empty);
217                 }
218
219                 public XmlAttribute CreateAttribute (string qualifiedName, string namespaceURI)
220                 {
221                         string prefix;
222                         string localName;
223
224                         ParseName (qualifiedName, out prefix, out localName);
225
226                         return CreateAttribute (prefix, localName, namespaceURI);
227                 }
228
229                 public virtual XmlAttribute CreateAttribute (string prefix, string localName, string namespaceURI)
230                 {
231                         if ((localName == null) || (localName == String.Empty))
232                                 throw new ArgumentException ("The attribute local name cannot be empty.");
233
234                         return new XmlAttribute (prefix, localName, namespaceURI, this);
235                 }
236
237                 public virtual XmlCDataSection CreateCDataSection (string data)
238                 {
239                         return new XmlCDataSection (data, this);
240                 }
241
242                 public virtual XmlComment CreateComment (string data)
243                 {
244                         return new XmlComment (data, this);
245                 }
246
247                 [MonoTODO]
248                 protected internal virtual XmlAttribute CreateDefaultAttribute (string prefix, string localName, string namespaceURI)
249                 {
250                         throw new NotImplementedException ();
251                 }
252
253                 public virtual XmlDocumentFragment CreateDocumentFragment ()
254                 {
255                         return new XmlDocumentFragment (this);
256                 }
257
258                 public virtual XmlDocumentType CreateDocumentType (string name, string publicId,
259                                                                    string systemId, string internalSubset)
260                 {
261                         return new XmlDocumentType (name, publicId, systemId, internalSubset, this);
262                 }
263
264                 public XmlElement CreateElement (string name)
265                 {
266                         return CreateElement (name, String.Empty);
267                 }
268
269                 public XmlElement CreateElement (
270                         string qualifiedName, 
271                         string namespaceURI)
272                 {
273                         string prefix;
274                         string localName;
275
276                         ParseName (qualifiedName, out prefix, out localName);
277
278                         return CreateElement (prefix, localName, namespaceURI);
279                 }
280
281                 public virtual XmlElement CreateElement (
282                         string prefix,
283                         string localName,
284                         string namespaceURI)
285                 {
286                         if ((localName == null) || (localName == String.Empty))
287                                 throw new ArgumentException ("The local name for elements or attributes cannot be null or an empty string.");
288
289                         return new XmlElement (prefix != null ? prefix : String.Empty, localName, namespaceURI != null ? namespaceURI : String.Empty, this);
290                 }
291
292                 public virtual XmlEntityReference CreateEntityReference (string name)
293                 {
294                         return new XmlEntityReference (name, this);
295                 }
296
297                 [MonoTODO]
298                 internal protected virtual XPathNavigator CreateNavigator (XmlNode node)
299                 {
300                         throw new NotImplementedException ();
301                 }
302
303                 public virtual XmlNode CreateNode (
304                         string nodeTypeString,
305                         string name,
306                         string namespaceURI)
307                 {
308                         return CreateNode (GetNodeTypeFromString (nodeTypeString), name, namespaceURI);
309                 }
310
311                 public virtual XmlNode CreateNode (
312                         XmlNodeType type,
313                         string name,
314                         string namespaceURI)
315                 {
316                         string prefix = null;
317                         string localName = name;
318
319                         if ((type == XmlNodeType.Attribute) || (type == XmlNodeType.Element) || (type == XmlNodeType.EntityReference))
320                                 ParseName (name, out prefix, out localName);
321                         
322                         return CreateNode (type, prefix, localName, namespaceURI);
323                 }
324
325                 public virtual XmlNode CreateNode (
326                         XmlNodeType type,
327                         string prefix,
328                         string name,
329                         string namespaceURI)
330                 {
331                         switch (type) {
332                                 case XmlNodeType.Attribute: return CreateAttribute (prefix, name, namespaceURI);
333                                 case XmlNodeType.CDATA: return CreateCDataSection (null);
334                                 case XmlNodeType.Comment: return CreateComment (null);
335                                 case XmlNodeType.Document: return new XmlDocument (); // TODO - test to see which constructor to use, i.e. use existing NameTable or not.
336                                 case XmlNodeType.DocumentFragment: return CreateDocumentFragment ();
337                                 case XmlNodeType.DocumentType: return CreateDocumentType (null, null, null, null);
338                                 case XmlNodeType.Element: return CreateElement (prefix, name, namespaceURI);
339                                 case XmlNodeType.EntityReference: return CreateEntityReference (null);
340                                 case XmlNodeType.ProcessingInstruction: return CreateProcessingInstruction (null, null);
341                                 case XmlNodeType.SignificantWhitespace: return CreateSignificantWhitespace (String.Empty);
342                                 case XmlNodeType.Text: return CreateTextNode (null);
343                                 case XmlNodeType.Whitespace: return CreateWhitespace (String.Empty);
344                                 case XmlNodeType.XmlDeclaration: return CreateXmlDeclaration ("1.0", null, null);
345                                 default: throw new ArgumentOutOfRangeException(String.Format("{0}\nParameter name: {1}",
346                                                          "Specified argument was out of the range of valid values", type.ToString ()));
347                         }
348                 }
349
350                 public virtual XmlProcessingInstruction CreateProcessingInstruction (
351                         string target,
352                         string data)
353                 {
354                         return new XmlProcessingInstruction (target, data, this);
355                 }
356
357                 public virtual XmlSignificantWhitespace CreateSignificantWhitespace (string text)
358                 {
359                         foreach (char c in text)
360                                 if ((c != ' ') && (c != '\r') && (c != '\n') && (c != '\t'))
361                                     throw new ArgumentException ("Invalid whitespace characters.");
362                          
363                         return new XmlSignificantWhitespace (text, this);
364                 }
365
366                 public virtual XmlText CreateTextNode (string text)
367                 {
368                         return new XmlText (text, this);
369                 }
370
371                 public virtual XmlWhitespace CreateWhitespace (string text)
372                 {
373                         foreach (char c in text)
374                                 if ((c != ' ') && (c != '\r') && (c != '\n') && (c != '\t'))
375                                     throw new ArgumentException ("Invalid whitespace characters.");
376                          
377                         return new XmlWhitespace (text, this);
378                 }
379
380                 public virtual XmlDeclaration CreateXmlDeclaration (string version, string encoding,
381                                                                     string standalone)
382                 {
383                         if (version != "1.0")
384                                 throw new ArgumentException ("version string is not correct.");
385
386                         if  ((standalone != null && standalone != String.Empty) && !((standalone == "yes") || (standalone == "no")))
387                                 throw new ArgumentException ("standalone string is not correct.");
388
389                         return new XmlDeclaration (version, encoding, standalone, this);
390                 }
391
392                 [MonoTODO]
393                 public virtual XmlElement GetElementById (string elementId)
394                 {
395                         throw new NotImplementedException ();
396                 }
397
398                 public virtual XmlNodeList GetElementsByTagName (string name)
399                 {
400                         ArrayList nodeArrayList = new ArrayList ();
401                         this.searchNodesRecursively (this, name, nodeArrayList);
402                         return new XmlNodeArrayList (nodeArrayList);
403                 }
404
405                 private void searchNodesRecursively (XmlNode argNode, string argName, 
406                         ArrayList argArrayList)
407                 {
408                         XmlNodeList xmlNodeList = argNode.ChildNodes;
409                         foreach (XmlNode node in xmlNodeList){
410                                 if (node.Name.Equals (argName))
411                                         argArrayList.Add (node);
412                                 else    
413                                         this.searchNodesRecursively (node, argName, argArrayList);
414                         }
415                 }
416
417                 private void searchNodesRecursively (XmlNode argNode, string argName, string argNamespaceURI, 
418                         ArrayList argArrayList)
419                 {
420                         XmlNodeList xmlNodeList = argNode.ChildNodes;
421                         foreach (XmlNode node in xmlNodeList){
422                                 if (node.LocalName.Equals (argName) && node.NamespaceURI.Equals (argNamespaceURI))
423                                         argArrayList.Add (node);
424                                 else    
425                                         this.searchNodesRecursively (node, argName, argNamespaceURI, argArrayList);
426                         }
427                 }
428
429                 public virtual XmlNodeList GetElementsByTagName (string localName, string namespaceURI)
430                 {
431                         ArrayList nodeArrayList = new ArrayList ();
432                         this.searchNodesRecursively (this, localName, namespaceURI, nodeArrayList);
433                         return new XmlNodeArrayList (nodeArrayList);
434                 }
435
436                 private XmlNodeType GetNodeTypeFromString (string nodeTypeString)
437                 {
438                         switch (nodeTypeString) {
439                                 case "attribute": return XmlNodeType.Attribute;
440                                 case "cdatasection": return XmlNodeType.CDATA;
441                                 case "comment": return XmlNodeType.Comment;
442                                 case "document": return XmlNodeType.Document;
443                                 case "documentfragment": return XmlNodeType.DocumentFragment;
444                                 case "documenttype": return XmlNodeType.DocumentType;
445                                 case "element": return XmlNodeType.Element;
446                                 case "entityreference": return XmlNodeType.EntityReference;
447                                 case "processinginstruction": return XmlNodeType.ProcessingInstruction;
448                                 case "significantwhitespace": return XmlNodeType.SignificantWhitespace;
449                                 case "text": return XmlNodeType.Text;
450                                 case "whitespace": return XmlNodeType.Whitespace;
451                                 default:
452                                         throw new ArgumentException(String.Format("The string doesn't represent any node type : {0}.", nodeTypeString));
453                         }
454                 }
455
456                 [MonoTODO("default attributes (of imported doc); Entity; Notation")]
457                 public virtual XmlNode ImportNode (XmlNode node, bool deep)
458                 {
459                         switch(node.NodeType)
460                         {
461                                 case XmlNodeType.Attribute:
462                                         {
463                                                 XmlAttribute src_att = node as XmlAttribute;
464                                                 XmlAttribute dst_att = this.CreateAttribute (src_att.Prefix, src_att.LocalName, src_att.NamespaceURI);
465                                                 dst_att.Value = src_att.Value;  // always explicitly specified (whether source is specified or not)
466                                                 return dst_att;
467                                         }
468
469                                 case XmlNodeType.CDATA:
470                                         return this.CreateCDataSection (node.Value);
471
472                                 case XmlNodeType.Comment:
473                                         return this.CreateComment (node.Value);
474
475                                 case XmlNodeType.Document:
476                                         throw new XmlException ("Document cannot be imported.");
477
478                                 case XmlNodeType.DocumentFragment:
479                                         {
480                                                 XmlDocumentFragment df = this.CreateDocumentFragment ();
481                                                 if(deep)
482                                                 {
483                                                         foreach(XmlNode n in node.ChildNodes)
484                                                         {
485                                                                 df.AppendChild (this.ImportNode (n, deep));
486                                                         }
487                                                 }
488                                                 return df;
489                                         }
490
491                                 case XmlNodeType.DocumentType:
492                                         throw new XmlException ("DocumentType cannot be imported.");
493
494                                 case XmlNodeType.Element:
495                                         {
496                                                 XmlElement src = (XmlElement)node;
497                                                 XmlElement dst = this.CreateElement (src.Prefix, src.LocalName, src.NamespaceURI);
498                                                 foreach(XmlAttribute attr in src.Attributes)
499                                                 {
500                                                         if(attr.Specified)      // copies only specified attributes
501                                                                 dst.SetAttributeNode ((XmlAttribute)this.ImportNode (attr, deep));
502                                                         if(DocumentType != null)
503                                                         {
504                                                                 // TODO: create default attribute values
505                                                         }
506                                                 }
507                                                 if(deep)
508                                                 {
509                                                         foreach(XmlNode n in src.ChildNodes)
510                                                                 dst.AppendChild (this.ImportNode (n, deep));
511                                                 }
512                                                 return dst;
513                                         }
514
515                                 case XmlNodeType.EndElement:
516                                         throw new XmlException ("Illegal ImportNode call for NodeType.EndElement");
517                                 case XmlNodeType.EndEntity:
518                                         throw new XmlException ("Illegal ImportNode call for NodeType.EndEntity");
519
520                                 case XmlNodeType.Entity:
521                                         throw new NotImplementedException ();   // TODO
522
523                                 case XmlNodeType.EntityReference:
524                                         return this.CreateEntityReference (node.Name);
525
526                                 case XmlNodeType.None:
527                                         throw new XmlException ("Illegal ImportNode call for NodeType.None");
528
529                                 case XmlNodeType.Notation:
530                                         throw new NotImplementedException ();   // TODO
531
532                                 case XmlNodeType.ProcessingInstruction:
533                                         XmlProcessingInstruction pi = node as XmlProcessingInstruction;
534                                         return this.CreateProcessingInstruction (pi.Target, pi.Data);
535
536                                 case XmlNodeType.SignificantWhitespace:
537                                         return this.CreateSignificantWhitespace (node.Value);
538
539                                 case XmlNodeType.Text:
540                                         return this.CreateTextNode (node.Value);
541
542                                 case XmlNodeType.Whitespace:
543                                         return this.CreateWhitespace (node.Value);
544
545                                 case XmlNodeType.XmlDeclaration:
546                                         XmlDeclaration srcDecl = node as XmlDeclaration;
547                                         return this.CreateXmlDeclaration (srcDecl.Version, srcDecl.Encoding, srcDecl.Standalone);
548
549                                 default:
550                                         throw new NotImplementedException ();
551                         }
552                 }
553
554                 public virtual void Load (Stream inStream)
555                 {
556                         XmlReader xmlReader = new XmlTextReader (inStream);
557                         Load (xmlReader);
558                 }
559
560                 public virtual void Load (string filename)
561                 {
562                         baseURI = filename;
563                         XmlReader xmlReader = new XmlTextReader (new StreamReader (filename));
564                         Load (xmlReader);
565                 }
566
567                 public virtual void Load (TextReader txtReader)
568                 {
569                         Load (new XmlTextReader (txtReader));
570                 }
571
572                 public virtual void Load (XmlReader xmlReader)
573                 {
574                         // Reset our document
575                         // For now this just means removing all our children but later this
576                         // may turn out o need to call a private method that resets other things
577                         // like properties we have, etc.
578                         RemoveAll ();
579
580                         XmlNode currentNode = this;
581
582                         // This method of XmlNode is previously written here.
583                         // Then I(ginga) moved them to use this logic with XmlElement.
584                         this.ConstructDOM(xmlReader, currentNode);
585                 }
586
587                 public virtual void LoadXml (string xml)
588                 {
589                         XmlReader xmlReader = new XmlTextReader (new StringReader (xml));
590                         Load (xmlReader);
591                 }
592
593                 internal void onNodeChanged (XmlNode node, XmlNode Parent)
594                 {
595                         if (NodeChanged != null)
596                                 NodeChanged (node, new XmlNodeChangedEventArgs
597                                         (XmlNodeChangedAction.Change,
598                                         node, Parent, Parent));
599                 }
600
601                 internal void onNodeChanging(XmlNode node, XmlNode Parent)
602                 {
603                         if (NodeChanging != null)
604                                 NodeChanging (node, new XmlNodeChangedEventArgs
605                                         (XmlNodeChangedAction.Change,
606                                         node, Parent, Parent));
607                 }
608
609                 internal void onNodeInserted (XmlNode node, XmlNode newParent)
610                 {
611                         if (NodeInserted != null)
612                                 NodeInserted (node, new XmlNodeChangedEventArgs
613                                         (XmlNodeChangedAction.Insert,
614                                         node, null, newParent));
615                 }
616
617                 internal void onNodeInserting (XmlNode node, XmlNode newParent)
618                 {
619                         if (NodeInserting != null)
620                                 NodeInserting (node, new XmlNodeChangedEventArgs
621                                         (XmlNodeChangedAction.Insert,
622                                         node, null, newParent));
623                 }
624
625                 internal void onNodeRemoved (XmlNode node, XmlNode oldParent)
626                 {
627                         if (NodeRemoved != null)
628                                 NodeRemoved (node, new XmlNodeChangedEventArgs
629                                         (XmlNodeChangedAction.Remove,
630                                         node, oldParent, null));
631                 }
632
633                 internal void onNodeRemoving (XmlNode node, XmlNode oldParent)
634                 {
635                         if (NodeRemoving != null)
636                                 NodeRemoving (node, new XmlNodeChangedEventArgs
637                                         (XmlNodeChangedAction.Remove,
638                                         node, oldParent, null));
639                 }
640
641                 private void ParseName (string name, out string prefix, out string localName)
642                 {
643                         int indexOfColon = name.IndexOf (':');
644                         
645                         if (indexOfColon != -1) {
646                                 prefix = name.Substring (0, indexOfColon);
647                                 localName = name.Substring (indexOfColon + 1);
648                         } else {
649                                 prefix = "";
650                                 localName = name;
651                         }
652                 }
653
654                 [MonoTODO]
655                 public virtual XmlNode ReadNode(XmlReader reader)
656                 {
657                         throw new NotImplementedException ();
658                 }
659
660                 public virtual void Save(Stream outStream)
661                 {
662                         XmlTextWriter xmlWriter = new XmlTextWriter (outStream, Encoding.UTF8);
663                         WriteContentTo (xmlWriter);
664                         xmlWriter.Close ();
665                 }
666
667                 public virtual void Save (string filename)
668                 {
669                         XmlTextWriter xmlWriter = new XmlTextWriter (filename, Encoding.UTF8);
670                         WriteContentTo (xmlWriter);
671                         xmlWriter.Close ();
672                 }
673
674                 [MonoTODO]
675                 public virtual void Save (TextWriter writer)
676                 {
677                         XmlTextWriter xmlWriter = new XmlTextWriter (writer);
678                         WriteContentTo (xmlWriter);
679                         xmlWriter.Flush ();
680                 }
681
682                 public virtual void Save (XmlWriter xmlWriter)
683                 {
684                         //
685                         // This should preserve white space if PreserveWhiteSpace is true
686                         //
687                         WriteContentTo (xmlWriter);
688                         xmlWriter.Flush ();
689                 }
690
691                 public override void WriteContentTo (XmlWriter w)
692                 {
693                         foreach(XmlNode childNode in ChildNodes) {
694                                 childNode.WriteTo (w);
695                                 if(!PreserveWhitespace) {
696                                         w.WriteRaw ("\n");
697                                 }
698                         }
699                 }
700
701                 public override void WriteTo (XmlWriter w)
702                 {
703                         WriteContentTo (w);
704                 }
705
706                 private void AddDefaultNameTableKeys ()
707                 {
708                         // The following keys are default of MS .NET Framework
709                         nameTable.Add ("#text");
710                         nameTable.Add ("xml");
711                         nameTable.Add ("xmlns");
712                         nameTable.Add ("#entity");
713                         nameTable.Add ("#document-fragment");
714                         nameTable.Add ("#comment");
715                         nameTable.Add ("space");
716                         nameTable.Add ("id");
717                         nameTable.Add ("#whitespace");
718                         nameTable.Add ("http://www.w3.org/2000/xmlns/");
719                         nameTable.Add ("#cdata-section");
720                         nameTable.Add ("lang");
721                         nameTable.Add ("#document");
722                         nameTable.Add ("#significant-whitespace");
723                 }
724                 #endregion
725         }
726 }