There is a node-set function called id() in xpath. It might be the case that it does not work on your data if you load in HTML documents into FluentDOM / DOM-XML. The result is that you do not get any result, no nodes are returned by the find() function. That’s a pitty because you can use it to access elements in a short notation. There are two ways to deal with the problem:
- Give it a doctype: That’s what missing here to switch XPATH into XML mode or something like that. It’s enough that you add “
<!DOCTYPE>” in front of the HTML string before loading it into FluentDOM.
- Use the predicate: Just query the elements by their id attribute value:
//*[@id="content"]replaces pretty well
You can find out more about FluentDOM on a previous Blog-Post of mine.