FXML
FXML copied to clipboard
Strange behavior when using xpath with HTML documents
After doing
(ql:quickload (list "xpath" "fxml" "fxml/stp" "fxml/xpath" "fxml/html5"))
This works:
(xpath:evaluate "//*"
(fxml.html:parse "<html><head></head><body><p>hello></p></body></html>"
(fxml.stp:make-builder)))
==>
#<XPATH:NODE-SET <html xmlns="http://www.w3.org/1999/xhtml">
<head/>
<body>
<p>hello></p>
</body>
</html>, ... {101A546243}>
But this doesn't:
(xpath:evaluate "//html"
(fxml.html:parse "<html><head></head><body><p>hello></p></body></html>"
(fxml.stp:make-builder)))
==>
#<XPATH:NODE-SET empty {101A581663}>
Nor does this:
(xpath:evaluate "//p"
(fxml.html:parse "<html><head></head><body><p>hello></p></body></html>"
(fxml.stp:make-builder)))
==>
#<XPATH:NODE-SET empty {101A581663}>
It seems that wildcard searches are able to find matches while specific tag searches are failing.
I believe this issue here may be namespacing: the elements are in the XHTML namespace. This works for me:
(xpath:with-namespaces (("html" "http://www.w3.org/1999/xhtml"))
(xpath:evaluate "//html:p"
(fxml.html:parse "<html><head></head><body><p>hello></p></body></html>"
(fxml.stp:make-builder))))
=> #<XPATH:NODE-SET <p>hello></p>, ... {100C3D71C3}>#<XPATH:NODE-SET <p>hello></p>, ... {100C3D71C3}>