首页 > 学院 > 开发设计 > 正文

XmlUtil

2019-11-06 06:38:57
字体:
来源:转载
供稿:网友
import java.io.File;import org.apache.commons.lang.StringUtils;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.dom4j.Document;import org.dom4j.DocumentException;import org.dom4j.Element;import org.dom4j.io.SAXReader;public class xmlUtil{    /* the log. */    PRivate static final Log log = LogFactory.getLog(XmlUtil.class.getName());    /**     * Get the Document for response XML file.     *      * @param filePath     *            filePath     *      * @return Document     */    public static Document getDocument(String filePath)    {        Document document = null;        try        {            if (StringUtils.isBlank(filePath))            {                log.error("input param filePath is null.");                return document;            }                        document = new SAXReader().read(new File(filePath));        }        catch (DocumentException e)        {            log.error("getDocument failed.", e);        }        return document;    }    /**     * Judge the element whether has children.     *      * @param el     *            . Element Object.     * @return boolean true/false.     */    public static boolean hasChildren(Element el)    {        if (el.hasContent() && el.elements().size() > 0)        {            return true;        }        return false;    }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表