Попробуйте что-то вроде этого:
private static final DocumentBuilderFactory DOCUMENT_BUILDER_FACTORY = DocumentBuilderFactory.newInstance();
private static final XPathFactory XPATH_FACTORY = XPathFactory.newInstance();
public static void parseXml(String urlPath) throws Exception {
URL url = new URL(urlPath);
URLConnection connection = url.openConnection();
DocumentBuilder db = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder();
final Document document = db.parse(connection.getInputStream());
XPath xPathEvaluator = XPATH_FACTORY.newXPath();
NodeList tracksinfoNodes = (NodeList) xPathEvaluator.compile("lfm/results/trackmatches/track").evaluate(
document, XPathConstants.NODESET);
for (int i = 0; i < tracksinfoNodes.getLength(); i++) {
Node trackNameNode = tracksinfoNodes.item(i);
NodeList childs = trackNameNode.getChildNodes();
for (int j = 0; j < childs.getLength(); j++) {
Node n = childs.item(j);
if (!n.getNodeName().equals("#text")) {
System.out.println(String.format("%s: %s", n.getNodeName(), n.getTextContent()));
}
}
System.out.println("==============");
}
}