The Inbox: Help-Squeak-Project-it.4.mcz

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

The Inbox: Help-Squeak-Project-it.4.mcz

commits-2
A new version of Help-Squeak-Project was added to project The Inbox:
http://source.squeak.org/inbox/Help-Squeak-Project-it.4.mcz

==================== Summary ====================

Name: Help-Squeak-Project-it.4
Author: it
Time: 4 May 2010, 10:31:33.929 am
UUID: 1460ca93-adfa-0147-adbb-35447aa254ac
Ancestors: Help-Squeak-Project-tbn.3

Adding "Retrieving XML data" tutorial. A rewritten version from http://mecenia.blogspot.com/2010/05/using-squeak-with-blogger-export-files.html

=============== Diff against Help-Squeak-Project-tbn.3 ===============

Item was added:
+ ----- Method: SqueakTutorials classSide>>bookName (in category 'accessing') -----
+ bookName
+ ^'Tutorials'!

Item was added:
+ ----- Method: SqueakTutorialsOnXML classSide>>pages (in category 'accessing') -----
+ pages
+ ^# (dataRetrieval)!

Item was added:
+ SqueakTutorials subclass: #SqueakTutorialsOnXML
+ instanceVariableNames: ''
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'Help-Squeak-Project'!

Item was added:
+ ----- Method: SqueakTutorialsOnXML classSide>>dataRetrieval (in category 'pages') -----
+ dataRetrieval
+ ^HelpTopic
+ title: 'Retrieving XML data'
+ contents:
+ 'Retrieving data from XML documents is simple and easy. This tutorial demonstrates the fundamentals with a straightforward approach where code can be tested right away either here or in a Workspace window. The beauty of Squeak Smalltalk resides in the possibility to evaluate, inspect, print and debug code anywhere and this window is no different.
+
+ This tutorial demonstrates how...
+
+ * to retrieve an XML document from the World Wide Web
+ * to instance an XML document class
+ * to inspect and understand the content of an XML document
+ * to retrieve and display values from specific XML tags
+
+ Retrieve an XML document from the World Wide Web
+
+ There are many manners to retrieve data from the World Wide Web in Squeak Smalltalk. HTTPClient is among them and let you download files in all simplicity. Select the following code snippet and inspect it (press alt-i). An Inspect window will open with the document loaded in memory. The result is a MIMEDocument object.
+
+ HTTPClient httpGetDocument: ''http://www.squeaksource.com/ss/feed.rss''.
+
+ TIP: Select HTTPClient and browse it (press alt-b) to open a System Browser window on its class. HTTPClient does not have instance methods but it has class methods. Click on class to see class methods.
+
+ Instantiate an XML Document
+
+ An instance of MIMEDocument will not allow to retrieve XML data in a comprehensive manner because it does not understand the nature of XML. For this reason, it is necessary to parse the content of MIMEDocument using XMLDOMParser. XMLDOMParser>>parseDocumentFrom: requires a stream as a parameter and ReadStream will be used for this purpose. The following code snippet instantiates an XMLDocument using the content of the downloaded file.
+
+ | doc |
+ doc := HTTPClient httpGetDocument: ''http://www.squeaksource.com/ss/feed.rss''.
+ XMLDOMParser parseDocumentFrom: (ReadStream on: (doc content)).
+
+ Inspect and understand the content of an XML document
+
+ XML is a flexible document format and it is necessary to understand how each given XML file is structured in order to properly search, retrieve and manipulate data. Inspecting values is critical in a dynamic programming language and environment, such as Squeak Smalltalk. Select the previous code snippet and inspect it (press alt-i).
+
+ Unfortunately, the Inspect window does not reveal a lot about the XML structure of the downloaded file. Select the previous code snippet once again and explore it (press alt and the capital letter i). An Explorer window will open with a tree outline on the instance of XMLDocument.
+
+ The Inspect and Explorer windows tell a lot about an XMLDocument. The sections are instance variables and their values are displayed aside. In the Explorer window, unfold elementsAndContents. Unfold other sections as deem necessary to understand the XML format and the data available.
+
+ The gibberish coding is about to become clear. Open a Browser window from the world menu and right click in the first pane, select find class (press alt-f) and type XMLDocument to search for its class, or select the class name and browse it (press alt-b). However, it is suggested to read more about XMLParser and XMLParserTest first.
+
+ Retrieve and display values from specific XML tags
+
+ The downloaded XML file contains a list of items which are denoted by the tag name "item". The Explorer window revealed the content of interest is located at the array index 1 of the elementsAndContents.
+
+ The following code snippet will display items in a Transcript window. Open a Transcript window using the world menu before selecting and executing the code. Select the code snippet and execute it (press alt-d).
+
+ | doc xml |
+ doc := HTTPClient httpGetDocument: ''http://www.squeaksource.com/ss/feed.rss''.
+ xml := XMLDOMParser parseDocumentFrom: (ReadStream on: (doc content)).
+ (xml elements at: 1) tagsNamed: #item do: [:e |
+ Transcript show: (e asString); cr.
+ ].
+
+ An XML item looks like this:
+
+ <item>
+ <title>SqueakSource-lr.1039.mcz</title>
+ <link>http://www.squeaksource.com/ss.html</link>
+ <description>integrated new stylesheet</description>
+ <pubDate>Sat, 10 Apr 2010 11:30:38 +0100</pubDate>
+ <author>Lukas Renggli &lt;[hidden email]&gt;</author>
+ <category>SqueakSource, seaside, server</category>
+ <enclosure length="302570" type="application/x-monticello" url="http://www.squeaksource.com/ss/SqueakSource-lr.1039.mcz"/>
+ <guid isPermaLink="false"/> </item>
+
+ The following code snippet uses information learned, retrieves each comment and displays them in a Transcript window. Notice an author can have a nil value and is handled accordingly.
+
+ | doc xml |
+ doc := HTTPClient httpGetDocument: ''http://www.squeaksource.com/ss/feed.rss''.
+ xml := XMLDOMParser parseDocumentFrom: (ReadStream on: (doc content)).
+ (xml elements at: 1) tagsNamed: #item do: [:e |
+ Transcript
+ show: ''Date: '', ((e firstTagNamed: #pubDate) contentString); cr;
+ show: ''Title: '', ((e firstTagNamed: #title) contentString); cr;
+ show: ''Author: '',
+ (((e firstTagNamed: #author) notNil)
+ ifTrue: [(e firstTagNamed: #author) contentString]
+ ifFalse: ['''']); cr;
+ show: ''Description: '', ((e firstTagNamed: #description) contentString); cr; cr.
+ ].
+
+ An item will now looks like:
+
+ Date: Wed, 21 Apr 2010 22:33:18 +0100
+ Title: SqueakSource-lr.1060.mcz
+ Author: Lukas Renggli <[hidden email]>
+ Description: - ignore email errors
+ '!

Item was added:
+ ----- Method: SqueakTutorialsOnXML classSide>>bookName (in category 'accessing') -----
+ bookName
+ ^'XML'!

Item was added:
+ SqueakHelp subclass: #SqueakTutorials
+ instanceVariableNames: ''
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'Help-Squeak-Project'!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Help-Squeak-Project-it.4.mcz

Hannes Hirzel
I have read through it and I like it. I will test it later.

One minor thing
instead of

    * to instance an XML document class
I would say
either
    * to create and instance of the XMLDocument class
or
    * to instantiate an XML document class object (however I'm not
sure about this)

--Hannes



On Tue, 4 May 2010 14:31:38.375 0000, [hidden email]
<[hidden email]> wrote:

> A new version of Help-Squeak-Project was added to project The Inbox:
> http://source.squeak.org/inbox/Help-Squeak-Project-it.4.mcz
>
> ==================== Summary ====================
>
> Name: Help-Squeak-Project-it.4
> Author: it
> Time: 4 May 2010, 10:31:33.929 am
> UUID: 1460ca93-adfa-0147-adbb-35447aa254ac
> Ancestors: Help-Squeak-Project-tbn.3
>
> Adding "Retrieving XML data" tutorial. A rewritten version from
> http://mecenia.blogspot.com/2010/05/using-squeak-with-blogger-export-files.html
>
> =============== Diff against Help-Squeak-Project-tbn.3 ===============
>
> Item was added:
> + ----- Method: SqueakTutorials classSide>>bookName (in category
> 'accessing') -----
> + bookName
> + ^'Tutorials'!
>
> Item was added:
> + ----- Method: SqueakTutorialsOnXML classSide>>pages (in category
> 'accessing') -----
> + pages
> + ^# (dataRetrieval)!
>
> Item was added:
> + SqueakTutorials subclass: #SqueakTutorialsOnXML
> + instanceVariableNames: ''
> + classVariableNames: ''
> + poolDictionaries: ''
> + category: 'Help-Squeak-Project'!
>
> Item was added:
> + ----- Method: SqueakTutorialsOnXML classSide>>dataRetrieval (in category
> 'pages') -----
> + dataRetrieval
> + ^HelpTopic
> + title: 'Retrieving XML data'
> + contents:
> + 'Retrieving data from XML documents is simple and easy. This tutorial
> demonstrates the fundamentals with a straightforward approach where code can
> be tested right away either here or in a Workspace window. The beauty of
> Squeak Smalltalk resides in the possibility to evaluate, inspect, print and
> debug code anywhere and this window is no different.
> +
> + This tutorial demonstrates how...
> +
> + * to retrieve an XML document from the World Wide Web
> + * to instance an XML document class
> + * to inspect and understand the content of an XML document
> + * to retrieve and display values from specific XML tags
> +
> + Retrieve an XML document from the World Wide Web
> +
> + There are many manners to retrieve data from the World Wide Web in Squeak
> Smalltalk. HTTPClient is among them and let you download files in all
> simplicity. Select the following code snippet and inspect it (press alt-i).
> An Inspect window will open with the document loaded in memory. The result
> is a MIMEDocument object.
> +
> + HTTPClient httpGetDocument: ''http://www.squeaksource.com/ss/feed.rss''.
> +
> + TIP: Select HTTPClient and browse it (press alt-b) to open a System
> Browser window on its class. HTTPClient does not have instance methods but
> it has class methods. Click on class to see class methods.
> +
> + Instantiate an XML Document
> +
> + An instance of MIMEDocument will not allow to retrieve XML data in a
> comprehensive manner because it does not understand the nature of XML. For
> this reason, it is necessary to parse the content of MIMEDocument using
> XMLDOMParser. XMLDOMParser>>parseDocumentFrom: requires a stream as a
> parameter and ReadStream will be used for this purpose. The following code
> snippet instantiates an XMLDocument using the content of the downloaded
> file.
> +
> + | doc |
> + doc := HTTPClient httpGetDocument:
> ''http://www.squeaksource.com/ss/feed.rss''.
> + XMLDOMParser parseDocumentFrom: (ReadStream on: (doc content)).
> +
> + Inspect and understand the content of an XML document
> +
> + XML is a flexible document format and it is necessary to understand how
> each given XML file is structured in order to properly search, retrieve and
> manipulate data. Inspecting values is critical in a dynamic programming
> language and environment, such as Squeak Smalltalk. Select the previous code
> snippet and inspect it (press alt-i).
> +
> + Unfortunately, the Inspect window does not reveal a lot about the XML
> structure of the downloaded file. Select the previous code snippet once
> again and explore it (press alt and the capital letter i). An Explorer
> window will open with a tree outline on the instance of XMLDocument.
> +
> + The Inspect and Explorer windows tell a lot about an XMLDocument. The
> sections are instance variables and their values are displayed aside. In the
> Explorer window, unfold elementsAndContents. Unfold other sections as deem
> necessary to understand the XML format and the data available.
> +
> + The gibberish coding is about to become clear. Open a Browser window from
> the world menu and right click in the first pane, select find class (press
> alt-f) and type XMLDocument to search for its class, or select the class
> name and browse it (press alt-b). However, it is suggested to read more
> about XMLParser and XMLParserTest first.
> +
> + Retrieve and display values from specific XML tags
> +
> + The downloaded XML file contains a list of items which are denoted by the
> tag name "item". The Explorer window revealed the content of interest is
> located at the array index 1 of the elementsAndContents.
> +
> + The following code snippet will display items in a Transcript window. Open
> a Transcript window using the world menu before selecting and executing the
> code. Select the code snippet and execute it (press alt-d).
> +
> + | doc xml |
> + doc := HTTPClient httpGetDocument:
> ''http://www.squeaksource.com/ss/feed.rss''.
> + xml := XMLDOMParser parseDocumentFrom: (ReadStream on: (doc content)).
> + (xml elements at: 1) tagsNamed: #item do: [:e |
> + Transcript show: (e asString); cr.
> + ].
> +
> + An XML item looks like this:
> +
> + <item>
> + <title>SqueakSource-lr.1039.mcz</title>
> + <link>http://www.squeaksource.com/ss.html</link>
> + <description>integrated new stylesheet</description>
> + <pubDate>Sat, 10 Apr 2010 11:30:38 +0100</pubDate>
> + <author>Lukas Renggli &lt;[hidden email]&gt;</author>
> + <category>SqueakSource, seaside, server</category>
> + <enclosure length="302570" type="application/x-monticello"
> url="http://www.squeaksource.com/ss/SqueakSource-lr.1039.mcz"/>
> + <guid isPermaLink="false"/> </item>
> +
> + The following code snippet uses information learned, retrieves each
> comment and displays them in a Transcript window. Notice an author can have
> a nil value and is handled accordingly.
> +
> + | doc xml |
> + doc := HTTPClient httpGetDocument:
> ''http://www.squeaksource.com/ss/feed.rss''.
> + xml := XMLDOMParser parseDocumentFrom: (ReadStream on: (doc content)).
> + (xml elements at: 1) tagsNamed: #item do: [:e |
> + Transcript
> + show: ''Date: '', ((e firstTagNamed: #pubDate) contentString); cr;
> + show: ''Title: '', ((e firstTagNamed: #title) contentString); cr;
> + show: ''Author: '',
> + (((e firstTagNamed: #author) notNil)
> + ifTrue: [(e firstTagNamed: #author) contentString]
> + ifFalse: ['''']); cr;
> + show: ''Description: '', ((e firstTagNamed: #description)
> contentString); cr; cr.
> + ].
> +
> + An item will now looks like:
> +
> + Date: Wed, 21 Apr 2010 22:33:18 +0100
> + Title: SqueakSource-lr.1060.mcz
> + Author: Lukas Renggli <[hidden email]>
> + Description: - ignore email errors
> + '!
>
> Item was added:
> + ----- Method: SqueakTutorialsOnXML classSide>>bookName (in category
> 'accessing') -----
> + bookName
> + ^'XML'!
>
> Item was added:
> + SqueakHelp subclass: #SqueakTutorials
> + instanceVariableNames: ''
> + classVariableNames: ''
> + poolDictionaries: ''
> + category: 'Help-Squeak-Project'!
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Help-Squeak-Project-it.4.mcz

Hannes Hirzel
Sorry I meant

to create an instance of the XMLDocument class


On 5/4/10, Hannes Hirzel <[hidden email]> wrote:

> I have read through it and I like it. I will test it later.
>
> One minor thing
> instead of
>
>     * to instance an XML document class
> I would say
> either
>     * to create and instance of the XMLDocument class
> or
>     * to instantiate an XML document class object (however I'm not
> sure about this)
>
> --Hannes
>
>
>
> On Tue, 4 May 2010 14:31:38.375 0000, [hidden email]
> <[hidden email]> wrote:
>> A new version of Help-Squeak-Project was added to project The Inbox:
>> http://source.squeak.org/inbox/Help-Squeak-Project-it.4.mcz
>>
>> ==================== Summary ====================
>>
>> Name: Help-Squeak-Project-it.4
>> Author: it
>> Time: 4 May 2010, 10:31:33.929 am
>> UUID: 1460ca93-adfa-0147-adbb-35447aa254ac
>> Ancestors: Help-Squeak-Project-tbn.3
>>
>> Adding "Retrieving XML data" tutorial. A rewritten version from
>> http://mecenia.blogspot.com/2010/05/using-squeak-with-blogger-export-files.html
>>
>> =============== Diff against Help-Squeak-Project-tbn.3 ===============
>>
>> Item was added:
>> + ----- Method: SqueakTutorials classSide>>bookName (in category
>> 'accessing') -----
>> + bookName
>> + ^'Tutorials'!
>>
>> Item was added:
>> + ----- Method: SqueakTutorialsOnXML classSide>>pages (in category
>> 'accessing') -----
>> + pages
>> + ^# (dataRetrieval)!
>>
>> Item was added:
>> + SqueakTutorials subclass: #SqueakTutorialsOnXML
>> + instanceVariableNames: ''
>> + classVariableNames: ''
>> + poolDictionaries: ''
>> + category: 'Help-Squeak-Project'!
>>
>> Item was added:
>> + ----- Method: SqueakTutorialsOnXML classSide>>dataRetrieval (in
>> category
>> 'pages') -----
>> + dataRetrieval
>> + ^HelpTopic
>> + title: 'Retrieving XML data'
>> + contents:
>> + 'Retrieving data from XML documents is simple and easy. This tutorial
>> demonstrates the fundamentals with a straightforward approach where code
>> can
>> be tested right away either here or in a Workspace window. The beauty of
>> Squeak Smalltalk resides in the possibility to evaluate, inspect, print
>> and
>> debug code anywhere and this window is no different.
>> +
>> + This tutorial demonstrates how...
>> +
>> + * to retrieve an XML document from the World Wide Web
>> + * to instance an XML document class
>> + * to inspect and understand the content of an XML document
>> + * to retrieve and display values from specific XML tags
>> +
>> + Retrieve an XML document from the World Wide Web
>> +
>> + There are many manners to retrieve data from the World Wide Web in
>> Squeak
>> Smalltalk. HTTPClient is among them and let you download files in all
>> simplicity. Select the following code snippet and inspect it (press
>> alt-i).
>> An Inspect window will open with the document loaded in memory. The
>> result
>> is a MIMEDocument object.
>> +
>> + HTTPClient httpGetDocument:
>> ''http://www.squeaksource.com/ss/feed.rss''.
>> +
>> + TIP: Select HTTPClient and browse it (press alt-b) to open a System
>> Browser window on its class. HTTPClient does not have instance methods
>> but
>> it has class methods. Click on class to see class methods.
>> +
>> + Instantiate an XML Document
>> +
>> + An instance of MIMEDocument will not allow to retrieve XML data in a
>> comprehensive manner because it does not understand the nature of XML.
>> For
>> this reason, it is necessary to parse the content of MIMEDocument using
>> XMLDOMParser. XMLDOMParser>>parseDocumentFrom: requires a stream as a
>> parameter and ReadStream will be used for this purpose. The following
>> code
>> snippet instantiates an XMLDocument using the content of the downloaded
>> file.
>> +
>> + | doc |
>> + doc := HTTPClient httpGetDocument:
>> ''http://www.squeaksource.com/ss/feed.rss''.
>> + XMLDOMParser parseDocumentFrom: (ReadStream on: (doc content)).
>> +
>> + Inspect and understand the content of an XML document
>> +
>> + XML is a flexible document format and it is necessary to understand how
>> each given XML file is structured in order to properly search, retrieve
>> and
>> manipulate data. Inspecting values is critical in a dynamic programming
>> language and environment, such as Squeak Smalltalk. Select the previous
>> code
>> snippet and inspect it (press alt-i).
>> +
>> + Unfortunately, the Inspect window does not reveal a lot about the XML
>> structure of the downloaded file. Select the previous code snippet once
>> again and explore it (press alt and the capital letter i). An Explorer
>> window will open with a tree outline on the instance of XMLDocument.
>> +
>> + The Inspect and Explorer windows tell a lot about an XMLDocument. The
>> sections are instance variables and their values are displayed aside. In
>> the
>> Explorer window, unfold elementsAndContents. Unfold other sections as
>> deem
>> necessary to understand the XML format and the data available.
>> +
>> + The gibberish coding is about to become clear. Open a Browser window
>> from
>> the world menu and right click in the first pane, select find class
>> (press
>> alt-f) and type XMLDocument to search for its class, or select the class
>> name and browse it (press alt-b). However, it is suggested to read more
>> about XMLParser and XMLParserTest first.
>> +
>> + Retrieve and display values from specific XML tags
>> +
>> + The downloaded XML file contains a list of items which are denoted by
>> the
>> tag name "item". The Explorer window revealed the content of interest is
>> located at the array index 1 of the elementsAndContents.
>> +
>> + The following code snippet will display items in a Transcript window.
>> Open
>> a Transcript window using the world menu before selecting and executing
>> the
>> code. Select the code snippet and execute it (press alt-d).
>> +
>> + | doc xml |
>> + doc := HTTPClient httpGetDocument:
>> ''http://www.squeaksource.com/ss/feed.rss''.
>> + xml := XMLDOMParser parseDocumentFrom: (ReadStream on: (doc content)).
>> + (xml elements at: 1) tagsNamed: #item do: [:e |
>> + Transcript show: (e asString); cr.
>> + ].
>> +
>> + An XML item looks like this:
>> +
>> + <item>
>> + <title>SqueakSource-lr.1039.mcz</title>
>> + <link>http://www.squeaksource.com/ss.html</link>
>> + <description>integrated new stylesheet</description>
>> + <pubDate>Sat, 10 Apr 2010 11:30:38 +0100</pubDate>
>> + <author>Lukas Renggli &lt;[hidden email]&gt;</author>
>> + <category>SqueakSource, seaside, server</category>
>> + <enclosure length="302570" type="application/x-monticello"
>> url="http://www.squeaksource.com/ss/SqueakSource-lr.1039.mcz"/>
>> + <guid isPermaLink="false"/> </item>
>> +
>> + The following code snippet uses information learned, retrieves each
>> comment and displays them in a Transcript window. Notice an author can
>> have
>> a nil value and is handled accordingly.
>> +
>> + | doc xml |
>> + doc := HTTPClient httpGetDocument:
>> ''http://www.squeaksource.com/ss/feed.rss''.
>> + xml := XMLDOMParser parseDocumentFrom: (ReadStream on: (doc content)).
>> + (xml elements at: 1) tagsNamed: #item do: [:e |
>> + Transcript
>> + show: ''Date: '', ((e firstTagNamed: #pubDate) contentString); cr;
>> + show: ''Title: '', ((e firstTagNamed: #title) contentString); cr;
>> + show: ''Author: '',
>> + (((e firstTagNamed: #author) notNil)
>> + ifTrue: [(e firstTagNamed: #author) contentString]
>> + ifFalse: ['''']); cr;
>> + show: ''Description: '', ((e firstTagNamed: #description)
>> contentString); cr; cr.
>> + ].
>> +
>> + An item will now looks like:
>> +
>> + Date: Wed, 21 Apr 2010 22:33:18 +0100
>> + Title: SqueakSource-lr.1060.mcz
>> + Author: Lukas Renggli <[hidden email]>
>> + Description: - ignore email errors
>> + '!
>>
>> Item was added:
>> + ----- Method: SqueakTutorialsOnXML classSide>>bookName (in category
>> 'accessing') -----
>> + bookName
>> + ^'XML'!
>>
>> Item was added:
>> + SqueakHelp subclass: #SqueakTutorials
>> + instanceVariableNames: ''
>> + classVariableNames: ''
>> + poolDictionaries: ''
>> + category: 'Help-Squeak-Project'!
>>
>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Help-Squeak-Project-it.4.mcz

Ian Trudel-2
2010/5/4 Hannes Hirzel <[hidden email]>:
> Sorry I meant
>
> to create an instance of the XMLDocument class
>

Thanks for the feedback. I have noticed few errors to be corrected but
I will do it later. On this particular matter, "to create an instance"
and "to instantiate" are synonyms.

Ian.
--
http://mecenia.blogspot.com/