我的 XML 文件;
<settings version="2">
<setting id="TimeShift" default="true">0</setting>
<setting id="Override" default="true">false</setting>
<setting id="Cache">true</setting>
<setting id="Path">/storage/</setting>
<setting id="PathType">0</setting>
<setting id="Url1">http://localhost:8080/main.php?value1=abcd-1234&value2=OqUy1cHm&type=post</setting>
<setting id="startNum">1</setting>
</settings>
我需要提取变量 URL 值。我尝试了一些 sed 和 grep 命令但没有得到结果。我应该使用哪个命令?
答案1
假设 URL 实际上已正确编码(现在不是,这会破坏一些 XML 解析器;两者都&
应该是&
):
$ xmlstarlet sel -t -v '/settings/setting[@id = "Url1"]' -nl file.xml
http://localhost:8080/main.php?value1=abcd-1234&value2=OqUy1cHm&type=post
这用于获取属性为 的文档节点xmlstarlet
的值。/settings/setting
id
Url1