由于最近项目需求,肯能会进行解析不同xml文件,故写了这样一个工具类,value赋值的部分,当前只写了String,Integer,List的赋值,要进行其他类型的赋值,请参照原先部分,写到addValue中即可,理论上来讲使用的是递归,list可以继续嵌套list进行赋值
package com.htht.project.task.util;
import com.htht.project.task.bean.Product;
import com.htht.project.task.bean.TaskXml;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import static com.htht.common.utils.job.JobInvokeUtil.getMethodName;
/**
* @ClassName XmlUtil
* @Author Hui_chen
* @Description //用来解析xml文件
* @Date 2020/7/28 13:46
* @Version V1.0
**/
public class XmlUtil{
public static void node(NodeList list){
for (int i = 0; i <list.getLength() ; i++) {
Node node = list.item(i);
NodeList childNodes = node.getChildNodes();
for (int j = 0; j <childNodes.getLength() ; j++) {
if (childNodes.item(j).getNodeType()== Node.ELEMENT_NODE)