Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>2002-09-14 00:39:10 +0400
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>2002-09-14 00:39:10 +0400
commite3f40371618b4440117de2f34c586b6fe7a16043 (patch)
tree28848c6777ea8d98e576c5ee46418e7a3219f590 /mcs/class/System.XML/System.Xml
parente53b062a80b8ee08f76143e675d8589566a46f7a (diff)
2002-09-13 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* XmlException.cs: added a new internal constructor for IXmlLineInfo and output line and position info in Message. * XmlReader.cs: implemented missing bits. svn path=/trunk/mcs/; revision=7440
Diffstat (limited to 'mcs/class/System.XML/System.Xml')
-rw-r--r--mcs/class/System.XML/System.Xml/ChangeLog7
-rwxr-xr-xmcs/class/System.XML/System.Xml/XmlException.cs19
-rw-r--r--mcs/class/System.XML/System.Xml/XmlReader.cs203
3 files changed, 190 insertions, 39 deletions
diff --git a/mcs/class/System.XML/System.Xml/ChangeLog b/mcs/class/System.XML/System.Xml/ChangeLog
index 85f0dda994f..17928bc6125 100644
--- a/mcs/class/System.XML/System.Xml/ChangeLog
+++ b/mcs/class/System.XML/System.Xml/ChangeLog
@@ -1,3 +1,10 @@
+2002-09-13 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * XmlException.cs: added a new internal constructor for IXmlLineInfo
+ and output line and position info in Message.
+
+ * XmlReader.cs: implemented missing bits.
+
2002-09-12 Piers Haken <piersh@friksit.com>
* XmlDocumentNavigator.cs: implement MoveToId()
diff --git a/mcs/class/System.XML/System.Xml/XmlException.cs b/mcs/class/System.XML/System.Xml/XmlException.cs
index f6efec719ad..e0aa241752d 100755
--- a/mcs/class/System.XML/System.Xml/XmlException.cs
+++ b/mcs/class/System.XML/System.Xml/XmlException.cs
@@ -17,7 +17,6 @@ namespace System.Xml
{
#region Fields
- string msg; // Cache message here because SystemException doesn't expose it
int lineNumber;
int linePosition;
@@ -28,7 +27,6 @@ namespace System.Xml
public XmlException (string message, Exception innerException)
: base (message, innerException)
{
- msg = message;
}
protected XmlException (SerializationInfo info, StreamingContext context)
@@ -41,9 +39,16 @@ namespace System.Xml
internal XmlException (string message)
: base (message)
{
- msg = message;
}
+ internal XmlException (IXmlLineInfo li, string message) : base (message)
+ {
+ if (li != null) {
+ this.lineNumber = li.LineNumber;
+ this.linePosition = li.LinePosition;
+ }
+ }
+
internal XmlException (string message, int lineNumber, int linePosition) : base (message)
{
this.lineNumber = lineNumber;
@@ -63,7 +68,13 @@ namespace System.Xml
}
public override string Message {
- get { return msg; }
+ get {
+ if (lineNumber == 0)
+ return base.Message;
+
+ return String.Format ("{0} Line {1}, position {2}.",
+ base.Message, lineNumber, linePosition);
+ }
}
#endregion
diff --git a/mcs/class/System.XML/System.Xml/XmlReader.cs b/mcs/class/System.XML/System.Xml/XmlReader.cs
index c2cd2f6541a..6e4d243b2f6 100644
--- a/mcs/class/System.XML/System.Xml/XmlReader.cs
+++ b/mcs/class/System.XML/System.Xml/XmlReader.cs
@@ -1,10 +1,12 @@
//
// XmlReader.cs
//
-// Author:
-// Jason Diamond (jason@injektilo.org)
+// Authors:
+// Jason Diamond (jason@injektilo.org)
+// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
// (C) 2001, 2002 Jason Diamond http://injektilo.org/
+// (c) 2002 Ximian, Inc. (http://www.ximian.com)
//
namespace System.Xml
@@ -130,24 +132,25 @@ namespace System.Xml
return result;
}
- [MonoTODO]
public virtual bool IsStartElement ()
{
- throw new NotImplementedException ();
+ return (MoveToContent () == XmlNodeType.Element);
}
- [MonoTODO]
public virtual bool IsStartElement (string name)
{
- throw new NotImplementedException ();
+ if (!IsStartElement ())
+ return false;
+
+ return (Name == name);
}
- [MonoTODO]
- public virtual bool IsStartElement (
- string localName,
- string namespaceName)
+ public virtual bool IsStartElement (string localName, string namespaceName)
{
- throw new NotImplementedException ();
+ if (!IsStartElement ())
+ return false;
+
+ return (LocalName == localName && NamespaceURI == namespaceName);
}
public abstract string LookupNamespace (string prefix);
@@ -160,10 +163,38 @@ namespace System.Xml
string localName,
string namespaceName);
- [MonoTODO]
+ private bool IsContent (XmlNodeType nodeType)
+ {
+ /* MS doc says:
+ * (non-white space text, CDATA, Element, EndElement, EntityReference, or EndEntity)
+ */
+ switch (nodeType) {
+ case XmlNodeType.Text:
+ return true;
+ case XmlNodeType.CDATA:
+ return true;
+ case XmlNodeType.Element:
+ return true;
+ case XmlNodeType.EndElement:
+ return true;
+ case XmlNodeType.EntityReference:
+ return true;
+ case XmlNodeType.EndEntity:
+ return true;
+ }
+
+ return false;
+ }
+
public virtual XmlNodeType MoveToContent ()
{
- throw new NotImplementedException ();
+ do {
+ XmlNodeType nodeType = NodeType;
+ if (IsContent (nodeType))
+ return nodeType;
+ } while (Read ());
+
+ return XmlNodeType.None;
}
public abstract bool MoveToElement ();
@@ -176,64 +207,166 @@ namespace System.Xml
public abstract bool ReadAttributeValue ();
- [MonoTODO]
public virtual string ReadElementString ()
{
- throw new NotImplementedException ();
+ if (MoveToContent () != XmlNodeType.Element) {
+ string error = String.Format ("'{0}' is an invalid node type.",
+ NodeType.ToString ());
+ throw new XmlException (this as IXmlLineInfo, error);
+ }
+
+ string result = String.Empty;
+ if (!IsEmptyElement) {
+ Read ();
+ result = ReadString ();
+ if (NodeType != XmlNodeType.EndElement) {
+ string error = String.Format ("'{0}' is an invalid node type.",
+ NodeType.ToString ());
+ throw new XmlException (this as IXmlLineInfo, error);
+ }
+ }
+
+ Read ();
+ return result;
}
- [MonoTODO]
public virtual string ReadElementString (string name)
{
- throw new NotImplementedException ();
+ if (MoveToContent () != XmlNodeType.Element) {
+ string error = String.Format ("'{0}' is an invalid node type.",
+ NodeType.ToString ());
+ throw new XmlException (this as IXmlLineInfo, error);
+ }
+
+ if (name != Name) {
+ string error = String.Format ("The {0} tag from namespace {1} is expected.",
+ Name, NamespaceURI);
+ throw new XmlException (this as IXmlLineInfo, error);
+ }
+
+ string result = String.Empty;
+ if (!IsEmptyElement) {
+ Read ();
+ result = ReadString ();
+ if (NodeType != XmlNodeType.EndElement) {
+ string error = String.Format ("'{0}' is an invalid node type.",
+ NodeType.ToString ());
+ throw new XmlException (this as IXmlLineInfo, error);
+ }
+ }
+
+ Read ();
+ return result;
}
- [MonoTODO]
- public virtual string ReadElementString (
- string localName,
- string namespaceName)
+ public virtual string ReadElementString (string localName, string namespaceName)
{
- throw new NotImplementedException ();
+ if (MoveToContent () != XmlNodeType.Element) {
+ string error = String.Format ("'{0}' is an invalid node type.",
+ NodeType.ToString ());
+ throw new XmlException (this as IXmlLineInfo, error);
+ }
+
+ if (localName != LocalName || NamespaceURI != namespaceName) {
+ string error = String.Format ("The {0} tag from namespace {1} is expected.",
+ LocalName, NamespaceURI);
+ throw new XmlException (this as IXmlLineInfo, error);
+ }
+
+ string result = String.Empty;
+ if (!IsEmptyElement) {
+ Read ();
+ result = ReadString ();
+ if (NodeType != XmlNodeType.EndElement) {
+ string error = String.Format ("'{0}' is an invalid node type.",
+ NodeType.ToString ());
+ throw new XmlException (this as IXmlLineInfo, error);
+ }
+ }
+
+ Read ();
+ return result;
}
- [MonoTODO]
public virtual void ReadEndElement ()
{
- throw new NotImplementedException ();
+ if (MoveToContent () != XmlNodeType.EndElement) {
+ string error = String.Format ("'{0}' is an invalid node type.",
+ NodeType.ToString ());
+ throw new XmlException (this as IXmlLineInfo, error);
+ }
+
+ Read ();
}
public abstract string ReadInnerXml ();
public abstract string ReadOuterXml ();
- [MonoTODO]
public virtual void ReadStartElement ()
{
- throw new NotImplementedException ();
+ if (MoveToContent () != XmlNodeType.Element) {
+ string error = String.Format ("'{0}' is an invalid node type.",
+ NodeType.ToString ());
+ throw new XmlException (this as IXmlLineInfo, error);
+ }
+
+ Read ();
}
- [MonoTODO]
public virtual void ReadStartElement (string name)
{
- throw new NotImplementedException ();
+ if (MoveToContent () != XmlNodeType.Element) {
+ string error = String.Format ("'{0}' is an invalid node type.",
+ NodeType.ToString ());
+ throw new XmlException (this as IXmlLineInfo, error);
+ }
+
+ if (name != Name) {
+ string error = String.Format ("The {0} tag from namespace {1} is expected.",
+ Name, NamespaceURI);
+ throw new XmlException (this as IXmlLineInfo, error);
+ }
+
+ Read ();
}
- [MonoTODO]
- public virtual void ReadStartElement (
- string localName,
- string namespaceName)
+ public virtual void ReadStartElement (string localName, string namespaceName)
{
- throw new NotImplementedException ();
+ if (MoveToContent () != XmlNodeType.Element) {
+ string error = String.Format ("'{0}' is an invalid node type.",
+ NodeType.ToString ());
+ throw new XmlException (this as IXmlLineInfo, error);
+ }
+
+ if (localName != LocalName || NamespaceURI != namespaceName) {
+ string error = String.Format ("The {0} tag from namespace {1} is expected.",
+ LocalName, NamespaceURI);
+ throw new XmlException (this as IXmlLineInfo, error);
+ }
+
+ Read ();
}
public abstract string ReadString ();
public abstract void ResolveEntity ();
- [MonoTODO]
public virtual void Skip ()
{
- throw new NotImplementedException ();
+ if (ReadState != ReadState.Interactive)
+ return;
+
+ MoveToElement ();
+ if (NodeType != XmlNodeType.Element || IsEmptyElement) {
+ Read ();
+ return;
+ }
+
+ int depth = Depth;
+ while (Read() && depth < Depth);
+ if (NodeType == XmlNodeType.EndElement)
+ Read ();
}
#endregion