I am encountering an issue with the document.evaluate function when attempting to validate xPath in Firefox. The document.createNSResolver function seems to be malfunctioning as I only receive xmlDoc and nothing else. Even when I try leaving it with a null value in evaluate, it still does not work. Strangely, Edge, Opera, and Chrome do not have this problem as everything works smoothly on those browsers. I have been searching for a solution but have been unsuccessful so far...
My main function is structured like this:
const checkXPathVisiblity = (xPathValid?: string) => {
if (!xPathValid) return false;
try {
const parsedXPathValid = _.unescape(xPathValid);
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xml, 'text/xml');
const resolver = document.createNSResolver(xmlDoc);
const result = document.evaluate(parsedXPathValid, xmlDoc, resolver);
return !!result.booleanValue;
} catch (error) {
return false;
}
};
Where:
xPathValid:
number(Dokument/F0002x2) = 1
xml:
<?xml version="1.0" encoding="utf-8"?>
<Dokument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<F0001x1 id="F0001x1"></F0001x1>
<F0002x2 id="F0002x2">1</F0002x2>
</Dokument>