我正在尝试使用xmlstartlet解析info.plist(对于iOS应用)。我在MacBook Pro上的OSX中这样做。这是我的info.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">
<dict>
<key>UIRequiresFullScreen</key>
<true/>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>MinimumOSVersion</key>
<string>9.3</string>
<key>CFBundleDisplayName</key>
<string>My iOS App</string>
<key>CFBundleIdentifier</key>
<string>local.nowhere.MyiOSApp</string>
<key>CFBundleShortVersionString</key>
<string>3.3.0</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UISupportedExternalAccessoryProtocols</key>
<key>UIBackgroundModes</key>
<array>
<string>external-accessory</string>
</array>
<key>UIAppFonts</key>
<array>
<string>FontAwesome.ttf</string>
</array>
<key>CFBundleVersion</key>
<string>321</string>
<key>NSLocationWhenInUseUsageDescription</key>
<array>
<string>Location enabled?</string>
</array>
<key>NSCameraUsageDescription</key>
<string>needs access to the camera</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>needs access to photos</string>
<key>NSCalendarsUsageDescription</key>
<string>needs access to the calendar</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>needs access to bluetooth</string>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>XSAppIconAssets</key>
<string>Resources/Media.xcassets/AppIcons.appiconset</string>
<key>XSLaunchImageAssets</key>
<string>Resources/Media.xcassets/LaunchImages.launchimage</string>
</dict>
</plist>
这是我的xmlstarlet命令:
xmlstarlet sel -t -m "/plist/dict[key='CFBundleVersion']" -v string ./Info.plist
这是输出:
Attempt to load network entity http://www.apple.com/DTDs/PropertyList-1.0.dtd
9.3
My iOS App
local.nowhere.MyiOSApp
3.3.0
321
needs access to the camera
needs access to photos
needs access to the calendar
needs access to bluetooth
UIStatusBarStyleLightContent
Resources/Media.xcassets/AppIcons.appiconset
Resources/Media.xcassets/LaunchImages.launchimage
任何想法,为什么它返回所有&#39;字符串&#39;那个级别的节点?
答案 0 :(得分:2)
您正在匹配dict
并获取string
的值,以便它返回dict
中的所有字符串。
检查是否存在值为key
的{{1}}元素,除了仅选择CFBundleVersion
之外,其他任何操作都不起作用。
尝试选择dict
本身,然后获取第一个后续兄弟key
的值......
string
这将返回:
xmlstarlet sel --net -t -m "/plist/dict/key[.='CFBundleVersion']" -v "following-sibling::string[1]" ./Info.plist
答案 1 :(得分:0)
或者为了更快的运行版本(因为我无法对其进行评论),请不要查找DTD&amp;忽略STDERR:
xmlstarlet sel -t -m "/plist/dict/key[text()='CFBundleVersion']" -v "following-sibling::string[1]" ./Info.plist 2>/dev/null