KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bull > eclipse > jonas > utils > xml > GetNodeInXmlFile


1 /*
2  * Created on 24 juin 2004
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

7 package com.bull.eclipse.jonas.utils.xml;
8
9 import java.io.File JavaDoc;
10 import java.io.FileInputStream JavaDoc;
11 import java.io.FileNotFoundException JavaDoc;
12 import java.io.IOException JavaDoc;
13
14 import javax.xml.parsers.ParserConfigurationException JavaDoc;
15
16 import org.w3c.dom.Document JavaDoc;
17 import org.w3c.dom.NodeList JavaDoc;
18 import org.xml.sax.SAXException JavaDoc;
19
20 import com.bull.eclipse.jonas.JonasLauncherPlugin;
21
22 /**
23  * @author riase
24  *
25  * To change the template for this generated type comment go to
26  * Window>Preferences>Java>Code Generation>Code and Comments
27  */

28 public class GetNodeInXmlFile {
29     
30     public static String JavaDoc getValueForNode(File JavaDoc xmlFile, String JavaDoc node) {
31         try {
32             FileInputStream JavaDoc is = new FileInputStream JavaDoc(xmlFile);
33             Document JavaDoc docXmlWeb = XMLUtils.newDocument(is,true);
34             
35             NodeList JavaDoc nlSC = docXmlWeb.getElementsByTagName(node);
36             for(int i = 0;i < nlSC.getLength(); i++) {
37                 JonasLauncherPlugin.log("Node Value = " + nlSC.item(i).getFirstChild().getNodeValue());
38                 return nlSC.item(i).getFirstChild().getNodeValue();
39             }
40
41         } catch (FileNotFoundException JavaDoc e) {
42             // TODO Auto-generated catch block
43
e.printStackTrace();
44         } catch (ParserConfigurationException JavaDoc e) {
45             // TODO Auto-generated catch block
46
e.printStackTrace();
47         } catch (SAXException JavaDoc e) {
48             // TODO Auto-generated catch block
49
e.printStackTrace();
50         } catch (IOException JavaDoc e) {
51             // TODO Auto-generated catch block
52
e.printStackTrace();
53         }
54         return null;
55     }
56
57
58 }
59
Popular Tags