2014-10-22 74 views
0

我在尋找某種現成的Java庫的驗證和獲取有關信息的內置HTML標籤和屬性如下所示:的Java:驗證和獲取有關HTML標籤信息/屬性

public class MyHTMLGenerator { 

    /** 
    * Accepts tag name and attributes and returns a string containing HTML 
    * element. 
    */ 
    public String createElement(
      String tagName, Map<String, String> tagAttributes) throws Exception { 
     HTMLUtils utils = HTMLUtils.for(HTMLDialects.HTML_5); 
     HTMLTagInfo tagInfo = utils.getTagInfo(tagName); 
     ... 
     // checking that tag name specified is a valid HTML5 tag name 
     // checking that tag attributes' names and values are valid for this tag 
     // does this tag is paired or not? which one to return: 
     // "<p>" or "<p></p>"? 
     // etc. 
     ... 
     return result; 
    } 

} 

回答

0

我推薦Jsoup,它允許您將HTML解析到Java DOM中並對其進行處理。