import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
public class Demo {
public static void main(String[] args) throws Exception{
Document document=new SAXReader().read("D:/daima/exercise/xml/xml/web.xml");
//通过xpath
Element element = (Element) document.selectSingleNode("//servlet-class");
String path = element.getText();
//反射
Class clazz=Class.forName(path);
Method method = clazz.getMethod("add");
method.invoke(clazz.newInstance());
}
}
通过解析xml文件,让类的方法执行
最新推荐文章于 2023-01-30 16:08:36 发布