using System.Diagnostics;
using System.IO;
using System.Text;
+#if !NET_2_1
using System.Xml.Schema; // only required for NET_2_0 (SchemaInfo)
using System.Xml.Serialization; // only required for NET_2_0 (SchemaInfo)
-using Mono.Xml; // only required for NET_2_0
using Mono.Xml.Schema; // only required for NET_2_0
+#endif
+using Mono.Xml; // only required for NET_2_0
namespace System.Xml
{
get { return AttributeCount > 0; }
}
+#if !NET_2_1
public abstract bool HasValue { get; }
+#endif
public abstract bool IsEmptyElement { get; }
public abstract ReadState ReadState { get; }
#if NET_2_0
+#if !NET_2_1
public virtual IXmlSchemaInfo SchemaInfo {
get { return null; }
}
+#endif
public virtual XmlReaderSettings Settings {
get { return settings; }
XmlNameTable nt = PopulateNameTable (settings);
return new XmlParserContext (nt,
new XmlNamespaceManager (nt),
+ null,
+ null,
+ null,
+ null,
baseUri,
- XmlSpace.None);
+ null,
+ XmlSpace.None,
+ null);
}
private static XmlNodeType GetNodeType (
public static XmlReader Create (string url, XmlReaderSettings settings, XmlParserContext context)
{
settings = PopulateSettings (settings);
- if (context == null)
- context = PopulateParserContext (settings, url);
- XmlTextReader xtr = new XmlTextReader (true, url, GetNodeType (settings), context);
- XmlReader ret = CreateCustomizedTextReader (xtr, settings);
- xtr.CloseInput = true;
- return xtr;
+ bool closeInputBak = settings.CloseInput;
+ try {
+ settings.CloseInput = true; // forced. See XmlReaderCommonTests.CreateFromUrlClose().
+ if (context == null)
+ context = PopulateParserContext (settings, url);
+ XmlTextReader xtr = new XmlTextReader (false, settings.XmlResolver, url, GetNodeType (settings), context);
+ XmlReader ret = CreateCustomizedTextReader (xtr, settings);
+ return ret;
+ } finally {
+ settings.CloseInput = closeInputBak;
+ }
}
public static XmlReader Create (Stream stream, XmlReaderSettings settings, XmlParserContext context)
reader.XmlResolver = settings.XmlResolver;
// Normalization is set true by default.
reader.Normalization = true;
+ reader.EntityHandling = EntityHandling.ExpandEntities;
if (settings.ProhibitDtd)
reader.ProhibitDtd = true;
reader = CreateValidatingXmlReader (reader, settings);
- if (reader.Settings != null ||
- settings.IgnoreComments ||
- settings.IgnoreProcessingInstructions ||
- settings.IgnoreWhitespace)
+ if ( settings.IgnoreComments ||
+ settings.IgnoreProcessingInstructions ||
+ settings.IgnoreWhitespace)
return new XmlFilterReader (reader, settings);
else {
reader.settings = settings;
private static XmlReader CreateValidatingXmlReader (XmlReader reader, XmlReaderSettings settings)
{
+#if NET_2_1
+ return reader;
+#else
XmlValidatingReader xvr = null;
switch (settings.ValidationType) {
// Auto and XDR are obsoleted in 2.0 and therefore ignored.
// throw new NotImplementedException ();
return xvr != null ? xvr : reader;
- }
#endif
+ }
-#if NET_2_0
void IDisposable.Dispose ()
{
Dispose (false);
if (i >= AttributeCount)
throw new ArgumentOutOfRangeException ();
MoveToFirstAttribute ();
- for (int a = 1; a < i; a++)
+ for (int a = 0; a < i; a++)
MoveToNextAttribute ();
}
#else
public abstract bool Read ();
+#if !NET_2_1
public abstract bool ReadAttributeValue ();
+#endif
public virtual string ReadElementString ()
{
if (ReadState != ReadState.Interactive)
return false;
int depth = Depth;
- for (Skip (); depth >= Depth; Skip ())
+ Skip ();
+ for (; !EOF && depth <= Depth; Skip ())
if (NodeType == XmlNodeType.Element && name == Name)
return true;
return false;
if (ReadState != ReadState.Interactive)
return false;
int depth = Depth;
- for (Skip (); depth >= Depth; Skip ())
+ Skip ();
+ for (; !EOF && depth <= Depth; Skip ())
if (NodeType == XmlNodeType.Element && localName == LocalName && namespaceURI == NamespaceURI)
return true;
return false;
public virtual XmlReader ReadSubtree ()
{
+ if (NodeType != XmlNodeType.Element)
+ throw new InvalidOperationException ("ReadSubtree() can be invoked only when the reader is positioned on an element");
return new SubtreeXmlReader (this);
}
public virtual string ReadElementContentAsString (string localName, string namespaceURI)
{
+ bool isEmpty = IsEmptyElement;
ReadStartElement (localName, namespaceURI);
- if (IsEmptyElement)
+ if (isEmpty)
return String.Empty;
string s = ReadContentString (false);
ReadEndElement ();
return binary.ReadElementContentAsBinHex (
buffer, offset, length);
}
+
+ private void CheckSupport ()
+ {
+ // Default implementation expects both.
+ if (!CanReadBinaryContent || !CanReadValueChunk)
+ throw new NotSupportedException ();
+ if (binary == null)
+ binary = new XmlReaderBinarySupport (this);
+ }
+
#endif
#if NET_2_0
return binary.ReadValueChunk (buffer, offset, length);
}
- private void CheckSupport ()
- {
- // Default implementation expects both.
- if (!CanReadBinaryContent || !CanReadValueChunk)
- throw new NotSupportedException ();
- if (binary == null)
- binary = new XmlReaderBinarySupport (this);
- }
-
public abstract void ResolveEntity ();
public virtual void Skip ()
{
return new XmlException (this as IXmlLineInfo, BaseURI, message);
}
-
+#if NET_2_0
private XmlException XmlError (string message, Exception innerException)
{
return new XmlException (this as IXmlLineInfo, BaseURI, message);
}
-
+#endif
#endregion
}
}