日期:2014-05-20 浏览次数:20692 次
org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader(); doc = reader.read(new File("conf/you.cfg.xml")); Element root = doc.getRootElement(); List dbs = root.elements(); if (dbs.size() > 0) { Element elm = (Element) dbs.get(0); String name = elm.getName(); initConnProp(elm); }
------解决方案--------------------
试试这个吧,只能截取带<data>节点中是小数的:
String xml = "<Row><Data>0</Data><Data>10057</Data><Data>8602</Data>\n<Data>114.018909</Data>\n<Data>23.209072</Data>\n<Data>广东省惠州市的G324附近,新禾村附近</Data></Row>"; Pattern pattern = Pattern.compile("<data>(\\d*\\.\\d*)</data>", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(xml); ArrayList<String> lst = new ArrayList<String>(); while (matcher.find()) { lst.add(matcher.group(1)); } System.out.println(lst);
------解决方案--------------------
循环结束后:
String s1 = lst.get(1);
String s2 = lst.get(2);