FXML icon indicating copy to clipboard operation
FXML copied to clipboard

Strange behavior when using xpath with HTML documents

Open ghollisjr opened this issue 1 year ago • 1 comments

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&gt;</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.

ghollisjr avatar May 11 '23 05:05 ghollisjr

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&gt;</p>, ... {100C3D71C3}>#<XPATH:NODE-SET <p>hello&gt;</p>, ... {100C3D71C3}>

ruricolist avatar May 14 '23 18:05 ruricolist