Help: I can't figure out how to use YAXO - the examples show how to
parse a document (and I get that far) but how do I do useful things with the document? The #tagsNamed... and #findFirstTagNamed: methods don't seem to find anything when I use them. Furthermore, I don't see any generic way to visit all nodes and do the comparison myself (#printXMLOn: is the only thing close, but it seems pretty tied to printing XML and not a generic way to visiting the nodes)? As I don't see any XPath implementations, I must be missing something big. Can someone give me a pointer? Basically I have a little test document, and I'd like to get to the span node called #main, and ideally replace its contents with another node (e.g. a div). This should be pretty trivial to do, but I am stuck. I started writing my own visit methods but I must be missing something? <html> <head> <title>My Title</title> </head> <body> <div id="test"> <p>This is <b>some</b> text</p> <p>Second paragraph</p> <span editable="true" id="main">edittable text</span> <br/> </div> </body> </html> Tim |
Did you try #elementsDoAndRecurse: ?
-- Hwee Boon |
hmmm I don't see: #elementsDoAndRecurse:
And I appear to be using the latest version from DolphinHarbour? #entityAt:looked promising but no go? Tim |
"TimM" <[hidden email]> wrote:
> hmmm I don't see: #elementsDoAndRecurse: > > And I appear to be using the latest version from DolphinHarbour? > Hi Tim I think I must come clean here. I did a crude port of Yaxo to Dolphin last year, because it was needed to port the SqueakMap HTML Parser, the latter being my real interest. I passed the results to Hwee Boon, who was interested in the XML stuff, so I expect he is mentioning #elementsDoAndRecurse: because he found it in my version. It is an instance method I added to the class XMLNodeWithElements, because I found the same problem you did with visiting the whole tree. I did not put in a method comment admitting to authorship, so Hwee Boon may not have realised it was mine. The code of the method is pretty trivial: elementsDoAndRecurse: aBlock elements ifNotNil: [:x| self elements do: [:each | aBlock value: each. (each respondsTo: #elements) ifTrue:[ each elementsDoAndRecurse: aBlock]]] (The apparently redundant argument in the block above deals with a difference in syntax between Squeak and Dolphin in handling ifNotNil:, which takes a zero-argument block in Squeak and a one-argument block in Dolphin.) By the way, although you talk about XML parsing, the example in your first post is pure HTML. If this is typical of your material, you may want the HTML parser as well as Yaxo. My port to Dolphin is currently hosted by Bill Schwab (http://needle.anest.ufl.edu/anest4/bills/Smalltalk.htm) if you want to try it. Come back if any queries. Best wishes Peter Kenny |
> elementsDoAndRecurse: aBlock
> > elements > > ifNotNil: [:x| > > self elements do: [:each | aBlock value: each. > > (each respondsTo: #elements) ifTrue:[ each > elementsDoAndRecurse: aBlock]]] > > (The apparently redundant argument in the block above deals with a > difference in syntax between Squeak and Dolphin in handling ifNotNil:, > which > takes a zero-argument block in Squeak and a one-argument block in > Dolphin.) The ifNotNil one arg block is nice when you need to expect nil returns from message sends self elements ifNotNil: [ :e | e doSomething ]. Squeak doesn't support this (IMO it should). However, Dolphin 6, like VisualWorks, now supports both forms. so you can write: elements ifNotNil: [ :e | ] or elements ifNotNil: [ ] Dolphin 5 hits you with an error if you try and do that. |
Hey thanks guys, so it would seem that Peter's method would be better
written as: elements ifNotNil: [:x| x do: [:each | aBlock value: each..... Although, in my version of Yaxo, #elements is defined as: elements ^self entities collect: [:each | each value] So I had to change the method to: self elements ifNotNil: [ :x | however, if elements is defined as above.... it won't ever be nil (you will get a walkback if entities is nil)? So you might as well do: self elements do: [:each | .... Tim "Sean M" <[hidden email]> wrote in message news:7Qvef.548$[hidden email]... >> elementsDoAndRecurse: aBlock >> >> elements >> >> ifNotNil: [:x| >> >> self elements do: [:each | aBlock value: each. >> >> (each respondsTo: #elements) ifTrue:[ each >> elementsDoAndRecurse: aBlock]]] >> >> (The apparently redundant argument in the block above deals with a >> difference in syntax between Squeak and Dolphin in handling ifNotNil:, >> which >> takes a zero-argument block in Squeak and a one-argument block in >> Dolphin.) > > The ifNotNil one arg block is nice when you need to expect nil returns > from message sends > > self elements ifNotNil: [ :e | e doSomething ]. > > Squeak doesn't support this (IMO it should). > > However, Dolphin 6, like VisualWorks, now supports both forms. so you can > write: > > elements ifNotNil: [ :e | ] > or > elements ifNotNil: [ ] > > Dolphin 5 hits you with an error if you try and do that. > |
In reply to this post by Peter Kenny-2
> method I added to the class XMLNodeWithElements, because I found the same
> problem you did with visiting the whole tree. Your method was exactly what I was writing (except yours is better so I'll keep it ;-) This does beg the question - what is the point of the #tagsNamed... and #firstTagNamed: methods? They seem pretty pointless as they don't recurse down any of the levels of tags? In fact other than successfully parsing the document it seems that YAXO doesn't really do anything. When searching the archives on people using YAXO it seems that many have switched from MSXML to it, but I am left wondering how they are using it. Maybe just for really simple things like: <customer> <name>Tim</name> <age>25</age> </customer> But even then those methods don't find <age>.... so whats to the point? Tim |
In reply to this post by Sean M-7
Sean M escribió:
>>elementsDoAndRecurse: aBlock >>(The apparently redundant argument in the block above deals with a >>difference in syntax between Squeak and Dolphin in handling ifNotNil:, >>which >>takes a zero-argument block in Squeak and a one-argument block in >>Dolphin.) > The ifNotNil one arg block is nice when you need to expect nil returns from > message sends > self elements ifNotNil: [ :e | e doSomething ]. > Squeak doesn't support this (IMO it should). Indeed it does, but using #ifNotNilDo: monadicValuable VisualAge has #ifNil: #ifNotNil: with the same semantics as Dolphin, but doesn't have an implementation of #ifNil:ifNotNil: :-) However, Dolphin optimizes the sends of #ifNil:/#ifNotNil:, right? > However, Dolphin 6, like VisualWorks, now supports both forms. so you can > write: > elements ifNotNil: [ :e | ] > or > elements ifNotNil: [ ] Hey! I didn't noticed that :-) Thank you Regards, -- Esteban. |
In reply to this post by TimM-3
"TimM" <[hidden email]> wrote:
> Hey thanks guys, so it would seem that Peter's method would be better > written as: > > elements > ifNotNil: [:x| > x do: [:each | aBlock value: each..... > > Although, in my version of Yaxo, #elements is defined as: > > elements > ^self entities collect: [:each | each value] > > > So I had to change the method to: > > self elements ifNotNil: [ :x | > > however, if elements is defined as above.... it won't ever be nil (you > get a walkback if entities is nil)? So you might as well do: > > self elements do: [:each | .... Tim It looks as though we are talking about different versions of Yaxo. The version I have, which I got from SqueakMap just over a year ago, is called Yaxo-2.0b. In this version there is no mention of entities; elements just is an instance variable, though its accessor uses a sort of lazy initialisation: elements elements ifNil: [elements := OrderedCollection new]. ^elements The coding of #elementsDoAndRecurse: uses a simple extension of the existing #elementsDo: method; I didn't stop to think if there was any implicit double testing of conditions. However, the coding of #elements above shows that the instance variable can have a nil value. It would be as well to check whether your version of Yaxo from Dolphin Harbor is up to date. When I corresponded with Hwee Boon last year, he said he had agreed with Steve Waring to merge my port with the existing version on DH and post the result back there; it looks as though that may not have happened. Good luck! Peter Kenny |
Is there any way you can post your 2.0b port? The version on Dolphin
harbour says: Download: DolphinYAXO_5.1.2.zip (download may be redirected to mirror) Release Date: 6 Nov 2002 Version: 5.1.2 More importantly - this is what may be included in the latest D6, as STS uses it. It would be good to ensure that at least the newer version can be loaded or if not, that the newer dolphin could include the latest version. |
I had a quick look at Squeak and got as far as loading YAXO from Squeak
Map (I think - Squeak is just too wierd for me to get my head around) But not sure where it put it? In a Package browser I can see a Category XML with some sub-section called Parser that has similar classes in it. But If I click on parser and do file out, does that give me the code I would need? But then how did Dolphin endup with BASE and DOM packages? Can I then use STS to help me import this stuff (I noticed there was code snippet for importing squeak stuff in your readme Peter). Anyway - any pointers would be helpful. Tim |
In reply to this post by Tim M
"TimM" <[hidden email]> wrote in message
news:[hidden email]... > Is there any way you can post your 2.0b port? The version on Dolphin > harbour says: > > Download: DolphinYAXO_5.1.2.zip (download may be redirected to mirror) > > Release Date: 6 Nov 2002 > > Version: 5.1.2 > > More importantly - this is what may be included in the latest D6, as > STS uses it. It would be good to ensure that at least the newer version > can be loaded or if not, that the newer dolphin could include the > latest version. > Tim My port is currently available on Bill Schwab's site (http://needle.anest.ufl.edu/anest4/bills/Smalltalk.htm), but: a. This is in a bundle which includes the Squeak HTML parsers (which were my main interest). b. There were one or two holes in the port (due to my ignorance of Squeak syntax), which did not affect the HTML side but might be important for XML. I believe that Yar Hwee Boon produced a version of my port which filled in the holes mentioned in b. above. My work has moved in a different direction over the past year, so I am not currently working on this, but if anyone has any queries not covered by the (rather long-winded) package comments I will do my best to help. Best wishes Peter |
In reply to this post by Tim M
Tim
"TimM" <[hidden email]> wrote: > I had a quick look at Squeak and got as far as loading YAXO from Squeak > Map (I think - Squeak is just too wierd for me to get my head around) I have looked at SqueakMap, and I am pretty certain that what is now there is the same as I downloaded last year. So if you start there, you will simply be repeating what I did. It will be easier to just import my package SquealMapXMLParser.pac from Bill's site. As far as I can see, it is all complete apart from a couple of methods in class XMLNamespaceScope, which will only matter if you want to use namespaces - I am sure it will not be too difficult to fix these anyway, once I understand the Squeak curly bracket notation. I have checked back, and the ported code passed the YAXO unit tests. > (I noticed there was > code snippet for importing squeak stuff in your readme Peter). > All that code snippet does is to convert the Squeak left-arrow assignment to the Dolphin convention and change the line ending convention. This is irrelevant if you start from my ported code . Best wishes Peter |
In reply to this post by Peter Kenny-2
Opps. I did have the intention to do the integration and had a short
discussion with Steve. I started working on it but interest faded as I moved on to something else :) Sorry for not updating the status. I seem to remember David Gorisek's OmniBase (or was it STS) packages come with the YAXO package. Maybe someone can check it out and see if he allows usage of it, if it is appropriate. -- Hwee Boon |
"[hidden email]" <[hidden email]> wrote:
> Opps. I did have the intention to do the integration and had a short > discussion with Steve. I started working on it but interest faded as I > moved on to something else :) Sorry for not updating the status. Hwee Boon Never mind - much the same happens to most of us, including me. But could you remind me how you completed my port of YAXO by translating the Squeak curly bracket notation? (It affects the methods XMLNamespaceScope>>enterScope and >>initScope only, as far as I can see.) If I had that, I could post the completed port on Bill's site, and that might be helpful to Tim. If Tim is right, STS uses the older version of YAXO that is on DolphinHarbor. Thanks Peter |
Offhand, these would be:
enterScope self scope addLast: (Array with: self defaultNamespace with: nil with: currentBindings) initScope scope := OrderedCollection new: 20. currentBindings := Dictionary new. scope addLast: (Array with: 'http://www.w3.org/TR/REC-xml-names' with: currentBindings with: nil) since the Squeak {} syntax is evaluated at run time (contrast with #()) to create an Array instance. -- Hwee Boon |
"[hidden email]" <[hidden email]> wrote in message
news:[hidden email]... > Offhand, these would be: > > enterScope > self scope addLast: (Array with: self defaultNamespace with: nil with: > currentBindings) > > > initScope > scope := OrderedCollection new: 20. > currentBindings := Dictionary new. > scope addLast: (Array with: 'http://www.w3.org/TR/REC-xml-names' with: > currentBindings with: nil) > > > since the Squeak {} syntax is evaluated at run time (contrast with #()) > to create an Array instance. > > -- > Hwee Boon > Hwee Boon Many thanks - I shall get those incorporated as soon as I can. Peter |
Guys - it would be good to push and get this stuff sorted out before the
release of D6 (and tested in that image), as YAXO does appear to be in the D6 professional image due to STS. While it seems that the differences are small - it has suprised me that something quite common seems quite backward in such a modern environment... But like you said - its often a labor of love and then you move on to something else... I do wonder if Dolphin is missing a community repository to pt these things into.... with STS being readily available maybe it would be good to push for some open repository in both editions... It seems to have helped squeak (if I could ever figure it out) a lot. Tim Anyway - I really appreciate your help and pointers. "Peter Kenny" <[hidden email]> wrote in message news:[hidden email]... > > "[hidden email]" <[hidden email]> wrote in message > news:[hidden email]... >> Offhand, these would be: >> >> enterScope >> self scope addLast: (Array with: self defaultNamespace with: nil with: >> currentBindings) >> >> >> initScope >> scope := OrderedCollection new: 20. >> currentBindings := Dictionary new. >> scope addLast: (Array with: 'http://www.w3.org/TR/REC-xml-names' with: >> currentBindings with: nil) >> >> >> since the Squeak {} syntax is evaluated at run time (contrast with #()) >> to create an Array instance. >> >> -- >> Hwee Boon >> > > Hwee Boon > > Many thanks - I shall get those incorporated as soon as I can. > > Peter > > |
Free forum by Nabble | Edit this page |