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:
authorJason Diamond <injektilo@mono-cvs.ximian.com>2002-05-27 23:17:13 +0400
committerJason Diamond <injektilo@mono-cvs.ximian.com>2002-05-27 23:17:13 +0400
commit4d82c52aebf33ced1d8b934323eccbb905419a9e (patch)
treeda951bb40c1830e4e80542f343377bae6390b615 /mcs/class/System.XML/System.Xml
parent3c712f2b0cc37fe31edb707c5df92965f5c1e9a3 (diff)
In System.Xml:
* XmlDocumentNavigator.cs: Added file to directory. * XmlNode.cs (CreateNavigator): Implemented. (InnerText): Implemented. * XmlDocument.cs (NamespaceURI, Prefix): Return String.Empty instead of throwing exception. (Load(XmlReader)): Allow for namespace qualified attributes. * XmlElement.cs: Implemented GetAttribute(string, string) and both GetAttributeNode overloads. (SetAttributeNode(XmlAttribute)): Implemented. * XmlNamedNodeMap.cs: Fixed copy/paste bugs in GetNamedItem(string, string) and RemoveNamedItem(string, string). * XmlLinkedNode.cs (PreviousSibling): Implemented. * XmlTextReader.cs: Added code to maintain the order of attributes as they're parsed. XML doesn't require this but Microsoft's parser does it and matching them makes testing easier so now we have it, too. In Test: * XPathNavigatorTests.cs: Added file to directory. * AllTests.cs: Added XPathNavigatorTests to suite. * XmlTextReaderTests.cs: Added test to make sure attributes are ordered like Microsoft's parser does it. svn path=/trunk/mcs/; revision=4971
Diffstat (limited to 'mcs/class/System.XML/System.Xml')
-rw-r--r--mcs/class/System.XML/System.Xml/ChangeLog24
-rw-r--r--mcs/class/System.XML/System.Xml/XmlDocument.cs13
-rw-r--r--mcs/class/System.XML/System.Xml/XmlElement.cs12
-rw-r--r--mcs/class/System.XML/System.Xml/XmlLinkedNode.cs26
-rw-r--r--mcs/class/System.XML/System.Xml/XmlNamedNodeMap.cs8
-rw-r--r--mcs/class/System.XML/System.Xml/XmlNode.cs31
-rw-r--r--mcs/class/System.XML/System.Xml/XmlTextReader.cs61
7 files changed, 117 insertions, 58 deletions
diff --git a/mcs/class/System.XML/System.Xml/ChangeLog b/mcs/class/System.XML/System.Xml/ChangeLog
index 25d1c1035fb..52e28ab6ba9 100644
--- a/mcs/class/System.XML/System.Xml/ChangeLog
+++ b/mcs/class/System.XML/System.Xml/ChangeLog
@@ -1,3 +1,27 @@
+2002-05-27 Jason Diamond <jason@injektilo.org>
+
+ * XmlDocumentNavigator.cs: Added file to directory.
+
+ * XmlNode.cs (CreateNavigator): Implemented.
+ (InnerText): Implemented.
+
+ * XmlDocument.cs (NamespaceURI, Prefix): Return String.Empty instead of
+ throwing exception.
+ (Load(XmlReader)): Allow for namespace qualified attributes.
+
+ * XmlElement.cs: Implemented GetAttribute(string, string) and both
+ GetAttributeNode overloads.
+ (SetAttributeNode(XmlAttribute)): Implemented.
+
+ * XmlNamedNodeMap.cs: Fixed copy/paste bugs in GetNamedItem(string, string)
+ and RemoveNamedItem(string, string).
+
+ * XmlLinkedNode.cs (PreviousSibling): Implemented.
+
+ * XmlTextReader.cs: Added code to maintain the order of attributes as
+ they're parsed. XML doesn't require this but Microsoft's parser does it and
+ matching them makes testing easier so now we have it, too.
+
2002-05-26 Miguel de Icaza <miguel@ximian.com>
* XmlDocument.cs: Implement the Save methods.
diff --git a/mcs/class/System.XML/System.Xml/XmlDocument.cs b/mcs/class/System.XML/System.Xml/XmlDocument.cs
index 66c1c25c2b5..1781600ae70 100644
--- a/mcs/class/System.XML/System.Xml/XmlDocument.cs
+++ b/mcs/class/System.XML/System.Xml/XmlDocument.cs
@@ -241,12 +241,6 @@ namespace System.Xml
throw new NotImplementedException ();
}
- [MonoTODO]
- protected internal virtual XPathNavigator CreateNavigator (XmlNode node)
- {
- throw new NotImplementedException ();
- }
-
public virtual XmlNode CreateNode (
string nodeTypeString,
string name,
@@ -428,8 +422,11 @@ namespace System.Xml
currentNode.AppendChild (element);
// set the element's attributes.
- while (xmlReader.MoveToNextAttribute ())
- element.SetAttribute (xmlReader.Name, xmlReader.Value);
+ while (xmlReader.MoveToNextAttribute ()) {
+ XmlAttribute attribute = CreateAttribute (xmlReader.Prefix, xmlReader.LocalName, xmlReader.NamespaceURI);
+ attribute.Value = xmlReader.Value;
+ element.SetAttributeNode (attribute);
+ }
xmlReader.MoveToElement ();
diff --git a/mcs/class/System.XML/System.Xml/XmlElement.cs b/mcs/class/System.XML/System.Xml/XmlElement.cs
index 8963918f9bb..c352c96a1a4 100644
--- a/mcs/class/System.XML/System.Xml/XmlElement.cs
+++ b/mcs/class/System.XML/System.Xml/XmlElement.cs
@@ -155,19 +155,22 @@ namespace System.Xml
[MonoTODO]
public virtual string GetAttribute (string localName, string namespaceURI)
{
- throw new NotImplementedException ();
+ XmlNode attributeNode = Attributes.GetNamedItem (localName, namespaceURI);
+ return attributeNode != null ? attributeNode.Value : String.Empty;
}
[MonoTODO]
public virtual XmlAttribute GetAttributeNode (string name)
{
- throw new NotImplementedException ();
+ XmlNode attributeNode = Attributes.GetNamedItem (name);
+ return attributeNode != null ? attributeNode as XmlAttribute : null;
}
[MonoTODO]
public virtual XmlAttribute GetAttributeNode (string localName, string namespaceURI)
{
- throw new NotImplementedException ();
+ XmlNode attributeNode = Attributes.GetNamedItem (localName, namespaceURI);
+ return attributeNode != null ? attributeNode as XmlAttribute : null;
}
[MonoTODO]
@@ -259,7 +262,8 @@ namespace System.Xml
[MonoTODO]
public virtual XmlAttribute SetAttributeNode (XmlAttribute newAttr)
{
- throw new NotImplementedException ();
+ XmlNode oldAttr = Attributes.SetNamedItem(newAttr);
+ return oldAttr != null ? oldAttr as XmlAttribute : null;
}
[MonoTODO]
diff --git a/mcs/class/System.XML/System.Xml/XmlLinkedNode.cs b/mcs/class/System.XML/System.Xml/XmlLinkedNode.cs
index f7b64e8a30d..090bedcf6b9 100644
--- a/mcs/class/System.XML/System.Xml/XmlLinkedNode.cs
+++ b/mcs/class/System.XML/System.Xml/XmlLinkedNode.cs
@@ -1,3 +1,13 @@
+//
+// System.Xml.XmlLinkedNode
+//
+// Authors:
+// Jason Diamond <jason@injektilo.org>
+// Kral Ferch <kral_ferch@hotmail.com>
+//
+// (C) 2002 Jason Diamond, Kral Ferch
+//
+
using System;
namespace System.Xml
@@ -5,6 +15,7 @@ namespace System.Xml
public abstract class XmlLinkedNode : XmlNode
{
#region Fields
+
XmlLinkedNode nextSibling;
#endregion
@@ -14,7 +25,8 @@ namespace System.Xml
#endregion
- #region Properties
+ #region Properties
+
public override XmlNode NextSibling
{
get {
@@ -33,11 +45,19 @@ namespace System.Xml
set { nextSibling = value; }
}
- [MonoTODO]
public override XmlNode PreviousSibling
{
get {
- throw new NotImplementedException ();
+ if (ParentNode != null) {
+ XmlNode node = ParentNode.FirstChild;
+ if (node != this) {
+ do {
+ if (node.NextSibling == this)
+ return node;
+ } while ((node = node.NextSibling) != null);
+ }
+ }
+ return null;
}
}
diff --git a/mcs/class/System.XML/System.Xml/XmlNamedNodeMap.cs b/mcs/class/System.XML/System.Xml/XmlNamedNodeMap.cs
index c188272a283..c605a82cb34 100644
--- a/mcs/class/System.XML/System.Xml/XmlNamedNodeMap.cs
+++ b/mcs/class/System.XML/System.Xml/XmlNamedNodeMap.cs
@@ -46,8 +46,8 @@ namespace System.Xml
public virtual XmlNode GetNamedItem (string localName, string namespaceURI)
{
foreach (XmlNode node in nodeList) {
- if ((node.Name == localName)
- && (parent.NamespaceURI == namespaceURI))
+ if ((node.LocalName == localName)
+ && (node.NamespaceURI == namespaceURI))
return node;
}
@@ -76,8 +76,8 @@ namespace System.Xml
public virtual XmlNode RemoveNamedItem (string localName, string namespaceURI)
{
foreach (XmlNode node in nodeList)
- if ((node.Name == localName)
- && (parent.NamespaceURI == namespaceURI)) {
+ if ((node.LocalName == localName)
+ && (node.NamespaceURI == namespaceURI)) {
nodeList.Remove (node);
return node;
}
diff --git a/mcs/class/System.XML/System.Xml/XmlNode.cs b/mcs/class/System.XML/System.Xml/XmlNode.cs
index 87fbc8aa214..48744fad3c8 100644
--- a/mcs/class/System.XML/System.Xml/XmlNode.cs
+++ b/mcs/class/System.XML/System.Xml/XmlNode.cs
@@ -10,6 +10,7 @@
using System;
using System.Collections;
using System.IO;
+using System.Text;
using System.Xml.XPath;
namespace System.Xml
@@ -68,10 +69,26 @@ namespace System.Xml
[MonoTODO]
public virtual string InnerText {
- get { throw new NotImplementedException (); }
+ get {
+ StringBuilder builder = new StringBuilder ();
+ AppendChildValues (this, builder);
+ return builder.ToString ();
+ }
+
set { throw new NotImplementedException (); }
}
+ private void AppendChildValues(XmlNode parent, StringBuilder builder)
+ {
+ XmlNode node = parent.FirstChild;
+
+ while (node != null) {
+ builder.Append (node.Value);
+ AppendChildValues (node, builder);
+ node = node.NextSibling;
+ }
+ }
+
[MonoTODO("Setter.")]
public virtual string InnerXml {
get {
@@ -132,9 +149,8 @@ namespace System.Xml
public abstract string Name { get; }
- [MonoTODO]
public virtual string NamespaceURI {
- get { throw new NotImplementedException (); }
+ get { return String.Empty; }
}
public virtual XmlNode NextSibling {
@@ -162,10 +178,9 @@ namespace System.Xml
get { return parentNode; }
}
- [MonoTODO]
public virtual string Prefix {
- get { throw new NotImplementedException (); }
- set { throw new NotImplementedException (); }
+ get { return String.Empty; }
+ set {}
}
public virtual XmlNode PreviousSibling {
@@ -213,9 +228,9 @@ namespace System.Xml
public abstract XmlNode CloneNode (bool deep);
[MonoTODO]
- public XPathNavigator CreateNavigator ()
+ public virtual XPathNavigator CreateNavigator ()
{
- throw new NotImplementedException ();
+ return new XmlDocumentNavigator(this);
}
public IEnumerator GetEnumerator ()
diff --git a/mcs/class/System.XML/System.Xml/XmlTextReader.cs b/mcs/class/System.XML/System.Xml/XmlTextReader.cs
index 673cb9fd1f8..271ce5281d3 100644
--- a/mcs/class/System.XML/System.Xml/XmlTextReader.cs
+++ b/mcs/class/System.XML/System.Xml/XmlTextReader.cs
@@ -374,35 +374,29 @@ namespace System.Xml
public override bool MoveToAttribute (string name)
{
MoveToElement ();
- bool match = false;
+
if (attributes == null)
return false;
- if (attributeEnumerator == null) {
+ if (orderedAttributesEnumerator == null) {
SaveProperties ();
- attributeEnumerator = attributes.GetEnumerator ();
+ orderedAttributesEnumerator = orderedAttributes.GetEnumerator ();
}
- while (attributeEnumerator.MoveNext ()) {
- if(name == attributeEnumerator.Key as string) {
- match = true;
- break;
+ while (orderedAttributesEnumerator.MoveNext ()) {
+ if(name == orderedAttributesEnumerator.Current as string) {
+ string value = attributes [name] as string;
+ SetProperties (
+ XmlNodeType.Attribute, // nodeType
+ name, // name
+ false, // isEmptyElement
+ value, // value
+ false // clearAttributes
+ );
}
}
- if (match) {
- string attname = attributeEnumerator.Key as string;
- string value = attributeEnumerator.Value as string;
- SetProperties (
- XmlNodeType.Attribute, // nodeType
- attname, // name
- false, // isEmptyElement
- value, // value
- false // clearAttributes
- );
- }
-
- return match;
+ return false;
}
[MonoTODO]
@@ -413,8 +407,8 @@ namespace System.Xml
public override bool MoveToElement ()
{
- if (attributeEnumerator != null) {
- attributeEnumerator = null;
+ if (orderedAttributesEnumerator != null) {
+ orderedAttributesEnumerator = null;
RestoreProperties ();
return true;
}
@@ -433,14 +427,14 @@ namespace System.Xml
if (attributes == null)
return false;
- if (attributeEnumerator == null) {
+ if (orderedAttributesEnumerator == null) {
SaveProperties ();
- attributeEnumerator = attributes.GetEnumerator ();
+ orderedAttributesEnumerator = orderedAttributes.GetEnumerator ();
}
- if (attributeEnumerator.MoveNext ()) {
- string name = attributeEnumerator.Key as string;
- string value = attributeEnumerator.Value as string;
+ if (orderedAttributesEnumerator.MoveNext ()) {
+ string name = orderedAttributesEnumerator.Current as string;
+ string value = attributes [name] as string;
SetProperties (
XmlNodeType.Attribute, // nodeType
name, // name
@@ -588,7 +582,8 @@ namespace System.Xml
private bool saveIsEmptyElement;
private Hashtable attributes;
- private IDictionaryEnumerator attributeEnumerator;
+ private ArrayList orderedAttributes;
+ private IEnumerator orderedAttributesEnumerator;
private bool returnEntityReference;
private string entityReferenceName;
@@ -624,7 +619,8 @@ namespace System.Xml
value = String.Empty;
attributes = new Hashtable ();
- attributeEnumerator = null;
+ orderedAttributes = new ArrayList ();
+ orderedAttributesEnumerator = null;
returnEntityReference = false;
entityReferenceName = String.Empty;
@@ -699,14 +695,17 @@ namespace System.Xml
private void AddAttribute (string name, string value)
{
attributes.Add (name, value);
+ orderedAttributes.Add (name);
}
private void ClearAttributes ()
{
- if (attributes.Count > 0)
+ if (attributes.Count > 0) {
attributes.Clear ();
+ orderedAttributes.Clear ();
+ }
- attributeEnumerator = null;
+ orderedAttributesEnumerator = null;
}
private int PeekChar ()