java xml文件中相同Id遍历

import java.io.File;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
public class Test {
public static void main(String[] args) throws DocumentException {
SAXReader reader = new SAXReader();
Document doc = reader.read(new File("F:/a.xml"));
List<Node> nodes1 = doc.selectNodes("//ref/syn");
List<Node> nodes2 = doc.selectNodes("//ref/rel");
for (Node node : nodes1) {
System.out.println(node.selectSingleNode("word").getText() + " "
+ node.selectSingleNode("exp").getText());
}
for (Node node : nodes2) {
System.out.println(node.selectSingleNode("word").getText() + " "
+ node.selectSingleNode("exp").getText());
}
}
}

posted on 2018-03-07 16:53  天天天12345  阅读(273)  评论(0编辑  收藏  举报

导航