Validating XML documents

(Gary Henderson) #1

Need an example of an XPATH expression that tests for a correct value in the element being checked. So far tests all Pass, even when the target element is not present or has undesired content. I think I need just one good example!

(Tibor Blenessy) #2


it’s not very clear how your question relates to SonarQube / SonarLint or SonarCloud. Are you trying to analyze some code? Which language? Please try to explain what are you trying to achieve and provide some examples.

(Gary Henderson) #3

Thank you, Tibor. My goal is to validate server configuration files, source code stored as declarative XML, etc, and it seems that SonarQube will do that if I can create the custom tests needed. A normal validation will be, Does a specific XML element in the file contain the correct value? The use of XPATH in the test expressions is perfect for this, but I need the answer to the question… does the node at //path/element contain the right value? XPATH can find the value for me, in the file being tested, but how do I ask “is it equal to X?” and get a failed test if it is not?

(Pierre-Yves Nicolas) #4


Did you try something like the following expression?
//title[text() = 'Hello']

This is pure XPath, it has nothing specific to SonarQube.


(Tibor Blenessy) #5

A post was split to a new topic: Help with xpath for xml custom rules