Ejemplo n.º 1
0
        public void TextReader()
        {
            string input =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<rootsym>
	<!-- This is a comment -->
	<fiddle x=""foo"" y=""1"" z=""false""></fiddle>
</rootsym>";

            XmlInput xmlinput = new XmlInput(new StringReader(input), "teststring");

            xmlinput.CheckElement("rootsym");
            xmlinput.Read();
            xmlinput.CheckElement("fiddle");
            Assert.AreEqual(1, xmlinput.GetAttributeInt("y"));
            Assert.AreEqual(false, xmlinput.GetAttributeBool("z"));
            Assert.AreEqual("foo", xmlinput.GetAttributeString("x"));
            xmlinput.Skip();
        }
Ejemplo n.º 2
0
        public void Read1()
        {
            XmlInput xmlinput = new XmlInput(TestUtil.GetTestFile("xmlinput.xml"));
            xmlinput.CheckElement("rootsym");

            try {
                xmlinput.CheckElement("fiddle");
                Assert.Fail("expect exception");
            }
            catch (Exception e) {
                Assert.IsTrue(e is XmlFileFormatException);
            }

            xmlinput.Read();
            xmlinput.CheckElement("fiddle");
            Assert.AreEqual(1, xmlinput.GetAttributeInt("y"));
            Assert.AreEqual(false, xmlinput.GetAttributeBool("z"));
            Assert.AreEqual("foo", xmlinput.GetAttributeString("x"));

            xmlinput.Skip();

            xmlinput.CheckElement("faddle");
            Assert.AreEqual(3.4F, xmlinput.GetAttributeFloat("x"));
            try {
                Assert.AreEqual("", xmlinput.GetAttributeString("q"));
                Assert.Fail("should throw");
            }
            catch (Exception e) {
                Assert.IsTrue(e is XmlFileFormatException);
            }

            int i = 0;
            bool first = true;
            while (xmlinput.FindSubElement(first, "hello", "zung", "zang", "zing")) {
                ++i;
                first = false;

                switch (xmlinput.Name) {
                    case "zing":
                        Assert.AreEqual(5, xmlinput.GetAttributeInt("why", 5));
                        Assert.AreEqual(true, xmlinput.GetAttributeBool("why", true));
                        Assert.AreEqual(5.7F, xmlinput.GetAttributeFloat("why", 5.7F));
                        Assert.AreEqual("Whazzzle", xmlinput.GetAttributeString("why", "Whazzzle"));
                        Assert.AreEqual("This is the zing", xmlinput.GetContentString());
                        break;

                    case "zang":
                        Assert.AreEqual(true, xmlinput.GetAttributeBool("r"));
                        try {
                            Assert.AreEqual(true, xmlinput.GetAttributeBool("z"));
                            Assert.Fail("should throw");
                        }
                        catch (Exception) {
                        }

                        xmlinput.Skip();
                        break;

                    case "zung":
                        xmlinput.Read();
                        xmlinput.CheckElement("diddle");
                        xmlinput.Skip();
                        xmlinput.Skip();
                        break;
                    default:
                        Assert.Fail("shouldn't get here");
                        break;
                }
            }

            Assert.AreEqual(4, i);
        }
Ejemplo n.º 3
0
        public void TextReader()
        {
            string input =
            @"<?xml version=""1.0"" encoding=""utf-8""?>
            <rootsym>
            <!-- This is a comment -->
            <fiddle x=""foo"" y=""1"" z=""false""></fiddle>
            </rootsym>";

            XmlInput xmlinput = new XmlInput(new StringReader(input), "teststring");

            xmlinput.CheckElement("rootsym");
            xmlinput.Read();
            xmlinput.CheckElement("fiddle");
            Assert.AreEqual(1, xmlinput.GetAttributeInt("y"));
            Assert.AreEqual(false, xmlinput.GetAttributeBool("z"));
            Assert.AreEqual("foo", xmlinput.GetAttributeString("x"));
            xmlinput.Skip();
        }
Ejemplo n.º 4
0
        public void Read1()
        {
            XmlInput xmlinput = new XmlInput(TestUtil.GetTestFile("xmlinput.xml"));

            xmlinput.CheckElement("rootsym");

            try {
                xmlinput.CheckElement("fiddle");
                Assert.Fail("expect exception");
            }
            catch (Exception e) {
                Assert.IsTrue(e is XmlFileFormatException);
            }

            xmlinput.Read();
            xmlinput.CheckElement("fiddle");
            Assert.AreEqual(1, xmlinput.GetAttributeInt("y"));
            Assert.AreEqual(false, xmlinput.GetAttributeBool("z"));
            Assert.AreEqual("foo", xmlinput.GetAttributeString("x"));

            xmlinput.Skip();

            xmlinput.CheckElement("faddle");
            Assert.AreEqual(3.4F, xmlinput.GetAttributeFloat("x"));
            try {
                Assert.AreEqual("", xmlinput.GetAttributeString("q"));
                Assert.Fail("should throw");
            }
            catch (Exception e) {
                Assert.IsTrue(e is XmlFileFormatException);
            }

            int  i     = 0;
            bool first = true;

            while (xmlinput.FindSubElement(first, "hello", "zung", "zang", "zing"))
            {
                ++i;
                first = false;

                switch (xmlinput.Name)
                {
                case "zing":
                    Assert.AreEqual(5, xmlinput.GetAttributeInt("why", 5));
                    Assert.AreEqual(true, xmlinput.GetAttributeBool("why", true));
                    Assert.AreEqual(5.7F, xmlinput.GetAttributeFloat("why", 5.7F));
                    Assert.AreEqual("Whazzzle", xmlinput.GetAttributeString("why", "Whazzzle"));
                    Assert.AreEqual("This is the zing", xmlinput.GetContentString());
                    break;

                case "zang":
                    Assert.AreEqual(true, xmlinput.GetAttributeBool("r"));
                    try {
                        Assert.AreEqual(true, xmlinput.GetAttributeBool("z"));
                        Assert.Fail("should throw");
                    }
                    catch (Exception) {
                    }

                    xmlinput.Skip();
                    break;

                case "zung":
                    xmlinput.Read();
                    xmlinput.CheckElement("diddle");
                    xmlinput.Skip();
                    xmlinput.Skip();
                    break;

                default:
                    Assert.Fail("shouldn't get here");
                    break;
                }
            }

            Assert.AreEqual(4, i);
        }