0
我試圖解析,我從LinkedIn使用他們的API獲得一個XML文檔(樣本響應是在這裏:http://developer.linkedin.com/documents/get-network-updates-and-statistics-api)。通過XML文件循環不會返回所有結果
在我的XML響應,我有一個以上的「更新」,但不管是什麼原因,我的for循環只打印第一次更新,而不是通過所有250個循環左右他們。
Response response = request.send();
stream = response.getStream();
System.out.println(response.getBody());
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
try
{
DocumentBuilder dbBuilder = dbFactory.newDocumentBuilder();
Document doc = dbBuilder.parse(stream);
doc.getDocumentElement().normalize();
System.out.println("root of xml: " + doc.getDocumentElement().getNodeName());
NodeList nodes = doc.getElementsByTagName("updates");
for (int i=0; i < nodes.getLength(); i++)
{
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE)
{
/**
* Let's get the update type first, and then determine how we should proceed
* if we are CONN, VIRL, etc.
*/
Element element = (Element) node;
String update_type = getValue("update-type", element);
if (update_type.equals("CONN"))
{
String url = getValue("url", element);
String user = getValue("first-name", element) + " " + getValue("last-name", element);
getConnectedProfile(url);
}
}
}
} catch (ParserConfigurationException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
謝謝。