I have an XML stored in a String and I am trying to get an attribute value.
Here is the xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<header xmlns="mfp:anaf:dgti:spv:respUploadFisier:v1" dateResponse="202206020900"
ExecutionStatus="0" index_incarcare="123"/>
Here is the code that I have tried:
String response = restTemplate.postForObject(uriLink, reqEntity, String.class);
System.out.println(response);
File f = new File(response);
//parsare xml
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = (Document) db.parse(new File(f.toString()));
NodeList nodeList = (NodeList) document.getProperty("index_incarcare");
String indexIncarcare = nodeList.toString();
System.out.println("-----------------------------"+indexIncarcare);
And I get this error:
java.io.FileNotFoundException: C:\efactura_spring\efactura\<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<header xmlns="mfp:anaf:dgti:spv:respUploadFisier:v1" dateResponse="202206020900" ExecutionStatus="0" index_incarcare="455587"\>
All the examples I found online are to get from a file but I want to get from a String. Can someone give me a working example or an answer?