I have a junit report XML file like this:
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite>
<testcase classname='Formatting Test' name='Test.swift'>
<failure message='Function parameters should be aligned vertically'>warning: Line:39 </failure>
</testcase>
<testcase classname='Formatting Test' name='Test.swift'>
<failure message='Function parameters should be aligned vertically'>warning: Line:40 </failure>
</testcase>
</testsuite>
</testsuites>
I want to replace content of <failure>
tag with its message
attribute using XMLStarlet. I found a similar question about updating with xpath expression: SO question
but if I try any of those commands:
xmlstarlet edit -u '//testsuites/testsuite/testcase/failure' -x '@message/text()' test.xml
xmlstarlet edit -u '//testsuites/testsuite/testcase/failure' -x '@message' test.xml
then the <failure
> value is completely gone. If I use this (just to test):
xmlstarlet edit -u '//testsuites/testsuite/testcase/failure' -x '../@name' test.xml
the result will be:
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite>
<testcase classname="Formatting Test" name="Test.swift">
<failure message="Function parameters should be aligned vertically" name="Test.swift"/>
</testcase>
<testcase classname="Formatting Test" name="Test.swift">
<failure message="Function parameters should be aligned vertically" name="Test.swift"/>
</testcase>
</testsuite>
</testsuites>
It appends name
attribute to <failure>
tag! It's so confusing how the xpath works for -x
parameter. So how to replace the content of <failure>
tag with its attribute value?
warning: Line:xx
withFunction parameters should be aligned vertically
? – Jack Fleeting