70 likes | 210 Vues
2003/08/05. <?xml version="1.0" encoding="big5"?> <marketplace> <market> <name>guitar</name> <buyer> <filename>625105517buyer.xml</filename> </buyer> <seller> <filename>626214333seller.xml</filename> </seller> </market> </marketplace>.
E N D
<?xml version="1.0" encoding="big5"?> <marketplace> <market> <name>guitar</name> <buyer> <filename>625105517buyer.xml</filename> </buyer> <seller> <filename>626214333seller.xml</filename> </seller> </market> </marketplace> • how to add a new filename here? • how to add a new filename here? 改進insert
while(market.hasNext()){ • Element marketname=(Element)market.next(); • Iterator marketIterator=marketname.elementIterator("name"); • Element market_elem=(Element)marketIterator.next(); • Iterator buyerIterator=marketname.elementIterator("buyer"); • Element buyerfile=(Element)buyerIterator.next(); • if(market_elem.getText().equals(ProductName)){ • out.println("the same Product is =" +ProductName); • buyerfile.addElement("filename").addText(filename); • break; • }//end if • }// end while
All.xml <?xml version="1.0" encoding="big5"?> <marketplace> <market> <name>pant</name> <buyer> <filename>722035buyer.xml</filename> <filename>721235010buyer.xml</filename> </buyer> <seller> <filename>626232920seller.xml</filename> <filename>722101050seller.xml</filename> <filename>722101029seller.xml</filename> </seller> </market> <market> <name>guitar</name> <buyer> <filename>625105517buyer.xml</filename> <filename>715134725buyer.xml</filename> </buyer> <seller> <filename>626214333seller.xml</filename> <filename>72323042seller.xml </filename> </seller> </market> </marketplace> <?xml version="1.0" encoding="big5"?> <marketplace> <market> <name>pant</name> <buyer> <filename>722035buyer.xml</filename> </buyer> <seller> <filename>626232920seller.xml</filename> </seller> </market> <market> <name>guitar</name> <buyer> <filename>625105517buyer.xml</filename> </buyer> <seller> <filename>626214333seller.xml</filename> </seller> </market> </marketplace>
Facilitator.jsp while(market.hasNext()){ Element marketname=(Element)market.next(); Iterator marketIterator=marketname.elementIterator("name"); Element market_elem=(Element)marketIterator.next(); String market_dir=market_elem.getText(); //取得market的名稱 out.println("marketname = "+market_dir+" ; "); Iterator buyerIterator=marketname.elementIterator("buyer"); Element buyer_elem=(Element)buyerIterator.next(); Iterator buyerfileIterator=buyer_elem.elementIterator("filename"); //取得market/buyer/filename的名稱 Iterator sellerIterator=marketname.elementIterator("seller"); Element seller_elem=(Element)sellerIterator.next(); Iterator sellerfileIterator=seller_elem.elementIterator("filename"); while(buyerfileIterator.hasNext()&&sellerfileIterator.hasNext()){ //當buye跟seller皆有filename的元素時 Element buyerfile_elem=(Element)buyerfileIterator.next(); //進入while迴圈 String buyerfile=buyerfile_elem.getText(); Element sellerfile_elem=(Element)sellerfileIterator.next(); String sellerfile=sellerfile_elem.getText();