XMLファイル:
<apps>
<app name="google">
<branches>
<branch location="us">
<datacenters>
<datacenter city="Mayes County" />
<datacenter city="Douglas County" />
</datacenters>
</branch>
</branches>
</app>
<app name="facebook">
</app>
</apps>
Javaコード:
XPath xpath = XPathFactory.newInstance().newXPath();
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
String expression = "/apps/app[name='google']";
Element element = xpath.evaluvate(expression,document.getDocumentElement();
Element app = (Element)xpath.evaluvate(expression,element,XPathConstants.NODE);
app要素を格納し、app要素内でxpath式を実行できます。このような
xpath.evaluvate("branches/branch[@location='us']",app,XPathConstants.STRING);
VTD XMLでこれを行うにはどうすればよいですか?