Changes the value in xml using parsing


#1

Hi @Larryc

I am using xml_edit to change the value of xml. This is not working with below scenario.

I want to change the title of Atwood, Margaret author in Second Bookshelf in below xml:

<?xml version="1.0"?>
<shelves>
<bookshelf>
   <Name>First Bookshelf</Name>
   <book>
      <author>Conway, Damien</author>
      <title>Perl Best Practices</title>
   </book>
   <book>
      <author>Atwood, Margaret</author>
      <title>Perl Best Practices</title>
   </book>
</bookshelf>
<bookshelf>
   <Name>Second Bookshelf</Name>
   <book>
      <author>Conway, Damien</author>
      <title>Perl Best Practices</title>
   </book>
   <book>
      <author>Atwood, Margaret</author>
      <title>Perl Best Practices</title>
   </book>
</bookshelf>
</shelves>

I am trying to use below recipe. I don't know, how could I verify the Name and auther of second bookshelf.

xml_edit 'change title' do
    path 'C:\\testing\\text.xml'
    target '/shelves/bookshelf/book/title[text()=\'Perl Best Practices\']'
    fragment '<title>Hello World</title>'
    action :replace

end