SonarQube 如何使用 xpath 为 xml 创建自定义规则 [英] SonarQube how to creat custom rule for xml with xpath
问题描述
- SonaQube:6.4
- 声纳扫描仪:3.0.3
- 项目名称:testxml
我已经阅读了指南
名为myXmlRule
的新规则已在Qualiy Profile saas xml rules
我的目标是找到具有 lang
属性的 title
节点,然后提升它.规则怎么写?
test.xml 文件内容:
<书店><书><title lang="eng">哈利波特</title><价格>29.99</价格>书><书><title lang="eng">学习 XML</title><价格>39.95</价格>书></书店>
在我的项目 testxml
中只有 test.xml
和 sonar-project.properties
在项目文件夹中运行sonar-scanner
,出现错误信息
WARN:SCM 提供程序自动检测失败.没有 SCM 提供商声称支持该项目.请使用 sonar.scm.provider 来定义您的项目的 SCM.16:41:11.456 警告:找不到架构//ATTRIBUTE[@tokenValue='lang']16:41:11.456 警告:无法验证文件/Users/zt/Desktop/testXml/test.xml16:41:11.457 警告:原因:org.sonar.plugins.xml.checks.XmlSchemaCheck$SchemaNotFoundException:无法加载架构//ATTRIBUTE[@tokenValue='lang']"
请帮忙.谢谢.
创建 XPath 检查的规则是跟踪 XPath 规则的违规" (xml:XPathCheck) ,而不是XML 文件应该是有效的"(屏幕截图中显示的那个).
- SonaQube:6.4
- sonar-scanner:3.0.3
- project name:testxml
I have fllow the guide https://docs.sonarqube.org/display/DEV/Adding+Coding+Rules+using+XPath create a xpath rule , and active it in saas xml rules
.
the xpath rule 7 fileds like this:
- name -> myXmlRule
- keyword -> myXmlRule
- description -> test
- severity -> major
- statues -> ready
- filePattern ->
- schemas -> //ATTRIBUTE[@tokenValue='lang']
the schemas //ATTRIBUTE[@tokenValue='lang']
success in xmlToolKit
,that means schemas is correct.
the new rule named myXmlRule
, has actived in Qualiy Profile saas xml rules
My goal is find title
node with lang
attribute, then raise it.
How to write rule?
test.xml file content:
<?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>
In my project testxml
only test.xml
and sonar-project.properties
in project folder run sonar-scanner
, it take error message
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']"
Please Help. Thanks.
The rule to create XPath checks is 'Track breaches of an XPath rule' (xml:XPathCheck) , not 'XML files should be valid' (the one shown in your screenshot).
这篇关于SonarQube 如何使用 xpath 为 xml 创建自定义规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!