Trying to bring the properties/values such as the names or dates of an XML file into java from a directory




Trying to bring the properties/values such as the names or dates of an XML file into java from a directory.the problem i am now having is trying to get the xml values out of the xml files

public class ProcessXML {
public static void main2(String[] args) {

File f = null;
File[] paths;

try{
// file
f = new File("/Users/Adrian/Dropbox/DirectoryParse");

// array of files and directory
paths = f.listFiles();

// for each name in the path array
for(File path:paths)
{
path.isDirectory();
// prints filename and directory name
System.out.println(path);
}
}catch(Exception e){
// if any error occurs
e.printStackTrace();
}
}

public static void main(String[] args) {

File f = null;
try{
// file
f = new File("/Users/Adrian/Dropbox/XML");
//other file
//f = new File("/Users/Adrian/Dropbox/");
listFile(f, " ");
}catch(Exception e){
// if any error occurs
e.printStackTrace();
}
}

private static void listFile(final File file, final String indent) throws IOException, ParserConfigurationException, SAXException {
if (file.isFile()) {
if (file.getName().endsWith(".xml")) {
System.out.println(indent + "File " + file.getName());
// final InputStream is = new FileInputStream(file);
processXML(file);
}
} else if (file.isDirectory()) {
System.out.println(indent + "Dir " + file.getName());
final File[] children = file.listFiles();
for (final File child : children) {
listFile(child, indent + " ");
}
}
}

private static void processXML(final File file) throws
IOException, ParserConfigurationException, SAXException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);


}

}


Trying to bring the properties/values such as the names or dates of an XML file into java from a directory.the problem i am now having is trying to get the xml values out of the xml files i am nout sure what way to about it so if anyone has examples or can tell me which way to go about it it would be very appreciated


No comments:

Post a Comment