Currently I´m using this method to find a specified tag in a XML document:
public static String parseDocument(byte[] stream, String tagName, String resourceName) {
String result = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new ByteArrayInputStream(stream));
document.getDocumentElement().normalize();
Node tag = document.getElementsByTagName(tagName).item(0);
result = tag.getAttributes().getNamedItem(resourceName).getNodeValue();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
But this returns only the first match. How can I implement a method that returns all found tags?
1 Answer