【问题标题】:SonarQube how to creat custom rule for xml with xpathSonarQube 如何使用 xpath 为 xml 创建自定义规则
【发布时间】:2017-07-20 22:37:07
【问题描述】:
  • SonaQube:6.4
  • 声纳扫描仪:3.0.3
  • 项目名称:testxml

我已经按照指南 https://docs.sonarqube.org/display/DEV/Adding+Coding+Rules+using+XPath 创建了一个 xpath 规则,并在 saas xml rules 中激活它。

xpath 规则 7 文件如下:

  • 名称 -> myXmlRule
  • 关键字 -> myXmlRule
  • 描述 -> 测试
  • 严重性 -> 严重
  • 雕像 -> 准备就绪
  • 文件模式->
  • schemas -> //ATTRIBUTE[@tokenValue='lang']

xmlToolKit 中的架构 //ATTRIBUTE[@tokenValue='lang'] 成功,这意味着架构是正确的。

名为myXmlRule 的新规则已在Qualiy Profile saas xml rules 中激活

我的目标是找到具有lang 属性的title 节点,然后提升它。 规则怎么写?

test.xml 文件内容:

<?xml version="1.0" encoding="ISO-8859-1"?>

<bookstore>
<book>
    <title lang="eng">Harry Potter</title>
    <price>29.99</price>
</book>
<book>
    <title lang="eng">Learning XML</title>
    <price>39.95</price>
</book>
</bookstore>

在我的项目testxml 中只有test.xmlsonar-project.properties

在项目文件夹中运行sonar-scanner,出现错误信息

WARN: SCM provider autodetection failed. No SCM provider claims to support this project. Please use sonar.scm.provider to define SCM of your project.
16:41:11.456 WARN: Could not find schema //ATTRIBUTE[@tokenValue='lang']
16:41:11.456 WARN: Cannot validate file /Users/zt/Desktop/testXml/test.xml
16:41:11.457 WARN: Cause: org.sonar.plugins.xml.checks.XmlSchemaCheck$SchemaNotFoundException: Could not load schema "//ATTRIBUTE[@tokenValue='lang']"

请帮忙。谢谢。

【问题讨论】:

  • 您确定您使用的是正确的规则吗? schema 参数表明您正在使用规则规则 'XML files should be valid' ,而 XPath 检查的规则是 'Track违反 XPath规则'(xml:XPathCheck)。
  • @NicolasB.-SonarSourceTeam 谢谢,它有效。创建新规则必须检查Track breaches of an XPath rule

标签: xml xpath sonarqube


【解决方案1】:

创建 XPath 检查的规则是“跟踪违反 XPath 规则的情况”(xml:XPathCheck),而不是“XML 文件应该是有效的 em>'(屏幕截图中显示的那个)。

【讨论】:

    猜你喜欢
    • 2021-02-06
    • 2019-05-21
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-08
    • 2017-08-03
    相关资源
    最近更新 更多