Remove confusing trailing dot
[mono.git] / mcs / class / System.XML / System.Xml / XmlDocumentFragment.cs
1 //
2 // System.Xml.XmlDocumentFragment
3 //
4 // Author:
5 //   Duncan Mak  (duncan@ximian.com)
6 //   Atsushi Enomoto  (ginga@kit.hi-ho.ne.jp)
7 //
8 // (C), Ximian, Inc
9 // (C)2002 Atsushi Enomoto
10
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31 using System;
32 using System.IO;
33 using System.Text;
34 using System.Xml.XPath;
35
36 namespace System.Xml
37 {
38         public class XmlDocumentFragment : XmlNode, IHasXmlChildNode
39         {
40                 XmlLinkedNode lastLinkedChild;
41
42                 #region Constructor
43
44                 protected internal XmlDocumentFragment (XmlDocument ownerDocument)
45                         : base (ownerDocument)
46                 {
47                 }
48                 
49                 #endregion
50
51                 #region Properties
52
53                 XmlLinkedNode IHasXmlChildNode.LastLinkedChild {
54                         get { return lastLinkedChild; }
55                         set { lastLinkedChild = value; }
56                 }
57
58                 public override string InnerXml {
59                         set {
60                                 // Copied from XmlElement.InnerXml (in the meantime;-))
61                                 for (int i = 0; i < ChildNodes.Count; i++)
62                                         this.RemoveChild (ChildNodes [i]);
63
64                                 // I hope there are any well-performance logic...
65                                 XmlNamespaceManager nsmgr = this.ConstructNamespaceManager ();
66                                 XmlParserContext ctx = new XmlParserContext (OwnerDocument.NameTable, nsmgr,
67                                         OwnerDocument.DocumentType != null ? OwnerDocument.DocumentType.DTD : null,
68                                         BaseURI, XmlLang, XmlSpace, null);
69                                 XmlTextReader xmlReader = new XmlTextReader (value, XmlNodeType.Element, ctx);
70                                 xmlReader.XmlResolver = OwnerDocument.Resolver;
71
72                                 do {
73                                         XmlNode n = OwnerDocument.ReadNode (xmlReader);
74                                         if(n == null) break;
75                                         AppendChild (n);
76                                 } while (true);
77                         }
78                         get {
79                                 StringBuilder sb = new StringBuilder ();
80                                 for (int i = 0; i < ChildNodes.Count; i++)
81                                         sb.Append (ChildNodes [i].OuterXml);
82                                 return sb.ToString ();
83                         }
84                 }
85                 
86                 public override string LocalName {
87                         get { return "#document-fragment"; }
88                 }
89
90
91                 public override string Name { 
92                         get { return "#document-fragment"; }
93                 }
94
95                 public override XmlNodeType NodeType {
96                         get { return XmlNodeType.DocumentFragment; }
97                 }
98
99                 public override XmlDocument OwnerDocument {
100                         get { return base.OwnerDocument; }
101                 }
102
103                 public override XmlNode ParentNode {
104                         get { return null; } // it's always null here.
105                 }
106
107                 internal override XPathNodeType XPathNodeType
108                 {
109                         get { return XPathNodeType.Root; }
110                 }
111                 #endregion
112
113                 #region Methods         
114                 public override XmlNode CloneNode (bool deep)
115                 {
116                         if (deep) { // clone document + child nodes
117                                 XmlNode node = FirstChild;
118
119                                 while ((node != null) && (node.HasChildNodes)) {
120                                         AppendChild (node.NextSibling.CloneNode (false));
121                                         node = node.NextSibling;
122                                 }
123
124                                 return node;
125                         } else
126                                 return new XmlDocumentFragment (OwnerDocument);
127                 }
128
129                 public override void WriteContentTo (XmlWriter w)
130                 {
131                         for (int i = 0; i < ChildNodes.Count; i++)
132                                 ChildNodes [i].WriteContentTo (w);
133                 }
134
135                 public override void WriteTo (XmlWriter w)
136                 {
137                         for (int i = 0; i < ChildNodes.Count; i++)
138                                 ChildNodes [i].WriteTo (w);
139                 }
140
141                 #endregion
142         }
143 }