マイペースなプログラミング日記

DTMやプログラミングにお熱なd-kamiがマイペースに書くブログ

ブラウザ上でXPath

GWTのクライアントサイドでXPath使いたいと思いGoogleで検索したらhttps://code.google.com/p/gwtxpath/が見つかった。これをクラスパスに追加して、***.gwt.xmlに以下の一行を追加すればクライアントサイドでXPathが使えるようだ。

<inherits name="com.mouchel.gwt.xpath.xpath" />

以下のように書いてXPathの動作確認、File APIと組み合わせると面白い

Document document = XMLParser.parse(text);
List<Element> outlines = XPath.evaluate(document, "/opml/body/outline", Element.class);
		
for(Element outline : outlines){
    Window.alert(XPath.evaluateSingle(outline, "@title", Attr.class).getValue());
}