awesome
stuff ..among the most parser this is the very easy way to marshal
& unmarshal java object .no need to have sax or dom parser ..you can
enjoy this lib
class Company{
String name;
Employee employees[];
Company(String name, Employee... employees){
this.name = name;
this.employees = employees;
}
}
class Employee{
String id;
String name;
String email;
int age;
Employee(String id, String name, String email, int age){
this.id = id;
this.name = name;
this.email = email;
this.age = age;
}
}
import jlibs.xml.sax.XMLDocument;
import javax.xml.transform.stream.StreamResult;
XMLDocument xml = new XMLDocument(new StreamResult(System.out), false, 4, null);
xml.startDocument();{
xml.startElement("company");{
xml.addAttribute("name", company.name);
for(Employee emp: company.employees){
xml.startElement("employee");{
xml.addAttribute("id", emp.id);
xml.addAttribute("age", ""+emp.age);
xml.addElement("name", emp.name);
xml.addElement("email", emp.email);
}
xml.endElement("employee");
}
}
xml.endElement("company");
}
xml.endDocument();
No comments:
Post a Comment