我在这里问你一个关于 jdom 的基本问题。我正在尝试读取 Document 对象,但一直出错。我要阅读的文件是,
<message>
<header>
<messageType>snmp</messageType>
<sendFrom>192.168.0.16</sendFrom>
<hostName>oghmasysMehmet</hostName>
<sendTo>192.168.0.12</sendTo>
<receiverName>Mehmet</receiverName>
<date>03/10/2011</date>
</header>
<body>
<snmpType>getbulk</snmpType>
<ip>127.0.0.1</ip>
<port>161</port>
<oids>
<oid>1.3.6.1.2.1.1</oid>
</oids>
<community>public</community>
<nR>0</nR>
<mR>5</mR>
</body>
</message>
我正在努力评估。为此,我编写了一个函数,
public Vector<String> getOIDs(Document document){
Vector<String> oids = new Vector<String>();
Element root = document.getRootElement();
Element body = root.getChild("body");
//Element element = body.getChild("oids");
List rows = body.getChildren("oid");
for (int i = 0; i < rows.size(); i++) {
Element row = (Element) rows.get(i);
String s = row.getText();
oids.add(s);
}
return oids;
}
但是当我调试它时,我总是可以看到该函数没有读取任何内容。你能帮帮我吗?
谢谢你们
编辑:好吧,很抱歉问了这样一个菜鸟问题,我只是在 getchildren () 中犯了一个错误;我应该写 oids 而不是 oid
编辑 2:实际上我在评论我的问题时更改了代码,但现在,我读到的唯一内容是“\n \n”而不是“1.3.6.1.2.1.1”。你认为问题可能是什么?