Skip to content

Exploring_XML

hhzl edited this page May 24, 2025 · 34 revisions

Gathering of existing material ... to be moved to the tutorial.

Introduction https://wiki.squeak.org/squeak/1407

XML types

  • free definition of tags
  • standards based on XML for example SVG and MusicXML

example

XMLDOMParser addressBookXMLWithDTD
XMLDOMParser  parseDocumentFrom: XMLTokenizer addressBookXMLWithDTD readStream

Reading a XML file

https://wiki.squeak.org/squeak/6342

Accessing the topElement element

Cuis has xmlDocument topElement while Squeak and Pharo have #root. But that refers just to #topElement https://wiki.squeak.org/squeak/6439

Squeak tutorial

Squeak has an XML tutorial which explains how to access information in a rss page.

doc := HTTPClient httpGetDocument: 'http://source.squeak.org/trunk/feed.rss'.
	XMLDOMParser parseDocumentFrom: (ReadStream on: (doc content)).

for more see Squeak 6.0. adapt it for Cuis; seems not to work; check again.

Erudite

Lift out examples from Erudite https://github.com/Cuis-Smalltalk/Erudite

https://raw.githubusercontent.com/Cuis-Smalltalk/Erudite/refs/heads/master/Examples/xmlbook3.xml Add the statement which reads this here

FAO country names example

https://wiki.squeak.org/squeak/6342

(XMLDOMParser parseFileNamed: 'fao_country_names.xml')
  firstNode
  allElementsSelect: [ : each |
    each localName = 'geographical_region' ].

The file fao_country_names.xml seems to be no longer available in XML, see https://data.apps.fao.org/catalog/dataset/country-names

Find another example which uses allElementsSelect:

Pharo

From Pharo examples https://github.com/pharo-contributions/XML-XMLParser

|xmlString|
xmlString := '<?xml version="1.0" encoding="UTF-8"?>
<countries>
  <country code="af" handle="afghanistan" continent="asia" iso="4">Afghanistan</country>
  <country code="al" handle="albania" continent="europe" iso="8">Albania</country>
  <country code="dz" handle="algeria" continent="africa" iso="12">Algeria</country>
</countries>'.

"adapted for Cuis"

XMLDOMParser  parseDocumentFrom: xmlString readStream

The Cuis YAXO version does not have the Pharo XPath access. That is however in a separate Library: https://github.com/pharo-contributions/XML-XPath For more see the Pharo XPath booklet.

13 year old Pharo video https://www.youtube.com/watch?v=6q78hzawfGU

Exploring MusicXML

Tune: Mary had a little lamb

ABC notation https://abcnotation.com/tunePage?a=trillian.mit.edu/~jc/music/abc/mirror/musicaviva.com/england/mary-had-a-little-lamb-f/0000

MusicXML notation

https://abcnotation.com/getResource/downloads/code_/mary-had-a-little-lamb.xml?a=trillian.mit.edu/~jc/music/abc/mirror/musicaviva.com/england/mary-had-a-little-lamb-f/0000

https://musescore.com/user/34504790/scores/6127202 Clicking the download button offers to download it in MusicXML.

https://abcnotation.com/tunePage?a=trillian.mit.edu/~jc/music/abc/mirror/back.numachi.com/Frere_Jacques/0000 MusicXML https://abcnotation.com/getResource/downloads/code_/frere-jacques.xml?a=back.numachi.com:8000/dtrad/abc_dtrad.tar.gz/abc_dtrad/FRERJACQ/0000

Next

Next thing to do: Finalize the MusicXML example Frere Jacques : play it with correct duration.

Clone this wiki locally