The Artima Developer Community
Sponsored Link

Java Answers Forum
xpathfunctionresolver

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jinu G

Posts: 1
Nickname: gj69463
Registered: Apr, 2009

xpathfunctionresolver Posted: Apr 2, 2009 12:13 AM
Reply to this message Reply
Advertisement
I am using the xpathfunctionresolver to add my custom function into the xpath namespace. Most of the examples that I found on web makes use of myAdditionFuntion(2,3) where the functionresolver adds the two numbers and returns the double object.

I want my custom function myAdditionFunction(a,b) to return the two parameters provided a and b at expr.evaluate(doc);

String str = new String("ext:myAdditionFunction(a,b)"

XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
factory.setXPathFunctionResolver(new MyFunctionResolver());
xpath.setNamespaceContext(new MyNamespaceContext());
xpath.setXPathFunctionResolver(new MyFunctionResolver());
 
XPathExpression expr = xpath.compile(str);
String result = expr.evaluate(doc); 
System.out.println(result);


Result should fetch me 'a' and 'b'
or 'a' and 'b' in a list

public Object evaluate(java.util.List args) 
{
	System.out.println("Inside evaluate");
	if (args.size() == 2) {
	
        return new String(args.get(0).toString() 
                          + " , " + 
                          args.get(1).toString());	
 
	}
}
 


The output of the above code is:

com.sun.org.apache.xml.
internal.dtm.ref.DTMNodeList@42719c
,
com.sun.org.apache.xml.
internal.dtm.ref.DTMNodeList@30c221

That is instead of the output as a,b I am getting here the object details as a DTMNodeList.

Please tell me way to work around with DTMNodelist to retreive the text contents of the DTMNode. I would be grateful if you can provide me with any example other than adding double and returning double value.

Thanks in Advance.

Topic: illegal start of type Previous Topic   Next Topic Topic: [ANN] nWire 1.0 Released: Innovative Plugin For Java Code Exploration

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use