G5W
G5W

Reputation: 37661

XPath not handling self-closing tags

I am trying to make an XPath path to describe a node in html. This node contains a self-closing tag and that is making my XPath not work. Am I doing something wrong or is this a bug in the xml2 package?

library(xml2)
TestHTML = '<html> <body> <h2>ABC <br/>DEF</h2> </body> </html>'
Parsed = read_html(TestHTML)

# The text looks OK
H2 = xml_find_first(Parsed, "//h2")
xml_text(H2)
## [1] "ABC DEF"

# But when built into the path, it fails
xml_find_first(Parsed, "//h2[contains(text(), 'DEF')]")
## {xml_missing}
## <NA>

If I remove the <br/> part, it works fine.

I am using xml2_1.3.6.

Upvotes: 0

Views: 69

Answers (0)

Related Questions