示例#1
0
        void ReadSubtree2(XPathNavigator nav, string label)
        {
            XmlReader r = nav.ReadSubtree();

            XmlAssert.AssertNode(label + "#1", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.None, 0, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 String.Empty, String.Empty, String.Empty, String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 0, false);

            Assert.IsTrue(r.Read(), label + "#2");
            XmlAssert.AssertNode(label + "#3", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Element, 0, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "root", String.Empty, "root", String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 0, false);

            Assert.IsTrue(r.Read(), label + "#4");
            XmlAssert.AssertNode(label + "#5", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.EndElement, 0, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "root", String.Empty, "root", String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 0, false);

            Assert.IsFalse(r.Read(), label + "#6");
        }
示例#2
0
        void DocElem_OpenClose_Attribute(XPathNavigator nav, string label)
        {
            XmlReader r = nav.ReadSubtree();

            XmlAssert.AssertNode(label + "#1", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.None, 0, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 String.Empty, String.Empty, String.Empty, String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 0, false);

            Assert.IsTrue(r.Read(), label + "#2");
            XmlAssert.AssertNode(label + "#3", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Element, 0, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "root", String.Empty, "root", String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 1, true);

            Assert.IsTrue(r.MoveToFirstAttribute(), label + "#4");
            XmlAssert.AssertNode(label + "#5", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Attribute, 1, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "attr", String.Empty, "attr", String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 "value", true, 1, true);

            Assert.IsTrue(r.ReadAttributeValue(), label + "#6");
            XmlAssert.AssertNode(label + "#7", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Text, 2, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 String.Empty, String.Empty, String.Empty, String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 "value", true, 1, true);

            Assert.IsFalse(r.ReadAttributeValue(), label + "#8");
            Assert.IsFalse(r.MoveToNextAttribute(), label + "#9");
            Assert.IsTrue(r.MoveToElement(), label + "#10");

            Assert.IsTrue(r.Read(), label + "#11");
            XmlAssert.AssertNode(label + "#12", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.EndElement, 0, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "root", String.Empty, "root", String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 0, false);

            Assert.IsFalse(r.Read(), label + "#13");
        }
示例#3
0
        void FromChildElement(XPathNavigator nav, string label)
        {
            XmlReader r = nav.ReadSubtree();

            XmlAssert.AssertNode(label + "#1", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.None, 0, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 String.Empty, String.Empty, String.Empty, String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 0, false);

            Assert.IsTrue(r.Read(), label + "#2");
            XmlAssert.AssertNode(label + "#3", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Element, 0, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "foo", String.Empty, "foo", String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 1, true);

            Assert.IsTrue(r.Read(), label + "#4");
            XmlAssert.AssertNode(label + "#5", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Text, 1, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 String.Empty, String.Empty, String.Empty, String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 "test", true, 0, false);

            Assert.IsTrue(r.Read(), label + "#6");
            XmlAssert.AssertNode(label + "#7", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.EndElement, 0, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "foo", String.Empty, "foo", String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 0, false);

            // end at </foo>, without moving toward <bar>.
            Assert.IsFalse(r.Read(), label + "#8");
        }
示例#4
0
        void MixedContentAndDepth(XPathNavigator nav, string label)
        {
            XmlReader r = nav.ReadSubtree();

            r.Read();
            XmlAssert.AssertNode(label + "#1", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Element, 0, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "one", String.Empty, "one", String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 0, false);

            r.Read();
            XmlAssert.AssertNode(label + "#2", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Element, 1, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "two", String.Empty, "two", String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 0, false);

            r.Read();
            XmlAssert.AssertNode(label + "#3", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Text, 2, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 String.Empty, String.Empty, String.Empty, String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 "Some data.", true, 0, false);

            r.Read();
            XmlAssert.AssertNode(label + "#4", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Element, 2, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "three", String.Empty, "three", String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 0, false);

            r.Read();
            XmlAssert.AssertNode(label + "#5", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Text, 3, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 String.Empty, String.Empty, String.Empty, String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 "more", true, 0, false);

            r.Read();
            XmlAssert.AssertNode(label + "#6", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.EndElement, 2, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "three", String.Empty, "three", String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 0, false);

            r.Read();
            XmlAssert.AssertNode(label + "#7", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Text, 2, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 String.Empty, String.Empty, String.Empty, String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 " done.", true, 0, false);

            r.Read();
            XmlAssert.AssertNode(label + "#8", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.EndElement, 1, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "two", String.Empty, "two", String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 0, false);

            r.Read();
            XmlAssert.AssertNode(label + "#9", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.EndElement, 0, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "one", String.Empty, "one", String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 0, false);

            Assert.IsFalse(r.Read(), label + "#10");
        }
示例#5
0
        void AttributesAndNamespaces(XPathNavigator nav, string label)
        {
            XmlReader r = nav.ReadSubtree();

            XmlAssert.AssertNode(label + "#1", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.None, 0, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 String.Empty, String.Empty, String.Empty, String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 0, false);

            Assert.IsTrue(r.Read(), label + "#2");
            XmlAssert.AssertNode(label + "#3", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Element, 0, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "root", String.Empty, "root", "urn:default",
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 4, true);

            // Namespaces

            Assert.IsTrue(r.MoveToAttribute("xmlns:x"), label + "#4");
            XmlAssert.AssertNode(label + "#5", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Attribute, 1, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "xmlns:x", "xmlns", "x",
                                 "http://www.w3.org/2000/xmlns/",
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 "urn:foo", true, 4, true);

            Assert.IsTrue(r.ReadAttributeValue(), label + "#6");
///* MS.NET has a bug here
            XmlAssert.AssertNode(label + "#7", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Text, 2, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 String.Empty, String.Empty, String.Empty, String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 "urn:foo", true, 4, true);
//*/

            Assert.IsFalse(r.ReadAttributeValue(), label + "#8");

            Assert.IsTrue(r.MoveToAttribute("xmlns"), label + "#9");
            XmlAssert.AssertNode(label + "#10", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Attribute, 1, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "xmlns", String.Empty, "xmlns",
                                 "http://www.w3.org/2000/xmlns/",
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 "urn:default", true, 4, true);

            Assert.IsTrue(r.ReadAttributeValue(), label + "#11");
///* MS.NET has a bug here
            XmlAssert.AssertNode(label + "#12", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Text, 2, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 String.Empty, String.Empty, String.Empty, String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 "urn:default", true, 4, true);
//*/

            Assert.IsFalse(r.ReadAttributeValue(), label + "#13");

            // Attributes

            Assert.IsTrue(r.MoveToAttribute("attr"), label + "#14");
            XmlAssert.AssertNode(label + "#15", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Attribute, 1, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "attr", String.Empty, "attr", String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 "value", true, 4, true);

            Assert.IsTrue(r.ReadAttributeValue(), label + "#16");
            XmlAssert.AssertNode(label + "#17", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Text, 2, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 String.Empty, String.Empty, String.Empty, String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 "value", true, 4, true);

            Assert.IsFalse(r.ReadAttributeValue(), label + "#18");

            Assert.IsTrue(r.MoveToAttribute("x:a2"), label + "#19");
            XmlAssert.AssertNode(label + "#20", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Attribute, 1, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "x:a2", "x", "a2", "urn:foo",
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 "v2", true, 4, true);

            Assert.IsTrue(r.ReadAttributeValue(), label + "#21");
            XmlAssert.AssertNode(label + "#22", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.Text, 2, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 String.Empty, String.Empty, String.Empty, String.Empty,
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 "v2", true, 4, true);

            Assert.IsTrue(r.MoveToElement(), label + "#24");

            Assert.IsTrue(r.Read(), label + "#25");
            XmlAssert.AssertNode(label + "#26", r,
                                 // NodeType, Depth, IsEmptyElement
                                 XmlNodeType.EndElement, 0, false,
                                 // Name, Prefix, LocalName, NamespaceURI
                                 "root", String.Empty, "root", "urn:default",
                                 // Value, HasValue, AttributeCount, HasAttributes
                                 String.Empty, false, 0, false);

            Assert.IsFalse(r.Read(), label + "#27");
        }
示例#6
0
        public void PrependChildXmlReader()
        {
            XPathNavigator nav = GetInstance("<root><foo>existing_child</foo></root>");

            nav.MoveToFirstChild();
            nav.MoveToFirstChild(); // foo

            XmlReader reader = new XmlTextReader(
                "<child>text</child><next_sibling/>",
                XmlNodeType.Element,
                null);

            nav.PrependChild(reader);

            XmlAssert.AssertNode("#0",
                                 reader,
                                 XmlNodeType.None,
                                 0,             // Depth
                                 false,         // IsEmptyElement
                                 String.Empty,  // Name
                                 String.Empty,  // Prefix
                                 String.Empty,  // LocalName
                                 String.Empty,  // NamespaceURI
                                 String.Empty,  // Value
                                 false,         // HasValue
                                 0,             // AttributeCount
                                 false);        // HasAttributes

            AssertNavigator("#1", nav,
                            XPathNodeType.Element,
                            String.Empty,         // Prefix
                            "foo",                // LocalName
                            String.Empty,         // NamespaceURI
                            "foo",                // Name
                            "textexisting_child", // Value
                            false,                // HasAttributes
                            true,                 // HasChildren
                            false);               // IsEmptyElement

            Assert.IsTrue(nav.MoveToFirstChild(), "#1-2");

            AssertNavigator("#2", nav,
                            XPathNodeType.Element,
                            String.Empty, // Prefix
                            "child",      // LocalName
                            String.Empty, // NamespaceURI
                            "child",      // Name
                            "text",       // Value
                            false,        // HasAttributes
                            true,         // HasChildren
                            false);       // IsEmptyElement

            Assert.IsTrue(nav.MoveToNext(), "#2-2");

            AssertNavigator("#3", nav,
                            XPathNodeType.Element,
                            String.Empty,   // Prefix
                            "next_sibling", // LocalName
                            String.Empty,   // NamespaceURI
                            "next_sibling", // Name
                            String.Empty,   // Value
                            false,          // HasAttributes
                            false,          // HasChildren
                            true);          // IsEmptyElement

            Assert.IsTrue(nav.MoveToNext(), "#3-2");

            AssertNavigator("#4", nav,
                            XPathNodeType.Text,
                            String.Empty,     // Prefix
                            String.Empty,     // LocalName
                            String.Empty,     // NamespaceURI
                            String.Empty,     // Name
                            "existing_child", // Value
                            false,            // HasAttributes
                            false,            // HasChildren
                            false);           // IsEmptyElement
        }