Sin*_*arf 5 xml bash xmlstarlet
我试图提取'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>
Run Code Online (Sandbox Code Playgroud)
如果我直接引用节点,我可以提取值:
$ xmlstarlet sel -t -m '/FrontendStatus[1]/State[1]/String[31]' -v Value <status.xml
WatchingLiveTV
Run Code Online (Sandbox Code Playgroud)
但我想通过'Key'节点的值来选择它
这个XPath将选择Value的State基于其Key等于state:
/FrontendStatus/State/String[Key='state']/Value
Run Code Online (Sandbox Code Playgroud)
或者,在xmlstarlet中:
$ xmlstarlet sel -t -m "/FrontendStatus/State/String[Key='state']" -v Value <status.xml
Run Code Online (Sandbox Code Playgroud)
WatchingLiveTV将按要求返回.
| 归档时间: |
|
| 查看次数: |
7600 次 |
| 最近记录: |