Kaynağa Gözat

*** empty log message ***

svn path=/trunk/mcs/; revision=8952
Atsushi Eno 23 yıl önce
ebeveyn
işleme
57fc30817d

+ 10 - 0
mcs/class/System.XML/System.Xml/ChangeLog

@@ -1,3 +1,13 @@
+2002-11-13  Atsushi Enomoto <[email protected]>
+
+	XmlAttribute.cs : set_InnerText, set_InnerXml, some check for set_Prefix
+	XmlAttributeCollection.cs : (indexer) this[localName, namespaceURI]
+	XmlCharacterData.cs : exchanged Data and Value
+		(for processing events and inheritance)
+	XmlDocumentFragment.cs : set_InnerXml
+	XmlSignificantWhitespace.cs : set_Value
+	XmlTextReader.cs : ReadAttributeValue
+
 2002-11-04  Atsushi Enomoto <[email protected]>
 
 	XmlAttribute.cs: fixed missing internal 'OwnerElement''SetOwnerElement'

+ 24 - 7
mcs/class/System.XML/System.Xml/XmlAttribute.cs

@@ -35,6 +35,8 @@ namespace System.Xml
 			string namespaceURI, 
 			XmlDocument doc) : base (doc)
 		{
+			// What to be recognized is: xml:space, xml:lang, xml:base, and
+			// xmlns and xmlns:* (when XmlDocument.Namespaces = true only)
 			this.prefix = prefix;
 			this.localName = localName;
 			this.namespaceURI = namespaceURI;
@@ -50,7 +52,6 @@ namespace System.Xml
 			}
 		}
 
-		[MonoTODO ("Setter")]
 		public override string InnerText {
 			get {
 				StringBuilder builder = new StringBuilder ();
@@ -59,7 +60,7 @@ namespace System.Xml
                         }
 
 			set {
-				throw new NotImplementedException ();
+				Value = value;
 			}
 		}
 
@@ -74,7 +75,7 @@ namespace System.Xml
                         }
                 }
 		
-		[MonoTODO ("Setter.")]
+		[MonoTODO ("Setter is incomplete(XmlTextReader.ReadAttribute is incomplete;No resolution for xml:lang/space")]
 		public override string InnerXml {
 			get {
 				// Not sure why this is an override.  Passing through for now.
@@ -82,7 +83,11 @@ namespace System.Xml
 			}
 
 			set {
-				throw new NotImplementedException ();
+				XmlNamespaceManager nsmgr = ConstructNamespaceManager ();
+				XmlParserContext ctx = new XmlParserContext (OwnerDocument.NameTable, nsmgr, String.Empty, XmlSpace.Default);
+				XmlTextReader xtr = new XmlTextReader ("'" + value.Replace ("'", "&apos;") + "'", XmlNodeType.Attribute, ctx);
+				xtr.ReadAttributeValue ();
+				Value = xtr.Value;
 			}
 		}
 
@@ -128,19 +133,31 @@ namespace System.Xml
 			}
 		}
 
-		[MonoTODO]
 		public override XmlNode ParentNode {
 			get {
+				// It always returns null (by specification).
 				return null;
 			}
 		}
 
-		[MonoTODO]
+		[MonoTODO("setter incomplete (name character check, format check, wrong prefix&nsURI)")]
 		// We gotta do more in the set block here
 		// We need to do the proper tests and throw
 		// the correct Exceptions
+		//
+		// Wrong cases are: (1)check readonly, (2)check character validity,
+		// (3)check format validity, (4)this is attribute and qualifiedName != "xmlns"
+		// (5)when argument is 'xml' or 'xmlns' and namespaceURI doesn't match
 		public override string Prefix {
 			set {
+				if(IsReadOnly)
+					throw new XmlException ("This node is readonly.");
+
+				XmlNamespaceManager nsmgr = ConstructNamespaceManager ();
+				string nsuri = nsmgr.LookupNamespace (value);
+				if(nsuri == null)
+					throw new XmlException ("Namespace URI not found for this prefix");
+
 				prefix = value;
 			}
 			
@@ -192,7 +209,7 @@ namespace System.Xml
 		}
 
 		// Parent of XmlAttribute must be null
-		internal void SetOwnerElement(XmlElement el) {
+		internal void SetOwnerElement (XmlElement el) {
 			ownerElement = el;
 		}
 

+ 27 - 25
mcs/class/System.XML/System.Xml/XmlAttributeCollection.cs

@@ -3,8 +3,10 @@
 //
 // Author:
 //   Jason Diamond ([email protected])
+//   Atsushi Enomoto ([email protected])
 //
 // (C) 2002 Jason Diamond  http://injektilo.org/
+// (C) 2002 Atsushi Enomoto
 //
 
 using System;
@@ -20,7 +22,7 @@ namespace System.Xml
 		{
 			ownerElement = parent as XmlElement;
 			if(ownerElement == null)
-				throw new XmlException("invalid construction for XmlAttributeCollection.");
+				throw new XmlException ("invalid construction for XmlAttributeCollection.");
 		}
 
 		bool ICollection.IsSynchronized {
@@ -55,7 +57,7 @@ namespace System.Xml
 		[System.Runtime.CompilerServices.IndexerName ("ItemOf")]
 		public virtual XmlAttribute this [string localName, string namespaceURI] {
 			get {
-				throw new NotImplementedException ();
+				return (XmlAttribute) GetNamedItem (localName, namespaceURI);
 			}
 		}
 
@@ -76,29 +78,29 @@ namespace System.Xml
 		{
 			// assuming that Nodes is a correct collection.
 			for(int i=0; i<Nodes.Count; i++)
-				array[index+i] = Nodes[i] as XmlAttribute;
+				array [index + i] = Nodes [i] as XmlAttribute;
 		}
 
 		[MonoTODO] // I don't know why this method is required...
 		void ICollection.CopyTo (Array array, int index)
 		{
 			// assuming that Nodes is a correct collection.
-			array.CopyTo(Nodes.ToArray(typeof(XmlAttribute)), index);
+			array.CopyTo (Nodes.ToArray (typeof(XmlAttribute)), index);
 		}
 
 		public virtual XmlAttribute InsertAfter (XmlAttribute newNode, XmlAttribute refNode)
 		{
 			if(newNode.OwnerDocument != this.ownerElement.OwnerDocument)
-				throw new ArgumentException("different document created this newNode.");
+				throw new ArgumentException ("different document created this newNode.");
 
-			ownerElement.OwnerDocument.onNodeInserting(newNode, null);
+			ownerElement.OwnerDocument.onNodeInserting (newNode, null);
 
 			int pos = Nodes.Count + 1;
 			if(refNode != null)
 			{
 				for(int i=0; i<Nodes.Count; i++)
 				{
-					XmlNode n = Nodes[i] as XmlNode;
+					XmlNode n = Nodes [i] as XmlNode;
 					if(n == refNode)
 					{
 						pos = i + 1;
@@ -106,13 +108,13 @@ namespace System.Xml
 					}
 				}
 				if(pos > Nodes.Count)
-					throw new XmlException("refNode not found in this collection.");
+					throw new XmlException ("refNode not found in this collection.");
 			}
 			else
 				pos = 0;
-			SetNamedItem(newNode, pos);
+			SetNamedItem (newNode, pos);
 
-			ownerElement.OwnerDocument.onNodeInserted(newNode, null);
+			ownerElement.OwnerDocument.onNodeInserted (newNode, null);
 
 			return newNode;
 		}
@@ -120,16 +122,16 @@ namespace System.Xml
 		public virtual XmlAttribute InsertBefore (XmlAttribute newNode, XmlAttribute refNode)
 		{
 			if(newNode.OwnerDocument != this.ownerElement.OwnerDocument)
-				throw new ArgumentException("different document created this newNode.");
+				throw new ArgumentException ("different document created this newNode.");
 
-			ownerElement.OwnerDocument.onNodeInserting(newNode, null);
+			ownerElement.OwnerDocument.onNodeInserting (newNode, null);
 
 			int pos = Nodes.Count;
 			if(refNode != null)
 			{
 				for(int i=0; i<Nodes.Count; i++)
 				{
-					XmlNode n = Nodes[i] as XmlNode;
+					XmlNode n = Nodes [i] as XmlNode;
 					if(n == refNode)
 					{
 						pos = i;
@@ -137,24 +139,24 @@ namespace System.Xml
 					}
 				}
 				if(pos == Nodes.Count)
-					throw new XmlException("refNode not found in this collection.");
+					throw new XmlException ("refNode not found in this collection.");
 			}
-			SetNamedItem(newNode, pos);
+			SetNamedItem (newNode, pos);
 
-			ownerElement.OwnerDocument.onNodeInserted(newNode, null);
+			ownerElement.OwnerDocument.onNodeInserted (newNode, null);
 
 			return newNode;
 		}
 
 		public virtual XmlAttribute Prepend (XmlAttribute node) 
 		{
-			return this.InsertAfter(node, null);
+			return this.InsertAfter (node, null);
 		}
 
 		public virtual XmlAttribute Remove (XmlAttribute node) 
 		{
 			if(node == null || node.OwnerDocument != this.ownerElement.OwnerDocument)
-				throw new ArgumentException("node is null or different document created this node.");
+				throw new ArgumentException ("node is null or different document created this node.");
 
 			XmlAttribute retAttr = null;
 			foreach(XmlAttribute attr in Nodes)
@@ -168,9 +170,9 @@ namespace System.Xml
 
 			if(retAttr != null)
 			{
-				ownerElement.OwnerDocument.onNodeRemoving(node, null);
-				base.RemoveNamedItem(retAttr.LocalName, retAttr.NamespaceURI);
-				ownerElement.OwnerDocument.onNodeRemoved(node, null);
+				ownerElement.OwnerDocument.onNodeRemoving (node, null);
+				base.RemoveNamedItem (retAttr.LocalName, retAttr.NamespaceURI);
+				ownerElement.OwnerDocument.onNodeRemoved (node, null);
 			}
 			return retAttr;
 		}
@@ -178,14 +180,14 @@ namespace System.Xml
 		public virtual void RemoveAll () 
 		{
 			while(Count > 0)
-				Remove((XmlAttribute)Nodes[0]);
+				Remove ((XmlAttribute)Nodes [0]);
 		}
 
 		public virtual XmlAttribute RemoveAt (int i) 
 		{
 			if(Nodes.Count <= i)
 				return null;
-			return Remove((XmlAttribute)Nodes[i]);
+			return Remove ((XmlAttribute)Nodes [i]);
 		}
 
 		public override XmlNode SetNamedItem (XmlNode node)
@@ -194,10 +196,10 @@ namespace System.Xml
 		}
 
 		[MonoTODO("event handling")]
-		internal new XmlNode SetNamedItem(XmlNode node, int pos)
+		internal new XmlNode SetNamedItem (XmlNode node, int pos)
 		{
 			if(IsReadOnly)
-				throw new XmlException("this AttributeCollection is read only.");
+				throw new XmlException ("this AttributeCollection is read only.");
 
 			return base.SetNamedItem (node, pos);
 		}

+ 12 - 10
mcs/class/System.XML/System.Xml/XmlCharacterData.cs

@@ -34,13 +34,22 @@ namespace System.Xml
 		public virtual string Data {
 			get { return data; }
 			
-			set { data = value; }
+			set {
+				OwnerDocument.onNodeChanging (this, this.ParentNode);
+
+				if (IsReadOnly)
+					throw new ArgumentException ("Node is read-only.");
+
+				data = value;
+
+				OwnerDocument.onNodeChanged (this, this.ParentNode);
+			}
 		}
 
 		public override string InnerText {
 			get { return data; }
 
-			set { data = value; }
+			set { Data = value; }	// invokes events
 		}
 
 		public virtual int Length {
@@ -51,14 +60,7 @@ namespace System.Xml
 			get { return data; }
 
 			set {
-				OwnerDocument.onNodeChanging (this, this.ParentNode);
-
-				if (IsReadOnly)
-					throw new ArgumentException ("Node is read-only.");
-
-				data = value;
-
-				OwnerDocument.onNodeChanged (this, this.ParentNode);
+				Data = value;
 			}
 		}
 

+ 23 - 11
mcs/class/System.XML/System.Xml/XmlDocumentFragment.cs

@@ -29,14 +29,30 @@ namespace System.Xml
 		#endregion
 		#region Properties
 
-		[MonoTODO]
+		[MonoTODO("Setter is as incomplete as that of XmlElement.InnerXml")]
 		public override string InnerXml {
-			set { throw new NotImplementedException (); }
+			set {
+				// Copied from XmlElement.InnerXml (in the meantime;-))
+				foreach(XmlNode n in ChildNodes)
+				{
+					this.RemoveChild (n);
+				}		  
+
+				// How to get xml:lang and xml:space? Create logic as ConstructNamespaceManager()?
+				XmlNameTable nt = this.OwnerDocument.NameTable;
+				XmlNamespaceManager nsmgr = this.ConstructNamespaceManager (); //new XmlNamespaceManager(nt);
+				string lang = "";
+				XmlSpace space = XmlSpace.Default;
+
+				XmlParserContext ctx = new XmlParserContext (nt, nsmgr, lang, space);
+				XmlTextReader xmlReader = new XmlTextReader (value, this.NodeType, ctx);
+				this.ConstructDOM (xmlReader, this);
+			}
 			get {
-				StringBuilder sb = new StringBuilder();
+				StringBuilder sb = new StringBuilder ();
 				foreach(XmlNode n in ChildNodes)
-					sb.Append(n.OuterXml);
-				return sb.ToString();
+					sb.Append (n.OuterXml);
+				return sb.ToString ();
 			}
 		}
 		
@@ -86,20 +102,16 @@ namespace System.Xml
 				return new XmlDocumentFragment (OwnerDocument);
 		}
 
-//		[MonoTODO]
 		public override void WriteContentTo (XmlWriter w)
 		{
 			foreach(XmlNode n in ChildNodes)
-				n.WriteContentTo(w);
-//			throw new NotImplementedException ();
+				n.WriteContentTo (w);
 		}
 
-//		[MonoTODO]
 		public override void WriteTo (XmlWriter w)
 		{
 			foreach(XmlNode n in ChildNodes)
-				n.WriteTo(w);
-//			throw new NotImplementedException ();
+				n.WriteTo (w);
 		}
 
 		#endregion

+ 1 - 1
mcs/class/System.XML/System.Xml/XmlSignificantWhitespace.cs

@@ -41,10 +41,10 @@ namespace System.Xml
 		
 		public override string Value {
 			get { return Data; }
-			[MonoTODO]
 			set {
 				if (IsValidWhitespaceChar (value) == false)
 					throw new ArgumentException ("Invalid whitespace characters.");
+				base.Data = value;
 			}
 		}
 

+ 3 - 2
mcs/class/System.XML/System.Xml/XmlTextReader.cs

@@ -492,10 +492,11 @@ namespace System.Xml
 			return more;
 		}
 
-		[MonoTODO]
+		[MonoTODO("This method should check position validity; consider entity references")]
 		public override bool ReadAttributeValue ()
 		{
-			throw new NotImplementedException ();
+			value = ReadAttribute ();
+			return true;
 		}
 
 		[MonoTODO]

+ 5 - 0
mcs/class/System.XML/Test/ChangeLog

@@ -1,3 +1,8 @@
+2002-11-13  Atsushi Enomoto <[email protected]>
+
+	* XmlAttributeTests.cs : TestSetInnerAndOuterXml
+	* XmlSignificantWhitespaceTests.cs : TestDataAndValue
+
 2002-11-03  Atsushi Enomoto <[email protected]>
 
 	* XmlAttributeCollectionTests.cs : TestSetNamedItem,

+ 47 - 18
mcs/class/System.XML/Test/XmlAttributeTests.cs

@@ -13,22 +13,22 @@ namespace MonoTests.System.Xml
 {
 	public class XmlAttributeTests : TestCase
 	{
-		public XmlAttributeTests() : base("MonoTests.System.Xml.XmlAttributeTests testsuite") { }
-		public XmlAttributeTests(string name) : base(name) { }
+		public XmlAttributeTests () : base("MonoTests.System.Xml.XmlAttributeTests testsuite") { }
+		public XmlAttributeTests (string name) : base(name) { }
 
 		XmlDocument doc;
 		XmlAttribute attr;
 
 		protected override void SetUp()
 		{
-			doc = new XmlDocument();
-			attr = doc.CreateAttribute("attr1");
+			doc = new XmlDocument ();
+			attr = doc.CreateAttribute ("attr1");
 			attr.Value = "val1";
 		}
 
-		public void TestAttributes()
+		public void TestAttributes ()
 		{
-			AssertNull(attr.Attributes);
+			AssertNull (attr.Attributes);
 		}
 
 		public void TestAttributeInnerAndOuterXml ()
@@ -62,34 +62,63 @@ namespace MonoTests.System.Xml
 			AssertEquals ("value", attribute.ChildNodes [0].Value);
 		}
 
-		public void TestHasChildNodes()
+		public void TestHasChildNodes ()
 		{
-			Assert(attr.HasChildNodes);
+			Assert (attr.HasChildNodes);
 		}
 
-		public void TestName()
+		public void TestName ()
 		{
-			AssertEquals("attr1", attr.Name);
+			AssertEquals ("attr1", attr.Name);
 		}
 
-		public void TestNodeType()
+		public void TestNodeType ()
 		{
-			AssertEquals(XmlNodeType.Attribute, attr.NodeType);
+			AssertEquals (XmlNodeType.Attribute, attr.NodeType);
 		}
 
-		public void TestOwnerDocument()
+		public void TestOwnerDocument ()
 		{
-			AssertSame(doc, attr.OwnerDocument);
+			AssertSame (doc, attr.OwnerDocument);
 		}
 
-		public void TestParentNode()
+		public void TestParentNode ()
 		{
-			AssertNull("Attr parents not allowed", attr.ParentNode);
+			AssertNull ("Attr parents not allowed", attr.ParentNode);
 		}
 
-		public void TestValue()
+		public void TestValue ()
 		{
-			AssertEquals("val1", attr.Value);
+			AssertEquals ("val1", attr.Value);
+		}
+
+		public void TestSetInnerTextAndXml ()
+		{
+			string original = doc.OuterXml;
+			doc.LoadXml ("<root name='value' />");
+			XmlNodeChangedEventHandler eh = new XmlNodeChangedEventHandler (OnSetInnerText);
+			try {
+				doc.DocumentElement.Attributes ["name"].InnerText = "a&b";
+				AssertEquals ("setInnerText", "a&b", doc.DocumentElement.Attributes ["name"].Value);
+				doc.DocumentElement.Attributes ["name"].InnerXml = "a&amp;b";
+				AssertEquals ("setInnerXml", "a&b", doc.DocumentElement.Attributes ["name"].Value);
+
+				doc.NodeChanged += eh;
+				doc.DocumentElement.Attributes ["name"].InnerText = "fire";
+				// If you failed to pass it, then the reason may be loop of event.
+				AssertEquals ("setInnerText.Event", "event was fired", doc.DocumentElement.GetAttribute ("appended"));
+			} catch(Exception ex) {
+				Fail(ex.Message);
+			} finally {
+				doc.LoadXml (original);
+				doc.NodeChanged -= eh;
+			}
+		}
+
+		public void OnSetInnerText (object o, XmlNodeChangedEventArgs e)
+		{
+			if(e.NewParent.Value == "fire")
+				doc.DocumentElement.SetAttribute ("appended", "event was fired");
 		}
 	}
 }

+ 10 - 0
mcs/class/System.XML/Test/XmlSignificantWhitespaceTests.cs

@@ -44,6 +44,16 @@ namespace MonoTests.System.Xml
 			AssertEquals (String.Empty, whitespace.InnerXml);
 			AssertEquals ("\r\n\t ", whitespace.OuterXml);
 		}
+
+		public void TestDataAndValue ()
+		{
+			string val = "\t\t\r\n ";
+			whitespace = doc2.CreateSignificantWhitespace (val);
+			AssertEquals ("#DataValue.1", val, whitespace.Data);
+			AssertEquals ("#DataValue.2", val, whitespace.Value);
+			whitespace.Value = val + "\t";
+			AssertEquals ("#DataValue.3", val + "\t", whitespace.Data);
+		}
 			
 		internal void TestXmlNodeBaseProperties (XmlNode original, XmlNode cloned)
 		{