[plexippus-xpath-devel] interaction of plexippus and closure-html

Andras Simon szajmi at gmail.com
Sat Mar 7 16:31:05 UTC 2009


On 3/7/09, Ivan Shvedunov <ivan4th at gmail.com> wrote:
> On Sat, Mar 7, 2009 at 5:51 PM, Andras Simon <szajmi at gmail.com> wrote:
>> I'm trying to use plexippus with closure-html to search in possibly
>> badly formed html. But I ran into the following:
>>
>> (defun show (xpath doc)
>>  (xpath:do-node-set (node (xpath:evaluate xpath doc))
>>    (format t "found element: ~A~%"
>>            (xpath-protocol:local-name node))))
>>
>>
>> (show "/html" (cxml:parse "<html><head></head><body></body></html>"
>> (stp:make-builder)))
>> found element: html
>> NIL
>>
>> as expected, but
>>
>> (show "/html" (chtml:parse #p"test.html" (stp:make-builder)))
>> NIL
>>
>> Here test.html contains the same string that was given to cxml:parse
>> above.
>>
>> Comparing the results of the two parse functions it looks like this
>> may have something to do with namespaces, but I'm not sure.
>>
>> What am I missing?
>>
>
> Yes, you must specify namespace bindings using xpath:with-namespaces
> around your xpath:evaluate call.
> The output of closure-html uses XHTML namespace which is
> http://www.w3.org/1999/xhtml
>
> CL-USER> (xpath:map-node-set->list
>           #'stp:local-name
>           (xpath:with-namespaces ((nil "http://www.w3.org/1999/xhtml"))
>             (xpath:evaluate "/html" (chtml:parse
> "<html><body></body></html>"
>                                                  (stp:make-builder)))))
> ("html")

Thanks! I tried with-namespaces (with this namespace) before, but gave
it a non-nil prefix and that didn't work. I was reading

http://common-lisp.net/project/plexippus-xpath/examples.html#id54052

which says "Note that it does not matter which namespace prefix we use
to name the 'http://foo' namespace. We could have called it 'foo' in
the XML document and 'quux' when using XPath, because the namespace
URI is what identifies the namespace, not the prefix." This paragraph
is probably fine as it is, but helped by my total lack of xml
expertise, it managed to mislead me. Thanks for the clarification!

Andras




More information about the plexippus-xpath-devel mailing list