登录 注册
当前位置:主页 > 资源下载 > 40 > dom4j-1.6.1.jar下载

dom4j-1.6.1.jar下载

  • 更新:2024-05-13 18:36:08
  • 大小:307KB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:Java - 后端
  • 格式:JAR

资源介绍

//一下代码创建一个xml文档 import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.io.XMLWriter; import java.io.*; public class XmlDom4J{ public void generateDocument(){ Document document = DocumentHelper.createDocument(); Element catalogElement = document.addElement("catalog"); catalogElement.addComment("An XML Catalog"); catalogElement.addProcessingInstruction("target","text"); Element journalElement = catalogElement.addElement("journal"); journalElement.addAttribute("title", "XML Zone"); journalElement.addAttribute("publisher", "IBM developerWorks"); Element articleElement=journalElement.addElement("article"); articleElement.addAttribute("level", "Intermediate"); articleElement.addAttribute("date", "December-2001"); Element titleElement=articleElement.addElement("title"); titleElement.setText("Java configuration with XML Schema"); Element authorElement=articleElement.addElement("author"); Element firstNameElement=authorElement.addElement("firstname"); firstNameElement.setText("Marcello"); Element lastNameElement=authorElement.addElement("lastname"); lastNameElement.setText("Vitaletti"); document.addDocType("catalog", null,"file://c:/Dtds/catalog.dtd"); try{ XMLWriter output = new XMLWriter( new FileWriter( new File("c:/catalog/catalog.xml") )); output.write( document ); output.close(); } catch(IOException e){System.out.println(e.getMessage());} } public static void main(String[] argv){ XmlDom4J dom4j=new XmlDom4J(); dom4j.generateDocument(); }}