progamme sui ne passe jamais dans endElement
Bonjour,
j'ai un problème avec l'API Sax (que je ne maitrise pas bien).
J'ai écrit le petit programme de de test que voilà :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
import java.io.File;
import java.io.IOException;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class TestSax {
private static class localSaxHandler extends DefaultHandler {
boolean labelState = false;
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
System.out.println("startElement : "+qName);
}
public void endElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
System.out.println("endElement : "+qName);
}
public void startDocument() {
System.out.println("startDocument");
}
public void endDocument() {
System.out.println("endDocument");
}
}
/**
* @param args
*/
public static void main(String[] args) {
try {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
SAXParser parser = parserFactory.newSAXParser();
parser.parse(new File("c:/tmp/toto.xml"),new localSaxHandler());
} catch (FactoryConfigurationError e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} |
voilà le fichier toto.xml :
Code:
1 2 3 4 5 6
|
<?xml version="1.0" encoding="utf-8"?>
<racine>
<fils></fils>
<fils></fils>
</racine> |
Le problème est que le programme ne passe jamais dans la methode endElement ; pourquoi ?
voici la sortie :
Code:
1 2 3 4 5 6
|
startDocument
startElement : racine
startElement : fils
startElement : fils
endDocument |
merci de votre aide.