对于Ubuntu和/或CentOS,是否有一个包,它有一个命令行工具,可以执行XPath单线程,foo //element@attribute filename.xml或者foo //element@attribute < filename.xml逐行返回结果?
我正在寻找一些可以让我只是apt-get install foo或者yum install foo然后只是开箱即用,没有包装或其他必要的改编的东西.
以下是一些接近的事例:
引入nokogiri.如果我写这个包装器,我可以用上面描述的方式调用包装器:
#!/usr/bin/ruby
require 'nokogiri'
Nokogiri::XML(STDIN).xpath(ARGV[0]).each do |row|
puts row
end
Run Code Online (Sandbox Code Playgroud)
XML :: XPath的.可以使用这个包装器:
#!/usr/bin/perl
use strict;
use warnings;
use XML::XPath;
my $root = XML::XPath->new(ioref => 'STDIN');
for my $node ($root->find($ARGV[0])->get_nodelist) {
print($node->getData, "\n");
}
Run Code Online (Sandbox Code Playgroud)
xpath来自XML :: XPath返回太多噪音,-- NODE --和attribute = "value".
xml_grep 来自XML :: Twig无法处理不返回元素的表达式,因此无法在不进一步处理的情况下提取属性值.
编辑:
echo cat //element/@attribute | xmllint --shell filename.xml返回类似的噪音xpath …
拥有以下XML:
<node>Text1<subnode/>text2</node>
Run Code Online (Sandbox Code Playgroud)
如何通过XPath选择第一个或第二个文本节点?
像这样的东西:
/node/text()[2]
Run Code Online (Sandbox Code Playgroud)
当然不起作用,因为它是节点内每个文本的合并结果.
我正在使用Jenkins 2来编译Java项目,我想从pom.xml中读取该版本,我遵循这个例子:
https://github.com/jenkinsci/pipeline-plugin/blob/master/TUTORIAL.md
这个例子表明:
似乎访问文件系统存在一些安全问题,但我无法弄清楚它给出了什么(或为什么)这个问题:
我只是做了一个与示例有点不同的事情:
def version() {
String path = pwd();
def matcher = readFile("${path}/pom.xml") =~ '<version>(.+)</version>'
return matcher ? matcher[0][1] : null
}
Run Code Online (Sandbox Code Playgroud)
我在运行'version'方法时遇到的错误:
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method groovy.lang.GroovyObject invokeMethod java.lang.String java.lang.Object (org.codehaus.groovy.runtime.GStringImpl call org.codehaus.groovy.runtime.GStringImpl)
at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectMethod(StaticWhitelist.java:165)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:117)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:103)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:149)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:146)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:15)
at WorkflowScript.run(WorkflowScript:71)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:55)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:106)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:79)
at sun.reflect.GeneratedMethodAccessor408.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:100)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:79)
at sun.reflect.GeneratedMethodAccessor408.invoke(Unknown Source) …Run Code Online (Sandbox Code Playgroud) 我已经创建了一个管道并使用嵌入式groovy管道脚本定义,似乎无法从POM获取项目的版本ID.我试过这个在groovy控制台中工作但在Jenkins构建管道脚本中:
def project = new XmlSlurper().parse(new File("pom.xml"))
def pomv = project.version.toString()
Run Code Online (Sandbox Code Playgroud)
根据詹金斯的文档$POM_VERSION,当我将它分配给变量并将其回显时,该值中没有任何内容.
def pomv = "$POM_VERSION"
Run Code Online (Sandbox Code Playgroud)
要么
def pomv = '$POM_VERSION"
Run Code Online (Sandbox Code Playgroud)