Results 1 to 4 of 4
  1. #1
    omripe is offline Member
    Join Date
    Jul 2011
    Posts
    13
    Rep Power
    0

    Default "javax.xml.transform.TransformerException: Could not find function: matches" help!

    Hi :)
    I am using org.w3c.dom and javax.xml
    I am receiving the following error when trying to parse an XML document with xpath and the function 'matches':
    javax.xml.transform.TransformerException: Could not find function: matches
    What is wrong?
    Am I not using xpath2.0 ? and if so, how can I change it?
    Thanks!

  2. #2
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    On which class are you calling method 'matches'? Can you post the extract of code where you call this method?

  3. #3
    omripe is offline Member
    Join Date
    Jul 2011
    Posts
    13
    Rep Power
    0

    Default

    I am using the matches method as part of the xpath expression. check out this example to illustrate my problem(I am writing some of it from memory so there might be some syntex errors).

    The bottom line is the one where I encounter my error:


    import java.io.File;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.xpath.XPath;
    import javax.xml.xpath.XPathConstants;
    import javax.xml.xpath.XPathFactory;
    import javax.xml.xpath.XPathExpression
    import org.w3c.dom.Document;
    import org.w3c.dom.NodeList;
    import org.xml.sax.InputSource;

    public class XMLReplaceDemo {
    static String inputFile = "C:/temp/data.xml";
    static String outputFile = "C:/temp/data_new.xml";

    public static void main(String[] args) throws Exception {
    Document doc = DocumentBuilderFactory.newInstance()
    .newDocumentBuilder().parse(new InputSource(inputFile));

    // locate the node(s)
    XPath xpath = XPathFactory.newInstance().newXPath();
    NodeList nodes = (NodeList)xpath.evaluate
    ("/accounts/account", doc, XPathConstants.NODESET);

    XPathExpression username = XPathFactory.newInstance().newXPath().compile("./node()[matches('sometext','[a-z]')]"); // here I dont find the method matches

  4. #4
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Apologies for the delay - I've been away...

    You don't appear to be using XPath2 - I don't see any includes for an XPath2 implementation. I get the same error running that code, but it goes away if I use an XPath2 implementation (e.g. Saxon).

    Just put the Saxon jar on your classpath and instantiate the XPathFactory for the Saxon model:
    Java Code:
    ...
    XPathFactory factory = XPathFactory.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON);

Similar Threads

  1. Replies: 3
    Last Post: 04-29-2011, 02:08 AM
  2. Replies: 4
    Last Post: 10-30-2009, 08:54 PM
  3. Replies: 2
    Last Post: 08-07-2009, 11:21 PM
  4. How "Pattern.matches(regex, input)" function works?
    By kishan in forum Advanced Java
    Replies: 2
    Last Post: 04-26-2009, 01:46 AM
  5. Replies: 1
    Last Post: 10-20-2008, 08:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •