Results 1 to 4 of 4
- 07-23-2011, 12:19 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 13
- Rep Power
- 0
"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!
- 07-23-2011, 01:45 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
On which class are you calling method 'matches'? Can you post the extract of code where you call this method?
- 07-23-2011, 03:11 PM #3
Member
- Join Date
- Jul 2011
- Posts
- 13
- Rep Power
- 0
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
- 07-27-2011, 01:07 PM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
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
-
Urgent! How to display this function,use symbol"*" to draw line
By jaxber in forum New To JavaReplies: 3Last Post: 04-29-2011, 01:08 AM -
"package javax.microedition.lcdui doesnt exsist" But on suns webbpage they say it do!
By Addez in forum New To JavaReplies: 4Last Post: 10-30-2009, 07:54 PM -
Exception in thread "main" javax.naming.NameNotFoundException: jmx not bound
By Vartika in forum Advanced JavaReplies: 2Last Post: 08-07-2009, 10:21 PM -
How "Pattern.matches(regex, input)" function works?
By kishan in forum Advanced JavaReplies: 2Last Post: 04-26-2009, 12:46 AM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks