Following from this questions, I am now able to update a specific variable in a number of XMLs.
However, they all have a lot (unnecessary) whitespaces and xmllint removes them all. I now have 50 lines modified and that makes it very hard to see the functional difference when looking at git diff. Is there a way for xmllint not to do that and only change the value I'm interested in? (I tried to take a look at xmllint's man but didn't find any option that seemed to that)
Example: Original file:
<target_tags>
<target_tag name="my_tag1" default="old_value1" />
<target_tag name="my_tag2" default="old_value2" />
<target_tag name="my_tag3" default="old_value3" />
</target_tags>
xmllint command:
xmllint --shell /tmp/tmp.xml << EOF
> cd //target_tag[@name="my_tag1"]/@default
> set new_value
> save
> bye
> EOF
/ > default > default > default >
Modified file:
<target_tags>
<target_tag name="my_tag1" default="new_value"/>
<target_tag name="my_tag2" default="old_value2"/>
<target_tag name="my_tag3" default="old_value3"/>
</target_tags>
A possible solution using
xmllintcould be to output lines as is until the desired value is found. Then generate a simple xml doc with the line to modify preserving indentationOnly the modified line will be changed