I’m writing an XPath expression in Java, and am trying to grab all elements with a particular GUID. Basically, I’m doing:
(NodeList) xpath.evaluate("//object[guid=" + guid + "]", objectDoc, XPathConstants.NODESET);
with a GUID:
eb52a56c-2a16-4256-ab0c-523cb6d19a3f
XPath throws me an error:
eb52a56c-2a16-4256-ab0c-523cb6d19a3f could not be formatted to a number!
and I assume that this is because of the dashes. Am I wrong? If not, is there a way to escape them? I found mention of escaping characters in XPath via Google, but nobody mentioned dashes.
Thanks,
Cody
Quote it. “//object[guid='” + guid + “‘]”