如何从Java中的控制台从输出文件中获取特定的xml标记

时间:2019-01-30 12:46:03

标签: java xml spring

这是我的代码:我有xml文件作为输出,我需要从该文件中获取一个特定的标签  尝试{

        RestTemplate restTemplate = new RestTemplate();
        final String url = "https://wildfire.paloaltonetworks.com/publicapi/get/verdict";
        String apikey = "f719c27d2063d2e25579681a64ebc1ba";
        String hash = "a1a3b09875f9e9acade5623e1cca680009a6c9e0452489931cfa5b0041f4d290";

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

        MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
        map.add("apikey", apikey);
        map.add("hash", hash);

        HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);


        ResponseEntity responseEntity = restTemplate.postForEntity("https://wildfire.paloaltonetworks.com/publicapi/get/verdict", request, String.class);

        System.out.println(responseEntity);

1 个答案:

答案 0 :(得分:1)

下面的链接将向您展示如何将XML文件(以XML文件或XML字符串开头)转换为文档。

https://howtodoinjava.com/xml/parse-string-to-xml-dom/

有了文档后,您就可以...

String tag = document.getDocumentElement().getAttribute("<TAG NAME>");

希望这会有所帮助