How read plist file with XMLDocument class?

I’m looking to read information (here in asterisks) from my plist file using the XMLDocument class. Can you help me pls?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">
  <key>**Application #1**</key>
  <key>Application #2</key>

I would NOT recommend using the XML class to read plist files, as plist can be in a variety of formats.

I am sure that I’ve made a feature request somewhere for Xojo to support Apple’s native dictionary serialization. But since I made the feature request, it’ll probably never get added.

It can be done with declares, a sheet-ton of declares or I bet the plugin vendors have a plugin you can buy for it.

I’m sure that there are other workarounds floating around that I don’t know about it.

I had a crack at this but wasted an hour and a half , getting nowhere.
The main problem, to me, is that its a valid but crazy format, where different kinds of things have the same key name.

You cant just XQL for for example … you get Application1 and Visible
To me, Visible and Path are attributes of Application 1

You could brute force this file by reading sequentially from the top down,
finding Application row - then reading until you get a Visible row, then reading the visible state,
then changing the Application on the next one and so on.
That assumes that Application as a word appears as the first part of a group.
If it is actually an app name that can be a different form each time, like Banana, it wouldn’t even work like that.

Have a look at Monkeybread Xojo plugin - CFPreferencesMBS class .


Thanks @Jeff_Tullin,
So, what do you suggest as the ideal structure of the plist to memorize these 3 pieces of information (program name, program path and visibility status)?

To me?
Attributes. But you don’t have that choice because the format ‘exists’ and you cant amend it.

If I was storing it?

<app  appname="Banana" path="path_to_app" visible="true" />
<app  appname="Finder" path="path_to_app" visible="false" />
<app  appname="Calc" path="path_to_app" visible="false" />

XQL gets you an XMLnodelist of all apps
Loop through them, and ask each whether visible or not

mylist = somenode.XQL("//app") 
For i  as integer = 0 To mylist.Length-1
  localappname = mylist.Item(i).GetAttribute("appname")
  localvisible  = mylist.Item(i).GetAttribute("visible")

pList Class for RealBasic by MacCrafters. Old, but still works great, at least with API1.


Also NewCFObjectMBSFromXML function in MBS Xojo MacCF Plugin can read plist in either text or binary format.

For my own learning, is this CFObject method better than CFDictionaryMBS.dictionaryWithContentsOfFile?

Yes. I’ve used it for many years. The developer was Floyd Resler. A few years ago I found him on LinkedIn.

Over the years, I’ve updated it a couple of times. While still in the RB days, I had to convert EditField references to TextFields, etc. And (sigh), I eventually bit the bullet and converted it to API2.

1 Like

Wow, I’ve long wondered who “MacCrafters” was, thanks!

Yes, me too. Added methods for things like appending a dict to another dict, additional constructors (including one where you can pass nil for the target folderitem and it’ll give you a new pList with just headers), a toDictionary method, etc. Also I needed to change all instances of “Chr(13)” to EndofLine.MacOS for some reason, it was long ago…

No, this is just a shortcut to make a dictionary.

I’ve had no problems, but I should take a look at that, too. I don’t remember that one. :slight_smile: