📄 processquery.java
字号:
/*
* ProcessQuery.java
*
* Created on 2007年5月10日, 下午11:12
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package XRSystem.Process;
/**
*
* @author 王刚
*/
import com.fatdog.xmlEngine.ResultList;
import com.fatdog.xmlEngine.XQEngine;
import com.fatdog.xmlEngine.exceptions.*;
import javax.xml.parsers.*;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import java.lang.*;
import java.util.*;
import java.sql.*;
import XRSystem.DataAccess.*;
public class ProcessQuery {
private String DocumentName;
private String DocURL;
private String XPathExpr;
private XQEngine ThisEngine;
private boolean PRETTYPRINT = true;
private String RunResult;
/** Creates a new instance of ProcessQuery */
public ProcessQuery(String DocumentName,String XPathExpr) {
this.DocumentName = DocumentName;
this.XPathExpr = XPathExpr;
}
private String GetDocURL() {
ResultSet rs = null;
String SQLString = "SELECT DocumentPath FROM Document WHERE DocumentName ="+"'"+DocumentName+"'";
try{
rs = new SQLResultSet().ExecuteSQL(SQLString);
while(rs.next()){
DocURL = rs.getString(1);
}
} catch(SQLException e){e.printStackTrace();} catch(Exception e){e.printStackTrace();}
return DocURL;
}
public String RunQuery() {
ThisEngine = new XQEngine();
try{
installSunXMLReader();
ThisEngine.setDocument(this.GetDocURL());
ResultList results = ThisEngine.setQuery(XPathExpr);
RunResult = results.emitXml(PRETTYPRINT) + "\n";
}catch( Exception e ){e.printStackTrace();}
return RunResult;
}
private void installXercesXMLReader() throws Exception {
String parserName = "org.apache.xerces.parsers.SAXParser";
XMLReader parser = XMLReaderFactory.createXMLReader( parserName );
ThisEngine.setXMLReader( parser );
}
private void installSunXMLReader() throws Exception {
SAXParserFactory spf = SAXParserFactory.newInstance();
try {
SAXParser parser = spf.newSAXParser();
XMLReader reader = parser.getXMLReader();
ThisEngine.setXMLReader( reader );
} catch( Exception e ) { throw e; }
}
public static void main(String[] args)
{
System.out.println(new ProcessQuery("pub.xml","//author").RunQuery());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -