xml解析循环参数实例


Document document = sr.read(IOUtils.toInputStream(result));
List<Node> nodes = document.selectNodes("/output/data/list");
for (Node node : nodes) {
                for (Node node : nodes) {
                    String id = XmlUtils.getNodeValue(node, "id");
                    String userName = XmlUtils.getNodeValue(node, "userName");
public class XmlUtils {

    public static String getNodeValue(Node node, String nodeName) {
        Node target = node.selectSingleNode(nodeName);
        return getNodeText(target);
    }
   
    public static String getNodeText(Node node) {
        return node != null ? node.getText().trim() : null;
    }
}

posted on 2012-08-29 17:12  anuo_ruibo  阅读(323)  评论(0编辑  收藏  举报

导航