0

I use with success xmlstarlet in order to replace values from an XML node.

xmlstarlet ed -u //author[text()='Gambardella, Matthew'] -v 'Gambardella' bookstore.xml
    <catalog>
       <book id="bk101">
          <author>Gambardella, Matthew</author>
          <title>XML Developer's Guide</title>
          <genre>Computer</genre>
          <price>44.95</price>
          <publish_date>2000-10-01</publish_date>
          <description>An in-depth look at creating applications 
          with XML.</description>
       </book>

I have not found a way, to do this in batch mode, say I wanted to replace many author values, found in fileA.txt:

valueoriginal1
valueoriginal2
valueoriginal3
...

with the values of fileB.txt:

valuereplacement1
valuereplacement2
valuereplacement3
...

and also, have in another file, a log file, of how many occurrences were changed, what was not changed, and in which particular book id each replacement was made... Perhaps I should use another tool, like sed or awk for this?

  • So you are dealing with non-compliant xml? – Thor Apr 25 '17 at 18:17
  • *some logs, of how many occurrences were changed, what was not changed, and in which particular book id each replacement was made* - too broad for "replacement values" task – RomanPerekhrest Apr 25 '17 at 19:02
  • [This answer](http://stackoverflow.com/a/9882528/319698) may be useful as inspiration. – npostavs Apr 25 '17 at 21:09
  • @Thor: i would appreciate an approach, that would also work for non-compliant xml, and regarding the info that a log may have,i need a way, to see, what from file A was not changed, to spot where the problem occurred, why the replacement was not made –  Apr 26 '17 at 06:40

0 Answers0