2 // System.Xml.XmlNodeReader.cs
5 // Duncan Mak (duncan@ximian.com)
11 using System.Collections;
16 public class XmlNodeReader : XmlReader
21 ReadState state = ReadState.Initial;
24 public XmlNodeReader (XmlNode node)
33 public override int AttributeCount {
35 return ((ICollection) current.Attributes).Count;
39 public override string BaseURI {
40 get { return current.BaseURI; }
43 public override bool CanResolveEntity {
47 public override int Depth {
52 public override bool EOF {
56 public override bool HasAttributes {
58 if (current.Attributes == null)
65 public override bool HasValue {
67 if (current.NodeType == XmlNodeType.Element ||
68 current.NodeType == XmlNodeType.EntityReference ||
69 current.NodeType == XmlNodeType.Document ||
70 current.NodeType == XmlNodeType.DocumentFragment ||
71 current.NodeType == XmlNodeType.Notation ||
72 current.NodeType == XmlNodeType.EndElement ||
73 current.NodeType == XmlNodeType.EndEntity)
82 public override bool IsDefault {
84 if (current.NodeType != XmlNodeType.Attribute)
92 public override bool IsEmptyElement {
94 if (current.NodeType == XmlNodeType.Entity &&
95 ((XmlEntity) current).Value.EndsWith ("/>"))
102 public override string this [int i] {
104 if (i < 0 || i > AttributeCount)
105 throw new ArgumentOutOfRangeException ("i is out of range.");
107 return current.Attributes [i].Value;
111 public override string this [string name] {
113 string ret = current.Attributes [name].Value;
122 public override string this [string name, string namespaceURI] {
124 string ret = current.Attributes [name].Value;
133 public override string LocalName {
135 if (current is XmlCharacterData)
138 return current.LocalName;
142 public override string Name {
143 get { return current.Name; }
146 public override string NamespaceURI {
148 return current.NamespaceURI;
153 public override XmlNameTable NameTable {
157 public override XmlNodeType NodeType {
159 return current.NodeType;
163 public override string Prefix {
165 return current.Prefix;
169 public override char QuoteChar {
173 public override ReadState ReadState {
174 get { return state; }
177 public override string Value {
178 get { return current.Value; }
182 public override string XmlLang {
183 get { return String.Empty; }
187 public override XmlSpace XmlSpace {
194 public override void Close ()
197 state = ReadState.Closed;
200 public override string GetAttribute (int attributeIndex)
202 return this [attributeIndex];
205 public override string GetAttribute (string name)
210 public override string GetAttribute (string name, string namespaceURI)
212 return this [name, namespaceURI];
216 public override string LookupNamespace (string prefix)
221 public override void MoveToAttribute (int attributeIndex)
223 if (attributeIndex < 0 || attributeIndex > AttributeCount)
224 throw new ArgumentOutOfRangeException ();
226 state = ReadState.Interactive;
227 current = current.Attributes [attributeIndex];
230 public override bool MoveToAttribute (string name)
232 if (GetAttribute (name) == null)
238 public override bool MoveToAttribute (string name, string namespaceURI)
240 if (GetAttribute (name, namespaceURI) == null)
246 public override bool MoveToElement ()
248 if (current.NodeType == XmlNodeType.Attribute) {
249 current = ((XmlAttribute) current).OwnerElement;
256 public override bool MoveToFirstAttribute ()
262 public override bool MoveToNextAttribute ()
264 if (current.NodeType != XmlNodeType.Attribute)
265 return MoveToFirstAttribute ();
271 public override bool Read ()
277 public override bool ReadAttributeValue ()
282 public override string ReadInnerXml ()
284 if (current.NodeType != XmlNodeType.Attribute &&
285 current.NodeType != XmlNodeType.Element)
288 return current.InnerXml;
291 public override string ReadOuterXml ()
293 if (current.NodeType != XmlNodeType.Attribute &&
294 current.NodeType != XmlNodeType.Element)
297 return current.OuterXml;
301 public override string ReadString ()
307 public override void ResolveEntity ()
309 if (current.NodeType != XmlNodeType.EntityReference)
310 throw new InvalidOperationException ("The current node is not an Entity Reference");
314 public override void Skip ()