I am also facing same kind of issue, I am trying to validate if a file name weblogic.xml, If the file doesn’t have declared the attribute names as page-check-seconds then report violation.
filePattern : weblogic.xml
The XPath query = not(//jsp-descriptor/jsp-param/param-name[text()=‘page-check-seconds’])
Message : Page check seconds are not mentioned
For XML, which is already immediately accessible to XPath, you can simply write your rules and check them using any of the freely available tools for examining XPath on XML.
Did you try these freely available tools to validate your XPath query before trying to use it in SQ?
Can you copy/paste here an example of weblogic.xml file containing the “page-check-seconds” attribute?
Just a suggestion to discard this problem: check the single quotes surrounding page-check-seconds, they look weird. I had on my side to replace them with real single quote: ‘page-check-seconds’
concat(count(//jsp-descriptor/jsp-param/param-name[contains(text(),‘page-check-seconds’)])>0,substring(false, 1 div not(//jsp-descriptor/jsp-param/param-name[contains(text(),‘page-check-seconds’)])))
but then also it is not working, any help will be really great. Thanks !!
To raise an XPath issue on a file, the XPath expression has to return a boolean. As your last expression is the result of the concat function, it returns a string.
I suggest using: count(//jsp-descriptor/jsp-param/param-name[text()='page-check-seconds']) = 0
One more thing: if the pattern of the XPath rule is weblogic.xml, it will only look for a file named weblogic.xml at the root of the project. You may want to set the pattern to **/weblogic.xml to scan all files named weblogic.xml.