java xml basex 数据库

官方:

eg:xquery使用
import  org.basex.core.Commands;
import  org.basex.core.proc.Proc;
import  org.basex.data.Result;
import  org.basex.io.ConsoleOutput;
import  org.basex.query.QueryException;
import  org.basex.query.QueryProcessor;
import  org.basex.query.xquery.XQueryProcessor;

/**
 * This class serves an example for executing XQuery requests.
 
*/
public   final   class  XQueryExample {
  
/**  Sample query.  */
  
private   static   final  String XMLFILE  =  XPathExample. class .getClassLoader().getSystemResource(
              
" xx.xml "
         ).getPath();
  
  
  
private   static   final  String QUERY  =   "  for $x in doc(' " + XMLFILE + " ')//property  "   +
                                              
"  return <child>{data($x/@name)}</child> " ;

  
/**  Private constructor.  */
  
private  XQueryExample() { }
  
/**
   * Main method of the example class.
   * 
@param  args (ignored) command-line arguments
   * 
@throws  Exception exception
   
*/
  
public   static   void  main( final  String[] args)  throws  Exception {

    
//  FIRST EXAMPLE:
    System.out.println( " First example: " );

    
//  create standard output stream
     final  ConsoleOutput out  =   new  ConsoleOutput(System.out);

    
//  Create a BaseX process
     final  Proc proc  =  Proc.get(Commands.XQUERY, QUERY);
    
//  launch process
     if (proc.execute()) {
      
//  successful execution: print result
      proc.output(out);
    } 
else  {
      
//  execution failed: print result
      proc.info(out);
    }
    out.flush();
    System.out.println();
    
    
//  SECOND EXAMPLE (ALTERNATIVE):
    System.out.println( " Second example: " );

    
//  Execute XQuery request
     try  {
      
//  create query instance
       final  QueryProcessor xquery  =   new  XQueryProcessor(QUERY);
      
//  execute query; no initial context set is specified (null)
       final  Result result  =  xquery.query( null );
      
//  print output
      result.serialize(out,  false );
      out.println();
    } 
catch ( final  QueryException e) {
      
//  dump stack trace
      e.printStackTrace();
    }

    
//  close output stream
    out.close();
  }
}


结果:
First example:
< child > connection.datasource </ child >
< child > dialect </ child >
< child > show_sql </ child >
< child > hibernate.cache.provider_class </ child >
< child > cache.use_query_cache </ child >

Second example:
< child > connection.datasource </ child >
< child > dialect </ child >
< child > show_sql </ child >
< child > hibernate.cache.provider_class </ child >
< child > cache.use_query_cache </ child >


数据来源:
xx.xml
<? xml version='1.0' encoding='utf-8' ?>

< hibernate-configuration >

    
< session-factory >

        
< property  name ="connection.datasource" > java:comp/env/jdbc/USERPORTAL1 </ property >
        
< property  name ="dialect" > org.hibernate.dialect.MySQLInnoDBDialect </ property >
         
< property  name ="show_sql" > true </ property >
         
< property  name ="hibernate.cache.provider_class" > org.hibernate.cache.EhCacheProvider </ property >
         
< property  name ="cache.use_query_cache" > true </ property >
    
<!--  JDBC connection pool (use the built-in)  -->

    
</ session-factory >

</ hibernate-configuration >


你可能感兴趣的:(java xml basex 数据库)