Hi there. I am writing a fairly basic GreaseMonkey script that locates text in a specific element and then uses that text to do things later. The relevant bits of code are as follows:
In the HTML there is a span with the class 'someclass', which contains a small string of text:
<span class="someclass">some text</span>
Then in the JavaScript i am trying to find this class and pull its contents (the 'some text') into a variable using the standard XPath jazz:
document.evaluate("//span[@class='someclass']/text()", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
Here's the problem: When i run this on pages where 'some text' is a basic string with basic characters, everything works fine, but when i run it on pages where 'some text' contains entities, then it fails. For example, these are all fine and XPath returns the text i want:
<span class="someclass">some text</span>
<span class="someclass">some other text</span>
<span class="someclass">sometext</span>
<span class="someclass">some text 12345</span>
However, this gives me an error:
<span class="someclass">some text's text</span>
The error returned is:
Error: The expression is not a legal expression.
Source File: file:///blahblahblah.user.js
Line: (JS line i gave above)
I found a few results on here and on Google talking about how XPath has trouble with entities, but they were all doing things like [text() = 'blah &racquo; blah']
— in other words, their entities are in the XPath query itself. Mine aren't, they're in the text that i'm trying to return from the XPath query.
Is this the same problem? Is there any easy way around it?
Thanks!