Estou fazendo uma aplicacao, onde eu tenho que ler um arquivo xml como este abaixo:
<html>
<head>
<title> juca shows </title>
<title>hehehehehehehehe</title>
<style>oooooooooooooooo</style>
<title>hehehehehehehehe</title>
<title>hehehehehehehehe</title>
<title>hehehehehehehehe</title>
<title>hehehehehehehehe</title>
</head>
<body onload=“javascript:alert(‘ola!’)”>
ola mundo!
</body> </html>Este arquivo tem 14 linhas. Eu preciso identificar em quais linhas do arquivo, que tem a tag <title>, para
poder pegar o que esta escrito entre elas. O meu codigo em java, segue abaixo:
public static void main(String[] args) throws Exception {
dbf = DocumentBuilderFactory.newInstance();
docbuilder = dbf.newDocumentBuilder();
doc = docbuilder.parse();new File("arquivo.xml")
//rotina para pegar o dado entre as tags
do {
htmltag = doc.getDocumentElement();
headtag = (Element) htmltag.getElementsByTagName("head").item(0);
titletag = (Element) headtag.getElementsByTagName("title").item(i);
if( != null){titletag.getTextContent()
//mostra o que foi pego entre as tags
System.out.println("Titulo: " + titletag.getTextContent());
}else{
System.out.println("null");
}
//incrementa o contador
i++;
} while (i <= 5);
}
}
Eu queria fazer uma estrutura que varresse todas as linhas do arquivo xml e identifica-se quais delas tem a tag
<title> e pegar os respectivos dados que estao entre elas.
Você poderia me ajudar??
grato.