我想编辑现有的XML文件,同时保留它的原始布局.这包括新行,注释等.编辑包括在XML中查找元素和修改文本值.
我的第一次尝试是将XMLParser与XmlUtil.serialize一起使用,但这不符合要求.
任何人都知道XMLParser的任何替代方法,其中编辑是原始XML字符串的"到位"?如果没有,也许有一个库使用XPath/GPath执行搜索,只返回查找的位置,所以我可以做StringBuilder.replace.
编辑:
现在我做了这个函数,找到XML节点的字符串索引(我可以使用xpath找到),然后我在索引上进行替换.适用于简单节点<node> value </ node>:
def find_location_by_node(xmlString, root_xml, node)
{
current_index = 0;
for(current_node in root_xml.depthFirst())
{
node_name = current_node.name().getLocalPart()
current_index = xmlString.indexOf('<' + node_name, current_index);
if(current_node == node)
{
end_tag = '</' + node_name + '>';
end_tag_index = xmlString.indexOf(end_tag, current_index) + end_tag.length();
return [current_index, end_tag_index];
}
}
return -1;
}
Run Code Online (Sandbox Code Playgroud) 有没有办法启动或停止使用上下文文件或@Scheduled注释初始化的Spring Scheduled Tasks安排的任务?
我想在需要时启动任务,并在不再需要运行任务时停止它.
如果这是不可能的,那么将弹簧变量注入线程的替代方法是什么?
添加配方rvm :: vagrant并运行vagrant配置后,我得到了:
/usr/local/bin/chef-solo: line 23: /opt/vagrant_ruby/bin/chef-solo: No such file
or directory
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
Run Code Online (Sandbox Code Playgroud)
这个问题应该已修复:https: //github.com/fnichol/chef-rvm/issues/121
即使我添加了这行:
'rvm' => {
'vagrant' => {
'system_chef_solo' => '/opt/vagrant_ruby/bin/chef-solo'
}
}
Run Code Online (Sandbox Code Playgroud)
我仍然得到错误.我该如何从中恢复?
我有节点的配方和属性文件.例如localhost和linode.我试图在默认或其他属性之前首先加载属性文件(并设置主机名等).例:
属性/ localhost.rb:
default[:hostname] = "localhost"
default[:nginx][:hostname] = 'mbdev-localhost'
include_attribute 'mbdev::common'
Run Code Online (Sandbox Code Playgroud)
属性/ common.rb
default[:nginx][:website1][:url] = "subdomain." + default[:nginx][:hostname]
Run Code Online (Sandbox Code Playgroud)
食谱/ localhost.rb
include_recipe 'mbdev::default'
Run Code Online (Sandbox Code Playgroud)
运行列表:
'mbdev::localhost'
Run Code Online (Sandbox Code Playgroud)
但是,似乎include_attribute使'common'属性首先加载.因此nginx-hostname尚未设置...
我得到的顺序是:1)加载属性/ default.rb 2)加载属性/ common.rb 3)关于+的错误
如何在common.rb之前加载localhost.rb?
如果我使用Scala Process/ProcessBuilder启动了一个进程.我怎样才能获得创建过程的pid?
我找不到PID提及任何官方文档: http://www.scala-lang.org/api/2.10.4/index.html#scala.sys.process.Process HTTP://www.scala -lang.org/api/2.10.4/index.html#scala.sys.process.ProcessBuilder http://www.scala-lang.org/api/2.10.4/index.html#scala.sys.process.包
在内部ContainerResponseFilter我想得到"处理程序",即类@Path和@GET/ @PUT-annotated方法匹配我将提供的URL.
例:
someJerseyVariable.getHandlerForURI(request.getRequestUri());
Run Code Online (Sandbox Code Playgroud)
我找不到任何类似的方法.
我想要这个的原因是,要统计每个处理程序服务的请求数以及成功/失败的数量.还欢迎任何其他替代方案.
从这里:http://www.google.com/support/analyticshelp/bin/answer.py?hl = zh-CN& answer = 1136920
<script type="text/javascript">
function recordOutboundLink(link, category, action) {
try {
var myTracker=_gat._getTrackerByName();
_gaq.push(['myTracker._trackEvent', ' + category + ', ' + action + ']);
setTimeout('document.location = "' + link.href + '"', 100)
}catch(err){}
}
</script>
Run Code Online (Sandbox Code Playgroud)
如果您注意到+类别+和+动作+都在引号中.那么分析脚本如何获得它们的价值呢?
我想在我的应用程序中出现异常时发送电子邮件并呈现常规500页.我找不到如何执行500页渲染:
class ApplicationController < ActionController::Base
rescue_from StandardError do
send_email_of_error
# what goes here?
end
...
end
Run Code Online (Sandbox Code Playgroud) 我想做这样的事情:
属性/ default.rb
if node[:chef_environment] == 'dev'
include_attribute "mbev::dev"
else
include_attribute "mbdev::production"
end
Run Code Online (Sandbox Code Playgroud)
但似乎'node'等于当前节点的名称.
VIM包含一个'set guifont'选项来更改字体.Neovim 不支持此选项,所以我想知道是否可以更改Neovim在终端中使用的字体?
我想中止带有自定义退出代码的 rake 任务(与执行的 shell 脚本通信满足特定条件)。
Rake 任务成功返回 0,失败总是返回 1。有没有办法制作自定义代码?
我想使用JSON序列化将查询结果保存到redis中并查询它.
将查询结果提供给json非常简单:
JSON.generate(Model.all.collect {|item| item.attributes})
Run Code Online (Sandbox Code Playgroud)
但是我找不到将其反序列化回ActiveRecord的正确方法.最直接的方式:
JSON.parse(@json_string).collect {|item| Model.new.from_json(item)}
Run Code Online (Sandbox Code Playgroud)
给我一个错误:
WARNING: Can't mass-assign protected attributes: id
Run Code Online (Sandbox Code Playgroud)
所以id变空了.我想过只使用OpenStruct代替ActiveRecord,但我相信有更好的方法.
我刚刚安装了spf13-vim并在运行vim时收到此警告:
airline themes have been migrated to github.com/vim-airline/vim-airline-themes
and will be removed from the core in the near future.
Run Code Online (Sandbox Code Playgroud)
我该如何修复或禁用该通知?