I have an xml file test.gpx:
cat test.gpx
<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1">
<trk>
<name>Name 1</name>
<desc>Description 1</desc>
</trk>
<trk>
<name>Name 2</name>
<desc>Description 2</desc>
</trk>
</gpx>
xmlstartlet is not able to perform successfully when trying to insert a subnode in this file:
xmlstarlet edit --subnode "/gpx/trk" --type elem -n "new" -v "Hello World!" test.gpx
<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1">
<trk>
<name>Name 1</name>
<desc>Description 1</desc>
</trk>
<trk>
<name>Name 2</name>
<desc>Description 2</desc>
</trk>
</gpx>
Whereas with only one attribute in the first gpx element, it works:
xmlstarlet edit --subnode "/gpx/trk" --type elem -n "new" -v "Hello World!" test.gpx
<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<trk>
<name>Name 1</name>
<desc>Description 1</desc>
<new>Hello World!</new>
</trk>
<trk>
<name>Name 2</name>
<desc>Description 2</desc>
<new>Hello World!</new>
</trk>
</gpx>
Hence my question: how could I succeed with the original file, having more than one attribute in its first gpx element?
Version info:
xmlstarlet --version
1.6.1
compiled against libxml2 2.9.10, linked with 20913
compiled against libxslt 1.1.34, linked with 10134
On Ubuntu 22.04.