Estou tentando recuperar valores trazidos de um xml com o SAX:
Minhas classes são:
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
class XMLHandler extends DefaultHandler {
private StringBuffer galhoAtual = new StringBuffer(200);
private StringBuffer valorAtual = new StringBuffer(100);
public void startDocument() {
System.out.print("Iniciando");
}
public void startElement(
String uri,
String localName,
String tag,
Attributes atributos)
{
galhoAtual.append("/" + tag);
valorAtual.delete(0, valorAtual.length());
}
public void characters(char[] ch, int start, int length) {
valorAtual.append(ch, start, length);
}
public void endElement(String uri, String localName, String tag)
{
System.out.println(valorAtual.toString().trim());
valorAtual.delete(0, valorAtual.length());
galhoAtual.delete(
galhoAtual.length() - tag.length() - 1,
galhoAtual.length());
}
public void endDocument() {
System.out.print("\nTerminando");
}
}
import java.io.IOException;
import javax.xml.parsers.*;
import org.xml.sax.*;
public class ExemploSax {
public static void main(String[] args) {
String arquivo = args[0];
try {
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
InputSource input = new InputSource(arquivo);
parser.parse(input, new XMLHandler());
} catch (ParserConfigurationException ex) {
ex.printStackTrace();
} catch (SAXException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
o retorno que estou obtendo é:
eu quero recuperar esses valores assim:
151 - 8482.10.90 - 10644 - ROLAMENTO ÁRVORE PRIM CÂMBIO MF 834850M1 - ROLAMENTO ; ÁRVORE ; PRIMÁRIA CÂMBIO MF 95/95X - Que tipo de rolamento? De carga radial?
152 - 8708.31.10 - 10646 - MANCAL PEDESTAL EIXO 1 3/4 FCM SN 510 - MANCAL ; PEDESTAL ; DIÂMETRO EIXO 1 3;4 EQUIPAMENTOS INDÚSTRIAIS - Mancal com ou sem rolamento? Montado com bronze?
como eu posso recuperar esses valores dessa forma?
