public void TransformSimple ()
		{
			XmlDsigXPathTransform t = new XmlDsigXPathTransform ();
			XmlDocument xpdoc = new XmlDocument ();
			string ns = "http://www.w3.org/2000/09/xmldsig#";
			string xpath = "<XPath xmlns='" + ns + "' xmlns:x='urn:foo'>*|@*|namespace::*</XPath>"; // not absolute path.. so @* and namespace::* does not make sense.
			xpdoc.LoadXml (xpath);
			t.LoadInnerXml (xpdoc.ChildNodes);
			XmlDocument doc = new XmlDocument ();
			doc.LoadXml ("<element xmlns='urn:foo'><foo><bar>test</bar></foo></element>");
			t.LoadInput (doc);
			XmlNodeList nl = (XmlNodeList) t.GetOutput ();
			AssertEquals (XmlNodeType.Document, nl [0].NodeType);
			AssertEquals (XmlNodeType.Element, nl [1].NodeType);
			AssertEquals ("element", nl [1].LocalName);
			AssertEquals (XmlNodeType.Element, nl [2].NodeType);
			AssertEquals ("foo", nl [2].LocalName);
			AssertEquals (XmlNodeType.Element, nl [3].NodeType);
			AssertEquals ("bar", nl [3].LocalName);
			// MS.NET bug - ms.net returns ns node even when the
			// current node is ns node (it is like returning
			// attribute from attribute nodes).
//			AssertEquals (XmlNodeType.Attribute, nl [4].NodeType);
//			AssertEquals ("xmlns", nl [4].LocalName);
		}
		public void FunctionHereObsolete ()
		{
			XmlDsigXPathTransform t = new XmlDsigXPathTransform ();
			XmlDocument xpdoc = new XmlDocument ();
			string ns = "http://www.w3.org/2000/09/xmldsig#";
//			string xpath = "<XPath xmlns='" + ns + "' xmlns:x='urn:foo'>here()</XPath>";
			string xpath = "<XPath xmlns='" + ns + "' xmlns:x='urn:foo'></XPath>";
			xpdoc.LoadXml (xpath);
			t.LoadInnerXml (xpdoc.ChildNodes);
			XmlDocument doc = new XmlDocument ();

			doc.LoadXml ("<element a='b'><foo><bar>test</bar></foo></element>");
			t.LoadInput (doc);
			// FX 2.0 throws at next line!
			XmlNodeList nl = (XmlNodeList) t.GetOutput ();
			AssertEquals (0, nl.Count);

			doc.LoadXml ("<element xmlns='urn:foo'><foo><bar>test</bar></foo></element>");
			t.LoadInput (doc);
			nl = (XmlNodeList) t.GetOutput ();
			AssertEquals (1, nl.Count);

			doc.LoadXml ("<element xmlns='urn:foo'><foo xmlns='urn:bar'><bar>test</bar></foo></element>");
			t.LoadInput (doc);
			nl = (XmlNodeList) t.GetOutput ();
			AssertEquals (2, nl.Count);

			doc.LoadXml ("<element xmlns='urn:foo' xmlns:x='urn:x'><foo xmlns='urn:bar'><bar>test</bar></foo></element>");
			t.LoadInput (doc);
			nl = (XmlNodeList) t.GetOutput ();
			AssertEquals (3, nl.Count);

			doc.LoadXml ("<envelope><Signature xmlns='http://www.w3.org/2000/09/xmldsig#'><XPath>blah</XPath></Signature></envelope>");
			t.LoadInput (doc);
			nl = (XmlNodeList) t.GetOutput ();
			AssertEquals (1, nl.Count);
			AssertEquals (XmlNodeType.Attribute, nl [0].NodeType);
		}
예제 #3
0
		// MS.NET looks incorrect, or something incorrect in this test code; It turned out nothing to do with function here()
		public void FunctionHereObsolete ()
		{
			XmlDsigXPathTransform t = new XmlDsigXPathTransform ();
			XmlDocument xpdoc = new XmlDocument ();
			string ns = "http://www.w3.org/2000/09/xmldsig#";
//			string xpath = "<XPath xmlns='" + ns + "' xmlns:x='urn:foo'>here()</XPath>";
			string xpath = "<XPath xmlns='" + ns + "' xmlns:x='urn:foo'></XPath>";
			xpdoc.LoadXml (xpath);
			t.LoadInnerXml (xpdoc.ChildNodes);
			XmlDocument doc = new XmlDocument ();

			doc.LoadXml ("<element a='b'><foo><bar>test</bar></foo></element>");
			t.LoadInput (doc);

			XmlNodeList nl = (XmlNodeList) t.GetOutput ();
			Assert.AreEqual (0, nl.Count, "0");

			doc.LoadXml ("<element xmlns='urn:foo'><foo><bar>test</bar></foo></element>");
			t.LoadInput (doc);
			nl = (XmlNodeList) t.GetOutput ();
#if NET_2_0
			Assert.AreEqual (0, nl.Count, "1");
#else
			Assert.AreEqual (1, nl.Count, "1");
#endif

			doc.LoadXml ("<element xmlns='urn:foo'><foo xmlns='urn:bar'><bar>test</bar></foo></element>");
			t.LoadInput (doc);
			nl = (XmlNodeList) t.GetOutput ();
#if NET_2_0
			Assert.AreEqual (0, nl.Count, "2");
#else
			Assert.AreEqual (2, nl.Count, "2");
#endif

			doc.LoadXml ("<element xmlns='urn:foo' xmlns:x='urn:x'><foo xmlns='urn:bar'><bar>test</bar></foo></element>");
			t.LoadInput (doc);
			nl = (XmlNodeList) t.GetOutput ();
#if NET_2_0
			Assert.AreEqual (0, nl.Count, "3");
#else
			Assert.AreEqual (3, nl.Count, "3");
#endif

			doc.LoadXml ("<envelope><Signature xmlns='http://www.w3.org/2000/09/xmldsig#'><XPath>blah</XPath></Signature></envelope>");
			t.LoadInput (doc);
			nl = (XmlNodeList) t.GetOutput ();
#if NET_2_0
			Assert.AreEqual (0, nl.Count, "4");
#else
			Assert.AreEqual (1, nl.Count, "4");
			Assert.AreEqual (XmlNodeType.Attribute, nl [0].NodeType, "NodeType");
#endif
		}