jai un fichier XML, je veux le lire et l'afficher avec java
voici le code XML
<?xml version="1.0" encoding="UTF-8"?>
<Config>
<Application>
<name>statdata</name>
<authType>0</authType>
<conf>
<server>statdata</server>
<url>
http://statdata/servlet/conn.ACCES</url>
</conf>
<conf>
<server>stat1</server>
<url>
http://stat1/servlet/conn.ACCES</url>
</conf>
<parameter>
<name>F_USERNAME</name>
<value>svision</value>
</parameter>
<parameter>
<name>F_PASSWORD</name>
<value>svision</value>
</parameter>
</Application>
<Application>
<name>transbscs</name>
<authType>0</authType>
<conf>
<server>...</server>
<url>
http://</url>
</conf>
<conf>
<server>stat2</server>
<url>
http://stat2/servlet/conn.ACCES</url>
</conf>
<parameter>
<name>F_passwd</name>
<value>svision</value>
</parameter>
</application>
</config>
jai commencer avec ca :
public static void main (String argv []){
try {
File file = new File("c:\\NV.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement ().normalize ();
System.out.println ("Root element of the doc is " +
doc.getDocumentElement().getNodeName());
NodeList listOfapplication = doc.getElementsByTagName("application");
int totalapplication = listOfapplication.getLength();
System.out.println("Total no of application: " + totalapplication);
for(int s=0; s<listOfapplication.getLength() ; s++){
Node firstapplicationNode = listOfapplication.item(s);
if(firstapplicationNode.getNodeType() == Node.ELEMENT_NODE){
Element firstapplicationElement = (Element)firstapplicationNode;
NodeList firstnameList = firstapplicationElement.getElementsByTagName("name");
Element firstnameElement = (Element)firstnameList.item(0);
NodeList textFNList = firstnameElement.getChildNodes();
System.out.println("name : " +
((Node)textFNList.item(0)).getNodeValue().trim());
NodeList listOfconf= firstapplicationElement.getElementsByTagName("conf");
int totalconf = listOfconf.getLength();
System.out.println("Total no of conf: " + totalconf);
for(int i=0; i<listOfconf.getLength() ; i++){
Node firstconfNode = listOfconf.item(i);
if(firstconfNode.getNodeType() == Node.ELEMENT_NODE){
Element firstconfElement = (Element)firstconfNode;
NodeList firstserverList = firstconfElement.getElementsByTagName("server");
Element firstserverElement = (Element)firstserverList.item(0);
NodeList textNList = firstserverElement.getChildNodes();
System.out.println("server : " +
((Node)textNList.item(0)).getNodeValue().trim());
NodeList firsturlList = firstserverElement.getElementsByTagName("url");
Element firsturlElement = (Element)firsturlList.item(0);
NodeList textURLList = firsturlElement.getChildNodes();
System.out.println("url : " +
((Node)textURLList.item(0)).getNodeValue().trim());
j'aimerais bien que vous m'aidez le plutot possible et merci d'avance