como eu faria a leitura nesse caso? tentei utilizar um for só que não deu muito certo…, tem alguma forma de passar o elemento “telefone” e ele retorna a lista?
packageteste;importcom.sun.org.apache.xerces.internal.parsers.DOMParser;importjavax.xml.xpath.XPath;importjavax.xml.xpath.XPathConstants;importjavax.xml.xpath.XPathFactory;importorg.w3c.dom.Document;importorg.w3c.dom.Node;importorg.w3c.dom.NodeList;publicclassLeituraXML{publicstaticvoidmain(String[]args){try{DOMParserdom=newDOMParser();dom.parse("CAMINHO DO SEU XML");Documentdoc=dom.getDocument();XPathxPath=XPathFactory.newInstance().newXPath();NodeListlistNode=(NodeList)xPath.compile("//telefone").evaluate(doc,XPathConstants.NODESET);if(listNode!=null){for(inti=0;i<listNode.getLength();i++){Nodenode=listNode.item(i);System.out.println(node.getNodeName()+" "+node.getTextContent());}}}catch(Exceptione){System.out.println("Erro: "+e.getMessage());}}}