I have managed a code to handle a file.
Now I want to use the same code to handle all the XML files which are located in a directory.
Can someone tell me how can I declare the path and how to look for a loop.
Thanks in advance
import org.xml.sax.SAXException;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.io.IOException;
public class XmlReadWrite3 {
public static void main(String[] args) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse("C:/Users/Desktop/1381.xml");
Element langs = doc.getDocumentElement();
Element filename= getElement(langs, "Filename");
Element beschreibung = getElement(langs, "Beschreibung");
Element name = getElement(langs, "Name");
Element ide = getElement(langs, "IDe");
System.out.println("Filename: " + filename.getTextContent() + "\n" + "Beschreibung: "
+ beschreibung.getTextContent() + "\n" + "Ersteller: " + name.getTextContent() + "\n"
+ "Pnummer: " + ide.getTextContent() + "\n\n");
}catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (SAXException se) {
se.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
private static Element getElement(Element langs, String tag){
return (Element) langs.getElementsByTagName(tag).item(0);
}
}