Xml文件
ffnullnull02013-11null1232013-11-252013-11-261233nullnull02013-11null2013-11-252013-11-2521312null1232013-11-252013-11-25nullD:/w2.jpgnullnull23null1232013-11-252013-11-25nullnullnullnull122013-11-2521时32分飞机nullD:/w2.jpgnullnullnull实体类packagecom.test;importjava.io.File;importjava.util.List;importorg.dom4j.Document;importorg.dom4j.Node;importorg.dom4j.io.SAXReader;importcom.xcfh.usermanager.service.UserManagerService;publicclassTestXML3{publicstaticvoidmain(String[]args){//traffic_info other_info stay_infogetImages("stay_info","w2.jpg");}/*publicstaticvoidgetImage(Stringtype,StringimageName){Stringstrxml="D:\\test.xml";StringimagePath="D:/w2.jpg";try{Filefile=newFile(strxml);SAXReaderreader=newSAXReader();Documentdoc=reader.read(file);Elementroot=doc.getRootElement();if(imagePath.substring((imagePath.lastIndexOf("/")1)).equals(imageName)){imageName=imagePath;//Stringtext1="//bookstore[@name='"infoname"']/*[title_id=\'"fName"']";Stringtext="//table[@name='"type"']/*[stay_invoice_local_path='"imageName"']";System.out.println(text);List
node=doc.selectNodes(text);System.out.println(node.get(0).getName());System.out.println(node.get(0).selectSingleNode("stay_invoice_local_path").getText());}}catch(Exceptione){e.printStackTrace();}}*/publicstaticvoidgetImages(Stringtype,StringimageName){Stringstrxml="D:\\test.xml";try{Filefile=newFile(strxml);SAXReaderreader=newSAXReader();Documentdoc=reader.read(file);Listnode=doc.selectNodes("//table[@name='"type"']/*");for(Noden:node){//System.out.println(n.getName());if("stay_info".equals(type)){Stringstay_invoice_local_paths=n.selectSingleNode("stay_invoice_local_path").getText();//System.out.println(stay_invoice_local_paths);if(stay_invoice_local_paths.substring(stay_invoice_local_paths.lastIndexOf("/")1).equals(imageName)){imageName=stay_invoice_local_paths;//System.out.println(imageName"--------------");Stringtext="//table[@name='"type"']/*[stay_invoice_local_path='"imageName"']";Listnode1=doc.selectNodes(text);//System.out.println(node1.get(0).getName()"\t--------------");System.out.println(node.get(0).selectSingleNode("stay_invoice_local_path").getText());}}if("traffic_info".equals(type)){Stringtraffic_invoice_local_paths=n.selectSingleNode("traffic_invoice_local_path").getText();if(traffic_invoice_local_paths.substring(traffic_invoice_local_paths.lastIndexOf("/")1).equals(imageName)){imageName=traffic_invoice_local_paths;Stringtext="//table[@name='"type"']/*[traffic_invoice_local_path='"imageName"']";Listnode1=doc.selectNodes(text);System.out.println(node.get(0).selectSingleNode("traffic_invoice_local_path").getText());}}if("other_info".equals(type)){Stringother_invoice_local_paths=n.selectSingleNode("other_invoice_local_path").getText();if(other_invoice_local_paths.substring(other_invoice_local_paths.lastIndexOf("/")1).equals(imageName)){imageName=other_invoice_local_paths;Stringtext="//table[@name='"type"']/*[other_invoice_local_path='"imageName"']";Listnode1=doc.selectNodes(text);System.out.println(node.get(0).selectSingleNode("other_invoice_local_path").getText());}}} }catch(Exceptione){e.printStackTrace();}}}