I'm working with XMLStarlet in a bash script to basically find specific XML nodes based on what has changed on git within that file.
This is working fine until we hit a node that needs to be searched that contains >
as part of it's value.
Example of the node that I want to find:
<?xml version="1.0" encoding="UTF-8"?>
<CustomLabels xmlns="http://soap.sforce.com/2006/04/metadata">
<labels>
<fullName>Button_Value_Get_Data</fullName>
<categories>Button Value</categories>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Value for Button to get Data</shortDescription>
<value>> GET VEHICLE DATA</value>
</labels>
</CustomLabels>
This is the command that I'm running:
xmlstarlet sel -N x="http://soap.sforce.com/2006/04/metadata" -t -c "//x:labels[x:value/text()=\"> GET VEHICLE DATA\"]/x:fullName" -n myFile.xml
This same command works great when the value that needs to be searched doesn't contain >
.
Is there a way to be able to search this? Or is this an xmlstarlet limitation?
Thank you.
>
is an encoding of >
. If you use the literal value in your expression, it matches properly:
$ xmlstarlet sel -N x="http://soap.sforce.com/2006/04/metadata" -t -c "//x:labels[x:value/text()=\"> GET VEHICLE DATA\"]/x:fullName" -n test.xml
<fullName xmlns="http://soap.sforce.com/2006/04/metadata">Button_Value_Get_Data</fullName>