【问题标题】:How to write PDM rules for xml using xpath expressions in Sonar?如何在 Sonar 中使用 xpath 表达式为 xml 编写 PDM 规则?
【发布时间】:2014-02-11 18:28:11
【问题描述】:

我想在声纳中编写一个 XPATH 规则来检查是否存在某些 xml 标签,而不是用于自定义 xml。如果不可用,声纳应显示为错误。

提前致谢

感谢您的回复。我正在尝试在声纳中编写 XPATH 规则。这是 XML ..

<root>
    <child1 name =”test” > …………….. </child1>
    <child2 name =”test2”> ………….. </child2> 
</root>

这是我的 Xpath 表达式:

/child2 

这工作正常。该节点由声纳识别。如果找到 child2 节点,声纳会给出违规。

现在如果我没有找到 child1 节点,我想显示违规。 我正在尝试低于 XPATH 表达式,但它失败了。

not(boolean(/child1)) 

我还想知道 name 属性是否存在于 child1 节点中。 请帮我 … 提前致谢。

【问题讨论】:

    标签: sonarqube


    【解决方案1】:

    为此,您不应使用 PMD 插件,而应使用带有“XPath 规则”的XML plugin(请参阅this rule on Nemo)。

    【讨论】:

    • 感谢您的回复。我正在尝试在声纳中编写 XPATH 规则。这是 XML .. &lt;root&gt; &lt;child1 name =”test” &gt; …………….. &lt;/child1&gt; &lt;child2 name =”test2”&gt; ………….. &lt;/child2&gt; &lt;/root&gt; 这是我的 Xpath 表达式:这工作正常。它由声纳识别。如果找到 child2 节点,则表示违规。 //child2 现在如果我没有找到 child1 节点,我想给出违规。我正在尝试低于 XPATH 表达式,但它失败了。 Not(Boolean(//child2)) 我还想知道 name 属性是否存在于 child2 节点中。请帮助我……提前致谢。
    • 请编辑您的问题(或创建一个新问题)以添加详细信息,因为它在评论中不可读。谢谢。
    • 谢谢,我已经添加了更多信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-23
    • 1970-01-01
    • 1970-01-01
    • 2014-11-11
    • 2014-06-22
    相关资源
    最近更新 更多