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
|
public class MonHandler extends DefaultHandler
{
private String id;
private String szTag;
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
{
szTag = qName;
if (szTag.equals ("personne"))
id = attributes.getValue (0);
}
public void characters(char[] ch, int start, int length)
{
String szValue = new String (ch, start, length).trim ();
if (id != null && szTag.equals ("nom"))
System.out.println ("nom de la personne d'id " + id + " : " + szValue);
}
public void endElement(String uri, String localName, String qName)
{
if (qName.equals ("personne"))
id = null;
}
} |
Partager