How to access XML tag name?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
25 messages Options
12
Reply | Threaded
Open this post in threaded view
|

How to access XML tag name?

stepharo
Hi

Yesterday I started to hack a smart SAX handler. The idea is that I want
to just specify the tags
I want to visit and the SAX handler should invoke (generated) visit
methods. Like that I can easily
get visitors on XML domain.

Here is an example of what I did.

     | h |
     h := SmartSAXHandler new
                 visitor: (MyFilmVisitor new visitTags: #(FILM ROLE));
                 on: FileSystem workingDirectory / 'FILMS.XML'.
     h parseDocument.
     ^ h



SmartSAXHAndler >> startElement: aQualifiedName attributes: aDictionary

     (visitor shouldVisit: aQualifiedName)
         ifTrue: [
                 visitor
                     perform: (visitor createdVisitSelector: aQualifiedName)
                     with: aQualifiedName
                     with: aDictionary
         ]


Object subclass: #GenericTagSAXVisitor
     instanceVariableNames: 'visitTag visitTags'
     classVariableNames: ''
     category: 'SmartXMLHandler'


GenericTagSAXVisitor>>visitTags: aCollection
     "set the tags that will lead to a call to a visitTag:with: method
in the visitor"

     visitTags := aCollection collect: [ :each | each asLowercase ].
     self createVisitMethods.

and in a subclass the visit* methods automatically generated


Now I could not get when I have a <TITRE>Vertigo</TITRE> where I can get
the Vertigo information.
I redefined several methods of SAXhandler but without success.


<?xml version="1.0" encoding="iso-8859-1"?>
<FILMS>
   <FILM annee="1958">
     <TITRE>Vertigo</TITRE>
     <GENRE>Drame</GENRE>
     <PAYS>USA</PAYS>
     <MES idref="3"/>
     <ROLES>
       <ROLE>
         <PRENOM>James</PRENOM>
         <NOM>Stewart</NOM>
         <INTITULE>John Ferguson</INTITULE>
       </ROLE>
       <ROLE>
         <PRENOM>Kim</PRENOM>
         <NOM>Novak</NOM>
         <INTITULE>Madeleine Elster</INTITULE>
       </ROLE>
     </ROLES>
     <RESUME>Scottie Ferguson, ancien inspecteur de police, est sujet
au vertige depuis qu'il a vu mourir son
  collegue. Elster, son ami, le charge de surveiller sa femme,
Madeleine, ayant des tendances
  suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le
piege qui se trame autour
  de lui et dont il va etre la victime... </RESUME>
   </FILM>

Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

Blondeau Vincent
Hi,

The qualified name in function startElement: aQualifiedName attributes: aDictionary, will be FILMS and after FILM and after TITRE,...etc...
So, you have to tell to your shouldVisit: method to accept TITRE too and get in and after you should implement characters: to get the content on the tag.

Vincent

> -----Message d'origine-----
> De : Pharo-users [mailto:[hidden email]] De la part de
> stepharo
> Envoyé : vendredi 11 mars 2016 14:04
> À : Any question about pharo is welcome
> Objet : [Pharo-users] How to access XML tag name?
>
> Hi
>
> Yesterday I started to hack a smart SAX handler. The idea is that I want to just
> specify the tags I want to visit and the SAX handler should invoke (generated)
> visit methods. Like that I can easily get visitors on XML domain.
>
> Here is an example of what I did.
>
>      | h |
>      h := SmartSAXHandler new
>                  visitor: (MyFilmVisitor new visitTags: #(FILM ROLE));
>                  on: FileSystem workingDirectory / 'FILMS.XML'.
>      h parseDocument.
>      ^ h
>
>
>
> SmartSAXHAndler >> startElement: aQualifiedName attributes: aDictionary
>
>      (visitor shouldVisit: aQualifiedName)
>          ifTrue: [
>                  visitor
>                      perform: (visitor createdVisitSelector: aQualifiedName)
>                      with: aQualifiedName
>                      with: aDictionary
>          ]
>
>
> Object subclass: #GenericTagSAXVisitor
>      instanceVariableNames: 'visitTag visitTags'
>      classVariableNames: ''
>      category: 'SmartXMLHandler'
>
>
> GenericTagSAXVisitor>>visitTags: aCollection
>      "set the tags that will lead to a call to a visitTag:with: method in the visitor"
>
>      visitTags := aCollection collect: [ :each | each asLowercase ].
>      self createVisitMethods.
>
> and in a subclass the visit* methods automatically generated
>
>
> Now I could not get when I have a <TITRE>Vertigo</TITRE> where I can get the
> Vertigo information.
> I redefined several methods of SAXhandler but without success.
>
>
> <?xml version="1.0" encoding="iso-8859-1"?>
> <FILMS>
>    <FILM annee="1958">
>      <TITRE>Vertigo</TITRE>
>      <GENRE>Drame</GENRE>
>      <PAYS>USA</PAYS>
>      <MES idref="3"/>
>      <ROLES>
>        <ROLE>
>          <PRENOM>James</PRENOM>
>          <NOM>Stewart</NOM>
>          <INTITULE>John Ferguson</INTITULE>
>        </ROLE>
>        <ROLE>
>          <PRENOM>Kim</PRENOM>
>          <NOM>Novak</NOM>
>          <INTITULE>Madeleine Elster</INTITULE>
>        </ROLE>
>      </ROLES>
>      <RESUME>Scottie Ferguson, ancien inspecteur de police, est sujet
> au vertige depuis qu'il a vu mourir son
>   collegue. Elster, son ami, le charge de surveiller sa femme,
> Madeleine, ayant des tendances
>   suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le
> piege qui se trame autour
>   de lui et dont il va etre la victime... </RESUME>
>    </FILM>


!!!*************************************************************************************
"Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité de Worldline ne pourra être recherchée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être recherchée pour tout dommage résultant d'un virus transmis.

This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Worldline liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.!!!"
Reply | Threaded
Open this post in threaded view
|

RE: How to access XML tag name?

BriceG
In reply to this post by stepharo

Hi,

according to what have found in the SAXHandler and XMLDOMParser class, you should use SAXHandler>>characters: method to get the information inside a marker.

Information inside a marker is consider as an XMLString that is created after a call to XMLDOMParser>>characters:.


I hope I helped you with your question. =)



--------------
Brice Govin
PhD student in RMoD research team at INRIA Lille
Software Engineer at THALES AIR SYSTEMS Rungis
ENSTA-Bretagne ENSI2014

22 Avenue du General Leclerc 92340 BOURG-LA-REINE





De : stepharo [via Smalltalk] <ml-node+[hidden email]>
Envoyé : vendredi 11 mars 2016 13:37
À : Brice GOVIN
Objet : How to access XML tag name?
 
Hi

Yesterday I started to hack a smart SAX handler. The idea is that I want
to just specify the tags
I want to visit and the SAX handler should invoke (generated) visit
methods. Like that I can easily
get visitors on XML domain.

Here is an example of what I did.

     | h |
     h := SmartSAXHandler new
                 visitor: (MyFilmVisitor new visitTags: #(FILM ROLE));
                 on: FileSystem workingDirectory / 'FILMS.XML'.
     h parseDocument.
     ^ h



SmartSAXHAndler >> startElement: aQualifiedName attributes: aDictionary

     (visitor shouldVisit: aQualifiedName)
         ifTrue: [
                 visitor
                     perform: (visitor createdVisitSelector: aQualifiedName)
                     with: aQualifiedName
                     with: aDictionary
         ]


Object subclass: #GenericTagSAXVisitor
     instanceVariableNames: 'visitTag visitTags'
     classVariableNames: ''
     category: 'SmartXMLHandler'


GenericTagSAXVisitor>>visitTags: aCollection
     "set the tags that will lead to a call to a visitTag:with: method
in the visitor"

     visitTags := aCollection collect: [ :each | each asLowercase ].
     self createVisitMethods.

and in a subclass the visit* methods automatically generated


Now I could not get when I have a <TITRE>Vertigo</TITRE> where I can get
the Vertigo information.
I redefined several methods of SAXhandler but without success.


<?xml version="1.0" encoding="iso-8859-1"?>
<FILMS>
   <FILM annee="1958">
     <TITRE>Vertigo</TITRE>
     <GENRE>Drame</GENRE>
     <PAYS>USA</PAYS>
     <MES idref="3"/>
     <ROLES>
       <ROLE>
         <PRENOM>James</PRENOM>
         <NOM>Stewart</NOM>
         <INTITULE>John Ferguson</INTITULE>
       </ROLE>
       <ROLE>
         <PRENOM>Kim</PRENOM>
         <NOM>Novak</NOM>
         <INTITULE>Madeleine Elster</INTITULE>
       </ROLE>
     </ROLES>
     <RESUME>Scottie Ferguson, ancien inspecteur de police, est sujet
au vertige depuis qu'il a vu mourir son
  collegue. Elster, son ami, le charge de surveiller sa femme,
Madeleine, ayant des tendances
  suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le
piege qui se trame autour
  de lui et dont il va etre la victime... </RESUME>
   </FILM>




If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/How-to-access-XML-tag-name-tp4884065.html
To unsubscribe from Pharo Smalltalk Users, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

BriceG
In reply to this post by stepharo
 
Hi,

according to what have found in the SAXHandler and XMLDOMParser class, you should use SAXHandler>>characters: method to get the information inside a marker.

Information inside a marker is consider as an XMLString that is created after a call to XMLDOMParser>>characters:.


I hope I helped you with your question. =)



--------------
Brice Govin
PhD student in RMoD research team at INRIA Lille
Software Engineer at THALES AIR SYSTEMS Rungis
ENSTA-Bretagne ENSI2014

22 Avenue du General Leclerc 92340 BOURG-LA-REINE





De : stepharo [via Smalltalk] <ml-node+[hidden email]>
Envoyé : vendredi 11 mars 2016 13:37
À : Brice GOVIN
Objet : How to access XML tag name?
 
Hi

Yesterday I started to hack a smart SAX handler. The idea is that I want
to just specify the tags
I want to visit and the SAX handler should invoke (generated) visit
methods. Like that I can easily
get visitors on XML domain.

Here is an example of what I did.

     | h |
     h := SmartSAXHandler new
                 visitor: (MyFilmVisitor new visitTags: #(FILM ROLE));
                 on: FileSystem workingDirectory / 'FILMS.XML'.
     h parseDocument.
     ^ h



SmartSAXHAndler >> startElement: aQualifiedName attributes: aDictionary

     (visitor shouldVisit: aQualifiedName)
         ifTrue: [
                 visitor
                     perform: (visitor createdVisitSelector: aQualifiedName)
                     with: aQualifiedName
                     with: aDictionary
         ]


Object subclass: #GenericTagSAXVisitor
     instanceVariableNames: 'visitTag visitTags'
     classVariableNames: ''
     category: 'SmartXMLHandler'


GenericTagSAXVisitor>>visitTags: aCollection
     "set the tags that will lead to a call to a visitTag:with: method
in the visitor"

     visitTags := aCollection collect: [ :each | each asLowercase ].
     self createVisitMethods.

and in a subclass the visit* methods automatically generated


Now I could not get when I have a <TITRE>Vertigo</TITRE> where I can get
the Vertigo information.
I redefined several methods of SAXhandler but without success.


<?xml version="1.0" encoding="iso-8859-1"?>
<FILMS>
   <FILM annee="1958">
     <TITRE>Vertigo</TITRE>
     <GENRE>Drame</GENRE>
     <PAYS>USA</PAYS>
     <MES idref="3"/>
     <ROLES>
       <ROLE>
         <PRENOM>James</PRENOM>
         <NOM>Stewart</NOM>
         <INTITULE>John Ferguson</INTITULE>
       </ROLE>
       <ROLE>
         <PRENOM>Kim</PRENOM>
         <NOM>Novak</NOM>
         <INTITULE>Madeleine Elster</INTITULE>
       </ROLE>
     </ROLES>
     <RESUME>Scottie Ferguson, ancien inspecteur de police, est sujet
au vertige depuis qu'il a vu mourir son
  collegue. Elster, son ami, le charge de surveiller sa femme,
Madeleine, ayant des tendances
  suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le
piege qui se trame autour
  de lui et dont il va etre la victime... </RESUME>
   </FILM>




If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/How-to-access-XML-tag-name-tp4884065.html
To unsubscribe from Pharo Smalltalk Users, click here.
NAML


View this message in context: RE: How to access XML tag name?
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

stepharo
In reply to this post by Blondeau Vincent
Thanks

Ok it was characters: I will try it
What a bad name!

I will probably have to build a stack or dictionary of dictionary of the
part that I will not want to visit but this is another story :)

Stef


Le 11/3/16 14:17, Blondeau Vincent a écrit :

> Hi,
>
> The qualified name in function startElement: aQualifiedName attributes: aDictionary, will be FILMS and after FILM and after TITRE,...etc...
> So, you have to tell to your shouldVisit: method to accept TITRE too and get in and after you should implement characters: to get the content on the tag.
>
> Vincent
>
>> -----Message d'origine-----
>> De : Pharo-users [mailto:[hidden email]] De la part de
>> stepharo
>> Envoyé : vendredi 11 mars 2016 14:04
>> À : Any question about pharo is welcome
>> Objet : [Pharo-users] How to access XML tag name?
>>
>> Hi
>>
>> Yesterday I started to hack a smart SAX handler. The idea is that I want to just
>> specify the tags I want to visit and the SAX handler should invoke (generated)
>> visit methods. Like that I can easily get visitors on XML domain.
>>
>> Here is an example of what I did.
>>
>>       | h |
>>       h := SmartSAXHandler new
>>                   visitor: (MyFilmVisitor new visitTags: #(FILM ROLE));
>>                   on: FileSystem workingDirectory / 'FILMS.XML'.
>>       h parseDocument.
>>       ^ h
>>
>>
>>
>> SmartSAXHAndler >> startElement: aQualifiedName attributes: aDictionary
>>
>>       (visitor shouldVisit: aQualifiedName)
>>           ifTrue: [
>>                   visitor
>>                       perform: (visitor createdVisitSelector: aQualifiedName)
>>                       with: aQualifiedName
>>                       with: aDictionary
>>           ]
>>
>>
>> Object subclass: #GenericTagSAXVisitor
>>       instanceVariableNames: 'visitTag visitTags'
>>       classVariableNames: ''
>>       category: 'SmartXMLHandler'
>>
>>
>> GenericTagSAXVisitor>>visitTags: aCollection
>>       "set the tags that will lead to a call to a visitTag:with: method in the visitor"
>>
>>       visitTags := aCollection collect: [ :each | each asLowercase ].
>>       self createVisitMethods.
>>
>> and in a subclass the visit* methods automatically generated
>>
>>
>> Now I could not get when I have a <TITRE>Vertigo</TITRE> where I can get the
>> Vertigo information.
>> I redefined several methods of SAXhandler but without success.
>>
>>
>> <?xml version="1.0" encoding="iso-8859-1"?>
>> <FILMS>
>>     <FILM annee="1958">
>>       <TITRE>Vertigo</TITRE>
>>       <GENRE>Drame</GENRE>
>>       <PAYS>USA</PAYS>
>>       <MES idref="3"/>
>>       <ROLES>
>>         <ROLE>
>>           <PRENOM>James</PRENOM>
>>           <NOM>Stewart</NOM>
>>           <INTITULE>John Ferguson</INTITULE>
>>         </ROLE>
>>         <ROLE>
>>           <PRENOM>Kim</PRENOM>
>>           <NOM>Novak</NOM>
>>           <INTITULE>Madeleine Elster</INTITULE>
>>         </ROLE>
>>       </ROLES>
>>       <RESUME>Scottie Ferguson, ancien inspecteur de police, est sujet
>> au vertige depuis qu'il a vu mourir son
>>    collegue. Elster, son ami, le charge de surveiller sa femme,
>> Madeleine, ayant des tendances
>>    suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le
>> piege qui se trame autour
>>    de lui et dont il va etre la victime... </RESUME>
>>     </FILM>
>
> !!!*************************************************************************************
> "Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité de Worldline ne pourra être recherchée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être recherchée pour tout dommage résultant d'un virus transmis.
>
> This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Worldline liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.!!!"


Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

stepharo
In reply to this post by Blondeau Vincent
This is more complex than that.
Because I would like to have a visitor generated from the token I give.

And this
     start
     character
     end

does not really help me.

Because in SAXHandler I have
         start
             where I should store the properties
        same in characters:
             to store the name
        end
             where I should invoke the visitor

Now it means that I should only store the information for the tag I want.
Does anybody already did that and publish it?
I know doru did that in the past.
I will try.

Stef



Le 11/3/16 14:17, Blondeau Vincent a écrit :

> Hi,
>
> The qualified name in function startElement: aQualifiedName attributes: aDictionary, will be FILMS and after FILM and after TITRE,...etc...
> So, you have to tell to your shouldVisit: method to accept TITRE too and get in and after you should implement characters: to get the content on the tag.
>
> Vincent
>
>> -----Message d'origine-----
>> De : Pharo-users [mailto:[hidden email]] De la part de
>> stepharo
>> Envoyé : vendredi 11 mars 2016 14:04
>> À : Any question about pharo is welcome
>> Objet : [Pharo-users] How to access XML tag name?
>>
>> Hi
>>
>> Yesterday I started to hack a smart SAX handler. The idea is that I want to just
>> specify the tags I want to visit and the SAX handler should invoke (generated)
>> visit methods. Like that I can easily get visitors on XML domain.
>>
>> Here is an example of what I did.
>>
>>       | h |
>>       h := SmartSAXHandler new
>>                   visitor: (MyFilmVisitor new visitTags: #(FILM ROLE));
>>                   on: FileSystem workingDirectory / 'FILMS.XML'.
>>       h parseDocument.
>>       ^ h
>>
>>
>>
>> SmartSAXHAndler >> startElement: aQualifiedName attributes: aDictionary
>>
>>       (visitor shouldVisit: aQualifiedName)
>>           ifTrue: [
>>                   visitor
>>                       perform: (visitor createdVisitSelector: aQualifiedName)
>>                       with: aQualifiedName
>>                       with: aDictionary
>>           ]
>>
>>
>> Object subclass: #GenericTagSAXVisitor
>>       instanceVariableNames: 'visitTag visitTags'
>>       classVariableNames: ''
>>       category: 'SmartXMLHandler'
>>
>>
>> GenericTagSAXVisitor>>visitTags: aCollection
>>       "set the tags that will lead to a call to a visitTag:with: method in the visitor"
>>
>>       visitTags := aCollection collect: [ :each | each asLowercase ].
>>       self createVisitMethods.
>>
>> and in a subclass the visit* methods automatically generated
>>
>>
>> Now I could not get when I have a <TITRE>Vertigo</TITRE> where I can get the
>> Vertigo information.
>> I redefined several methods of SAXhandler but without success.
>>
>>
>> <?xml version="1.0" encoding="iso-8859-1"?>
>> <FILMS>
>>     <FILM annee="1958">
>>       <TITRE>Vertigo</TITRE>
>>       <GENRE>Drame</GENRE>
>>       <PAYS>USA</PAYS>
>>       <MES idref="3"/>
>>       <ROLES>
>>         <ROLE>
>>           <PRENOM>James</PRENOM>
>>           <NOM>Stewart</NOM>
>>           <INTITULE>John Ferguson</INTITULE>
>>         </ROLE>
>>         <ROLE>
>>           <PRENOM>Kim</PRENOM>
>>           <NOM>Novak</NOM>
>>           <INTITULE>Madeleine Elster</INTITULE>
>>         </ROLE>
>>       </ROLES>
>>       <RESUME>Scottie Ferguson, ancien inspecteur de police, est sujet
>> au vertige depuis qu'il a vu mourir son
>>    collegue. Elster, son ami, le charge de surveiller sa femme,
>> Madeleine, ayant des tendances
>>    suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le
>> piege qui se trame autour
>>    de lui et dont il va etre la victime... </RESUME>
>>     </FILM>
>
> !!!*************************************************************************************
> "Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité de Worldline ne pourra être recherchée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être recherchée pour tout dommage résultant d'un virus transmis.
>
> This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Worldline liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.!!!"


Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

hernanmd
Hi Stephane,

Do you want to extract subtree from a XML?
Or just extract the text in specific nodes?

I think StAX parser is more friendly for selecting nodes (you don't have to subclass), i.e.:

| parser doc |
doc := '<?xml version="1.0" encoding="iso-8859-1"?>
<FILMS>
  <FILM annee="1958">
    <TITRE>Vertigo</TITRE>
    <GENRE>Drame</GENRE>
    <PAYS>USA</PAYS>
    <MES idref="3"/>
    <ROLES>
      <ROLE>
        <PRENOM>James</PRENOM>
        <NOM>Stewart</NOM>
        <INTITULE>John Ferguson</INTITULE>
      </ROLE>
      <ROLE>
        <PRENOM>Kim</PRENOM>
        <NOM>Novak</NOM>
        <INTITULE>Madeleine Elster</INTITULE>
      </ROLE>
    </ROLES>
    <RESUME>Scottie Ferguson, ancien inspecteur de police, est sujet
au vertige depuis qu''il a vu mourir son
 collegue. Elster, son ami, le charge de surveiller sa femme, Madeleine, ayant des tendances
 suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le piege qui se trame autour
 de lui et dont il va etre la victime... </RESUME>
  </FILM>
<FILMS>'.
parser := XMLPullParser parse: doc.
[ parser isEndDocument ] whileFalse: [
    parser
        if: 'FILM'
        peek: [ : found |
            Transcript show: found name , ' -> ' , found attributes asString; cr.
            parser next.
            Transcript show: parser tagName ].
    parser next ]

Anyway if you want to try with SAX, have a look at #test01ParsingNodes and add some halts in BioNCBIBlastSAXParser to see it in action (that's in BioSmalltalk). I didn't used visitors though.

Hernán

2016-03-12 5:33 GMT-03:00 stepharo <[hidden email]>:
This is more complex than that.
Because I would like to have a visitor generated from the token I give.

And this
    start
    character
    end

does not really help me.

Because in SAXHandler I have
        start
            where I should store the properties
       same in characters:
            to store the name
       end
            where I should invoke the visitor

Now it means that I should only store the information for the tag I want.
Does anybody already did that and publish it?
I know doru did that in the past.
I will try.

Stef



Le 11/3/16 14:17, Blondeau Vincent a écrit :
Hi,


The qualified name in function startElement: aQualifiedName attributes: aDictionary, will be FILMS and after FILM and after TITRE,...etc...
So, you have to tell to your shouldVisit: method to accept TITRE too and get in and after you should implement characters: to get the content on the tag.

Vincent

-----Message d'origine-----
De : Pharo-users [mailto:[hidden email]] De la part de
stepharo
Envoyé : vendredi 11 mars 2016 14:04
À : Any question about pharo is welcome
Objet : [Pharo-users] How to access XML tag name?

Hi

Yesterday I started to hack a smart SAX handler. The idea is that I want to just
specify the tags I want to visit and the SAX handler should invoke (generated)
visit methods. Like that I can easily get visitors on XML domain.

Here is an example of what I did.

      | h |
      h := SmartSAXHandler new
                  visitor: (MyFilmVisitor new visitTags: #(FILM ROLE));
                  on: FileSystem workingDirectory / 'FILMS.XML'.
      h parseDocument.
      ^ h



SmartSAXHAndler >> startElement: aQualifiedName attributes: aDictionary

      (visitor shouldVisit: aQualifiedName)
          ifTrue: [
                  visitor
                      perform: (visitor createdVisitSelector: aQualifiedName)
                      with: aQualifiedName
                      with: aDictionary
          ]


Object subclass: #GenericTagSAXVisitor
      instanceVariableNames: 'visitTag visitTags'
      classVariableNames: ''
      category: 'SmartXMLHandler'


GenericTagSAXVisitor>>visitTags: aCollection
      "set the tags that will lead to a call to a visitTag:with: method in the visitor"

      visitTags := aCollection collect: [ :each | each asLowercase ].
      self createVisitMethods.

and in a subclass the visit* methods automatically generated


Now I could not get when I have a <TITRE>Vertigo</TITRE> where I can get the
Vertigo information.
I redefined several methods of SAXhandler but without success.


<?xml version="1.0" encoding="iso-8859-1"?>
<FILMS>
    <FILM annee="1958">
      <TITRE>Vertigo</TITRE>
      <GENRE>Drame</GENRE>
      <PAYS>USA</PAYS>
      <MES idref="3"/>
      <ROLES>
        <ROLE>
          <PRENOM>James</PRENOM>
          <NOM>Stewart</NOM>
          <INTITULE>John Ferguson</INTITULE>
        </ROLE>
        <ROLE>
          <PRENOM>Kim</PRENOM>
          <NOM>Novak</NOM>
          <INTITULE>Madeleine Elster</INTITULE>
        </ROLE>
      </ROLES>
      <RESUME>Scottie Ferguson, ancien inspecteur de police, est sujet
au vertige depuis qu'il a vu mourir son
   collegue. Elster, son ami, le charge de surveiller sa femme,
Madeleine, ayant des tendances
   suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le
piege qui se trame autour
   de lui et dont il va etre la victime... </RESUME>
    </FILM>

!!!*************************************************************************************
"Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité de Worldline ne pourra être recherchée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être recherchée pour tout dommage résultant d'un virus transmis.

This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Worldline liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.!!!"



Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

Tudor Girba-2
In reply to this post by stepharo
Hi,

My original work only survived for the XMLDOMParser. See this example:
(paste this in Spotter :))

For an XMLDOMParser, you can say that you want to instantiate a node in the DOM with an custom instance. For example, here I instantiate <NOM> with AAAName:


You are looking for something a bit different. In a way you want to associate the triggering of a specific handler when some XPath like expression is being matched for the current element. I think something like this should go in the main implementation.

Cheers,
Doru



On Mar 12, 2016, at 9:33 AM, stepharo <[hidden email]> wrote:

This is more complex than that.
Because I would like to have a visitor generated from the token I give.

And this
   start
   character
   end

does not really help me.

Because in SAXHandler I have
       start
           where I should store the properties
      same in characters:
           to store the name
      end
           where I should invoke the visitor

Now it means that I should only store the information for the tag I want.
Does anybody already did that and publish it?
I know doru did that in the past.
I will try.

Stef



Le 11/3/16 14:17, Blondeau Vincent a écrit :
Hi,

The qualified name in function startElement: aQualifiedName attributes: aDictionary, will be FILMS and after FILM and after TITRE,...etc...
So, you have to tell to your shouldVisit: method to accept TITRE too and get in and after you should implement characters: to get the content on the tag.

Vincent

-----Message d'origine-----
De : Pharo-users [[hidden email]] De la part de
stepharo
Envoyé : vendredi 11 mars 2016 14:04
À : Any question about pharo is welcome
Objet : [Pharo-users] How to access XML tag name?

Hi

Yesterday I started to hack a smart SAX handler. The idea is that I want to just
specify the tags I want to visit and the SAX handler should invoke (generated)
visit methods. Like that I can easily get visitors on XML domain.

Here is an example of what I did.

     | h |
     h := SmartSAXHandler new
                 visitor: (MyFilmVisitor new visitTags: #(FILM ROLE));
                 on: FileSystem workingDirectory / 'FILMS.XML'.
     h parseDocument.
     ^ h



SmartSAXHAndler >> startElement: aQualifiedName attributes: aDictionary

     (visitor shouldVisit: aQualifiedName)
         ifTrue: [
                 visitor
                     perform: (visitor createdVisitSelector: aQualifiedName)
                     with: aQualifiedName
                     with: aDictionary
         ]


Object subclass: #GenericTagSAXVisitor
     instanceVariableNames: 'visitTag visitTags'
     classVariableNames: ''
     category: 'SmartXMLHandler'


GenericTagSAXVisitor>>visitTags: aCollection
     "set the tags that will lead to a call to a visitTag:with: method in the visitor"

     visitTags := aCollection collect: [ :each | each asLowercase ].
     self createVisitMethods.

and in a subclass the visit* methods automatically generated


Now I could not get when I have a <TITRE>Vertigo</TITRE> where I can get the
Vertigo information.
I redefined several methods of SAXhandler but without success.


<?xml version="1.0" encoding="iso-8859-1"?>
<FILMS>
   <FILM annee="1958">
     <TITRE>Vertigo</TITRE>
     <GENRE>Drame</GENRE>
     <PAYS>USA</PAYS>
     <MES idref="3"/>
     <ROLES>
       <ROLE>
         <PRENOM>James</PRENOM>
         <NOM>Stewart</NOM>
         <INTITULE>John Ferguson</INTITULE>
       </ROLE>
       <ROLE>
         <PRENOM>Kim</PRENOM>
         <NOM>Novak</NOM>
         <INTITULE>Madeleine Elster</INTITULE>
       </ROLE>
     </ROLES>
     <RESUME>Scottie Ferguson, ancien inspecteur de police, est sujet
au vertige depuis qu'il a vu mourir son
  collegue. Elster, son ami, le charge de surveiller sa femme,
Madeleine, ayant des tendances
  suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le
piege qui se trame autour
  de lui et dont il va etre la victime... </RESUME>
   </FILM>

!!!*************************************************************************************
"Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité de Worldline ne pourra être recherchée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être recherchée pour tout dommage résultant d'un virus transmis.

This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Worldline liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.!!!"



--
www.tudorgirba.com
www.feenk.com

"We can create beautiful models in a vacuum.
But, to get them effective we have to deal with the inconvenience of reality."

Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

abergel
In reply to this post by stepharo
Hi Stef,

I have the impression that a visitor is not the ideal solution to query XML tree. It works well in some case, and it is disastrous in some other.
XPath is the way to query XML data. As far as I know, there is no complete support. Pastell was a nice try however...

Alexandre


> On Mar 12, 2016, at 8:11 AM, stepharo <[hidden email]> wrote:
>
> Thanks
>
> Ok it was characters: I will try it
> What a bad name!
>
> I will probably have to build a stack or dictionary of dictionary of the part that I will not want to visit but this is another story :)
>
> Stef
>
>
> Le 11/3/16 14:17, Blondeau Vincent a écrit :
>> Hi,
>>
>> The qualified name in function startElement: aQualifiedName attributes: aDictionary, will be FILMS and after FILM and after TITRE,...etc...
>> So, you have to tell to your shouldVisit: method to accept TITRE too and get in and after you should implement characters: to get the content on the tag.
>>
>> Vincent
>>
>>> -----Message d'origine-----
>>> De : Pharo-users [mailto:[hidden email]] De la part de
>>> stepharo
>>> Envoyé : vendredi 11 mars 2016 14:04
>>> À : Any question about pharo is welcome
>>> Objet : [Pharo-users] How to access XML tag name?
>>>
>>> Hi
>>>
>>> Yesterday I started to hack a smart SAX handler. The idea is that I want to just
>>> specify the tags I want to visit and the SAX handler should invoke (generated)
>>> visit methods. Like that I can easily get visitors on XML domain.
>>>
>>> Here is an example of what I did.
>>>
>>>      | h |
>>>      h := SmartSAXHandler new
>>>                  visitor: (MyFilmVisitor new visitTags: #(FILM ROLE));
>>>                  on: FileSystem workingDirectory / 'FILMS.XML'.
>>>      h parseDocument.
>>>      ^ h
>>>
>>>
>>>
>>> SmartSAXHAndler >> startElement: aQualifiedName attributes: aDictionary
>>>
>>>      (visitor shouldVisit: aQualifiedName)
>>>          ifTrue: [
>>>                  visitor
>>>                      perform: (visitor createdVisitSelector: aQualifiedName)
>>>                      with: aQualifiedName
>>>                      with: aDictionary
>>>          ]
>>>
>>>
>>> Object subclass: #GenericTagSAXVisitor
>>>      instanceVariableNames: 'visitTag visitTags'
>>>      classVariableNames: ''
>>>      category: 'SmartXMLHandler'
>>>
>>>
>>> GenericTagSAXVisitor>>visitTags: aCollection
>>>      "set the tags that will lead to a call to a visitTag:with: method in the visitor"
>>>
>>>      visitTags := aCollection collect: [ :each | each asLowercase ].
>>>      self createVisitMethods.
>>>
>>> and in a subclass the visit* methods automatically generated
>>>
>>>
>>> Now I could not get when I have a <TITRE>Vertigo</TITRE> where I can get the
>>> Vertigo information.
>>> I redefined several methods of SAXhandler but without success.
>>>
>>>
>>> <?xml version="1.0" encoding="iso-8859-1"?>
>>> <FILMS>
>>>    <FILM annee="1958">
>>>      <TITRE>Vertigo</TITRE>
>>>      <GENRE>Drame</GENRE>
>>>      <PAYS>USA</PAYS>
>>>      <MES idref="3"/>
>>>      <ROLES>
>>>        <ROLE>
>>>          <PRENOM>James</PRENOM>
>>>          <NOM>Stewart</NOM>
>>>          <INTITULE>John Ferguson</INTITULE>
>>>        </ROLE>
>>>        <ROLE>
>>>          <PRENOM>Kim</PRENOM>
>>>          <NOM>Novak</NOM>
>>>          <INTITULE>Madeleine Elster</INTITULE>
>>>        </ROLE>
>>>      </ROLES>
>>>      <RESUME>Scottie Ferguson, ancien inspecteur de police, est sujet
>>> au vertige depuis qu'il a vu mourir son
>>>   collegue. Elster, son ami, le charge de surveiller sa femme,
>>> Madeleine, ayant des tendances
>>>   suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le
>>> piege qui se trame autour
>>>   de lui et dont il va etre la victime... </RESUME>
>>>    </FILM>
>>
>> !!!*************************************************************************************
>> "Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité de Worldline ne pourra être recherchée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être recherchée pour tout dommage résultant d'un virus transmis.
>>
>> This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Worldline liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.!!!"
>
>

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.




Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

stepharo
In reply to this post by hernanmd
Hi hernan

I do not what I want :).
Irina a woman learning Pharo has a xml output from a tool (I have no idea what is inside :)
and I thought ok this is a good idea to check a bit the solutions in Pharo.

I will add your example to the PullParser Chapter. Because I like the Pull approach
I'm doing a pass on OPAX package because it was cool too.

Stef

Le 12/3/16 09:53, Hernán Morales Durand a écrit :
Hi Stephane,

Do you want to extract subtree from a XML?
Or just extract the text in specific nodes?

I think StAX parser is more friendly for selecting nodes (you don't have to subclass), i.e.:

| parser doc |
doc := '<?xml version="1.0" encoding="iso-8859-1"?>
<FILMS>
  <FILM annee="1958">
    <TITRE>Vertigo</TITRE>
    <GENRE>Drame</GENRE>
    <PAYS>USA</PAYS>
    <MES idref="3"/>
    <ROLES>
      <ROLE>
        <PRENOM>James</PRENOM>
        <NOM>Stewart</NOM>
        <INTITULE>John Ferguson</INTITULE>
      </ROLE>
      <ROLE>
        <PRENOM>Kim</PRENOM>
        <NOM>Novak</NOM>
        <INTITULE>Madeleine Elster</INTITULE>
      </ROLE>
    </ROLES>
    <RESUME>Scottie Ferguson, ancien inspecteur de police, est sujet
au vertige depuis qu''il a vu mourir son
 collegue. Elster, son ami, le charge de surveiller sa femme, Madeleine, ayant des tendances
 suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le piege qui se trame autour
 de lui et dont il va etre la victime... </RESUME>
  </FILM>
<FILMS>'.
parser := XMLPullParser parse: doc.
[ parser isEndDocument ] whileFalse: [
    parser
        if: 'FILM'
        peek: [ : found |
            Transcript show: found name , ' -> ' , found attributes asString; cr.
            parser next.
            Transcript show: parser tagName ].
    parser next ]

Anyway if you want to try with SAX, have a look at #test01ParsingNodes and add some halts in BioNCBIBlastSAXParser to see it in action (that's in BioSmalltalk). I didn't used visitors though.

Hernán

2016-03-12 5:33 GMT-03:00 stepharo <[hidden email]>:
This is more complex than that.
Because I would like to have a visitor generated from the token I give.

And this
    start
    character
    end

does not really help me.

Because in SAXHandler I have
        start
            where I should store the properties
       same in characters:
            to store the name
       end
            where I should invoke the visitor

Now it means that I should only store the information for the tag I want.
Does anybody already did that and publish it?
I know doru did that in the past.
I will try.

Stef



Le 11/3/16 14:17, Blondeau Vincent a écrit :
Hi,


The qualified name in function startElement: aQualifiedName attributes: aDictionary, will be FILMS and after FILM and after TITRE,...etc...
So, you have to tell to your shouldVisit: method to accept TITRE too and get in and after you should implement characters: to get the content on the tag.

Vincent

-----Message d'origine-----
De : Pharo-users [mailto:[hidden email]] De la part de
stepharo
Envoyé : vendredi 11 mars 2016 14:04
À : Any question about pharo is welcome
Objet : [Pharo-users] How to access XML tag name?

Hi

Yesterday I started to hack a smart SAX handler. The idea is that I want to just
specify the tags I want to visit and the SAX handler should invoke (generated)
visit methods. Like that I can easily get visitors on XML domain.

Here is an example of what I did.

      | h |
      h := SmartSAXHandler new
                  visitor: (MyFilmVisitor new visitTags: #(FILM ROLE));
                  on: FileSystem workingDirectory / 'FILMS.XML'.
      h parseDocument.
      ^ h



SmartSAXHAndler >> startElement: aQualifiedName attributes: aDictionary

      (visitor shouldVisit: aQualifiedName)
          ifTrue: [
                  visitor
                      perform: (visitor createdVisitSelector: aQualifiedName)
                      with: aQualifiedName
                      with: aDictionary
          ]


Object subclass: #GenericTagSAXVisitor
      instanceVariableNames: 'visitTag visitTags'
      classVariableNames: ''
      category: 'SmartXMLHandler'


GenericTagSAXVisitor>>visitTags: aCollection
      "set the tags that will lead to a call to a visitTag:with: method in the visitor"

      visitTags := aCollection collect: [ :each | each asLowercase ].
      self createVisitMethods.

and in a subclass the visit* methods automatically generated


Now I could not get when I have a <TITRE>Vertigo</TITRE> where I can get the
Vertigo information.
I redefined several methods of SAXhandler but without success.


<?xml version="1.0" encoding="iso-8859-1"?>
<FILMS>
    <FILM annee="1958">
      <TITRE>Vertigo</TITRE>
      <GENRE>Drame</GENRE>
      <PAYS>USA</PAYS>
      <MES idref="3"/>
      <ROLES>
        <ROLE>
          <PRENOM>James</PRENOM>
          <NOM>Stewart</NOM>
          <INTITULE>John Ferguson</INTITULE>
        </ROLE>
        <ROLE>
          <PRENOM>Kim</PRENOM>
          <NOM>Novak</NOM>
          <INTITULE>Madeleine Elster</INTITULE>
        </ROLE>
      </ROLES>
      <RESUME>Scottie Ferguson, ancien inspecteur de police, est sujet
au vertige depuis qu'il a vu mourir son
   collegue. Elster, son ami, le charge de surveiller sa femme,
Madeleine, ayant des tendances
   suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le
piege qui se trame autour
   de lui et dont il va etre la victime... </RESUME>
    </FILM>

!!!*************************************************************************************
"Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité de Worldline ne pourra être recherchée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être recherchée pour tout dommage résultant d'un virus transmis.

This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Worldline liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.!!!"




Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

stepharo
In reply to this post by Tudor Girba-2
Hi doru

I was also looking at OPAX and doing a cleaning pass.
Plus adding a little builder to get the subnodes automatically generated.
I'm writing a little doc too.

Stef

Le 12/3/16 21:59, Tudor Girba a écrit :
Hi,

My original work only survived for the XMLDOMParser. See this example:
(paste this in Spotter :))

For an XMLDOMParser, you can say that you want to instantiate a node in the DOM with an custom instance. For example, here I instantiate <NOM> with AAAName:


You are looking for something a bit different. In a way you want to associate the triggering of a specific handler when some XPath like expression is being matched for the current element. I think something like this should go in the main implementation.

Cheers,
Doru



On Mar 12, 2016, at 9:33 AM, stepharo <[hidden email]> wrote:

This is more complex than that.
Because I would like to have a visitor generated from the token I give.

And this
   start
   character
   end

does not really help me.

Because in SAXHandler I have
       start
           where I should store the properties
      same in characters:
           to store the name
      end
           where I should invoke the visitor

Now it means that I should only store the information for the tag I want.
Does anybody already did that and publish it?
I know doru did that in the past.
I will try.

Stef



Le 11/3/16 14:17, Blondeau Vincent a écrit :
Hi,

The qualified name in function startElement: aQualifiedName attributes: aDictionary, will be FILMS and after FILM and after TITRE,...etc...
So, you have to tell to your shouldVisit: method to accept TITRE too and get in and after you should implement characters: to get the content on the tag.

Vincent

-----Message d'origine-----
De : Pharo-users [[hidden email]] De la part de
stepharo
Envoyé : vendredi 11 mars 2016 14:04
À : Any question about pharo is welcome
Objet : [Pharo-users] How to access XML tag name?

Hi

Yesterday I started to hack a smart SAX handler. The idea is that I want to just
specify the tags I want to visit and the SAX handler should invoke (generated)
visit methods. Like that I can easily get visitors on XML domain.

Here is an example of what I did.

     | h |
     h := SmartSAXHandler new
                 visitor: (MyFilmVisitor new visitTags: #(FILM ROLE));
                 on: FileSystem workingDirectory / 'FILMS.XML'.
     h parseDocument.
     ^ h



SmartSAXHAndler >> startElement: aQualifiedName attributes: aDictionary

     (visitor shouldVisit: aQualifiedName)
         ifTrue: [
                 visitor
                     perform: (visitor createdVisitSelector: aQualifiedName)
                     with: aQualifiedName
                     with: aDictionary
         ]


Object subclass: #GenericTagSAXVisitor
     instanceVariableNames: 'visitTag visitTags'
     classVariableNames: ''
     category: 'SmartXMLHandler'


GenericTagSAXVisitor>>visitTags: aCollection
     "set the tags that will lead to a call to a visitTag:with: method in the visitor"

     visitTags := aCollection collect: [ :each | each asLowercase ].
     self createVisitMethods.

and in a subclass the visit* methods automatically generated


Now I could not get when I have a <TITRE>Vertigo</TITRE> where I can get the
Vertigo information.
I redefined several methods of SAXhandler but without success.


<?xml version="1.0" encoding="iso-8859-1"?>
<FILMS>
   <FILM annee="1958">
     <TITRE>Vertigo</TITRE>
     <GENRE>Drame</GENRE>
     <PAYS>USA</PAYS>
     <MES idref="3"/>
     <ROLES>
       <ROLE>
         <PRENOM>James</PRENOM>
         <NOM>Stewart</NOM>
         <INTITULE>John Ferguson</INTITULE>
       </ROLE>
       <ROLE>
         <PRENOM>Kim</PRENOM>
         <NOM>Novak</NOM>
         <INTITULE>Madeleine Elster</INTITULE>
       </ROLE>
     </ROLES>
     <RESUME>Scottie Ferguson, ancien inspecteur de police, est sujet
au vertige depuis qu'il a vu mourir son
  collegue. Elster, son ami, le charge de surveiller sa femme,
Madeleine, ayant des tendances
  suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le
piege qui se trame autour
  de lui et dont il va etre la victime... </RESUME>
   </FILM>

!!!*************************************************************************************
"Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité de Worldline ne pourra être recherchée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être recherchée pour tout dommage résultant d'un virus transmis.

This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Worldline liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.!!!"



--
www.tudorgirba.com
www.feenk.com

"We can create beautiful models in a vacuum.
But, to get them effective we have to deal with the inconvenience of reality."


Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

stepharo
In reply to this post by Tudor Girba-2
I have the impression that I should also look at

    XMLPluggableElementFactory new handleElement: 'NOM' withClass: AAAName.

Because it looks like that I inject my nodes inside the dom

Am I correct?


Le 12/3/16 21:59, Tudor Girba a écrit :
Hi,

My original work only survived for the XMLDOMParser. See this example:
(paste this in Spotter :))

For an XMLDOMParser, you can say that you want to instantiate a node in the DOM with an custom instance. For example, here I instantiate <NOM> with AAAName:


You are looking for something a bit different. In a way you want to associate the triggering of a specific handler when some XPath like expression is being matched for the current element. I think something like this should go in the main implementation.

Cheers,
Doru



On Mar 12, 2016, at 9:33 AM, stepharo <[hidden email]> wrote:

This is more complex than that.
Because I would like to have a visitor generated from the token I give.

And this
   start
   character
   end

does not really help me.

Because in SAXHandler I have
       start
           where I should store the properties
      same in characters:
           to store the name
      end
           where I should invoke the visitor

Now it means that I should only store the information for the tag I want.
Does anybody already did that and publish it?
I know doru did that in the past.
I will try.

Stef



Le 11/3/16 14:17, Blondeau Vincent a écrit :
Hi,

The qualified name in function startElement: aQualifiedName attributes: aDictionary, will be FILMS and after FILM and after TITRE,...etc...
So, you have to tell to your shouldVisit: method to accept TITRE too and get in and after you should implement characters: to get the content on the tag.

Vincent

-----Message d'origine-----
De : Pharo-users [[hidden email]] De la part de
stepharo
Envoyé : vendredi 11 mars 2016 14:04
À : Any question about pharo is welcome
Objet : [Pharo-users] How to access XML tag name?

Hi

Yesterday I started to hack a smart SAX handler. The idea is that I want to just
specify the tags I want to visit and the SAX handler should invoke (generated)
visit methods. Like that I can easily get visitors on XML domain.

Here is an example of what I did.

     | h |
     h := SmartSAXHandler new
                 visitor: (MyFilmVisitor new visitTags: #(FILM ROLE));
                 on: FileSystem workingDirectory / 'FILMS.XML'.
     h parseDocument.
     ^ h



SmartSAXHAndler >> startElement: aQualifiedName attributes: aDictionary

     (visitor shouldVisit: aQualifiedName)
         ifTrue: [
                 visitor
                     perform: (visitor createdVisitSelector: aQualifiedName)
                     with: aQualifiedName
                     with: aDictionary
         ]


Object subclass: #GenericTagSAXVisitor
     instanceVariableNames: 'visitTag visitTags'
     classVariableNames: ''
     category: 'SmartXMLHandler'


GenericTagSAXVisitor>>visitTags: aCollection
     "set the tags that will lead to a call to a visitTag:with: method in the visitor"

     visitTags := aCollection collect: [ :each | each asLowercase ].
     self createVisitMethods.

and in a subclass the visit* methods automatically generated


Now I could not get when I have a <TITRE>Vertigo</TITRE> where I can get the
Vertigo information.
I redefined several methods of SAXhandler but without success.


<?xml version="1.0" encoding="iso-8859-1"?>
<FILMS>
   <FILM annee="1958">
     <TITRE>Vertigo</TITRE>
     <GENRE>Drame</GENRE>
     <PAYS>USA</PAYS>
     <MES idref="3"/>
     <ROLES>
       <ROLE>
         <PRENOM>James</PRENOM>
         <NOM>Stewart</NOM>
         <INTITULE>John Ferguson</INTITULE>
       </ROLE>
       <ROLE>
         <PRENOM>Kim</PRENOM>
         <NOM>Novak</NOM>
         <INTITULE>Madeleine Elster</INTITULE>
       </ROLE>
     </ROLES>
     <RESUME>Scottie Ferguson, ancien inspecteur de police, est sujet
au vertige depuis qu'il a vu mourir son
  collegue. Elster, son ami, le charge de surveiller sa femme,
Madeleine, ayant des tendances
  suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le
piege qui se trame autour
  de lui et dont il va etre la victime... </RESUME>
   </FILM>

!!!*************************************************************************************
"Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité de Worldline ne pourra être recherchée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être recherchée pour tout dommage résultant d'un virus transmis.

This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Worldline liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.!!!"



--
www.tudorgirba.com
www.feenk.com

"We can create beautiful models in a vacuum.
But, to get them effective we have to deal with the inconvenience of reality."


Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

stepharo
In reply to this post by abergel
Hi alex

I do not know :)
I like visitor because they are better than a series of if.
So I will see. I would like to help people to extract their information
easily.
May be inside the visitNode I could use XPath (do you know what is the
constraint to use XPath)
does it work on dom objects?

I would like to have something like that (being able to use some node to
perform custom actions)
Now I do not see how from one visit method I can access the other. and
if I do not do it in the visit
what is the information I should store (like parent link) to be able to
identify that a given role is associated to a given film.

visitFilm
     title := self extractFromChildren: #Titre.
     pays := self extractFromChildren: #Pays.
     self newFilm: title from: pays.


visitRole

  <FILM annee="1958">
      <TITRE>Vertigo</TITRE>
      <GENRE>Drame</GENRE>
      <PAYS>USA</PAYS>
      <MES idref="3"/>
      <ROLES>
        <ROLE>
          <PRENOM>James</PRENOM>
          <NOM>Stewart</NOM>
          <INTITULE>John Ferguson</INTITULE>
        </ROLE>
        <ROLE>
          <PRENOM>Kim</PRENOM>
          <NOM>Novak</NOM>
          <INTITULE>Madeleine Elster</INTITULE>
        </ROLE>



Stef


Le 13/3/16 11:26, Alexandre Bergel a écrit :

> Hi Stef,
>
> I have the impression that a visitor is not the ideal solution to query XML tree. It works well in some case, and it is disastrous in some other.
> XPath is the way to query XML data. As far as I know, there is no complete support. Pastell was a nice try however...
>
> Alexandre
>
>
>> On Mar 12, 2016, at 8:11 AM, stepharo <[hidden email]> wrote:
>>
>> Thanks
>>
>> Ok it was characters: I will try it
>> What a bad name!
>>
>> I will probably have to build a stack or dictionary of dictionary of the part that I will not want to visit but this is another story :)
>>
>> Stef
>>
>>
>> Le 11/3/16 14:17, Blondeau Vincent a écrit :
>>> Hi,
>>>
>>> The qualified name in function startElement: aQualifiedName attributes: aDictionary, will be FILMS and after FILM and after TITRE,...etc...
>>> So, you have to tell to your shouldVisit: method to accept TITRE too and get in and after you should implement characters: to get the content on the tag.
>>>
>>> Vincent
>>>
>>>> -----Message d'origine-----
>>>> De : Pharo-users [mailto:[hidden email]] De la part de
>>>> stepharo
>>>> Envoyé : vendredi 11 mars 2016 14:04
>>>> À : Any question about pharo is welcome
>>>> Objet : [Pharo-users] How to access XML tag name?
>>>>
>>>> Hi
>>>>
>>>> Yesterday I started to hack a smart SAX handler. The idea is that I want to just
>>>> specify the tags I want to visit and the SAX handler should invoke (generated)
>>>> visit methods. Like that I can easily get visitors on XML domain.
>>>>
>>>> Here is an example of what I did.
>>>>
>>>>       | h |
>>>>       h := SmartSAXHandler new
>>>>                   visitor: (MyFilmVisitor new visitTags: #(FILM ROLE));
>>>>                   on: FileSystem workingDirectory / 'FILMS.XML'.
>>>>       h parseDocument.
>>>>       ^ h
>>>>
>>>>
>>>>
>>>> SmartSAXHAndler >> startElement: aQualifiedName attributes: aDictionary
>>>>
>>>>       (visitor shouldVisit: aQualifiedName)
>>>>           ifTrue: [
>>>>                   visitor
>>>>                       perform: (visitor createdVisitSelector: aQualifiedName)
>>>>                       with: aQualifiedName
>>>>                       with: aDictionary
>>>>           ]
>>>>
>>>>
>>>> Object subclass: #GenericTagSAXVisitor
>>>>       instanceVariableNames: 'visitTag visitTags'
>>>>       classVariableNames: ''
>>>>       category: 'SmartXMLHandler'
>>>>
>>>>
>>>> GenericTagSAXVisitor>>visitTags: aCollection
>>>>       "set the tags that will lead to a call to a visitTag:with: method in the visitor"
>>>>
>>>>       visitTags := aCollection collect: [ :each | each asLowercase ].
>>>>       self createVisitMethods.
>>>>
>>>> and in a subclass the visit* methods automatically generated
>>>>
>>>>
>>>> Now I could not get when I have a <TITRE>Vertigo</TITRE> where I can get the
>>>> Vertigo information.
>>>> I redefined several methods of SAXhandler but without success.
>>>>
>>>>
>>>> <?xml version="1.0" encoding="iso-8859-1"?>
>>>> <FILMS>
>>>>     <FILM annee="1958">
>>>>       <TITRE>Vertigo</TITRE>
>>>>       <GENRE>Drame</GENRE>
>>>>       <PAYS>USA</PAYS>
>>>>       <MES idref="3"/>
>>>>       <ROLES>
>>>>         <ROLE>
>>>>           <PRENOM>James</PRENOM>
>>>>           <NOM>Stewart</NOM>
>>>>           <INTITULE>John Ferguson</INTITULE>
>>>>         </ROLE>
>>>>         <ROLE>
>>>>           <PRENOM>Kim</PRENOM>
>>>>           <NOM>Novak</NOM>
>>>>           <INTITULE>Madeleine Elster</INTITULE>
>>>>         </ROLE>
>>>>       </ROLES>
>>>>       <RESUME>Scottie Ferguson, ancien inspecteur de police, est sujet
>>>> au vertige depuis qu'il a vu mourir son
>>>>    collegue. Elster, son ami, le charge de surveiller sa femme,
>>>> Madeleine, ayant des tendances
>>>>    suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le
>>>> piege qui se trame autour
>>>>    de lui et dont il va etre la victime... </RESUME>
>>>>     </FILM>
>>> !!!*************************************************************************************
>>> "Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité de Worldline ne pourra être recherchée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être recherchée pour tout dommage résultant d'un virus transmis.
>>>
>>> This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Worldline liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.!!!"
>>


Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

stepharo
In reply to this post by abergel
Alex

what Pastell brings compared to XPath?

Stef

Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

stepharo
In reply to this post by stepharo


Le 13/3/16 13:33, stepharo a écrit :

> Hi alex
>
> I do not know :)
> I like visitor because they are better than a series of if.
> So I will see. I would like to help people to extract their
> information easily.
> May be inside the visitNode I could use XPath (do you know what is the
> constraint to use XPath)
> does it work on dom objects?
>
> I would like to have something like that (being able to use some node
> to perform custom actions)
> Now I do not see how from one visit method I can access the other. and
> if I do not do it in the visit
> what is the information I should store (like parent link) to be able
> to identify that a given role is associated to a given film.
>
> visitFilm
>     title := self extractFromChildren: #Titre.
>     pays := self extractFromChildren: #Pays.
>     self newFilm: title from: pays.
         in fact for subnodes like role I should just continue the visit
flow and get

But I will keep in mind XPath. It would be grtea to have tutorial on all
these XML technologies


     - SAX
     - DOM
     - PullParser
     - XPath queries / Pastell
     - Opax

It could be XML in Pharo a nice book


>
>
> visitRole
>
>  <FILM annee="1958">
>      <TITRE>Vertigo</TITRE>
>      <GENRE>Drame</GENRE>
>      <PAYS>USA</PAYS>
>      <MES idref="3"/>
>      <ROLES>
>        <ROLE>
>          <PRENOM>James</PRENOM>
>          <NOM>Stewart</NOM>
>          <INTITULE>John Ferguson</INTITULE>
>        </ROLE>
>        <ROLE>
>          <PRENOM>Kim</PRENOM>
>          <NOM>Novak</NOM>
>          <INTITULE>Madeleine Elster</INTITULE>
>        </ROLE>
>
>
>
> Stef
>
>
> Le 13/3/16 11:26, Alexandre Bergel a écrit :
>> Hi Stef,
>>
>> I have the impression that a visitor is not the ideal solution to
>> query XML tree. It works well in some case, and it is disastrous in
>> some other.
>> XPath is the way to query XML data. As far as I know, there is no
>> complete support. Pastell was a nice try however...
>>
>> Alexandre
>>
>>
>>> On Mar 12, 2016, at 8:11 AM, stepharo <[hidden email]> wrote:
>>>
>>> Thanks
>>>
>>> Ok it was characters: I will try it
>>> What a bad name!
>>>
>>> I will probably have to build a stack or dictionary of dictionary of
>>> the part that I will not want to visit but this is another story :)
>>>
>>> Stef
>>>
>>>
>>> Le 11/3/16 14:17, Blondeau Vincent a écrit :
>>>> Hi,
>>>>
>>>> The qualified name in function startElement: aQualifiedName
>>>> attributes: aDictionary, will be FILMS and after FILM and after
>>>> TITRE,...etc...
>>>> So, you have to tell to your shouldVisit: method to accept TITRE
>>>> too and get in and after you should implement characters: to get
>>>> the content on the tag.
>>>>
>>>> Vincent
>>>>
>>>>> -----Message d'origine-----
>>>>> De : Pharo-users [mailto:[hidden email]] De
>>>>> la part de
>>>>> stepharo
>>>>> Envoyé : vendredi 11 mars 2016 14:04
>>>>> À : Any question about pharo is welcome
>>>>> Objet : [Pharo-users] How to access XML tag name?
>>>>>
>>>>> Hi
>>>>>
>>>>> Yesterday I started to hack a smart SAX handler. The idea is that
>>>>> I want to just
>>>>> specify the tags I want to visit and the SAX handler should invoke
>>>>> (generated)
>>>>> visit methods. Like that I can easily get visitors on XML domain.
>>>>>
>>>>> Here is an example of what I did.
>>>>>
>>>>>       | h |
>>>>>       h := SmartSAXHandler new
>>>>>                   visitor: (MyFilmVisitor new visitTags: #(FILM
>>>>> ROLE));
>>>>>                   on: FileSystem workingDirectory / 'FILMS.XML'.
>>>>>       h parseDocument.
>>>>>       ^ h
>>>>>
>>>>>
>>>>>
>>>>> SmartSAXHAndler >> startElement: aQualifiedName attributes:
>>>>> aDictionary
>>>>>
>>>>>       (visitor shouldVisit: aQualifiedName)
>>>>>           ifTrue: [
>>>>>                   visitor
>>>>>                       perform: (visitor createdVisitSelector:
>>>>> aQualifiedName)
>>>>>                       with: aQualifiedName
>>>>>                       with: aDictionary
>>>>>           ]
>>>>>
>>>>>
>>>>> Object subclass: #GenericTagSAXVisitor
>>>>>       instanceVariableNames: 'visitTag visitTags'
>>>>>       classVariableNames: ''
>>>>>       category: 'SmartXMLHandler'
>>>>>
>>>>>
>>>>> GenericTagSAXVisitor>>visitTags: aCollection
>>>>>       "set the tags that will lead to a call to a visitTag:with:
>>>>> method in the visitor"
>>>>>
>>>>>       visitTags := aCollection collect: [ :each | each asLowercase ].
>>>>>       self createVisitMethods.
>>>>>
>>>>> and in a subclass the visit* methods automatically generated
>>>>>
>>>>>
>>>>> Now I could not get when I have a <TITRE>Vertigo</TITRE> where I
>>>>> can get the
>>>>> Vertigo information.
>>>>> I redefined several methods of SAXhandler but without success.
>>>>>
>>>>>
>>>>> <?xml version="1.0" encoding="iso-8859-1"?>
>>>>> <FILMS>
>>>>>     <FILM annee="1958">
>>>>>       <TITRE>Vertigo</TITRE>
>>>>>       <GENRE>Drame</GENRE>
>>>>>       <PAYS>USA</PAYS>
>>>>>       <MES idref="3"/>
>>>>>       <ROLES>
>>>>>         <ROLE>
>>>>>           <PRENOM>James</PRENOM>
>>>>>           <NOM>Stewart</NOM>
>>>>>           <INTITULE>John Ferguson</INTITULE>
>>>>>         </ROLE>
>>>>>         <ROLE>
>>>>>           <PRENOM>Kim</PRENOM>
>>>>>           <NOM>Novak</NOM>
>>>>>           <INTITULE>Madeleine Elster</INTITULE>
>>>>>         </ROLE>
>>>>>       </ROLES>
>>>>>       <RESUME>Scottie Ferguson, ancien inspecteur de police, est
>>>>> sujet
>>>>> au vertige depuis qu'il a vu mourir son
>>>>>    collegue. Elster, son ami, le charge de surveiller sa femme,
>>>>> Madeleine, ayant des tendances
>>>>>    suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le
>>>>> piege qui se trame autour
>>>>>    de lui et dont il va etre la victime... </RESUME>
>>>>>     </FILM>
>>>> !!!*************************************************************************************
>>>>
>>>> "Ce message et les pièces jointes sont confidentiels et réservés à
>>>> l'usage exclusif de ses destinataires. Il peut également être
>>>> protégé par le secret professionnel. Si vous recevez ce message par
>>>> erreur, merci d'en avertir immédiatement l'expéditeur et de le
>>>> détruire. L'intégrité du message ne pouvant être assurée sur
>>>> Internet, la responsabilité de Worldline ne pourra être recherchée
>>>> quant au contenu de ce message. Bien que les meilleurs efforts
>>>> soient faits pour maintenir cette transmission exempte de tout
>>>> virus, l'expéditeur ne donne aucune garantie à cet égard et sa
>>>> responsabilité ne saurait être recherchée pour tout dommage
>>>> résultant d'un virus transmis.
>>>>
>>>> This e-mail and the documents attached are confidential and
>>>> intended solely for the addressee; it may also be privileged. If
>>>> you receive this e-mail in error, please notify the sender
>>>> immediately and destroy it. As its integrity cannot be secured on
>>>> the Internet, the Worldline liability cannot be triggered for the
>>>> message content. Although the sender endeavours to maintain a
>>>> computer virus-free network, the sender does not warrant that this
>>>> transmission is virus-free and will not be liable for any damages
>>>> resulting from any virus transmitted.!!!"
>>>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

stepharo
In reply to this post by stepharo
Alex

I saw that Pastell is only tagged for Pharo30 and has not metadata.
It would be good to revise it.

Stef

Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

Tudor Girba-2
In reply to this post by stepharo
Hi,

Yes, exactly. You get a qualified DOM with a hierarchy that you can afterwards visit.

Only the current implementation only works only with the XMLDOMParser. It does not work with SAX.

Cheers,
Doru

> On Mar 13, 2016, at 12:55 PM, stepharo <[hidden email]> wrote:
>
> I have the impression that I should also look at
>
>     XMLPluggableElementFactory new handleElement: 'NOM' withClass: AAAName.
>
> Because it looks like that I inject my nodes inside the dom
>
> Am I correct?
>
>
> Le 12/3/16 21:59, Tudor Girba a écrit :
>> Hi,
>>
>> My original work only survived for the XMLDOMParser. See this example:
>> http://ws.stfx.eu/NK2WLSW99X10
>> (paste this in Spotter :))
>>
>> For an XMLDOMParser, you can say that you want to instantiate a node in the DOM with an custom instance. For example, here I instantiate <NOM> with AAAName:
>>
>> <Mail Attachment.png>
>>
>> You are looking for something a bit different. In a way you want to associate the triggering of a specific handler when some XPath like expression is being matched for the current element. I think something like this should go in the main implementation.
>>
>> Cheers,
>> Doru
>>
>>
>>
>>> On Mar 12, 2016, at 9:33 AM, stepharo <[hidden email]> wrote:
>>>
>>> This is more complex than that.
>>> Because I would like to have a visitor generated from the token I give.
>>>
>>> And this
>>>    start
>>>    character
>>>    end
>>>
>>> does not really help me.
>>>
>>> Because in SAXHandler I have
>>>        start
>>>            where I should store the properties
>>>       same in characters:
>>>            to store the name
>>>       end
>>>            where I should invoke the visitor
>>>
>>> Now it means that I should only store the information for the tag I want.
>>> Does anybody already did that and publish it?
>>> I know doru did that in the past.
>>> I will try.
>>>
>>> Stef
>>>
>>>
>>>
>>> Le 11/3/16 14:17, Blondeau Vincent a écrit :
>>>> Hi,
>>>>
>>>> The qualified name in function startElement: aQualifiedName attributes: aDictionary, will be FILMS and after FILM and after TITRE,...etc...
>>>> So, you have to tell to your shouldVisit: method to accept TITRE too and get in and after you should implement characters: to get the content on the tag.
>>>>
>>>> Vincent
>>>>
>>>>> -----Message d'origine-----
>>>>> De : Pharo-users [mailto:[hidden email]] De la part de
>>>>> stepharo
>>>>> Envoyé : vendredi 11 mars 2016 14:04
>>>>> À : Any question about pharo is welcome
>>>>> Objet : [Pharo-users] How to access XML tag name?
>>>>>
>>>>> Hi
>>>>>
>>>>> Yesterday I started to hack a smart SAX handler. The idea is that I want to just
>>>>> specify the tags I want to visit and the SAX handler should invoke (generated)
>>>>> visit methods. Like that I can easily get visitors on XML domain.
>>>>>
>>>>> Here is an example of what I did.
>>>>>
>>>>>      | h |
>>>>>      h := SmartSAXHandler new
>>>>>                  visitor: (MyFilmVisitor new visitTags: #(FILM ROLE));
>>>>>                  on: FileSystem workingDirectory / 'FILMS.XML'.
>>>>>      h parseDocument.
>>>>>      ^ h
>>>>>
>>>>>
>>>>>
>>>>> SmartSAXHAndler >> startElement: aQualifiedName attributes: aDictionary
>>>>>
>>>>>      (visitor shouldVisit: aQualifiedName)
>>>>>          ifTrue: [
>>>>>                  visitor
>>>>>                      perform: (visitor createdVisitSelector: aQualifiedName)
>>>>>                      with: aQualifiedName
>>>>>                      with: aDictionary
>>>>>          ]
>>>>>
>>>>>
>>>>> Object subclass: #GenericTagSAXVisitor
>>>>>      instanceVariableNames: 'visitTag visitTags'
>>>>>      classVariableNames: ''
>>>>>      category: 'SmartXMLHandler'
>>>>>
>>>>>
>>>>> GenericTagSAXVisitor>>visitTags: aCollection
>>>>>      "set the tags that will lead to a call to a visitTag:with: method in the visitor"
>>>>>
>>>>>      visitTags := aCollection collect: [ :each | each asLowercase ].
>>>>>      self createVisitMethods.
>>>>>
>>>>> and in a subclass the visit* methods automatically generated
>>>>>
>>>>>
>>>>> Now I could not get when I have a <TITRE>Vertigo</TITRE> where I can get the
>>>>> Vertigo information.
>>>>> I redefined several methods of SAXhandler but without success.
>>>>>
>>>>>
>>>>> <?xml version="1.0" encoding="iso-8859-1"?>
>>>>> <FILMS>
>>>>>    <FILM annee="1958">
>>>>>      <TITRE>Vertigo</TITRE>
>>>>>      <GENRE>Drame</GENRE>
>>>>>      <PAYS>USA</PAYS>
>>>>>      <MES idref="3"/>
>>>>>      <ROLES>
>>>>>        <ROLE>
>>>>>          <PRENOM>James</PRENOM>
>>>>>          <NOM>Stewart</NOM>
>>>>>          <INTITULE>John Ferguson</INTITULE>
>>>>>        </ROLE>
>>>>>        <ROLE>
>>>>>          <PRENOM>Kim</PRENOM>
>>>>>          <NOM>Novak</NOM>
>>>>>          <INTITULE>Madeleine Elster</INTITULE>
>>>>>        </ROLE>
>>>>>      </ROLES>
>>>>>      <RESUME>Scottie Ferguson, ancien inspecteur de police, est sujet
>>>>> au vertige depuis qu'il a vu mourir son
>>>>>   collegue. Elster, son ami, le charge de surveiller sa femme,
>>>>> Madeleine, ayant des tendances
>>>>>   suicidaires. Amoureux de la jeune femme Scottie ne remarque pas le
>>>>> piege qui se trame autour
>>>>>   de lui et dont il va etre la victime... </RESUME>
>>>>>    </FILM>
>>>>
>>>> !!!*************************************************************************************
>>>> "Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité de Worldline ne pourra être recherchée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être recherchée pour tout dommage résultant d'un virus transmis.
>>>>
>>>> This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Worldline liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.!!!"
>>>
>>>
>>
>> --
>> www.tudorgirba.com
>> www.feenk.com
>>
>> "We can create beautiful models in a vacuum.
>> But, to get them effective we have to deal with the inconvenience of reality."
>>
>

--
www.tudorgirba.com
www.feenk.com

"Reasonable is what we are accustomed with."


Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

Tudor Girba-2
In reply to this post by stepharo
XPath is better than Pastell. That is why in Moose we now have XPath.

Doru

> On Mar 13, 2016, at 1:49 PM, stepharo <[hidden email]> wrote:
>
> Alex
>
> I saw that Pastell is only tagged for Pharo30 and has not metadata.
> It would be good to revise it.
>
> Stef
>

--
www.tudorgirba.com
www.feenk.com

"Every successful trip needs a suitable vehicle."






Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

abergel
In reply to this post by stepharo
Pastell is an implementation of XPath. But I had a look at it many years ago (when I was extracting data from srcML xml files, you remember? :-)

Alexandre


> On Mar 13, 2016, at 1:39 PM, stepharo <[hidden email]> wrote:
>
> Alex
>
> what Pastell brings compared to XPath?
>
> Stef
>

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.




Reply | Threaded
Open this post in threaded view
|

Re: How to access XML tag name?

abergel
In reply to this post by Tudor Girba-2
Oh cool! I did not know there was a project XPath in Pharo.
I learnt something.

Cheers,
Alexandre


> On Mar 13, 2016, at 2:33 PM, Tudor Girba <[hidden email]> wrote:
>
> XPath is better than Pastell. That is why in Moose we now have XPath.
>
> Doru
>
>> On Mar 13, 2016, at 1:49 PM, stepharo <[hidden email]> wrote:
>>
>> Alex
>>
>> I saw that Pastell is only tagged for Pharo30 and has not metadata.
>> It would be good to revise it.
>>
>> Stef
>>
>
> --
> www.tudorgirba.com
> www.feenk.com
>
> "Every successful trip needs a suitable vehicle."
>
>
>
>
>
>

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.




12