[ssax-sxml] Re: custom sxpath convertors yielding non-sxml objects
Brought to you by:
oleg
From: <ol...@po...> - 2003-05-07 04:21:26
|
Hello! > 1. Is it possible and proper for a custom SXPath convertor to yield > output as *non*-SXML Scheme objects, when in the last step of an > SXPath query? A converter is defined as a Node|Nodelist -> Nodelist. It's highly desirable to abide by that signature. However, this requirement is not much an imposition: you can still do what you want. A custom converter should accept a nodelist, and return a proper list. If this list is non-empty, each element must be either - a proper list whose car is a symbol, or - *anything* else The SXML specification says that a Node, if it is not a proper node, must be a text string. It is certainly true for SXML produced by ssax:xml->sxml, but it is not strictly necessary. It's quite convenient, for example, to write integers in their "native" format rather than as strings of digits. It is sometimes convenient to use procedural values. Therefore, your example can be written as something like the following: ((sxpath `(// a @ href *text* ,custom)) sxml) where (define (custom attr-val) (let ((posn (regexp-match regexp attr-val))) (if posn (extract-match posn attr-val) '()))) Actually, I checked that at least in the old SXPath code, the custom converter is not even obliged to return a nodelist. A node suffices. So the function extract-match above can return basically anything it wishes to. If it returns a list, the list would be spliced in. Care should be taken in only one case: when returning an improper list or a list that should not be spliced in. Such a value can always be wrapped into a 1-arg vector or a closure. |