易截截图软件、单文件、免安装、纯绿色、仅160KB

通过DOM4J解析XML文件小结

创建XML文件:
public boolean createXML(){
  try{
   Document doc = DocumentHelper.createDocument();
   Element root = doc.addElement("root");
   Element personNode = root.addElement("person");
   Element sonNode = personNode.addElement("fristson");
   sonNode.setText("lk1");
   Element sonNode2 = personNode.addElement("secandtson");
   sonNode2.setText("lk2");
   
   OutputFormat opf = OutputFormat.createPrettyPrint();
   opf.setEncoding("GB2312");
   
   XMLWriter xmlw = new XMLWriter(new FileWriter("d:\\myXML.xml"),opf);
   xmlw.write(doc);
   
   xmlw.close();
   return true;
  }catch(Exception e){
   System.out.println("error: In create XML");
   return false;
  }
 }
以上只是个简单的创建了一个XML文件在D盘下,下边主要是分析XML文件,提取名字和内容:以JAVA项目中,经典的WEB.XML为例
public boolean updateXML(){
  Document doc = null;
  try{
   SAXReader sr = new SAXReader();
   doc = sr.read(new File("d:\\web.xml"));
   Element personRoot = doc.getRootElement();
   Iterator personNode = personRoot.elementIterator();
   while(personNode.hasNext()){
    Element sonNode = (Element)personNode.next();
    List sonNodes = sonNode.elements();
    System.out.println(sonNode.getName());
     for(int i = 0 ;i<sonNodes.size() ; i++){
      System.out.println(i+":"+((Element)sonNodes.get(i)).getName());
      System.out.println(i+":"+((Element)sonNodes.get(i)).getText());
     }


相关文档:

java解析XML的四种方法

XML现在已经成为一种通用的数据交换格式,它的平台无关性,语言无关性,系统无关性,给数据集成与交互带来了极大的方便。对于XML本身的语法知识与技术细节,需要阅读相关的技术文献,这里面包括的内容有DOM(Document Object Model),DTD(Document Type Definition),SAX(Simple API for XML),XSD(Xml Schema Definition),XSLT(Exten ......

vim html xml 自动补全(在closetag.vim 上作了点修改)

当输入 》时自动补全 当输入《/时自动补全
“=================================
" File: closetag.vim
" Summary: Functions and mappings to close open HTML/XML tags
" Uses: <C-_> -- close matching open tag
" Author: Steven Mueller <di ......

结合反射与 XML 实现 Java 编程的动态性

反射是 Java 语言被视为动态或准动态语言的一个关键性质,结合反射和 XML 会帮助我们更快、更方便地实现一些动态代码,从而解决编程中可能遇到的不确定问题。本文将结合反射与 XML 对 Java 编程的动态性进行深入浅出的讨论。在理解本文的思想之后,您可以将其应用到程序中以创建灵活的代码。
引言
在现实生活中,经常会发 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号