public void writeNode_XmlReader16(XmlWriterUtils utils)
        {
            XmlReader xr = CreateReaderIgnoreWS("XmlReader.xml");

            while (xr.Read())
            {
                if (xr.LocalName == "DefaultAttributesTrue")
                {
                    xr.Read();
                    break;
                }
            }
            using (XmlWriter w = utils.CreateWriter())
            {
                w.WriteStartElement("Root");
                w.WriteNode(xr, false);
                w.WriteEndElement();
            }
            xr.Dispose();
            if (ReaderLoosesDefaultAttrInfo())
            {
                Assert.True(utils.CompareReader("<Root><name a='b' FIRST='KEVIN' LAST='WHITE'/></Root>"));
            }
            else
            {
                Assert.True(utils.CompareReader("<Root><name a='b' /></Root>"));
            }
        }
        public void writeNode_XmlReader10(XmlWriterUtils utils)
        {
            XmlReader xr = CreateReaderIgnoreWS("XmlReader.xml");

            while (xr.Read())
            {
                if (xr.LocalName == "MixedContent")
                {
                    xr.Read();
                    break;
                }
            }
            using (XmlWriter w = utils.CreateWriter())
            {
                w.WriteNode(xr, false);
            }

            // check reader position
            CError.Compare(xr.NodeType, XmlNodeType.EndElement, "Error");
            CError.Compare(xr.Name, "MixedContent", "Error");
            xr.Dispose();

            if (IsXPathDataModelReader())
            {
                Assert.True(utils.CompareReader("<node1><?PI Instruction?><!--Comment-->Textcdata</node1>"));
            }

            Assert.True(utils.CompareReader("<node1><?PI Instruction?><!--Comment-->Text<![CDATA[cdata]]></node1>"));
        }
Exemple #3
0
        public void writeAttributes_2(XmlWriterUtils utils)
        {
            using (XmlWriter w = utils.CreateWriter())
            {
                using (XmlReader xr = CreateReader("XmlReader.xml"))
                {
                    while (xr.Read())
                    {
                        if (xr.LocalName == "name")
                        {
                            xr.MoveToFirstAttribute();
                            break;
                        }
                    }
                    w.WriteStartElement("Root");
                    w.WriteAttributes(xr, false);
                    w.WriteEndElement();
                }
            }

            if (IsXPathDataModelReader())
            {
                // always sees default attributes
                Assert.True(utils.CompareReader("<Root a=\"b\" FIRST=\"KEVIN\" LAST=\"WHITE\" />"));
            }
            else
            {
                Assert.True(utils.CompareReader("<Root a=\"b\" />"));
            }
        }
Exemple #4
0
        public void standalone_2(XmlWriterUtils utils)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();

            wSettings.ConformanceLevel = ConformanceLevel.Document;
            wSettings.CloseOutput      = false;

            XmlWriter w = utils.CreateWriter(wSettings);

            w.WriteStartDocument(false);
            w.WriteStartElement("Root");
            w.WriteEndElement();
            w.WriteEndDocument();
            w.Dispose();

            bool ret = false;

            if (utils.WriterType == WriterType.UnicodeWriter)
            {
                ret = utils.CompareReader("<?xml version=\"1.0\" encoding=\"unicode\" standalone=\"no\"?><Root />");
            }
            else
            {
                ret = utils.CompareReader("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?><Root />");
            }

            Assert.True(ret);
        }
        public void writeNode_XmlReader2(XmlWriterUtils utils)
        {
            using (XmlWriter w = utils.CreateWriter())
            {
                using (XmlReader xr = CreateReaderIgnoreWS("XmlReader.xml"))
                {
                    while (xr.Read())
                    {
                        if (xr.LocalName == "defattr")
                        {
                            xr.Read();
                            xr.MoveToFirstAttribute();
                            break;
                        }
                    }

                    if (xr.NodeType != XmlNodeType.Attribute)
                    {
                        CError.WriteLine("Reader positioned on {0}", xr.NodeType.ToString());
                        xr.Dispose();
                        w.Dispose();
                        Assert.True(false);
                    }
                    w.WriteStartElement("Root");
                    w.WriteNode(xr, false);
                    w.WriteEndElement();
                }
            }
            Assert.True(utils.CompareReader("<Root />"));
        }
Exemple #6
0
 public void writeAttributes_4(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         using (XmlReader xr = CreateReader("XmlReader.xml"))
         {
             while (xr.Read())
             {
                 if (xr.LocalName == "AttributesGeneric")
                 {
                     do
                     {
                         xr.Read();
                     } while (xr.LocalName != "node");
                     break;
                 }
             }
             if (xr.NodeType != XmlNodeType.Element)
             {
                 CError.WriteLine("Reader not positioned element");
                 CError.WriteLine(xr.LocalName);
                 xr.Dispose();
                 w.Dispose();
                 Assert.True(false);
             }
             w.WriteStartElement("Root");
             w.WriteAttributes(xr, false);
             w.WriteEndElement();
         }
     }
     Assert.True(utils.CompareReader("<Root a=\"b\" c=\"d\" e=\"f\" />"));
 }
Exemple #7
0
 public void writeAttributes_11(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         using (XmlReader xr = CreateReader("XmlReader.xml"))
         {
             while (xr.Read())
             {
                 if (xr.LocalName == "QuoteChar")
                 {
                     do
                     {
                         xr.Read();
                     } while (xr.LocalName != "node");
                     do
                     {
                         xr.Read();
                     } while (xr.LocalName != "node");
                     xr.MoveToFirstAttribute();
                     break;
                 }
             }
             w.WriteStartElement("Root");
             w.WriteAttributes(xr, false);
             w.WriteEndElement();
         }
     }
     Assert.True(utils.CompareReader("<Root a=\"b'c\" />"));
 }
        public void writeNode_XmlReader24(XmlWriterUtils utils)
        {
            if (IsXPathDataModelReader())
            {
                CError.WriteLine("XPath data model does not have CDATA node type, so {0} can not be positioned on CDATA", readerType);
                return;
            }

            XmlReader xr = CreateReaderIgnoreWS("XmlReader.xml");

            while (xr.Read())
            {
                if (xr.LocalName == "CDataNode")
                {
                    xr.Read();
                    break;
                }
            }
            if (xr.NodeType != XmlNodeType.CDATA)
            {
                CError.WriteLine("Reader positioned on {0}", xr.NodeType);
                xr.Dispose();
                Assert.True(false);
            }
            using (XmlWriter w = utils.CreateWriter())
            {
                w.WriteStartElement("root");
                w.WriteNode(xr, false);
                w.WriteEndElement();
            }
            xr.Dispose();

            Assert.True(utils.CompareReader("<root><![CDATA[cdata content]]></root>"));
        }
Exemple #9
0
 public void writeAttributes_8(XmlWriterUtils utils)
 {
     if (IsXPathDataModelReader())
     {
         CError.WriteLine("{0} does not support XmlDecl node", readerType);
         return;
     }
     using (XmlWriter w = utils.CreateWriter())
     {
         using (XmlReader xr = CreateReader("Simple.xml"))
         {
             xr.Read();
             if (xr.NodeType != XmlNodeType.XmlDeclaration)
             {
                 CError.WriteLine("Reader not positioned on XmlDeclaration");
                 CError.WriteLine(xr.LocalName);
                 xr.Dispose();
                 w.Dispose();
                 Assert.True(false);
             }
             w.WriteStartElement("Root");
             w.WriteAttributes(xr, false);
             w.WriteEndElement();
         }
     }
     Assert.True(utils.CompareReader("<Root version=\"1.0\" standalone=\"yes\" />"));
 }
Exemple #10
0
        public void writeAttributes_13(XmlWriterUtils utils)
        {
            string strxml = "<E a=\"&gt;&lt;&quot;&apos;&amp;\" />";

            using (XmlReader xr = CreateReader(new StringReader(strxml)))
            {
                xr.Read();
                xr.MoveToFirstAttribute();

                if (xr.NodeType != XmlNodeType.Attribute)
                {
                    CError.WriteLine("Reader positioned on {0}", xr.NodeType.ToString());
                    xr.Dispose();
                    Assert.True(false);
                }

                using (XmlWriter w = utils.CreateWriter())
                {
                    w.WriteStartElement("Root");
                    w.WriteAttributes(xr, false);
                    w.WriteEndElement();
                }
            }
            Assert.True(utils.CompareReader("<Root a=\"&gt;&lt;&quot;&apos;&amp;\" />"));
        }
        public void writeNode_XmlReader26(XmlWriterUtils utils)
        {
            XmlReader xr = CreateReaderIgnoreWS("XmlReader.xml");

            while (xr.Read())
            {
                if (xr.LocalName == "CommentNode")
                {
                    xr.Read();
                    break;
                }
            }
            if (xr.NodeType != XmlNodeType.Comment)
            {
                CError.WriteLine("Reader positioned on {0}", xr.NodeType);
                xr.Dispose();
                Assert.True(false);
            }
            using (XmlWriter w = utils.CreateWriter())
            {
                w.WriteStartElement("root");
                w.WriteNode(xr, false);
                w.WriteEndElement();
            }
            xr.Dispose();
            Assert.True(utils.CompareReader("<root><!--Comment--></root>"));
        }
Exemple #12
0
 public void element_3(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         w.WriteStartElement("Root", "http://my.com");
         w.WriteEndElement();
     }
     Assert.True(utils.CompareReader("<Root xmlns=\"http://my.com\" />"));
 }
Exemple #13
0
 public void element_1(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         w.WriteStartElement("Root");
         w.WriteEndElement();
     }
     Assert.True(utils.CompareReader("<Root />"));
 }
Exemple #14
0
 public void attribute_20(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         w.WriteStartElement("Root");
         w.WriteAttributeString("a", null, "< > &");
         w.WriteEndElement();
     }
     Assert.True(utils.CompareReader("<Root a=\"&lt; &gt; &amp;\" />"));
 }
Exemple #15
0
 public void attribute_15(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         w.WriteStartElement("Root");
         w.WriteAttributeString("a", null, "b\"c");
         w.WriteEndElement();
     }
     Assert.True(utils.CompareReader("<Root a=\"b&quot;c\" />"));
 }
Exemple #16
0
        public void frag_4(XmlWriterUtils utils)
        {
            XmlWriter w = utils.CreateWriter(ConformanceLevel.Fragment);
            int       i = 1;

            w.WriteValue(i);
            w.WriteElementString("Root", "test");
            w.Dispose();
            Assert.True(utils.CompareReader("1<Root>test</Root>"));
        }
Exemple #17
0
        public void frag_3(XmlWriterUtils utils)
        {
            XmlWriter w = utils.CreateWriter(ConformanceLevel.Fragment);

            w.WriteStartElement("Root");
            w.WriteEndElement();
            w.WriteString("Top level text");
            w.Dispose();
            Assert.True(utils.CompareReader("<Root />Top level text"));
        }
Exemple #18
0
 public void attribute_2(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         w.WriteStartElement("Root");
         w.WriteStartAttribute("attr1");
         w.WriteEndElement();
     }
     Assert.True(utils.CompareReader("<Root attr1=\"\" />"));
 }
Exemple #19
0
 public void attribute_24(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         w.WriteStartElement(string.Empty, "test", "ns");
         w.WriteStartAttribute("attr");
         w.WriteEndAttribute();
         w.WriteEndElement();
     }
     Assert.True(utils.CompareReader("<test attr=\"\" xmlns=\"ns\" />"));
 }
Exemple #20
0
        public void attribute_19(XmlWriterUtils utils)
        {
            using (XmlWriter w = utils.CreateWriter())
            {
                w.WriteStartElement("Root");
                w.WriteAttributeString("a", null, "\x20\x9\xD\xA");
                w.WriteEndElement();
            }

            Assert.True(utils.CompareReader("<Root a=\" &#x9;&#xD;&#xA;\" />"));
        }
Exemple #21
0
 public void var_2(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         w.WriteStartElement("Root");
         w.WriteStartAttribute("attr");
         w.WriteComment("This text is a comment");
         w.WriteEndElement();
     }
     Assert.True(utils.CompareReader("<Root attr=''><!--This text is a comment--></Root>"));
 }
Exemple #22
0
 public void attribute_26(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         w.WriteStartElement("pre", "test", "ns");
         w.WriteStartAttribute(null, "attr", "ns");
         w.WriteStartAttribute("attr");
         w.WriteEndElement();
     }
     Assert.True(utils.CompareReader("<pre:test pre:attr=\"\" attr=\"\" xmlns:pre=\"ns\" />"));
 }
Exemple #23
0
 public void attribute_7(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         w.WriteStartElement("Root");
         w.WriteStartAttribute("pre1", "attr1", "http://my.com");
         w.WriteEndAttribute();
         w.WriteEndElement();
     }
     Assert.True(utils.CompareReader("<Root pre1:attr1=\"\" xmlns:pre1=\"http://my.com\" />"));
 }
Exemple #24
0
 public void attribute_4(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         w.WriteStartElement("Root");
         w.WriteAttributeString("attr1", "val1");
         w.WriteAttributeString("attr2", "val2");
         w.WriteEndElement();
     }
     Assert.True(utils.CompareReader("<Root attr1=\"val1\" attr2=\"val2\" />"));
 }
        public void writeNode_XmlReader3(XmlWriterUtils utils)
        {
            using (XmlReader xr = CreateReader(new StringReader("<root />")))
            {
                using (XmlWriter w = utils.CreateWriter())
                {
                    w.WriteNode(xr, false);
                }
            }

            Assert.True(utils.CompareReader("<root />"));
        }
Exemple #26
0
 public void var_1(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         w.WriteStartElement("Root");
         w.WriteStartAttribute("attr");
         w.WriteStartElement("child");
         w.WriteEndElement();
         w.WriteEndElement();
     }
     Assert.True(utils.CompareReader("<Root attr=''><child /></Root>"));
 }
Exemple #27
0
        public void frag_6(XmlWriterUtils utils)
        {
            XmlWriter w = utils.CreateWriter(ConformanceLevel.Fragment);
            int       i = 1;

            w.WriteValue(i); w.WriteValue(i); w.WriteValue(i); w.WriteValue(i);
            w.WriteStartElement("Root");
            w.WriteEndElement();
            w.WriteValue(i); w.WriteValue(i); w.WriteValue(i); w.WriteValue(i);
            w.Dispose();
            Assert.True(utils.CompareReader("1111<Root />1111"));
        }
Exemple #28
0
 public void attribute_16(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         w.WriteStartElement("Root");
         w.WriteAttributeString("a", "&");
         w.WriteAttributeString("b", "&#65;");
         w.WriteAttributeString("c", "&#x43;");
         w.WriteEndElement();
     }
     Assert.True(utils.CompareReader("<Root a=\"&amp;\" b=\"&amp;#65;\" c=\"&amp;#x43;\" />"));
 }
        public void writeNode_XmlReader21(XmlWriterUtils utils)
        {
            string    strxml = "<root></root>";
            XmlReader xr     = CreateReader(new StringReader(strxml));

            using (XmlWriter w = utils.CreateWriter())
            {
                w.WriteNode(xr, false);
            }

            xr.Dispose();
            Assert.True(utils.CompareReader("<root></root>"));
        }
Exemple #30
0
        public void attribute_27(XmlWriterUtils utils)
        {
            XmlWriterSettings s = new XmlWriterSettings();

            s.NewLineHandling = NewLineHandling.Replace;

            using (XmlWriter w = utils.CreateWriter())
            {
                w.WriteStartElement("root");
                w.WriteAttributeString("a", "|\x0D|\x0A|\x0D\x0A|");
                w.WriteEndElement();
            }
            Assert.True(utils.CompareReader("<root a=\"|&#xD;|&#xA;|&#xD;&#xA;|\" />"));
        }