Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public void XmlDocumentLoading()
        {
            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);

            //XmlReader reader = new XmlTextReader(new StringReader(xml));

            //reader.MoveToContent();
            //Console.WriteLine(reader.ReadOuterXml());

            System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(Console.Out);

            while (reader.Read())
            {
                tw.Indent = reader.Depth;
                tw.WriteLine("Name={0}, Type={1}", reader.Name, reader.NodeType);
                int count = reader.AttributeCount;
                //reader.MoveToFirstAttribute();
                //for (int i = 0; i < count; i++)
                while (reader.MoveToNextAttribute())
                {
                    tw.Indent = reader.Depth;
                    tw.Write("{0}=", reader.Name);
                    reader.ReadAttributeValue();
                    tw.WriteLine(reader.Value);
                    //reader.MoveToNextAttribute();
                }
            }

            //reader = new DebuggingXmlTextReader(new XPathNavigatorReader(nav));
            reader = new XPathNavigatorReader(nav);
            XmlDocument doc = new XmlDocument(nav.NameTable);

            doc.Load(reader);

            Assert.AreEqual("customer", doc.DocumentElement.LocalName);
            Assert.AreEqual("urn-kzu", doc.DocumentElement.NamespaceURI);
            Assert.AreEqual(4, doc.DocumentElement.Attributes.Count);
            Assert.AreEqual(2, doc.DocumentElement.ChildNodes.Count);
        }
Esempio n. 4
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);
		}
Esempio n. 5
0
		public void XmlDocumentLoading()
		{
			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);
			//XmlReader reader = new XmlTextReader(new StringReader(xml));

			//reader.MoveToContent();
			//Console.WriteLine(reader.ReadOuterXml());

			System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(Console.Out);

			while (reader.Read())
			{
				tw.Indent = reader.Depth;
				tw.WriteLine("Name={0}, Type={1}", reader.Name, reader.NodeType);
				int count = reader.AttributeCount;
				//reader.MoveToFirstAttribute();
				//for (int i = 0; i < count; i++) 
				while (reader.MoveToNextAttribute())
				{
					tw.Indent = reader.Depth;
					tw.Write("{0}=", reader.Name);
					reader.ReadAttributeValue();
					tw.WriteLine(reader.Value);
					//reader.MoveToNextAttribute();
				}
			}

			//reader = new DebuggingXmlTextReader(new XPathNavigatorReader(nav));
			reader = new XPathNavigatorReader(nav);
			XmlDocument doc = new XmlDocument(nav.NameTable);
			doc.Load( reader );
           
			Assert.AreEqual("customer", doc.DocumentElement.LocalName);
			Assert.AreEqual("urn-kzu", doc.DocumentElement.NamespaceURI);
			Assert.AreEqual(4, doc.DocumentElement.Attributes.Count);
			Assert.AreEqual(2, doc.DocumentElement.ChildNodes.Count);
		}
Esempio n. 6
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);
		}