Results 1 to 3 of 3

Thread: Using spring xpath API to read xml with namespaces

  1. #1
    Join Date
    Apr 2009
    Posts
    5

    Default 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>

  2. #2

    Default

    see this post, it explains how to use the template with xml namespaces-

    http://krams915.blogspot.com/2011/01...-using_16.html

  3. #3

    Default

    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
  •