dom4j 解析String 数组格式xml

package com.sds.mobile.groupware.news.connector;
 
import java.util.Iterator;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
 
public class test {
    public static void main(String[] args) throws Exception {
        String jtxw = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><DOCUMENT><CHNLDOCS><CHNLDOC><ID>5570</ID><TITLE><![CDATA[ 这是集团新闻置顶的文章  ]]></TITLE><DATE><![CDATA[ 2013-10-11]]></DATE><COMPANY><![CDATA[ 信息管理部 ]]></COMPANY></CHNLDOC><CHNLDOC><ID>3036</ID><TITLE><![CDATA[ 一汽大众30万增量来自西南和华南]]></TITLE><DATE><![CDATA[ 2013-10-09  ]]></DATE><COMPANY><![CDATA[ 信息管理部  ]]></COMPANY></CHNLDOC></CHNLDOCS><PAGECOUNT>502</PAGECOUNT></DOCUMENT>";
        Document document = DocumentHelper.parseText(jtxw);
        Element rootElt = document.getRootElement();
        Element element = rootElt.element("CHNLDOCS");
        for(Iterator iterator = element.elementIterator("CHNLDOC"); iterator.hasNext();) {
            Element elem = (Element)iterator.next();
            System.out.println("ID::"+elem.elementTextTrim("ID"));
            System.out.println("TITLE::"+elem.elementTextTrim("TITLE"));
            System.out.println("DATE::"+elem.elementTextTrim("DATE"));
            System.out.println("COMPANY::"+elem.elementTextTrim("COMPANY"));
        }
    }
}

    该文需要用到dom4j-1.6.1.jar ,可以自行下载,也可到我的百度网盘下载地址:

http://pan.baidu.com/s/1DZBV9
或者

 

http://pan.baidu.com/s/1tGP5B

你可能感兴趣的:(java,xml,dom4j)