Электронный магазин на Java и XML




Класс Order - часть 4


Листинг 5.8. Метод writeXML (Order.java)

public void writeXML( Writer writer ) {

try {

writer.write( "<?xml version='1.0' ?>" );

writer.write( "<!DOCTYPE order SYSTEM '.."

+ File.separator + "order.dtd'>" );

writer.write( "<order id='" + id + "' " );

writer.write( "date='" + date + "'>" );

Enumeration enum = items.elements();

while( enum.hasMoreElements() ) {

CartItem item = (CartItem)enum.nextElement();

writer.write( "<item id='" + item.getId() + "' " );

writer.write( "quantity='" + item.getNumberOrdered() + "' ");

writer.write( "price='" + item.getPrice() + "'>" );

writer.write( item.getName() + "</item>" );

}

writer.write( "<customer_info>\n<first_name>" +

customerInfo.getFirstName() + "</first_name>" +

"\n<last_name>" + customerInfo.getLastName() + "</last_name>" +

"\n<address1>" + customerInfo.getAddress1() + "</address1>" +

"\n<address2>" + customerInfo.getAddress2() + "</address2>" +

"\n<city>" + customerInfo.getCity() + "</city>" +

"\n<state>" + customerInfo.getState() + "</state>" +

"\n<zip>" + customerInfo.getZip() + "</zip>" +

"\n<email>" + customerInfo.getEmail() + "</email>" +

"\n<phone>" + customerInfo.getPhoneNumber() + "</phone>" );

CreditInfo credit = customerInfo.getCreditInfo();

writer.write( "\n<credit_info>\n<card_number>" +

credit.getCreditCardNumber() + "</card_number>" +

"\n<card_type>" + credit.getCreditCardType() + "</card_type>" +

"\n<expiration_date>" + credit.getExpirationDate() +




Содержание  Назад  Вперед