FiniShed JaVa

import java.io.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
//import javax.xml.parsers.ParserConfigurationException;

//import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Finished {
private void CreateFileList() throws IOException{
File f1;
f1=new File("c:/TestReportGenerator.java");
if(!f1.exists()){
f1.createNewFile();
System.out.println("New file \"TestReportGenerator.java\" has been created to the current directory");
}
}
private void getFileList1(){
File file = new File("C:/Testxml");
File[] files = file.listFiles();
for (int fileInList = 0; fileInList < files.length; fileInList++)
{
System.out.println(files[fileInList].toString());
}
}
private void getXmlData(String S1){
try {
File file = new File(S1);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
System.out.println("Root element " + doc.getDocumentElement().getNodeName());
/*Node n=doc.getElementById("id");
System.out.println(" " + n);*/
NodeList nodeLst = doc.getElementsByTagName("param");
System.out.println("all the params value");

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("key");
Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
NodeList fstNm = fstNmElmnt.getChildNodes();
System.out.println("key : " + ((Node) fstNm.item(0)).getNodeValue());
NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("value");
Element lstNmElmnt = (Element) lstNmElmntLst.item(0);
NodeList lstNm = lstNmElmnt.getChildNodes();
System.out.println("value : " + ((Node) lstNm.item(0)).getNodeValue());
}

}
} catch (Exception e) {
e.printStackTrace();
}
}
/*private void validateXml(String S2) {

}
*/
public static void main(String[] args)throws Exception{
try{
Finished fnobj=new Finished();
fnobj.CreateFileList();
fnobj.getFileList1();
fnobj.getXmlData("C:/Testxml/DEL_IN.xml");
//fnobj.validateXml("C:\\MyXMLFile");
}
catch(Exception e){
e.printStackTrace();
}


}

}

Post a Comment

أحدث أقدم