0

我从服务器获取 html 响应我想要来自我的网络服务器的 xml 响应,所以使用哪个插件从服务器获取 XML 响应。任何人都可以帮助我解决这个问题,这将非常有帮助。

4

1 回答 1

0

请记住,对于 Java XPath API,拥有来自 Web 服务器、文件或任何相同的 xml。因此,您必须应用以下内容:

            //Partie connexion
        URL url = new URL(addressToConnect);
        HttpURLConnection connexion = (HttpURLConnection) url.openConnection();
        connexion.connect();
        InputSource geocoderResultInputSource;
        geocoderResultInputSource = new InputSource(connexion.getInputStream());
        
        //Partie XML/XPATH
        
        Document geocoderResultDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(geocoderResultInputSource);
        XPath xpath = XPathFactory.newInstance().newXPath();

        NodeList nodeListCodeResult = (NodeList) xpath.evaluate("//status", geocoderResultDocument, XPathConstants.NODESET);

ETC...

这里有更多示例,来自我正在制作的项目

希望它有帮助;)

于 2012-12-05T00:32:34.710 回答