在xmlstarlet中按文本值选择节点
发布时间:2020-12-15 21:48:47 所属栏目:安全 来源:网络整理
导读:我试图提
我试图提取’Value’节点的值,其中’Key’节点在bash
shell中是’state’:
<FrontendStatus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" serializerVersion="1.1"> <script/> <State> <String> ... ... </String> <String> ... ... </String> <String> <Key>state</Key> <Value>WatchingLiveTV</Value> </String> <String> <Key>studiolevels</Key> <Value>1</Value> </String> <String> ... ... </String> <String> ... ... </String> </State> </FrontendStatus> 如果我直接引用节点,我可以提取值: $xmlstarlet sel -t -m '/FrontendStatus[1]/State[1]/String[31]' -v Value <status.xml WatchingLiveTV 但我想通过’Key’节点的值来选择它 解决方法
此XPath将根据其Key等于状态选择State的值:
/FrontendStatus/State/String[Key='state']/Value 或者,在xmlstarlet中: $xmlstarlet sel -t -m "/FrontendStatus/State/String[Key='state']" -v Value <status.xml 将按要求返回WatchingLiveTV. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |