Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import javax.xml.parsers.DocumentBuilderFactory;
- import javax.xml.parsers.DocumentBuilder;
- import org.w3c.dom.Document;
- import org.w3c.dom.NodeList;
- import org.w3c.dom.Node;
- import org.w3c.dom.Element;
- public class Parser {
- public static void main(String[] args){
- String toSearchAttribute = "ERG";
- try {
- File inputFile = new File("parser.txt");
- DocumentBuilderFactory dbFactory
- = DocumentBuilderFactory.newInstance();
- DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
- Document doc = dBuilder.parse(inputFile);
- doc.getDocumentElement().normalize();
- NodeList nList = doc.getElementsByTagName("database");
- for (int temp = 0; temp < nList.getLength(); temp++) {
- Node nNode = nList.item(temp);
- if (nNode.getNodeType() == Node.ELEMENT_NODE) {
- Element eElement = (Element) nNode;
- String nodeAttribute = eElement.getAttribute("key");
- if(toSearchAttribute.equals(nodeAttribute)){
- System.out.println("driver : "
- + eElement.getAttribute("driver"));
- System.out.println("url.local : "
- + eElement.getAttribute("url.local"));
- System.out.println("login : "
- + eElement.getAttribute("login"));
- System.out.println("password : "
- + eElement.getAttribute("password"));
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment