SAXパーサを使用し、 "id1"開始要素の後に出現するテキストをid1値として、 "id2"開始要素の後のテキストをid2値として格納します。例えば
:あなたはこのことのためにJDOMを使用することができます
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;
}
を、[XPathの](http://www.ibm.com/developerworks/library/x-javaxpathapi /)はあなたの友人です –