易截截图软件、单文件、免安装、纯绿色、仅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());
     }


相关文档:

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 ......

spring xercesImpl xml 解析问题

问题描述:
   jboss应用服务器,使用spring 
   无法启动服务,错误日志:
[org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@155d3a3] does not
support XML Schema. Are you running on Java 1.4 or below with Apache
Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD ......

.net中,读取XML在页面显示,布局用Repeater控件

 public static IList<News> GetAllNews()
        {
            XmlDocument xdoc = new XmlDocument();
            xdoc.Load("你读取的地址:例如 ......

objective c xml解析

    今天在CC上看到evangel在招人,上面写了一条数据解析,我想应该就是对XML的解析吧,暂且这样理解了,呵呵。下午搜索了一点东西自己弄了一个XML然后读读看看,现在仅仅是读出了一些东西,先保存代码,待后续更新!
    这个是我创建的xml文件,用于测试用的:
<?xml version="1.0" e ......

AJAX使用json解析与使用xml解析的比较

工具:myeclipse 6.5
json中文官方:http://www.json.org/json-zh.html
新建项目webs,在WebRoot下新建目录json
xml的解析方式:
------------------------------------------------------------------
1.新建NewFile.xml
<?xml version="1.0" encoding="UTF-8"?>
<userinfo>
  ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号