Java tutorial
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class MainClass { static public void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse("y.xml"); NodeList configs = doc.getElementsByTagName("C"); for (int i = 0; i < configs.getLength(); i++) { Element config = (Element) configs.item(i); String runMode = config.getAttribute("r").trim(); if (runMode.equals("test")) { NodeList connectionURLs = config.getElementsByTagName("URL"); System.out.println(connectionURLs.item(0).getNodeName() + "=" + connectionURLs.item(0).getFirstChild().getNodeValue()); return; } } } }