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 = "5570<![CDATA[ 这是集团新闻置顶的文章  ]]>3036<![CDATA[ 一汽大众30万增量来自西南和华南]]>502";
        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)