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:
authorKral Ferch <kral@mono-cvs.ximian.com>2002-03-18 06:11:17 +0300
committerKral Ferch <kral@mono-cvs.ximian.com>2002-03-18 06:11:17 +0300
commit7472ae9d5d6c3dbcc4b8a6cd88d3537cca631b9a (patch)
tree982634ae808e7ad283a6ba617014f73587b38498
parent5b7629fbf350b66ceeb3273fb92ff0f6cd2e8851 (diff)
More XmlTextWriter and node WriteTo.
svn path=/trunk/mcs/; revision=3176
-rw-r--r--mcs/class/System.XML/System.Xml/ChangeLog15
-rw-r--r--mcs/class/System.XML/System.Xml/XmlCDataSection.cs30
-rw-r--r--mcs/class/System.XML/System.Xml/XmlComment.cs36
-rw-r--r--mcs/class/System.XML/System.Xml/XmlElement.cs2
-rw-r--r--mcs/class/System.XML/System.Xml/XmlProcessingInstruction.cs5
-rw-r--r--mcs/class/System.XML/System.Xml/XmlTextWriter.cs53
-rw-r--r--mcs/class/System.XML/Test/ChangeLog8
-rw-r--r--mcs/class/System.XML/Test/XmlDocumentTests.cs29
-rw-r--r--mcs/class/System.XML/Test/XmlTextWriterTests.cs76
9 files changed, 194 insertions, 60 deletions
diff --git a/mcs/class/System.XML/System.Xml/ChangeLog b/mcs/class/System.XML/System.Xml/ChangeLog
index d2375c59654..fc1bee8fc9c 100644
--- a/mcs/class/System.XML/System.Xml/ChangeLog
+++ b/mcs/class/System.XML/System.Xml/ChangeLog
@@ -1,4 +1,17 @@
-2002-03-14 Kral Ferch <kral_ferch@hotmail.com>
+2002-03-17 Kral Ferch <kral_ferch@hotmail.com>
+
+ * XmlCDataSection.cs: Formatting, Implementation for WriteTo.
+
+ * XmlComment.cs: Implementations for WriteTo and WriteContentTo.
+
+ * XmlElement.cs: Fixed bug in WriteTo.
+
+ * XmlProcessingInstruction.cs: Formatting.
+
+ * XmlTextWriter.cs: Implementations for Close, WriteCData, WriteComment,
+ fixes for WriteEndElement, WriteProcessingInstruction.
+
+2002-03-17 Kral Ferch <kral_ferch@hotmail.com>
* XmlDocument.cs: Implementations for WriteTo() and WriteContentTo(),
had Load() add PIs to the document, moved onXXX methods to alphabetical
diff --git a/mcs/class/System.XML/System.Xml/XmlCDataSection.cs b/mcs/class/System.XML/System.Xml/XmlCDataSection.cs
index 982de3c135a..271e5456e01 100644
--- a/mcs/class/System.XML/System.Xml/XmlCDataSection.cs
+++ b/mcs/class/System.XML/System.Xml/XmlCDataSection.cs
@@ -10,41 +10,45 @@ namespace System.Xml
{
public class XmlCDataSection : XmlCharacterData
{
- // Constructor
+ #region Constructors
+
protected internal XmlCDataSection (string data, XmlDocument doc)
: base (data, doc)
{
}
- // Properties
- public override string LocalName
- {
+ #endregion
+
+ #region Properties
+
+ public override string LocalName {
get { return "#cdata-section"; }
}
- public override string Name
- {
+ public override string Name {
get { return "#cdata-section"; }
}
- public override XmlNodeType NodeType
- {
+ public override XmlNodeType NodeType {
get { return XmlNodeType.CDATA; }
}
- // Methods
+ #endregion
+
+ #region Methods
+
public override XmlNode CloneNode (bool deep)
{
return null;
}
- public override void WriteContentTo (XmlWriter w)
- {
- // CDATA nodes have no children, WriteContentTo has no effect.
- }
+ public override void WriteContentTo (XmlWriter w) { }
public override void WriteTo (XmlWriter w)
{
+ w.WriteCData(Data);
}
+
+ #endregion
}
}
diff --git a/mcs/class/System.XML/System.Xml/XmlComment.cs b/mcs/class/System.XML/System.Xml/XmlComment.cs
index aed7777f9b2..c7ca111ff9b 100644
--- a/mcs/class/System.XML/System.Xml/XmlComment.cs
+++ b/mcs/class/System.XML/System.Xml/XmlComment.cs
@@ -15,52 +15,38 @@ namespace System.Xml
{
#region Constructors
- protected internal XmlComment(string comment, XmlDocument doc) : base(comment, doc) { }
+ protected internal XmlComment (string comment, XmlDocument doc) : base(comment, doc) { }
#endregion
#region Properties
- public override string LocalName
- {
- get {
- return "#comment";
- }
+ public override string LocalName {
+ get { return "#comment"; }
}
- public override string Name
- {
- get {
- return "#comment";
- }
+ public override string Name {
+ get { return "#comment"; }
}
- public override XmlNodeType NodeType
- {
- get {
- return XmlNodeType.Comment;
- }
+ public override XmlNodeType NodeType {
+ get { return XmlNodeType.Comment; }
}
#endregion
#region Methods
- public override XmlNode CloneNode(bool deep)
+ public override XmlNode CloneNode (bool deep)
{
return new XmlComment(Value, OwnerDocument);
}
- [MonoTODO]
- public override void WriteContentTo(XmlWriter w)
- {
- throw new NotImplementedException ();
- }
+ public override void WriteContentTo (XmlWriter w) { }
- [MonoTODO]
- public override void WriteTo(XmlWriter w)
+ public override void WriteTo (XmlWriter w)
{
- throw new NotImplementedException ();
+ w.WriteComment (Data);
}
#endregion
diff --git a/mcs/class/System.XML/System.Xml/XmlElement.cs b/mcs/class/System.XML/System.Xml/XmlElement.cs
index ab0a6ff5c3f..69a0449c89a 100644
--- a/mcs/class/System.XML/System.Xml/XmlElement.cs
+++ b/mcs/class/System.XML/System.Xml/XmlElement.cs
@@ -282,7 +282,7 @@ namespace System.Xml
public override void WriteTo (XmlWriter w)
{
- w.WriteStartElement(Value);
+ w.WriteStartElement(LocalName);
foreach(XmlNode attributeNode in Attributes)
attributeNode.WriteTo(w);
diff --git a/mcs/class/System.XML/System.Xml/XmlProcessingInstruction.cs b/mcs/class/System.XML/System.Xml/XmlProcessingInstruction.cs
index 440c9f4b101..47ffe04392e 100644
--- a/mcs/class/System.XML/System.Xml/XmlProcessingInstruction.cs
+++ b/mcs/class/System.XML/System.Xml/XmlProcessingInstruction.cs
@@ -18,8 +18,7 @@ namespace System.Xml
#region Constructors
- protected internal XmlProcessingInstruction (string target, string data, XmlDocument doc)
- : base(doc)
+ protected internal XmlProcessingInstruction (string target, string data, XmlDocument doc) : base(doc)
{
this.target = target;
this.data = data;
@@ -87,7 +86,7 @@ namespace System.Xml
public override void WriteTo (XmlWriter w)
{
- w.WriteProcessingInstruction(target, data);
+ w.WriteProcessingInstruction (target, data);
}
#endregion
diff --git a/mcs/class/System.XML/System.Xml/XmlTextWriter.cs b/mcs/class/System.XML/System.Xml/XmlTextWriter.cs
index 13bec99bdaa..283d462ea1f 100644
--- a/mcs/class/System.XML/System.Xml/XmlTextWriter.cs
+++ b/mcs/class/System.XML/System.Xml/XmlTextWriter.cs
@@ -104,13 +104,18 @@ namespace System.Xml
private void CheckOpenWriter ()
{
if (!openWriter) {
- throw new InvalidOperationException ();
+ throw new InvalidOperationException ("The Writer is closed.");
}
}
- [MonoTODO("Need to close all open elements and close the underlying streams.")]
public override void Close ()
{
+ while (openElements.Count > 0) {
+ WriteEndElement();
+ }
+
+ w.Close();
+
openWriter = false;
}
@@ -149,6 +154,14 @@ namespace System.Xml
public override void WriteCData (string text)
{
+ if (text.IndexOf("]]>") > 0)
+ {
+ throw new ArgumentException ();
+ }
+
+ CheckOpenWriter ();
+ CloseStartElement ();
+
w.Write("<![CDATA[{0}]]>", text);
}
@@ -166,7 +179,14 @@ namespace System.Xml
public override void WriteComment (string text)
{
- w.Write("<!--{0}-->", text);
+ if ((text.EndsWith("-")) || (text.IndexOf("-->") > 0)) {
+ throw new ArgumentException ();
+ }
+
+ CheckOpenWriter ();
+ CloseStartElement ();
+
+ w.Write ("<!--{0}-->", text);
}
[MonoTODO]
@@ -190,10 +210,12 @@ namespace System.Xml
public override void WriteEndElement ()
{
if (openStartElement) {
- w.Write(" />");
+ w.Write (" />");
+ openElements.Pop ();
+ openStartElement = false;
}
else {
- w.Write("</{0}>", openElements.Pop());
+ w.Write ("</{0}>", openElements.Pop ());
}
}
@@ -224,10 +246,13 @@ namespace System.Xml
public override void WriteProcessingInstruction (string name, string text)
{
if ((name == null) || (name == string.Empty) || (name.IndexOf("?>") > 0) || (text.IndexOf("?>") > 0)) {
- throw new ArgumentException();
+ throw new ArgumentException ();
}
- w.Write("<?{0} {1}?>", name, text);
+ CheckOpenWriter ();
+ CloseStartElement ();
+
+ w.Write ("<?{0} {1}?>", name, text);
}
[MonoTODO]
@@ -269,19 +294,19 @@ namespace System.Xml
[MonoTODO("Not dealing with prefix and ns yet.")]
public override void WriteStartElement (string prefix, string localName, string ns)
{
- CheckOpenWriter();
- CloseStartElement();
- w.Write("<{0}", localName);
- openElements.Push(localName);
+ CheckOpenWriter ();
+ CloseStartElement ();
+ w.Write ("<{0}", localName);
+ openElements.Push (localName);
openStartElement = true;
}
[MonoTODO("Haven't done any entity replacements yet.")]
public override void WriteString (string text)
{
- CheckOpenWriter();
- CloseStartElement();
- w.Write(text);
+ CheckOpenWriter ();
+ CloseStartElement ();
+ w.Write (text);
}
[MonoTODO]
diff --git a/mcs/class/System.XML/Test/ChangeLog b/mcs/class/System.XML/Test/ChangeLog
index cb45a568791..927c6aa8097 100644
--- a/mcs/class/System.XML/Test/ChangeLog
+++ b/mcs/class/System.XML/Test/ChangeLog
@@ -1,5 +1,13 @@
2002-03-17 Kral Ferch <kral_ferch@hotmail.com>
+ * XmlDocumentTests.cs: TestOuterXml.
+
+ * XmlTextWriterTests.cs: Tests for CData, Close, Comment, Element,
+ and ProcessingInstruction.
+
+
+2002-03-17 Kral Ferch <kral_ferch@hotmail.com>
+
* XmlDocumentTests.cs: More LoadXml tests.
* XmlTextWriterTests.cs: Test for invalid Processing Instructions.
diff --git a/mcs/class/System.XML/Test/XmlDocumentTests.cs b/mcs/class/System.XML/Test/XmlDocumentTests.cs
index 62035ed6442..dbb8b3e4a80 100644
--- a/mcs/class/System.XML/Test/XmlDocumentTests.cs
+++ b/mcs/class/System.XML/Test/XmlDocumentTests.cs
@@ -48,9 +48,21 @@ namespace Ximian.Mono.Tests
public void TestLoadXMLComment()
{
+// XmlTextReader needs to throw this exception
+// try {
+// document.LoadXml("<!--foo-->");
+// Fail("XmlException should have been thrown.");
+// }
+// catch (XmlException e) {
+// AssertEquals("Exception message doesn't match.", "The root element is missing.", e.Message);
+// }
+
document.LoadXml ("<foo><!--Comment--></foo>");
Assert (document.DocumentElement.FirstChild.NodeType == XmlNodeType.Comment);
AssertEquals ("Comment", document.DocumentElement.FirstChild.Value);
+
+ document.LoadXml (@"<foo><!--bar--></foo>");
+ AssertEquals ("Incorrect target.", "bar", ((XmlComment)document.FirstChild.FirstChild).Data);
}
public void TestLoadXmlElementSingle ()
@@ -108,5 +120,22 @@ namespace Ximian.Mono.Tests
AssertEquals ("Incorrect target.", "foo", ((XmlProcessingInstruction)document.FirstChild).Target);
AssertEquals ("Incorrect data.", "bar='baaz' quux='quuux'", ((XmlProcessingInstruction)document.FirstChild).Data);
}
+
+ public void TestOuterXml ()
+ {
+ string xml;
+
+ xml = "<root><![CDATA[foo]]></root>";
+ document.LoadXml (xml);
+ AssertEquals("XmlDocument with cdata OuterXml is incorrect.", xml, document.OuterXml);
+
+ xml = "<root><!--foo--></root>";
+ document.LoadXml (xml);
+ AssertEquals("XmlDocument with comment OuterXml is incorrect.", xml, document.OuterXml);
+
+ xml = "<root><?foo bar?></root>";
+ document.LoadXml (xml);
+ AssertEquals("XmlDocument with processing instruction OuterXml is incorrect.", xml, document.OuterXml);
+ }
}
}
diff --git a/mcs/class/System.XML/Test/XmlTextWriterTests.cs b/mcs/class/System.XML/Test/XmlTextWriterTests.cs
index cb3068a3a55..6480bd2020c 100644
--- a/mcs/class/System.XML/Test/XmlTextWriterTests.cs
+++ b/mcs/class/System.XML/Test/XmlTextWriterTests.cs
@@ -29,18 +29,82 @@ namespace Ximian.Mono.Tests
xtw = new XmlTextWriter (sw);
}
- public void TestCData ()
+ public void TestCDataValid ()
{
xtw.WriteCData ("foo");
- AssertEquals ("WriteCData had incorrect output.", sw.GetStringBuilder().ToString(), "<![CDATA[foo]]>");
+ AssertEquals ("WriteCData had incorrect output.", "<![CDATA[foo]]>", sw.GetStringBuilder().ToString());
}
- public void TestComment ()
+ public void TestCDataInvalid ()
+ {
+ try {
+ xtw.WriteCData("foo]]>bar");
+ Fail("Should have thrown an ArgumentException.");
+ }
+ catch (ArgumentException) { }
+ }
+
+ public void TestCloseOpenElements ()
+ {
+ xtw.WriteStartElement("foo");
+ xtw.WriteStartElement("bar");
+ xtw.WriteStartElement("baz");
+ xtw.Close();
+ AssertEquals ("Close didn't write out end elements properly.", "<foo><bar><baz /></bar></foo>",
+ sw.GetStringBuilder().ToString());
+ }
+
+ public void TestCloseWriteAfter ()
+ {
+ xtw.WriteElementString("foo", "bar");
+ xtw.Close();
+
+ try {
+ xtw.WriteCData ("foo");
+ Fail ("WriteCData after Close Should have thrown an InvalidOperationException.");
+ }
+ catch (InvalidOperationException e) {
+ AssertEquals ("InvalidOperationException message incorrect.", "The Writer is closed.", e.Message);
+ }
+
+ try {
+ xtw.WriteComment ("foo");
+ Fail ("WriteComment after Close Should have thrown an InvalidOperationException.");
+ }
+ catch (InvalidOperationException e) {
+ AssertEquals ("InvalidOperationException message incorrect.", "The Writer is closed.", e.Message);
+ }
+
+ try {
+ xtw.WriteProcessingInstruction ("foo", "bar");
+ Fail ("WriteProcessingInstruction after Close Should have thrown an InvalidOperationException.");
+ }
+ catch (InvalidOperationException e) {
+ AssertEquals ("InvalidOperationException message incorrect.", "The Writer is closed.", e.Message);
+ }
+ }
+
+ public void TestCommentValid ()
{
xtw.WriteComment ("foo");
AssertEquals ("WriteComment had incorrect output.", "<!--foo-->", sw.GetStringBuilder().ToString());
}
+ public void TestCommentInvalid ()
+ {
+ try {
+ xtw.WriteComment("foo-");
+ Fail("Should have thrown an ArgumentException.");
+ }
+ catch (ArgumentException) { }
+
+ try {
+ xtw.WriteComment("foo-->bar");
+ Fail("Should have thrown an ArgumentException.");
+ }
+ catch (ArgumentException) { }
+ }
+
public void TestElementEmpty ()
{
xtw.WriteStartElement ("foo");
@@ -54,6 +118,12 @@ namespace Ximian.Mono.Tests
AssertEquals ("WriteElementString has incorrect output.", "<foo>bar</foo>", sw.GetStringBuilder().ToString());
}
+ public void TestProcessingInstructionValid ()
+ {
+ xtw.WriteProcessingInstruction("foo", "bar");
+ AssertEquals ("WriteProcessingInstruction had incorrect output.", "<?foo bar?>", sw.GetStringBuilder().ToString());
+ }
+
public void TestProcessingInstructionInvalid ()
{
try {