(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Mono.Xml.Ext / Mono.Xml / SubtreeXmlReader.cs
blob3d22e59dc50d882a9c54914a4cfdcf767d907a9e
1 //
2 // SubtreeXmlReader.cs - reads descendant nodes in XmlReader
3 //
4 // Author:
5 // Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (c) 2004 Novell Inc. All rights reserved
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #if NET_2_0
31 using System;
32 using System.Collections;
33 using System.Xml;
35 namespace Mono.Xml
37 public class SubtreeXmlReader : XmlReader, IXmlLineInfo, IXmlNamespaceResolver
39 int startDepth;
40 bool eof;
41 bool initial;
42 bool read;
43 XmlReader Reader;
44 IXmlLineInfo li;
45 IXmlNamespaceResolver nsResolver;
47 public SubtreeXmlReader (XmlReader reader)
49 this.Reader = reader;
50 li = reader as IXmlLineInfo;
51 nsResolver = reader as IXmlNamespaceResolver;
52 initial = true;
53 startDepth = reader.Depth;
54 if (reader.ReadState == ReadState.Initial)
55 startDepth = -1; // end == the reader's end
58 public override int AttributeCount {
59 get { return initial ? 0 : Reader.AttributeCount; }
62 public override int Depth {
63 get { return Reader.Depth - startDepth; }
66 public override string BaseURI {
67 get { return Reader.BaseURI; }
70 public override bool EOF {
71 get { return eof || Reader.EOF; }
74 public int LineNumber {
75 get { return initial ? 0 : li != null ? li.LineNumber : 0; }
78 public int LinePosition {
79 get { return initial ? 0 : li != null ? li.LinePosition : 0; }
82 public override bool HasValue {
83 get { return initial ? false : Reader.HasValue; }
86 public override string LocalName {
87 get { return initial ? String.Empty : Reader.LocalName; }
90 public override string Name {
91 get { return initial ? String.Empty : Reader.Name; }
94 public override XmlNameTable NameTable {
95 get { return Reader.NameTable; }
98 public override string NamespaceURI {
99 get { return initial ? String.Empty : Reader.NamespaceURI; }
102 public override XmlNodeType NodeType {
103 get { return initial ? XmlNodeType.None : Reader.NodeType; }
106 public override string Prefix {
107 get { return initial ? String.Empty : Reader.Prefix; }
110 public override ReadState ReadState {
111 get { return initial ? ReadState.Initial : eof ? ReadState.EndOfFile : Reader.ReadState ; }
114 public override XmlReaderSettings Settings {
115 get { return Reader.Settings; }
118 public override string Value {
119 get { return initial ? String.Empty : Reader.Value; }
122 public override void Close ()
124 // do nothing
127 public override string GetAttribute (int i)
129 return initial ? null : Reader.GetAttribute (i);
132 public override string GetAttribute (string name)
134 return initial ? null : Reader.GetAttribute (name);
137 public override string GetAttribute (string local, string ns)
139 return initial ? null : Reader.GetAttribute (local, ns);
142 IDictionary IXmlNamespaceResolver.GetNamespacesInScope (XmlNamespaceScope scope)
144 return nsResolver != null ? nsResolver.GetNamespacesInScope (scope) : new Hashtable ();
147 public bool HasLineInfo ()
149 return li != null ? li.HasLineInfo () : false;
152 public override string LookupNamespace (string prefix)
154 return Reader.LookupNamespace (prefix);
157 string IXmlNamespaceResolver.LookupPrefix (string ns)
159 return nsResolver != null ? nsResolver.LookupPrefix (ns) : String.Empty;
162 string IXmlNamespaceResolver.LookupPrefix (string ns, bool atomizedNames)
164 return nsResolver != null ? nsResolver.LookupPrefix (ns, atomizedNames) : String.Empty;
167 public override bool MoveToFirstAttribute ()
169 return initial ? false : Reader.MoveToFirstAttribute ();
172 public override bool MoveToNextAttribute ()
174 return initial ? false : Reader.MoveToNextAttribute ();
177 public override void MoveToAttribute (int i)
179 if (!initial)
180 Reader.MoveToAttribute (i);
183 public override bool MoveToAttribute (string name)
185 return initial ? false : Reader.MoveToAttribute (name);
188 public override bool MoveToAttribute (string local, string ns)
190 return initial ? false : Reader.MoveToAttribute (local, ns);
193 public override bool MoveToElement ()
195 return initial ? false : Reader.MoveToElement ();
198 public override bool Read ()
200 if (initial) {
201 initial = false;
202 return true;
204 if (!read) {
205 read = true;
206 return !Reader.IsEmptyElement && Reader.Read ();
208 if (Reader.Depth > startDepth)
209 if (Reader.Read ())
210 return true;
211 eof = true;
212 return false;
215 public override bool ReadAttributeValue ()
217 if (initial || eof)
218 return false;
219 return Reader.ReadAttributeValue ();
222 public override void ResolveEntity ()
224 if (initial || eof)
225 return;
226 Reader.ResolveEntity ();
231 #endif