I am using windows version of xmlstarlet to update an xml file, via windows batch file.
xml edit --update "/xml/table/rec[@id=3]/@id" --value 10 %xmlfile%
I expected this to update the id attribute of rec node to 10. When I run this I see the updated xml as expected in the command line, but the file is never updated.
How can I do it, I want to stay away rewriting the whole file as the file could be big one.
before update:
<?xml version="1.0"?>
<xml>
<table>
<rec id="1" />
<rec id="2" />
<rec id="3" />
</table>
</xml>
after update:
<?xml version="1.0"?>
<xml>
<table>
<rec id="1" />
<rec id="2" />
<rec id="10" />
</table>
</xml>
sed -i
(inplace) option is still writing the data to a new place on disk and then deleting the old file. I think the same is true for XML tools. I'd be really surprized ifxmlstarlet
works any differently. Good luck.<xml><table><rec id="3"/></table></xml>
is sufficient to reproduce the issue - theid
attribute is modified but the output is printed to stdout, rather than back to the file.