Search

'HtmlCleaner'에 해당되는 글 1건

  1. 2009.07.27 [html] HtmlCleaner를 이용한 html 파싱 1
참고: http://x1210.tistory.com/385
http://htmlcleaner.sourceforge.net/index.php

public String getResultCode(String resp) throws IOException {
        // create an instance of HtmlCleaner
        HtmlCleaner cleaner = new HtmlCleaner();

        // take default cleaner properties
        CleanerProperties props = cleaner.getProperties();
         
//        // customize cleaner's behaviour with property setters
//        props.setXXX(...);
       
        // Clean HTML taken from simple string, file, URL, input stream,
        // input source or reader. Result is root node of created
        // tree-like structure. Single cleaner instance may be safely used
        // multiple times.
        TagNode node = cleaner.clean(resp);

        // optionally find parts of the DOM or modify some nodes
//        TagNode[] myNodes = node.getElementsByName(MLBConstants.MCODE_RESULT_NAME, true);
        TagNode[] myNodes = node.getElementsByName("input", true);
//        // and/or
//        Object[] myNodes = node.evaluateXPath(xPathExpression);
//        // and/or
//        aNode.removeFromTree();
//        // and/or
//        aNode.addAttribute(attName, attValue);
//        // and/or
//        aNode.removeAttribute(attName, attValue);
//        // and/or
//        cleaner.setInnerHtml(aNode, htmlContent);
         
//        // serialize a node to a file, output stream, DOM, JDom...
//        new XXXSerializer(props).writeXmlXXX(aNode, ...);
//        myJDom = new JDomSerializer(props, true).createJDom(aNode);
//        myDom = new DomSerializer(props, true).createDOM(aNode);
       
        String resultCode = "";
       
        for(int i = 0; i < myNodes.length; i++) {
           
            System.out.println("name = " + myNodes[i].getAttributeByName("name"));
           
            if(myNodes[i].getAttributeByName("name").equals("result")) {
                resultCode = myNodes[i].getAttributeByName(MLBConstants.MCODE_RESULT_ATTRIBUTE);
                System.out.println(">>> value of result = " + resultCode);
            }
        }
       
        return MLBConstants.getMcodeRequestResultMessage(resultCode);
    }