推薦:淺談XML的簡易教程文檔格式的排錯 我媽媽_的清單中有數(shù)十條菜譜,甚至數(shù)百條。如果產(chǎn)生一個致命錯誤,排錯將非常困難 - 你將一行一行地尋找丟失的標記符。如果使用幾層嵌套,發(fā)現(xiàn)錯誤將很困難。但是可以找到很好
六、利用XMLBean寫XML文件
利用XMLBean創(chuàng)建一個XML文檔也是一件輕而易舉的事.我們再增加一個Method,
請看一下的Java Class:
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(); }
}
|
修改main method.
public static void main(String[] args) { String filename = "F://JavaTest//Eclipse//XMLBean//xml//customers_new.xml"; CustomerXMLBean customerXMLBean = new CustomerXMLBean(filename); customerXMLBean.createCustomer(); }
|
分享:解析XML輕松學(xué)習(xí)手冊(3)XML的術(shù)語第三章 XML的術(shù)語提綱: 導(dǎo)言 一.XML文檔的有關(guān)術(shù)語 二.DTD的有關(guān)術(shù)語 導(dǎo)言 初學(xué)XML最令人頭疼的就是有一大堆新的術(shù)語概念要理解。由于XML本身也是一個嶄新的技術(shù),正在不斷發(fā)展和變化,各組織