All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tmsps.ne4Weixin.utils.XMLParser Maven / Gradle / Ivy

There is a newer version: 0.8.1
Show newest version
package com.tmsps.ne4Weixin.utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * @author zhangwei [email protected] XMLParser
 */
public class XMLParser {
	protected static Logger log = LoggerFactory.getLogger(WeixinUtil.class);

	/**
	 * @author zhangwei [email protected] 将xml文件转成map
	 */
	public static Map getXmlToMap(String xml) {
		if (StrUtil.isBlank(xml)) {
			log.error("XML PARAMETER ILLEGAL !!!!!!");
			throw new IllegalArgumentException();
		} else {
			Map xmlMap = new HashMap();
			try {
				Document document = DocumentHelper.parseText(xml.trim());
				Element root = document.getRootElement();
				@SuppressWarnings("unchecked")
				List list = root.elements();
				for (Element el : list) {
					xmlMap.put(el.getName().toLowerCase(), el.getData());
				}
			} catch (DocumentException e) {
				log.error(e.toString());
				e.printStackTrace();
			}
			return xmlMap;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy