ruby on rails - Nokogiri: Finding and XML element then adding child elements -


i have xml document , want add child elements under element name 'initgpty' , i'm attempting follows:

filename = "#{payment.updated_at.strftime("%y%m%d")}.xml" file_contents = file.read("#{filename}")  doc = nokogiri::xml(file_contents)  initgpty = doc.at_xpath("//initgpty") first_id_tag = nokogiri::xml::node.new "id", doc initgpty.add_next_sibling(first_id_tag) 

the problem that

initgpty = doc.at_xpath("//initgpty") 

returns nil i'm getting nomethoderror on .add_next_sibling. first time working both xml , nokogiri but, me, xml generated

doc = nokogiri::xml(file_contents) 

looks strange. here's snippet line outputs in rails console:

#<nokogiri::xml::element:0x58d9582 name="initgpty" namespace=#<nokogiri::xml::namespace:0x58ce1be href="urn:iso:std:iso:20022:tech:xsd:pain.008.003.02"> children=[#<nokogiri::xml::text:0x58d92d0 "\n        ">, #<nokogiri::xml::element:0x58d9212 name="nm" namespace=#<nokogiri::xml::namespace:0x58ce1be href="urn:iso:std:iso:20022:tech:xsd:pain.008.003.02"> children=[#<nokogiri::xml::text:0x58d8e84 "b8s chatter creators">]>, #<nokogiri::xml::text:0x58d8d12 "\n      ">]> 

is correct , nomethoderror being caused else? @ on matter appreciated.

try use css selectors. works xml-documents:

doc.css('initgpty').first #should return first element named initgpty 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -