0

Here is my code: I have got xml file as output and i need to get one specific tag from that file try {

        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 Answers1

1

The link below will show you how to convert your XML file (starting with either an XML file or XML String) into a Document.

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

Once you have the document you can simply...

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

Hope this helps

  • Thanks for the reply! Here I don't want to write the tags in my program. From the above program, I am getting the output in the XML file. Can I load it into the Pojo class? – shivakrishna karnati Jan 31 '19 at 05:21
  • It's not something I've needed to do myself to be honest. But it seems like there are a few ways of doing it. Check out some of the answers on this question... https://stackoverflow.com/questions/14789302/parse-xml-to-java-pojo-in-efficient-way – Graham Sant Jan 31 '19 at 09:37
  • 1
    Thank you Graham Sant! I have done it using Jackson method. – shivakrishna karnati Jan 31 '19 at 13:34