锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
銆銆棰勫 銆銆嫻嬭瘯鐜錛? 銆銆AMD姣掗緳1.4G OC 1.5G銆?56M DDR333銆乄indows2000 Server SP4銆丼un JDK 1.4.1+Eclipse 2.1+Resin 2.1.8錛屽湪Debug妯″紡涓嬫祴璇曘? 銆銆XML鏂囦歡鏍煎紡濡備笅錛? 銆銆錛?xml version="1.0" encoding="GB2312"?錛烇紲RESULT錛烇紲VALUE錛? 銆銆錛淣O錛濧1234錛?NO錛? 銆銆錛淎DDR錛炲洓宸濈渷XX鍘縓X闀嘪X璺疿孌礨X鍙鳳紲/ADDR錛烇紲/VALUE錛烇紲VALUE錛? 銆銆錛淣O錛濨1234錛?NO錛? 銆銆錛淎DDR錛炲洓宸濈渷XX甯俋X涔X鏉慩X緇勶紲/ADDR錛烇紲/VALUE錛烇紲/RESULT錛? 銆銆嫻嬭瘯鏂規硶錛? 銆銆閲囩敤JSP绔皟鐢˙ean(鑷充簬涓轟粈涔堥噰鐢↗SP鏉ヨ皟鐢紝璇峰弬鑰冿細http://blog.csdn.net/rosen/archive/2004/10/15/138324.aspx)錛岃姣忎竴縐嶆柟妗堝垎鍒В鏋?0K銆?00K銆?000K銆?0000K鐨刋ML鏂囦歡錛岃綆楀叾娑堣楁椂闂?鍗曚綅:姣)銆? 銆銆JSP鏂囦歡錛? 銆銆錛?@ page contentType="text/html; charset=gb2312" %錛烇紲%@ page import="com.test.*"%錛? 銆銆錛渉tml錛烇紲body錛烇紲%String args[]={""};MyXMLReader.main(args);%錛烇紲/body錛烇紲/html錛? 銆銆嫻嬭瘯 銆銆棣栧厛鍑哄満鐨勬槸DOM(JAXP Crimson瑙f瀽鍣? 銆銆DOM鏄敤涓庡鉤鍙板拰璇█鏃犲叧鐨勬柟寮忚〃紺篨ML鏂囨。鐨勫畼鏂筗3C鏍囧噯銆侱OM鏄互灞傛緇撴瀯緇勭粐鐨勮妭鐐規垨淇℃伅鐗囨柇鐨勯泦鍚堛傝繖涓眰嬈$粨鏋勫厑璁稿紑鍙戜漢鍛樺湪鏍戜腑瀵繪壘鐗瑰畾淇℃伅銆傚垎鏋愯緇撴瀯閫氬父闇瑕佸姞杞芥暣涓枃妗e拰鏋勯犲眰嬈$粨鏋勶紝鐒跺悗鎵嶈兘鍋氫換浣曞伐浣溿傜敱浜庡畠鏄熀浜庝俊鎭眰嬈$殑錛屽洜鑰孌OM琚涓烘槸鍩轟簬鏍戞垨鍩轟簬瀵硅薄鐨勩侱OM浠ュ強騫夸箟鐨勫熀浜庢爲鐨勫鐞嗗叿鏈夊嚑涓紭鐐廣傞鍏堬紝鐢變簬鏍戝湪鍐呭瓨涓槸鎸佷箙鐨勶紝鍥犳鍙互淇敼瀹冧互渚垮簲鐢ㄧ▼搴忚兘瀵規暟鎹拰緇撴瀯浣滃嚭鏇存敼銆傚畠榪樺彲浠ュ湪浠諱綍鏃跺欏湪鏍戜腑涓婁笅瀵艱埅錛岃屼笉鏄儚SAX閭f牱鏄竴嬈℃х殑澶勭悊銆侱OM浣跨敤璧鋒潵涔熻綆鍗曞緱澶氥? 銆銆鍙︿竴鏂歸潰錛屽浜庣壒鍒ぇ鐨勬枃妗o紝瑙f瀽鍜屽姞杞芥暣涓枃妗e彲鑳藉緢鎱笖寰堣楄祫婧愶紝鍥犳浣跨敤鍏朵粬鎵嬫鏉ュ鐞嗚繖鏍風殑鏁版嵁浼氭洿濂姐傝繖浜涘熀浜庝簨浠剁殑妯″瀷錛屾瘮濡係AX銆? 銆銆Bean鏂囦歡錛? 銆銆package com.test; 銆銆import java.io.*;import java.util.*;import org.w3c.dom.*;import javax.xml.parsers.*; 銆銆public class MyXMLReader{ 銆銆public static void main(String arge[]){ 銆銆long lasting =System.currentTimeMillis(); 銆銆try{ 銆銆銆File f=new File("data_10k.xml"); 銆銆銆DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); 銆銆銆DocumentBuilder builder=factory.newDocumentBuilder(); 銆銆銆Document doc = builder.parse(f); 銆銆銆NodeList nl = doc.getElementsByTagName("VALUE"); 銆銆銆for (int i=0;i錛渘l.getLength();i++){ 銆銆銆銆System.out.print("杞︾墝鍙風爜:" + doc.getElementsByTagName("NO").item(i).getFirstChild().getNodeValue()); 銆銆銆銆System.out.println("杞︿富鍦板潃:" + doc.getElementsByTagName("ADDR").item(i).getFirstChild().getNodeValue()); 銆銆} 銆銆}catch(Exception e){ 銆銆銆e.printStackTrace(); 銆銆} 銆銆System.out.println("榪愯鏃墮棿錛?+(System.currentTimeMillis() - lasting)+"姣");}} 銆銆10k娑堣楁椂闂達細265 203 219 172 銆銆100k娑堣楁椂闂達細9172 9016 8891 9000 銆銆1000k娑堣楁椂闂達細691719 675407 708375 739656 銆銆10000k娑堣楁椂闂達細OutOfMemoryError 銆銆鎺ョ潃鏄疭AX 銆銆榪欑澶勭悊鐨勪紭鐐歸潪甯哥被浼間簬嫻佸獟浣撶殑浼樼偣銆傚垎鏋愯兘澶熺珛鍗沖紑濮嬶紝鑰屼笉鏄瓑寰呮墍鏈夌殑鏁版嵁琚鐞嗐傝屼笖錛岀敱浜庡簲鐢ㄧ▼搴忓彧鏄湪璇誨彇鏁版嵁鏃舵鏌ユ暟鎹紝鍥犳涓嶉渶瑕佸皢鏁版嵁瀛樺偍鍦ㄥ唴瀛樹腑銆傝繖瀵逛簬澶у瀷鏂囨。鏉ヨ鏄釜宸ㄥぇ鐨勪紭鐐廣備簨瀹炰笂錛屽簲鐢ㄧ▼搴忕敋鑷充笉蹇呰В鏋愭暣涓枃妗o紱瀹冨彲浠ュ湪鏌愪釜鏉′歡寰楀埌婊¤凍鏃跺仠姝㈣В鏋愩備竴鑸潵璇達紝SAX榪樻瘮瀹冪殑鏇夸唬鑰匘OM蹇澶氥? 銆銆閫夋嫨DOM榪樻槸閫夋嫨SAX錛? 銆銆瀵逛簬闇瑕佽嚜宸辯紪鍐欎唬鐮佹潵澶勭悊XML鏂囨。鐨勫紑鍙戜漢鍛樻潵璇達紝 銆銆閫夋嫨DOM榪樻槸SAX瑙f瀽妯″瀷鏄竴涓潪甯擱噸瑕佺殑璁捐鍐崇瓥銆? 銆銆DOM閲囩敤寤虹珛鏍戝艦緇撴瀯鐨勬柟寮忚闂甔ML鏂囨。錛岃孲AX閲囩敤鐨勪簨浠舵ā鍨嬨? 銆銆DOM瑙f瀽鍣ㄦ妸XML鏂囨。杞寲涓轟竴涓寘鍚叾鍐呭鐨勬爲錛屽茍鍙互瀵規爲榪涜閬嶅巻銆傜敤DOM瑙f瀽妯″瀷鐨勪紭鐐規槸緙栫▼瀹規槗錛屽紑鍙戜漢鍛樺彧闇瑕佽皟鐢ㄥ緩鏍戠殑鎸囦護錛岀劧鍚庡埄鐢╪avigation APIs璁塊棶鎵闇鐨勬爲鑺傜偣鏉ュ畬鎴愪換鍔°傚彲浠ュ緢瀹規槗鐨勬坊鍔犲拰淇敼鏍戜腑鐨勫厓绱犮傜劧鑰岀敱浜庝嬌鐢―OM瑙f瀽鍣ㄧ殑鏃跺欓渶瑕佸鐞嗘暣涓猉ML鏂囨。錛屾墍浠ュ鎬ц兘鍜屽唴瀛樼殑瑕佹眰姣旇緝楂橈紝灝ゅ叾鏄亣鍒板緢澶х殑XML鏂囦歡鐨勬椂鍊欍傜敱浜庡畠鐨勯亶鍘嗚兘鍔涳紝DOM瑙f瀽鍣ㄥ父鐢ㄤ簬XML鏂囨。闇瑕侀綣佺殑鏀瑰彉鐨勬湇鍔′腑銆? 銆銆SAX瑙f瀽鍣ㄩ噰鐢ㄤ簡鍩轟簬浜嬩歡鐨勬ā鍨嬶紝瀹冨湪瑙f瀽XML鏂囨。鐨勬椂鍊欏彲浠ヨЕ鍙戜竴緋誨垪鐨勪簨浠訛紝褰撳彂鐜扮粰瀹氱殑tag鐨勬椂鍊欙紝瀹冨彲浠ユ縺媧諱竴涓洖璋冩柟娉曪紝鍛婅瘔璇ユ柟娉曞埗瀹氱殑鏍囩宸茬粡鎵懼埌銆係AX瀵瑰唴瀛樼殑瑕佹眰閫氬父浼氭瘮杈冧綆錛屽洜涓哄畠璁╁紑鍙戜漢鍛樿嚜宸辨潵鍐沖畾鎵瑕佸鐞嗙殑tag銆傜壒鍒槸褰撳紑鍙戜漢鍛樺彧闇瑕佸鐞嗘枃妗d腑鎵鍖呭惈鐨勯儴鍒嗘暟鎹椂錛孲AX榪欑鎵╁睍鑳藉姏寰楀埌浜嗘洿濂界殑浣撶幇銆備絾鐢⊿AX瑙f瀽鍣ㄧ殑鏃跺欑紪鐮佸伐浣滀細姣旇緝鍥伴毦錛岃屼笖寰堥毦鍚屾椂璁塊棶鍚屼竴涓枃妗d腑鐨勫澶勪笉鍚屾暟鎹? 銆銆Bean鏂囦歡錛? 銆銆package com.test;import org.xml.sax.*;import org.xml.sax.helpers.*;import javax.xml.parsers.*; 銆銆public class MyXMLReader extends DefaultHandler { 銆銆java.util.Stack tags = new java.util.Stack(); 銆銆public MyXMLReader() { 銆銆super();} 銆銆public static void main(String args[]) { 銆銆long lasting = System.currentTimeMillis(); 銆銆try { 銆銆銆SAXParserFactory sf = SAXParserFactory.newInstance(); 銆銆銆SAXParser sp = sf.newSAXParser(); 銆銆銆MyXMLReader reader = new MyXMLReader(); 銆銆銆sp.parse(new InputSource("data_10k.xml"), reader); 銆銆} catch (Exception e) { 銆銆銆e.printStackTrace(); 銆銆} 銆銆System.out.println("榪愯鏃墮棿錛? + (System.currentTimeMillis() - lasting) + "姣");} 銆銆public void characters(char ch[], int start, int length) throws SAXException { 銆銆String tag = (String) tags.peek(); 銆銆if (tag.equals("NO")) { 銆銆銆System.out.print("杞︾墝鍙風爜錛? + new String(ch, start, length));}if (tag.equals("ADDR")) { 銆銆System.out.println("鍦板潃:" + new String(ch, start, length));}} 銆銆public void startElement(String uri,String localName,String qName,Attributes attrs) { 銆銆tags.push(qName);}} 銆銆10k娑堣楁椂闂達細110 47 109 78 銆銆100k娑堣楁椂闂達細344 406 375 422 銆銆1000k娑堣楁椂闂達細3234 3281 3688 3312 銆銆10000k娑堣楁椂闂達細32578 34313 31797 31890 30328 銆銆鐒跺悗鏄疛DOM http://www.jdom.org/ 銆銆JDOM鐨勭洰鐨勬槸鎴愪負Java鐗瑰畾鏂囨。妯″瀷錛屽畠綆鍖栦笌XML鐨勪氦浜掑茍涓旀瘮浣跨敤DOM瀹炵幇鏇村揩銆傜敱浜庢槸絎竴涓狫ava鐗瑰畾妯″瀷錛孞DOM涓鐩村緱鍒板ぇ鍔涙帹騫垮拰淇冭繘銆傛鍦ㄨ冭檻閫氳繃鈥淛ava瑙勮寖璇鋒眰JSR-102鈥濆皢瀹冩渶緇堢敤浣溾淛ava鏍囧噯鎵╁睍鈥濄備粠2000騫村垵灝卞凡緇忓紑濮嬩簡JDOM寮鍙戙? 銆銆JDOM涓嶥OM涓昏鏈変袱鏂歸潰涓嶅悓銆傞鍏堬紝JDOM浠呬嬌鐢ㄥ叿浣撶被鑰屼笉浣跨敤鎺ュ彛銆傝繖鍦ㄦ煇浜涙柟闈㈢畝鍖栦簡API錛屼絾鏄篃闄愬埗浜嗙伒媧繪с傜浜岋紝API澶ч噺浣跨敤浜咰ollections綾伙紝綆鍖栦簡閭d簺宸茬粡鐔熸倝榪欎簺綾葷殑Java寮鍙戣呯殑浣跨敤銆? 銆銆JDOM鏂囨。澹版槑鍏剁洰鐨勬槸鈥滀嬌鐢?0%(鎴栨洿灝?鐨勭簿鍔涜В鍐?0%(鎴栨洿澶?Java/XML闂鈥?鏍規嵁瀛︿範鏇茬嚎鍋囧畾涓?0%)銆侸DOM瀵逛簬澶у鏁癑ava/XML搴旂敤紼嬪簭鏉ヨ褰撶劧鏄湁鐢ㄧ殑錛屽茍涓斿ぇ澶氭暟寮鍙戣呭彂鐜癆PI姣擠OM瀹規槗鐞嗚В寰楀銆侸DOM榪樺寘鎷紼嬪簭琛屼負鐨勭浉褰撳箍娉涙鏌ヤ互闃叉鐢ㄦ埛鍋氫換浣曞湪XML涓棤鎰忎箟鐨勪簨銆傜劧鑰岋紝瀹冧粛闇瑕佹偍鍏呭垎鐞嗚ВXML浠ヤ究鍋氫竴浜涜秴鍑哄熀鏈殑宸ヤ綔(鎴栬呯敋鑷崇悊瑙f煇浜涙儏鍐典笅鐨勯敊璇?銆傝繖涔熻鏄瘮瀛︿範DOM鎴朖DOM鎺ュ彛閮芥洿鏈夋剰涔夌殑宸ヤ綔銆? 銆銆JDOM鑷韓涓嶅寘鍚В鏋愬櫒銆傚畠閫氬父浣跨敤SAX2瑙f瀽鍣ㄦ潵瑙f瀽鍜岄獙璇佽緭鍏ML鏂囨。(灝界瀹冭繕鍙互灝嗕互鍓嶆瀯閫犵殑DOM琛ㄧず浣滀負杈撳叆)銆傚畠鍖呭惈涓浜涜漿鎹㈠櫒浠ュ皢JDOM琛ㄧず杈撳嚭鎴怱AX2浜嬩歡嫻併丏OM妯″瀷鎴朮ML鏂囨湰鏂囨。銆侸DOM鏄湪Apache璁稿彲璇佸彉浣撲笅鍙戝竷鐨勫紑鏀炬簮鐮併? 銆銆Bean鏂囦歡錛? 銆銆package com.test; 銆銆import java.io.*;import java.util.*;import org.jdom.*;import org.jdom.input.*; 銆銆public class MyXMLReader { 銆銆public static void main(String arge[]) { 銆銆long lasting = System.currentTimeMillis(); 銆銆try { 銆銆銆SAXBuilder builder = new SAXBuilder(); 銆銆銆Document doc = builder.build(new File("data_10k.xml")); 銆銆銆Element foo = doc.getRootElement(); 銆銆銆List allChildren = foo.getChildren(); 銆銆銆for(int i=0;i錛渁llChildren.size();i++) { 銆銆銆銆System.out.print("杞︾墝鍙風爜:" + ((Element)allChildren.get(i)).getChild("NO").getText()); 銆銆銆銆System.out.println("杞︿富鍦板潃:" + ((Element)allChildren.get(i)).getChild("ADDR").getText()); 銆銆銆} 銆銆} catch (Exception e) { 銆銆銆e.printStackTrace(); 銆銆} 銆銆System.out.println("榪愯鏃墮棿錛? + (System.currentTimeMillis() - lasting) + "姣");}} 銆銆10k娑堣楁椂闂達細125 62 187 94 銆銆100k娑堣楁椂闂達細704 625 640 766 銆銆1000k娑堣楁椂闂達細27984 30750 27859 30656 銆銆10000k娑堣楁椂闂達細OutOfMemoryError 銆銆鏈鍚庢槸DOM4J http://dom4j.sourceforge.net/ 銆銆铏界劧DOM4J浠h〃浜嗗畬鍏ㄧ嫭绔嬬殑寮鍙戠粨鏋滐紝浣嗘渶鍒濓紝瀹冩槸JDOM鐨勪竴縐嶆櫤鑳藉垎鏀傚畠鍚堝茍浜嗚澶氳秴鍑哄熀鏈琗ML鏂囨。琛ㄧず鐨勫姛鑳斤紝鍖呮嫭闆嗘垚鐨刋Path鏀寔銆乆ML Schema鏀寔浠ュ強鐢ㄤ簬澶ф枃妗f垨嫻佸寲鏂囨。鐨勫熀浜庝簨浠剁殑澶勭悊銆傚畠榪樻彁渚涗簡鏋勫緩鏂囨。琛ㄧず鐨勯夐」錛屽畠閫氳繃DOM4J API鍜屾爣鍑咲OM鎺ュ彛鍏鋒湁騫惰璁塊棶鍔熻兘銆備粠2000涓嬪崐騫村紑濮嬶紝瀹冨氨涓鐩村浜庡紑鍙戜箣涓? 銆銆涓烘敮鎸佹墍鏈夎繖浜涘姛鑳斤紝DOM4J浣跨敤鎺ュ彛鍜屾娊璞″熀鏈被鏂規硶銆侱OM4J澶ч噺浣跨敤浜咥PI涓殑Collections綾伙紝浣嗘槸鍦ㄨ澶氭儏鍐典笅錛屽畠榪樻彁渚涗竴浜涙浛浠f柟娉曚互鍏佽鏇村ソ鐨勬ц兘鎴栨洿鐩存帴鐨勭紪鐮佹柟娉曘傜洿鎺ュソ澶勬槸錛岃櫧鐒禗OM4J浠樺嚭浜嗘洿澶嶆潅鐨凙PI鐨勪唬浠鳳紝浣嗘槸瀹冩彁渚涗簡姣擩DOM澶у緱澶氱殑鐏墊椿鎬с? 銆銆鍦ㄦ坊鍔犵伒媧繪с乆Path闆嗘垚鍜屽澶ф枃妗e鐞嗙殑鐩爣鏃訛紝DOM4J鐨勭洰鏍囦笌JDOM鏄竴鏍風殑錛氶拡瀵笿ava寮鍙戣呯殑鏄撶敤鎬у拰鐩磋鎿嶄綔銆傚畠榪樿嚧鍔涗簬鎴愪負姣擩DOM鏇村畬鏁寸殑瑙e喅鏂規錛屽疄鐜板湪鏈川涓婂鐞嗘墍鏈塉ava/XML闂鐨勭洰鏍囥傚湪瀹屾垚璇ョ洰鏍囨椂錛屽畠姣擩DOM鏇村皯寮鴻皟闃叉涓嶆紜殑搴旂敤紼嬪簭琛屼負銆? 銆銆DOM4J鏄竴涓潪甯擱潪甯鎬紭縐鐨凧ava XML API錛屽叿鏈夋ц兘浼樺紓銆佸姛鑳藉己澶у拰鏋佺鏄撶敤浣跨敤鐨勭壒鐐癸紝鍚屾椂瀹冧篃鏄竴涓紑鏀炬簮浠g爜鐨勮蔣浠躲傚浠婁綘鍙互鐪嬪埌瓚婃潵瓚婂鐨凧ava杞歡閮藉湪浣跨敤DOM4J鏉ヨ鍐橷ML錛岀壒鍒煎緱涓鎻愮殑鏄繛Sun鐨凧AXM涔熷湪鐢―OM4J銆? 銆銆Bean鏂囦歡錛? 銆銆package com.test; 銆銆import java.io.*;import java.util.*;import org.dom4j.*;import org.dom4j.io.*; 銆銆public class MyXMLReader { 銆銆public static void main(String arge[]) { 銆銆long lasting = System.currentTimeMillis(); 銆銆try { 銆銆銆File f = new File("data_10k.xml"); 銆銆銆SAXReader reader = new SAXReader(); 銆銆銆Document doc = reader.read(f); 銆銆銆Element root = doc.getRootElement(); 銆銆銆Element foo; 銆銆銆for (Iterator i = root.elementIterator("VALUE"); i.hasNext();) { 銆銆銆銆foo = (Element) i.next(); 銆銆銆銆System.out.print("杞︾墝鍙風爜:" + foo.elementText("NO")); 銆銆銆銆System.out.println("杞︿富鍦板潃:" + foo.elementText("ADDR")); 銆銆銆} 銆銆} catch (Exception e) { 銆銆銆e.printStackTrace(); 銆銆} 銆銆System.out.println("榪愯鏃墮棿錛? + (System.currentTimeMillis() - lasting) + "姣");}} 銆銆10k娑堣楁椂闂達細109 78 109 31 銆銆100k娑堣楁椂闂達細297 359 172 312 銆銆1000k娑堣楁椂闂達細2281 2359 2344 2469 銆銆10000k娑堣楁椂闂達細20938 19922 20031 21078 銆銆JDOM鍜孌OM鍦ㄦц兘嫻嬭瘯鏃惰〃鐜頒笉浣籌紝鍦ㄦ祴璇?0M鏂囨。鏃跺唴瀛樻孩鍑恒傚湪灝忔枃妗f儏鍐典笅榪樺煎緱鑰冭檻浣跨敤DOM鍜孞DOM銆傝櫧鐒禞DOM鐨勫紑鍙戣呭凡緇忚鏄庝粬浠湡鏈涘湪姝e紡鍙戣鐗堝墠涓撴敞鎬ц兘闂錛屼絾鏄粠鎬ц兘瑙傜偣鏉ョ湅錛屽畠紜疄娌℃湁鍊煎緱鎺ㄨ崘涔嬪銆傚彟澶栵紝DOM浠嶆槸涓涓潪甯稿ソ鐨勯夋嫨銆侱OM瀹炵幇騫挎硾搴旂敤浜庡縐嶇紪紼嬭璦銆傚畠榪樻槸璁稿鍏跺畠涓嶺ML鐩稿叧鐨勬爣鍑嗙殑鍩虹錛屽洜涓哄畠姝e紡鑾峰緱W3C鎺ㄨ崘(涓庡熀浜庨潪鏍囧噯鐨凧ava妯″瀷鐩稿)錛屾墍浠ュ湪鏌愪簺綾誨瀷鐨勯」鐩腑鍙兘涔熼渶瑕佸畠(濡傚湪JavaScript涓嬌鐢―OM)銆? 銆銆SAX琛ㄧ幇杈冨ソ錛岃繖瑕佷緷璧栦簬瀹冪壒瀹氱殑瑙f瀽鏂瑰紡銆備竴涓猄AX媯嫻嬪嵆灝嗗埌鏉ョ殑XML嫻侊紝浣嗗茍娌℃湁杞藉叆鍒板唴瀛?褰撶劧褰揦ML嫻佽璇誨叆鏃訛紝浼氭湁閮ㄥ垎鏂囨。鏆傛椂闅愯棌鍦ㄥ唴瀛樹腑)銆? 銆銆鏃犵枒錛孌OM4J鏄繖鍦烘祴璇曠殑鑾瘋儨鑰咃紝鐩墠璁稿寮婧愰」鐩腑澶ч噺閲囩敤DOM4J錛屼緥濡傚ぇ鍚嶉紟榧庣殑Hibernate涔熺敤DOM4J鏉ヨ鍙朮ML閰嶇疆鏂囦歡銆傚鏋滀笉鑰冭檻鍙Щ妞嶆э紝閭e氨閲囩敤DOM4J鍚э紒(鏂?rosen錛?/td> |
<?xml version="1.0" encoding="UTF-8"?>
<Customers>
聽聽聽聽<customer>
聽聽聽聽聽聽聽聽聽聽聽聽<id>1</id>
聽聽聽聽聽聽聽聽聽聽聽聽<gender>female</gender>
聽聽聽聽聽聽聽聽聽聽聽聽<firstname>Jessica</firstname>
聽聽聽聽聽聽聽聽聽聽聽聽<lastname>Lim</lastname>
聽聽聽聽聽聽聽聽聽聽聽聽<phoneNumber>1234567</phoneNumber>
聽聽聽聽聽聽聽聽聽聽聽聽<address>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<primaryAddress>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<postalCode>350106</postalCode>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<addressLine1>#25-1</addressLine1>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<addressLine2>SHINSAYAMA 2-CHOME</addressLine2>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</primaryAddress>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<billingAddress>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<receiver>Ms Danielle</receiver>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<postalCode>350107</postalCode>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<addressLine1>#167</addressLine1>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<addressLine2>NORTH TOWER HARBOUR CITY</addressLine2>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</billingAddress>
聽聽聽聽聽聽聽聽聽聽聽聽</address>
聽聽聽聽</customer>
聽聽聽聽<customer>
聽聽聽聽聽聽聽聽聽聽聽聽<id>2</id>
聽聽聽聽聽聽聽聽聽聽聽聽<gender>male</gender>
聽聽聽聽聽聽聽聽聽聽聽聽<firstname>David</firstname>
聽聽聽聽聽聽聽聽聽聽聽聽<lastname>Bill</lastname>
聽聽聽聽聽聽聽聽聽聽聽聽<phoneNumber>808182</phoneNumber>
聽聽聽聽聽聽聽聽聽聽聽聽<address>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<primaryAddress>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<postalCode>319087</postalCode>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<addressLine1>1033 WS St.</addressLine1>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<addressLine2>Tima Road</addressLine2>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</primaryAddress>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<billingAddress>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<receiver>Mr William</receiver>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<postalCode>672993</postalCode>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<addressLine1>1033 WS St.</addressLine1>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<addressLine2>Tima Road</addressLine2>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</billingAddress>
聽聽聽聽聽聽聽聽聽聽聽聽</address>
聽聽聽聽</customer>
</Customers>
<xb:config xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config">
聽聽<xb:namespace>
聽聽聽聽<xb:package>sample.xmlbean</xb:package>
聽聽</xb:namespace>
</xb:config>
聽聽聽聽聽聽 <?xml version="1.0" encoding="UTF-8"?>
聽聽聽聽聽聽 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽elementFormDefault="qualified">
聽聽聽聽聽聽聽聽 <xs:element name="Customers">
聽聽聽聽聽聽聽聽聽聽 <xs:complexType>
聽聽聽聽聽聽聽聽聽聽聽聽 <xs:sequence>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <xs:element maxOccurs="unbounded" name="customer"
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 type="customerType"/>
聽聽聽聽聽聽聽聽聽聽聽聽 </xs:sequence>
聽聽聽聽聽聽聽聽聽聽 </xs:complexType>
聽聽聽聽聽聽聽聽 </xs:element>
聽聽聽聽聽聽 <xs:complexType name="customerType">
聽聽聽聽聽聽聽聽聽聽聽聽 <xs:sequence>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <xs:element name="id" type="xs:int"/>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <xs:element name="gender" type="xs:string"/>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <xs:element name="firstname" type="xs:string"/>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <xs:element name="lastname" type="xs:string"/>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <xs:element name="phoneNumber" type="xs:string"/>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <xs:element name="address" type="addressType"/>
聽聽聽聽聽聽聽聽聽聽聽聽 </xs:sequence>
聽聽聽聽聽聽 </xs:complexType>
聽聽聽聽聽聽聽聽 <xs:complexType name="addressType">
聽聽聽聽聽聽聽聽聽聽聽聽 <xs:sequence>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <xs:element name="primaryAddress" type="primaryAddressType"/>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <xs:element name="billingAddress" type="billingAddressType"/>
聽聽聽聽聽聽聽聽聽聽聽聽 </xs:sequence>
聽聽聽聽聽聽聽聽 </xs:complexType>
聽聽聽聽聽聽聽聽 <xs:complexType name="primaryAddressType">
聽聽聽聽聽聽聽聽聽聽聽聽 <xs:sequence>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <xs:element name="postalCode" type="xs:string"/>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <xs:element name="addressLine1" type="xs:string"/>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <xs:element name="addressLine2" type="xs:string"/>
聽聽聽聽聽聽聽聽聽聽聽聽 </xs:sequence>
聽聽聽聽聽聽聽聽 </xs:complexType>
聽聽聽聽聽聽聽聽 <xs:complexType name="billingAddressType">
聽聽聽聽聽聽聽聽聽聽聽聽 <xs:sequence>
聽聽聽聽聽聽 聽聽聽聽聽聽聽聽聽聽聽聽<xs:element name="receiver" type="xs:string"/>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <xs:element name="postalCode" type="xs:string"/>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <xs:element name="addressLine1" type="xs:string"/>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <xs:element name="addressLine2" type="xs:string"/>
聽聽聽聽聽聽聽聽聽聽聽聽 </xs:sequence>
聽聽聽聽聽聽聽聽 </xs:complexType>
聽聽聽聽聽聽 </xs:schema>
聽聽聽聽聽聽
聽聽聽聽聽聽 scomp [options] [dirs]* [schemaFile.xsd]* [service.wsdl]* [config.xsdconfig]*
聽聽聽聽聽聽
聽聽聽聽聽聽 scomp -src build\src聽聽-out build\customerXmlBean.jar schema\customer.xsd
聽聽聽聽聽聽聽聽聽聽聽聽 -compiler C:\jdk142_04\bin\javac customer.xsdconfig
聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽CustomersDocument.java聽聽聽聽-- 鏁翠釜XML鏂囨。鐨凧ava Class鏄犲皠
聽聽聽聽聽聽 CustomerType.java聽聽聽聽聽聽聽聽聽聽聽聽聽聽-- 鑺傜偣sustomer鐨勬槧灝?br />聽聽聽聽聽聽 AddressType.java聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 -- 鑺傜偣address鐨勬槧灝?br />聽聽聽聽聽聽 BillingAddressType.java聽聽聽聽聽聽聽聽-- 鑺傜偣billingAddress鐨勬槧灝?br />聽聽聽聽聽聽 PrimaryAddressType.java聽聽聽聽聽聽-- 鑺傜偣primaryAddress鐨勬槧灝?br />聽聽聽聽
聽聽聽聽package com.sample.reader;
聽聽聽聽import java.io.File;
聽聽聽聽
聽聽聽聽import sample.xmlbean.*;
聽聽聽聽import org.apache.commons.beanutils.BeanUtils;
聽聽聽聽import org.apache.xmlbeans.XmlOptions;
聽聽聽聽public class CustomerXMLBean {
聽聽聽聽private String filename = null;
聽聽聽聽
聽聽聽聽public CustomerXMLBean(String filename) {
聽聽聽聽聽聽聽聽聽聽聽聽super();
聽聽聽聽聽聽聽聽聽聽聽聽this.filename = filename;
聽聽聽聽}
聽聽聽聽public void customerReader() {
聽聽聽聽聽聽聽聽聽聽聽聽try {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽File xmlFile = new File(filename);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽CustomersDocument doc = CustomersDocument.Factory.parse(xmlFile);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽CustomerType[] customers = doc.getCustomers().getCustomerArray();
聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽for (int i = 0; i < customers.length; i++) {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽CustomerType customer = customers[i];
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽println("Customer#" + i);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽println("Customer ID:" + customer.getId());
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽println("First name:" + customer.getFirstname());
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽println("Last name:" + customer.getLastname());
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽println("Gender:" + customer.getGender());
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽println("PhoneNumber:" + customer.getPhoneNumber());
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽// Primary address
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽PrimaryAddressType primaryAddress = customer.getAddress().getPrimaryAddress();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽println("PrimaryAddress:");
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽println("PostalCode:" + primaryAddress.getPostalCode());
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽println("AddressLine1:" + primaryAddress.getAddressLine1());
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽println("AddressLine2:" + primaryAddress.getAddressLine2());
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽// Billing address
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽BillingAddressType billingAddress = customer.getAddress().getBillingAddress();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽println("BillingAddress:");
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽println("Receiver:" + billingAddress.getReceiver());
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽println("PostalCode:" + billingAddress.getPostalCode());
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽println("AddressLine1:" + billingAddress.getAddressLine1());
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽println("AddressLine2:" + billingAddress.getAddressLine2());
聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽} catch (Exception ex) {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽ex.printStackTrace();
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽}
聽聽聽聽private void println(String str) {
聽聽聽聽聽聽聽聽聽聽System.out.println(str);
聽聽聽聽}
聽聽 public static void main(String[] args) {
聽聽聽聽聽聽String filename = "F://JavaTest//Eclipse//XMLBean//xml//customers.xml";
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽 CustomerXMLBean customerXMLBean = new CustomerXMLBean(filename);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 customerXMLBean.customerReader();
聽聽聽聽}
聽聽聽聽}
聽聽聽聽
聽聽聽聽聽聽 Customer#0
聽聽聽聽聽聽 Customer ID:1
聽聽聽聽聽聽 First name:Jessica
聽聽聽聽聽聽 Last name:Lim
聽聽聽聽聽聽 Gender:female
聽聽聽聽聽聽 PhoneNumber:1234567
聽聽聽聽聽聽 PrimaryAddress:
聽聽聽聽聽聽 PostalCode:350106
聽聽聽聽聽聽 AddressLine1:#25-1
聽聽聽聽聽聽 AddressLine2:SHINSAYAMA 2-CHOME
聽聽聽聽聽聽 BillingAddress:
聽聽聽聽聽聽 Receiver:Ms Danielle
聽聽聽聽聽聽 PostalCode:350107
聽聽聽聽聽聽 AddressLine1:#167
聽聽聽聽聽聽 AddressLine2:NORTH TOWER HARBOUR CITY
聽聽聽聽聽聽 Customer#1
聽聽聽聽聽聽 Customer ID:2
聽聽聽聽聽聽 First name:David
聽聽聽聽聽聽 Last name:Bill
聽聽聽聽聽聽 Gender:male
聽聽聽聽聽聽 PhoneNumber:808182
聽聽聽聽聽聽 PrimaryAddress:
聽聽聽聽聽聽 PostalCode:319087
聽聽聽聽聽聽 AddressLine1:1033 WS St.
聽聽聽聽聽聽 AddressLine2:Tima Road
聽聽聽聽聽聽 BillingAddress:
聽聽聽聽聽聽 Receiver:Mr William
聽聽聽聽聽聽 PostalCode:672993
聽聽聽聽聽聽 AddressLine1:1033 WS St.
聽聽聽聽聽聽 AddressLine2:Tima Road
聽聽聽聽
聽聽聽聽public void createCustomer() {
聽聽聽聽try {
聽聽聽聽聽聽聽聽// Create Document
聽聽聽聽聽聽聽聽CustomersDocument doc = CustomersDocument.Factory.newInstance();
聽聽聽聽聽聽聽聽// Add new customer
聽聽聽聽聽聽聽聽CustomerType customer = doc.addNewCustomers().addNewCustomer();
聽聽聽聽聽聽聽聽// set customer info
聽聽聽聽聽聽聽聽customer.setId(3);
聽聽聽聽聽聽聽聽customer.setFirstname("Jessica");
聽聽聽聽聽聽聽聽customer.setLastname("Lim");
聽聽聽聽聽聽聽聽customer.setGender("female");
聽聽聽聽聽聽聽聽customer.setPhoneNumber("1234567");
聽聽聽聽聽聽聽聽// Add new address
聽聽聽聽聽聽聽聽AddressType address = customer.addNewAddress();
聽聽聽聽聽聽聽聽// Add new PrimaryAddress
聽聽聽聽聽聽聽聽PrimaryAddressType primaryAddress = address.addNewPrimaryAddress();
聽聽聽聽聽聽聽聽primaryAddress.setPostalCode("350106");
聽聽聽聽聽聽聽聽primaryAddress.setAddressLine1("#25-1");
聽聽聽聽聽聽聽聽primaryAddress.setAddressLine2("SHINSAYAMA 2-CHOME");
聽聽聽聽聽聽聽聽// Add new BillingAddress
聽聽聽聽聽聽聽聽BillingAddressType billingAddress = address.addNewBillingAddress();
聽聽聽聽聽聽聽聽billingAddress.setReceiver("Ms Danielle");
聽聽聽聽聽聽聽聽billingAddress.setPostalCode("350107");
聽聽聽聽聽聽聽聽billingAddress.setAddressLine1("#167");
聽聽聽聽聽聽聽聽billingAddress.setAddressLine2("NORTH TOWER HARBOUR CITY");
聽聽聽聽聽聽聽聽File xmlFile = new File(filename);
聽聽聽聽聽聽聽聽doc.save(xmlFile);
聽聽聽聽聽聽聽聽} catch (Exception ex) {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽ex.printStackTrace();
聽聽聽聽聽聽聽聽}
聽聽}
聽聽聽聽
聽聽聽聽public static void main(String[] args) {
聽聽聽聽String filename = "F://JavaTest//Eclipse//XMLBean//xml//customers_new.xml";
聽聽聽聽聽聽聽聽CustomerXMLBean customerXMLBean = new CustomerXMLBean(filename);
聽聽聽聽聽聽聽聽customerXMLBean.createCustomer();
聽聽聽聽}
聽聽聽聽
聽聽聽聽<?xml version="1.0" encoding="UTF-8"?>
聽聽聽聽<Customers>
聽聽聽聽<customer>
聽聽聽聽聽聽聽聽聽聽聽聽<id>3</id>
聽聽聽聽聽聽聽聽聽聽聽聽<gender>female</gender>
聽聽聽聽聽聽聽聽聽聽聽聽<firstname>Jessica</firstname>
聽聽聽聽聽聽聽聽聽聽聽聽<lastname>Lim</lastname>
聽聽聽聽聽聽聽聽聽聽聽聽<phoneNumber>1234567</phoneNumber>
聽聽聽聽聽聽聽聽聽聽聽聽<address>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<primaryAddress>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <postalCode>350106</postalCode>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <addressLine1>#25-1</addressLine1>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <addressLine2>SHINSAYAMA 2-CHOME</addressLine2>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</primaryAddress>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<billingAddress>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<receiver>Ms Danielle</receiver>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<postalCode>350107</postalCode>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <addressLine1>#167</addressLine1>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <addressLine2>NORTH TOWER HARBOUR CITY</addressLine2>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</billingAddress>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</address>
聽聽聽聽聽聽聽聽聽聽聽聽</customer>
聽聽聽聽</Customers>
聽聽聽聽
聽聽聽聽聽聽public void updateCustomer(int id,String lastname) {
聽聽聽聽聽聽聽聽 try {
聽聽聽聽聽聽聽聽File xmlFile = new File(filename);
聽聽聽聽聽聽聽聽CustomersDocument doc = CustomersDocument.Factory.parse(xmlFile);
聽聽聽聽聽聽聽聽CustomerType[] customers = doc.getCustomers().getCustomerArray();
聽聽聽聽聽聽
聽聽聽聽聽聽聽聽for (int i = 0; i < customers.length; i++) {
聽聽聽聽聽聽聽聽聽聽 CustomerType customer = customers[i];
聽聽聽聽聽聽聽聽聽聽if(customer.getId()==id){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽customer.setLastname(lastname);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽doc.save(xmlFile);
聽聽聽聽聽聽聽聽 } catch (Exception ex) {
聽聽聽聽聽聽聽聽聽聽ex.printStackTrace();
聽聽聽聽聽聽聽聽 }
聽聽 聽聽聽聽聽聽聽聽}
聽聽聽聽
聽聽聽聽public static void main(String[] args) {
聽聽聽聽 String filename = "F://JavaTest//Eclipse//XMLBean//xml//customers_new.xml";
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽CustomerXMLBean customerXMLBean = new CustomerXMLBean(filename);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽customerXMLBean.updateCustomer(3,"last");
聽聽聽聽}
聽聽聽聽
聽聽聽聽public void deleteCustomer(int id) {
聽聽聽聽 try {
聽聽聽聽聽聽File xmlFile = new File(filename);
聽聽聽聽 CustomersDocument doc = CustomersDocument.Factory.parse(xmlFile);
聽聽聽聽CustomerType[] customers = doc.getCustomers().getCustomerArray();
聽聽 for (int i = 0; i < customers.length; i++) {
聽聽聽聽聽聽聽聽CustomerType customer = customers[i];
聽聽聽聽聽聽聽聽if(customer.getId()==id){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽customer.setNil() ;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽 }
聽聽 doc.save(xmlFile);
聽聽 } catch (Exception ex) {
聽聽聽聽聽聽聽聽ex.printStackTrace();
聽聽聽聽聽聽聽聽}
聽聽 }
聽聽聽聽public static void main(String[] args) {
聽聽聽聽String filename = "F://JavaTest//Eclipse//XMLBean//xml//customers_new.xml";
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽CustomerXMLBean customerXMLBean = new CustomerXMLBean(filename);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽customerXMLBean.deleteCustomer(3);
聽聽聽聽}