5 // Jason Diamond (jason@injektilo.org)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
9 // (C) 2001, 2002 Jason Diamond http://injektilo.org/
10 // (c) 2002 Ximian, Inc. (http://www.ximian.com)
11 // (C) 2003 Atsushi Enomoto
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Collections;
35 using System.Diagnostics;
38 using System.Xml.Schema; // only required for NET_2_0 (SchemaInfo)
39 using System.Xml.Serialization; // only required for NET_2_0 (SchemaInfo)
40 using Mono.Xml; // only required for NET_2_0
41 using Mono.Xml.Schema; // only required for NET_2_0
46 public abstract class XmlReader : IDisposable
48 public abstract class XmlReader
51 private StringBuilder readStringBuffer;
52 private XmlReaderBinarySupport binary;
54 private XmlReaderSettings settings;
59 protected XmlReader ()
67 public abstract int AttributeCount { get; }
69 public abstract string BaseURI { get; }
71 internal XmlReaderBinarySupport Binary {
72 get { return binary; }
75 internal XmlReaderBinarySupport.CharGetter BinaryCharGetter {
76 get { return binary != null ? binary.Getter : null; }
79 binary = new XmlReaderBinarySupport (this);
80 binary.Getter = value;
85 // To enable it internally in sys.xml, just insert these
86 // two lines into Read():
89 // if (Binary != null)
93 public virtual bool CanReadBinaryContent {
97 public virtual bool CanReadValueChunk {
101 internal virtual bool CanReadBinaryContent {
102 get { return false; }
105 internal virtual bool CanReadValueChunk {
106 get { return false; }
110 public virtual bool CanResolveEntity
112 get { return false; }
115 public abstract int Depth { get; }
117 public abstract bool EOF { get; }
119 public virtual bool HasAttributes
121 get { return AttributeCount > 0; }
124 public abstract bool HasValue { get; }
126 public abstract bool IsEmptyElement { get; }
129 public virtual bool IsDefault {
130 get { return false; }
133 public virtual string this [int i] {
134 get { return GetAttribute (i); }
137 public virtual string this [string name] {
138 get { return GetAttribute (name); }
141 public virtual string this [string name, string namespaceURI] {
142 get { return GetAttribute (name, namespaceURI); }
145 public abstract bool IsDefault { get; }
147 public abstract string this [int i] { get; }
149 public abstract string this [string name] { get; }
151 public abstract string this [string localName, string namespaceName] { get; }
154 public abstract string LocalName { get; }
157 public virtual string Name {
159 return Prefix.Length > 0 ?
160 String.Concat (Prefix, ":", LocalName) :
165 public abstract string Name { get; }
168 public abstract string NamespaceURI { get; }
170 public abstract XmlNameTable NameTable { get; }
172 public abstract XmlNodeType NodeType { get; }
174 public abstract string Prefix { get; }
177 public virtual char QuoteChar {
181 public abstract char QuoteChar { get; }
184 public abstract ReadState ReadState { get; }
187 public virtual IXmlSchemaInfo SchemaInfo {
191 public virtual XmlReaderSettings Settings {
192 get { return settings; }
196 public abstract string Value { get; }
199 public virtual string XmlLang {
200 get { return String.Empty; }
203 public virtual XmlSpace XmlSpace {
204 get { return XmlSpace.None; }
207 public abstract string XmlLang { get; }
209 public abstract XmlSpace XmlSpace { get; }
216 public abstract void Close ();
219 private static XmlNameTable PopulateNameTable (
220 XmlReaderSettings settings)
222 XmlNameTable nameTable = settings.NameTable;
223 if (nameTable == null)
224 nameTable = new NameTable ();
228 private static XmlParserContext PopulateParserContext (
229 XmlReaderSettings settings, string baseUri)
231 XmlNameTable nt = PopulateNameTable (settings);
232 return new XmlParserContext (nt,
233 new XmlNamespaceManager (nt),
238 private static XmlNodeType GetNodeType (
239 XmlReaderSettings settings)
241 ConformanceLevel level = settings != null ? settings.ConformanceLevel : ConformanceLevel.Auto;
243 level == ConformanceLevel.Fragment ?
244 XmlNodeType.Element :
245 XmlNodeType.Document;
248 public static XmlReader Create (Stream stream)
250 return Create (stream, null);
253 public static XmlReader Create (string url)
255 return Create (url, null);
258 public static XmlReader Create (TextReader reader)
260 return Create (reader, null);
263 public static XmlReader Create (string url, XmlReaderSettings settings)
265 return Create (url, settings, null);
268 public static XmlReader Create (Stream stream, XmlReaderSettings settings)
270 return Create (stream, settings, String.Empty);
273 public static XmlReader Create (TextReader reader, XmlReaderSettings settings)
275 return Create (reader, settings, String.Empty);
278 public static XmlReader Create (Stream stream, XmlReaderSettings settings, string baseUri)
280 if (settings == null)
281 settings = new XmlReaderSettings ();
282 return Create (stream, settings,
283 PopulateParserContext (settings, baseUri));
286 public static XmlReader Create (TextReader reader, XmlReaderSettings settings, string baseUri)
288 if (settings == null)
289 settings = new XmlReaderSettings ();
290 return Create (reader, settings,
291 PopulateParserContext (settings, baseUri));
294 [MonoTODO ("ConformanceLevel")]
295 public static XmlReader Create (XmlReader reader, XmlReaderSettings settings)
297 if (settings == null)
298 settings = new XmlReaderSettings ();
299 XmlReader r = CreateFilteredXmlReader (reader, settings);
300 r.settings = settings;
304 [MonoTODO ("ConformanceLevel")]
305 public static XmlReader Create (string url, XmlReaderSettings settings, XmlParserContext context)
307 if (settings == null)
308 settings = new XmlReaderSettings ();
310 context = PopulateParserContext (settings, url);
311 return CreateCustomizedTextReader (
312 new XmlTextReader (true, url, GetNodeType (settings), context),
316 [MonoTODO ("ConformanceLevel")]
317 public static XmlReader Create (Stream stream, XmlReaderSettings settings, XmlParserContext context)
319 if (settings == null)
320 settings = new XmlReaderSettings ();
322 context = PopulateParserContext (settings, String.Empty);
323 return CreateCustomizedTextReader (new XmlTextReader (stream, GetNodeType (settings), context), settings);
326 [MonoTODO ("ConformanceLevel")]
327 public static XmlReader Create (TextReader reader, XmlReaderSettings settings, XmlParserContext context)
329 if (settings == null)
330 settings = new XmlReaderSettings ();
332 context = PopulateParserContext (settings, String.Empty);
333 return CreateCustomizedTextReader (new XmlTextReader (context.BaseURI, reader, GetNodeType (settings), context), settings);
336 private static XmlReader CreateCustomizedTextReader (XmlTextReader reader, XmlReaderSettings settings)
338 reader.XmlResolver = settings.XmlResolver;
339 // Normalization is set true by default.
340 reader.Normalization = true;
342 if (settings.ProhibitDtd)
343 reader.ProhibitDtd = true;
345 if (!settings.CheckCharacters)
346 reader.CharacterChecking = false;
348 // I guess it might be changed in 2.0 RTM to set true
349 // as default, or just disappear. It goes against
350 // XmlTextReader's default usage and users will have
351 // to close input manually (that's annoying). Moreover,
352 // MS XmlTextReader consumes text input more than
353 // actually read and users can acquire those extra
354 // consumption by GetRemainder() that returns different
356 reader.CloseInput = settings.CloseInput;
358 // I would like to support it in detail later;
359 // MSDN description looks source of confusion. We don't
360 // need examples, but precise list of how it works.
361 reader.Conformance = settings.ConformanceLevel;
363 reader.AdjustLineInfoOffset (settings.LineNumberOffset,
364 settings.LinePositionOffset);
366 if (settings.NameTable != null)
367 reader.SetNameTable (settings.NameTable);
369 XmlReader r = CreateFilteredXmlReader (reader, settings);
370 r.settings = settings;
374 private static XmlReader CreateFilteredXmlReader (XmlReader reader, XmlReaderSettings settings)
376 reader = CreateValidatingXmlReader (reader, settings);
378 if (reader.Settings != null ||
379 settings.IgnoreComments ||
380 settings.IgnoreProcessingInstructions ||
381 settings.IgnoreWhitespace)
382 return new XmlFilterReader (reader, settings);
384 reader.settings = settings;
389 private static XmlReader CreateValidatingXmlReader (XmlReader reader, XmlReaderSettings settings)
391 XmlValidatingReader xvr = null;
392 switch (settings.ValidationType) {
393 case ValidationType.None:
395 case ValidationType.DTD:
396 xvr = new XmlValidatingReader (reader);
397 xvr.XmlResolver = settings.XmlResolver;
398 xvr.ValidationType = ValidationType.DTD;
400 case ValidationType.Schema:
401 // xvr = new XmlValidatingReader (reader);
402 // xvr.ValidationType = ValidationType.Schema;
403 return new XmlSchemaValidatingReader (reader, settings);
404 case ValidationType.Auto:
405 xvr = new XmlValidatingReader (reader);
406 xvr.ValidationType = ValidationType.DTD;
408 goto case ValidationType.Schema;
409 case ValidationType.XDR:
410 throw new NotSupportedException ();
413 xvr.SetSchemas (settings.Schemas);
415 // Actually I don't think they are treated in DTD validation though...
416 if ((settings.ValidationFlags & XmlSchemaValidationFlags.ProcessIdentityConstraints) == 0)
417 throw new NotImplementedException ();
418 if ((settings.ValidationFlags & XmlSchemaValidationFlags.ProcessInlineSchema) != 0)
419 throw new NotImplementedException ();
420 if ((settings.ValidationFlags & XmlSchemaValidationFlags.ProcessSchemaLocation) != 0)
421 throw new NotImplementedException ();
422 if ((settings.ValidationFlags & XmlSchemaValidationFlags.ReportValidationWarnings) == 0)
423 throw new NotImplementedException ();
425 return xvr != null ? xvr : reader;
430 void IDisposable.Dispose ()
435 protected virtual void Dispose (bool disposing)
437 if (ReadState != ReadState.Closed)
442 public abstract string GetAttribute (int i);
444 public abstract string GetAttribute (string name);
446 public abstract string GetAttribute (
448 string namespaceName);
450 public static bool IsName (string s)
452 return s != null && XmlChar.IsName (s);
455 public static bool IsNameToken (string s)
457 return s != null && XmlChar.IsNmToken (s);
460 public virtual bool IsStartElement ()
462 return (MoveToContent () == XmlNodeType.Element);
465 public virtual bool IsStartElement (string name)
467 if (!IsStartElement ())
470 return (Name == name);
473 public virtual bool IsStartElement (string localName, string namespaceName)
475 if (!IsStartElement ())
478 return (LocalName == localName && NamespaceURI == namespaceName);
481 public abstract string LookupNamespace (string prefix);
484 public virtual void MoveToAttribute (int i)
486 if (i >= AttributeCount)
487 throw new ArgumentOutOfRangeException ();
488 MoveToFirstAttribute ();
489 for (int a = 1; a < i; a++)
490 MoveToNextAttribute ();
493 public abstract void MoveToAttribute (int i);
496 public abstract bool MoveToAttribute (string name);
498 public abstract bool MoveToAttribute (
500 string namespaceName);
502 private bool IsContent (XmlNodeType nodeType)
505 * (non-white space text, CDATA, Element, EndElement, EntityReference, or EndEntity)
508 case XmlNodeType.Text:
510 case XmlNodeType.CDATA:
512 case XmlNodeType.Element:
514 case XmlNodeType.EndElement:
516 case XmlNodeType.EntityReference:
518 case XmlNodeType.EndEntity:
525 public virtual XmlNodeType MoveToContent ()
527 if (NodeType == XmlNodeType.Attribute)
531 if (IsContent (NodeType))
535 return XmlNodeType.None;
538 public abstract bool MoveToElement ();
540 public abstract bool MoveToFirstAttribute ();
542 public abstract bool MoveToNextAttribute ();
544 public abstract bool Read ();
546 public abstract bool ReadAttributeValue ();
548 public virtual string ReadElementString ()
550 if (MoveToContent () != XmlNodeType.Element) {
551 string error = String.Format ("'{0}' is an invalid node type.",
552 NodeType.ToString ());
553 throw XmlError (error);
556 string result = String.Empty;
557 if (!IsEmptyElement) {
559 result = ReadString ();
560 if (NodeType != XmlNodeType.EndElement) {
561 string error = String.Format ("'{0}' is an invalid node type.",
562 NodeType.ToString ());
563 throw XmlError (error);
571 public virtual string ReadElementString (string name)
573 if (MoveToContent () != XmlNodeType.Element) {
574 string error = String.Format ("'{0}' is an invalid node type.",
575 NodeType.ToString ());
576 throw XmlError (error);
580 string error = String.Format ("The {0} tag from namespace {1} is expected.",
582 throw XmlError (error);
585 string result = String.Empty;
586 if (!IsEmptyElement) {
588 result = ReadString ();
589 if (NodeType != XmlNodeType.EndElement) {
590 string error = String.Format ("'{0}' is an invalid node type.",
591 NodeType.ToString ());
592 throw XmlError (error);
600 public virtual string ReadElementString (string localName, string namespaceName)
602 if (MoveToContent () != XmlNodeType.Element) {
603 string error = String.Format ("'{0}' is an invalid node type.",
604 NodeType.ToString ());
605 throw XmlError (error);
608 if (localName != LocalName || NamespaceURI != namespaceName) {
609 string error = String.Format ("The {0} tag from namespace {1} is expected.",
610 LocalName, NamespaceURI);
611 throw XmlError (error);
614 string result = String.Empty;
615 if (!IsEmptyElement) {
617 result = ReadString ();
618 if (NodeType != XmlNodeType.EndElement) {
619 string error = String.Format ("'{0}' is an invalid node type.",
620 NodeType.ToString ());
621 throw XmlError (error);
629 public virtual void ReadEndElement ()
631 if (MoveToContent () != XmlNodeType.EndElement) {
632 string error = String.Format ("'{0}' is an invalid node type.",
633 NodeType.ToString ());
634 throw XmlError (error);
641 public abstract string ReadInnerXml ();
643 public abstract string ReadOuterXml ();
646 public virtual string ReadInnerXml ()
648 return ReadInnerXmlInternal ();
651 public virtual string ReadOuterXml ()
653 return ReadOuterXmlInternal ();
657 internal string ReadInnerXmlInternal ()
659 if (ReadState != ReadState.Interactive || NodeType == XmlNodeType.EndElement)
662 StringWriter sw = new StringWriter ();
663 XmlTextWriter xtw = new XmlTextWriter (sw);
664 if (NodeType == XmlNodeType.Element) {
665 if (IsEmptyElement) {
669 int startDepth = Depth;
671 while (startDepth < Depth) {
672 if (ReadState != ReadState.Interactive)
673 throw XmlError ("Unexpected end of the XML reader.");
674 xtw.WriteNode (this, false);
676 // reader is now end element, then proceed once more.
680 xtw.WriteNode (this, false);
682 return sw.ToString ();
685 internal string ReadOuterXmlInternal ()
687 if (ReadState != ReadState.Interactive || NodeType == XmlNodeType.EndElement)
690 StringWriter sw = new StringWriter ();
691 XmlTextWriter xtw = new XmlTextWriter (sw);
692 xtw.WriteNode (this, false);
693 return sw.ToString ();
696 public virtual void ReadStartElement ()
698 if (MoveToContent () != XmlNodeType.Element) {
699 string error = String.Format ("'{0}' is an invalid node type.",
700 NodeType.ToString ());
701 throw XmlError (error);
707 public virtual void ReadStartElement (string name)
709 if (MoveToContent () != XmlNodeType.Element) {
710 string error = String.Format ("'{0}' is an invalid node type.",
711 NodeType.ToString ());
712 throw XmlError (error);
716 string error = String.Format ("The {0} tag from namespace {1} is expected.",
718 throw XmlError (error);
724 public virtual void ReadStartElement (string localName, string namespaceName)
726 if (MoveToContent () != XmlNodeType.Element) {
727 string error = String.Format ("'{0}' is an invalid node type.",
728 NodeType.ToString ());
729 throw XmlError (error);
732 if (localName != LocalName || NamespaceURI != namespaceName) {
733 string error = String.Format ("Expecting {0} tag from namespace {1}, got {2} and {3} instead",
734 localName, namespaceName,
735 LocalName, NamespaceURI);
736 throw XmlError (error);
743 public abstract string ReadString ();
745 public virtual string ReadString ()
747 return ReadStringInternal ();
751 internal string ReadStringInternal ()
753 if (readStringBuffer == null)
754 readStringBuffer = new StringBuilder ();
755 readStringBuffer.Length = 0;
762 case XmlNodeType.Element:
768 case XmlNodeType.Text:
769 case XmlNodeType.CDATA:
770 case XmlNodeType.Whitespace:
771 case XmlNodeType.SignificantWhitespace:
772 readStringBuffer.Append (Value);
778 case XmlNodeType.Text:
779 case XmlNodeType.CDATA:
780 case XmlNodeType.Whitespace:
781 case XmlNodeType.SignificantWhitespace:
784 case XmlNodeType.Text:
785 case XmlNodeType.CDATA:
786 case XmlNodeType.Whitespace:
787 case XmlNodeType.SignificantWhitespace:
788 readStringBuffer.Append (Value);
796 string ret = readStringBuffer.ToString ();
797 readStringBuffer.Length = 0;
802 public virtual Type ValueType {
803 get { return typeof (string); }
807 public virtual bool ReadToDescendant (string name)
809 if (NodeType != XmlNodeType.Element || IsEmptyElement)
812 for (Read (); depth < Depth; Read ())
813 if (NodeType == XmlNodeType.Element && name == Name)
819 public virtual bool ReadToDescendant (string localName, string namespaceURI)
821 if (NodeType != XmlNodeType.Element || IsEmptyElement)
824 for (Read (); depth < Depth; Read ())
825 if (NodeType == XmlNodeType.Element && localName == LocalName && namespaceURI == NamespaceURI)
831 public virtual bool ReadToFollowing (string name)
834 if (NodeType == XmlNodeType.Element && name == Name)
840 public virtual bool ReadToFollowing (string localName, string namespaceURI)
843 if (NodeType == XmlNodeType.Element && localName == Name && namespaceURI == NamespaceURI)
849 public virtual bool ReadToNextSibling (string name)
851 if (NodeType != XmlNodeType.Element || IsEmptyElement)
854 for (Skip (); depth < Depth; Skip ())
855 if (NodeType == XmlNodeType.Element && name == Name)
861 public virtual bool ReadToNextSibling (string localName, string namespaceURI)
863 if (NodeType != XmlNodeType.Element || IsEmptyElement)
866 for (Skip (); depth < Depth; Skip ())
867 if (NodeType == XmlNodeType.Element && localName == LocalName && namespaceURI == NamespaceURI)
873 public virtual XmlReader ReadSubtree ()
875 return new SubtreeXmlReader (this);
878 private string ReadContentString ()
881 case XmlNodeType.Text:
882 case XmlNodeType.CDATA:
883 case XmlNodeType.SignificantWhitespace:
884 case XmlNodeType.Whitespace:
887 throw new InvalidOperationException (String.Format ("This method does not support node type {0}.", NodeType));
889 return ReadString ();
893 public virtual object ReadElementContentAsObject ()
895 return ReadElementContentAs (ValueType, null);
899 public virtual object ReadElementContentAsObject (string localName, string namespaceURI)
901 return ReadElementContentAs (ValueType, null, localName, namespaceURI);
905 public virtual object ReadContentAsObject ()
907 return ReadContentAs (ValueType, null);
911 public virtual object ReadElementContentAs (Type type, IXmlNamespaceResolver resolver)
913 return ValueAs (ReadElementString (), type, resolver);
917 public virtual object ReadElementContentAs (Type type, IXmlNamespaceResolver resolver, string localName, string namespaceURI)
919 return ValueAs (ReadElementString (localName, namespaceURI), type, resolver);
923 public virtual object ReadContentAs (Type type, IXmlNamespaceResolver resolver)
925 return ValueAs (ReadContentString (), type, resolver);
928 private object ValueAs (string text, Type type, IXmlNamespaceResolver resolver)
931 if (type == typeof (XmlQualifiedName))
932 return XmlQualifiedName.Parse (text, resolver);
934 switch (Type.GetTypeCode (type)) {
935 case TypeCode.Boolean:
936 return ReadContentAsBoolean ();
937 case TypeCode.DateTime:
938 return ReadContentAsDateTime ();
939 case TypeCode.Decimal:
940 return ReadContentAsDecimal ();
941 case TypeCode.Double:
942 return ReadContentAsDouble ();
944 return ReadContentAsInt ();
946 return ReadContentAsLong ();
947 case TypeCode.Single:
948 return ReadContentAsFloat ();
949 case TypeCode.String:
950 return ReadContentAsString ();
952 } catch (Exception ex) {
953 return new FormatException (String.Format ("Current text value '{0}' is not acceptable for specified type '{1}'.", text, type));
955 throw new ArgumentException (String.Format ("Specified type '{0}' is not supported.", type));
959 public virtual bool ReadElementContentAsBoolean ()
961 return XQueryConvert.StringToBoolean (ReadElementString ());
965 public virtual DateTime ReadElementContentAsDateTime ()
967 return XQueryConvert.StringToDateTime (ReadElementString ());
971 public virtual decimal ReadElementContentAsDecimal ()
973 return XQueryConvert.StringToDecimal (ReadElementString ());
977 public virtual double ReadElementContentAsDouble ()
979 return XQueryConvert.StringToDouble (ReadElementString ());
983 public virtual float ReadElementContentAsFloat ()
985 return XQueryConvert.StringToFloat (ReadElementString ());
989 public virtual int ReadElementContentAsInt ()
991 return XQueryConvert.StringToInt (ReadElementString ());
995 public virtual long ReadElementContentAsLong ()
997 return XQueryConvert.StringToInteger (ReadElementString ());
1001 public virtual string ReadElementContentAsString ()
1003 return ReadElementString ();
1007 public virtual bool ReadElementContentAsBoolean (string localName, string namespaceURI)
1009 return XQueryConvert.StringToBoolean (ReadElementString (localName, namespaceURI));
1013 public virtual DateTime ReadElementContentAsDateTime (string localName, string namespaceURI)
1015 return XQueryConvert.StringToDateTime (ReadElementString (localName, namespaceURI));
1019 public virtual decimal ReadElementContentAsDecimal (string localName, string namespaceURI)
1021 return XQueryConvert.StringToDecimal (ReadElementString (localName, namespaceURI));
1025 public virtual double ReadElementContentAsDouble (string localName, string namespaceURI)
1027 return XQueryConvert.StringToDouble (ReadElementString (localName, namespaceURI));
1031 public virtual float ReadElementContentAsFloat (string localName, string namespaceURI)
1033 return XQueryConvert.StringToFloat (ReadElementString (localName, namespaceURI));
1037 public virtual int ReadElementContentAsInt (string localName, string namespaceURI)
1039 return XQueryConvert.StringToInt (ReadElementString (localName, namespaceURI));
1043 public virtual long ReadElementContentAsLong (string localName, string namespaceURI)
1045 return XQueryConvert.StringToInteger (ReadElementString (localName, namespaceURI));
1049 public virtual string ReadElementContentAsString (string localName, string namespaceURI)
1051 return ReadElementString (localName, namespaceURI);
1055 public virtual bool ReadContentAsBoolean ()
1057 return XQueryConvert.StringToBoolean (ReadContentString ());
1061 public virtual DateTime ReadContentAsDateTime ()
1063 return XQueryConvert.StringToDateTime (ReadContentString ());
1067 public virtual decimal ReadContentAsDecimal ()
1069 return XQueryConvert.StringToDecimal (ReadContentString ());
1073 public virtual double ReadContentAsDouble ()
1075 return XQueryConvert.StringToDouble (ReadContentString ());
1079 public virtual float ReadContentAsFloat ()
1081 return XQueryConvert.StringToFloat (ReadContentString ());
1085 public virtual int ReadContentAsInt ()
1087 return XQueryConvert.StringToInt (ReadContentString ());
1091 public virtual long ReadContentAsLong ()
1093 return XQueryConvert.StringToInteger (ReadContentString ());
1097 public virtual string ReadContentAsString ()
1099 return ReadContentString ();
1102 public virtual int ReadContentAsBase64 (
1103 byte [] buffer, int offset, int length)
1106 return binary.ReadContentAsBase64 (
1107 buffer, offset, length);
1110 public virtual int ReadContentAsBinHex (
1111 byte [] buffer, int offset, int length)
1114 return binary.ReadContentAsBinHex (
1115 buffer, offset, length);
1118 public virtual int ReadElementContentAsBase64 (
1119 byte [] buffer, int offset, int length)
1122 return binary.ReadElementContentAsBase64 (
1123 buffer, offset, length);
1126 public virtual int ReadElementContentAsBinHex (
1127 byte [] buffer, int offset, int length)
1130 return binary.ReadElementContentAsBinHex (
1131 buffer, offset, length);
1136 public virtual int ReadValueChunk (
1137 char [] buffer, int offset, int length)
1139 internal virtual int ReadValueChunk (
1140 char [] buffer, int offset, int length)
1143 if (!CanReadValueChunk)
1144 throw new NotSupportedException ();
1146 binary = new XmlReaderBinarySupport (this);
1147 return binary.ReadValueChunk (buffer, offset, length);
1150 private void CheckSupport ()
1152 // Default implementation expects both.
1153 if (!CanReadBinaryContent || !CanReadValueChunk)
1154 throw new NotSupportedException ();
1156 binary = new XmlReaderBinarySupport (this);
1159 public abstract void ResolveEntity ();
1161 public virtual void Skip ()
1163 if (ReadState != ReadState.Interactive)
1167 if (NodeType != XmlNodeType.Element || IsEmptyElement) {
1173 while (Read () && depth < Depth)
1175 if (NodeType == XmlNodeType.EndElement)
1179 private XmlException XmlError (string message)
1181 return new XmlException (this as IXmlLineInfo, BaseURI, message);