This is the code I have at present:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class XMLReader extends JFrame
{
JFileChooser _fileChooser = new JFileChooser();
JPanel content = new JPanel();
//... Create menu elements (menubar, menu, menu item)
JMenuBar menubar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenuItem openItem = new JMenuItem("Open...");
int retval = _fileChooser.showOpenDialog(XMLReader.this);
//... The user selected a file, get it, use it.
public static void main(String argv[])
{
ArrayList timeStamp = new ArrayList();
ArrayList Y = new ArrayList();
File file = XMLReader.this;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
System.out.println("Root element " + doc.getDocumentElement().getNodeName());
NodeList nodeLst = doc.getElementsByTagName("reading");
System.out.println("Share Data");
for (int s = 0; s < nodeLst.getLength(); s++) {
Node fstNode = nodeLst.item(s);
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
Element fstElmnt = (Element) fstNode;
NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("timeStamp");
.
.
.
}
I am trying to get a dialog box to allow the user to pick the XML they want parsed. I know the parsing works as I had hard coded in the file before.
I would also like to return the ArrayLists so that I can use them as the inputs to another class is this possible (at the moment I am only printing them to screen)?
System.out.println(timeStamp);
System.out.println(Y);
Can I use a return statement and if so how to I set up the class that I want to use them in?