The class comment (and other) could be better; it assumes you already know SAX-style parsing. I will improve it. I have been working on a tutorial that shows the usage of XMLParser and related libs (like XPath or XMLParserStAX). It is being structured like a chapter and formatted with Pillar, so it could go in one of your books (but not PBE, it's too specific for it). Also, instead of:
h := MySAXHandler new on: FileSystem workingDirectory / 'FILMS.XML'. h parseDocument.
You just want: result := MySAXHandler parseFileNamed: 'FILMS.XML'. or if you want to configure it before parsing, you can use an on*: constructor + parseDocument: result := (MySAXHandler onFileNamed: 'FILMS.XML') "...configure the instance here.." parseDocument.
Sent: Friday, March 11, 2016 at 7:55 AM From: stepharo <stepharo@free.fr> To: "Pharo Development List" <pharo-dev@lists.pharo.org> Subject: [Pharo-dev] Improving doc of XMLParser
Hi monty
Yesterday one student ask me to import in Moose an XML document. I spent more than 15 min trying....
What would have really help is the following (could you add it into the class comment): Many of the comment do not help because are scarce and not precise enough.
To use a SaxHandler subclass it
SAXHandler subclass: #MySAXHandler instanceVariableNames: '' classVariableNames: '' category: 'MyXMLImporter'
and redefine the method corresponding the notification you want for example:
MySAXHandler>>startElement: aQualifiedName attributes: aDictionary
self halt.
Then to use it simply do
| h | h := MySAXHandler new on: FileSystem workingDirectory / 'FILMS.XML'. h parseDocument. ^ h
Your method startElement: aQualifiedName attributes: aDictionary should get invoked.
I really think that having a tutorial on XML parser ***use*** is cruelly needed.
Stef