Element root = doc.getRootElement(); Element urla = root.getChild(a); xmlMap.put(a.toUpperCase(),urla.getText()); Element urlb = root.getChild(b); xmlMap.put(a.toUpperCase(),urlb.getText()); Element urlc = root.getChild(c); xmlMap.put(a.toUpperCase(),urlc.getText()); Element urld = root.getChild(d); xmlMap.put(a.toUpperCase(),urld.getText()); Element urle = root.getChild(e); xmlMap.put(a.toUpperCase(),urle.getText()); Element urlf = root.getChild(f); xmlMap.put(a.toUpperCase(),urlf.getText()); 我这样写就获取到了,其中a,b,c,d,e,f是我要取得元素名称(这个方法传过来的参数),但是代码太罗嗦了,有没有好点的方法?
代码跑一下就知道能不能存到map了。
比如说root.getChildren() 这里返回的是什么,debug看下。
Element urla = root.getChild(a);
xmlMap.put(a.toUpperCase(),urla.getText());
Element urlb = root.getChild(b);
xmlMap.put(a.toUpperCase(),urlb.getText());
Element urlc = root.getChild(c);
xmlMap.put(a.toUpperCase(),urlc.getText());
Element urld = root.getChild(d);
xmlMap.put(a.toUpperCase(),urld.getText());
Element urle = root.getChild(e);
xmlMap.put(a.toUpperCase(),urle.getText());
Element urlf = root.getChild(f);
xmlMap.put(a.toUpperCase(),urlf.getText());
我这样写就获取到了,其中a,b,c,d,e,f是我要取得元素名称(这个方法传过来的参数),但是代码太罗嗦了,有没有好点的方法?