Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Custom XPath functions

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: "Lance Eason" <leason AT betweenmarkets.com>
  • To: "Guilherme Germoglio" <germoglio AT gmail.com>, <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] Custom XPath functions
  • Date: Fri, 15 Sep 2006 14:43:47 -0500

We had a similar need. The way we approached it was to use Jaxen's
ability to register a Java class containing custom functions via a
namespace declaration. We wrapped adding that declaration to
XPath/XQuery expressions within a utility function:

public class XQueryUtil
{
public static Nodes xquery(Node node, String xpath)
{
// automatically make our custom functions available
xpath = "declare namespace
big='java:com.betweenmarkets.document.BMIFunctions';\n" + xpath;

return nux.xom.xquery.XQueryUtil.xquery(node, xpath);
}
}

and then use the utility function in lieu of directly calling
Node.query():

Nodes result = XQueryUtil.xquery(node,
"bmi:customFunction(/path/to/whatever)");

It works well (with the caveat that you have to know to call the utility
function instead of Node.query()) but I'd be interested to hear if you
come up with a different approach.


-----Original Message-----
From: xom-interest-bounces AT lists.ibiblio.org
[mailto:xom-interest-bounces AT lists.ibiblio.org] On Behalf Of Guilherme
Germoglio
Sent: Friday, September 15, 2006 2:05 PM
To: xom-interest AT lists.ibiblio.org
Subject: [XOM-interest] Custom XPath functions

Hello,

I'm planning to start a project that should use XOM to process XML.
However a must use customized XPath functions in this project.

I've searched for some information about custom XPath functions in XOM
and didn't find anything. Since XOM uses Jaxen for XPath processing, I
looked into adding custom functions to it and actually is quite easy to
do so (simply by getting the org.jaxen.XPathFunctionContext used and
registering a new Function on it).

However, the JaxenConnector class instead of using a singleton
XPathFunctionContext - that could be provided through
XPathFunctionContext.getInstance() and be able to be obtained the same
instance all over the code in order to customize it -, it creates a new
one, what makes more difficult for customization.

So, my question is: Is there any reason to create a new
XPathFunctionContext in JaxenConnector or I can modify it in order to
use the singleton pattern without any side-effects?

Thank you,
Guilherme
_______________________________________________
XOM-interest mailing list
XOM-interest AT lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/xom-interest




Archive powered by MHonArc 2.6.24.

Top of Page