com.san.strutsAjax.utils.ParseXMLFactory(xml文件生成类;由于是简单应用所以没做封装)
package com.san.strutsAjax.utils;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilderFactory;
import java.util.List;
import com.san.strutsAjax.forms.CustomerForm;
/**
* Created by IntelliJ IDEA.
* User: huxinsheng
* Date: 2006-4-9
* Time: 9:37:12
* To change this template use File | Settings | File Templates.
*/
public class ParseXMLFactory {
public static String resultsXML(List resultList) throws Exception {
StringBuffer resutls = new StringBuffer("<?xml version=/"1.0/" encoding=/"utf-8/"?>");
resutls.append("<customers>");
CustomerForm customer;
if (resultList != null) {
for (Object aResultList : resultList) {
customer = (CustomerForm) aResultList;
resutls.append("<customer>");
//CUSTOMER ID
resutls.append("<id>");
resutls.append(customer.getId());
resutls.append("</id>");
//CUSTOMER NAME
resutls.append("<name>");
resutls.append(customer.getName());
resutls.append("</name>");
//CUSTOMER AGE
resutls.append("<age>");
resutls.append(customer.getAge());
resutls.append("</age>");
//CUSTOMER TELEPHONE
resutls.append("<telephone>");
resutls.append(customer.getTelephone());
resutls.append("</telephone>");
//CUSTOMER ADDRESS
resutls.append("<address>");
resutls.append(customer.getAddress());
resutls.append("</address>");
//CUSTOMER POSTCODE
resutls.append("<postcode>");
resutls.append(customer.getPostcode());
resutls.append("</postcode>");
resutls.append("</customer>");
}
}
resutls.append("</customers>");
System.out.println(resutls.toString());
return resutls.toString();
}
}