1
我想通過xmlstartlet
查詢plist XML文件。我正在尋找一個string
標籤正文一個獨特的key
標籤的文字。 XML文件可以像在plist文件中如何通過xmlstarlet工具提取唯一鍵標籤後的字符串文本
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>15B42</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleIconFile</key>
<string>AppIcon</string>
.
.
.
</dict>
</plist>
或
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<othertag>
<dict>
<key>BuildMachineOSBuild</key>
<string>15B42</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleIconFile</key>
<string>AppIcon</string>
.
.
.
</dict>
</othertag>
</plist>
在任何情況下,我如照顧方式的字符串值密鑰CFBundleDevelopmentRegion
(在這種情況下爲en
)。
因此,詞典出現的層次結構中的位置是未知的(它可以是/plist/dict
或/plist/another/dict
或其他地方),但是關鍵文本在整個文件中是唯一的。
我已經試過
xmlstarlet sel -t -v '//string/following::key[text()="CFBundleDevelopmentRegion"]' myfile.plist
,但我沒有得到任何輸出。我的XPath是否有問題?或者我需要指定xmlstarlet
的其他參數嗎?
這項工作完美! – halloleo