[Newbies] xml file query and object mapping
ed.stow at gmail.com
Fri Jun 30 01:47:22 UTC 2006
I would use the SAX parser. If you only need to extract one 'record'
from the document then its not too hard.
Start by subclassing SAXHandler and define some methods to handle the events.
Suggest that you initially define two methods to get started. (Code is
startElement: elementName attributeList: attributeList
"currentElement is an instance variable"
currentElement := elementName.
(currentElement = 'ZONE') & (aString = '6504') ifTrue: [ .... ]
For more inspiration look to see how XMLDOMParser works - itself a
subclass of SAXHandler. The hardest part of writng a SAXParser is
that you need to keep track of the state of the parser so that you
handle the events and construct some objects that are meaningful for
On 30/06/06, cdrick <cdrick65 at gmail.com> wrote:
> Hi all
> I've got xml files that I receive from Meteo France (weather forecast) that
> I have to query and map to some objects
> I've tried several stuff like parsing the file, selecting only some
> elements, displaying it with a WATree but I'm a bit stuck as none results I
> got are good enough.
> The structure is like behind:
> <?xml version="1.0" encoding="UTF-8" ?>...
> <prev num="1"> // a prev concern a zone for 3 hours - there are 18 prev
> for a given zone
> .... around 450 prev (18 for each ZONE)
> <prevQ num="1"> // this are prevision for the whole day - 4 prevQ in
> each file for a given zone
> What I need to do is quering the file according to the some attribute (ZONE,
> VALIDITE, JJ and HH) so as to get the different value that characterize the
> weather forecast. The only thing I can do is selecting nodes accoring to one
> parameter, for instance all prevQ element of zone 6504 (using Xpath).
> | xml document path results |
> xml := (StandardFileStream readOnlyFileNamed:
> 'ressources/MF/backup/sympo0805200617h00.xml') contents.
> document := XMLDOMParser parseDocumentFrom: xml readStream.
> path := XPath for: 'prevision/prev'.
> results := path in: document.
> ^ results
> select: [:xmlElem | (xmlElem elementAt: #ZONE) contents first
> string = '6504']
> I'm a bit lost now. Is it possible to map to objects ? do I need to work
> directly on xml file by xsl transformation ? I don't really understand how
> to use a sax parser (I always do a full dom parse that I store in an inst
> Do you have advices, pointers or other good practises that can help me ?
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
More information about the Beginners