No finding tag with XMLStarlet that contains >

2019-08-31 12:01发布

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>&gt; 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()=\"&gt; GET VEHICLE DATA\"]/x:fullName" -n myFile.xml

This same command works great when the value that needs to be searched doesn't contain &gt;. Is there a way to be able to search this? Or is this an xmlstarlet limitation? Thank you.

1条回答
在下西门庆
2楼-- · 2019-08-31 12:56

&gt; 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>
查看更多
登录 后发表回答