23

来源:互联网 发布:淘宝历史最低价查询 编辑:程序博客网 时间:2024/05/01 01:59

try {

DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();

domFactory.setNamespaceAware(true);// never forget this!

DocumentBuilder builder = domFactory.newDocumentBuilder();

Document doc = builder.parse(new

ByteArrayInputStream(response.getBody().getBytes("UTF-8")));

XPathFactory factory = XPathFactory.newInstance();

XPath xpath = factory.newXPath();

XPathExpression expr = xpath.compile("//photos/photo");

Object result = expr.evaluate(doc, XPathConstants.NODESET);

NodeList nodes = (NodeList) result;

for (int i = 0; i < nodes.getLength(); i++) {

NamedNodeMap map = odes.item(i).getAttributes();n

if(map!=null) {

photoUrlList.add(RequestUrlHelper.getPhotoUrl(createPhoto(map)));

}

}

} catch (Exception e) {

e.printStackTrace();

}


                                             
0 0