2 // System.Xml.XmlDocumentFragment
\r
5 // Duncan Mak (duncan@ximian.com)
\r
6 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
\r
9 // (C)2002 Atsushi Enomoto
\r
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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.
34 using System.Xml.XPath;
\r
36 namespace System.Xml
\r
38 public class XmlDocumentFragment : XmlNode
\r
43 protected internal XmlDocumentFragment (XmlDocument doc)
\r
52 public override string InnerXml {
\r
54 // Copied from XmlElement.InnerXml (in the meantime;-))
\r
55 for (int i = 0; i < ChildNodes.Count; i++)
\r
56 this.RemoveChild (ChildNodes [i]);
\r
58 // I hope there are any well-performance logic...
\r
59 XmlNamespaceManager nsmgr = this.ConstructNamespaceManager ();
\r
60 XmlParserContext ctx = new XmlParserContext (OwnerDocument.NameTable, nsmgr,
61 OwnerDocument.DocumentType != null ? OwnerDocument.DocumentType.DTD : null,
62 BaseURI, XmlLang, XmlSpace, null);
63 XmlTextReader xmlReader = new XmlTextReader (value, XmlNodeType.Element, ctx);
\r
64 xmlReader.XmlResolver = OwnerDocument.Resolver;
\r
67 XmlNode n = OwnerDocument.ReadNode (xmlReader);
\r
68 if(n == null) break;
\r
73 StringBuilder sb = new StringBuilder ();
\r
74 for (int i = 0; i < ChildNodes.Count; i++)
75 sb.Append (ChildNodes [i].OuterXml);
\r
76 return sb.ToString ();
\r
80 public override string LocalName {
\r
81 get { return "#document-fragment"; }
\r
85 public override string Name {
\r
86 get { return "#document-fragment"; }
\r
89 public override XmlNodeType NodeType {
\r
90 get { return XmlNodeType.DocumentFragment; }
\r
93 public override XmlDocument OwnerDocument {
\r
94 get { return base.OwnerDocument; }
\r
97 public override XmlNode ParentNode {
\r
98 get { return null; } // it's always null here.
\r
101 internal override XPathNodeType XPathNodeType
\r
103 get { return XPathNodeType.Root; }
\r
108 public override XmlNode CloneNode (bool deep)
\r
110 if (deep) { // clone document + child nodes
\r
111 XmlNode node = FirstChild;
\r
113 while ((node != null) && (node.HasChildNodes)) {
\r
114 AppendChild (node.NextSibling.CloneNode (false));
\r
115 node = node.NextSibling;
\r
120 return new XmlDocumentFragment (OwnerDocument);
\r
123 public override void WriteContentTo (XmlWriter w)
\r
125 for (int i = 0; i < ChildNodes.Count; i++)
126 ChildNodes [i].WriteContentTo (w);
\r
129 public override void WriteTo (XmlWriter w)
\r
131 for (int i = 0; i < ChildNodes.Count; i++)
132 ChildNodes [i].WriteTo (w);
\r