XML Java

import java.util.Iterator;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
/**
 * @author robh
 *  
 */
public class HelloPeopleJDOM {
    public static void main(String[] args) throws Exception {
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build("./src/data.xml");
        StringBuffer output = new StringBuffer();
        // create the basic HTML output
        output.append("\n").append(
                "\n\nPerson List\n\n").append(
                "\n").append("
    \n");
            Iterator itr = doc.getRootElement().getChildren().iterator();
            while (itr.hasNext()) {
                Element elem = (Element) itr.next();
                output.append("
  • ");
                output.append(elem.getAttribute("lastName").getValue());
                output.append(", ");
                output.append(elem.getAttribute("firstName").getValue());
                output.append("
  • \n");
            }
            // create the end of the HTML output
            output.append("
\n\n");
        System.out.println(output.toString());
    }
}
           
         
    
  
velocity-DataInXML.zip( 1,874 k)