java 解析src下xml的问题

来源:互联网 发布:进口美工刀片 编辑:程序博客网 时间:2024/06/07 03:16
src目录下生成的xml就会自动到classes目录下吧,那就先把xml解析出来,放到一个对象里,再用js取出来不就完了这是有一个解析路径在src目录下的xml,希望对你有帮助!src目录下的文件会自动到你所说的:web-inf里面的classes目录下/** * @param args * 不会一次读完,是一个一个的读取 */public static void main(String[] args) {// TODO Auto-generated method stubInputStream is=Dom4jXML.class.getResourceAsStream("/actions.xml");//解Document doc;try {doc = new SAXReader().read(is);//rootElement root=doc.getRootElement();//readerList<Element> actionList=root.elements("action");//读取值for(Element el:actionList){System.out.println("*****************");System.out.println("Action--name:\t"+el.attributeValue("name"));System.out.println("path:"+el.element("path").getTextTrim());System.out.println("class:"+el.element("actionClass").getTextTrim());}} catch (DocumentException e) {// TODO Auto-generated catch blocke.printStackTrace();}}
原创粉丝点击