open xml file with nokogiri update node and save

后端 未结 1 1513
猫巷女王i
猫巷女王i 2021-01-16 01:17

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:38

    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 but no

    .

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