InnerXml, OuterXml, WriteContentTo, and WriteTo for most XmlNode derivatives.
authorKral Ferch <kral@mono-cvs.ximian.com>
Tue, 9 Apr 2002 01:38:59 +0000 (01:38 -0000)
committerKral Ferch <kral@mono-cvs.ximian.com>
Tue, 9 Apr 2002 01:38:59 +0000 (01:38 -0000)
svn path=/trunk/mcs/; revision=3704

22 files changed:
mcs/class/System.XML/System.Xml/ChangeLog
mcs/class/System.XML/System.Xml/XmlAttribute.cs
mcs/class/System.XML/System.Xml/XmlDeclaration.cs
mcs/class/System.XML/System.Xml/XmlDocument.cs
mcs/class/System.XML/System.Xml/XmlElement.cs
mcs/class/System.XML/System.Xml/XmlNode.cs
mcs/class/System.XML/System.Xml/XmlSignificantWhitespace.cs
mcs/class/System.XML/System.Xml/XmlText.cs
mcs/class/System.XML/System.Xml/XmlTextWriter.cs
mcs/class/System.XML/System.Xml/XmlWhitespace.cs
mcs/class/System.XML/Test/AllTests.cs
mcs/class/System.XML/Test/ChangeLog
mcs/class/System.XML/Test/MonoMicro.Test.csproj
mcs/class/System.XML/Test/XmlAttributeTests.cs
mcs/class/System.XML/Test/XmlCDataSectionTests.cs
mcs/class/System.XML/Test/XmlCommentTests.cs
mcs/class/System.XML/Test/XmlDeclarationTests.cs
mcs/class/System.XML/Test/XmlDocumentTests.cs
mcs/class/System.XML/Test/XmlElementTests.cs
mcs/class/System.XML/Test/XmlSignificantWhitespaceTests.cs
mcs/class/System.XML/Test/XmlTextWriterTests.cs
mcs/class/System.XML/Test/XmlWhiteSpaceTests.cs

index 659fe086fc5e53f1cc877e6f1b89452877475c8d..fb57fd907cf3ea6d6be01cc60bb2196580f3589d 100644 (file)
@@ -1,3 +1,24 @@
+2002-04-08  Kral Ferch  <kral_ferch@hotmail.com>
+
+       * XmlAttributes.cs: InnerXml getter, WriteContentTo, and WriteTo
+       implementations.
+       
+       * XmlDeclaration.cs: WriteTo implementation.
+       
+       * XmlDocument.cs: InnerXml getter implementation.
+       
+       * XmlElement.cs: InnerXml getter implementation.
+
+       * XmlNode.cs: Removed MonoTODO attrib on OuterXml.
+       
+       * XmlSignificantWhitespace.cs: WriteTo implementation.
+       
+       * XmlText.cs: WriteContentTo and WriteTo implementation.
+       
+       * XmlTextWriter.cs: WriteRaw implementation.
+       
+       * XmlWhitespace.cs: WriteContentTo and WriteTo implementations.
+
 2002-04-05  Kral Ferch  <kral_ferch@hotmail.com>
 
        * XmlAttributes.cs: Added reminder MonoTODO to set NamespaceURI
index 054eb655cbc54bfdcd1030a309c7c2cb8b6d07a8..c70108325dc9ff13680e19bb6dfb75548a1fc477 100644 (file)
@@ -59,10 +59,11 @@ namespace System.Xml
                        }
                }
 
-               [MonoTODO]
+               [MonoTODO ("Setter.")]
                public override string InnerXml {
                        get {
-                               throw new NotImplementedException ();
+                               // Not sure why this is an override.  Passing through for now.
+                               return base.InnerXml;
                        }
 
                        set {
@@ -166,16 +167,14 @@ namespace System.Xml
                        this.ownerElement = ownerElement;
                }
 
-               [MonoTODO]
                public override void WriteContentTo (XmlWriter w)
                {
-                       throw new NotImplementedException ();
+                       w.WriteString (Value);
                }
 
-               [MonoTODO]
                public override void WriteTo (XmlWriter w)
                {
-                       throw new NotImplementedException ();
+                       w.WriteAttributeString (prefix, localName, namespaceURI, Value);
                }
 
                #endregion
index e1dcf421527bbd175edfae34f7e5ba3402858a5c..8f1974e4d9aef7fd34764e2427267795bcf1f5fd 100644 (file)
@@ -89,16 +89,13 @@ namespace System.Xml
                        return new XmlDeclaration (Version, Encoding, standalone, OwnerDocument);
                }
 
-               public override void WriteContentTo (XmlWriter w)
-               {
-                       // Nothing to do - no children.
-               }
+               public override void WriteContentTo (XmlWriter w) {}
 
-               [MonoTODO]
                public override void WriteTo (XmlWriter w)
                {
-                       if ((Standalone == String.Empty) || (Encoding == String.Empty))
-                               return;
+                       // This doesn't seem to match up very well with w.WriteStartDocument()
+                       // so writing out custom here.
+                       w.WriteRaw (String.Format ("<?xml {0}?>", Value));
                }
 
                void ParseInput (string input)
index 15c5e641d2b851b36064797e3df66c3f63e9290d..765c1a810b63263433491c663a768be79d6e113f 100644 (file)
@@ -86,9 +86,12 @@ namespace System.Xml
                        get { throw new NotImplementedException(); }
                }
 
-               [MonoTODO]
+               [MonoTODO ("Setter.")]
                public override string InnerXml {
-                       get { throw new NotImplementedException(); }
+                       get {
+                               // Not sure why this is an override.  Passing through for now.
+                               return base.InnerXml;
+                       }
                        set { throw new NotImplementedException(); }
                }
 
@@ -147,13 +150,11 @@ namespace System.Xml
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public XmlAttribute CreateAttribute (string name)
                {
                        return CreateAttribute (name, String.Empty);
                }
 
-               [MonoTODO]
                public XmlAttribute CreateAttribute (string qualifiedName, string namespaceURI)
                {
                        string prefix;
index 41758ae7dd05993a9d3c79a4ab0d86b90a1db5cc..8963918f9bb708817e18d77b99b12851c88c4acc 100644 (file)
@@ -57,10 +57,12 @@ namespace System.Xml
                        set { throw new NotImplementedException (); }
                }
 
-               [MonoTODO]
+               [MonoTODO ("Setter.")]
                public override string InnerXml {
-                       get { throw new NotImplementedException (); }
-
+                       get {
+                               // Not sure why this is an override.  Passing through for now.
+                               return base.InnerXml;
+                       }
                        set { throw new NotImplementedException (); }
                }
 
index d25998638e6c797ef1c546526aab5ee30bc9c2bd..87fbc8aa2141ed642b2509944ac385a8a9fa5a73 100644 (file)
@@ -143,7 +143,6 @@ namespace System.Xml
 
                public abstract XmlNodeType NodeType { get;     }
 
-               [MonoTODO]
                public virtual string OuterXml {
                        get {
                                StringWriter sw = new StringWriter ();
index b4c08037d9397cae38d13f69c286f17ce9ac1f36..8999730699947a6a27228c80855886b70c59aa96 100644 (file)
@@ -1,56 +1,53 @@
-//\r
-// System.Xml.XmlSignificantWhitespace.cs\r
-//\r
-// Author:\r
-//     Duncan Mak  (duncan@ximian.com)\r
-//\r
-// (C) Ximian, Inc. http://www.ximian.com\r
-//\r
-\r
-using System;\r
-\r
-namespace System.Xml\r
-{\r
-       public class XmlSignificantWhitespace : XmlCharacterData\r
-       {\r
-               // Constructor\r
-               protected internal XmlSignificantWhitespace (string strData, XmlDocument doc)\r
-                       : base (strData, doc)\r
-               {\r
-               }\r
-               \r
-               // Properties\r
-               public override string LocalName {\r
-                       get { return "#significant-whitespace"; }\r
-               }\r
-\r
-               public override string Name {\r
-                       get { return "#significant-whitespace"; }\r
-               }\r
-\r
-               public override XmlNodeType NodeType {\r
-                       get { return XmlNodeType.SignificantWhitespace; }\r
-               }\r
-\r
-               public override string Value {\r
-                       get { return Data; }\r
-                       set {}\r
-               }\r
-\r
-               // Methods\r
-               public override XmlNode CloneNode (bool deep)\r
-               {\r
-                       return new XmlSignificantWhitespace (Data, OwnerDocument);\r
-               }\r
-\r
-               [MonoTODO]\r
-               public override void WriteContentTo (XmlWriter w)\r
-               {                       \r
-               }\r
-\r
-               [MonoTODO]\r
-               public override void WriteTo (XmlWriter w)\r
-               {                       \r
-               }\r
-       }\r
-}\r
+//
+// System.Xml.XmlSignificantWhitespace.cs
+//
+// Author:
+//     Duncan Mak  (duncan@ximian.com)
+//
+// (C) Ximian, Inc. http://www.ximian.com
+//
+
+using System;
+
+namespace System.Xml
+{
+       public class XmlSignificantWhitespace : XmlCharacterData
+       {
+               // Constructor
+               protected internal XmlSignificantWhitespace (string strData, XmlDocument doc)
+                       : base (strData, doc)
+               {
+               }
+               
+               // Properties
+               public override string LocalName {
+                       get { return "#significant-whitespace"; }
+               }
+
+               public override string Name {
+                       get { return "#significant-whitespace"; }
+               }
+
+               public override XmlNodeType NodeType {
+                       get { return XmlNodeType.SignificantWhitespace; }
+               }
+
+               public override string Value {
+                       get { return Data; }
+                       set {}
+               }
+
+               // Methods
+               public override XmlNode CloneNode (bool deep)
+               {
+                       return new XmlSignificantWhitespace (Data, OwnerDocument);
+               }
+
+               public override void WriteContentTo (XmlWriter w) {}
+
+               public override void WriteTo (XmlWriter w)
+               {
+                       w.WriteWhitespace (Data);
+               }
+       }
+}
index 9f10e49e18685b052201d157ddd1e94f6f9b594f..59f2ba1477f64f1f0b327416599f694ca9cc0459 100644 (file)
@@ -57,16 +57,11 @@ namespace System.Xml
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
-               public override void WriteContentTo (XmlWriter w)
-               {
-                       throw new NotImplementedException ();
-               }
+               public override void WriteContentTo (XmlWriter w) {}
 
-               [MonoTODO]
                public override void WriteTo (XmlWriter w)
                {
-                       throw new NotImplementedException ();
+                       w.WriteString (Data);
                }
 
                #endregion
index 5d0de250549ceb11fe6bcb3a735506b3770aa021..a598695b306666a6b7319b0984baa9a0caf5593a 100644 (file)
@@ -412,10 +412,9 @@ namespace System.Xml
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public override void WriteRaw (string data)
                {
-                       throw new NotImplementedException ();
+                       WriteStringInternal (data, false);
                }
 
                [MonoTODO]
@@ -568,21 +567,31 @@ namespace System.Xml
                        if (ws == WriteState.Prolog)
                                throw new InvalidOperationException ("Token content in state Prolog would result in an invalid XML document.");
 
+                       WriteStringInternal (text, true);
+               }
+
+               public void WriteStringInternal (string text, bool entitize)
+               {
                        if (text == null)
                                text = String.Empty;
 
-                       if (text != String.Empty) {
+                       if (text != String.Empty) 
+                       {
                                CheckState ();
 
-                               text = text.Replace ("&", "&amp;");
-                               text = text.Replace ("<", "&lt;");
-                               text = text.Replace (">", "&gt;");
-                               
-                               if (openAttribute) {
-                                       if (quoteChar == '"')
-                                               text = text.Replace ("\"", "&quot;");
-                                       else
-                                               text = text.Replace ("'", "&apos;");
+                               if (entitize)
+                               {
+                                       text = text.Replace ("&", "&amp;");
+                                       text = text.Replace ("<", "&lt;");
+                                       text = text.Replace (">", "&gt;");
+                                       
+                                       if (openAttribute) 
+                                       {
+                                               if (quoteChar == '"')
+                                                       text = text.Replace ("\"", "&quot;");
+                                               else
+                                                       text = text.Replace ("'", "&apos;");
+                                       }
                                }
 
                                if (!openAttribute)
@@ -590,11 +599,14 @@ namespace System.Xml
 
                                if (!openXmlLang && !openXmlSpace)
                                        w.Write (text);
-                               else {
+                               else 
+                               {
                                        if (openXmlLang)
                                                xmlLang = text;
-                                       else {
-                                               switch (text) {
+                                       else 
+                                       {
+                                               switch (text) 
+                                               {
                                                        case "default":
                                                                xmlSpace = XmlSpace.Default;
                                                                break;
index 610ec9c7d54fa38a7af512947ee3d083e26a25cf..fd8da124919758d98a7e90302ebfdc748341dc2f 100644 (file)
@@ -45,14 +45,11 @@ namespace System.Xml
                        return new XmlWhitespace (Data, OwnerDocument); 
                }
 
-               [MonoTODO]
-               public override void WriteContentTo (XmlWriter w)
-               {                       
-               }
+               public override void WriteContentTo (XmlWriter w) {}
 
-               [MonoTODO]
                public override void WriteTo (XmlWriter w)
-               {                       
+               {
+                       w.WriteWhitespace (Data);
                }
        }
 }
index 3551d7b3aac931b9065674f93efb99978a9f5bd2..e97c32e34ebed3c59932a408f1feef5d082d2e28 100644 (file)
@@ -19,6 +19,8 @@ namespace Ximian.Mono.Tests
                public static ITest Suite {
                        get {
                                TestSuite suite =  new TestSuite ();
+                               suite.AddTest (new TestSuite (typeof (XmlProcessingInstructionTests)));
+                               suite.AddTest (new TestSuite (typeof (XmlTextTests)));
                                suite.AddTest (new TestSuite (typeof (XmlTextReaderTests)));
                                suite.AddTest (new TestSuite (typeof (XmlTextWriterTests)));
                                suite.AddTest (new TestSuite (typeof (XmlNamespaceManagerTests)));
index c81b68c5514fb82026b25c54829b254362a4aafa..0fbb63d007d7b5037c8b50c5d98403ac301fb2a1 100644 (file)
@@ -1,3 +1,33 @@
+2002-04-08  Kral Ferch  <kral_ferch@hotmail.com>
+
+       * AllTests.cs: added XmlProcessingInstructionTests and XmlTextTests.
+       
+       * MonoMicro.Test.csproj: Added XmlProcessingInstructionTests.cs and
+       XmlTextTests.cs.
+       
+       * XmlAttributeTests.cs: Added TestAttributeInnerAndOuterXml.
+       
+       * XmlCDataSectionTests.cs: Added TestXmlCDataSectionInnerAndOuterXml.
+       
+       * XmlCommentTests.cs: Added TestXmlCommentInnerAndOuterXml.
+       
+       * XmlDeclarationTests.cs: Added TestInnerAndOuterXml.
+       
+       * XmlDocumentTests.cs: Added TestInnerAndOuterXml.
+       
+       * XmlElementTests.cs: Added TestInnerAndOuterXml.
+       
+       * XmlProcessingInstructionTests.cs: Initial check-in.
+       
+       * XmlSignificantWhitespaceTests.cs: Added TestInnerAndOuterXml.
+       
+       * XmlTextTests.cs: Initial check-in.
+       
+       * XmlTextWriterTests.cs: Added TestWriteRaw, TestWriteRawInvalidInAttribute,
+       and TestXmlSpaceRaw.
+       
+       * XmlWhiteSpacesTests.cs: Added TestInnerAndOuterXml.
+
 2002-04-05  Kral Ferch  <kral_ferch@hotmail.com>
 
        * XmlDocumentTests.cs: CreateNode tests.
index 80c2a6bfdd9524fa69ada997014892039c81ce27..0d5aea343d77ed82b499de536a3011edb73f4b22 100644 (file)
                     AssemblyName = "NUnitCore"
                     HintPath = "..\..\..\nunit\NUnitCore.dll"
                 />
+                <Reference
+                    Name = "System.Data"
+                    AssemblyName = "System.Data"
+                    HintPath = "..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Data.dll"
+                />
                 <Reference
                     Name = "System.XML"
                     AssemblyName = "System.XML"
-                    HintPath = "..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.XML.dll"
+                    HintPath = "..\obj\Debug\System.XML.dll"
                 />
             </References>
         </Build>
                     SubType = "Code"
                     BuildAction = "Compile"
                 />
+                <File
+                    RelPath = "XmlProcessingInstructionTests.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
                 <File
                     RelPath = "XmlSignificantWhitespaceTests.cs"
                     SubType = "Code"
                     SubType = "Code"
                     BuildAction = "Compile"
                 />
+                <File
+                    RelPath = "XmlTextTests.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
                 <File
                     RelPath = "XmlTextWriterTests.cs"
                     SubType = "Code"
index 9779b83fe2d7546697b92b8c1c64700c5979077f..41ca3b92dbecb22e3c22f932dca4e3ac59777431 100644 (file)
@@ -31,6 +31,14 @@ namespace Ximian.Mono.Tests
                        AssertNull(attr.Attributes);
                }
 
+               public void TestAttributeInnerAndOuterXml ()
+               {
+                       attr = doc.CreateAttribute ("foo", "bar", "http://abc.def");
+                       attr.Value = "baz";
+                       AssertEquals ("baz", attr.InnerXml);
+                       AssertEquals ("foo:bar=\"baz\"", attr.OuterXml);
+               }
+
                public void TestAttributeWithNoValue ()
                {
                        XmlAttribute attribute = doc.CreateAttribute ("name");
index f1cc1ae264927f1aeca0db847f2eb745f9c2d4ee..84bc194af2c556a14c9b9898a7b3e46f8c6f36b3 100755 (executable)
@@ -47,6 +47,13 @@ namespace Ximian.Mono.Tests
                         Assert ("Copies, not pointers", !Object.ReferenceEquals (original,cloned));
                }
               
+               public void TestXmlCDataSectionInnerAndOuterXml ()
+               {
+                       section = document.CreateCDataSection ("foo");
+                       AssertEquals (String.Empty, section.InnerXml);
+                       AssertEquals ("<![CDATA[foo]]>", section.OuterXml);
+               }
+
                public void TestXmlCDataSectionName ()
                {
                        AssertEquals (section.NodeType + " Name property broken",
index 35f3afd0ba08cb13a3d970be8e5579f7fcb3bf7b..f3602699e8a2c69a78e2916d8b9ab9354cc75fb9 100755 (executable)
@@ -22,73 +22,86 @@ namespace Ximian.Mono.Tests
                XmlNode deep;
                XmlNode shallow;
 
-               public XmlCommentTests ()
-                       : base ("Ximian.Mono.Tests.XmlCommentTests testsuite")
-               {
-               }
+               public XmlCommentTests () : base ("Ximian.Mono.Tests.XmlCommentTests testsuite") {}
 
-               public XmlCommentTests (string name)
-                       : base (name)
-               {
-               }
+               public XmlCommentTests (string name) : base (name) {}
 
                protected override void SetUp ()
                {
                        document = new XmlDocument ();
-                       document.LoadXml ("<root><foo></foo></root>");
-                       comment = document.CreateComment ("Comment");
                }
 
-               internal void TestXmlNodeBaseProperties (XmlNode original, XmlNode cloned)
+               public void TestXmlCommentCloneNode ()
                {
-//                     assertequals (original.nodetype + " was incorrectly cloned.",
-//                                   original.baseuri, cloned.baseuri);                        
+                       document.LoadXml ("<root><foo></foo></root>");
+                       comment = document.CreateComment ("Comment");
+                       original = comment;
 
-                       AssertNull (cloned.ParentNode);
+                       shallow = comment.CloneNode (false); // shallow
+                       TestXmlNodeBaseProperties (original, shallow);
+                       
+                       deep = comment.CloneNode (true); // deep
+                       TestXmlNodeBaseProperties (original, deep);
                        AssertEquals ("Value incorrectly cloned",
-                                     original.Value, cloned.Value);
+                               original.Value, deep.Value);
 
-                        Assert ("Copies, not pointers", !Object.ReferenceEquals (original,cloned));
+                       AssertEquals ("deep cloning differs from shallow cloning",
+                               deep.OuterXml, shallow.OuterXml);
                }
-              
-               public void TestXmlCommentName ()
+
+               public void TestXmlCommentInnerAndOuterXml ()
                {
-                       AssertEquals (comment.NodeType + " Name property broken",
-                                     comment.Name, "#comment");
+                       comment = document.CreateComment ("foo");
+                       AssertEquals (String.Empty, comment.InnerXml);
+                       AssertEquals ("<!--foo-->", comment.OuterXml);
+               }
+
+               public void TestXmlCommentIsReadOnly ()
+               {
+                       document.LoadXml ("<root><foo></foo></root>");
+                       comment = document.CreateComment ("Comment");
+                       AssertEquals ("XmlComment IsReadOnly property broken",
+                               comment.IsReadOnly, false);
                }
 
                public void TestXmlCommentLocalName ()
                {
+                       document.LoadXml ("<root><foo></foo></root>");
+                       comment = document.CreateComment ("Comment");
                        AssertEquals (comment.NodeType + " LocalName property broken",
                                      comment.LocalName, "#comment");
                }
 
+               public void TestXmlCommentName ()
+               {
+                       document.LoadXml ("<root><foo></foo></root>");
+                       comment = document.CreateComment ("Comment");
+                       AssertEquals (comment.NodeType + " Name property broken",
+                               comment.Name, "#comment");
+               }
+
                public void TestXmlCommentNodeType ()
                {
+                       document.LoadXml ("<root><foo></foo></root>");
+                       comment = document.CreateComment ("Comment");
                        AssertEquals ("XmlComment NodeType property broken",
                                      comment.NodeType.ToString (), "Comment");
                }
 
-               public void TestXmlCommentIsReadOnly ()
+               internal void TestXmlNodeBaseProperties (XmlNode original, XmlNode cloned)
                {
-                       AssertEquals ("XmlComment IsReadOnly property broken",
-                                     comment.IsReadOnly, false);
-               }
+                       document.LoadXml ("<root><foo></foo></root>");
+                       comment = document.CreateComment ("Comment");
 
-               public void TestXmlCommentCloneNode ()
-               {
-                       original = comment;
+                       //                      assertequals (original.nodetype + " was incorrectly cloned.",
+                       //                                    original.baseuri, cloned.baseuri);                        
 
-                       shallow = comment.CloneNode (false); // shallow
-                       TestXmlNodeBaseProperties (original, shallow);
-                       
-                       deep = comment.CloneNode (true); // deep
-                       TestXmlNodeBaseProperties (original, deep);
+                       AssertNull (cloned.ParentNode);
                        AssertEquals ("Value incorrectly cloned",
-                                      original.Value, deep.Value);
+                               original.Value, cloned.Value);
 
-                        AssertEquals ("deep cloning differs from shallow cloning",
-                                     deep.OuterXml, shallow.OuterXml);
+                       Assert ("Copies, not pointers", !Object.ReferenceEquals (original,cloned));
                }
+       
        }
 }
index 2dd0e34d55e01da23256a3ec5d275c95f9f0ca66..c362e8769ed7730af8d3e0601572b32164b679a4 100755 (executable)
@@ -20,15 +20,9 @@ namespace Ximian.Mono.Tests
                XmlDocument document;
                XmlDeclaration declaration;
                
-               public XmlDeclarationTests ()
-                       : base ("Ximian.Mono.Tests.XmlDeclarationTests testsuite")
-               {
-               }
+               public XmlDeclarationTests () : base ("Ximian.Mono.Tests.XmlDeclarationTests testsuite") {}
                
-               public XmlDeclarationTests (string name)
-                       : base (name)
-               {
-               }
+               public XmlDeclarationTests (string name) : base (name) {}
 
                protected override void SetUp ()
                {
@@ -37,6 +31,25 @@ namespace Ximian.Mono.Tests
                        declaration = document.CreateXmlDeclaration ("1.0", null, null);
                }
 
+               public void TestInnerAndOuterXml ()
+               {
+                       declaration = document.CreateXmlDeclaration ("1.0", null, null);
+                       AssertEquals (String.Empty, declaration.InnerXml);
+                       AssertEquals ("<?xml version=\"1.0\"?>", declaration.OuterXml);
+
+                       declaration = document.CreateXmlDeclaration ("1.0", "doesn't check", null);
+                       AssertEquals (String.Empty, declaration.InnerXml);
+                       AssertEquals ("<?xml version=\"1.0\" encoding=\"doesn't check\"?>", declaration.OuterXml);
+
+                       declaration = document.CreateXmlDeclaration ("1.0", null, "yes");
+                       AssertEquals (String.Empty, declaration.InnerXml);
+                       AssertEquals ("<?xml version=\"1.0\" standalone=\"yes\"?>", declaration.OuterXml);
+
+                       declaration = document.CreateXmlDeclaration ("1.0", "foo", "no");
+                       AssertEquals (String.Empty, declaration.InnerXml);
+                       AssertEquals ("<?xml version=\"1.0\" encoding=\"foo\" standalone=\"no\"?>", declaration.OuterXml);
+               }
+
                internal void TestXmlNodeBaseProperties (XmlNode original, XmlNode cloned)
                {
 //                     assertequals (original.nodetype + " was incorrectly cloned.",
index ffe822b4d02de7238648c63f98b2381162841b0a..5dd96282a9ca6f99ffcbc59585d8b6622f4c8a33 100644 (file)
@@ -193,6 +193,38 @@ namespace Ximian.Mono.Tests
                        AssertEquals ("Incorrect output for empty document.", "", document.OuterXml);
                }
 
+               public void TestInnerAndOuterXml ()
+               {
+                       AssertEquals (String.Empty, document.InnerXml);
+                       AssertEquals (document.InnerXml, document.OuterXml);
+
+                       XmlDeclaration declaration = document.CreateXmlDeclaration ("1.0", null, null);
+                       document.AppendChild (declaration);
+                       AssertEquals ("<?xml version=\"1.0\"?>", document.InnerXml);
+                       AssertEquals (document.InnerXml, document.OuterXml);
+
+                       XmlElement element = document.CreateElement ("foo");
+                       document.AppendChild (element);
+                       AssertEquals ("<?xml version=\"1.0\"?><foo />", document.InnerXml);
+                       AssertEquals (document.InnerXml, document.OuterXml);
+
+                       XmlComment comment = document.CreateComment ("bar");
+                       document.DocumentElement.AppendChild (comment);
+                       AssertEquals ("<?xml version=\"1.0\"?><foo><!--bar--></foo>", document.InnerXml);
+                       AssertEquals (document.InnerXml, document.OuterXml);
+
+                       XmlText text = document.CreateTextNode ("baz");
+                       document.DocumentElement.AppendChild (text);
+                       AssertEquals ("<?xml version=\"1.0\"?><foo><!--bar-->baz</foo>", document.InnerXml);
+                       AssertEquals (document.InnerXml, document.OuterXml);
+
+                       element = document.CreateElement ("quux");
+                       element.SetAttribute ("quuux", "squonk");
+                       document.DocumentElement.AppendChild (element);
+                       AssertEquals ("<?xml version=\"1.0\"?><foo><!--bar-->baz<quux quuux=\"squonk\" /></foo>", document.InnerXml);
+                       AssertEquals (document.InnerXml, document.OuterXml);
+               }
+
                public void TestLoadXmlCDATA ()
                {
                        document.LoadXml ("<foo><![CDATA[bar]]></foo>");
index 9dbe7c43498c803e74202a3e85f96dd0ef2497bd..895c903cd173094ca375747248a0b52fe4c62b4a 100644 (file)
@@ -37,6 +37,30 @@ namespace Ximian.Mono.Tests
                        //AssertEquals (attributesCount, element.Attributes.Count);
                }
 
+               public void TestCloneNode ()
+               {
+                       XmlElement element = document.CreateElement ("foo");
+                       XmlElement child = document.CreateElement ("bar");
+                       XmlElement grandson = document.CreateElement ("baz");
+
+                       element.SetAttribute ("attr1", "val1");
+                       element.SetAttribute ("attr2", "val2");
+                       element.AppendChild (child);
+                       child.SetAttribute ("attr3", "val3");
+                       child.AppendChild (grandson);
+                        
+                       document.AppendChild (element);
+                       XmlNode deep = element.CloneNode (true);
+                       // AssertEquals ("These should be the same", deep.OuterXml, element.OuterXml); 
+                       AssertNull ("This is not null", deep.ParentNode);
+                       Assert ("Copies, not pointers", !Object.ReferenceEquals (element,deep));
+
+                       XmlNode shallow = element.CloneNode (false);
+                       AssertNull ("This is not null", shallow.ParentNode);
+                       Assert ("Copies, not pointers", !Object.ReferenceEquals (element,shallow));
+                       AssertEquals ("Shallow clones shalt have no children!", false, shallow.HasChildNodes);
+               }
+
                public void TestCreateElement1 ()
                {
                        XmlElement element = document.CreateElement ("name");
@@ -68,37 +92,40 @@ namespace Ximian.Mono.Tests
                        AssertElement (element, "prefix", "localName", "namespaceURI", 0);
                }
 
-               public void TestSetGetAttribute ()
+               public void TestInnerAndOuterXml ()
                {
-                       XmlElement element = document.CreateElement ("foo");
-                       element.SetAttribute ("attr1", "val1");
-                       element.SetAttribute ("attr2", "val2");
-                       AssertEquals ("val1", element.GetAttribute ("attr1"));
-                       AssertEquals ("val2", element.GetAttribute ("attr2"));
+                       XmlElement element;
+                       XmlText text;
+                       XmlComment comment;
+                       
+                       element = document.CreateElement ("foo");
+                       AssertEquals (String.Empty, element.InnerXml);
+                       AssertEquals ("<foo />", element.OuterXml);
+
+                       text = document.CreateTextNode ("bar");
+                       element.AppendChild (text);
+                       AssertEquals ("bar", element.InnerXml);
+                       AssertEquals ("<foo>bar</foo>", element.OuterXml);
+
+                       element.SetAttribute ("baz", "quux");
+                       AssertEquals ("bar", element.InnerXml);
+                       AssertEquals ("<foo baz=\"quux\">bar</foo>", element.OuterXml);
+
+                       comment = document.CreateComment ("squonk");
+                       element.AppendChild (comment);
+                       AssertEquals ("bar<!--squonk-->", element.InnerXml);
+                       AssertEquals ("<foo baz=\"quux\">bar<!--squonk--></foo>", element.OuterXml);
+
+
                }
 
-               public void TestCloneNode ()
+               public void TestSetGetAttribute ()
                {
                        XmlElement element = document.CreateElement ("foo");
-                        XmlElement child = document.CreateElement ("bar");
-                        XmlElement grandson = document.CreateElement ("baz");
-
                        element.SetAttribute ("attr1", "val1");
                        element.SetAttribute ("attr2", "val2");
-                        element.AppendChild (child);
-                        child.SetAttribute ("attr3", "val3");
-                        child.AppendChild (grandson);
-                        
-                        document.AppendChild (element);
-                        XmlNode deep = element.CloneNode (true);
-                        // AssertEquals ("These should be the same", deep.OuterXml, element.OuterXml); 
-                        AssertNull ("This is not null", deep.ParentNode);
-                        Assert ("Copies, not pointers", !Object.ReferenceEquals (element,deep));
-
-                        XmlNode shallow = element.CloneNode (false);
-                        AssertNull ("This is not null", shallow.ParentNode);
-                        Assert ("Copies, not pointers", !Object.ReferenceEquals (element,shallow));
-                        AssertEquals ("Shallow clones shalt have no children!", false, shallow.HasChildNodes);
+                       AssertEquals ("val1", element.GetAttribute ("attr1"));
+                       AssertEquals ("val2", element.GetAttribute ("attr2"));
                }
        }
 }
index 6de4b2d558d9ab8976769a4570e9bab3c383cfbd..165fb69671d7622a200660cc2e961b60d42f62dd 100755 (executable)
@@ -17,21 +17,15 @@ namespace Ximian.Mono.Tests
        public class XmlSignificantWhitespaceTests : TestCase
        {
                XmlDocument document;
+               XmlDocument doc2;
                XmlSignificantWhitespace whitespace;
                XmlSignificantWhitespace broken;
-                XmlNode original;
-                XmlNode deep;
-                XmlNode shallow;
+        XmlNode original;
+        XmlNode deep;
+        XmlNode shallow;
                
-               public XmlSignificantWhitespaceTests ()
-                       : base ("Ximian.Mono.Tests.XmlWhitespaceTests testsuite")
-               {
-               }
-
-               public XmlSignificantWhitespaceTests (string name)
-                       : base (name)
-               {
-               }
+               public XmlSignificantWhitespaceTests () : base ("Ximian.Mono.Tests.XmlWhitespaceTests testsuite") {}
+               public XmlSignificantWhitespaceTests (string name) : base (name) {}
 
                protected override void SetUp ()
                {
@@ -40,8 +34,17 @@ namespace Ximian.Mono.Tests
                        XmlElement element = document.CreateElement ("foo");
                        whitespace = document.CreateSignificantWhitespace ("\r\n");
                        element.AppendChild (whitespace);
+
+                       doc2 = new XmlDocument ();
                }
 
+               public void TestInnerAndOuterXml ()
+               {
+                       whitespace = doc2.CreateSignificantWhitespace ("\r\n\t ");
+                       AssertEquals (String.Empty, whitespace.InnerXml);
+                       AssertEquals ("\r\n\t ", whitespace.OuterXml);
+               }
+                       
                internal void TestXmlNodeBaseProperties (XmlNode original, XmlNode cloned)
                {
 //                     assertequals (original.nodetype + " was incorrectly cloned.",
index 920c39f011fdbe67ec82795dcc1a93253c476645..16d49a6ad55f0bbd0068ade362484a38d2ae8920 100644 (file)
@@ -697,6 +697,28 @@ namespace Ximian.Mono.Tests
                        AssertEquals ("<foo></foo><bar foo='bar'></bar><baz bar=''></baz>", StringWriterText);
                }
 
+               public void TestWriteRaw ()
+               {
+                       xtw.WriteRaw("&<>\"'");
+                       AssertEquals ("&<>\"'", StringWriterText);
+
+                       xtw.WriteRaw(null);
+                       AssertEquals ("&<>\"'", StringWriterText);
+
+                       xtw.WriteRaw("");
+                       AssertEquals ("&<>\"'", StringWriterText);
+               }
+
+               public void TestWriteRawInvalidInAttribute ()
+               {
+                       xtw.WriteStartElement ("foo");
+                       xtw.WriteStartAttribute ("bar", null);
+                       xtw.WriteRaw ("&<>\"'");
+                       xtw.WriteEndAttribute ();
+                       xtw.WriteEndElement ();
+                       AssertEquals ("<foo bar='&<>\"'' />", StringWriterText);
+               }
+
                public void TestWriteState ()
                {
                        AssertEquals (WriteState.Start, xtw.WriteState);
@@ -820,7 +842,6 @@ namespace Ximian.Mono.Tests
                        AssertEquals (XmlSpace.Preserve, xtw.XmlSpace);
                        AssertEquals ("<foo><bar xml:space='preserve'><baz xml:space='preserve'", StringWriterText);
 
-
                        xtw.WriteStartElement ("quux");
                        xtw.WriteStartAttribute ("xml", "space", null);
                        AssertEquals (XmlSpace.Preserve, xtw.XmlSpace);
@@ -862,5 +883,21 @@ namespace Ximian.Mono.Tests
                                xtw.WriteWhitespace ("x");
                        } catch (ArgumentException) { }
                }
+
+               public void TestXmlSpaceRaw ()
+               {
+                       xtw.WriteStartElement ("foo");
+                       xtw.WriteStartAttribute ("xml", "space", null);
+                       AssertEquals (XmlSpace.None, xtw.XmlSpace);
+                       AssertEquals ("<foo xml:space='", StringWriterText);
+
+                       xtw.WriteString ("default");
+                       AssertEquals (XmlSpace.None, xtw.XmlSpace);
+                       AssertEquals ("<foo xml:space='", StringWriterText);
+
+                       xtw.WriteEndAttribute ();
+                       AssertEquals (XmlSpace.Default, xtw.XmlSpace);
+                       AssertEquals ("<foo xml:space='default'", StringWriterText);
+               }
        }
 }
index 4e3420f9a0ecb5da278b1eeaba202f43d6a60338..f0f16859d3a486afc5b86d90c96e1ac2545efe21 100755 (executable)
@@ -17,21 +17,15 @@ namespace Ximian.Mono.Tests
        public class XmlWhitespaceTests : TestCase
        {
                XmlDocument document;
+               XmlDocument doc2;
                XmlWhitespace whitespace;
                XmlWhitespace broken;
-                XmlNode original;
-                XmlNode deep;
-                XmlNode shallow;
+        XmlNode original;
+        XmlNode deep;
+        XmlNode shallow;
                
-               public XmlWhitespaceTests ()
-                       : base ("Ximian.Mono.Tests.XmlWhitespaceTests testsuite")
-               {
-               }
-
-               public XmlWhitespaceTests (string name)
-                       : base (name)
-               {
-               }
+               public XmlWhitespaceTests () : base ("Ximian.Mono.Tests.XmlWhitespaceTests testsuite") {}
+               public XmlWhitespaceTests (string name) : base (name) {}
 
                protected override void SetUp ()
                {
@@ -40,8 +34,17 @@ namespace Ximian.Mono.Tests
                        XmlElement element = document.CreateElement ("foo");
                        whitespace = document.CreateWhitespace ("\r\n");
                        element.AppendChild (whitespace);
+
+                       doc2 = new XmlDocument ();
                }
 
+               public void TestInnerAndOuterXml ()
+               {
+                       whitespace = doc2.CreateWhitespace ("\r\n\t ");
+                       AssertEquals (String.Empty, whitespace.InnerXml);
+                       AssertEquals ("\r\n\t ", whitespace.OuterXml);
+               }
+                       
                internal void TestXmlNodeBaseProperties (XmlNode original, XmlNode cloned)
                {
 //                     assertequals (original.nodetype + " was incorrectly cloned.",