Project

Profile

Help

own XPathFunction with C#

Added by Anonymous over 16 years ago

Legacy ID: #4791569 Legacy Poster: Alex (alex0834)

Hi, I want to write an extension with a function which extends XPathFunction. This is no problem in Java but with .NET there are packages/classes missing. For example XPathFunction (from javax.xml.xpath) is missing as well as the whole package sf.net.saxon.xpath (which e.g. contains XPathFunctionCall). I saw in the build file that xpath (as well as other packages) are exluded - probably for a reason (JAXP references?). Is it possible at all to implement a XPathFunction in C#? If yes how can I do it? thanks for help, Alex


Replies (3)

Please register to reply

RE: own XPathFunction with C# - Added by Anonymous over 16 years ago

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

Information about writing extension functions for Saxon on .NET is at http://www.saxonica.com/documentation/extensibility/dotnetextensions.html It's the same for XPath, XSLT, or XQuery. There's no equivalent to the JAXP XPath API on .NET - Saxon provides its own uniform API across the three languages. This is why the relevant package is excluded from the .NET build - it's entirely concerned with implementing an interface that's specific to the Java platform. Michael Kay http://www.saxonica.com/

RE: own XPathFunction with C# - Added by Anonymous over 16 years ago

Legacy ID: #4794239 Legacy Poster: Alex (alex0834)

thanks for your fast reply. I think my question was not what I really meant. Actually my problem is how I can register the function in the application. In Java I have code like this: ------------------------------------------------ XPathFactory xpf = new XPathFactoryImpl(); XPathEvaluator evaluator = (XPathEvaluator) xpf.newXPath(); Configuration config = evaluator.getStaticContext().getConfiguration(); evaluator.setStaticContext(new MyStandaloneContext(config)); evaluator.setXPathFunctionResolver(new MyXPathFunctionResolver()); evaluator.setNamespaceContext(new MyNamespaceContext(evaluator.getNamespaceContext())); DOMSource ds = new DOMSource(input); doc = evaluator.setSource(ds); xpe = evaluator.compile(xp); ------------------------------------------------- so when I evaluate the xpath (xp) functions which are resolved with MyXPathFunctionResolver can be used. In C# I currently do this: ------------------------------------------------- Processor processor = new Processor(); XPathCompiler xpc = processor.NewXPathCompiler(); DocumentBuilder builder = processor.NewDocumentBuilder(); XPathSelector sel = xpc.Compile(xPath).Load(); ... ------------------------------------------------- but here I see no way how I could set my own function resolver. regards, Alex

RE: own XPathFunction with C# - Added by Anonymous over 16 years ago

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

Mechanisms for binding extension functions vary enormously from one XSLT or XPath processor to another. The JAXP XPath interface is the only one I know of that uses this concept of a function resolver, and I haven't tried to replicate it in the .NET API.

    (1-3/3)

    Please register to reply