No finding tag with XMLStarlet that contains >

这一生的挚爱 提交于 2019-12-25 04:11:47

问题


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:


&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>


来源:https://stackoverflow.com/questions/52170642/no-finding-tag-with-xmlstarlet-that-contains-gt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!