I have a simple XML file like this:
<Course>
<CompanyName value="Ford"/>
<DepartmentName value="assessments"/>
<CourseName value="parts"/>
<Result>
<CoreData>
<Status value="completed"/>
In my controller I have:
def xml_facil
require 'xmlsimple'
config = XmlSimple.xml_in("#{Rails.root}/doc/TestResults/Ford/assessments/mike.xml", { 'KeyAttr' => 'value' })
@results = config['CourseName']
end
In my view I have:
<%= render @results %>
开发者_运维百科but the error I get is:
undefined method `formats' for nil:NilClass
I guess my method is returning nil here so how do I fix this so my view will render "parts"? Any help is appreciated!
Since you've switched to Nokogiri, you can dig out the value
attribute that you're interested in with this:
require 'nokogiri'
doc = Nokogiri::XML(open("#{Rails.root}/doc/TestResults/Ford/assessments/mike.xml").read)
value = doc.at('CourseName').attr('value')
精彩评论