Using Node set with Xpath in C#

NemikanNemikan Icrontian
edited May 2009 in Science & Tech
Currently I'm working on a program where I'm trying to create a custom function to be used with XPath in a C# application. I've done a decent bit of browsing around and testing on this issue now and am not sure what to try next. See below for a link showing the basis of part of what I'm attempting to do.

http://msdn.microsoft.com/en-us/library/ms950806.aspx

The issue is not with the majority of the code, it is with the datatype. I cannot seem to find a "node set" datatype, except for the field of XPathResultType.NodeSet which... is a field not a type. The only valid types for passing data within XPath are one of the following: Node Set, String, Boolean, Number, XSLT 1.0 additions (these can be seen in the link above). Since I need to use a collection of strings, Node Set is the only type that will work. The example below shows the basis of what I'm working with.

public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] ArgTypes)

...

case "Split":
r = new Regex(args[1].ToString());
string [] s1 = r.Split(args[0].ToString());
int n = Convert.ToInt32(args[2]);
if (s1.Length < n)
str = "";
else
str = s1[n - 1];
break;
...
</pre>This works fine, but that example is utilizing args[0] and args[2] as and int and string. I have to first convert args[0] to a Node Set in order to pass it correctly. (its not shown here but in the code i'm using it is required and isn't something I'm allowed to work around).

The closest thing I've found to what I want is by using XPathNavigator.Evaluate . The problem is it returns an Object, and without having a Node Set type I cannot cast / convert it to a Node Set.

The objective of what i'm trying to do is to create a function (as shown in the split example) with one parameter (args[0]) being of type Node Set. The question I have, is how can I use the type Node Set?

Comments

  • NemikanNemikan Icrontian
    edited May 2009
    mhmh... I think I figured out a work around... by using an XPathIterator. The required type looks like is for one of the three classes I'm using, and I can modify the parameter type in the one I need to... basically problem solved :rockon:
This discussion has been closed.