-
Jul 28th, 2010, 08:45 PM
#1
Using spring xpath API to read xml with namespaces
I would really appreciate someone who can help me on this, I searched internet but could not find detail info on this.
I am trying to run the example from this link
http://blog.springsource.com/2007/04...-web-services/
but to access a different web services such as Amazon. But the xml I got back has namespace defined in it. So the xpath such as "//photo" no longer worked.
My questions is from the example code given, how to modify it to retrieve xml content with namespace using spring rest?
-------------------------------------
List<BufferedImage> imageList = xpathTemplate.evaluate("//photo", photos, new NodeMapper() {
public Object mapNode(Node node, int i) throws DOMException {
Element photo = (Element) node;
Map<String, String> variables = new HashMap<String, String>(3);
variables.put("server", photo.getAttribute("server"));
variables.put("id", photo.getAttribute("id"));
variables.put("secret", photo.getAttribute("secret"));
String photoUrl = "http://static.flickr.com/{server}/{id}_{secret}_m.jpg";
return restTemplate.getForObject(photoUrl, BufferedImage.class, variables);
}
});
---------------------------------
the xml (simpler version)I am trying to read using spring rest xpath:
<ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2005-10-05">
<bookstore>
<books>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
<Item>
<ASIN>1111</ASIN>
</Item>
</book>
</ItemSearchResponse>
-
Nov 10th, 2011, 04:53 PM
#2
see this post, it explains how to use the template with xml namespaces-
http://krams915.blogspot.com/2011/01...-using_16.html
-
Nov 11th, 2011, 09:00 AM
#3
Nice and useful information.
Thanks for sharing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules