隨筆-37  評論-58  文章-4  trackbacks-0
           1public class Canon_2219Impl extends BaseCrawler{
           2   public Transformer transformer = null;
           3   public XPath xpath = null;
           4   .
           5   
           6   public Canon_2219Impl(){
           7      xpath = XPathFactory.newInstance().newXPath();
           8        try{
           9            transformer = TransformerFactory.newInstance().newTransformer();
          10            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
          11            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
          12            transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
          13            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount""4");
          14            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
          15        }
          catch(Exception e){
          16            e.printStackTrace();
          17        }

          18   
          19   }

          20
          21   
          22        //change node to string
          23    protected String asXml(Node node) throws Exception {
          24       if(node == null){
          25           return null;
          26       }

          27       DOMSource domSource = new DOMSource(node);
          28       java.io.StringWriter sw = new java.io.StringWriter();
          29       StreamResult sr = new StreamResult(sw);
          30       this.transformer.transform(domSource, sr);
          31       String xml = sw.toString();
          32       return xml;
          33    }

          34}

          35
          36






          posted on 2011-11-15 16:30 楓中玎玲 閱讀(1485) 評論(0)  編輯  收藏 所屬分類: Java常用

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 莱西市| 永城市| 抚顺市| 昂仁县| 临潭县| 隆化县| 阿合奇县| 湘阴县| 邵阳市| 平湖市| 金塔县| 肇州县| 岳池县| 杨浦区| 扬州市| 鹤庆县| 华阴市| 林西县| 金坛市| 南安市| 瓦房店市| 信阳市| 莒南县| 舞钢市| 辽中县| 镶黄旗| 平罗县| 资源县| 延吉市| 会宁县| 修武县| 体育| 临朐县| 开原市| 连州市| 台湾省| 驻马店市| 阿图什市| 兴化市| 清丰县| 信阳市|