open xml file with nokogiri update node and save

后端 未结 1 1889
栀梦
栀梦 2021-01-16 01:13

I\'m trying to figure out how to open an xml file, search by an id, replace a value in the node and then resave the document.

my xml



        
相关标签:
1条回答
  • 2021-01-16 01:36

    First of all, your node_update is actually a NodeSet, not the Node that you probably think it is. You need a Node if you want to call inner_html= on it:

    node_update[0].inner_html = 'true'
    

    Then writing out the updated XML is just a bit of standard file manipulating combined with a to_xml call:

    File.open('whatever.xml', 'w') { |f| f.print(doc.to_xml) }
    

    As an aside, your input isn't valid XML. You have a </details> but no <details>.

    0 讨论(0)
提交回复
热议问题