Hello everyone, I often use text editing software (EmEditor) modify the file of plist type.
I think the plist file is actually an xml file. In the help of QM, I saw that qm can manipulate xml, but I don't know how to implement it.
Here's an example, I hope someone can help me write a sample code, thanks in advance ___________________________________________________________________________________ Look for the key20 in the full text, if not found, add a key key20 under the key5, its value: string20
Look for the key7 in the full text, if found, if its property value is false, then modify it to true
Look for the key9 in the full text, if found, delete its key and value ___________________________________________________________________________________
Using text editing software to find and modify, it is too much trouble. I hope that my friends who are proficient in QM programming can help me complete the above examples, so that more people can refer to and use them.
My programming level is low, understanding the code is a little difficult, how to use conditional statements, search and modify key values?
My idea is to react the key values to a dialog box. The drop-down list in the dialog box allows you to select the key and then change the value directly.
08-20-2018, 07:25 PM (This post was last modified: 08-20-2018, 07:32 PM by Kevin.)
are you wanting to remove <key>key9</key>
or
<string>string6</string>
or both
<key>key9</key>
and
<string>string6</string> ??????
here is what you wanted to do not sure you will understand the code though
Thank you very much, I can understand the code, some of the functions used in it, I saw it for the first time.
I run the code, found a problem, with a space after the false and true, as shown in the image below.
In addition, how to generate the .plist file after processing the code, put it in the same directory as the original file, the file name is file_fix.plist
IXml x._create
x.FromFile("$desktop$\plist_file\file.plist") int t tt ARRAY(IXmlNode) a b c;int i
x.RootElement.GetAll(0 a) for i 0 a.len ,IXmlNode n=a[i] ,if(!StrCompare(n.Value"key20")) ,,t=1 ,if(!StrCompare(n.Value"key7")) ,,n=n.Next ,,if(!StrCompare(n.Name"false")) ,,,n.Name="true" ,if(!StrCompare(n.Value"key9")) ,,x.Delete(n);; remove <key>key9</key> ,,n=a[i+1] ,,if(!StrCompare(n.Name"string")) ,,,x.Delete(n);; remove <string>string6</string> if(t!=1) ,x.Path("plist/dict/dict").GetAll(0 b) ,for i 0 b.len ,,sel b[i].Name ,,,case"key" ,,,if(!StrCompare(b[i].Value"key5")) ,,,,IXmlNode iafter ,,,,iafter=b[i+1] ,,,,b[i].Parent.Insert(iafter "string""string20") ,,,,b[i].Parent.Insert(iafter "key""key20")
x.ToString(_s) out _s
x.Path("plist/dict/dict/[key='key5']/array").GetAll(0 c) for i 0 c.len ,n=c[i] ,if(!StrCompare(n.Name"string")) ,,x.Delete(n);; removes all <string>string*</string> from <key>key5</key>
n=x.Path("plist/dict/dict/[key='key5']/array");; path to key5 array
n.Add("dict""").Add("key""Comment").Parent.Add("string""Comment1").Parent.Add("key""Disabled").Parent.Add("true").Parent.Add("key""Find").Parent.Add("data""Comment1").Parent.Add("key""Replace").Parent.Add("data""Comment1+")
n.Add("dict""").Add("key""Comment").Parent.Add("string""Comment2").Parent.Add("key""Disabled").Parent.Add("true").Parent.Add("key""Find").Parent.Add("data""Comment2").Parent.Add("key""Replace").Parent.Add("data""Comment2+")
n.Add("dict""").Add("key""Comment").Parent.Add("string""Comment3").Parent.Add("key""Disabled").Parent.Add("true").Parent.Add("key""Find").Parent.Add("data""Comment3").Parent.Add("key""Replace").Parent.Add("data""Comment3+") IXmlNode e=x.Path("plist/dict/dict/string[='string20']");; path to <string>string20</string>
e.Value=""
e.Name="array";; change <string>string20</string> to <array></array> ;adds new data to <key>key20</key> <array>*data added here</array>
e.Add("dict""").Add("key""Comment").Parent.Add("string""Comment1").Parent.Add("key""Disabled").Parent.Add("true").Parent.Add("key""Find").Parent.Add("data""Comment1").Parent.Add("key""Replace").Parent.Add("data""Comment1+")
e.Add("dict""").Add("key""Comment").Parent.Add("string""Comment2").Parent.Add("key""Disabled").Parent.Add("true").Parent.Add("key""Find").Parent.Add("data""Comment2").Parent.Add("key""Replace").Parent.Add("data""Comment2+")
e.Add("dict""").Add("key""Comment").Parent.Add("string""Comment3").Parent.Add("key""Disabled").Parent.Add("true").Parent.Add("key""Find").Parent.Add("data""Comment3").Parent.Add("key""Replace").Parent.Add("data""Comment3+")
x.ToString(_s) out _s
x.ToFile("$desktop$\plist_file\file.plist")