Re: Does it make sense to work only with strings?
"Dmitry Lizorkin" <[email protected]> Wed, 22 Dec 2004 12:49:42 +0300
| Newsgroups | gmane.lisp.scheme.ssax-sxml |
|---|---|
| Message-ID | <[email protected]> |
Hello!
> ; And this doesn't work (numbers are numbers):
> ;
> (define tree
> '(*TOP*
> (item (@ (level 1)))
> (item (@ (level 3)))
> (item (@ (level 4)))))
> (write ((txpath "item[@level>2]") tree))
> ===> ()
> ....
> Is it really useful to return empty string here?
You have asked a very reasonable question.
XPath 1.0 Data Model implies all attribute values and character data in text
nodes to have the type _string_. On the other hand, as XML Schema appeared,
attribute values and text nodes were allowed to have different types, in
particular, number types. In fact, the SXML Specification also allows using
the Scheme datatype _number_ for attribute values and text nodes, for
example:
<cite-from-SXML-Specification>
(WEIGHT (@ (unit "pound"))
(NET (@ (certified)) 67)
(GROSS 95)
)
</cite-from-SXML-Specification>
I believe it useful to make SXPath consistent with the SXML Specification
and thus make SXPath consider non-string attribute values and text nodes as
a correct situation.
I modified the function "sxml:string-value" and committed the file
"sxpath-ext.scm" to SSAX CVS on SourceForge. In fact, the modification I
made consists of replacing the piece of code you noted
(if (string? node)
node
"") ; for XPath 1.0 it is an incorrect situation
with
(sxml:string node)
Your example now works as you expect it to:
((txpath "item[@level>2]")
'(*TOP*
(item (@ (level 1)))
(item (@ (level 3)))
(item (@ (level 4)))))
==>
((item (@ (level 3))) (item (@ (level 4))))
To elaborate, it may also be reasonable to map the XPath node test "text()"
not to
(ntype?? '*text*)
as it is currently mapped in SXPath, but to
(ntype?? '*data*)
in order to be able to extract non-string attribute values and text nodes
properly with SXPath. Does anyone has any objections to making such a change
in SXPath?
Dmitry
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/