import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.io.FileReader;
import java.io.IOException;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
public class Main extends JPanel {
public Main() {
super(new GridLayout());
final JTextArea jt= new JTextArea("dear test :) ",5,20);
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File("file.xml");
jt.File( );
try{
Document document = (Document) builder.build(xmlFile);
Element rootNode = document.getRootElement();
List list = rootNode.getChildren("staff");
for (int i=0; i< list.size(); i++)
{
Element node = (Element) list.get(i);
System.out.println("First Name : " + node.getChildText("firstname"));
System.out.println("Last Name : " + node.getChildText("lastname"));
System.out.println("Nick Name : " + node.getChildText("nickname"));
System.out.println("Salary : " + node.getChildText("salary"));
jt.read(node.getChildText("salary"));
}
}catch(IOException io){
System.out.println(io.getMessage());
}catch(JDOMException jdomex){
System.out.println(jdomex.getMessage());
}
add(jt);
}
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("TextDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add contents to the window.
frame.add(new Main());
//Display the window.
frame.pack();
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}
public static void main(String[] args) {
//Schedule a job for the event dispatch thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
Pretendo visualizar o conteudo do arquivo file.xml na JTextArea jt , como faco isso?
Valeu []