Author: atsushi
Date: 2007-05-05 00:30:52 -0400 (Sat, 05 May 2007)
New Revision: 76730
Modified:
trunk/olive/class/System.Xml.Linq/System.Xml.Linq/ChangeLog
trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XDocument.cs
trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XElement.cs
trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XNode.cs
trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XUtil.cs
trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/XElementTest.cs
Log:
2007-05-05 Atsushi Enomoto <[EMAIL PROTECTED]>
* XNode.cs
XDocument.cs
XElement.cs
XContainer.cs
XUtil.cs : added members for schema support.
Shrink object array so that sequential strings are concatenated.
* XElementTest.cs : Tests for ReplaceAll() and AddBeforeSelf() for
sequential strings.
Modified: trunk/olive/class/System.Xml.Linq/System.Xml.Linq/ChangeLog
===================================================================
--- trunk/olive/class/System.Xml.Linq/System.Xml.Linq/ChangeLog 2007-05-05
01:18:14 UTC (rev 76729)
+++ trunk/olive/class/System.Xml.Linq/System.Xml.Linq/ChangeLog 2007-05-05
04:30:52 UTC (rev 76730)
@@ -1,3 +1,12 @@
+2007-05-05 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * XNode.cs
+ XDocument.cs
+ XElement.cs
+ XContainer.cs
+ XUtil.cs : added members for schema support.
+ Shrink object array so that sequential strings are concatenated.
+
2007-05-04 Atsushi Enomoto <[EMAIL PROTECTED]>
* XNode.cs : Nodes() is safe for removal of current item.
Modified: trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
===================================================================
--- trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
2007-05-05 01:18:14 UTC (rev 76729)
+++ trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
2007-05-05 04:30:52 UTC (rev 76730)
@@ -53,10 +53,6 @@
{
if (content == null)
return;
-// if (content is XAttribute) {
-// AddAttribute ((XAttribute) content);
-// return;
-// }
XNode n = XUtil.ToNode (content);
CheckChildType (n, false);
@@ -73,35 +69,26 @@
public void Add (params object [] content)
{
- for (int i = 0; i < content.Length; i++)
- Add (content [i]);
+ foreach (object o in XUtil.ShrinkArray (content))
+ Add (o);
}
public void AddFirst (object content)
{
- if (content == null)
- return;
-// if (content is XAttribute) {
-// AddAttribute ((XAttribute) content);
-// return;
-// }
- XNode n = XUtil.ToNode (content);
- OnAdded (n, true);
- CheckChildType (n, true);
- n.SetOwner (this);
if (first == null)
- first = last = n;
- else {
- n.NextNode = first;
- first.PreviousNode = n;
- first = n;
- }
+ Add (content);
+ else
+ first.AddBeforeSelf (content);
}
public void AddFirst (params object [] content)
{
- for (int i = content.Length - 1; i >= 0; i--)
- AddFirst (content [i]);
+ if (content == null)
+ return;
+ if (first == null)
+ Add (content);
+ else
+ first.AddBeforeSelf (content);
}
[MonoTODO]
Modified: trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XDocument.cs
===================================================================
--- trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XDocument.cs
2007-05-05 01:18:14 UTC (rev 76729)
+++ trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XDocument.cs
2007-05-05 04:30:52 UTC (rev 76730)
@@ -4,10 +4,14 @@
using System.IO;
using System.Text;
using System.Xml;
+using System.Xml.Schema;
+using System.Xml.Serialization;
namespace System.Xml.Linq
{
- public class XDocument : XContainer
+ [XmlRoot ("XDocument")]
+ [XmlSchemaProvider ("GetSchemaType")]
+ public class XDocument : XContainer, IXmlSerializable
{
XDeclaration xmldecl;
@@ -104,19 +108,24 @@
static XDocument LoadCore (XmlReader reader)
{
XDocument doc = new XDocument ();
+ doc.ReadContent (reader);
+ return doc;
+ }
+
+ void ReadContent (XmlReader reader)
+ {
if (reader.ReadState == ReadState.Initial)
reader.Read ();
if (reader.NodeType == XmlNodeType.XmlDeclaration) {
- doc.Declaration = new XDeclaration (
+ Declaration = new XDeclaration (
reader.GetAttribute ("version"),
reader.GetAttribute ("encoding"),
reader.GetAttribute ("standalone"));
reader.Read ();
}
- doc.ReadContentFrom (reader);
- if (doc.Root == null)
+ ReadContentFrom (reader);
+ if (Root == null)
throw new InvalidOperationException ("The
document element is missing.");
- return doc;
}
static void ValidateWhitespace (string s)
@@ -215,5 +224,26 @@
throw new InvalidOperationException
("An element cannot be added before the document type declaration");
}
}
+
+ [MonoTODO]
+ public static XmlSchemaType GetSchemaType (XmlSchemaSet schemas)
+ {
+ throw new NotImplementedException ();
+ }
+
+ void IXmlSerializable.WriteXml (XmlWriter writer)
+ {
+ Save (writer);
+ }
+
+ void IXmlSerializable.ReadXml (XmlReader reader)
+ {
+ ReadContent (reader);
+ }
+
+ XmlSchema IXmlSerializable.GetSchema ()
+ {
+ return null;
+ }
}
}
Modified: trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XElement.cs
===================================================================
--- trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XElement.cs
2007-05-05 01:18:14 UTC (rev 76729)
+++ trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XElement.cs
2007-05-05 04:30:52 UTC (rev 76730)
@@ -4,13 +4,14 @@
using System.IO;
using System.Text;
using System.Xml;
+using System.Xml.Schema;
+using System.Xml.Serialization;
-using XPI = System.Xml.Linq.XProcessingInstruction;
-
-
namespace System.Xml.Linq
{
- public class XElement : XContainer
+ [XmlRoot ("XElement")]
+ [XmlSchemaProvider ("GetSchemaType")]
+ public class XElement : XContainer, IXmlSerializable
{
static IEnumerable <XElement> emptySequence =
new List <XElement> ();
@@ -397,16 +398,16 @@
throw new NotImplementedException ();
}
- [MonoTODO]
public void ReplaceAll (object item)
{
- throw new NotImplementedException ();
+ RemoveNodes ();
+ Add (item);
}
- [MonoTODO]
public void ReplaceAll (params object [] items)
{
- throw new NotImplementedException ();
+ RemoveNodes ();
+ Add (items);
}
[MonoTODO]
@@ -421,16 +422,18 @@
throw new NotImplementedException ();
}
- [MonoTODO]
public void SetElementValue (XName name, object value)
{
- throw new NotImplementedException ();
+ XElement el = new XElement (name, value);
+ RemoveNodes ();
+ Add (el);
}
- [MonoTODO]
public void SetValue (object value)
{
- throw new NotImplementedException ();
+ XNode n = XUtil.ToNode (value);
+ RemoveNodes ();
+ Add (n);
}
internal override void OnAdded (XNode node, bool addFirst)
@@ -438,5 +441,26 @@
if (node is XDocument || node is XDocumentType)
throw new ArgumentException (String.Format ("A
node of type {0} cannot be added as a content", node.GetType ()));
}
+
+ [MonoTODO]
+ public static XmlSchemaType GetSchemaType (XmlSchemaSet schemas)
+ {
+ throw new NotImplementedException ();
+ }
+
+ void IXmlSerializable.WriteXml (XmlWriter writer)
+ {
+ Save (writer);
+ }
+
+ void IXmlSerializable.ReadXml (XmlReader reader)
+ {
+ ReadContentFrom (reader);
+ }
+
+ XmlSchema IXmlSerializable.GetSchema ()
+ {
+ return null;
+ }
}
}
Modified: trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XNode.cs
===================================================================
--- trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XNode.cs 2007-05-05
01:18:14 UTC (rev 76729)
+++ trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XNode.cs 2007-05-05
04:30:52 UTC (rev 76730)
@@ -87,7 +87,7 @@
if (Parent == null)
throw new InvalidOperationException ();
XNode n = this;
- foreach (object o in content) {
+ foreach (object o in XUtil.ShrinkArray (content)) {
n.AddAfterSelf (o);
n = n.NextNode;
}
@@ -112,7 +112,7 @@
{
if (Parent == null)
throw new InvalidOperationException ();
- foreach (object o in content)
+ foreach (object o in XUtil.ShrinkArray (content))
AddBeforeSelf (o);
}
Modified: trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XUtil.cs
===================================================================
--- trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XUtil.cs 2007-05-05
01:18:14 UTC (rev 76729)
+++ trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XUtil.cs 2007-05-05
04:30:52 UTC (rev 76730)
@@ -1,5 +1,3 @@
-#if NET_2_0
-
using System;
using System.Collections;
using System.Collections.Generic;
@@ -71,6 +69,25 @@
throw new NotImplementedException ();
throw new ArgumentException ();
}
+
+ public static IEnumerable<object> ShrinkArray (params object []
content)
+ {
+ if (content == null || content.Length == 0)
+ yield break;
+ string prev = null;
+ foreach (object o in content) {
+ if (o is XNode) {
+ if (prev != null) {
+ yield return prev;
+ prev = null;
+ }
+ yield return o;
+ } else {
+ prev += o;
+ }
+ }
+ if (prev != null)
+ yield return prev;
+ }
}
}
-#endif
Modified: trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
===================================================================
--- trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
2007-05-05 01:18:14 UTC (rev 76729)
+++ trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
2007-05-05 04:30:52 UTC (rev 76730)
@@ -1,3 +1,8 @@
+2007-05-05 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * XElementTest.cs : Tests for ReplaceAll() and AddBeforeSelf() for
+ sequential strings.
+
2007-05-04 Atsushi Enomoto <[EMAIL PROTECTED]>
* XElementTest.cs : added tests for Add[Before|After]Self().
Modified: trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/XElementTest.cs
===================================================================
--- trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/XElementTest.cs
2007-05-05 01:18:14 UTC (rev 76729)
+++ trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/XElementTest.cs
2007-05-05 04:30:52 UTC (rev 76730)
@@ -212,14 +212,55 @@
}
[Test]
+ public void AddBeforeSelfList2 ()
+ {
+ XElement el = XElement.Parse
("<root><foo/><bar/></root>");
+ el.FirstNode.AddBeforeSelf ("t1", "t2", "t3");
+ XText t = el.FirstNode as XText;
+ Assert.IsNotNull (t, "#1");
+ Assert.AreEqual ("t1t2t3", t.Value, "#2");
+ XElement foo = t.NextNode as XElement;
+ Assert.IsNotNull (foo, "#3");
+ Assert.AreEqual ("foo", foo.Name.LocalName, "#4");
+ }
+
+ [Test]
public void ReplaceWith ()
{
XElement el = XElement.Parse
("<root><foo/><bar/></root>");
XNode fc = el.FirstNode;
- fc.ReplaceWith("test");
+ fc.ReplaceWith ("test");
XText t = el.FirstNode as XText;
Assert.IsNotNull (t, "#1");
Assert.AreEqual ("test", t.Value, "#2");
}
+
+ [Test]
+ public void ReplaceAll ()
+ {
+ XElement el = XElement.Parse
("<root><foo/><bar/></root>");
+ el.ReplaceAll ("test");
+ XText t = el.FirstNode as XText;
+ Assert.IsNotNull (t, "#1");
+ Assert.AreEqual ("test", t.Value, "#2");
+ Assert.AreEqual (1, new List<XNode> (el.Nodes
()).Count, "#3");
+ }
+
+ [Test]
+ public void ReplaceAllList ()
+ {
+ XElement el = XElement.Parse
("<root><foo/><bar/></root>");
+ el.ReplaceAll (
+ new XText ("test1"),
+ new XText ("test2"),
+ new XText ("test3"));
+ XText t = el.FirstNode as XText;
+ Assert.IsNotNull (t, "#1");
+ Assert.AreEqual ("test1", t.Value, "#2");
+ t = el.LastNode as XText;
+ Assert.IsNotNull (t, "#3");
+ Assert.AreEqual ("test3", t.Value, "#4");
+ Assert.AreEqual (3, new List<XNode> (el.Nodes
()).Count, "#5");
+ }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches