无法使用具有 xml 标记属性的 xmlstarlet 更新 xml 文件

Unable to update xml file using xmlstarlet with xml tag attribute

由于标记属性 xmlns(命名空间)

,我无法更新以下 xml 文件
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<advertiserFeatures
xmlns:doc="http://api.homeaway.com/service/v1"
xmlns="http://api.homeaway.com/domain/v0" etag="33054400302" url="/advertisers/0024/e74510aa-d4f0-4509-8c48-7c101e6f021c/features">
<parentEntity href="/advertisers/0024/e74510aa-d4f0-4509-8c48-7c101e6f021c" rel="parentEntity"/>
<advertiseVasCart>true</advertiseVasCart>
<agentAssistedCheckout>true</agentAssistedCheckout>
<dcfEnabled>false</dcfEnabled>
<enhancedDistribution>false</enhancedDistribution>
<inserted>2016-02-12T15:38:58.977Z</inserted>
<travelerFeeEnabled>true</travelerFeeEnabled>
<updated>2016-02-12T15:38:58.977Z</updated>

如果删除该属性,我可以使用以下命令进行更新

xmlstarlet ed -u "/advertiserFeatures/advertiseVasCart" -v "false" advertiserFeatures.xml > advertiserFeatures1.xml

知道我错过了什么吗?

您需要将前缀绑定到默认命名空间 URI,然后在您的 XPath 中使用该前缀来寻址相应命名空间中的元素:

xmlstarlet ed -N x="http://api.homeaway.com/domain/v0" \
    -u "/x:advertiserFeatures/x:advertiseVasCart" \
    -v "false" advertiserFeatures.xml > advertiserFeatures1.xml

进一步阅读:xmlstarlet documentation on 'Namespaces and default namespace'