OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   =?utf-8?B?UkU6IFt4bWwtZGV2XSBtYXRjaGluZyB0ZXh0IHdpdGggcmVnZXhw?==?utf-8?

[ Lists Home | Date Index | Thread Index ]

Title: RE: [xml-dev] 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@microsoft.com]
> Sent: Donnerstag, 8. August 2002 16:58
> To: Wannheden, Knut; xml-dev@lists.xml.org
> Subject: RE: [xml-dev] 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@paranor.ch]
>       Sent: Thu 8/8/2002 2:32 AM
>       To: xml-dev@lists.xml.org
>       Cc:
>       Subject: [xml-dev] 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
>
>





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS