Seguinte… preciso de um programa que leia um xml e separa as tags na variaveis, a duvida é que na tag
de alguns xmls de nota fiscal eletronica ele nao me tras tudo oq esta dentro da tag… apenas um pedaço… o que pode ser?
grato,
public class SAXLister {
public String cnpj;
public String chave1;
public String nome1;
public String nome2;
public String nomes;
public String numeroNF;
public String tudo1;
int cont = 1;
public static void main(String[] args) throws Exception {
new SAXLister("W:/TI/Bruno/Projetos JAVA/XML/4.xml");
}
public SAXLister(String caminho) throws SAXException, IOException {
XMLReader parser = XMLReaderFactory.createXMLReader();
// should load properties rather than hardcoding class name
parser.setContentHandler(new PeopleHandler());
parser.parse(caminho);
}
public class PeopleHandler extends DefaultHandler {
boolean emit = false;
boolean chave = false;
boolean nome = false;
boolean numero = false;
boolean tudo = false;
public void startElement(String nsURI, String localName,
String rawName, Attributes attributes) throws SAXException {
if (rawName.equalsIgnoreCase("emit")) {
emit = true;
}
if (rawName.equalsIgnoreCase("chNFe")) {
chave = true;
}
if (rawName.equalsIgnoreCase("cNF")) {
numero = true;
}
if (cont == 1) {
if (rawName.equalsIgnoreCase("xnome")) {
nome = true;
}
}
}
public void characters(char[] ch, int start, int length) {
if (emit) {
cnpj = new String(ch, start, length);
emit = false;
}
if (chave) {
chave1 = new String(ch, start, length);
chave = false;
}
if (numero) {
numeroNF = new String(ch, start, length);
numero = false;
}
if (nome) {
nome1 = new String(ch, start, length);
System.out.println((new String(ch, start, length)));
nome = false;
cont = 2;
}
}
}