Project

Profile

Help

.net extension: error in expression

Added by Anonymous about 17 years ago

Legacy ID: #4232634 Legacy Poster: Bruno_Rosa (bruno_rosa)

hi, I'm working in .net (c#). I've created an assembly, to add extension functions to saxon xpath, and i've imported it to current working class. If i execute the following code, with 'ff' being the namespace associated to my extension class, and 'value()' a function in that class that returns a 'int' value. XPathExecutable xpe = xpc.Compile("ff:value('powerMode')"); XPathSelector xps = xpe.Load(); XdmAtomicValue val1 = (XdmAtomicValue)xps.EvaluateSingle(); val1.Value will be a INt64 object and no errors ocurr. But if i change the previous xpath expression to "ff:value('powerMode') eq 2", this throws a cast exception: "Unable to cast object of type 'net.sf.saxon.dotnet.DotNetExternalObjectType' to type 'net.sf.saxon.type.BuiltInAtomicType'." Why does this happen? Any one can help me? Bruno


Replies (10)

Please register to reply

RE: .net extension: error in expression - Added by Anonymous about 17 years ago

Legacy ID: #4233015 Legacy Poster: Michael Kay (mhkay)

There's certainly something a little odd going on here, I'll have to investigate. Any chance you could package up a small reproducible example? Michael Kay

RE: .net extension: error in expression - Added by Anonymous about 17 years ago

Legacy ID: #4233872 Legacy Poster: Bruno_Rosa (bruno_rosa)

I've uploaded a package example at "http://student.dei.uc.pt/~brosa/arquivos/package_example.zip". It as a readme file that explain some details. Thanks for the attention Bruno

RE: .net extension: error in expression - Added by Anonymous about 17 years ago

Legacy ID: #4237963 Legacy Poster: Michael Kay (mhkay)

Thanks. I've reproduced the problem (but haven't yet fixed it) - whereas the run-time code is converting a returned CLI Int64 value to an XPath integer, the compile-time code isn't doing the equivalent static type inference. As a workaround, you can use number(my:Int64('string')) = 2 Michael Kay http://www.saxonica.com/

RE: .net extension: error in expression - Added by Anonymous about 17 years ago

Legacy ID: #4238764 Legacy Poster: Michael Kay (mhkay)

Problem now logged and fixed, see http://sourceforge.net/tracker/index.php?func=detail&aid=1692540&group_id=29872&atid=397617

RE: .net extension: error in expression - Added by Anonymous about 17 years ago

Legacy ID: #4239330 Legacy Poster: Bruno_Rosa (bruno_rosa)

Thanks for the help. Bruno Rosa

RE: .net extension: error in expression - Added by Anonymous about 17 years ago

Legacy ID: #4250899 Legacy Poster: Bruno_Rosa (bruno_rosa)

hi, i'm having another problem. I want to set the return type of 'ff:value(string id)'(see the initial post) function to 'object', so that i can use it to return int, bool, string. So i set the return type to object. But when i try to compile the following expression XPathExecutable xpe = xpc.Compile("uis:value('evacuating') eq 2"); it trows the following exception 'Cannot perform comparisons involving external objects' Is there any way to solve this problem? Regards, Bruno Rosa

RE: .net extension: error in expression - Added by Anonymous about 17 years ago

Legacy ID: #4251772 Legacy Poster: Michael Kay (mhkay)

You will have to perform the necessary type conversions explicitly, for example "number(string(uis:value('evacuating'))) eq 2" The string() function works on external objects - it invokes their ToString() method.

RE: .net extension: error in expression - Added by Anonymous about 17 years ago

Legacy ID: #4252643 Legacy Poster: Bruno_Rosa (bruno_rosa)

Ok, that works, but i'm trying to do this without changing the xpath expression. Is there any way so that i can cast the result of the value function inside the java code? In c# we can use a built-in function to determine the type of the object when we receive a object. It's not possible to use that functionality somehow in the java code? If string() can invoke the ToString() method of a object, can't i change something so that it can invoke the c# function that returns the object type, and then make the cast to the specific type? thanks for your help, Bruno Rosa

RE: .net extension: error in expression - Added by Anonymous about 17 years ago

Legacy ID: #4252928 Legacy Poster: Michael Kay (mhkay)

When you write (my:f() eq 3), Saxon determines the static type of the lhs as "external object" and the static type of the rhs as "integer". There's no value that is both an external object and an integer, so Saxon reports a static type error. If you want this to work, you have to (a) ensure that the compile-time type of my:f() is a type that overlaps xs:integer or one of the other numeric types in XML Schema, and (b) ensure that the run-time type returned is xs:integer or one of the other numeric types. In effect that means that the function signature for my:f has to declare the return type as int, long, double, or something similar. I think you're right that improvements should be possible here. If the static type inferred were xs:anyAtomicType, then it would probably work. What happens, as a matter of interest, if you do ((my:f() treat as xs:anyAtomicType) eq 3) ...?

RE: .net extension: error in expression - Added by Anonymous about 17 years ago

Legacy ID: #4252970 Legacy Poster: Bruno_Rosa (bruno_rosa)

It trows the same exception as before. I can't declare the return type of the uis:value function to int, because i need the function to be able to return boolean and string too (and possibly other, but for now not needed). In the project i'm developing i need the value function to evaluate the value of a variable and return that value (a int, boolean, string, or a double...) So i will have some cases like "uis:value('evacuating') eq 2" but can also have "uis:value('enter') eq 'yes'" For now the only solution i have is to do what you've told me "number(string(uis:value('evacuating'))) eq 2" but to do this i have to parse the expression, and when it finds uis:value function, determine the type of the variable represented by the function argument, and then add the proper functions to the expression (in your example the number() and string() functions). I will try to find another solution to this without parsing the expression, maybe by making same changes when it determinate the static type (if possible). If i find some thing, i will report it here. thanks for your help and availability Bruno Rosa

    (1-10/10)

    Please register to reply