From szajmi at gmail.com Sat Mar 7 14:51:55 2009 From: szajmi at gmail.com (Andras Simon) Date: Sat, 7 Mar 2009 15:51:55 +0100 Subject: [plexippus-xpath-devel] interaction of plexippus and closure-html Message-ID: <9008cd5d0903070651kf0298a0y295478774c56a08d@mail.gmail.com> 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 "" (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? Andras From ivan4th at gmail.com Sat Mar 7 15:24:46 2009 From: ivan4th at gmail.com (Ivan Shvedunov) Date: Sat, 7 Mar 2009 18:24:46 +0300 Subject: [plexippus-xpath-devel] interaction of plexippus and closure-html In-Reply-To: <9008cd5d0903070651kf0298a0y295478774c56a08d@mail.gmail.com> References: <9008cd5d0903070651kf0298a0y295478774c56a08d@mail.gmail.com> Message-ID: <4d93c5bf0903070724k443c0252se0f8908f291be15b@mail.gmail.com> On Sat, Mar 7, 2009 at 5:51 PM, Andras Simon 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 "" > (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 "" (stp:make-builder))))) ("html") Ivan From szajmi at gmail.com Sat Mar 7 16:31:05 2009 From: szajmi at gmail.com (Andras Simon) Date: Sat, 7 Mar 2009 17:31:05 +0100 Subject: [plexippus-xpath-devel] interaction of plexippus and closure-html In-Reply-To: <4d93c5bf0903070724k443c0252se0f8908f291be15b@mail.gmail.com> References: <9008cd5d0903070651kf0298a0y295478774c56a08d@mail.gmail.com> <4d93c5bf0903070724k443c0252se0f8908f291be15b@mail.gmail.com> Message-ID: <9008cd5d0903070831g3b60c70dlea38c13439f2f4af@mail.gmail.com> On 3/7/09, Ivan Shvedunov wrote: > On Sat, Mar 7, 2009 at 5:51 PM, Andras Simon 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 "" >> (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 > "" > (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