1

I have a .plist XML file that looks like:

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>system-entities</key>
    <array>
        <dict>
            <key>content-hint</key>
            <string>Linux</string>
            <key>dev-entry</key>
            <string>/dev/disk5s2</string>
            <key>mount-point</key>
            <string>/Volumes/rootfs</string>
            <key>potentially-mountable</key>
            <true/>
            <key>unmapped-content-hint</key>
            <string>Linux</string>
            <key>volume-kind</key>
            <string>ufsd_ExtFS</string>
        </dict>
        <dict>
            <key>content-hint</key>
            <string>Windows_FAT_32</string>
            <key>dev-entry</key>
            <string>/dev/disk5s1</string>
            <key>mount-point</key>
            <string>/Volumes/bootfs 1</string>
            <key>potentially-mountable</key>
            <true/>
            <key>unmapped-content-hint</key>
            <string>Windows_FAT_32</string>
            <key>volume-kind</key>
            <string>msdos</string>
        </dict>
        <dict>
            <key>content-hint</key>
            <string>FDisk_partition_scheme</string>
            <key>dev-entry</key>
            <string>/dev/disk5</string>
            <key>potentially-mountable</key>
            <false/>
            <key>unmapped-content-hint</key>
            <string>FDisk_partition_scheme</string>
        </dict>
    </array>
  </dict>
</plist>

I want to search the with the content-hint following sibling Windows_FAT_32 and return the mount-point following sibling /Volumes/bootfs 1.

ie. return the "mount point" for the "Windows_FAT_32" partition.

Since this is in a shell script, I've been using xpath...

xpath "//dict/array/dict[string='Windows_FAT_32']/key[.='mount-point']/following-sibling::string[1]/text()"

...which is returning nothing.

My lack of experience with xpath searching has me stuck. I was thinking it may have to be done in 2 steps, one to select the right dict, and a second to extract the mount-point, but I'm still stuck with the selection of the dict match.

Does anyone know how this can be done?

Jupiter
  • 21
  • 1
  • 4
  • Your xpath expression seems just fine. Using either `xmllint --xpath` or the `xpath` program from Perl's `XML::XPATH` module, your expression returns `'/Volumes/bootfs 1`. – larsks Jul 09 '23 at 20:38
  • Your XPath looks alright. How are you executing it? E.g: `xpath -q -e '//dict/array/dict[string='Windows_FAT_32']/key[.='mount-point']/following-sibling::string[1]/text()' file.xml` – kjhughes Jul 09 '23 at 20:39
  • Thanks @kjhughes I'm executing it like... `sdcard_mount_p1=`echo $attach_result | xpath "//dict/array/dict[string='Linux']/key[.='mount-point']/following-sibling::string[1]/text()" 2>/dev/null`` – Jupiter Jul 09 '23 at 21:04
  • Thanks @larsks I'm not sure what's happening then but I'll look further. – Jupiter Jul 09 '23 at 21:07
  • 1
    For anyone who comes across this I found the problem, I didn't have the -e selector. I have other scripts that don't use -e that work fine, so I'm not sure when/if that changed. In any case, it was a simple fix. – Jupiter Jul 09 '23 at 22:26

0 Answers0