XMLファイルからXPathで内容を取り出すワンライナー
JavaでXPathを簡単に使えないかと聞かれたので、試しにやってみたらこうなった。
NodeList nodes = (NodeList)XPathFactory.newInstance().newXPath().compile( "xpath" ).evaluate( DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( "filename" ), XPathConstants.NODESET ); for( int i = 0; i < nodes.getLength(); i++ ) { System.out.println( nodes.item( i ).getTextContent() ); }