0
我有一个html文件,看起来像这样使用引入nokogiri如何使用引入nokogiri :: XML ::文本错误的参数数目
<html>
<head>
<title><* page.title *></title>
</head>
<body>
<h1>h<* recipe.name *></h1>
<* EACH recipes recipe *>
<* food.name *>
<* EACH recipe.nicknames nickname *>
<p><* things to be replaced *></p>
<* ENDEACH *>
<* ENDEACH *>
</body>
</html>
我有一个JSON文件更改节点的文本值。我正在使用json ruby library
来解析它,并将它作为一个散列回来。我需要使用这些键并将值插入到这个html文件中。
到目前为止,我的Ruby脚本看起来像这样
require 'rubygems'
require 'nokogiri'
require 'json'
data = File.read("data.json")
obj = JSON.parse(data)
puts obj.values
page = Nokogiri::HTML(open("somethingtemplate"))
# base = Nokogiri::XML::Node.new
# base["href"] = "http://google.com"
# page.xpath('//body/h1').each do |node|
# node.add_child(base)
# puts child.text
# end
builder = Nokogiri::XML::Text.new do page
page.body {
page.h1
page.text "hello world"
}
end
puts builder.doc
我在这里看到了别人的例子 - >Insert Text After Specific XML Tag in Nokogiri
我收到此错误
`new': wrong number of arguments (0 for 2+) (ArgumentError)
的文档没有例子,它不适合我。