I have a html file that looks like this
<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>
I have a json file. I am using the json ruby library to parse it and its coming back as a hash. I need to use the keys and insert the values into this html file.
so far my ruby script looks like this
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
I saw someone's example here -> Insert Text After Specific XML Tag in Nokogiri
I am getting this error
`new': wrong number of arguments (0 for 2+) (ArgumentError)
The doc does not have examples, its not working for me.
No comments:
Post a Comment