随笔-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 枫中玎玲 阅读(1446) 评论(0)  编辑  收藏 所属分类: Java常用

只有注册用户登录后才能发表评论。


网站导航: