KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > javax > xml > xpath > XPathVariableResolver

javax.xml.xpath
Interface XPathVariableResolver

See Also:
Top Examples, Source Code

Object resolveVariable(QName variableName)
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1984]XPathVariableResolver example
By gaspoda on 2008/11/03 12:01:17  Rate
public class VariableTest 
  {  
  public static void main ( String [  ]  args )   {  
   javax.xml.xpath.XPathFactory factory = javax.xml.xpath.XPathFactory.newInstance (  ) ;                 
   factory.setXPathVariableResolver ( new MyVariableResolver (  )  ) ;        
   javax.xml.xpath.XPath xpath = factory.newXPath (  ) ;                 
   xpath.setXPathVariableResolver ( new MyVariableResolver (  )  ) ; 
   Object result = xpath.evaluate ( "/person/ [ @name=$x ] ", document, XPathConstants.NODESET ) ; 
   }  
  }  
  
  
 class MyVariableResolver implements XPathVariableResolver 
      {     
         public Object resolveVariable ( QName var )  
          {  
             if  ( var == null )  
                 throw new NullPointerException ( "The variable name cannot be null" ) ; 
                
             if  ( var.equals ( new QName ( "x" )  )  )  
                 return "John"; 
             else 
                 return null; 
          }  
      }  
 

Popular Tags