jdom生成不带声明的xml字段串


/**   
     * Document转换为字符串   
     *    
     * @param xmlFilePath XML文件路径   
     * @return xmlStr 字符串   
     * @throws Exception   
     */    
    public static String doc2String(Document doc) throws Exception {     
        Format format = Format.getPrettyFormat();     
        //format.setEncoding("UTF-8");// 设置xml文件的字符为UTF-8,解决中文问题     
        XMLOutputter xmlout = new XMLOutputter(format);     
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
        Element rootElement = doc.getRootElement();
        xmlout.output(rootElement, bo);     
        return bo.toString();     
    }




你可能感兴趣的:(xml编码,jdom去掉声明,xml转string,xml删除声明,头部声明)