xml属性名称相同的问题

tuckeryeh 2015-08-18 11:28:03
<?xml version="1.0" encoding="UTF-8"?>
<histdata totalcount="4" listend="1">
<item>
<datetime>2015/8/6 上午 12:00:00</datetime>
<datetime_raw>42222.6666666667</datetime_raw>
<value channel="Traffic Total (volume)" channelid="-1">929,245 MByte</value>
<value_raw channel="Traffic Total (volume)" channelid="-1">974383866418.3032</value_raw>
<value channel="Traffic Total (speed)" channelid="-1">90 Mbit/s</value>
<value_raw channel="Traffic Total (speed)" channelid="-1">11296009.8181</value_raw>
<value channel="Traffic In (volume)" channelid="0">802,390 MByte</value>
<value_raw channel="Traffic In (volume)" channelid="0">841367289696.6233</value_raw>
<value channel="Traffic In (speed)" channelid="0">78 Mbit/s</value>
<value_raw channel="Traffic In (speed)" channelid="0">9753951.6946</value_raw>
<value channel="Traffic Out (volume)" channelid="1">126,854 MByte</value>
<value_raw channel="Traffic Out (volume)" channelid="1">133016576721.6800</value_raw>
<value channel="Traffic Out (speed)" channelid="1">12 Mbit/s</value>
<value_raw channel="Traffic Out (speed)" channelid="1">1542058.1235</value_raw>
<value channel="Downtime" channelid="-4">0 %</value>
<value_raw channel="Downtime" channelid="-4">0.0000</value_raw>
<coverage>100 %</coverage>
<coverage_raw>0000009984</coverage_raw>
</item>
</histdata>


用Dom4j 讀取xml

public class Demo {
public static void main(String[] args) throws Exception {
SAXReader reader = new SAXReader();
Document document = reader.read(new File("histdata.xml"));
Element root = document.getRootElement();

Iterator it = root.elementIterator();
while (it.hasNext()) {
Element element = (Element) it.next();

System.out.println("Traffic Total (speed): " + element.elementText("value"));
System.out.println();
}
}
}

运行结果:
Traffic Total (speed):900,605 MByte
Traffic Total (speed):1,045,356 MByte
Traffic Total (speed):968,420 MByte
Traffic Total (speed):929,250 MByte
Traffic Total (speed):897,072 MByte

属性名称相同,一直取到Traffic Total (volume),我是需要Traffic Total (speed)的值
请问怎么解决??
...全文
256 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
tony4geek 2015-08-27
  • 打赏
  • 举报
回复
那么早的日期解决了吧。
tuckeryeh 2015-08-27
  • 打赏
  • 举报
回复
顶~~~~~~~

50,560

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧