Java

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Custom XPath functions

    1 answers - 2394 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    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='';\n" + xpath;
    return (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.
    Message
    From: xom-interest-bounces (AT) lists (DOT) ibiblio.org
    [mailto:xom-interest-bounces (AT) lists (DOT) ibiblio.org] Behalf Guilherme
    Germoglio
    Sent: Friday, September 15, 2006 2:05 PM
    To: xom-interest (AT) lists (DOT) ibiblio.org
    Subject: [XM-interest] Custom XPath functions
    Hello,
    I'm planning to start a project that should use XM to process XML.
    However a must use customized XPath functions in this project.
    I've searched for some information about custom XPath functions in XM
    and didn't find anything. Since XM 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
    () 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
    XM-interest mailing list
    XM-interest (AT) lists (DOT) ibiblio.org
    XM-interest mailing list
    XM-interest (AT) lists (DOT) ibiblio.org
  • No.1 | | 683 bytes | |

    Lance Eason wrote:
    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:

    It looks like you're using NUX, not XM; and XQuery instead of XPath. if
    that's an option, that might be the simplest approach.

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

    return (node, xpath);
    }
    }

Re: Custom XPath functions


max 4000 letters.
Your nickname that display:
In order to stop the spam: 7 + 6 =
QUESTION ON "Java"

EMSDN.COM