publicintformatXMLFile(Stringfilename){ intreturnValue=0; try{ SAXReadersaxReader=newSAXReader(); Documentdocument=saxReader.read(newFile(filename)); XMLWriteroutput=null; /**格式化输出,类型IE浏览一样*/ OutputFormatformat=OutputFormat.createPrettyPrint(); /**指定XML字符集编码*/ format.setEncoding("G...
String str = clazz.getName(); String objName = str.substring(str.lastIndexOf(".")+1); //获取对象元素(以表名为标签的元素),不存在,则创建 Element tableElement = root.element(objName); if(tableElement == null){ tableElement = root.addElement(objName).addAttribute("id", id); } //创...
1packagecom.holen.dom4j;2importjava.io.File;3importjava.io.FileWriter;4importjava.util.Iterator;5importjava.util.List;6importorg.dom4j.Attribute;7importorg.dom4j.Document;8importorg.dom4j.DocumentHelper;9importorg.dom4j.Element;10importorg.dom4j.io.OutputFormat;11importorg.dom4j.io.SAXReader;12import...
public Document read(String fileName) throws MalformedURLException, DocumentException { SAXReader reader = new SAXReader(); Document document = reader.read(new File(fileName)); return document; } 其中,reader的read方法是重载的,可以从InputStream, File, Url等多种不同的源来读 取。得到的Document对象...
import java.io.File;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import org.dom4j.Attribute;import org.dom4j.Document;import org.dom4j.DocumentException;import org.dom4j.Element;import org.dom4j.io.SAXReader;public class ParserHeroXML {Document document = null;Element roo...
importorg.dom4j.Document; importorg.dom4j.DocumentException; importorg.dom4j.Element; importorg.dom4j.io.SAXReader; publicclassParserHeroXML{ Documentdocument=null; ElementrootElement=null; Herohero=null; // 用来保存所有的英雄数据 List<Hero> heros =newArrayList<>(); ...
文档名由输入参数决定23*@paramfilename 需建立的文件名24*@return返回操作结果, 0表失败, 1表成功25*/26publicintcreateXMLFile(String filename){27/**返回操作结果, 0表失败, 1表成功*/28intreturnValue = 0;29/**建立document对象*/30Document document =DocumentHelper.createDocument();31/**建立XML文档...
*@paramfilename需建立的文件名 *@return返回操作结果,0表失败,1表成功 */ publicintcreateXMLFile(Stringfilename){ /**返回操作结果,0表失败,1表成功*/ intreturnValue=0; /**建立document对象*/ Documentdocument=DocumentHelper.createDocument();