Example #1
0
        public void SimpleReading()
        {
            XPathDocument doc = new XPathDocument(new StringReader(
                                                      "<customer id='1' pp:id='aba' xmlns='urn-kzu' xmlns:pp='urn-pepenamespace'><order id='1'>Chocolates</order></customer>"));
            XPathNavigator nav = doc.CreateNavigator();

            XmlReader reader = new XPathNavigatorReader(nav);

            reader.Read();
            Assert.AreEqual("customer", reader.LocalName);
            Assert.AreEqual("urn-kzu", reader.NamespaceURI);
            Assert.AreEqual(4, reader.AttributeCount);
            // @id
            reader.MoveToFirstAttribute();
            Assert.AreEqual("id", reader.LocalName);
            // @pp:id
            reader.MoveToNextAttribute();
            Assert.AreEqual("id", reader.LocalName);
            Assert.AreEqual("urn-pepenamespace", reader.NamespaceURI);
            // xmlns="urn-kzu" and xmlns:pp="urn-pepenamespace". Order is not guaranteed.
            reader.MoveToNextAttribute();
            Assert.AreEqual(XmlNamespaces.XmlNs, reader.NamespaceURI);
            reader.MoveToNextAttribute();
            Assert.AreEqual(XmlNamespaces.XmlNs, reader.NamespaceURI);

            reader.Read();
            Assert.AreEqual("order", reader.LocalName);
            Assert.AreEqual("urn-kzu", reader.NamespaceURI);
            Assert.AreEqual(1, reader.AttributeCount);
            reader.MoveToFirstAttribute();
            Assert.AreEqual("id", reader.LocalName);
            Assert.IsTrue(reader.ReadAttributeValue());
            Assert.AreEqual("1", reader.Value);
            Assert.IsFalse(reader.MoveToNextAttribute());

            reader.Read();
            Assert.AreEqual(XmlNodeType.Text, reader.NodeType);
            Assert.AreEqual("Chocolates", reader.Value);

            reader.Read();
            Assert.AreEqual("order", reader.LocalName);
            Assert.AreEqual(XmlNodeType.EndElement, reader.NodeType);

            reader.Read();
            Assert.AreEqual("customer", reader.LocalName);
            Assert.AreEqual(XmlNodeType.EndElement, reader.NodeType);

            reader.Read();
            Assert.AreEqual(ReadState.EndOfFile, reader.ReadState);
        }
Example #2
0
        public void XmlReaderNames()
        {
            string xml = "<customer id='1' pp:id='aba' xmlns='urn-kzu' xmlns:pp='urn-pepenamespace'><pp:order /><order id='1'>Chocolates</order></customer>";

            XPathNavigator nav    = new XPathDocument(new StringReader(xml)).CreateNavigator();
            XmlReader      reader = new XPathNavigatorReader(nav);

            reader.MoveToContent();
            Assert.AreEqual("customer", reader.Name);

            reader.MoveToFirstAttribute();
            Assert.AreEqual("id", reader.Name);

            reader.MoveToNextAttribute();
            Assert.AreEqual("pp:id", reader.Name);

            // Namespace order is not guaranteed.
            reader.MoveToNextAttribute();
            Assert.IsTrue(reader.Name == "xmlns:pp" || reader.Name == "xmlns");
            reader.MoveToNextAttribute();
            Assert.IsTrue(reader.Name == "xmlns:pp" || reader.Name == "xmlns");

            reader.MoveToElement();
            reader.Read();

            Assert.AreEqual("pp:order", reader.Name);
        }
Example #3
0
		public void SimpleReading()
		{
			XPathDocument doc = new XPathDocument(new StringReader(
				"<customer id='1' pp:id='aba' xmlns='urn-kzu' xmlns:pp='urn-pepenamespace'><order id='1'>Chocolates</order></customer>"));
			XPathNavigator nav = doc.CreateNavigator();

			XmlReader reader = new XPathNavigatorReader(nav);

			reader.Read();
			Assert.AreEqual("customer", reader.LocalName);
			Assert.AreEqual("urn-kzu", reader.NamespaceURI);
			Assert.AreEqual(4, reader.AttributeCount);
			// @id
			reader.MoveToFirstAttribute();
			Assert.AreEqual("id", reader.LocalName);
			// @pp:id
			reader.MoveToNextAttribute();
			Assert.AreEqual("id", reader.LocalName);
			Assert.AreEqual("urn-pepenamespace", reader.NamespaceURI);
			// xmlns="urn-kzu" and xmlns:pp="urn-pepenamespace". Order is not guaranteed.
			reader.MoveToNextAttribute();
			Assert.AreEqual(XmlNamespaces.XmlNs, reader.NamespaceURI);
			reader.MoveToNextAttribute();
			Assert.AreEqual(XmlNamespaces.XmlNs, reader.NamespaceURI);
            
			reader.Read();
			Assert.AreEqual("order", reader.LocalName);
			Assert.AreEqual("urn-kzu", reader.NamespaceURI);
			Assert.AreEqual(1, reader.AttributeCount);
			reader.MoveToFirstAttribute();
			Assert.AreEqual("id", reader.LocalName);
			Assert.IsTrue(reader.ReadAttributeValue());
            Assert.AreEqual("1", reader.Value);
			Assert.IsFalse(reader.MoveToNextAttribute());

			reader.Read();
			Assert.AreEqual(XmlNodeType.Text, reader.NodeType);
			Assert.AreEqual("Chocolates", reader.Value);

			reader.Read();
			Assert.AreEqual("order", reader.LocalName);
			Assert.AreEqual(XmlNodeType.EndElement, reader.NodeType);

			reader.Read();
			Assert.AreEqual("customer", reader.LocalName);
			Assert.AreEqual(XmlNodeType.EndElement, reader.NodeType);

			reader.Read();
			Assert.AreEqual(ReadState.EndOfFile, reader.ReadState);
		}
Example #4
0
		public void XmlReaderNames()
		{
			string xml = "<customer id='1' pp:id='aba' xmlns='urn-kzu' xmlns:pp='urn-pepenamespace'><pp:order /><order id='1'>Chocolates</order></customer>";

			XPathNavigator nav = new XPathDocument(new StringReader(xml)).CreateNavigator();
			XmlReader reader = new XPathNavigatorReader(nav);

			reader.MoveToContent();
			Assert.AreEqual("customer", reader.Name);
			
			reader.MoveToFirstAttribute();
			Assert.AreEqual("id", reader.Name);

			reader.MoveToNextAttribute();
			Assert.AreEqual("pp:id", reader.Name);
		
			// Namespace order is not guaranteed.
            reader.MoveToNextAttribute();
			Assert.IsTrue( reader.Name == "xmlns:pp" || reader.Name == "xmlns" );
			reader.MoveToNextAttribute();
			Assert.IsTrue( reader.Name == "xmlns:pp" || reader.Name == "xmlns" );

			reader.MoveToElement();
			reader.Read();

			Assert.AreEqual("pp:order", reader.Name);
		}