2017-02-10 37 views
0

は、私はこのような彼らの名によってノード/要素を反復処理することができる方法はあります:ハウツー反復処理

<rootnode> 
    <foo> 
    <bar> 
     stuff 
    </bar> 
.... 


document.getDocumentElement.getElement("foo").getElement("bar").getValue(); 
+0

あなたはXPathを知っていますか?あなたはすでにorg.w3c.dom.Documentとして文書を解析されている提供

あなたのユースケースに合っていますか? – GPI

答えて

2

私はXPathはトリックを行うべきだと思います。

String expression = "/rootnode/foo/bar"; 
NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET); 
for (int i = 0; i < nodeList.getLength(); i++) { 
    System.out.println(nodeList.item(i).getFirstChild().getNodeValue()); 
} 
+0

うーんxPathはオプションになる可能性があります。それを試してみよう – Gobliins

+0

なぜこれが投票されたのですか? –