evaluating XPathCompiler.compilePattern
Added by Anonymous about 16 years ago
Legacy ID: #5402950 Legacy Poster: kendall shaw (queshaw)
I want to test that an element exists, so I tried using XPathCompiler.compilePattern() and have not managed to get it to work as I expect. How is it used? After using compilePattern, I tried XPathSelector.effectiveBooleanValue() which returned false when the element existed. I got the same from trying XPathSelector.evaluateSingle() and checking the boolean value of the atomic value.
Replies (2)
RE: evaluating XPathCompiler.compilePattern - Added by Anonymous about 16 years ago
Legacy ID: #5403057 Legacy Poster: Michael Kay (mhkay)
I'm not sure what you mean. After calling compilePattern(), you get an expression E that allows you to determine whether the context item matches the given pattern. But if an element doesn't exist, then it can't be the context item, so how would you test it? (If it doesn't exist, then surely it can't be an element? This is getting metaphysical.) Perhaps you want to test whether a document D contains any elements named N? Or any elements that match some other criteria? In the former case, evaluate the XPath expression "//N" with D as the context node, and test whether the result is empty.
RE: evaluating XPathCompiler.compilePattern - Added by Anonymous about 16 years ago
Legacy ID: #5403309 Legacy Poster: kendall shaw (queshaw)
Urggh. I was confused, sorry. I guess the document node won't match a pattern referring to some element.
Please register to reply