From: laurent blévin (blevinlaurent2@hotmail.com)
Date: 02/07/2001 - 15:10
Bonjour,
Merci beaucoup pour vos exemples .
j'ai un autre problème.
j'ai l'impression qu'il parse deux fois la méthode characters ,
une fois pour endelement une autre pour startelement.
je récupère deux elements un avec la valeur un autre vide.
il y a t-il une solution a ce problème?
>Bonjour,
>
>laurent blévin wrote:
> >
> > bonjour ,
> > je suis débutant en java .
> > je voudrais savoir si quelqu'un pourrait m'envoyé le source complet d'un
> > parser simple qui récupère les données contenues dans les tags d'un
>document
> > xml.
> > parce que pour l'instant j'y comprend rien.
>
>Voici deux exemples que j'utilise lors de mes formations...
>
>Ils affichent tous les deux les informations reçues d'un parseur SAX.
>
>Le premier utilise la version 1 de SAX (qui ne gère pas les espaces de
>noms) et le deuxième utilise SAX2.
>
>Cordialement,
>
>Eric van der Vlist
>
>1) SAX 1:
>
>import org.xml.sax.*;
>
>public class Dump extends HandlerBase {
>
> public static void main (String args[]) throws Exception {
> new Dump(args[0]);
> }
>
> public Dump(String uri) {
> try {
>// Parser p = new org.brownell.xml.aelfred2.SAXDriver();
> Parser p = new org.apache.xerces.parsers.SAXParser();
> p.setDocumentHandler(this);
> p.parse(uri);
> } catch (Exception e) {
> System.err.println(e.toString());
> e.printStackTrace();
> }
> }
>
> public void startDocument(){
> System.out.println("startDocument");
> }
>
> public void endDocument(){
> System.out.println("endDocument");
> }
>
> public void startElement(String name, AttributeList atts){
> System.out.println("startElement: "+name);
> for (int i=0; i<atts.getLength(); i++) {
> System.out.println(" attribute "+atts.getName(i)+
> " = "+atts.getValue(i));
> }
> }
>
> public void endElement(String name){
> System.out.println("startElement: "+name);
> }
>
> public void characters(char[] ch, int start, int length){
> System.out.println(" text ["+
> new String(ch, start, length)+ "]");
>
> }
>}
>
>SAX 2:
>
>import org.xml.sax.*;
>import org.xml.sax.helpers.*;
>
>public class Dump2 extends DefaultHandler {
>
> public static void main (String args[]) throws Exception {
> new Dump2(args[0]);
> }
>
> public Dump2(String uri) {
> try {
>// XMLReader p = new org.brownell.xml.aelfred2.SAXDriver();
> XMLReader p = new org.apache.xerces.parsers.SAXParser();
> p.setContentHandler(this);
> p.parse(uri);
> } catch (Exception e) {
> System.err.println(e.toString());
> e.printStackTrace();
> }
> }
>
> public void startDocument(){
> System.out.println("startDocument");
> }
>
> public void endDocument(){
> System.out.println("endDocument");
> }
>
> public void startElement(String uri, String localName,
> String qName, Attributes atts){
>
> System.out.println("startElement: "+ uri + "|" + localName);
>
> for (int i=0; i<atts.getLength(); i++) {
> System.out.println(" attribute " + atts.getURI(i) +
> "|" + atts.getLocalName(i) + " = " + atts.getValue(i));
> }
> }
>
> public void endElement(String uri, String localName,
> String qName){
> System.out.println("endElement: "+ uri + "|" + localName);
> }
>
> public void characters(char[] ch, int start, int length){
> System.out.println(" text ["+
> new String(ch, start, length)+ "]");
>
> }
>}
>
> >
> > merci
> > a+
>--
>See you at XTech in San Diego.
> http://conferences.oreillynet.com/cs/os2001/view/e_spkr/790
>------------------------------------------------------------------------
>Eric van der Vlist http://xmlfr.org http://dyomedea.com
>http://xsltunit.org http://4xt.org http://examplotron.org
>------------------------------------------------------------------------
>--
>Devenez redacteur <XML>fr et contribuez au developpement du
>xml francophone (http://xmlfr.org/infos/redacteurs/) !
>
>Liste de diffusion "xml-tech@xmlfr.org" (http://xmlfr.org).
>
>Cette liste est a votre disposition pour discuter en francais de
>tout sujet technique lie a XML.
>
>Pour resilier votre abonnement, envoyez un message contenant
>la commande "unsubscribe" a xml-tech-request@xmlfr.org
>(mailto:xml-tech-request@xmlfr.org?Subject=unsubscribe)
>
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
--
Devenez redacteur <XML>fr et contribuez au developpement du
xml francophone (http://xmlfr.org/infos/redacteurs/) !
Liste de diffusion "xml-tech@xmlfr.org" (http://xmlfr.org).
Cette liste est a votre disposition pour discuter en francais de
tout sujet technique lie a XML.
Pour resilier votre abonnement, envoyez un message contenant
la commande "unsubscribe" a xml-tech-request@xmlfr.org
(mailto:xml-tech-request@xmlfr.org?Subject=unsubscribe)
Archive générée par hypermail 2.1.3 le 28/06/2004 - 11:06 UTC
webmaster@xmlfr.org
|