用于解析 JAX-RS 结果的 XPath

发布于 2024-09-28 16:25:54 字数 849 浏览 9 评论 0原文

我不知道如何使用 XPath,所以我可以解析从 JAX-RS 获得的 XML 结果并将其放入 ArrayList 或其他内容中,这是我到目前为止的代码,它生成一个字符串...但是我希望能够使用 XPath 来解析它,因为解析 XML 比解析 String 更好。

private Client client = Client.create();
    private List<String> venueName = new ArrayList<String>();

    private String getNearbyVenues(double lattitude, double longitude){
        WebResource webResource = client.resource("http://api.foursquare.com/v1/venues");
        MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
        queryParams.add("geolat", String.valueOf(lattitude));
        queryParams.add("geolong", String.valueOf(longitude));
        return webResource.queryParams(queryParams).get(String.class);
    }

结果类似于这个

I don't know how to use XPath so I can parse the result of the XML I got from JAX-RS and put it into an ArrayList or something, here's the code I have so far, it generates a String... but I want to be able to use XPath to parse it, as it's better to parse XML rather than parsing String.

private Client client = Client.create();
    private List<String> venueName = new ArrayList<String>();

    private String getNearbyVenues(double lattitude, double longitude){
        WebResource webResource = client.resource("http://api.foursquare.com/v1/venues");
        MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
        queryParams.add("geolat", String.valueOf(lattitude));
        queryParams.add("geolong", String.valueOf(longitude));
        return webResource.queryParams(queryParams).get(String.class);
    }

The result goes something like this

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云之铃。 2024-10-05 16:25:54

下面是我对另一个问题的回答,解释了如何使用 Java SE javax.xml.xpath 库:

Below is an answer of mine to another question that explains how to use the Java SE javax.xml.xpath libraries:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文