Use a SAX parser and store the text emitted after the "id1" start element as the id1 value and the text after the "id2" start element as the id2 value.
For example:
public static List<String> getIds(InputStream xmlStream) throws ParserConfigurationException, SAXException, IOException {
final List<String> ids = new ArrayList<String>();
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
saxParser.parse(xmlStream, new DefaultHandler() {
boolean getChars = false;
public void startElement(String uri, String name, String qName, Attributes attrs) throws SAXException {
if ("id1".equalsIgnoreCase(qName)) getChars = true;
if ("id2".equalsIgnoreCase(qName)) getChars = true;
}
public void characters(char cs[], int start, int len) throws SAXException {
if (getChars) {
ids.add(new String(cs, start, len));
getChars = false;
}
}
});
return ids;
}