[Home] [By Thread] [By Date] [Recent Entries]

  • To: =?utf-8?B?J0RhcmUgT2Jhc2Fuam8n?= <dareo@m...>, xml-dev@l...
  • Subject: =?utf-8?B?UkU6IFt4bWwtZGV2XSBtYXRjaGluZyB0ZXh0IHdpdGggcmVnZXhw?==?utf-8?B?IGluIHhwYXRo?=
  • From: =?utf-8?B?V2FubmhlZGVuLCBLbnV0?= <knut.wannheden@p...>
  • Date: Thu, 8 Aug 2002 17:11:01 +0200

Title: RE: matching text with regexp in xpath

I wasn't going to make use of any XSLT engine at all.  The intention is to use it as part of an XPath expression inside a XML processing Java application.  Currently I don't even have to be able to use the function from inside a document, just in the processor.  I'm using dom4j and Jaxen to process the XML document and run XPath queries.

I now have a first implementation of my function, although I still have a problem with the namespaces.  I wasn't able to register the function with an associated namespace, just without namespace.  But there must be some solution to that.  Maybe someone can tell me how I can get that to work...  This is what I'm doing now (without namespace):

        XPathFunctionContext ctx = new XPathFunctionContext();
        // myFunction implements org.jaxen.Function
        ctx.registerFunction(null, "match", myFunction);
        XPath xp = DocumentFactory.getInstance().
                createXPath("/a/b[match(@c, '{.}')]");
        xp.setFunctionContext(ctx);
        List matches = xp.selectNodes(element);

If I use a namespace I get an InvalidXPathException when calling createXPath() even though I have it registered using DocumentFactory.setXPathNamespaceURIs().

--
knut

> -----Original Message-----
> From: Dare Obasanjo [mailto:dareo@m...]
> Sent: Donnerstag, 8. August 2002 16:58
> To: Wannheden, Knut; xml-dev@l...
> Subject: RE: matching text with regexp in xpath
>
>
> It depends on what XSLT processor you are using to determine
> what extension functions are available to you or embedded
> scripting options you have.
>
>       -----Original Message-----
>       From: Wannheden, Knut [mailto:knut.wannheden@p...]
>       Sent: Thu 8/8/2002 2:32 AM
>       To: xml-dev@l...
>       Cc:
>       Subject: matching text with regexp in xpath
>      
>      
>
>       Hi,
>
>       I was wondering if anybody knows of an extension
> function to XPath which allows me to match text and attribute
> values in XML documents against regular expressions.  I'd
> like to be able to write something like:
>
>               /a/b[re:match(@c, '{.}')]
>
>       to match all elements where an attribute has a value
> matching the regexp {.} (AVT) or:
>
>               /a/b/@c[re:match(., '{.}')]
>
>       to match the attribute elements themselves.
>
>       If there isn't such a thing yet I imagine it shouldn't
> be to hard to write.  Can somebody give me some
> hints/directions on how to get started with this?
>
>       Thanks,
>
>       --
>       knut
>
>


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member