下面是SSIS包的XML代码段;我正在尝试编写XPath查询以从SSIS包中查找所有“ SELECT *”语句。
我遇到了错误
<DTS:Executable
DTS:refId="Package\TEST\TEST_COUNT"
<DTS:ObjectData>
<SQLTask:SqlTaskData
SQLTask:Connection="{F7343EC3-A89E-4236-962C-FD2EB8B9491E}"
SQLTask:SqlStatementSource="select * from dbo.TEST where colname1=? and colname2=?"
SQLTask:ResultType="ResultSetType_SingleRow" xmlns:SQLTask="www.microsoft.com/sqlserver/dts/tasks/sqltask">
</SQLTask:SqlTaskData>
</DTS:ObjectData>
</DTS:Executable>
XML:
//SQLTask:SqlTaskData[contains(translate(@SQLTask:SqlStatementSource,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') ,"select *")]/../../@DTS:refId
Xpath查询:
{{1}}
我能够从https://www.freeformatter.com/xpath-tester.html成功地评估xpath表达式。但是,实际的软件包通过SonarQube中定义的XPath规则进行了验证,从那里我会收到此错误。
答案 0 :(得分:1)
这是您的XPath查询,带有注释中指出的带有短名称空间:
//*:SqlTaskData[contains(translate(@*:SqlStatementSource,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') ,"select *")]/../../@*:refId
现在,获取所有包含“ select *”的SqlStatementSource的方式相同:
//*:SqlTaskData[contains(translate(@*:SqlStatementSource,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') ,"select *")]/@*:SqlStatementSource
或使用已经发现的local-name()
函数:
//*[local-name()='SqlTaskData'][contains(translate(@*[local-name()='SqlStatementSource'],'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') ,"select count(*)")]/@*[local-name()='SqlStatementSource']