• Dom4j分解xml


    package cn.com.guju.util;
    
    import java.io.ByteArrayInputStream;
    import java.io.UnsupportedEncodingException;
    import java.util.Iterator;
    
    import org.dom4j.Document;
    import org.dom4j.DocumentException;
    import org.dom4j.Element;
    import org.dom4j.io.SAXReader;
    
    public class XmlUtil {
    
    	public static void parserXmlString(String inputXml) {
    		SAXReader saxReader = new SAXReader();
    		try {
    			Document document = saxReader.read(new ByteArrayInputStream(
    					inputXml.getBytes("UTF-8")));
    			Element xml = document.getRootElement();
    			for (Iterator<Element> i = xml.elementIterator(); i.hasNext();) {
    				Element info = i.next();
    				System.out.println(info.getName()+":"+info.getData());
    			}
    		} catch (DocumentException | UnsupportedEncodingException e) {
    			System.out.println(e.getMessage());
    		}
    	}
    
    	public static void main(String[] args) {
    		String xml = "<xml><ToUserName><![CDATA[gh_cc18c38ec023]]></ToUserName><FromUserName><![CDATA[okPKJjjEeML-0szW0Gg1ITKPZiW4]]></FromUserName><CreateTime>1426741701</CreateTime><MsgType><![CDATA[event]]></MsgType><Event><![CDATA[CLICK]]></Event><EventKey><![CDATA[houseType]]></EventKey></xml>";
    		parserXmlString(xml);
    	}
    }
    

    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    74.QT窗口实现类的封装
    73,QT指针数组实战(指针数组与数组指针)
    72.函数模板指针与类函数模板的绑定
    71.lambda表达式的递归
    C++ new delete(一)
    ios之@class
    xcode菜单栏
    ios 自定义delegate(一)
    strong&weak
    TCP/UDP
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4914654.html
Copyright © 2020-2023  润新知