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);
		}
		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);
		}
예제 #3
0
 private static XmlDsigXPathTransform CreateXPathTransform(string xPathString)
 {
     var doc = new XmlDocument();
     doc.LoadXml("<XPath xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"></XPath>");
     var xPathElem = (XmlElement) doc.SelectSingleNode("XPath");
     xPathElem.InnerText = xPathString;
     var xForm = new XmlDsigXPathTransform();
     xForm.LoadInnerXml(xPathElem.SelectNodes("."));
     return xForm;
 }
예제 #4
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
		}
예제 #5
0
        // Create the XML that represents the transform. 
        private static XmlDsigXPathTransform CreateXPathTransform(string xpath, IDictionary<string, string> namespaces)
        {
            // create the XML that represents the transform
            XmlDocument doc = new XmlDocument();

            XmlElement xpathElem = doc.CreateElement("XPath");
            xpathElem.InnerText = xpath;

            // Add the namespaces that should be in scope for the XPath expression
            if (namespaces != null)
            {
                foreach (string ns in namespaces.Keys)
                {
                    XmlAttribute nsAttr = doc.CreateAttribute("xmlns", ns, "http://www.w3.org/2000/xmlns/");
                    nsAttr.Value = namespaces[ns];
                    xpathElem.Attributes.Append(nsAttr);
                }
            }

            // Build a transform from the inputs
            XmlDsigXPathTransform xpathTransform = new XmlDsigXPathTransform();
            xpathTransform.LoadInnerXml(xpathElem.SelectNodes("."));

            return xpathTransform;
        }