隨筆-37  評(píng)論-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 楓中玎玲 閱讀(1483) 評(píng)論(0)  編輯  收藏 所屬分類: Java常用

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 社旗县| 曲松县| 陕西省| 锦屏县| 班玛县| 东丰县| 聊城市| 平邑县| 苍南县| 望奎县| 高邮市| 乌兰察布市| 厦门市| 明光市| 霍林郭勒市| 将乐县| 麦盖提县| 林州市| 灵璧县| 博乐市| 修武县| 镶黄旗| 阳谷县| 宕昌县| 伊金霍洛旗| 香港 | 张家界市| 夏邑县| 尖扎县| 淳安县| 泰安市| 乌兰县| 灵寿县| 柏乡县| 凤城市| 环江| 新源县| 泸西县| 新密市| 夏邑县| 威海市|