Re: SXPath namespaces

Victor Morilla Padial <[email protected]> Fri, 12 May 2006 21:22:25 +0200
Newsgroups gmane.lisp.scheme.ssax-sxml
Message-ID <[email protected]>
Thanks for your clear explanation

Best regards

V=EDctor

Dmitry Lizorkin wrote:
> Hi,
> =20
> Please excuse me for the delayed answer to your question.
> =20
> Since your SXML document contains a namespace-id in element names, a=20
> namespace prefix occuring in the XPath node test should be mapped to=20
> that namespace-id for obtaining the result we expect, i.e:
> =20
> ((sxpath "my:schema" '[(my . "xsd")])
>    doc)
> =3D=3D>
> ((xsd:schema))
> =20
> Please note that (unlike XPath 2.0) the XPath 1.0 Specification=20
> implemented in sxpath does not support a default namespace declaration=20
> in node tests: in subsect. 2.3 of the XPath 1.0 Specification, it is=20
> stated that "..if the QName [in the node test] does not have a prefix,=20
> then the namespace URI is null (this is the same way attribute names=20
> are expanded)." You thus _have to_ use a prefix in an XPath name=20
> test for addressing a
> named node from a non-null namespace URI; i.e. your code
> /(sxpath "schema" '[...])/
> selects the 'schema child element (from a null namespace) regardless=20
> of the namespace binding supplied as the second argument.
> =20
> Since "XPath is a language for _addressing_ parts of an XML document",=20
> the result produced by the `sxpath' function for an XPath location=20
> path is a nodeset consisting of nodes in _exactly_ the same form (by=20
> `eq?') as in the original SXML document. You thus have no way of=20
> converting the '(xsd:schema) element into a '(schema) or '(my:schema)=20
> element in pure XPath. If you want your result to be returned in a=20
> different form, you can apply queries/transformations to it=20
> afterwards. For example, you can remove the "xsd:" prefix from all the=20
> nodes in the nodeset by using pre-post-order transformations:
> =20
> (pre-post-order
>    '((xsd:schema))
>    `((*text* . ,(lambda (tag text) text))
>      (*default*
>       . ,(lambda (tag . content)
>            (cons
>             (if
>              (equal?
>               (sxml:name->ns-id tag)  ; produces either #f or a string
>               "xsd")
>              (string->symbol (sxml:ncname
>                               (list tag)  ; a node is required as an=20
> argument
>                               ))
>              tag)
>             content)))))
> =3D=3D>
> ((schema))
> =20
> Note however that new SXML nodes are essentially constructed as a=20
> result of such a transformation; these new nodes are physically=20
> different from the ones from the original SXML document.
> =20
> Regards,
> Dmitry
> =20
>
>     ----- Original Message -----
>     *From:* Victor Morilla Padial <mailto:[email protected]>
>     *To:* [email protected]
>     <mailto:[email protected]>
>     *Sent:* Tuesday, May 09, 2006 1:42 AM
>     *Subject:* [ssax-sxml] SXPath namespaces
>
>     Hi,
>
>     Given the following code:
>
>     /(define doc
>       '(*TOP*
>         (@
>          (*NAMESPACES*
>           (xsd "http://www.w3.org/2001/XMLSchema")))
>         (*PI* xml "version=3D\"1.0\" encoding=3D\"UTF-8\"")
>         (xsd:schema)))
>
>     (pretty-print ((sxpath "my:schema" '[(my .
>     "http://www.w3.org/2001/XMLSchema")]) doc))
>     (pretty-print ((sxpath "schema" '[(#f .
>     "http://www.w3.org/2001/XMLSchema")]) doc))
>     (pretty-print ((sxpath "xsd:schema" '[(xsd .
>     "http://www.w3.org/2001/XMLSchema")]) doc))
>     /
>
>     I spected the result:
>     /((my:schema))
>     ((schema))
>     ((xsd:schema))/
>
>     But the real result is:
>     /(())
>     (())
>     (())/
>
>
>     What am I doing wrong? What's the correct way to deal with
>     namespaces using SXPath
>
>     Thanks in advance,
>
>     V=EDctor Morilla
>
>



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job ea=
sier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronim=
o
http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat=3D=
121642