qiulin.java~4~

来自「本程序用JAVA编制」· JAVA~4~ 代码 · 共 53 行

JAVA~4~
53
字号
import java.util.*;import java.io.*;import java.sql.Timestamp;import org.w3c.dom.*;public class Qiulin {  private static final String source =  "http://stock.sina.com.cn/cgi-bin/stock/quote/quote.cgi?symbol=600891&country=sh";  private static final String xslFile = "new-xml/600891.xsl";  private static final String xmlFile = "new-xml/600891-result.xml";  public Qiulin(){  //public static void main(String args[]) {    try {      // Retrieve the source document as XML      Document xhtml = StockHelper.tidyHTML(source);      // Parse the XSL document      Document xsl   = StockHelper.parseXMLFromFile(xslFile);      // Get the current data by applying the XSL transform      Document data  = StockHelper.transformXML(xhtml, xsl);      // For convenience, add a timestamp to what we have done      Date now = new Date();      Timestamp time = new Timestamp(now.getTime());      Element root = data.getDocumentElement();      NodeList nl = root.getElementsByTagName("stock");      Element stock = (Element)nl.item(0);      for(int i=0;i<stock.getChildNodes().getLength();i++){        String value=stock.getChildNodes().item(i).getChildNodes().item(0).getNodeValue();        stock.getChildNodes().item(i).getChildNodes().item(0).setNodeValue(value.trim());      }      //Write the output file, merging if necessary      File dataFile  = new File(xmlFile);      if (dataFile.exists()) {         //If we have extracted before, merge the data and write the file        Document oldData = StockHelper.parseXMLFromFile(dataFile);        StockHelper.mergeXML(oldData.getDocumentElement(), stock, false);        StockHelper.outputXMLToFile(oldData, xmlFile);        //System.out.print(stock.getChildNodes().item(0).getChildNodes().item(0).getNodeValue());      } else {        // If this is our first extraction, just write the file        StockHelper.outputXMLToFile(data, xmlFile);      }    } catch (XMLHelperException xmlhe) {      System.err.println(          "There was an error in the extraction process:\n" + xmlhe.getMessage());    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?