1
I’m trying to read a file .xml
using the code below
public static String lerArquivoXML(String string){
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File("c:\\teste.xml");
try {
Document document = (Document) builder.build(xmlFile);
Element rootNode = document.getRootElement();
List list = rootNode.getChildren("staff");
for (int i = 0; i < list.size(); i++) {
Element node = (Element) list.get(i);
System.out.println("First Name : " + node.getChildText("firstname"));
System.out.println("Last Name : " + node.getChildText("lastname"));
System.out.println("Nick Name : " + node.getChildText("nickname"));
System.out.println("Salary : " + node.getChildText("salary"));
}
} catch (IOException io) {
System.out.println(io.getMessage());
} catch (JDOMException jdomex) {
System.out.println(jdomex.getMessage());
}
return null;
}
However, I have an error return on line 8(Element rootNode = document.getRootElement();
) according to the title of the question. The imports
are OK
xml used
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:apis="http://schemas.datacontract.org/2004/07/Integracao.Modelo.Chamada">
<soapenv:Body>
<tem:CancelaSP>
<!--Optional:-->
<tem:token>386922849949</tem:token>
<!--Optional:-->
<tem:cancelaSPIntegracao>
<!--Optional:-->
<apis:AnoSP>2016</apis:AnoSP>
<!--Optional:-->
<apis:NumeroSP>5656</apis:NumeroSP>
</tem:cancelaSPIntegracao>
</tem:CancelaSP>
</soapenv:Body>
</soapenv:Envelope>
Put which is line 8 in your question.
– Taisbevalle
@Taisbevalle edited
– Lucas Torres